From: nds Date: Tue, 15 Dec 2015 09:42:11 +0000 (+0300) Subject: #1112 tab key doesn't work on the last field of left panels X-Git-Tag: V_2.1.0~182 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=72c4913ec2fb7b25caf65d14eb1152f9625ab6ce;p=modules%2Fshaper.git #1112 tab key doesn't work on the last field of left panels Improvement: modification of the value in the property panel should make enabled the Apply button in the panel. The value is not applyed to the model yet, but click on Apply leads to the values apply. The button becomes disabled if the result is invalid feature. --- diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 4fa9775d6..9023cb2d2 100755 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -22,6 +22,29 @@ std::shared_ptr shape(const ResultPtr& theResult) return theResult->shape(); } +std::string getFeatureError(const FeaturePtr& theFeature) +{ + std::string anError; + if (!theFeature.get() || !theFeature->data()->isValid() || theFeature->isAction()) + return anError; + + // to be removed later, this error should be got from the feature + if (theFeature->data()->execState() == ModelAPI_StateDone || + theFeature->data()->execState() == ModelAPI_StateMustBeUpdated) + return anError; + + // set error indication + anError = theFeature->error(); + if (anError.empty()) { + bool isDone = ( theFeature->data()->execState() == ModelAPI_StateDone + || theFeature->data()->execState() == ModelAPI_StateMustBeUpdated ); + if (!isDone) + anError = theFeature->data()->execState(); + } + + return anError; +} + ObjectPtr objectByName(const DocumentPtr& theDocument, const std::string& theGroup, const std::string& theName) { for (int anIndex = 0; anIndex < theDocument->size(theGroup); ++anIndex) { diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index 9d544cbf8..0b3f965b7 100755 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -24,6 +24,12 @@ namespace ModelAPI_Tools { /// Returns shape from the given Result object MODELAPI_EXPORT std::shared_ptr shape(const ResultPtr& theResult); +/*! Returns the feature error generated according to feature error and exec state + * \param theFeature a feature + * \return error value or empty string + */ +MODELAPI_EXPORT std::string getFeatureError(const FeaturePtr& theFeature); + /*! * Searches for variable with name \param theName in \param theDocument. * If found, set it value in the \param outValue and returns true. diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index c73bf3c1c..2994da26d 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -8,7 +8,7 @@ #include "ModuleBase_ISelection.h" #include "ModuleBase_OperationDescription.h" #include "ModuleBase_OperationFeature.h" -#include +#include "ModuleBase_ModelWidget.h" #include @@ -16,6 +16,7 @@ #include #include #include +#include "ModelAPI_Tools.h" #include #include @@ -82,25 +83,7 @@ const char* toString(ModelAPI_ExecState theExecState) QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature) { - QString anError; - if (!theFeature.get() || !theFeature->data()->isValid() || theFeature->isAction()) - return anError; - - // to be removed later, this error should be got from the feature - if (theFeature->data()->execState() == ModelAPI_StateDone || - theFeature->data()->execState() == ModelAPI_StateMustBeUpdated) - return anError; - - // set error indication - anError = QString::fromStdString(theFeature->error()); - if (anError.isEmpty()) { - bool isDone = ( theFeature->data()->execState() == ModelAPI_StateDone - || theFeature->data()->execState() == ModelAPI_StateMustBeUpdated ); - if (!isDone) - anError = toString(theFeature->data()->execState()); - } - - return anError; + return ModelAPI_Tools::getFeatureError(theFeature).c_str(); } QString ModuleBase_IModule::getWidgetError(ModuleBase_ModelWidget* theWidget) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index d9c678185..504b8ca8f 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -64,10 +64,6 @@ QString ModuleBase_ModelWidget::getValueStateError() const if (anAttr.get()) { QString anAttributeName = anAttr->id().c_str(); switch (aState) { - case ModuleBase_ModelWidget::ModifiedInPP: - anError = "Attribute \"" + anAttributeName + - "\" modification is not applyed. Please click \"Enter\" or \"Tab\"."; - break; case ModuleBase_ModelWidget::ModifiedInViewer: anError = "Attribute \"" + anAttributeName + "\" is locked by modification value in the viewer."; @@ -75,6 +71,9 @@ QString ModuleBase_ModelWidget::getValueStateError() const case ModuleBase_ModelWidget::Reset: anError = "Attribute \"" + anAttributeName + "\" is not initialized."; break; + case ModuleBase_ModelWidget::ModifiedInPP: // Apply should be enabled in this mode + default: + break; } } } diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 25ccc5aa1..8194af412 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -16,6 +16,7 @@ #include +class ModuleBase_OperationFeature; class Config_WidgetAPI; class ModuleBase_IWorkshop; class QKeyEvent; @@ -301,6 +302,8 @@ private: bool myUseReset; /// blocked flag of modification of the value state bool myIsValueStateBlocked; + + friend ModuleBase_OperationFeature; // to call storeValue() by commit if value state is ModifiedInPP }; #endif diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index c8f1224b6..0471bfae7 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -86,17 +86,9 @@ bool ModuleBase_OperationFeature::isValid() const return true; // rename operation if (myFeature->isAction()) return true; - //Get validators for the Id - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - bool aValid = aFactory->validate(myFeature); - - // the feature exec state should be checked in order to do not apply features, which result can not - // be built. E.g. extrusion on sketch, where the "to" is a perpendicular plane to the sketch - bool isDone = ( myFeature->data()->execState() == ModelAPI_StateDone - || myFeature->data()->execState() == ModelAPI_StateMustBeUpdated ); - return aValid && isDone; + std::string anError = ModelAPI_Tools::getFeatureError(myFeature); + return anError.empty(); } void ModuleBase_OperationFeature::startOperation() @@ -268,6 +260,13 @@ void ModuleBase_OperationFeature::abort() bool ModuleBase_OperationFeature::commit() { + ModuleBase_IPropertyPanel* aPanel = propertyPanel(); + if (aPanel) { + ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); + if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) { + anActiveWidget->storeValue(); + } + } if (canBeCommitted()) { emit beforeCommitted(); // the widgets of property panel should not process any events come from data mode diff --git a/src/XGUI/XGUI_ErrorMgr.cpp b/src/XGUI/XGUI_ErrorMgr.cpp index afacb5d82..7156e296f 100644 --- a/src/XGUI/XGUI_ErrorMgr.cpp +++ b/src/XGUI/XGUI_ErrorMgr.cpp @@ -55,13 +55,20 @@ void XGUI_ErrorMgr::updateActions(const FeaturePtr& theFeature) (workshop()->operationMgr()->currentOperation()); if (aFOperation && aFOperation->feature() == theFeature) { QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept); - QString anError = myWorkshop->module()->getFeatureError(theFeature); - + ModuleBase_ModelWidget* anActiveWidget = activeWidget(); - QString aWidgetError = myWorkshop->module()->getWidgetError(anActiveWidget); - if (anError.isEmpty()) - anError = aWidgetError; - + bool isApplyEnabledByActiveWidget = false; + if (anActiveWidget) + isApplyEnabledByActiveWidget = anActiveWidget->getValueState() == + ModuleBase_ModelWidget::ModifiedInPP; + QString anError = ""; + QString aWidgetError = ""; + if (!isApplyEnabledByActiveWidget) { + anError = myWorkshop->module()->getFeatureError(theFeature); + aWidgetError = myWorkshop->module()->getWidgetError(anActiveWidget); + if (anError.isEmpty()) + anError = aWidgetError; + } updateActionState(anOkAction, anError); updateToolTip(anActiveWidget, aWidgetError); } @@ -82,6 +89,19 @@ void XGUI_ErrorMgr::updateAcceptAllAction(const FeaturePtr& theFeature) } } +bool XGUI_ErrorMgr::isApplyEnabled() const +{ + bool isEnabled = false; + XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr(); + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (workshop()->operationMgr()->currentOperation()); + if (aFOperation) { + QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept); + isEnabled = anOkAction && anOkAction->isEnabled(); + } + return isEnabled; +} + void XGUI_ErrorMgr::updateActionState(QAction* theAction, const QString& theError) { bool anEnabled = theError.isEmpty(); diff --git a/src/XGUI/XGUI_ErrorMgr.h b/src/XGUI/XGUI_ErrorMgr.h index 7970f6ec0..03d057c5b 100644 --- a/src/XGUI/XGUI_ErrorMgr.h +++ b/src/XGUI/XGUI_ErrorMgr.h @@ -44,6 +44,9 @@ public: /// \param theFeature a feature void updateAcceptAllAction(const FeaturePtr& theFeature); + /// Returns true if the apply is enabled for the current feature + bool isApplyEnabled() const; + protected slots: /// Reimplemented from ModuleBase_ErrorMgr::onWidgetChanged(). virtual void onWidgetChanged(); diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 5271d1836..b8bc93c95 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -30,7 +30,7 @@ XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop) -: QObject(theParent), myIsApplyEnabled(false), myWorkshop(theWorkshop) +: QObject(theParent), myWorkshop(theWorkshop) { } @@ -174,7 +174,7 @@ bool XGUI_OperationMgr::commitAllOperations() bool isCompositeCommitted = false; while (hasOperation()) { ModuleBase_Operation* anOperation = currentOperation(); - if (isApplyEnabled()) { + if (workshop()->errorMgr()->isApplyEnabled()) { onCommitOperation(); } else { abortOperation(anOperation); @@ -199,28 +199,8 @@ void XGUI_OperationMgr::onValidateOperation() return; ModuleBase_OperationFeature* aFOperation = dynamic_cast (currentOperation()); - if(aFOperation && aFOperation->feature().get()) { - QString anError = myWorkshop->module()->getFeatureError(aFOperation->feature()); - if (anError.isEmpty()) { - ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel(); - if (aPanel) { - ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); - if (anActiveWidget) - anError = myWorkshop->module()->getWidgetError(anActiveWidget); - } - } - setApplyEnabled(anError.isEmpty()); - } -} - -void XGUI_OperationMgr::setApplyEnabled(const bool theEnabled) -{ - myIsApplyEnabled = theEnabled; - ModuleBase_OperationFeature* aFOperation = dynamic_cast - (currentOperation()); - if (aFOperation) { + if(aFOperation && aFOperation->feature().get()) workshop()->errorMgr()->updateActions(aFOperation->feature()); - } } void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation) @@ -230,40 +210,13 @@ void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperati ModuleBase_OperationFeature* aFOperation = dynamic_cast(theOperation); if (aFOperation) anErrorMgr->updateAcceptAllAction(aFOperation->feature()); - //emit nestedStateChanged(theOperation->getDescription()->operationId().toStdString(), - // theOperation->isValid()); } else { foreach(ModuleBase_Operation* anOperation, myOperations) { if (anOperation) updateApplyOfOperations(anOperation); - //emit nestedStateChanged(anOperation->getDescription()->operationId().toStdString(), - // anOperation->isValid()); - } - } -} - -bool XGUI_OperationMgr::isApplyEnabled() const -{ - return myIsApplyEnabled; -} - -bool XGUI_OperationMgr::isParentOperationValid() const -{ - bool isValid = false; - // the enable state of the parent operation of the nested one is defined by the rules that - // firstly there are nested operations and secondly the parent operation is valid - ModuleBase_Operation* aPrevOp = 0; - Operations::const_iterator anIt = myOperations.end(); - if (anIt != myOperations.begin()) { // there are items in the operations list - --anIt; - aPrevOp = *anIt; // the last top operation, the operation which is started - if (anIt != myOperations.begin()) { // find the operation where the started operation is nested - --anIt; - aPrevOp = *anIt; } } - return aPrevOp && aPrevOp->isValid(); } bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation) @@ -344,7 +297,7 @@ bool XGUI_OperationMgr::canStartOperation(const QString& theId) else if (canStopOperation(aCurrentOp)) { // the started operation is granted in the parrent operation, // e.g. current - Line in Sketch, started Circle - if (myIsApplyEnabled && aCurrentOp->isModified()) + if (workshop()->errorMgr()->isApplyEnabled() && aCurrentOp->isModified()) aCurrentOp->commit(); else abortOperation(aCurrentOp); diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index d6172b894..e7e715128 100755 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -98,15 +98,6 @@ Q_OBJECT /// \param theOperation an aborted operation void abortOperation(ModuleBase_Operation* theOperation); - /// Returns enable apply state - /// \return theEnabled a boolean value - bool isApplyEnabled() const; - - /// Returns valid state of the parent operation. If the current operation is the last one - /// it returns the valid state of the operation - /// \return boolean value - bool isParentOperationValid() const; - public slots: /// Slot that commits the current operation. void onCommitOperation(); @@ -142,11 +133,6 @@ signals: /// Signal is emitted after the key released click. void keyEnterReleased(); - protected: - /// Sets apply state to the value and emit signal about this state is changed - /// \param theEnabled the state value - void setApplyEnabled(const bool theEnabled); - public: // TEMPORARY, it should be protected and be performed automatically /// Emits nestedStateChange for operations with an information about validity of the operation /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent. @@ -219,9 +205,6 @@ private: /// Current workshop ModuleBase_IWorkshop* myWorkshop; - - /// Lock/Unlock access to Ok button in property panel - bool myIsApplyEnabled; }; #endif diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index 8b658c997..5f4e082fc 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -74,8 +74,6 @@ XGUI_WorkshopListener::XGUI_WorkshopListener(ModuleBase_IWorkshop* theWorkshop) myUpdatePrefs(false) { XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr(); - //connect(anOperationMgr, SIGNAL(nestedStateChanged(const std::string&, const bool)), - // this, SLOT(onNestedStateChanged(const std::string&, const bool))); } //****************************************************** @@ -430,30 +428,6 @@ void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptrisFeatureOfNested(theFeatureId); - if (aWorkshop->isSalomeMode()) { - XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector(); - XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr(); - if (aSalomeConnector->isFeatureOfNested(anActionsMgr->action(theFeatureId.c_str()))) - aActionToBeUpdated = true; - } else { - AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject(); - AppElements_Command* aCommand = aMenuBar->feature(theFeatureId.c_str()); - if (aCommand && aCommand->button()->additionalButtonWidget()) - aActionToBeUpdated = true; - } - if (aActionToBeUpdated) { - QAction* anAcceptAllAction = aWorkshop->actionsMgr()->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL); - anAcceptAllAction->setEnabled(theState); - } -}*/ - bool XGUI_WorkshopListener::event(QEvent * theEvent) { PostponeMessageQtEvent* aPostponedEv = dynamic_cast(theEvent);