From: nds Date: Tue, 19 Apr 2016 10:20:49 +0000 (+0300) Subject: Issue #1303 Reordering menu items: Sketch action enable state X-Git-Tag: V_2.3.0~191 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=81870af2d38a9fc77e96ce17271a434614187b2d;p=modules%2Fshaper.git Issue #1303 Reordering menu items: Sketch action enable state --- diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp index 8af02ae2d..78cdcb08d 100644 --- a/src/SHAPERGUI/SHAPERGUI.cpp +++ b/src/SHAPERGUI/SHAPERGUI.cpp @@ -375,8 +375,7 @@ CAM_DataModel* SHAPERGUI::createDataModel() } QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo, - const bool isAddSeparator, - bool isMenuAction, bool isToolAction) + const bool isAddSeparator) { return addFeature(theWBName, theInfo.id, @@ -385,15 +384,14 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theIn theInfo.icon, theInfo.shortcut, theInfo.checkable, - isAddSeparator, isMenuAction, isToolAction); + isAddSeparator); } //****************************************************** QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId, const QString& theTitle, const QString& theTip, const QIcon& theIcon, const QKeySequence& theKeys, - bool isCheckable, const bool isAddSeparator, - bool isMenuAction, bool isToolAction) + bool isCheckable, const bool isAddSeparator) { static QString aLastTool = ""; static int aNb = 0; @@ -418,18 +416,16 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId, isCheckable); aAction->setData(theId); - 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); - } + int aWBMenu = createMenu(theWBName, -1, -1, 50/*10-Window, 1000 - Help*/); + int aItemId = createMenu(aId, aWBMenu); + if (isAddSeparator) + createMenu(separator(), aWBMenu); + + int aWBTool = createTool(theWBName, theWBName); + int aToolId = createTool(aId, aWBTool); + if (isAddSeparator) + createTool(separator(), aWBTool); + return aAction; } @@ -440,10 +436,8 @@ bool SHAPERGUI::isFeatureOfNested(const QAction* theAction) QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName, const ActionInfo& theInfo, - const QList& theNestedActions, - bool isMenuAction, bool isToolAction) + const QList& theNestedActions) { - int aId = myActionsList.size(); myActionsList.append(theInfo.id); SUIT_Desktop* aDesk = application()->desktop(); SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions); @@ -458,14 +452,12 @@ QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName, anAction->setShortcut(theInfo.shortcut); anAction->setFont(theInfo.font); - 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); - } + int aWBMenu = createMenu(theWBName, -1, -1, 50); + int aItemId = createMenu(anAction, aWBMenu); + + int aWBTool = createTool(theWBName, theWBName); + int aToolId = createTool(anAction, aWBTool); + return anAction; } @@ -524,13 +516,8 @@ QList SHAPERGUI::commandList() const if (aCmd && myActionsList.contains(aCmd->data().toString())) aActions.append(aCmd); } - return aActions; -} -//****************************************************** -QStringList SHAPERGUI::commandIdList() const -{ - return myActionsList; + return aActions; } //****************************************************** @@ -539,25 +526,6 @@ QMainWindow* SHAPERGUI::desktop() const return application()->desktop(); } -//****************************************************** -QString SHAPERGUI::commandId(const QAction* theCmd) const -{ - int aId = actionId(theCmd); - if (aId < myActionsList.size()) - return myActionsList[aId]; - return QString(); -} - -//****************************************************** -QAction* SHAPERGUI::command(const QString& theId) const -{ - int aId = myActionsList.indexOf(theId); - if ((aId != -1) && (aId < myActionsList.size())) { - return action(aId); - } - return 0; -} - void SHAPERGUI::setFeatureInfo(const QString& theFeatureId, const std::shared_ptr& theMessage) { diff --git a/src/SHAPERGUI/SHAPERGUI.h b/src/SHAPERGUI/SHAPERGUI.h index 7e1ff0b1e..36e0f1ade 100644 --- a/src/SHAPERGUI/SHAPERGUI.h +++ b/src/SHAPERGUI/SHAPERGUI.h @@ -52,13 +52,11 @@ 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, const bool isAddSeparator = false, - bool isMenuAction = true, bool isToolAction = true); + bool isCheckable = false, const bool isAddSeparator = false); //! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action virtual QAction* addFeature(const QString& theWBName, - const ActionInfo& theInfo, const bool isAddSeparator, - bool isMenuAction = true, bool isToolAction = true); + const ActionInfo& theInfo, const bool isAddSeparator); /// Add a nested feature /// \param theWBName a workbench name @@ -66,8 +64,7 @@ Q_OBJECT /// \param theNestedActions a list of nested actions virtual QAction* addFeatureOfNested(const QString& theWBName, const ActionInfo& theInfo, - const QList& theNestedActions, - bool isMenuAction = true, bool isToolAction = true); + const QList& theNestedActions); //! Returns true if the feature action is a nested action, in other words, //! it is created by addNestedFeature(). @@ -94,11 +91,7 @@ Q_OBJECT virtual QMainWindow* desktop() const; - virtual QString commandId(const QAction* theCmd) const; - - virtual QAction* command(const QString& theId) const; - - //! Stores XML information for the feature kind + //! Stores XML information for the feature kind //! \param theFeatureId a feature kind //! \param theMessage a container of the feature XML properties virtual void setFeatureInfo(const QString& theFeatureId, @@ -118,9 +111,6 @@ Q_OBJECT //! Returns list of defined actions (just by SHAPER module) virtual QList commandList() const; - //! Returns list of Ids of defined actions (just by SHAPER module) - virtual QStringList commandIdList() const; - /// Redefinition of virtual function. /// \param theClient name of pop-up client /// \param theMenu popup menu instance @@ -189,6 +179,9 @@ Q_OBJECT /// List of registered actions QStringList myActionsList; + /// List of registered nested actions + QStringList myNestedActionsList; + /// Reference to workshop XGUI_Workshop* myWorkshop; diff --git a/src/SHAPERGUI/SHAPERGUI_NestedButton.cpp b/src/SHAPERGUI/SHAPERGUI_NestedButton.cpp index 0ce9e0133..02753ac05 100644 --- a/src/SHAPERGUI/SHAPERGUI_NestedButton.cpp +++ b/src/SHAPERGUI/SHAPERGUI_NestedButton.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include SHAPERGUI_NestedButton::SHAPERGUI_NestedButton(QObject* theParent, @@ -43,6 +44,12 @@ void SHAPERGUI_NestedButton::showAdditionalButtons(bool isShow) QWidget * SHAPERGUI_NestedButton::createWidget(QWidget * theParent) { + // the action has widget only in tool bar, in menu bar, the default + // action presentation is shown + QToolBar* aToolBar = dynamic_cast(theParent); + if (!aToolBar) + return 0; + myButtonFrame = new QFrame(theParent); QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame); aBoxLay->setContentsMargins(2, 0, 0, 0); diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp index 619302a9f..f1d5e49b1 100644 --- a/src/XGUI/XGUI_ActionsMgr.cpp +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -97,7 +97,7 @@ bool XGUI_ActionsMgr::isNested(const QString& theId) const void XGUI_ActionsMgr::updateCommandsStatus() { - setAllEnabled(true); + setAllEnabled(); XGUI_Selection* aSelection = myWorkshop->selector()->selection(); if (aSelection->getSelected(ModuleBase_ISelection::Viewer).size() > 0) updateOnViewSelection(); @@ -281,10 +281,13 @@ ActionInfo XGUI_ActionsMgr::actionInfoById(const QString& theId) return aResult; } -void XGUI_ActionsMgr::setAllEnabled(bool isEnabled) +void XGUI_ActionsMgr::setAllEnabled() { foreach(QString eachAction, myActions.keys()) { - setActionEnabled(eachAction, isEnabled); + if (myActions.contains(eachAction)) { + QAction* aAction = myActions[eachAction]; + aAction->setEnabled(true); + } } } diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h index d101a64cf..f1f4e80ca 100644 --- a/src/XGUI/XGUI_ActionsMgr.h +++ b/src/XGUI/XGUI_ActionsMgr.h @@ -100,8 +100,8 @@ class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener //! Updates actions according to current selection in the viewer void updateOnViewSelection(); - //! Sets all actions to isEnabled state. - void setAllEnabled(bool isEnabled); + //! Sets all actions to enabled state. + void setAllEnabled(); //! Sets all nested actions to isEnabled state for the command with given ID. //! If ID is empty - all nested actions will be affected. diff --git a/src/XGUI/XGUI_MenuMgr.cpp b/src/XGUI/XGUI_MenuMgr.cpp index 6cbf91c1a..9ee7ed9e9 100755 --- a/src/XGUI/XGUI_MenuMgr.cpp +++ b/src/XGUI/XGUI_MenuMgr.cpp @@ -196,10 +196,7 @@ QAction* XGUI_MenuMgr::buildAction(const std::shared_ptr& 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); + aNestedActList); } else { //Issue #650: in the SALOME mode the tooltip should be same as text diff --git a/src/XGUI/XGUI_SalomeConnector.h b/src/XGUI/XGUI_SalomeConnector.h index b607f7327..4a4308c78 100644 --- a/src/XGUI/XGUI_SalomeConnector.h +++ b/src/XGUI/XGUI_SalomeConnector.h @@ -36,34 +36,25 @@ class XGUI_EXPORT XGUI_SalomeConnector //! \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, const bool isAddSeparator, - bool isMenuAction = true, bool isToolAction = true) = 0; + const QKeySequence& theKeys, bool isCheckable, const bool isAddSeparator) = 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, const bool isAddSeparator, - bool isMenuAction = true, bool isToolAction = true) = 0; + const ActionInfo& theInfo, const bool isAddSeparator) = 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, - bool isMenuAction = true, bool isToolAction = true) = 0; + const QList& theNestedActions) = 0; //! Returns true if the feature action is a nested action, in other words, //! it is created by addFeatureOfNested(). @@ -102,18 +93,9 @@ class XGUI_EXPORT XGUI_SalomeConnector //! Returns desktop window of SALOME virtual QMainWindow* desktop() const = 0; - //! Returns command string Id by QAction instance - virtual QString commandId(const QAction* theCmd) const = 0; - - //! Returns QAction instance by command string Id - virtual QAction* command(const QString& theId) const = 0; - //! Returns list of defined actions (just by SHAPER module) virtual QList commandList() const = 0; - //! Returns list of Ids of defined actions (just by NewGeom module) - virtual QStringList commandIdList() const = 0; - //! Stores XML information for the feature kind //! \param theFeatureId a feature kind //! \param theMessage a container of the feature XML properties