From 0f9e6aed4b7f5b75eb13b39709dac59986fd3684 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 14 Apr 2016 10:22:01 +0300 Subject: [PATCH] Issue 1303 Re-ordering of Sketcher menus: using menu mechanizm to group SALOME actions. --- src/ModuleBase/ModuleBase_IModule.h | 4 +- src/SHAPERGUI/SHAPERGUI.cpp | 56 ++++++++++----- src/SHAPERGUI/SHAPERGUI.h | 14 ++-- src/XGUI/XGUI_MenuGroup.cpp | 2 +- src/XGUI/XGUI_MenuGroup.h | 2 +- src/XGUI/XGUI_MenuMgr.cpp | 107 +++++++++++++++++++++------- src/XGUI/XGUI_MenuMgr.h | 14 +++- src/XGUI/XGUI_SalomeConnector.h | 22 ++++-- src/XGUI/XGUI_Workshop.cpp | 1 + 9 files changed, 165 insertions(+), 57 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 269c11568..a89671c2f 100755 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -327,8 +327,8 @@ protected slots: /// Called on selection changed event virtual void onSelectionChanged() {} - protected: - /// Register validators for this module +protected: + /// Register validators for this module virtual void registerValidators() {} /// Register selection filters for this module diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp index a85c0d9a0..8af02ae2d 100644 --- a/src/SHAPERGUI/SHAPERGUI.cpp +++ b/src/SHAPERGUI/SHAPERGUI.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -373,7 +374,9 @@ CAM_DataModel* SHAPERGUI::createDataModel() return new SHAPERGUI_DataModel(this); } -QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo) +QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo, + const bool isAddSeparator, + bool isMenuAction, bool isToolAction) { return addFeature(theWBName, theInfo.id, @@ -381,14 +384,16 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theIn theInfo.toolTip, theInfo.icon, theInfo.shortcut, - theInfo.checkable); + theInfo.checkable, + isAddSeparator, isMenuAction, isToolAction); } //****************************************************** QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId, - const QString& theTitle, const QString& theTip, - const QIcon& theIcon, const QKeySequence& theKeys, - bool isCheckable) + const QString& theTitle, const QString& theTip, + const QIcon& theIcon, const QKeySequence& theKeys, + bool isCheckable, const bool isAddSeparator, + bool isMenuAction, bool isToolAction) { static QString aLastTool = ""; static int aNb = 0; @@ -403,9 +408,6 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId, } aNb++; - int aMenu = createMenu(theWBName, -1, -1, 50); - int aTool = createTool(theWBName, theWBName); - int aId = myActionsList.size(); myActionsList.append(theId); SUIT_Desktop* aDesk = application()->desktop(); @@ -415,9 +417,19 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId, 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); + if (isMenuAction) { + int aWBMenu = createMenu(theWBName, -1, -1, 50/*10-Window, 1000 - Help*/); + int aItemId = createMenu(aId, aWBMenu); + if (isAddSeparator) + createMenu(separator(), aWBMenu); + } + if (isToolAction) { + int aWBTool = createTool(theWBName, theWBName); + int aToolId = createTool(aId, aWBTool); + if (isAddSeparator) + createTool(separator(), aWBTool); + } return aAction; } @@ -427,12 +439,10 @@ bool SHAPERGUI::isFeatureOfNested(const QAction* theAction) } QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName, - const ActionInfo& theInfo, - const QList& theNestedActions) + const ActionInfo& theInfo, + const QList& theNestedActions, + bool isMenuAction, bool isToolAction) { - int aMenu = createMenu(theWBName, -1, -1, 50); - int aTool = createTool(theWBName, theWBName); - int aId = myActionsList.size(); myActionsList.append(theInfo.id); SUIT_Desktop* aDesk = application()->desktop(); @@ -448,9 +458,14 @@ QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName, anAction->setShortcut(theInfo.shortcut); anAction->setFont(theInfo.font); - //int aItemId = createMenu(aId, aMenu, -1, 10); - int aToolId = createTool(anAction, aTool, aId); - + if (isMenuAction) { + int aWBMenu = createMenu(theWBName, -1, -1, 50); + int aItemId = createMenu(anAction, aWBMenu); + } + if (isToolAction) { + int aWBTool = createTool(theWBName, theWBName); + int aToolId = createTool(anAction, aWBTool); + } return anAction; } @@ -651,3 +666,8 @@ bool SHAPERGUI::abortAllOperations() { return workshop()->operationMgr()->abortAllOperations(); } + +void SHAPERGUI::createFeatureActions() +{ + myWorkshop->menuMgr()->createFeatureActions(); +} diff --git a/src/SHAPERGUI/SHAPERGUI.h b/src/SHAPERGUI/SHAPERGUI.h index 7e1c1435e..7e1ff0b1e 100644 --- a/src/SHAPERGUI/SHAPERGUI.h +++ b/src/SHAPERGUI/SHAPERGUI.h @@ -52,11 +52,13 @@ Q_OBJECT virtual QAction* addFeature(const QString& theWBName, const QString& theId, const QString& theTitle, const QString& theTip, const QIcon& theIcon, const QKeySequence& theKeys = QKeySequence(), - bool isCheckable = false); + bool isCheckable = false, const bool isAddSeparator = false, + bool isMenuAction = true, bool isToolAction = true); //! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action virtual QAction* addFeature(const QString& theWBName, - const ActionInfo& theInfo); + const ActionInfo& theInfo, const bool isAddSeparator, + bool isMenuAction = true, bool isToolAction = true); /// Add a nested feature /// \param theWBName a workbench name @@ -64,7 +66,8 @@ Q_OBJECT /// \param theNestedActions a list of nested actions virtual QAction* addFeatureOfNested(const QString& theWBName, const ActionInfo& theInfo, - const QList& theNestedActions); + const QList& theNestedActions, + bool isMenuAction = true, bool isToolAction = true); //! Returns true if the feature action is a nested action, in other words, //! it is created by addNestedFeature(). @@ -85,7 +88,10 @@ Q_OBJECT /// \param theAction an ation to add /// \param theToolBarTitle a name of tool bar virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ); - + + /// Creates menu/tool bar actions for loaded features stored in the menu manager + virtual void createFeatureActions(); + virtual QMainWindow* desktop() const; virtual QString commandId(const QAction* theCmd) const; diff --git a/src/XGUI/XGUI_MenuGroup.cpp b/src/XGUI/XGUI_MenuGroup.cpp index c2ce5b20f..26407a0e9 100755 --- a/src/XGUI/XGUI_MenuGroup.cpp +++ b/src/XGUI/XGUI_MenuGroup.cpp @@ -16,7 +16,7 @@ void XGUI_MenuGroup::setFeatureInfo(const std::shared_ptr myFeatureInfo.push_back(theMessage); } -const std::list >& XGUI_MenuGroup::featureInfo() const +const std::list >& XGUI_MenuGroup::featuresInfo() const { return myFeatureInfo; } diff --git a/src/XGUI/XGUI_MenuGroup.h b/src/XGUI/XGUI_MenuGroup.h index 8b4716390..c265608a4 100755 --- a/src/XGUI/XGUI_MenuGroup.h +++ b/src/XGUI/XGUI_MenuGroup.h @@ -38,7 +38,7 @@ class XGUI_EXPORT XGUI_MenuGroup /// Returns container of existing features /// \returns list - const std::list >& featureInfo() const; + const std::list >& featuresInfo() const; private: std::string myName; /// a name of the workbench diff --git a/src/XGUI/XGUI_MenuMgr.cpp b/src/XGUI/XGUI_MenuMgr.cpp index 8dff16c1f..6cbf91c1a 100755 --- a/src/XGUI/XGUI_MenuMgr.cpp +++ b/src/XGUI/XGUI_MenuMgr.cpp @@ -60,16 +60,11 @@ void XGUI_MenuMgr::addFeature(const std::shared_ptr& theM #endif return; } - { - std::string aWchName = theMessage->workbenchId(); - std::shared_ptr aWorkbench = findWorkbench(aWchName); - - std::string aGroupName = theMessage->groupId(); - std::shared_ptr aGroup = aWorkbench->findGroup(aGroupName); - - aGroup->setFeatureInfo(theMessage); - } - +#ifdef HAVE_SALOME + std::shared_ptr aWorkbench = findWorkbench(theMessage->workbenchId()); + std::shared_ptr aGroup = aWorkbench->findGroup(theMessage->groupId()); + aGroup->setFeatureInfo(theMessage); +#else ActionInfo aFeatureInfo; aFeatureInfo.initFrom(theMessage); @@ -94,21 +89,6 @@ void XGUI_MenuMgr::addFeature(const std::shared_ptr& theM } } -#ifdef HAVE_SALOME - XGUI_SalomeConnector* aSalomeConnector = myWorkshop->salomeConnector(); - QAction* aAction; - if (isColumnButton) { - aAction = aSalomeConnector->addFeatureOfNested(aWchName, aFeatureInfo, aNestedActList); - } else { - //Issue #650: in the SALOME mode the tooltip should be same as text - aFeatureInfo.toolTip = aFeatureInfo.text; - aAction = aSalomeConnector->addFeature(aWchName, aFeatureInfo); - } - aSalomeConnector->setFeatureInfo(aFeatureInfo.id, theMessage); - - myWorkshop->actionsMgr()->addCommand(aAction); - myWorkshop->module()->actionCreated(aAction); -#else //Find or create Workbench AppElements_MainMenu* aMenuBar = myWorkshop->mainWindow()->menuObject(); AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName); @@ -138,7 +118,7 @@ void XGUI_MenuMgr::addFeature(const std::shared_ptr& theM #endif } -std::shared_ptr XGUI_MenuMgr::findWorkbench(std::string& theWorkbenchName) +std::shared_ptr XGUI_MenuMgr::findWorkbench(const std::string& theWorkbenchName) { std::list< std::shared_ptr >::const_iterator anIt = myWorkbenches.begin(), aLast = myWorkbenches.end(); @@ -154,3 +134,78 @@ std::shared_ptr XGUI_MenuMgr::findWorkbench(std::string& the } return aResultWorkbench; } + +void XGUI_MenuMgr::createFeatureActions() +{ +#ifdef HAVE_SALOME + std::list< std::shared_ptr >::const_iterator anIt = myWorkbenches.begin(), + aLast = myWorkbenches.end(); + XGUI_SalomeConnector* aSalomeConnector = myWorkshop->salomeConnector(); + for (; anIt != aLast; anIt++) { + std::shared_ptr aWorkbench = *anIt; + std::string aWchName = aWorkbench->getName(); + const std::list >& aGroups = aWorkbench->groups(); + std::list >::const_iterator aGIt = aGroups.begin(), + aGLast = aGroups.end(); + for (; aGIt != aGLast; aGIt++) { + const std::shared_ptr aGroup = *aGIt; + std::string aGName = aGroup->getName(); + const std::list >& aFeaturesInfo = aGroup->featuresInfo(); + std::list >::const_iterator aFIt = aFeaturesInfo.begin(), + aFLast = aFeaturesInfo.end(); + int aFSize = aFeaturesInfo.size(); + for(int i = 0; aFIt != aFLast; aFIt++, i++) { + std::shared_ptr aMessage = *aFIt; + bool aUseSeparator = i == aFSize-1; + QAction* aAction = buildAction(aMessage, aWchName, aUseSeparator); + + aSalomeConnector->setFeatureInfo(QString::fromStdString(aMessage->id()), aMessage); + myWorkshop->actionsMgr()->addCommand(aAction); + myWorkshop->module()->actionCreated(aAction); + } + } + } +#endif +} + +QAction* XGUI_MenuMgr::buildAction(const std::shared_ptr& theMessage, + const std::string& theWchName, const bool aUseSeparator) const +{ + QAction* anAction; + +#ifdef HAVE_SALOME + XGUI_SalomeConnector* aSalomeConnector = myWorkshop->salomeConnector(); + + ActionInfo aFeatureInfo; + aFeatureInfo.initFrom(theMessage); + QStringList aNestedFeatures = + QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts); + QList aNestedActList; + if (!aNestedFeatures.isEmpty()) { + QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested()); + XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr(); + XGUI_ActionsMgr* anActionsMgr = myWorkshop->actionsMgr(); + if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) { + QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL); + QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations())); + aNestedActList << anAction; + } + if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) { + QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL); + QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations())); + aNestedActList << anAction; + } + anAction = aSalomeConnector->addFeatureOfNested(theWchName.c_str(), aFeatureInfo, + aNestedActList, false, true); + QAction* aMenuAction = aSalomeConnector->addFeature(theWchName.c_str(), aFeatureInfo, + aUseSeparator, true, false); + myWorkshop->module()->actionCreated(aMenuAction); + } + else { + //Issue #650: in the SALOME mode the tooltip should be same as text + aFeatureInfo.toolTip = aFeatureInfo.text; + anAction = aSalomeConnector->addFeature(theWchName.c_str(), aFeatureInfo, aUseSeparator); + } +#endif + return anAction; +} diff --git a/src/XGUI/XGUI_MenuMgr.h b/src/XGUI/XGUI_MenuMgr.h index 74bf04407..ac25c80ec 100755 --- a/src/XGUI/XGUI_MenuMgr.h +++ b/src/XGUI/XGUI_MenuMgr.h @@ -19,6 +19,8 @@ class XGUI_MenuWorkbench; class XGUI_Workshop; class Config_FeatureMessage; +class QAction; + /** * \ingroup GUI * A class for management of menu actions (features). The actions should be arranged like they are @@ -33,6 +35,8 @@ class XGUI_MenuMgr : public Events_Listener XGUI_EXPORT XGUI_MenuMgr(XGUI_Workshop* theWorkshop); XGUI_EXPORT virtual ~XGUI_MenuMgr() {} + XGUI_EXPORT void createFeatureActions(); + /// Redefinition of Events_Listener method XGUI_EXPORT virtual void processEvent(const std::shared_ptr& theMessage); @@ -43,7 +47,15 @@ protected: /// Finds or creates a workbench for the given name /// \param theWorkbenchName a name defined in XML /// \return an instance of workbench - std::shared_ptr findWorkbench(std::string& theWorkbenchName); + std::shared_ptr findWorkbench(const std::string& theWorkbenchName); + + /// Creates a new action by the message + /// \param theMessage an XML information of the feature + /// \param theWchName a workbench name, will be used as menu/tool bar name + /// \param aUseSeparator boolean value if a separator should be added after the action + /// \return an action + QAction* buildAction(const std::shared_ptr& theMessage, + const std::string& theWchName, const bool aUseSeparator) const; private: XGUI_Workshop* myWorkshop; /// the current workshop diff --git a/src/XGUI/XGUI_SalomeConnector.h b/src/XGUI/XGUI_SalomeConnector.h index 7596878a1..b607f7327 100644 --- a/src/XGUI/XGUI_SalomeConnector.h +++ b/src/XGUI/XGUI_SalomeConnector.h @@ -35,24 +35,35 @@ class XGUI_EXPORT XGUI_SalomeConnector //! \param theIcon - icon //! \param isCheckable - is checkable or not //! \param theKeys - hot keys + //! \param isAddSeparator boolean flag about adding separator after the action + //! \param isMenuAction boolean flag about adding the action to application menu bar + //! \param isToolAction boolean flag about adding the action to application tool bar //! 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; + const QKeySequence& theKeys, bool isCheckable, const bool isAddSeparator, + bool isMenuAction = true, bool isToolAction = true) = 0; //! Creates a feature (command) in SALOME desktop //! \param theWBName - name of toolbar (workbench) //! \param theInfo - information about action (icon, text, etc) + //! \param isAddSeparator boolean flag about adding separator after the action + //! \param isMenuAction boolean flag about adding the action to application menu bar + //! \param isToolAction boolean flag about adding the action to application tool bar virtual QAction* addFeature(const QString& theWBName, - const ActionInfo& theInfo) = 0; + const ActionInfo& theInfo, const bool isAddSeparator, + bool isMenuAction = true, bool isToolAction = true) = 0; //! Creates a feature (command) in SALOME desktop //! \param theWBName - name of toolbar (workbench) //! \param theInfo - information about action (icon, text, etc) //! \param theNestedActions a list of nested actions + //! \param isMenuAction boolean flag about adding the action to application menu bar + //! \param isToolAction boolean flag about adding the action to application tool bar virtual QAction* addFeatureOfNested(const QString& theWBName, - const ActionInfo& theInfo, - const QList& theNestedActions) = 0; + const ActionInfo& theInfo, + const QList& theNestedActions, + bool isMenuAction = true, bool isToolAction = true) = 0; //! Returns true if the feature action is a nested action, in other words, //! it is created by addFeatureOfNested(). @@ -85,6 +96,9 @@ class XGUI_EXPORT XGUI_SalomeConnector /// \param theToolBarTitle the toolbar name virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ) = 0; + /// Creates menu/tool bar actions for loaded features stored in the menu manager + virtual void createFeatureActions() = 0; + //! Returns desktop window of SALOME virtual QMainWindow* desktop() const = 0; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index d28a944b2..b4a48cd09 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1002,6 +1002,7 @@ bool XGUI_Workshop::createModule() // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr))); myModule->createFeatures(); + salomeConnector()->createFeatureActions(); //myActionsMgr->update(); return true; } -- 2.39.2