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.
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";
return aAction;
}
+bool NewGeom_Module::isNestedFeature(const QAction* theAction)
+{
+ return dynamic_cast<const NewGeom_NestedButton*>(theAction);
+}
QAction* NewGeom_Module::addNestedFeature(const QString& theWBName,
const ActionInfo& theInfo,
const ActionInfo& theInfo,
const QList<QAction*>& 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,
NewGeom_NestedButton(QObject *parent, const QList<QAction*>& theNestedActions);
virtual ~NewGeom_NestedButton();
- public slots:
+ private slots:
/// Shows/hides the additional buttons widget
void showAdditionalButtons(bool);
void actionStateChanged();
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;
//! 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
#include "ModuleBase_Operation.h"
#include "ModuleBase_IWorkshop.h"
#include "ModuleBase_IModule.h"
+#include "ModuleBase_OperationDescription.h"
#include "ModelAPI_CompositeFeature.h"
#include "ModelAPI_Session.h"
{
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
void XGUI_OperationMgr::onOperationStarted()
{
ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
+ updateApplyOfOperations(aSenderOperation);
emit operationStarted(aSenderOperation);
}
void XGUI_OperationMgr::onOperationCommitted()
{
+ updateApplyOfOperations();
+
ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
emit operationCommitted(aSenderOperation);
}
/// 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();
/// \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();
const ActionInfo& theInfo,
const QList<QAction*>& 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
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)));
-
}
//******************************************************
#include <Config_FeatureMessage.h>
#include <Config_PointerMessage.h>
#include <Config_SelectionFilterMessage.h>
+#include <Config_Keywords.h>
#include <QApplication>
#include <QMainWindow>
//}
}
+void XGUI_WorkshopListener::onNestedStateChanged(const std::string& theFeatureId, const bool theState)
+{
+ XGUI_Workshop* aWorkshop = workshop();
+
+ //one button is used for all features, which can have nested actions, so it is obtained from
+ // the action manager
+ QAction* anAcceptAllAction = aWorkshop->actionsMgr()->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<PostponeMessageQtEvent*>(theEvent);
QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
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;
aWorkshop->actionsMgr()->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)));
}
/// 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);