theFeature->connectTo(this, SLOT(onFeatureTriggered()));
}
+QStringList PartSet_Module::nestedFeatures(QString)
+{
+ return QStringList();
+}
+
std::string PartSet_Module::featureFile(const std::string& theFeatureId)
{
return myFeaturesInFiles[theFeatureId];
void PartSet_Module::onFeatureTriggered()
{
XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
+ //Do nothing on uncheck
+ if(aCmd->isCheckable() && !aCmd->isChecked())
+ return;
launchOperation(aCmd->id());
}
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);
XGUI_DataTreeModel.h
XGUI_SelectionMgr.h
XGUI_SalomeConnector.h
+ XGUI_ActionsMgr.h
)
SET(PROJECT_AUTOMOC
XGUI_ObjectsBrowser.cpp
XGUI_OperationMgr.cpp
XGUI_SelectionMgr.cpp
+ XGUI_ActionsMgr.cpp
)
SET(PROJECT_RESOURCES
--- /dev/null
+/*
+ * XGUI_ActionsMgr.cpp
+ */
+
+#include <XGUI_ActionsMgr.h>
+#include <XGUI_Command.h>
+#include <QAction>
+
+
+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<XGUI_Command*>(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);
+ }
+}
--- /dev/null
+/*
+ * XGUI_ActionsMgr.h
+ */
+
+#ifndef XGUI_ACTIONSMGR_H_
+#define XGUI_ACTIONSMGR_H_
+
+#include <QObject>
+#include <QMap>
+#include <QStringList>
+
+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<QString, QAction*> myActions;
+ QMap<QString, bool> myActionsState;
+};
+
+#endif /* XGUI_ACTIONSMGR_H_ */
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
return aList;
}
-void XGUI_MainMenu::onFeatureChecked(bool isChecked)
-{
- if (!isChecked) {
- restoreCommandState();
- return;
- }
-
- saveCommandsState();
- QStringList aSkippedIds;
- XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(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<XGUI_Command*> 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<XGUI_Command*> allFeatures = features();
- XGUI_Command* eachFeature = NULL;
- foreach(eachFeature, allFeatures) {
- myCommandState.insert(eachFeature, eachFeature->enabled());
- }
-}
-
-void XGUI_MainMenu::restoreCommandState()
-{
- QList<XGUI_Command*> allFeatures = features();
- XGUI_Command* eachFeature = NULL;
- foreach(eachFeature, allFeatures) {
- eachFeature->setChecked(false);
- eachFeature->setEnabled(myCommandState[eachFeature]);
- }
-}
//! Returns list of created commands
QList<XGUI_Command*> features() const;
-public slots:
- void onFeatureChecked(bool);
-
- void saveCommandsState();
- void restoreCommandState();
-
virtual bool eventFilter(QObject *theWatched, QEvent *theEvent);
private:
class XGUI_MainMenu;
class XGUI_Viewer;
+class XGUI_ActionsMgr;
class QMdiArea;
class PyConsole_EnhConsole;
private:
XGUI_MainMenu* myMenuBar;
-
XGUI_Viewer* myViewer;
PyConsole_EnhConsole* myPythonConsole;
#include "XGUI_Displayer.h"
#include "XGUI_OperationMgr.h"
#include "XGUI_SalomeConnector.h"
+#include "XGUI_ActionsMgr.h"
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Feature.h>
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*)));
hidePropertyPanel();
updateCommandStatus();
- if (myMainWindow) {
- XGUI_MainMenu* aMenu = myMainWindow->menuObject();
- aMenu->restoreCommandState();
- }
+ if (myMainWindow) {
+ myActionsMgr->restoreCommandState();
+ }
}
}
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);
}
}
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)));
}
//******************************************************
class XGUI_OperationMgr;
class XGUI_SalomeConnector;
class XGUI_ObjectsBrowser;
+class XGUI_ActionsMgr;
class ModuleBase_Operation;
class ModuleBase_PropPanelOperation;
XGUI_Displayer* myDisplayer;
XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
+ XGUI_ActionsMgr* myActionsMgr;
+
XGUI_SalomeConnector* mySalomeConnector;
};