Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

Commit ebeedd64 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

UIDataWidget modified in order to enable the drag&drop of multiple items.

parent cae6b66f
......@@ -140,6 +140,32 @@ void UIDataWidget::mouseReleaseEvent( QMouseEvent *evt )
}
QList<UIDataWidgetItem*> UIDataWidget::dataWidgetsFromDropEvent( QDropEvent *evt ) const
{
QStringList pointerStrings = evt->mimeData()->text().split( ';' );
QList< UIDataWidgetItem* > widgetList;
for( QString &ptrStr : pointerStrings )
{
bool ok;
UIDataWidgetItem *ptr = (UIDataWidgetItem*) ptrStr.toLongLong( &ok, 16 );
if( ok && ptr )
widgetList.push_back( ptr );
}
return widgetList;
}
QList<GenericUIData*> UIDataWidget::dataFromDropEvent( QDropEvent *evt ) const
{
QList< GenericUIData* > dataList;
for( auto w : dataWidgetsFromDropEvent(evt) )
dataList.push_back( w->getUIData() );
return dataList;
}
void UIDataWidget::dragEnterEvent( QDragEnterEvent *evt )
{
evt->acceptProposedAction();
......@@ -157,34 +183,36 @@ void UIDataWidget::dropEvent( QDropEvent *evt )
if( evt->source() == this )
{
UIDataWidgetItem* dstItem = (UIDataWidgetItem*) itemAt( evt->pos() );
QList<UIDataWidgetItem*> draggedItems = dataWidgetsFromDropEvent(evt);
if( (!dstItem && m_DragItem->parent()) || dstItem != m_DragItem->parent() )
{
auto p = (QTreeWidgetItem*) dstItem;
while( p )
for( auto draggedItem : draggedItems )
if( (!dstItem && draggedItem->parent()) || dstItem != draggedItem->parent() )
{
if( p == m_DragItem )
return;
p = p->parent();
}
auto p = (QTreeWidgetItem*) dstItem;
while( p )
{
if( p == draggedItem )
return;
p = p->parent();
}
if( m_DragItem->parent() )
{
m_DragItem->parent()->removeChild( m_DragItem );
if( !dstItem )
m_DragItem->getUIData()->SetParent( NULL );
}
else
invisibleRootItem()->removeChild( m_DragItem );
if( draggedItem->parent() )
{
draggedItem->parent()->removeChild( draggedItem );
if( !dstItem )
draggedItem->getUIData()->SetParent( NULL );
}
else
invisibleRootItem()->removeChild( draggedItem );
if( dstItem )
{
dstItem->addChild( m_DragItem );
m_DragItem->getUIData()->SetParent( dstItem->getUIData() );
if( dstItem )
{
dstItem->addChild( draggedItem );
draggedItem->getUIData()->SetParent( dstItem->getUIData() );
}
else
invisibleRootItem()->addChild( draggedItem );
}
else
invisibleRootItem()->addChild( m_DragItem );
}
}
else
emit contentDropped( evt );
......@@ -200,19 +228,22 @@ void UIDataWidget::mouseDoubleClickEvent( QMouseEvent *evt )
}
void UIDataWidget::mousePressEvent( QMouseEvent *evt )
{
m_DragItem = dynamic_cast<UIDataWidgetItem*>( itemAt( evt->pos() ) );
QTreeWidget::mousePressEvent( evt );
}
void UIDataWidget::mouseMoveEvent( QMouseEvent *evt )
{
if( (evt->buttons() & Qt::RightButton) && m_DragItem )
if( evt->buttons() & Qt::RightButton )
{
QString mimeText;
QList<QTreeWidgetItem*> selection = selectedItems();
while( !selection.isEmpty() )
{
mimeText += "0x" + QString::number( (qulonglong) selection.takeFirst(), 16 );
if( !selection.isEmpty() )
mimeText += ";";
}
QMimeData *mimeData = new QMimeData();
mimeData->setText( m_DragItem->text(0) );
mimeData->setText( mimeText );
QDrag *drag = new QDrag( this );
drag->setMimeData( mimeData );
......
......@@ -20,7 +20,7 @@ class GLViewer;
#include <iostream>
class UIDataWidget : public QTreeWidget
class GUIMAIN_API UIDataWidget : public QTreeWidget
{
Q_OBJECT
......@@ -35,14 +35,14 @@ public:
private:
GenericUIData *m_ClickedOnMenuPopup;
QList<ExportInterface*> m_ExportPlugins;
UIDataWidgetItem *m_DragItem;
QList<UIDataWidgetItem*> dataWidgetsFromDropEvent( QDropEvent *evt ) const;
void dragEnterEvent( QDragEnterEvent *evt );
void dragMoveEvent( QDragMoveEvent *evt );
void dropEvent( QDropEvent *evt );
void mouseReleaseEvent( QMouseEvent *evt );
void mouseDoubleClickEvent( QMouseEvent *evt );
void mousePressEvent( QMouseEvent *evt );
void mouseMoveEvent( QMouseEvent *evt );
public:
......@@ -60,6 +60,8 @@ public:
template <typename TFunc>
inline void forAllTreeItems( const TFunc& func );
QList<GenericUIData*> dataFromDropEvent( QDropEvent *evt ) const;
signals:
void removalAsked();
void visibilityChanged( const QList<QTreeWidgetItem*> &items );
......
......@@ -16,7 +16,7 @@
class UIDataWidgetItem : public QTreeWidgetItem
class GUIMAIN_API UIDataWidgetItem : public QTreeWidgetItem
{
public:
inline UIDataWidgetItem( GenericUIData *uiData ) : QTreeWidgetItem()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment