From: vsv Date: Mon, 15 Dec 2014 16:08:29 +0000 (+0300) Subject: Issue #252: Make Ok button non accessible while cursor of mouse within 3d viewer... X-Git-Tag: before_slalome_7.5.1~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2d7d83dc1d1a31a8bf6952b1fc6e11b681551cfb;p=modules%2Fshaper.git Issue #252: Make Ok button non accessible while cursor of mouse within 3d viewer. Only for sketcher operations. --- diff --git a/src/ModuleBase/ModuleBase_IPropertyPanel.h b/src/ModuleBase/ModuleBase_IPropertyPanel.h index a5bc8defa..fdac20d13 100644 --- a/src/ModuleBase/ModuleBase_IPropertyPanel.h +++ b/src/ModuleBase/ModuleBase_IPropertyPanel.h @@ -33,6 +33,18 @@ public: void setEditingMode(bool isEditing) { myIsEditing = isEditing; } bool isEditingMode() const { return myIsEditing; } + /// Set Enable/Disable state of Ok button + virtual void setOkEnabled(bool theEnabled) = 0; + + /// Returns state of Ok button + virtual bool isOkEnabled() const = 0; + + /// Set Enable/Disable state of Ok button + virtual void setCancelEnabled(bool theEnabled) = 0; + + /// Returns state of Ok button + virtual bool isCancelEnabled() const = 0; + signals: /// The signal about key release on the control, that corresponds to the attribute /// \param theEvent key release event diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index d3f73af25..5f0fc5750 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -68,7 +70,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, myXSpin->setToolTip("X"); aGroupLay->addWidget(myXSpin, 0, 1); - connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); + connect(myXSpin, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); } { QLabel* aLabel = new QLabel(myGroupBox); @@ -82,7 +84,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, myYSpin->setToolTip("X"); aGroupLay->addWidget(myYSpin, 1, 1); - connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); + connect(myYSpin, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); } } @@ -107,8 +109,13 @@ void PartSet_WidgetPoint2D::setPoint(double theX, double theY) { bool isBlocked = this->blockSignals(true); + myXSpin->blockSignals(true); myXSpin->setValue(theX); + myXSpin->blockSignals(false); + + myYSpin->blockSignals(true); myYSpin->setValue(theY); + myYSpin->blockSignals(false); this->blockSignals(isBlocked); emit valuesChanged(); @@ -148,8 +155,13 @@ bool PartSet_WidgetPoint2D::restoreValue() double _Y = aPoint->y(); #endif bool isBlocked = this->blockSignals(true); + myXSpin->blockSignals(true); myXSpin->setValue(aPoint->x()); + myXSpin->blockSignals(false); + + myYSpin->blockSignals(true); myYSpin->setValue(aPoint->y()); + myYSpin->blockSignals(false); this->blockSignals(isBlocked); return true; } @@ -167,25 +179,6 @@ QList PartSet_WidgetPoint2D::getControls() const return aControls; } -//bool PartSet_WidgetPoint2D::initFromPrevious(ObjectPtr theObject) -//{ -// if (myOptionParam.length() == 0) -// return false; -// std::shared_ptr aData = theObject->data(); -// std::shared_ptr aPoint = std::dynamic_pointer_cast( -// aData->attribute(myOptionParam)); -// if (aPoint) { -// bool isBlocked = this->blockSignals(true); -// myXSpin->setValue(aPoint->x()); -// myYSpin->setValue(aPoint->y()); -// this->blockSignals(isBlocked); -// -// emit valuesChanged(); -// emit storedPoint2D(theObject, myOptionParam); -// return true; -// } -// return false; -//} void PartSet_WidgetPoint2D::activate() { @@ -259,6 +252,9 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { + myWorkshop->operationMgr()->setLockValidating(true); + myWorkshop->propertyPanel()->setOkEnabled(false); + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); double aX, anY; @@ -276,3 +272,8 @@ double PartSet_WidgetPoint2D::y() const return myYSpin->value(); } +void PartSet_WidgetPoint2D::onValuesChanged() +{ + myWorkshop->operationMgr()->setLockValidating(false); + emit valuesChanged(); +} diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 809ad91f9..69e6461ea 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -98,6 +98,9 @@ protected slots: void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); +private slots: + void onValuesChanged(); + private: bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape, double& theX, double& theY) const; diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index 2e722d028..9e4826780 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -12,6 +12,8 @@ #include #include +#include +#include #include #include @@ -28,32 +30,16 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId) { myFirstPntName = theData->getProperty("first_point"); + + // Reconnect to local slot + disconnect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); + connect(mySpinBox, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); } PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance() { } -//bool PartSet_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue) -//{ -// bool isDone = false; -// -// if (theValue) { -// ModuleBase_WidgetValueFeature* aFeatureValue = -// dynamic_cast(theValue); -// if (aFeatureValue) { -// std::shared_ptr aPnt = aFeatureValue->point(); -// ObjectPtr aObject = aFeatureValue->object(); -// FeaturePtr aFeature = std::dynamic_pointer_cast(aObject); -// if (aFeature && aPnt) { -// setPoint(aFeature, aPnt); -// isDone = true; -// } -// } -// } -// return isDone; -//} - void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const std::shared_ptr& thePnt) { @@ -67,7 +53,10 @@ void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, AttributeDoublePtr aReal = aData->real(attributeID()); if (aReal && (aReal->value() != aRadius)) { aReal->setValue(aRadius); + mySpinBox->blockSignals(true); mySpinBox->setValue(aRadius); + mySpinBox->blockSignals(false); + emit valuesChanged(); } } @@ -103,6 +92,9 @@ void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWn void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { + myWorkshop->operationMgr()->setLockValidating(true); + myWorkshop->propertyPanel()->setOkEnabled(false); + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); double aX, aY; @@ -112,4 +104,9 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, setPoint(feature(), aPnt); } +void PartSet_WidgetPoint2dDistance::onValuesChanged() +{ + myWorkshop->operationMgr()->setLockValidating(false); + emit valuesChanged(); +} diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.h b/src/PartSet/PartSet_WidgetPoint2dDistance.h index a03a78494..ca95b75fd 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.h +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.h @@ -56,6 +56,9 @@ protected: /// Set the second point which defines a value in the widget as a distance with a first point defined by feature void setPoint(FeaturePtr theFeature, const std::shared_ptr& thePnt); +private slots: + void onValuesChanged(); + private: XGUI_Workshop* myWorkshop; std::string myFirstPntName; diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index a46365d9f..a8f68277b 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -13,7 +13,7 @@ #include XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent) - : QObject(theParent) + : QObject(theParent), myIsValidationLock(false) { } @@ -139,7 +139,7 @@ void XGUI_OperationMgr::onValidateOperation() if (!hasOperation()) return; ModuleBase_Operation* anOperation = currentOperation(); - if(anOperation) { + if(anOperation && (!myIsValidationLock)) { bool isValid = anOperation->isValid(); emit operationValidated(isValid); } diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index c80553285..1cf7dcefc 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -82,6 +82,13 @@ Q_OBJECT /// Returns true if the operation can be aborted bool canAbortOperation(); + /// Blocking/unblocking enabling of Ok button in property panel. + /// It is used when operation can not be validated even all attributes are valid + void setLockValidating(bool toLock) { myIsValidationLock = toLock; } + + /// Returns state of validation locking + bool isValidationLocked() const { return myIsValidationLock; } + public slots: /// Slot that commits the current operation. void onCommitOperation(); @@ -146,6 +153,9 @@ signals: typedef QList Operations; ///< definition for a list of operations Operations myOperations; ///< a stack of started operations. The active operation is on top, // others are suspended and started by the active is finished + + /// Lock/Unlock access to Ok button in property panel + bool myIsValidationLock; }; #endif diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 8a3cf8bf1..c3d200d41 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -221,3 +221,29 @@ void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget) else if (!isEditingMode()) emit noMoreWidgets(); } + +void XGUI_PropertyPanel::setOkEnabled(bool theEnabled) +{ + QPushButton* anOkBtn = findChild(PROP_PANEL_OK); + anOkBtn->setEnabled(theEnabled); +} + +bool XGUI_PropertyPanel::isOkEnabled() const +{ + QPushButton* anOkBtn = findChild(PROP_PANEL_OK); + return anOkBtn->isEnabled(); +} + +void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled) +{ + QPushButton* anCancelBtn = findChild(PROP_PANEL_CANCEL); + anCancelBtn->setEnabled(theEnabled); +} + +bool XGUI_PropertyPanel::isCancelEnabled() const +{ + QPushButton* anCancelBtn = findChild(PROP_PANEL_CANCEL); + return anCancelBtn->isEnabled(); +} + + diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index 70afb7e7f..071779431 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -59,6 +59,18 @@ Q_OBJECT void setStretchEnabled(bool isEnabled); + /// Set Enable/Disable state of Ok button + virtual void setOkEnabled(bool theEnabled); + + /// Returns state of Ok button + virtual bool isOkEnabled() const; + + /// Set Enable/Disable state of Ok button + virtual void setCancelEnabled(bool theEnabled); + + /// Returns state of Ok button + virtual bool isCancelEnabled() const; + public slots: void updateContentWidget(FeaturePtr theFeature); // Enables / disables "ok" ("accept") button diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 79491af82..0157532e7 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1229,15 +1229,12 @@ void XGUI_Workshop::onWidgetValuesChanged() FeaturePtr aFeature = anOperation->feature(); ModuleBase_ModelWidget* aSenderWidget = dynamic_cast(sender()); - //if (aCustom) - // aCustom->storeValue(aFeature); const QList& aWidgets = myPropertyPanel->modelWidgets(); QList::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end(); for (; anIt != aLast; anIt++) { ModuleBase_ModelWidget* aCustom = *anIt; - if (aCustom && (/*!aCustom->isInitialized(aFeature) ||*/aCustom == aSenderWidget)) { - //aCustom->storeValue(aFeature); + if (aCustom && (aCustom == aSenderWidget)) { aCustom->storeValue(); } }