INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/XGUI
${PROJECT_SOURCE_DIR}/src/Events
${PROJECT_SOURCE_DIR}/src/ModuleBase
+ ${PROJECT_SOURCE_DIR}/src/ModelAPI
${SALOME_GUI_INCLUDE}
${SALOME_KERNEL_INCLUDE}
${CAS_INCLUDE_DIRS}
#include <QtxActionMenuMgr.h>
#include <QDockWidget>
+#include <QAction>
extern "C" {
NewGeom_EXPORT CAM_Module* createModule() {
}
//******************************************************
-void NewGeom_Module::addFeature(const QString& theWBName,
- const QString& theId,
- const QString& theTitle,
- const QString& theTip,
- const QIcon& theIcon,
- bool isCheckable,
- QObject* theReciever,
- const char* theMember,
- const QKeySequence& theKeys)
+QAction* NewGeom_Module::addFeature(const QString& theWBName,
+ const QString& theId,
+ const QString& theTitle,
+ const QString& theTip,
+ const QIcon& theIcon,
+ const QKeySequence& theKeys,
+ bool isCheckable)
{
int aMenu = createMenu(theWBName, -1, -1, 50);
int aTool = createTool(theWBName);
int aKeys = 0;
for (int i = 0; i < theKeys.count(); i++)
aKeys += theKeys[i];
- createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
- isCheckable, theReciever, theMember);
+ QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
+ isCheckable);
+ aAction->setData(theId);
int aItemId = createMenu( aId, aMenu, -1, 10 );
int aToolId = createTool( aId, aTool );
+ return aAction;
}
//******************************************************
-void NewGeom_Module::addEditCommand(const QString& theId,
- const QString& theTitle,
- const QString& theTip,
- const QIcon& theIcon,
- bool isCheckable,
- QObject* theReciever,
- const char* theMember,
- const QKeySequence& theKeys)
+QAction* NewGeom_Module::addEditCommand(const QString& theId,
+ const QString& theTitle,
+ const QString& theTip,
+ const QIcon& theIcon,
+ const QKeySequence& theKeys,
+ bool isCheckable)
{
int aMenu = createMenu(tr( "MEN_DESK_EDIT" ), -1, -1);
int aKeys = 0;
for (int i = 0; i < theKeys.count(); i++)
aKeys += theKeys[i];
- createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
- isCheckable, theReciever, theMember);
+ QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
+ isCheckable);
+ aAction->setData(theId);
createMenu( aId, aMenu, 10 );
+ return aAction;
}
//******************************************************
createMenu( separator(), aMenu, -1, 10 );
}
+//******************************************************
+QList<QAction*> NewGeom_Module::commandList() const
+{
+ QList<QAction*> aActions;
+ for (int i = 0; i < myActionsList.size(); i++)
+ aActions.append(action(i));
+ return aActions;
+}
+
+//******************************************************
+QStringList NewGeom_Module::commandIdList() const
+{
+ return myActionsList;
+}
+
//******************************************************
QMainWindow* NewGeom_Module::desktop() const
{
virtual void selectionChanged();
//--- XGUI connector interface -----
- virtual void addFeature(const QString& theWBName,
- const QString& theId,
- const QString& theTitle,
- const QString& theTip,
- const QIcon& theIcon,
- bool isCheckable = false,
- QObject* reciever = 0,
- const char* member = 0,
- const QKeySequence& theKeys = QKeySequence());
-
- virtual void addEditCommand(const QString& theId,
- const QString& theTitle,
+ virtual QAction* addFeature(const QString& theWBName,
+ const QString& theId,
+ const QString& theTitle,
const QString& theTip,
const QIcon& theIcon,
- bool isCheckable,
- QObject* reciever,
- const char* member,
- const QKeySequence& theKeys);
+ const QKeySequence& theKeys = QKeySequence(),
+ bool isCheckable = false);
+
+ virtual QAction* addEditCommand(const QString& theId,
+ const QString& theTitle,
+ const QString& theTip,
+ const QIcon& theIcon,
+ const QKeySequence& theKeys,
+ bool isCheckable);
virtual void addEditMenuSeparator();
//! Returns interface to Salome viewer
virtual XGUI_SalomeViewer* viewer() const { return myProxyViewer; }
+ //! Returns list of defined actions (just by NewGeom module)
+ virtual QList<QAction*> commandList() const;
+
+ //! Returns list of Ids of defined actions (just by NewGeom module)
+ virtual QStringList commandIdList() const;
+
public slots:
virtual bool activateModule( SUIT_Study* theStudy);
virtual bool deactivateModule( SUIT_Study* theStudy);
myFeaturesInFiles = aXMLReader.featuresInFiles();
}
-void PartSet_Module::featureCreated(XGUI_Command* theFeature)
+void PartSet_Module::featureCreated(QAction* theFeature)
{
- theFeature->connectTo(this, SLOT(onFeatureTriggered()));
+ connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
}
QStringList PartSet_Module::nestedFeatures(QString)
*/
void PartSet_Module::onFeatureTriggered()
{
- XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
+ QAction* aCmd = dynamic_cast<QAction*>(sender());
//Do nothing on uncheck
if(aCmd->isCheckable() && !aCmd->isChecked())
return;
- launchOperation(aCmd->id());
+ launchOperation(aCmd->data().toString());
}
void PartSet_Module::launchOperation(const QString& theCmdId)
XGUI_Workshop* workshop() const;
virtual void createFeatures();
- virtual void featureCreated(XGUI_Command* theFeature);
+ virtual void featureCreated(QAction* theFeature);
virtual QStringList nestedFeatures(QString theFeature);
std::string featureFile(const std::string&);
}
-void XGUI_ActionsMgr::addCommand(QString theId, QAction* theCmd)
+void XGUI_ActionsMgr::addCommand(QAction* theCmd)
{
- myActions.insert(theId,theCmd);
- myActionsState.insert(theId, theCmd->isEnabled());
+ QString aId = theCmd->data().toString();
+ myActions.insert(aId, theCmd);
+ myActionsState.insert(aId, theCmd->isEnabled());
connect(theCmd, SIGNAL(triggered(bool)), this, SLOT(setActionsDisabled(bool)));
}
-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)
saveCommandsState();
QString aSkippedId;
- if (myWorkshop->isSalomeMode()) {
- QAction* aToggledFeature = dynamic_cast<QAction*>(sender());
- aSkippedId = myWorkshop->salomeConnector()->commandId(aToggledFeature);
- } else {
- XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
- aSkippedId = aToggledFeature->id();
- }
+ QAction* aToggledFeature = dynamic_cast<QAction*>(sender());
+ aSkippedId = aToggledFeature->data().toString();
+
QStringList anActionIdsList = myActions.keys();
foreach(QString eachKey, anActionIdsList) {
if (eachKey == aSkippedId) {
virtual ~XGUI_ActionsMgr();
- void addCommand(XGUI_Command* theCmd);
-
- /// Register a command in SALOME mode
- /// \param theId - string ID of the command
- /// \param theCmd - command object
- void addCommand(QString theId, QAction* theCmd);
+ void addCommand(QAction* theCmd);
void saveCommandsState();
void restoreCommandState();
#include <QPushButton>
XGUI_Command::XGUI_Command(const QString& theId, QObject * parent, bool isCheckable)
- : QWidgetAction(parent), myId(theId), myCheckable(isCheckable)
+ : QWidgetAction(parent), myCheckable(isCheckable)
{
+ setData(theId);
}
XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text,
QObject* parent, bool isCheckable)
- : QWidgetAction(parent), myId(theId), myCheckable(isCheckable)
+ : QWidgetAction(parent), myCheckable(isCheckable)
{
setIcon(icon);
setText(text);
+ setData(theId);
}
XGUI_Command::~XGUI_Command()
return QWidgetAction::createWidget(theParent);
}
-bool XGUI_Command::enabled() const
-{
- return isEnabled();
-}
-
-void XGUI_Command::enable()
-{
- setEnabled(true);
-}
-
-void XGUI_Command::disable()
-{
- setEnabled(false);
-}
-
void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
{
connect(this, SIGNAL(triggered(bool)), theResiver, theSlot);
XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent, bool isCheckable = false);
~XGUI_Command();
- //! Returns true if the command is enabled
- virtual bool enabled() const;
-
- //! Set the command enabled
- virtual void enable();
-
- //! Set the command disabled
- virtual void disable();
-
- //! Returns Id of the command
- virtual QString id() const
+ //VSV: Don't use this method for compatibility with SALOME. Use the construction below
+ /*virtual QString id() const
{
- return myId;
- }
+ return data().toString();
+ }*/
const QStringList& unblockableCommands() const;
void setUnblockableCommands(const QStringList& myUnblockableCommands);
virtual QWidget* createWidget(QWidget* theParent);
private:
- QString myId;
bool myCheckable;
//! List of Ids of commands which WILL NOT be blocked when the command is on.
QStringList myUnblockableCommands;
XGUI_Command* XGUI_MenuGroupPanel::feature(const QString& theId) const
{
- QList<XGUI_Command*>::const_iterator aIt;
- for (aIt = myActions.constBegin(); aIt != myActions.constEnd(); ++aIt)
- if ((*aIt)->id() == theId)
- return (*aIt);
+ foreach (XGUI_Command* aCmd, myActions) {
+ if (aCmd->data().toString() == theId)
+ return aCmd;
+ }
return 0;
}
#include <XGUI_Workshop.h>\r
#include <QString>\r
\r
-class XGUI_Command;\r
+class QAction;\r
\r
class XGUI_Module\r
{\r
public:\r
virtual void createFeatures() = 0;\r
- virtual void featureCreated(XGUI_Command*) = 0;\r
+ virtual void featureCreated(QAction*) = 0;\r
virtual void launchOperation(const QString& theCmdId) = 0;\r
\r
virtual ~XGUI_Module() {};\r
//! \param theTip - a tooltip string (help)
//! \param theIcon - icon
//! \param isCheckable - is checkable or not
- //! \param reciever - QObject which will react on the command call
- //! \param member - a method of receiver which will be called on the command
//! \param theKeys - hot keys
- virtual void addFeature(const QString& theWBName,
- const QString& theId,
- const QString& theTitle,
- const QString& theTip,
- const QIcon& theIcon,
- bool isCheckable,
- QObject* reciever,
- const char* member,
- const QKeySequence& theKeys) = 0;
+ //! returns created action
+ virtual QAction* addFeature(const QString& theWBName,
+ const QString& theId,
+ const QString& theTitle,
+ const QString& theTip,
+ const QIcon& theIcon,
+ const QKeySequence& theKeys,
+ bool isCheckable) = 0;
//! Creates a command in Edit menu of SALOME desktop
//! \param theId - an id of the feature
//! \param theTip - a tooltip string (help)
//! \param theIcon - icon
//! \param isCheckable - is checkable or not
- //! \param reciever - QObject which will react on the command call
- //! \param member - a method of receiver which will be called on the command
//! \param theKeys - hot keys
- virtual void addEditCommand(const QString& theId,
- const QString& theTitle,
- const QString& theTip,
- const QIcon& theIcon,
- bool isCheckable,
- QObject* reciever,
- const char* member,
- const QKeySequence& theKeys) = 0;
+ //! returns created action
+ virtual QAction* addEditCommand(const QString& theId,
+ const QString& theTitle,
+ const QString& theTip,
+ const QIcon& theIcon,
+ const QKeySequence& theKeys,
+ bool isCheckable) = 0;
//! Insert separator into Edit menu of SALOME desktop
virtual void addEditMenuSeparator() = 0;
//! Returns QAction instance by command string Id
virtual QAction* command(const QString& theId) const = 0;
+ //! Returns list of defined actions (just by NewGeom module)
+ virtual QList<QAction*> commandList() const = 0;
+
+ //! Returns list of Ids of defined actions (just by NewGeom module)
+ virtual QStringList commandIdList() const = 0;
+
//! Set nested actions dependent on command Id
//! \param theId - the command ID
//! \param theActions - the list of nested actions
{
if (isSalomeMode()) {
// Create only Undo, Redo commands
- salomeConnector()->addEditCommand("UNDO_CMD",
+ QAction* aAction = salomeConnector()->addEditCommand("UNDO_CMD",
tr("Undo"), tr("Undo last command"),
QIcon(":pictures/undo.png"),
- false, this, SLOT(onUndo()),
- QKeySequence::Undo);
- salomeConnector()->addEditCommand("REDO_CMD",
+ QKeySequence::Undo, false);
+ connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
+ aAction = salomeConnector()->addEditCommand("REDO_CMD",
tr("Redo"), tr("Redo last command"),
QIcon(":pictures/redo.png"),
- false, this, SLOT(onRedo()),
- QKeySequence::Redo);
+ QKeySequence::Redo, false);
+ connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
salomeConnector()->addEditMenuSeparator();
return;
}
bool isUsePropPanel = theMessage->isUseInput();
if (isSalomeMode()) {
QString aId = QString::fromStdString(theMessage->id());
- salomeConnector()->addFeature(aWchName,
- QString::fromStdString(theMessage->id()),
- aId,
- QString::fromStdString(theMessage->tooltip()),
- QIcon(theMessage->icon().c_str()),
- isUsePropPanel, this,
- SLOT(onFeatureTriggered()), QKeySequence());
- myActionsMgr->addCommand(aId, salomeConnector()->command(aId));
+ QAction* aAction = salomeConnector()->addFeature(aWchName,
+ aId,
+ QString::fromStdString(theMessage->text()),
+ QString::fromStdString(theMessage->tooltip()),
+ QIcon(theMessage->icon().c_str()),
+ QKeySequence(), isUsePropPanel);
+ myActionsMgr->addCommand(aAction);
salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" "));
-
+ myPartSetModule->featureCreated(aAction);
} else {
XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
//******************************************************
void XGUI_Workshop::updateCommandStatus()
{
- if (isSalomeMode()) // TODO: update commands in SALOME
- return;
- XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
-
- QList<XGUI_Command*> aCommands = aMenuBar->features();
- QList<XGUI_Command*>::const_iterator aIt;
-
+ QList<QAction*> aCommands;
+ if (isSalomeMode()) { // update commands in SALOME mode
+ aCommands = salomeConnector()->commandList();
+ } else {
+ XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
+ foreach (XGUI_Command* aCmd, aMenuBar->features())
+ aCommands.append(aCmd);
+ }
PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
if (aMgr->hasRootDocument()) {
- XGUI_Command* aUndoCmd;
- XGUI_Command* aRedoCmd;
- foreach(XGUI_Command* aCmd, aCommands) {
- if (aCmd->id() == "UNDO_CMD")
+ QAction* aUndoCmd;
+ QAction* aRedoCmd;
+ foreach(QAction* aCmd, aCommands) {
+ QString aId = aCmd->data().toString();
+ if (aId == "UNDO_CMD")
aUndoCmd = aCmd;
- else if (aCmd->id() == "REDO_CMD")
+ else if (aId == "REDO_CMD")
aRedoCmd = aCmd;
else // Enable all commands
- aCmd->enable();
+ aCmd->setEnabled(true);
}
DocumentPtr aDoc = aMgr->rootDocument();
aUndoCmd->setEnabled(aDoc->canUndo());
aRedoCmd->setEnabled(aDoc->canRedo());
} else {
- foreach(XGUI_Command* aCmd, aCommands) {
- if (aCmd->id() == "NEW_CMD")
- aCmd->enable();
- else if (aCmd->id() == "EXIT_CMD")
- aCmd->enable();
+ foreach(QAction* aCmd, aCommands) {
+ QString aId = aCmd->data().toString();
+ if (aId == "NEW_CMD")
+ aCmd->setEnabled(true);
+ else if (aId == "EXIT_CMD")
+ aCmd->setEnabled(true);
else
- aCmd->disable();
+ aCmd->setEnabled(false);
}
}
}