]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2154: Multiselection field is cleared when trying to add another object
authornds <nds@opencascade.com>
Mon, 31 Jul 2017 09:20:46 +0000 (12:20 +0300)
committernds <nds@opencascade.com>
Mon, 31 Jul 2017 09:20:46 +0000 (12:20 +0300)
we should not remove from list objects hidden in the viewer if selection was done with SHIFT button

src/ModuleBase/ModuleBase_IWorkshop.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_ModuleConnector.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h

index ac0e3a561772647f0e991bc17e246f875f13f26c..77d9314d74d6b7d1d6d10096153bbdb97d82186b 100644 (file)
@@ -137,6 +137,9 @@ Q_OBJECT
   /// Returns main window of the application
   virtual QMainWindow* desktop() const = 0;
 
+  /// Returns true if SHIFT is pressed
+  /// \return boolean value
+  virtual bool hasSHIFTPressed() const = 0;
 
 signals:
   /// Signal selection changed.
index 1c5153c0605e6b52b058915731a7a53acdd5078d..d144f33821c377a605e3bed8e80daee5059919a8 100755 (executable)
@@ -744,7 +744,8 @@ bool ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
     for (int i = 0; i < aSelectionListAttr->size(); i++) {
       AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
-      bool aFound = findInSelection(anAttr->context(), anAttr->value(), aGeomSelection);
+      bool aFound = findInSelection(anAttr->context(), anAttr->value(), aGeomSelection,
+                                    myWorkshop);
       if (!aFound)
         anIndicesToBeRemoved.insert(i);
     }
@@ -756,7 +757,8 @@ bool ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
     for (int i = 0; i < aRefListAttr->size(); i++) {
       ObjectPtr anObject = aRefListAttr->object(i);
       if (anObject.get()) {
-        bool aFound = findInSelection(anObject, GeomShapePtr(), aGeomSelection);
+        bool aFound = findInSelection(anObject, GeomShapePtr(), aGeomSelection,
+                                      myWorkshop);
         if (!aFound)
           anIndicesToBeRemoved.insert(i);
       }
@@ -786,7 +788,8 @@ bool ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
         aFound = anAttributes.find(anAttribute) != anAttributes.end();
       }
       else {
-        aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection);
+        aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection,
+                                 myWorkshop);
       }
       if (!aFound)
         anIndicesToBeRemoved.insert(i);
@@ -826,8 +829,14 @@ std::map<ObjectPtr, std::set<GeomShapePtr> > ModuleBase_WidgetMultiSelector::con
 
 bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject,
                               GeomShapePtr theShape,
-                              const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection)
+                              const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection,
+                              ModuleBase_IWorkshop* theWorkshop)
 {
+  // issue #2154: we should not remove from list objects hidden in the viewer if selection
+  // was done with SHIFT button
+  if (theWorkshop->hasSHIFTPressed() && !theObject->isDisplayed())
+    return true;
+
   bool aFound = false;
   GeomShapePtr anEmptyShape(new GeomAPI_Shape());
   if (theShape.get()) { // treat shape equal to context as null: 2219, keep order of shapes in list
index 2fecf4ed46412deafbb965906a60dd236930aaf5..2e43e575d1f93c0f9382e81a342c513cfb0325c4 100755 (executable)
@@ -184,10 +184,12 @@ protected:
   /// \param theObject a model object, a set of shapes is searched by it
   /// \param theShape a shape to be in the set of the object shapes
   /// \param theGeomSelection a map built on selection
+  /// \param theWorkshop a current workshop
   /// \return boolean result
   static bool findInSelection(const ObjectPtr& theObject,
                             GeomShapePtr theShape,
-                            const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection);
+                            const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection,
+                            ModuleBase_IWorkshop* theWorkshop);
 
 protected:
   /// List control
index 4e599649fa3eb786a10decc12b93eebe725d5eb1..b832fbb3071833f34b1eb610a7dcef366587b1c3 100644 (file)
@@ -193,6 +193,10 @@ QMainWindow* XGUI_ModuleConnector::desktop() const
   return myWorkshop->desktop();
 }
 
+bool XGUI_ModuleConnector::hasSHIFTPressed() const
+{
+  return myWorkshop->operationMgr()->hasSHIFTPressed();
+}
 
 std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
 {
index 2d0d1473706cf16788361d2ccb859f333b785c33..06536228efd826ec8b0abb1e7cee7310c6260328 100644 (file)
@@ -119,6 +119,9 @@ Q_OBJECT
   /// Return application main window
   virtual QMainWindow* desktop() const;
 
+  /// Returns true if SHIFT is pressed
+  /// \return boolean value
+  virtual bool hasSHIFTPressed() const;
 
   //! Returns workshop
   XGUI_Workshop* workshop() const { return myWorkshop; }
index a0a879c7aaa353aa6c05b6b2f8b705322175c9be..42f892d212103f2d37bebefb575461c1d6c767d5 100644 (file)
@@ -72,18 +72,25 @@ public:
   virtual bool eventFilter(QObject *theObject, QEvent *theEvent)
   {
     bool isAccepted = false;
-    if (myIsActive && theEvent->type() == QEvent::KeyRelease) {
-      QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
-      if (aKeyEvent) {
-        switch (aKeyEvent->key()) {
-          case Qt::Key_Delete:
-            isAccepted = myOperationMgr->onProcessDelete(theObject);
-          break;
-          default:
-            isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
+    if (myIsActive) {
+      if (theEvent->type() == QEvent::KeyRelease) {
+        QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
+        if (aKeyEvent) {
+          myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
+          switch (aKeyEvent->key()) {
+            case Qt::Key_Delete:
+              isAccepted = myOperationMgr->onProcessDelete(theObject);
             break;
+            default:
+              isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
+              break;
+          }
         }
       }
+      else if (theEvent->type() == QEvent::KeyPress) {
+        QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
+        myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
+      }
     }
     if (!isAccepted)
       isAccepted = QObject::eventFilter(theObject, theEvent);
@@ -97,7 +104,7 @@ private:
 
 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
                                      ModuleBase_IWorkshop* theWorkshop)
-: QObject(theParent), myWorkshop(theWorkshop)
+: QObject(theParent), myWorkshop(theWorkshop), mySHIFTPressed(false)
 {
   /// we need to install filter to the application in order to react to 'Delete' key button
   /// this key can not be a short cut for a corresponded action because we need to set
index 56286cc1fece6026f805b72ea65f5eca9925decf..3e6f3b099a86378a1d7250d9b24f7ee59adc0c73 100755 (executable)
@@ -127,6 +127,14 @@ Q_OBJECT
   /// Slot that commits the current operation.
   bool onCommitOperation();
 
+  /// Returns true if SHIFT is pressed
+  /// \param thePressed new boolean state
+  void setSHIFTPressed(const bool thePressed) { mySHIFTPressed = thePressed; }
+
+  /// Returns true if SHIFT is pressed
+  /// \return boolean value
+  bool hasSHIFTPressed() const { return mySHIFTPressed; }
+
 public slots:
   /// Slot that aborts the current operation.
   void onAbortOperation();
@@ -239,6 +247,7 @@ private:
   ModuleBase_IWorkshop* myWorkshop;
 
   XGUI_ShortCutListener* myShortCutListener;
+  bool mySHIFTPressed;
 };
 
 #endif