]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Support of drag-and-drop: moving item between other items
authorsln <sln@opencascade.com>
Thu, 7 Jul 2011 14:53:56 +0000 (14:53 +0000)
committersln <sln@opencascade.com>
Thu, 7 Jul 2011 14:53:56 +0000 (14:53 +0000)
src/SUIT/SUIT_TreeModel.cxx

index 6974a5ed6c3e3d4cda54b7bdd053a5f2c701bf4c..40c20228fc69198869f180c7a89e72fa50312e8c 100755 (executable)
@@ -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<SUIT_DataObject*> list;
+          dataObj->children( list );
+          QList<SUIT_DataObject*>::iterator it = list.begin();
+          for ( int i = 1 ; it != list.end(); ++it, ++i )
+          {
+            if ( i == row )
+            {
+              targetObj = *it ;
+              break;
+            }
+          }
+        }
+      }
+    }
+
+    getObjects( data, resList );
   }
   catch (...)
   {