From 9f1d5e2c89ba45d2ba3d098ca8ea020bd3310488 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 25 Aug 2015 16:32:16 +0300 Subject: [PATCH] Synchronize AcceptAll actions state between Tool bar and property panel. In the new realized version, this button state is updated by commit modification to the document and when the operation is started. In the previous version this state was updated by any modification of the model during operaion. --- src/Config/Config_Keywords.h | 2 ++ src/NewGeom/NewGeom_Module.cpp | 4 ++++ src/NewGeom/NewGeom_Module.h | 6 ++++++ src/NewGeom/NewGeom_NestedButton.h | 2 +- src/XGUI/XGUI_ActionsMgr.cpp | 9 +++++++++ src/XGUI/XGUI_ActionsMgr.h | 5 ++++- src/XGUI/XGUI_OperationMgr.cpp | 18 ++++++++++++++++-- src/XGUI/XGUI_OperationMgr.h | 10 ++++++++-- src/XGUI/XGUI_SalomeConnector.h | 6 ++++++ src/XGUI/XGUI_Workshop.cpp | 4 ---- src/XGUI/XGUI_WorkshopListener.cpp | 27 +++++++++++++++++++++++++-- src/XGUI/XGUI_WorkshopListener.h | 6 ++++++ 12 files changed, 87 insertions(+), 12 deletions(-) diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index b9ee0b4a0..bf10876bf 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -55,6 +55,8 @@ const static char* FEATURE_TEXT = "title"; const static char* FEATURE_KEYSEQUENCE = "keysequence"; const static char* FEATURE_NESTED = "nested"; const static char* FEATURE_WHEN_NESTED = "when_nested"; +const static char* FEATURE_WHEN_NESTED_ACCEPT = "accept"; +const static char* FEATURE_WHEN_NESTED_ABORT = "abort"; const static char* FEATURE_DOC = WORKBENCH_DOC; // NODE_VALIDATOR properties, NODE_SELFILTER properties const static char* _PARAMETERS = "parameters"; diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index cb422b659..df5088628 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -398,6 +398,10 @@ QAction* NewGeom_Module::addFeature(const QString& theWBName, const QString& the return aAction; } +bool NewGeom_Module::isNestedFeature(const QAction* theAction) +{ + return dynamic_cast(theAction); +} QAction* NewGeom_Module::addNestedFeature(const QString& theWBName, const ActionInfo& theInfo, diff --git a/src/NewGeom/NewGeom_Module.h b/src/NewGeom/NewGeom_Module.h index 7c0aa1a6e..0ba1345b7 100644 --- a/src/NewGeom/NewGeom_Module.h +++ b/src/NewGeom/NewGeom_Module.h @@ -61,6 +61,12 @@ Q_OBJECT const ActionInfo& theInfo, const QList& theNestedActions); + //! Returns true if the feature action is a nested action, in other words, + //! it is created by addNestedFeature(). + //! \param theId - an action of a feature + //! returns boolean result + virtual bool isNestedFeature(const QAction* theAction); + virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle, const QString& theTip, const QIcon& theIcon, const QKeySequence& theKeys, bool isCheckable, diff --git a/src/NewGeom/NewGeom_NestedButton.h b/src/NewGeom/NewGeom_NestedButton.h index 7be12d491..bc39376c4 100644 --- a/src/NewGeom/NewGeom_NestedButton.h +++ b/src/NewGeom/NewGeom_NestedButton.h @@ -26,7 +26,7 @@ class NewGeom_NestedButton : public QWidgetAction NewGeom_NestedButton(QObject *parent, const QList& theNestedActions); virtual ~NewGeom_NestedButton(); - public slots: + private slots: /// Shows/hides the additional buttons widget void showAdditionalButtons(bool); void actionStateChanged(); diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp index 6dc01fa3d..8cf0c02c1 100644 --- a/src/XGUI/XGUI_ActionsMgr.cpp +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -260,6 +260,15 @@ QAction* XGUI_ActionsMgr::operationStateAction(OperationStateActionId theId, QOb return aResult; } +QAction* XGUI_ActionsMgr::action(const QString& theId) +{ + QAction* anAction; + if(myActions.contains(theId)) { + anAction = myActions.value(theId); + } + return anAction; +} + ActionInfo XGUI_ActionsMgr::actionInfoById(const QString& theId) { ActionInfo aResult; diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h index 0acc6a26a..9191021ad 100644 --- a/src/XGUI/XGUI_ActionsMgr.h +++ b/src/XGUI/XGUI_ActionsMgr.h @@ -80,10 +80,13 @@ class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener //! If there is no such action, it will be created. QAction* operationStateAction(OperationStateActionId theId, QObject* theParent = 0); + /// Return an action by the given id, if it was registered in the manager + QAction* action(const QString& theId); + /// Return info (icon, text, etc) about the action by the given id, if it was registered in the manager ActionInfo actionInfoById(const QString& theId); - public slots: +public slots: //! Update workbench actions according to OperationMgr state: //! No active operations: all actions but nested are available //! There is active operation: current operation + it's nested diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 3bab1779f..fe2b72830 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -9,6 +9,7 @@ #include "ModuleBase_Operation.h" #include "ModuleBase_IWorkshop.h" #include "ModuleBase_IModule.h" +#include "ModuleBase_OperationDescription.h" #include "ModelAPI_CompositeFeature.h" #include "ModelAPI_Session.h" @@ -188,9 +189,19 @@ void XGUI_OperationMgr::setApplyEnabled(const bool theEnabled) { myIsApplyEnabled = theEnabled; emit validationStateChanged(theEnabled); +} - bool aParentValid = true;//isParentOperationValid(); - emit nestedStateChanged(aParentValid); +void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation) +{ + if (theOperation) + emit nestedStateChanged(theOperation->getDescription()->operationId().toStdString(), + theOperation->isValid()); + else { + foreach(ModuleBase_Operation* anOperation, myOperations) { + emit nestedStateChanged(anOperation->getDescription()->operationId().toStdString(), + anOperation->isValid()); + } + } } bool XGUI_OperationMgr::isApplyEnabled() const @@ -301,6 +312,7 @@ void XGUI_OperationMgr::onAbortOperation() void XGUI_OperationMgr::onOperationStarted() { ModuleBase_Operation* aSenderOperation = dynamic_cast(sender()); + updateApplyOfOperations(aSenderOperation); emit operationStarted(aSenderOperation); } @@ -312,6 +324,8 @@ void XGUI_OperationMgr::onOperationAborted() void XGUI_OperationMgr::onOperationCommitted() { + updateApplyOfOperations(); + ModuleBase_Operation* aSenderOperation = dynamic_cast(sender()); emit operationCommitted(aSenderOperation); } diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index 582dc4ce4..7f6e26b93 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -138,8 +138,10 @@ signals: /// Signal is emitted after the apply enable state changed. void validationStateChanged(bool); - /// Signal is emitted after the apply enable state changed. - void nestedStateChanged(bool); + /// Signal is emitted after the model is modified. It is emitted for all active operations. + /// \param theFeatureKind a feature id + /// \param theState validity of the operation with the feature kind + void nestedStateChanged(const std::string& theFeatureKind, const bool theState); /// Signal is emitted after the current operation is filled with existing preselection. void operationActivatedByPreselection(); @@ -152,6 +154,10 @@ signals: /// \param theEnabled the state value void setApplyEnabled(const bool theEnabled); + /// 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. + void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0); + /// Commits the current operatin if it is valid bool commitOperation(); diff --git a/src/XGUI/XGUI_SalomeConnector.h b/src/XGUI/XGUI_SalomeConnector.h index 742a6055b..910aaa249 100644 --- a/src/XGUI/XGUI_SalomeConnector.h +++ b/src/XGUI/XGUI_SalomeConnector.h @@ -52,6 +52,12 @@ class XGUI_EXPORT XGUI_SalomeConnector const ActionInfo& theInfo, const QList& theNestedActions) = 0; + //! Returns true if the feature action is a nested action, in other words, + //! it is created by addNestedFeature(). + //! \param theId - an action of a feature + //! returns boolean result + virtual bool isNestedFeature(const QAction* theAction) = 0; + //! Creates a command in Edit menu of SALOME desktop //! \param theId - an id of the feature //! \param theTitle - a menu item string diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 82fb45c18..e08bae76c 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -906,10 +906,6 @@ void XGUI_Workshop::createDockWidgets() myOperationMgr, SLOT(onKeyReleased(QKeyEvent*))); connect(myOperationMgr, SIGNAL(validationStateChanged(bool)), aOkAct, SLOT(setEnabled(bool))); - QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll); - connect(myOperationMgr, SIGNAL(nestedStateChanged(bool)), - aAcceptAllAct, SLOT(setEnabled(bool))); - } //****************************************************** diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index 2e22c49ed..b55879fae 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -355,6 +356,25 @@ void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptractionsMgr()->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL); + if (aWorkshop->isSalomeMode()) { + XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector(); + XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr(); + if (aSalomeConnector->isNestedFeature(anActionsMgr->action(theFeatureId.c_str()))) + anAcceptAllAction->setEnabled(theState); + } else { + AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject(); + if (aMenuBar->feature(theFeatureId.c_str())->button()->additionalButtonWidget()) + anAcceptAllAction->setEnabled(theState); + } +} + bool XGUI_WorkshopListener::event(QEvent * theEvent) { PostponeMessageQtEvent* aPostponedEv = dynamic_cast(theEvent); @@ -389,12 +409,12 @@ void XGUI_WorkshopListener::addFeature(const std::shared_ptractionsWhenNested()); XGUI_OperationMgr* anOperationMgr = aWorkshop->operationMgr(); XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr(); - if (aNestedActions.contains("accept")) { + if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) { QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL); connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations())); aNestedActList << anAction; } - if (aNestedActions.contains("abort")) { + if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) { QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL); connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations())); aNestedActList << anAction; @@ -447,6 +467,9 @@ void XGUI_WorkshopListener::addFeature(const std::shared_ptractionsMgr()->addCommand(aCommand); aWorkshop->module()->actionCreated(aCommand); } + XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr(); + connect(anOperationMgr, SIGNAL(nestedStateChanged(const std::string&, const bool)), + this, SLOT(onNestedStateChanged(const std::string&, const bool))); } diff --git a/src/XGUI/XGUI_WorkshopListener.h b/src/XGUI/XGUI_WorkshopListener.h index 71d0a9985..912fb85df 100755 --- a/src/XGUI/XGUI_WorkshopListener.h +++ b/src/XGUI/XGUI_WorkshopListener.h @@ -44,6 +44,12 @@ signals: /// Emitted when error in applivation happens void errorOccurred(const QString&); +protected slots: + /// Updates Apply All button state of the feature to the state if the feature has the button + /// \param theFeatureId an index of the feature, the action is searched, which state is to be changed + /// \param theState an action enable state + void onNestedStateChanged(const std::string& theFeatureId, const bool theState); + protected: /// Procedure to process postponed events bool event(QEvent * theEvent); -- 2.39.2