From bddbc598492a5dfa976d115200097724d7c6505e Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 7 Oct 2015 14:51:20 +0300 Subject: [PATCH] Apply modifications in the editors by Enter/Tab event only. --- src/ModuleBase/ModuleBase_DoubleSpinBox.cpp | 47 ++++++++++++++++++- src/ModuleBase/ModuleBase_DoubleSpinBox.h | 10 ++++ src/ModuleBase/ModuleBase_IModule.cpp | 4 +- src/ModuleBase/ModuleBase_IModule.h | 2 +- src/ModuleBase/ModuleBase_ModelWidget.cpp | 13 +++++ src/ModuleBase/ModuleBase_ModelWidget.h | 9 ++++ .../ModuleBase_OperationFeature.cpp | 4 +- .../ModuleBase_WidgetDoubleValue.cpp | 9 +++- src/ModuleBase/ModuleBase_WidgetDoubleValue.h | 3 ++ src/ModuleBase/ModuleBase_WidgetIntValue.cpp | 3 +- src/PartSet/PartSet_Module.cpp | 4 +- src/PartSet/PartSet_Module.h | 2 +- src/PartSet/PartSet_SketcherMgr.cpp | 35 +++++++++++--- src/PartSet/PartSet_SketcherMgr.h | 6 ++- src/PartSet/PartSet_WidgetPoint2d.cpp | 9 +++- src/PartSet/PartSet_WidgetPoint2d.h | 3 ++ src/PartSet/PartSet_WidgetPoint2dDistance.cpp | 7 ++- src/PartSet/PartSet_WidgetPoint2dDistance.h | 3 ++ src/XGUI/XGUI_OperationMgr.cpp | 22 ++++++++- 19 files changed, 173 insertions(+), 22 deletions(-) diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp index 080138f54..e436875bf 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp @@ -57,7 +57,8 @@ const double PSEUDO_ZERO = 1.e-20; */ ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePrecision) : QDoubleSpinBox(theParent), - myCleared(false) + myCleared(false), + myIsModified(false) { // VSR 01/07/2010: Disable thousands separator for spin box // (to avoid inconsistency of double-2-string and string-2-double conversion) @@ -75,6 +76,9 @@ ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePr connect(lineEdit(), SIGNAL(textChanged( const QString& )), this, SLOT(onTextChanged( const QString& ))); + + connect(this, SIGNAL(valueChanged(const QString&)), this, SLOT(onValueChanged(const QString&))); + connect(this, SIGNAL(editingFinished()), this, SLOT(onEditingFinished())); } /*! @@ -196,6 +200,31 @@ QString ModuleBase_DoubleSpinBox::removeTrailingZeroes(const QString& src) const return res; } +#include +void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent *theEvent) +{ + myProcessedEvent = 0; + + bool anIsModified = myIsModified; + QDoubleSpinBox::keyPressEvent(theEvent); + + switch (theEvent->key()) { + case Qt::Key_Enter: + case Qt::Key_Return: { + if (anIsModified) + myProcessedEvent = theEvent; + /*qDebug("ModuleBase_DoubleSpinBox::keyPressEvent"); + if (anIsModified) // we should not perform this event outside + theEvent->setAccepted(true); + else + theEvent->setAccepted(false);*/ + } + break; + default: + break; + } +} + /*! \brief Perform \a steps increment/decrement steps. @@ -306,4 +335,20 @@ QValidator::State ModuleBase_DoubleSpinBox::validate(QString& str, int& pos) con void ModuleBase_DoubleSpinBox::onTextChanged(const QString& ) { myCleared = false; + myIsModified = true; +} + +void ModuleBase_DoubleSpinBox::onValueChanged(const QString& theValue) +{ + myIsModified = true; +} + +void ModuleBase_DoubleSpinBox::onEditingFinished() +{ + myIsModified = false; +} + +bool ModuleBase_DoubleSpinBox::isEventProcessed(QKeyEvent* theEvent) +{ + return myProcessedEvent && myProcessedEvent == theEvent; } diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.h b/src/ModuleBase/ModuleBase_DoubleSpinBox.h index 87cbe6e84..52eb6e3f9 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.h +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.h @@ -11,6 +11,7 @@ #include #include +class QKeyEvent; /** * \ingroup GUI @@ -48,13 +49,18 @@ Q_OBJECT /// Validate current value virtual QValidator::State validate(QString&, int&) const; + virtual bool isEventProcessed(QKeyEvent* theEvent); + protected slots: /// Called on text changed virtual void onTextChanged(const QString&); + void onValueChanged(const QString& theValue); + void onEditingFinished(); protected: /// Removes extra trailing zero symbols QString removeTrailingZeroes(const QString&) const; + virtual void keyPressEvent(QKeyEvent* theEvent); private: /// Is clear flag @@ -62,6 +68,10 @@ Q_OBJECT /// Precision value int myPrecision; + /// Boolean value whether the spin box content is modified + bool myIsModified; + + QKeyEvent* myProcessedEvent; }; #endif diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 90bb8ede3..fb973e591 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -184,10 +184,10 @@ bool ModuleBase_IModule::canRedo() const return aMgr->hasModuleDocument() && aMgr->canRedo() && !aMgr->isOperation(); } -bool ModuleBase_IModule::canCommitOperation() const +/*/bool ModuleBase_IModule::canCommitOperation() const { return true; -} +}*/ void ModuleBase_IModule::onFeatureTriggered() { diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 747dda203..a32b0224c 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -122,7 +122,7 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// Returns True if the current operation can be committed. By default it is true. /// \return a boolean value - virtual bool canCommitOperation() const; + //virtual bool canCommitOperation() const; /// Returns whether the object can be erased. The default realization returns true. /// \param theObject a model object diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 75d99535b..87d490d88 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -148,6 +148,14 @@ bool ModuleBase_ModelWidget::restoreValue() return isDone; } +void ModuleBase_ModelWidget::storeValueByApply() +{ + // do not emit signal about update the currenty feature object + // in order to do not perform additional redisplay in the viewer. + // It should happens by finish operation of the apply action + storeValueCustom(); +} + void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) { blockUpdateViewer(true); @@ -168,6 +176,11 @@ void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) //blockUpdateViewer(false); } +bool ModuleBase_ModelWidget::isEventProcessed(QKeyEvent* theEvent) +{ + return false; +} + bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) { QWidget* aWidget = qobject_cast(theObject); diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 175305244..dd60b1664 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -91,6 +91,10 @@ Q_OBJECT /// \return True in success bool restoreValue(); + /// Saves the internal parameters to the given feature. Emits signals before and after store + /// \return True in success + void storeValueByApply(); + /// Set focus to the first control of the current widget. The focus policy of the control is checked. /// If the widget has the NonFocus focus policy, it is skipped. /// \return the state whether the widget can accept the focus @@ -147,6 +151,9 @@ Q_OBJECT /// \return Current Editing mode bool isEditingMode() const { return myIsEditing; } + /// Returns true if the event is processed. + virtual bool isEventProcessed(QKeyEvent* theEvent); + /// Sends Update and Redisplay for the given object /// \param theObj is updating object static void updateObject(ObjectPtr theObj); @@ -160,6 +167,8 @@ signals: void beforeValuesChanged(); /// The signal about widget values changed void valuesChanged(); + /// The signal about widget values modified + void valuesModified(); /// The signal about widget values are to be changed void afterValuesChanged(); diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index 7d03e735f..39bdd4e38 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -38,6 +38,8 @@ #include #endif +#define APPLY_BY_ENTER_OR_TAB + ModuleBase_OperationFeature::ModuleBase_OperationFeature(const QString& theId, QObject* theParent) : ModuleBase_Operation(theId, theParent), myIsEditing(false) @@ -250,7 +252,7 @@ bool ModuleBase_OperationFeature::commit() ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel(); if (aPropertyPanel) aPropertyPanel->cleanContent(); - + myFeature->setStable(true); SessionPtr aMgr = ModelAPI_Session::get(); diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 9b478cc8e..5f9dc8a5b 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -31,7 +31,7 @@ #include #endif -//#define APPLY_BY_ENTER_OR_TAB +#define APPLY_BY_ENTER_OR_TAB ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData, @@ -91,6 +91,8 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, #ifdef APPLY_BY_ENTER_OR_TAB // Apply widget value change by enter/tab event. connect(mySpinBox, SIGNAL(editingFinished()), this, SIGNAL(valuesChanged())); + connect(mySpinBox, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesModified())); + #else connect(mySpinBox, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesChanged())); #endif @@ -157,3 +159,8 @@ QList ModuleBase_WidgetDoubleValue::getControls() const aList.append(mySpinBox); return aList; } + +bool ModuleBase_WidgetDoubleValue::isEventProcessed(QKeyEvent* theEvent) +{ + return mySpinBox->isEventProcessed(theEvent); +} diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index 81052981c..04e871795 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -44,6 +44,9 @@ Q_OBJECT /// \return a control list virtual QList getControls() const; + /// Returns true if the event is processed. + virtual bool isEventProcessed(QKeyEvent* 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_WidgetIntValue.cpp b/src/ModuleBase/ModuleBase_WidgetIntValue.cpp index 95045d0c2..005a45100 100644 --- a/src/ModuleBase/ModuleBase_WidgetIntValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetIntValue.cpp @@ -34,7 +34,7 @@ #include #endif -//#define APPLY_BY_ENTER_OR_TAB +#define APPLY_BY_ENTER_OR_TAB ModuleBase_WidgetIntValue::ModuleBase_WidgetIntValue(QWidget* theParent, const Config_WidgetAPI* theData, @@ -90,6 +90,7 @@ ModuleBase_WidgetIntValue::ModuleBase_WidgetIntValue(QWidget* theParent, #ifdef APPLY_BY_ENTER_OR_TAB // Apply widget value change by enter/tab event. connect(mySpinBox, SIGNAL(editingFinished()), this, SIGNAL(valuesChanged())); + connect(mySpinBox, SIGNAL(valueChanged(int)), this, SIGNAL(valuesModified())); #else connect(mySpinBox, SIGNAL(valueChanged(int)), this, SIGNAL(valuesChanged())); #endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 15e86b4cd..e9fda30ce 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -376,10 +376,10 @@ bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& t return aValid; } -bool PartSet_Module::canCommitOperation() const +/*bool PartSet_Module::canCommitOperation() const { return mySketchMgr->canCommitOperation(); -} +}*/ bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const { diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 0287c2b5b..f983ca04c 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -118,7 +118,7 @@ public: /// Returns True if the current operation can be committed. Asks the sketch manager. /// \return a boolean value - virtual bool canCommitOperation() const; + //virtual bool canCommitOperation() const; /// Returns whether the object can be erased at the bounds of the active operation. /// The sub-objects of the current operation can not be erased diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 270877d4b..b1fd51d51 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -152,7 +152,7 @@ void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner, PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule) : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false), - myIsResetCurrentValue(false), myIsMouseOverWindow(false), + myIsResetCurrentValue(false), myIsCurrentValueUnderModification(false), myIsMouseOverWindow(false), myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true), myIsPopupMenuActive(false), myIsConstraintsShown(true) { @@ -192,6 +192,7 @@ void PartSet_SketcherMgr::onEnterViewPort() // redisplayed before this update, the feature presentation jumps from reset value to current. myIsMouseOverWindow = true; myIsResetCurrentValue = false; + myIsCurrentValueUnderModification = false; // it is important to validate operation here only if sketch entity create operation is active // because at this operation we reacts to the mouse leave/enter view port //operationMgr()->onValidateOperation(); @@ -278,9 +279,20 @@ void PartSet_SketcherMgr::onLeaveViewPort() } } +void PartSet_SketcherMgr::onValuesModied() +{ + myIsCurrentValueUnderModification = true; + // update Apply enable state + //myIsResetCurrentValue = false; + //if (!isNestedCreateOperation(getCurrentOperation())) + // return; + operationMgr()->onValidateOperation(); +} + void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel() { myIsResetCurrentValue = false; + myIsCurrentValueUnderModification = false; if (isNestedCreateOperation(getCurrentOperation())) return; @@ -705,7 +717,8 @@ QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature) AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR()); anError = aAttributeString->value().c_str(); } - else if (myIsResetCurrentValue) { // this flag do not allow commit of the current operation + else if (myIsResetCurrentValue || myIsCurrentValueUnderModification) { + // this flags do not allow commit of the current operation ModuleBase_OperationFeature* aFOperation = dynamic_cast (getCurrentOperation()); if (aFOperation) { @@ -719,7 +732,11 @@ QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature) if (anAttr.get()) anAttributeName = anAttr->id().c_str(); } - anError = "Attribute \"" + anAttributeName + "\" is not initialized."; + if (myIsResetCurrentValue) + anError = "Attribute \"" + anAttributeName + "\" is not initialized."; + else if (myIsCurrentValueUnderModification) { + anError = "Attribute \"" + anAttributeName + "\" modification is not applyed. Please click \"Enter\" or \"Tab\"."; + } } } } @@ -939,6 +956,7 @@ void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp) { connectToPropertyPanel(false); myIsResetCurrentValue = false; + myIsCurrentValueUnderModification = false; myIsMouseOverViewProcessed = true; operationMgr()->onValidateOperation(); if (isNestedCreateOperation(theOp)) @@ -971,15 +989,16 @@ bool PartSet_SketcherMgr::canRedo() const return isNestedCreateOperation(getCurrentOperation()); } -bool PartSet_SketcherMgr::canCommitOperation() const +/*bool PartSet_SketcherMgr::canCommitOperation() const { bool aCanCommit = true; - if (isNestedCreateOperation(getCurrentOperation()) && myIsResetCurrentValue) + if (isNestedCreateOperation(getCurrentOperation()) && + (myIsResetCurrentValue || myIsCurrentValueUnderModification)) aCanCommit = false; return aCanCommit; -} +}*/ bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const { @@ -1077,7 +1096,7 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const { - return myIsMouseOverWindow || !myIsResetCurrentValue; + return myIsMouseOverWindow || (!myIsResetCurrentValue && !myIsCurrentValueUnderModification); #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str()); #endif @@ -1234,6 +1253,8 @@ void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect) if (isToConnect) { connect(aWidget, SIGNAL(beforeValuesChanged()), this, SLOT(onBeforeValuesChangedInPropertyPanel())); + connect(aWidget, SIGNAL(valuesModified()), + this, SLOT(onValuesModied())); connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel())); connect(aWidget, SIGNAL(afterValuesChanged()), this, SLOT(onAfterValuesChangedInPropertyPanel())); diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 5e8a09597..f926b6b65 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -137,7 +137,7 @@ public: /// Returns False only if the sketch creating feature can not be visualized. /// \return a boolean value - bool canCommitOperation() const; + //bool canCommitOperation() const; /// Returns whether the object can be erased at the bounds of the active operation. /// Sketch sub-entities can not be erased during the sketch operation @@ -205,6 +205,9 @@ private slots: /// Process the leave mouse of the view port. If the current operation is a create of /// a nested sketch feature, it hides the feature in the viewer void onLeaveViewPort(); + + /// Updates the flag of reset state + void onValuesModied(); /// Listens to the value changed signal and display the current operation feature void onBeforeValuesChangedInPropertyPanel(); /// Listens to the signal about values are to be changed in the property panel @@ -298,6 +301,7 @@ private: bool myIsDragging; bool myDragDone; bool myIsResetCurrentValue; /// the state that value in the property panel is reset + bool myIsCurrentValueUnderModification; /// the value is modified in PP but it is not applyed in the model bool myIsMouseOverWindow; /// the state that the mouse over the view bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method bool myIsPopupMenuActive; /// the state of the popup menu is shown diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index bb75fd068..09dff2d14 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -52,7 +52,7 @@ const double MaxCoordinate = 1e12; static QStringList MyFeaturesForCoincedence; -//#define APPLY_BY_ENTER_OR_TAB +#define APPLY_BY_ENTER_OR_TAB PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, @@ -93,6 +93,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, #ifdef APPLY_BY_ENTER_OR_TAB // Apply widget value change by enter/tab event. connect(myXSpin, SIGNAL(editingFinished()), this, SLOT(onValuesChanged())); + connect(myXSpin, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesModified())); #else connect(myXSpin, SIGNAL(valueChanged(const QString&)), this, SLOT(onValuesChanged())); #endif @@ -111,6 +112,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, #ifdef APPLY_BY_ENTER_OR_TAB // Apply widget value change by enter/tab event. connect(myYSpin, SIGNAL(editingFinished()), this, SLOT(onValuesChanged())); + connect(myYSpin, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesModified())); #else connect(myYSpin, SIGNAL(valueChanged(const QString&)), this, SLOT(onValuesChanged())); #endif @@ -473,3 +475,8 @@ void PartSet_WidgetPoint2D::onValuesChanged() myLockApplyMgr->valuesChanged(); emit valuesChanged(); } + +bool PartSet_WidgetPoint2D::isEventProcessed(QKeyEvent* theEvent) +{ + return myXSpin->isEventProcessed(theEvent) || myXSpin->isEventProcessed(theEvent); +} diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 88ae9ac2e..93921a544 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -87,6 +87,9 @@ Q_OBJECT /// Returns coordinate Y currently defined in the control double y() const; + /// Returns true if the event is processed. + virtual bool isEventProcessed(QKeyEvent* theEvent); + signals: /// Signal about selection of an existing vertex from an object void vertexSelected(); diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index a644d55cc..15061b90c 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -23,7 +23,7 @@ #include -//#define APPLY_BY_ENTER_OR_TAB +#define APPLY_BY_ENTER_OR_TAB PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, @@ -40,6 +40,7 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, // Apply widget value change by enter/tab event. disconnect(mySpinBox, SIGNAL(editingFinished()), this, SIGNAL(valuesChanged())); connect(mySpinBox, SIGNAL(editingFinished()), this, SLOT(onValuesChanged())); + connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesModified())); #else disconnect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); connect(mySpinBox, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); @@ -139,3 +140,7 @@ void PartSet_WidgetPoint2dDistance::onValuesChanged() emit valuesChanged(); } +bool PartSet_WidgetPoint2dDistance::isEventProcessed(QKeyEvent* theEvent) +{ + return mySpinBox->isEventProcessed(theEvent); +} diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.h b/src/PartSet/PartSet_WidgetPoint2dDistance.h index f300f2fb8..7dc45bcca 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.h +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.h @@ -59,6 +59,9 @@ Q_OBJECT /// Set sketch instance void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; } + /// Returns true if the event is processed. + virtual bool isEventProcessed(QKeyEvent* theEvent); + public slots: /// Process of mouse move /// \param theWnd a pointer to a window diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 92db97689..a64083ae5 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -498,16 +498,34 @@ void XGUI_OperationMgr::onOperationStopped() } } +#include +#include bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent) { + qDebug("XGUI_OperationMgr::onKeyReleased"); + QObject* aSender = sender(); + // Let the manager decide what to do with the given key combination. ModuleBase_Operation* anOperation = currentOperation(); bool isAccepted = true; switch (theEvent->key()) { case Qt::Key_Return: case Qt::Key_Enter: { - emit keyEnterReleased(); - commitOperation(); + ModuleBase_Operation* aOperation = currentOperation(); + ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); + ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget(); + if (aActiveWgt && !aActiveWgt->isEventProcessed(theEvent)) { + qDebug("XGUI_OperationMgr::onKeyReleased accept Enter"); + ModuleBase_OperationFeature* aFOperation = dynamic_cast(currentOperation()); + if (!aFOperation || myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) { + emit keyEnterReleased(); + commitOperation(); + } + else + isAccepted = false; + } + //else + // isAccepted = false; } case Qt::Key_N: case Qt::Key_P: { -- 2.39.2