]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Improve deletion behavior: select last item if last item was deleted
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 5 May 2016 08:54:50 +0000 (11:54 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 5 May 2016 08:56:08 +0000 (11:56 +0300)
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp

index b7f2995afc00f3f3339b5642c4e9ab8c2fa2ac8f..a651aa185eb0372540bf230277e7dcec2a3bd44f 100755 (executable)
@@ -326,9 +326,6 @@ bool ModuleBase_WidgetMultiSelector::processDelete()
   getSelectedAttributeIndices(anAttributeIds);
 
   QModelIndexList aIndexes = myListControl->selectionModel()->selectedIndexes();
-  //foreach(QModelIndex aIndex, aIndexes) {
-  //  aIndex.row();
-  //}
 
   // refill attribute by the items which indices are not in the list of ids
   bool aDone = false;
@@ -363,8 +360,18 @@ bool ModuleBase_WidgetMultiSelector::processDelete()
     myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments,
                                           true); /// hope that something is redisplayed by object updated
   }
-  foreach(QModelIndex aIndex, aIndexes) {
-    myListControl->selectionModel()->select(aIndex, QItemSelectionModel::Select);
+
+  // Restore selection
+  int aRows = myListControl->model()->rowCount();
+  if (aRows > 0) {
+    foreach(QModelIndex aIndex, aIndexes) {
+      if (aIndex.row() < aRows)
+        myListControl->selectionModel()->select(aIndex, QItemSelectionModel::Select);
+      else {
+        QModelIndex aIdx = myListControl->model()->index(aRows - 1, 0);
+        myListControl->selectionModel()->select(aIdx, QItemSelectionModel::Select);
+      }
+    }
   }
   return aDone;
 }