From: nds Date: Mon, 31 Jul 2017 09:20:46 +0000 (+0300) Subject: Issue #2154: Multiselection field is cleared when trying to add another object X-Git-Tag: V_2.7.2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1d95654c34de2fb1fb9e0833470661cd64e39c32;p=modules%2Fshaper.git Issue #2154: Multiselection field is cleared when trying to add another object we should not remove from list objects hidden in the viewer if selection was done with SHIFT button --- diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h index ac0e3a561..77d9314d7 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.h +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -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. diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 1c5153c06..d144f3382 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -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 > ModuleBase_WidgetMultiSelector::con bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject, GeomShapePtr theShape, - const std::map >& theGeomSelection) + const std::map >& 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 diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 2fecf4ed4..2e43e575d 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -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 >& theGeomSelection); + const std::map >& theGeomSelection, + ModuleBase_IWorkshop* theWorkshop); protected: /// List control diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 4e599649f..b832fbb30 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -193,6 +193,10 @@ QMainWindow* XGUI_ModuleConnector::desktop() const return myWorkshop->desktop(); } +bool XGUI_ModuleConnector::hasSHIFTPressed() const +{ + return myWorkshop->operationMgr()->hasSHIFTPressed(); +} std::shared_ptr XGUI_ModuleConnector::featureInfo(const QString& theId) const { diff --git a/src/XGUI/XGUI_ModuleConnector.h b/src/XGUI/XGUI_ModuleConnector.h index 2d0d14737..06536228e 100644 --- a/src/XGUI/XGUI_ModuleConnector.h +++ b/src/XGUI/XGUI_ModuleConnector.h @@ -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; } diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index a0a879c7a..42f892d21 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -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(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(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(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 diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index 56286cc1f..3e6f3b099 100755 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -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