From: nds Date: Thu, 14 Jan 2016 11:41:05 +0000 (+0300) Subject: Correction for Delete processing. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=414980b1160a56026dd76ba19b0f3f7b77164c20;p=modules%2Fshaper.git Correction for Delete processing. It should be done in a separate listener. Because when operation manager is an install filter for qApp, it will process, besides Delete key, Enter key release of application. But we need to process Enter key release only for Property Panel. In previous case there were regressions, such as: 1. OpenParts: dimension constraint, Enter in flyout point do nothing 2. OpenParts: enter in save dialog leads to crash. --- diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 4b6b22579..e46877afa 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -31,6 +31,45 @@ //#define DEBUG_CURRENT_FEATURE +/// Processes "Delete" key event of application. This key is used by several application actions. +/// There is a logical order of the actions processing. So the key can not be set for actions +/// as a shortcut. The class listens the key event and call operation manager processor. +class XGUI_ShortCutListener : public QObject +{ +public: + /// Constructor + /// \param theParent the parent to be deleted when the parent is deleted + /// \param theOperationMgr the class to perform deletion + XGUI_ShortCutListener(QObject* theParent, XGUI_OperationMgr* theOperationMgr) + : QObject(theParent), myOperationMgr(theOperationMgr) + { + qApp->installEventFilter(this); + } + ~XGUI_ShortCutListener() {} + + /// Redefinition of virtual function to process Delete key release + virtual bool eventFilter(QObject *theObject, QEvent *theEvent) + { + bool isAccepted = false; + if (theEvent->type() == QEvent::KeyRelease) { + QKeyEvent* aKeyEvent = dynamic_cast(theEvent); + if(aKeyEvent) { + switch (aKeyEvent->key()) { + case Qt::Key_Delete: { + isAccepted = myOperationMgr->onProcessDelete(); + } + } + } + } + if (!isAccepted) + isAccepted = QObject::eventFilter(theObject, theEvent); + return isAccepted; + } + +private: + XGUI_OperationMgr* myOperationMgr; /// processor for key event +}; + XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop) : QObject(theParent), myWorkshop(theWorkshop) @@ -38,7 +77,7 @@ XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent, /// 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 /// the actions priority - //qApp->installEventFilter(this); + XGUI_ShortCutListener* aShortCutListener = new XGUI_ShortCutListener(theParent, this); } XGUI_OperationMgr::~XGUI_OperationMgr() @@ -531,9 +570,6 @@ bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent) } } } - case Qt::Key_Delete: { - isAccepted = onProcessDelete(); - } break; break; default: diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index b87501c4b..fba23b0d4 100755 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -162,17 +162,17 @@ protected: // TEMPORARY /// \param theEvent the mouse event bool onKeyReleased(QKeyEvent* theEvent); - 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(); - /// 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(); + 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(); + /// Slot that is called by an operation stop. Removes the stopped operation form the stack. /// If there is a suspended operation, restart it. void onOperationStopped();