From 6c2dac14ead4222dcda35cb7c1509c06c680d68d Mon Sep 17 00:00:00 2001 From: sln Date: Thu, 7 Jul 2011 14:53:56 +0000 Subject: [PATCH] Support of drag-and-drop: moving item between other items --- src/SUIT/SUIT_TreeModel.cxx | 41 ++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index 6974a5ed6..40c20228f 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -828,8 +828,7 @@ Qt::ItemFlags SUIT_TreeModel::flags( const QModelIndex& index ) const if ( obj->isCheckable( index.column() ) ) f = f | Qt::ItemIsUserCheckable; - if ( index.isValid() ) - f = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | f; + f = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | f; } return f; } @@ -1791,9 +1790,41 @@ bool SUIT_TreeModel::dropMimeData( const QMimeData* data, Qt::DropAction action, try { - targetObj = object( parent ); - if ( targetObj ) - getObjects( data, resList ); + SUIT_DataObject* dataObj = object( parent ); + + if ( dataObj ) + { + if ( row == -1 ) + { + // mouse cursor other item + targetObj = dataObj; + } + else + { + // mouse between items (top item is considered as parent) + if ( row == 0 ) + { + // cursor between parent item and its first child + targetObj = dataObj; + } + else if ( row > 0 ) + { + QList list; + dataObj->children( list ); + QList::iterator it = list.begin(); + for ( int i = 1 ; it != list.end(); ++it, ++i ) + { + if ( i == row ) + { + targetObj = *it ; + break; + } + } + } + } + } + + getObjects( data, resList ); } catch (...) { -- 2.39.2