From: sbh Date: Wed, 10 Sep 2014 11:34:06 +0000 (+0400) Subject: Restarting of the "create line" operation on "Return" key fixed. X-Git-Tag: V_0.4.4~77 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=022a1c0d5127efd6495f0ced6892ad4730bec5db;p=modules%2Fshaper.git Restarting of the "create line" operation on "Return" key fixed. --- diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index bc520ffb3..4b1940ad5 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -96,7 +96,7 @@ signals: /// The signal about key release on the control, that corresponds to the attribute /// \param theAttributeName a name of the attribute /// \param theEvent key release event - void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent); + void keyReleased(QKeyEvent* theEvent); /// The signal about the widget is lost focus /// \param theWidget the model base widget void focusOutWidget(ModuleBase_ModelWidget* theWidget); diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 91130350c..50d2478ad 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -173,3 +173,9 @@ bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const } return false; } + +void ModuleBase_Operation::keyReleased(const int theKey) +{ + // Do nothing... +} + diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 15e157bae..4fd5eff1b 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -66,17 +66,14 @@ Q_OBJECT /// Stores a custom value in model. void storeCustomValue(); - virtual void keyReleased(std::string theName, QKeyEvent* theEvent) - { - } - ; - /// Sets the operation feature void setEditingFeature(FeaturePtr theFeature); /// Returns True if the current operation works with the given object (feature or result) virtual bool hasObject(ObjectPtr theObj) const; + virtual void keyReleased(const int theKey); + public slots: /// Slots which listen the mode widget activation /// \param theWidget the model widget diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index f98bf3dcf..35641c2a5 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -122,10 +122,11 @@ bool ModuleBase_WidgetDoubleValue::eventFilter(QObject *theObject, QEvent *theEv if (theObject == mySpinBox) { if (theEvent->type() == QEvent::KeyRelease) { QKeyEvent* aKeyEvent = (QKeyEvent*) theEvent; - if (aKeyEvent && aKeyEvent->key() == Qt::Key_Return) { + if (aKeyEvent && (aKeyEvent->key() == Qt::Key_Return || + aKeyEvent->key() == Qt::Key_Enter)) { emit focusOutWidget(this); } - emit keyReleased(attributeID(), (QKeyEvent*) theEvent); + emit keyReleased((QKeyEvent*) theEvent); return true; } } diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 5e447ef1d..881a6486d 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -36,7 +36,7 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)), theParent); QGridLayout* aGroupLay = new QGridLayout(myGroupBox); - aGroupLay->setContentsMargins(0, 0, 0, 0); + aGroupLay->setContentsMargins(2, 0, 2, 0); aGroupLay->setColumnStretch(1, 1); { QLabel* aLabel = new QLabel(myGroupBox); @@ -149,10 +149,11 @@ 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) { + if (aKeyEvent && (aKeyEvent->key() == Qt::Key_Return || + aKeyEvent->key() == Qt::Key_Enter)) { emit focusOutWidget(this); } - emit keyReleased(attributeID(), (QKeyEvent*) theEvent); + emit keyReleased((QKeyEvent*) theEvent); return true; } } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 993d46757..cf2bcbc7c 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -286,15 +286,12 @@ void PartSet_Module::onFitAllView() myWorkshop->viewer()->fitAll(); } -void PartSet_Module::onLaunchOperation(std::string theName, ObjectPtr theObject) +void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject) { FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (!aFeature) { - qDebug("Warning! Restart operation without feature!"); - return; - } - ModuleBase_Operation* anOperation = createOperation(theName.c_str(), - aFeature ? aFeature->getKind() : ""); + + std::string aKind = aFeature ? aFeature->getKind() : ""; + ModuleBase_Operation* anOperation = createOperation(theName, aKind); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { XGUI_Selection* aSelection = myWorkshop->selector()->selection(); @@ -303,7 +300,7 @@ void PartSet_Module::onLaunchOperation(std::string theName, ObjectPtr theObject) std::list aHighlighted = aSelection->getHighlighted(); aPreviewOp->initFeature(aFeature); aPreviewOp->initSelection(aSelected, aHighlighted); - } else { + } else if (aFeature) { anOperation->setEditingFeature(aFeature); //Deactivate result of current feature in order to avoid its selection XGUI_Displayer* aDisplayer = myWorkshop->displayer(); @@ -415,14 +412,16 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation(); FeaturePtr aSketch; PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); - if (aPrevOp) + if (aPrevOp) { aSketch = aPrevOp->sketch(); - if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) + } + if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) { anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch); - else if (theCmdId == PartSet_OperationFeatureEditMulti::Type()) + } else if (theCmdId == PartSet_OperationFeatureEditMulti::Type()) { anOperation = new PartSet_OperationFeatureEditMulti(theCmdId.c_str(), this, aSketch); - else if (theCmdId == PartSet_OperationFeatureEdit::Type()) + } else if (theCmdId == PartSet_OperationFeatureEdit::Type()) { anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch); + } } if (!anOperation) { @@ -455,8 +454,8 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI if (aPreviewOp) { connect(aPreviewOp, SIGNAL(featureConstructed(ObjectPtr, int)), this, SLOT(onFeatureConstructed(ObjectPtr, int))); - connect(aPreviewOp, SIGNAL(launchOperation(std::string, ObjectPtr)), this, - SLOT(onLaunchOperation(std::string, ObjectPtr))); + connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this, + SLOT(onRestartOperation(std::string, ObjectPtr))); connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this, SLOT(onMultiSelectionEnabled(bool))); @@ -588,7 +587,7 @@ void PartSet_Module::editFeature(FeaturePtr theFeature) //} //if (aFeature) { - onLaunchOperation(theFeature->getKind(), theFeature); + onRestartOperation(theFeature->getKind(), theFeature); updateCurrentPreview(theFeature->getKind()); //} // } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 797e55c74..39ee6a763 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -112,7 +112,7 @@ Q_OBJECT /// SLOT, to fit all current viewer void onFitAllView(); - void onLaunchOperation(std::string theName, ObjectPtr theFeature); + void onRestartOperation(std::string theName, ObjectPtr theFeature); /// SLOT, to switch on/off the multi selection in the viewer /// \param theEnabled the enabled state diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index 6a405901a..c56fe194f 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -167,16 +167,6 @@ void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3 } } -void PartSet_OperationFeatureCreate::keyReleased(std::string theName, QKeyEvent* theEvent) -{ - int aKeyType = theEvent->key(); - // the second point should be activated by any modification in the property panel - if (!theName.empty()) { - //setPointSelectionMode(myFeaturePrs->getNextMode(theName), false); - } - keyReleased(theEvent->key()); -} - void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* theWidget) { myActiveWidget = theWidget; @@ -201,10 +191,11 @@ void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* t void PartSet_OperationFeatureCreate::keyReleased(const int theKey) { switch (theKey) { - case Qt::Key_Return: { + case Qt::Key_Return: + case Qt::Key_Enter: { if (commit()) { // it start a new line creation at a free point - restartOperation(feature()->getKind(), FeaturePtr()); + restartOperation(feature()->getKind()); } } break; @@ -213,6 +204,7 @@ void PartSet_OperationFeatureCreate::keyReleased(const int theKey) abort(); } } + break; default: break; } diff --git a/src/PartSet/PartSet_OperationFeatureCreate.h b/src/PartSet/PartSet_OperationFeatureCreate.h index a6e3aa877..730ab7aa6 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.h +++ b/src/PartSet/PartSet_OperationFeatureCreate.h @@ -73,8 +73,6 @@ Q_OBJECT /// \param theKey a key value virtual void keyReleased(const int theKey); - virtual void keyReleased(std::string theName, QKeyEvent* theEvent); - public slots: /// Slots which listen the mode widget activation /// \param theWidget the model widget diff --git a/src/PartSet/PartSet_OperationFeatureEdit.cpp b/src/PartSet/PartSet_OperationFeatureEdit.cpp index 4d3edb9e9..2bbc2229e 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ b/src/PartSet/PartSet_OperationFeatureEdit.cpp @@ -163,7 +163,7 @@ void PartSet_OperationFeatureEdit::mouseDoubleClick( void PartSet_OperationFeatureEdit::keyReleased(const int theKey) { - if (theKey == Qt::Key_Return) { + if (theKey == Qt::Key_Return || theKey == Qt::Key_Enter) { commit(); } else PartSet_OperationSketchBase::keyReleased(theKey); diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index 9272c8c9e..93c1818e1 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -103,8 +103,10 @@ void PartSet_OperationSketchBase::keyReleased(const int theKey) bool toAbort = true; if (isModified()) { int anAnswer = QMessageBox::question( - qApp->activeWindow(), tr("Cancel operation"), - tr("Operation %1 will be cancelled. Continue?").arg(id()), QMessageBox::Yes, + qApp->activeWindow(), + tr("Cancel operation"), + tr("Do you want to cancel %1 operation?").arg(id()), + QMessageBox::Yes, QMessageBox::No); toAbort = (anAnswer == QMessageBox::Yes); } @@ -117,11 +119,6 @@ void PartSet_OperationSketchBase::keyReleased(const int theKey) } } -void PartSet_OperationSketchBase::keyReleased(std::string theName, QKeyEvent* theEvent) -{ - keyReleased(theEvent->key()); -} - void PartSet_OperationSketchBase::restartOperation(const std::string& theType, ObjectPtr theFeature) { FeaturePtr aFeature = ModelAPI_Feature::feature(theFeature); @@ -129,10 +126,10 @@ void PartSet_OperationSketchBase::restartOperation(const std::string& theType, O QStringList aNested = this->nestedFeatures(); if (!aNested.isEmpty()) { if (aNested.contains(QString(aFeature->getKind().c_str()))) - emit launchOperation(theType, theFeature); + emit restartRequired(theType, theFeature); else return; } } - emit launchOperation(theType, theFeature); + emit restartRequired(theType, theFeature); } diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 66e3cd004..e2e992dd7 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -118,8 +118,6 @@ Q_OBJECT /// \param theKey a key value virtual void keyReleased(const int theKey); - virtual void keyReleased(std::string theName, QKeyEvent* theEvent); - /// Emits a signal about the operation start. This signal has an information about the feature. /// If the provided feature is empty, the current operation feature is used. /// \param theType a type of an operation started @@ -130,7 +128,7 @@ signals: /// signal about the request to launch operation /// theName the operation name /// theFeature the operation argument - void launchOperation(std::string theName, ObjectPtr theFeature); + void restartRequired(std::string theName, ObjectPtr theFeature); /// Signal about the feature construing is finished /// \param theFeature the result feature diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 12d0dd6a7..af509801a 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -203,7 +203,8 @@ bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent) } else if (theEvent->type() == QEvent::KeyRelease) { QKeyEvent* aEvent = (QKeyEvent*) theEvent; switch (aEvent->key()) { - case Qt::Key_Return: // Accept current input + case Qt::Key_Return: + case Qt::Key_Enter: // Accept current input closeDocNameEditing(true); break; case Qt::Key_Escape: // Cancel the input diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 53f324b40..d10689f04 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -104,7 +104,7 @@ bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent) if (aKeyEvent && aKeyEvent->key() == Qt::Key_Escape) { // 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 - onKeyReleased("", aKeyEvent); + onKeyReleased(aKeyEvent); return true; } } @@ -206,11 +206,11 @@ void XGUI_OperationMgr::onOperationStopped() } } -void XGUI_OperationMgr::onKeyReleased(const std::string& theName, QKeyEvent* theEvent) +void XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent) { ModuleBase_Operation* anOperation = currentOperation(); if (anOperation) - anOperation->keyReleased(theName, theEvent); + 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 f363da6b5..5dbd3cbce 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -104,7 +104,7 @@ signals: /// SLOT, that is called by the key in the property panel is clicked. /// \param theName the attribute name /// \param theEvent the mouse event - void onKeyReleased(const std::string& theName, QKeyEvent* theEvent); + void onKeyReleased(QKeyEvent* theEvent); /// SLOT, that reacts to the widget activation /// \param theWidget an activated widget diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 9a6e9500c..d6b88d19c 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -79,40 +79,40 @@ void XGUI_PropertyPanel::cleanContent() void XGUI_PropertyPanel::setModelWidgets(const QList& theWidgets) { myWidgets = theWidgets; + if (theWidgets.empty()) return; - if (!theWidgets.empty()) { - QList::const_iterator anIt = theWidgets.begin(), aLast = - theWidgets.end(); - for (; anIt != aLast; anIt++) { - connect(*anIt, SIGNAL(keyReleased(const std::string&, QKeyEvent*)), this, - SIGNAL(keyReleased(const std::string&, QKeyEvent*))); + 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(focusOutWidget(ModuleBase_ModelWidget*)), this, - SLOT(onActivateNextWidget(ModuleBase_ModelWidget*))); + connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this, + SLOT(onActivateNextWidget(ModuleBase_ModelWidget*))); - //connect(*anIt, SIGNAL(activated(ModuleBase_ModelWidget*)), - // this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*))); + //connect(*anIt, SIGNAL(activated(ModuleBase_ModelWidget*)), + // this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*))); - ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast(*anIt); - if (aPointWidget) - connect(aPointWidget, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this, - SIGNAL(storedPoint2D(ObjectPtr, const std::string&))); - } - ModuleBase_ModelWidget* aLastWidget = theWidgets.last(); - if (aLastWidget) { - QList aControls = aLastWidget->getControls(); - if (!aControls.empty()) { - QWidget* aLastControl = aControls.last(); + ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast(*anIt); + if (aPointWidget) + connect(aPointWidget, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this, + SIGNAL(storedPoint2D(ObjectPtr, const std::string&))); + } + ModuleBase_ModelWidget* aLastWidget = theWidgets.last(); + if (aLastWidget) { + QList aControls = aLastWidget->getControls(); + if (!aControls.empty()) { + QWidget* aLastControl = aControls.last(); - QPushButton* anOkBtn = findChild(XGUI::PROP_PANEL_OK); - QPushButton* aCancelBtn = findChild(XGUI::PROP_PANEL_CANCEL); + QPushButton* anOkBtn = findChild(XGUI::PROP_PANEL_OK); + QPushButton* aCancelBtn = findChild(XGUI::PROP_PANEL_CANCEL); - setTabOrder(aLastControl, anOkBtn); - setTabOrder(anOkBtn, aCancelBtn); - } + setTabOrder(aLastControl, anOkBtn); + setTabOrder(anOkBtn, aCancelBtn); } - onActivateNextWidget(0); } + onActivateNextWidget(NULL); } const QList& XGUI_PropertyPanel::modelWidgets() const @@ -127,9 +127,10 @@ bool XGUI_PropertyPanel::eventFilter(QObject *theObject, QEvent *theEvent) if (theObject == anOkBtn || theObject == aCancelBtn) { if (theEvent->type() == QEvent::KeyRelease) { QKeyEvent* aKeyEvent = (QKeyEvent*) theEvent; - if (aKeyEvent && aKeyEvent->key() == Qt::Key_Return) { + if (aKeyEvent && (aKeyEvent->key() == Qt::Key_Return || + aKeyEvent->key() == Qt::Key_Enter)) { // TODO: this is enter button processing when the focus is on "Apply" or "Cancel" buttons - emit keyReleased("", (QKeyEvent*) theEvent); + //emit keyReleased("", (QKeyEvent*) theEvent); return true; } } diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index 7331bc531..d6ff28170 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -44,9 +44,8 @@ Q_OBJECT signals: /// The signal about key release on the control, that corresponds to the attribute - /// \param theAttributeName a name of the attribute /// \param theEvent key release event - void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent); + void keyReleased(QKeyEvent* theEvent); /// The signal about the widget activation /// \param theWidget the activated widget void widgetActivated(ModuleBase_ModelWidget* theWidget); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index fec644039..4df53a8f9 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -861,9 +861,9 @@ 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())); - - connect(myPropertyPanel, SIGNAL(keyReleased(const std::string&, QKeyEvent*)), myOperationMgr, - SLOT(onKeyReleased(const std::string&, QKeyEvent*))); +//TODO(sbh): KeyReleasedProblem + connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr, + SLOT(onKeyReleased(QKeyEvent*))); connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr, SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));