From ea169bdaac0782d3153c5e1e5b2ae34a576cc6da Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 18 Jan 2016 10:35:38 +0300 Subject: [PATCH] Imrove multi-selector control to provide items multi-selection. Delete key in line edit should not abort the current operation. --- src/PartSet/PartSet_Module.cpp | 2 +- src/XGUI/XGUI_OperationMgr.cpp | 53 ++++++++++++++++++++++++++-------- src/XGUI/XGUI_OperationMgr.h | 14 +++++++-- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 356132804..35c38bc46 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -492,7 +492,7 @@ void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* the { XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr(); - anOpMgr->onKeyReleased(theEvent); + anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent); } void PartSet_Module::onOperationActivatedByPreselection() diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index e46877afa..f8879aa62 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -8,6 +8,7 @@ #include "XGUI_ModuleConnector.h" #include "XGUI_Workshop.h" #include "XGUI_ErrorMgr.h" +#include #include #include @@ -56,7 +57,7 @@ public: if(aKeyEvent) { switch (aKeyEvent->key()) { case Qt::Key_Delete: { - isAccepted = myOperationMgr->onProcessDelete(); + isAccepted = myOperationMgr->onProcessDelete(theObject); } } } @@ -154,9 +155,8 @@ bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent) bool isAccepted = false; if (theEvent->type() == QEvent::KeyRelease) { QKeyEvent* aKeyEvent = dynamic_cast(theEvent); - if(aKeyEvent) { - isAccepted = onKeyReleased(aKeyEvent); - } + if(aKeyEvent) + isAccepted = onKeyReleased(theObject, aKeyEvent); } if (!isAccepted) isAccepted = QObject::eventFilter(theObject, theEvent); @@ -544,7 +544,7 @@ void XGUI_OperationMgr::onOperationStopped() } } -bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent) +bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent) { // Let the manager decide what to do with the given key combination. ModuleBase_Operation* anOperation = currentOperation(); @@ -552,7 +552,7 @@ bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent) switch (theEvent->key()) { case Qt::Key_Return: case Qt::Key_Enter: { - isAccepted = onProcessEnter(); + isAccepted = onProcessEnter(theObject); } break; case Qt::Key_N: @@ -582,11 +582,16 @@ bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent) return isAccepted; } -bool XGUI_OperationMgr::onProcessEnter() +bool XGUI_OperationMgr::onProcessEnter(QObject* theObject) { bool isAccepted = false; ModuleBase_Operation* aOperation = currentOperation(); ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); + // only property panel enter is processed in order to do not process enter in application dialogs + bool isPPChild = isChildObject(theObject, aPanel); + if (!isPPChild) + return isAccepted; + ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget(); bool isAborted = false; if (!anActiveWgt) { @@ -619,20 +624,30 @@ bool XGUI_OperationMgr::onProcessEnter() return isAccepted; } -bool XGUI_OperationMgr::onProcessDelete() +bool XGUI_OperationMgr::onProcessDelete(QObject* theObject) { bool isAccepted = false; ModuleBase_Operation* aOperation = currentOperation(); ModuleBase_ModelWidget* anActiveWgt = 0; + // firstly the widget should process Delete action + ModuleBase_IPropertyPanel* aPanel; if (aOperation) { - ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); + aPanel = aOperation->propertyPanel(); if (aPanel) anActiveWgt = aPanel->activeWidget(); + if (anActiveWgt) { + isAccepted = anActiveWgt->processDelete(); + } } - if (anActiveWgt) - isAccepted = anActiveWgt->processDelete(); if (!isAccepted) { - workshop()->deleteObjects(); + // after widget, object browser and viewer should process delete + /// other widgets such as line edit controls should not lead to + /// processing delete by workshop + XGUI_ObjectsBrowser* aBrowser = workshop()->objectBrowser(); + QWidget* aViewPort = myWorkshop->viewer()->activeViewPort(); + if (isChildObject(theObject, aBrowser) || + isChildObject(theObject, aViewPort)) + workshop()->deleteObjects(); isAccepted = true; } @@ -645,3 +660,17 @@ XGUI_Workshop* XGUI_OperationMgr::workshop() const return aConnector->workshop(); } +bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent) +{ + bool isPPChild = false; + if (theParent && theObject) { + QObject* aParent = (QObject*)theObject; + while (aParent ) { + isPPChild = aParent == theParent; + if (isPPChild) + break; + aParent = aParent->parent(); + } + } + return isPPChild; +} diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index fba23b0d4..1453bf762 100755 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -160,18 +160,21 @@ protected: // TEMPORARY public slots: /// SLOT, that is called by the key in the property panel is clicked. /// \param theEvent the mouse event - bool onKeyReleased(QKeyEvent* theEvent); + /// \param theObject a sender of the event + bool onKeyReleased(QObject *theObject, QKeyEvent* theEvent); /// The functionaly, that should be done by delete click /// Fistly the active widget processes it, then workshop. If no one does not /// process it, do nothing - bool onProcessDelete(); + /// \param theObject a sender of the event + bool onProcessDelete(QObject* theObject); protected slots: /// The functionaly, that should be done by enter click /// Fistly the active widget processes it, then module. If no one does not /// process it, the current operation is committed - bool onProcessEnter(); + /// \param theObject a sender of the event + bool onProcessEnter(QObject *theObject); /// Slot that is called by an operation stop. Removes the stopped operation form the stack. /// If there is a suspended operation, restart it. @@ -203,6 +206,11 @@ protected: // TEMPORARY private: XGUI_Workshop* workshop() const; + /// Checks if the object is a parent or a child under + /// \param theObject an investivated object + /// \param theParent a candidate to be a parent + static bool isChildObject(const QObject* theObject, const QObject* theParent); + private: typedef QList Operations; ///< definition for a list of operations Operations myOperations; ///< a stack of started operations. The active operation is on top, -- 2.39.2