From: sbh Date: Mon, 28 Apr 2014 14:43:37 +0000 (+0400) Subject: Issue #6 advanced command enable/disable state processing X-Git-Tag: V_0.2~113 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d80699ac131d75798c6c39deff2c5e820aface5f;p=modules%2Fshaper.git Issue #6 advanced command enable/disable state processing --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index c91631f06..58a0a9450 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -63,6 +63,11 @@ void PartSet_Module::featureCreated(XGUI_Command* theFeature) theFeature->connectTo(this, SLOT(onFeatureTriggered())); } +QStringList PartSet_Module::nestedFeatures(QString) +{ + return QStringList(); +} + std::string PartSet_Module::featureFile(const std::string& theFeatureId) { return myFeaturesInFiles[theFeatureId]; @@ -74,6 +79,9 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId) void PartSet_Module::onFeatureTriggered() { XGUI_Command* aCmd = dynamic_cast(sender()); + //Do nothing on uncheck + if(aCmd->isCheckable() && !aCmd->isChecked()) + return; launchOperation(aCmd->id()); } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 523a15ad2..cb86b7c4e 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -21,6 +21,7 @@ public: virtual void createFeatures(); virtual void featureCreated(XGUI_Command* theFeature); + virtual QStringList nestedFeatures(QString theFeature); std::string featureFile(const std::string&); virtual void launchOperation(const QString& theCmdId); diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 460458d1a..989980d3b 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -26,6 +26,7 @@ SET(PROJECT_HEADERS XGUI_DataTreeModel.h XGUI_SelectionMgr.h XGUI_SalomeConnector.h + XGUI_ActionsMgr.h ) SET(PROJECT_AUTOMOC @@ -51,6 +52,7 @@ SET(PROJECT_SOURCES XGUI_ObjectsBrowser.cpp XGUI_OperationMgr.cpp XGUI_SelectionMgr.cpp + XGUI_ActionsMgr.cpp ) SET(PROJECT_RESOURCES diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp new file mode 100644 index 000000000..0d652dceb --- /dev/null +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -0,0 +1,67 @@ +/* + * XGUI_ActionsMgr.cpp + */ + +#include +#include +#include + + +XGUI_ActionsMgr::XGUI_ActionsMgr(QObject* theParent) + : QObject(theParent) +{ + +} + +XGUI_ActionsMgr::~XGUI_ActionsMgr() +{ +} + + +void XGUI_ActionsMgr::addCommand(XGUI_Command* theCmd) +{ + myActions.insert(theCmd->id(),theCmd); + myActionsState.insert(theCmd->id(), theCmd->enabled()); + theCmd->connectTo(this, SLOT(setActionsDisabled(bool))); +} + +void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled) +{ + //Re-enable actions (just restore their state) + if (!isDisabled) { + restoreCommandState(); + return; + } + //Disable all actions, but caller and unblockable (defined in a xml) + saveCommandsState(); + QStringList aSkippedIds; + XGUI_Command* aToggledFeature = dynamic_cast(sender()); + aSkippedIds.append(aToggledFeature->unblockableCommands()); + aSkippedIds.append(aToggledFeature->id()); + QStringList anActionIdsList = myActions.keys(); + foreach(QString eachKey, anActionIdsList) { + if (aSkippedIds.removeAll(eachKey) > 0) { + continue; + } + myActions[eachKey]->setEnabled(false); + } +} + +void XGUI_ActionsMgr::saveCommandsState() +{ + myActionsState.clear(); + QStringList anActionIdsList = myActions.keys(); + foreach(QString eachKey, anActionIdsList) { + myActionsState.insert(eachKey, myActions[eachKey]->isEnabled()); + } + +} + +void XGUI_ActionsMgr::restoreCommandState() +{ + QStringList anActionIdsList = myActions.keys(); + foreach(QString eachKey, anActionIdsList) { + myActions[eachKey]->setEnabled(myActionsState[eachKey]); + myActions[eachKey]->setChecked(false); + } +} diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h new file mode 100644 index 000000000..a3d7dea19 --- /dev/null +++ b/src/XGUI/XGUI_ActionsMgr.h @@ -0,0 +1,35 @@ +/* + * XGUI_ActionsMgr.h + */ + +#ifndef XGUI_ACTIONSMGR_H_ +#define XGUI_ACTIONSMGR_H_ + +#include +#include +#include + +class XGUI_Command; +class QAction; + +class XGUI_ActionsMgr: public QObject +{ + Q_OBJECT + +public: + XGUI_ActionsMgr(QObject* theParent); + virtual ~XGUI_ActionsMgr(); + + void addCommand(XGUI_Command* theCmd); + void restoreCommandState(); + void saveCommandsState(); + +public slots: + void setActionsDisabled(bool isEnabled); + +private: + QMap myActions; + QMap myActionsState; +}; + +#endif /* XGUI_ACTIONSMGR_H_ */ diff --git a/src/XGUI/XGUI_Command.cpp b/src/XGUI/XGUI_Command.cpp index ffd6ab103..9b5dd7b9a 100644 --- a/src/XGUI/XGUI_Command.cpp +++ b/src/XGUI/XGUI_Command.cpp @@ -63,7 +63,7 @@ void XGUI_Command::disable() void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot) { - connect(this, SIGNAL(triggered()), theResiver, theSlot); + connect(this, SIGNAL(triggered(bool)), theResiver, theSlot); } const QStringList& XGUI_Command::unblockableCommands() const diff --git a/src/XGUI/XGUI_MainMenu.cpp b/src/XGUI/XGUI_MainMenu.cpp index 96106a911..4c8e7dc3c 100644 --- a/src/XGUI/XGUI_MainMenu.cpp +++ b/src/XGUI/XGUI_MainMenu.cpp @@ -91,48 +91,3 @@ QList XGUI_MainMenu::features() const return aList; } -void XGUI_MainMenu::onFeatureChecked(bool isChecked) -{ - if (!isChecked) { - restoreCommandState(); - return; - } - - saveCommandsState(); - QStringList aSkippedIds; - XGUI_Command* aToggledFeature = dynamic_cast(sender()); - aSkippedIds.append(aToggledFeature->unblockableCommands()); -// aSkippedIds.append(aToggledFeature->id()); - XGUI_Workbench* aGeneralWB = findWorkbench(tr("General")); - foreach(XGUI_Command* eachFeature, aGeneralWB->features()) { - aSkippedIds.append(eachFeature->id()); - } - QList allFeatures = features(); - foreach(XGUI_Command* eachFeature, allFeatures) { - QString aFeatureId = eachFeature->id(); - if (aSkippedIds.removeAll(aFeatureId) > 0) { - continue; - } - eachFeature->setEnabled(false); - } -} - -void XGUI_MainMenu::saveCommandsState() -{ - myCommandState.clear(); - QList allFeatures = features(); - XGUI_Command* eachFeature = NULL; - foreach(eachFeature, allFeatures) { - myCommandState.insert(eachFeature, eachFeature->enabled()); - } -} - -void XGUI_MainMenu::restoreCommandState() -{ - QList allFeatures = features(); - XGUI_Command* eachFeature = NULL; - foreach(eachFeature, allFeatures) { - eachFeature->setChecked(false); - eachFeature->setEnabled(myCommandState[eachFeature]); - } -} diff --git a/src/XGUI/XGUI_MainMenu.h b/src/XGUI/XGUI_MainMenu.h index 0fed1a07f..48d974591 100644 --- a/src/XGUI/XGUI_MainMenu.h +++ b/src/XGUI/XGUI_MainMenu.h @@ -47,12 +47,6 @@ public: //! Returns list of created commands QList features() const; -public slots: - void onFeatureChecked(bool); - - void saveCommandsState(); - void restoreCommandState(); - virtual bool eventFilter(QObject *theWatched, QEvent *theEvent); private: diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index 553aa2735..17357858d 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -6,6 +6,7 @@ class XGUI_MainMenu; class XGUI_Viewer; +class XGUI_ActionsMgr; class QMdiArea; class PyConsole_EnhConsole; @@ -43,7 +44,6 @@ public slots: private: XGUI_MainMenu* myMenuBar; - XGUI_Viewer* myViewer; PyConsole_EnhConsole* myPythonConsole; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index b453a3ec9..127949282 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -14,6 +14,7 @@ #include "XGUI_Displayer.h" #include "XGUI_OperationMgr.h" #include "XGUI_SalomeConnector.h" +#include "XGUI_ActionsMgr.h" #include #include @@ -60,6 +61,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) mySelector = new XGUI_SelectionMgr(this); myOperationMgr = new XGUI_OperationMgr(this); + myActionsMgr = new XGUI_ActionsMgr(this); connect(myOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted())); connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this, SLOT(onOperationStopped(ModuleBase_Operation*))); @@ -230,10 +232,9 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) hidePropertyPanel(); updateCommandStatus(); - if (myMainWindow) { - XGUI_MainMenu* aMenu = myMainWindow->menuObject(); - aMenu->restoreCommandState(); - } + if (myMainWindow) { + myActionsMgr->restoreCommandState(); + } } } @@ -277,9 +278,7 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) QString::fromStdString(theMessage->tooltip()), QIcon(theMessage->icon().c_str()), QKeySequence(), isUsePropPanel); - - connect(aCommand, SIGNAL(toggled(bool)), - myMainWindow->menuObject(), SLOT(onFeatureChecked(bool))); + myActionsMgr->addCommand(aCommand); myPartSetModule->featureCreated(aCommand); } } @@ -304,7 +303,7 @@ void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation) aCommand = aMenu->feature(theOperation->operationId()); } //Abort operation on uncheck the command - connect(aCommand, SIGNAL(toggled(bool)), theOperation, SLOT(setRunning(bool))); + connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool))); } //****************************************************** diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 937aca383..551f23c50 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -18,6 +18,7 @@ class XGUI_Displayer; class XGUI_OperationMgr; class XGUI_SalomeConnector; class XGUI_ObjectsBrowser; +class XGUI_ActionsMgr; class ModuleBase_Operation; class ModuleBase_PropPanelOperation; @@ -127,6 +128,8 @@ private: XGUI_Displayer* myDisplayer; XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations + XGUI_ActionsMgr* myActionsMgr; + XGUI_SalomeConnector* mySalomeConnector; };