From fb96bfa1fc8d030bb5fc8c8642384bb5bdc28676 Mon Sep 17 00:00:00 2001 From: sbh Date: Thu, 18 Sep 2014 19:00:13 +0400 Subject: [PATCH] More clear way to process the operations --- src/ModuleBase/ModuleBase_Operation.cpp | 6 --- src/ModuleBase/ModuleBase_Operation.h | 4 +- .../ModuleBase_WidgetDoubleValue.cpp | 17 ------- src/ModuleBase/ModuleBase_WidgetDoubleValue.h | 5 -- src/ModuleBase/ModuleBase_WidgetPoint2D.cpp | 16 ------ src/ModuleBase/ModuleBase_WidgetPoint2D.h | 5 -- src/ModuleBase/ModuleBase_WidgetSelector.cpp | 12 ----- src/ModuleBase/ModuleBase_WidgetSelector.h | 3 -- .../PartSet_OperationFeatureCreate.cpp | 14 +++--- src/PartSet/PartSet_OperationFeatureCreate.h | 4 +- src/PartSet/PartSet_OperationFeatureEdit.cpp | 9 ---- src/PartSet/PartSet_OperationFeatureEdit.h | 4 -- src/XGUI/XGUI_OperationMgr.cpp | 50 ++++++++++--------- src/XGUI/XGUI_OperationMgr.h | 13 ++--- src/XGUI/XGUI_PropertyPanel.cpp | 4 +- src/XGUI/XGUI_PropertyPanel.h | 1 - src/XGUI/XGUI_Workshop.cpp | 2 - 17 files changed, 47 insertions(+), 122 deletions(-) diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 12eb36e53..9b24d742d 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -174,9 +174,3 @@ bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const return false; } -bool ModuleBase_Operation::keyReleased(const int theKey) -{ - // Do nothing... - return false; -} - diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index e29bdc6bc..0a5e1a54d 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -72,7 +72,9 @@ Q_OBJECT /// Returns True if the current operation works with the given object (feature or result) virtual bool hasObject(ObjectPtr theObj) const; - virtual bool keyReleased(const int theKey); + virtual void keyReleased(const int theKey) {}; + + virtual void activateNextToCurrentWidget() {}; public slots: /// Slots which listen the mode widget activation diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 16837acce..6d470dbbd 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -128,20 +128,3 @@ QList ModuleBase_WidgetDoubleValue::getControls() const aList.append(mySpinBox); return aList; } - -bool ModuleBase_WidgetDoubleValue::eventFilter(QObject *theObject, QEvent *theEvent) -{ - if (theObject == mySpinBox) { - if (theEvent->type() == QEvent::KeyRelease) { - QKeyEvent* aKeyEvent = (QKeyEvent*) theEvent; - if (aKeyEvent && (aKeyEvent->key() == Qt::Key_Return || - aKeyEvent->key() == Qt::Key_Enter)) { - emit focusOutWidget(this); - } - emit keyReleased((QKeyEvent*) theEvent); - return true; - } - } - return ModuleBase_ModelWidget::eventFilter(theObject, theEvent); -} - diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index 70c8a272b..20afafbe1 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -43,11 +43,6 @@ Q_OBJECT return myContainer; } - /// Process key release envent on the widget spin box controls - /// \param theObject the object where the event happens - /// \param theEvent the processed event - virtual bool eventFilter(QObject *theObject, QEvent *theEvent); - public slots: /// Delayed value chnged: when user starts typing something, // it gives him a 0,5 second to finish typing, when sends valueChnaged() signal diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index b20f2e8d7..8feec7a6c 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -144,22 +144,6 @@ QList ModuleBase_WidgetPoint2D::getControls() const return aControls; } -bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent) -{ - if (theObject == myXSpin || theObject == myYSpin) { - if (theEvent->type() == QEvent::KeyRelease) { - QKeyEvent* aKeyEvent = (QKeyEvent*) theEvent; - if (aKeyEvent && (aKeyEvent->key() == Qt::Key_Return || - aKeyEvent->key() == Qt::Key_Enter)) { - emit focusOutWidget(this); - } - emit keyReleased((QKeyEvent*) theEvent); - return true; - } - } - return ModuleBase_ModelWidget::eventFilter(theObject, theEvent); -} - bool ModuleBase_WidgetPoint2D::initFromPrevious(ObjectPtr theObject) { if (myOptionParam.length() == 0) diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h index 0151d1455..29d65a7b2 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.h @@ -53,11 +53,6 @@ Q_OBJECT /// \return a control list virtual QList getControls() const; - /// Process key release envent on the widget spin box controls - /// \param theObject the object where the event happens - /// \param theEvent the processed event - virtual bool eventFilter(QObject *theObject, QEvent *theEvent); - bool initFromPrevious(ObjectPtr theObject); signals: diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 8f0c1324f..f5b5af3b1 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -207,18 +207,6 @@ void ModuleBase_WidgetSelector::updateSelectionName() myTextLine->setText(""); } -//******************************************************************** -bool ModuleBase_WidgetSelector::eventFilter(QObject* theObj, QEvent* theEvent) -{ - if (theObj == myTextLine) { - //if (theEvent->type() == QEvent::Polish) { - // myActivateBtn->setChecked(myActivateOnStart); - // onSelectionChanged(); - //} - } - return ModuleBase_ModelWidget::eventFilter(theObj, theEvent); -} - //******************************************************************** void ModuleBase_WidgetSelector::enableOthersControls(bool toEnable) const { diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index 5973c520a..e39f97f32 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -60,9 +60,6 @@ Q_OBJECT /// Activate or deactivate selection void activateSelection(bool toActivate); - protected: - bool eventFilter(QObject* theObj, QEvent* theEvent); - private slots: void onSelectionChanged(); diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index 0bfd4a4bc..759356cd2 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -184,7 +184,7 @@ void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* t } } -bool PartSet_OperationFeatureCreate::keyReleased(const int theKey) +void PartSet_OperationFeatureCreate::keyReleased(const int theKey) { switch (theKey) { case Qt::Key_Return: @@ -195,16 +195,14 @@ bool PartSet_OperationFeatureCreate::keyReleased(const int theKey) } } break; - case Qt::Key_Escape: { - if (!commit()) { - abort(); - } - } - break; default: break; } - return true; +} + +void PartSet_OperationFeatureCreate::activateNextToCurrentWidget() +{ + emit activateNextWidget(myActiveWidget); } void PartSet_OperationFeatureCreate::startOperation() diff --git a/src/PartSet/PartSet_OperationFeatureCreate.h b/src/PartSet/PartSet_OperationFeatureCreate.h index 6fcadf5c0..07dd0eab5 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.h +++ b/src/PartSet/PartSet_OperationFeatureCreate.h @@ -71,7 +71,9 @@ Q_OBJECT virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); /// Processes the key pressed in the view /// \param theKey a key value - virtual bool keyReleased(const int theKey); + virtual void keyReleased(const int theKey); + + virtual void activateNextToCurrentWidget(); public slots: /// Slots which listen the mode widget activation diff --git a/src/PartSet/PartSet_OperationFeatureEdit.cpp b/src/PartSet/PartSet_OperationFeatureEdit.cpp index 6524fc215..7a16b9240 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ b/src/PartSet/PartSet_OperationFeatureEdit.cpp @@ -161,15 +161,6 @@ void PartSet_OperationFeatureEdit::mouseDoubleClick( } } -bool PartSet_OperationFeatureEdit::keyReleased(const int theKey) -{ - if (theKey == Qt::Key_Return || theKey == Qt::Key_Enter) { - commit(); - return true; - } - return PartSet_OperationSketchBase::keyReleased(theKey); -} - void PartSet_OperationFeatureEdit::startOperation() { PartSet_OperationSketchBase::startOperation(); diff --git a/src/PartSet/PartSet_OperationFeatureEdit.h b/src/PartSet/PartSet_OperationFeatureEdit.h index 0f7ed18c8..7bdb6aee2 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.h +++ b/src/PartSet/PartSet_OperationFeatureEdit.h @@ -111,10 +111,6 @@ Q_OBJECT const std::list& theSelected, const std::list& theHighlighted); - /// Processes the key pressed in the view - /// \param theKey a key value - virtual bool keyReleased(const int theKey); - protected: /// \brief Virtual method called when operation is started /// Virtual method called when operation started (see start() method for more description) diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 3a5060d8c..b8e43d7ea 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -48,6 +48,18 @@ QStringList XGUI_OperationMgr::operationList() return result; } +bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent) +{ + if (theEvent->type() == QEvent::KeyRelease) { + QKeyEvent* aKeyEvent = dynamic_cast(theEvent); + if(aKeyEvent) { + onKeyReleased(aKeyEvent); + return true; + } + } + return QObject::eventFilter(theObject, theEvent); +} + bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation) { if (!canStartOperation(theOperation)) @@ -106,25 +118,13 @@ void XGUI_OperationMgr::onValidateOperation() validateOperation(currentOperation()); } -bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent) -{ - if (theEvent->type() == QEvent::KeyRelease) { - QKeyEvent* aKeyEvent = dynamic_cast(theEvent); - // TODO: this is Escape button processing when the property panel has empty content, - // but the operation should be stopped by the Enter has been clicked - if(aKeyEvent) { - onKeyReleased(aKeyEvent); - return true; - } - } - return QObject::eventFilter(theObject, theEvent); -} - -void XGUI_OperationMgr::commitOperation() +bool XGUI_OperationMgr::commitOperation() { if (validateOperation(currentOperation())) { onCommitOperation(); + return true; } + return false; } void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation) @@ -154,7 +154,6 @@ bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation) void XGUI_OperationMgr::onCommitOperation() { ModuleBase_Operation* anOperation = currentOperation(); - anOperation->onWidgetActivated(NULL); if (anOperation) anOperation->commit(); } @@ -169,6 +168,8 @@ void XGUI_OperationMgr::onAbortOperation() bool XGUI_OperationMgr::canAbortOperation() { ModuleBase_Operation* anOperation = currentOperation(); + if(operationsCount() > 1) //in case of nested (sketch) operation no confirmation needed + return true; if (anOperation && anOperation->isModified()) { QString aMessage = tr("%1 operation will be aborted.").arg(anOperation->id()); int anAnswer = QMessageBox::question(qApp->activeWindow(), @@ -212,24 +213,27 @@ void XGUI_OperationMgr::onOperationStopped() void XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent) { + // Let the manager decide what to do with the given key combination. ModuleBase_Operation* anOperation = currentOperation(); - if (anOperation) { - bool isFinished = anOperation->keyReleased(theEvent->key()); - if(isFinished) - return; + if(anOperation) { + anOperation->activateNextToCurrentWidget(); } - // Let the manager decide what to do with the given key combination. + bool isRestart = false; switch (theEvent->key()) { - case Qt::Key_Escape: + case Qt::Key_Escape: { onAbortOperation(); + } break; case Qt::Key_Return: - case Qt::Key_Enter: + case Qt::Key_Enter: { commitOperation(); + } break; default: break; } + if(anOperation) + anOperation->keyReleased(theEvent->key()); } void XGUI_OperationMgr::onWidgetActivated(ModuleBase_ModelWidget* theWidget) diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index 954f61e88..b19fcefac 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -78,7 +78,7 @@ signals: protected: /// Commits the current operatin if it is valid - void commitOperation(); + bool commitOperation(); /// Sets the current operation or NULL /// \param theOperation the started operation /// \param isCheckBeforeStart the flag whether to check whether the operation can be started @@ -99,11 +99,7 @@ signals: /// Returns true if the operation can be aborted bool canAbortOperation(); - protected slots: - /// 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(); - + public slots: /// SLOT, that is called by the key in the property panel is clicked. /// \param theName the attribute name /// \param theEvent the mouse event @@ -113,6 +109,11 @@ signals: /// \param theWidget an activated widget void onWidgetActivated(ModuleBase_ModelWidget* theWidget); + protected slots: + /// 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(); + private: typedef QList Operations; ///< definition for a list of operations Operations myOperations; ///< a stack of started operations. The active operation is on top, diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index d6b88d19c..69408d05c 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -84,9 +84,7 @@ void XGUI_PropertyPanel::setModelWidgets(const QList& t QList::const_iterator anIt = theWidgets.begin(), aLast = theWidgets.end(); for (; anIt != aLast; anIt++) { - //TODO(sbh): Think how to connect prop panle hotkeys and operations mgr - connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, - SIGNAL(keyReleased(QKeyEvent*))); + connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*))); connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this, SLOT(onActivateNextWidget(ModuleBase_ModelWidget*))); diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index d6ff28170..c29232110 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -31,7 +31,6 @@ Q_OBJECT void cleanContent(); - protected: virtual bool eventFilter(QObject *theObject, QEvent *theEvent); public slots: diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 0f3fa139c..f3c19f8b3 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -940,10 +940,8 @@ void XGUI_Workshop::createDockWidgets() connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation())); QPushButton* aCancelBtn = myPropertyPanel->findChild(XGUI::PROP_PANEL_CANCEL); connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation())); -//TODO(sbh): KeyReleasedProblem connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr, SLOT(onKeyReleased(QKeyEvent*))); - connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr, SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel, -- 2.39.2