]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2806: Provide correct selection with Shift button when Multi selector widget...
authorvsv <vsv@opencascade.com>
Thu, 29 Nov 2018 15:23:52 +0000 (18:23 +0300)
committervsv <vsv@opencascade.com>
Thu, 29 Nov 2018 15:24:25 +0000 (18:24 +0300)
src/ModuleBase/ModuleBase_ISelection.cpp
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_Workshop.cpp

index b54f6e4eee19902ad0652be1c036c71bb2bbe6ac..cde321d1e92d3139df679e268f4d00fe42d76d96 100644 (file)
@@ -34,24 +34,19 @@ void ModuleBase_ISelection::appendSelected(const QList<ModuleBase_ViewerPrsPtr>
 {
   // collect the objects from the viewer
   QObjectPtrList anExistedObjects;
-  QList<ModuleBase_ViewerPrsPtr>::const_iterator aPrsIt = theValuesTo.begin(),
-                                              aPrsLast = theValuesTo.end();
-  for (; aPrsIt != aPrsLast; aPrsIt++) {
-    if ((*aPrsIt)->owner() && (*aPrsIt)->object())
-      anExistedObjects.push_back((*aPrsIt)->object());
+  foreach(ModuleBase_ViewerPrsPtr aPrs, theValuesTo) {
+    if (aPrs->owner() && aPrs->object())
+      anExistedObjects.append(aPrs->object());
   }
 
-
-  QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(),
-                                              aLast = theValues.end();
-  for (; anIt != aLast; anIt++) {
-    ObjectPtr anObject = (*anIt)->object();
+  ObjectPtr anObject;
+  foreach(ModuleBase_ViewerPrsPtr aPrs, theValues) {
+    anObject = aPrs->object();
     if (anObject.get() != NULL && !anExistedObjects.contains(anObject)) {
       theValuesTo.append(std::shared_ptr<ModuleBase_ViewerPrs>(
                new ModuleBase_ViewerPrs(anObject, GeomShapePtr(), NULL)));
     }
   }
-
 }
 
 //********************************************************************
index 5c67a3d5037b62d454236c5de5ec2b8b403b1c11..0c7dcd6beba771096d0057cad314e8df2af0a0c4 100644 (file)
@@ -137,9 +137,7 @@ void XGUI_ModuleConnector::setSelected(const QList<ModuleBase_ViewerPrsPtr>& the
     foreach(ModuleBase_ViewerPrsPtr aVal, theValues) {
       anObjects.append(aVal->object());
     }
-    bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
     aBrowser->setObjectsSelected(anObjects);
-    myWorkshop->objectBrowser()->blockSignals(aBlocked);
   }
 }
 
index b08ccc36e8fd56b2ca403aef51190fc6f529b660..7f28e6f4166be884baaf00b4d2ef19e185d1fbd0 100644 (file)
@@ -40,6 +40,7 @@
 #include <QAction>
 #include <QStyledItemDelegate>
 #include <QMessageBox>
+#include <QApplication>
 
 #ifdef DEBUG_INDXES
 #include <QToolTip>
@@ -533,17 +534,61 @@ void XGUI_ObjectsBrowser::rebuildDataTree()
 //***************************************************
 void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects)
 {
-  QList<QModelIndex> theIndexes;
   QItemSelectionModel* aSelectModel = myTreeView->selectionModel();
-  aSelectModel->clear();
+  QModelIndexList aIndexes = aSelectModel->selectedIndexes();
+  if (theObjects.size() == 0) {
+    bool aIsBlock = aSelectModel->blockSignals(true);
+    aSelectModel->clear();
+    aSelectModel->blockSignals(aIsBlock);
+    foreach(QModelIndex aIdx, aIndexes) {
+      myTreeView->update(aIdx);
+    }
+    return;
+  }
 
-  foreach(ObjectPtr aFeature, theObjects)
-  {
-    QModelIndex aIndex = myDocModel->objectIndex(aFeature);
-    if (aIndex.isValid()) {
-      aSelectModel->select(aIndex, QItemSelectionModel::Select);
+  ObjectPtr aObject;
+  QModelIndexList aUnselect;
+  QObjectPtrList aToSelect = theObjects;
+  QHash<qint64, ObjectPtr> aNotChanged;
+  foreach(QModelIndex aIdx, aIndexes) {
+    aObject = myDocModel->object(aIdx);
+    if (aObject.get()) {
+      if (aToSelect.contains(aObject)) {
+        aNotChanged.insert((qint64)aObject.get(), aObject);
+      } else {
+        aUnselect.append(aIdx);
+      }
+    }
+    else {
+      aUnselect.append(aIdx);
     }
   }
+
+  foreach(ObjectPtr aObj, aNotChanged)
+    aToSelect.removeAll(aObj);
+
+  bool aIsBlock = aSelectModel->blockSignals(true);
+  foreach(QModelIndex aIdx, aUnselect) {
+    aSelectModel->select(aIdx, QItemSelectionModel::Deselect);
+    myTreeView->update(aIdx);
+  }
+
+  QModelIndex aIndex0, aIndex1, aIndex2, aCurrent;
+  foreach(ObjectPtr aFeature, aToSelect) {
+    aIndex1 = myDocModel->objectIndex(aFeature, 1);
+    if (aIndex1.isValid()) {
+      if (!aCurrent.isValid())
+        aCurrent = aIndex1;
+      aIndex0 = myDocModel->objectIndex(aFeature, 0);
+      aIndex2 = myDocModel->objectIndex(aFeature, 2);
+      aSelectModel->select(aIndex1, QItemSelectionModel::Select | QItemSelectionModel::Rows);
+      myTreeView->update(aIndex0);
+      myTreeView->update(aIndex1);
+      myTreeView->update(aIndex2);
+    }
+  }
+  aSelectModel->setCurrentIndex(aCurrent, QItemSelectionModel::NoUpdate);
+  aSelectModel->blockSignals(aIsBlock);
 }
 
 //***************************************************
@@ -585,14 +630,14 @@ QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes)
   QObjectPtrList aList;
   QModelIndexList aIndexes = selectedIndexes();
   XGUI_DataModel* aModel = dataModel();
-  QModelIndexList::const_iterator aIt;
-  for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) {
-    if ((*aIt).column() == 1) {
-      ObjectPtr aObject = aModel->object(*aIt);
+
+  foreach(QModelIndex aIdx, aIndexes) {
+    if (aIdx.column() == 1) {
+      ObjectPtr aObject = aModel->object(aIdx);
       if (aObject) {
         aList.append(aObject);
         if (theIndexes)
-          theIndexes->append(*aIt);
+          theIndexes->append(aIdx);
       }
     }
   }
index 6ea539481fbdd6393a7beae474a4bea4c8e0153f..a4cf3bbcbd1f766e7ec1e897518294f8e7b78845 100755 (executable)
@@ -146,10 +146,7 @@ void XGUI_SelectionMgr::onViewerSelection()
 
   QObjectPtrList anObjects;
   convertToObjectBrowserSelection(aValues, anObjects);
-
-  bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
   myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
-  myWorkshop->objectBrowser()->blockSignals(aBlocked);
 
   emit selectionChanged();
 }
@@ -191,9 +188,7 @@ void XGUI_SelectionMgr::updateSelectionBy(const ModuleBase_ISelection::Selection
 void XGUI_SelectionMgr::clearSelection()
 {
   QObjectPtrList aFeatures;
-  bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
   myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
-  myWorkshop->objectBrowser()->blockSignals(aBlocked);
 
   QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
              myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
@@ -211,12 +206,9 @@ void XGUI_SelectionMgr::setSelected(const QList<ModuleBase_ViewerPrsPtr>& theVal
   aDisplayer->setSelected(theValues);
 
   // update selection in Object Browser
-  bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
   QObjectPtrList anObjects;
   convertToObjectBrowserSelection(theValues, anObjects);
-
   myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
-  myWorkshop->objectBrowser()->blockSignals(aBlocked);
 }
 
 //**************************************************************
index 823d8fe8885d56219c2d64bb417de44914666571..e3db137e014486486f5838eb1501c447bd5b4a17 100755 (executable)
@@ -171,8 +171,8 @@ QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
 //#define DEBUG_CLEAN_HISTORY
 
 #ifdef HAVE_SALOME
-static QString MyFilter(QObject::tr("OpenParts files (*.shaper *.opp)"));
-static QString MyFilter2(QObject::tr("OpenParts files (*.shaper)"));
+static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.opp)"));
+static QString MyFilter2(QObject::tr("SHAPER files (*.shaper)"));
 static QString MyExtension(".shaper");
 #else
 static QString MyFilter(QObject::tr("OpenParts files (*.opp);;All files (*.*)"));
@@ -2723,9 +2723,7 @@ void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
   }
   if (aSelList.count() > theObjects.count()) {
     // if something was found
-    bool aBlocked = objectBrowser()->blockSignals(true);
     objectBrowser()->setObjectsSelected(aSelList);
-    objectBrowser()->blockSignals(aBlocked);
     objectBrowser()->ensureVisible(aNewSel.first());
   }
   if (aHasHidden)
@@ -2752,9 +2750,7 @@ void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
   }
   if (aSelList.count() > theObjects.count()) {
     // if something was found
-    bool aBlocked = objectBrowser()->blockSignals(true);
     objectBrowser()->setObjectsSelected(aSelList);
-    objectBrowser()->blockSignals(aBlocked);
     objectBrowser()->ensureVisible(aNewSel.first());
   }
 }