From 531d7de2014ce6b79bdcfd47829b4d28c56c939f Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 1 Sep 2023 12:07:04 +0200 Subject: [PATCH] Gui: make GroupCommand more flexible Currently the GroupCommand by default sets the action group as non-exclusive, checkable and having a drop-down menu which isn't always the desired behaviour in sub-classes. Thus, some new methods are added to let a sub-class in its constructor decide how it should behave. --- src/Gui/Command.cpp | 36 +++++++++++++++++++++++++++++++++--- src/Gui/Command.h | 9 +++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 52076fa768..53fb0e33ec 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -1006,6 +1006,36 @@ GroupCommand::GroupCommand(const char *name) :Command(name) {} +bool GroupCommand::isCheckable() const +{ + return checkable; +} + +void GroupCommand::setCheckable(bool on) +{ + checkable = on; +} + +bool GroupCommand::isExclusive() const +{ + return exclusive; +} + +void GroupCommand::setExclusive(bool on) +{ + exclusive = on; +} + +bool GroupCommand::hasDropDownMenu() const +{ + return dropDownMenu; +} + +void GroupCommand::setDropDownMenu(bool on) +{ + dropDownMenu = on; +} + int GroupCommand::addCommand(Command *cmd, bool reg) { cmds.emplace_back(cmd,cmds.size()); if(cmd && reg) @@ -1030,9 +1060,9 @@ Command *GroupCommand::getCommand(int idx) const Action * GroupCommand::createAction() { auto* pcAction = new ActionGroup(this, getMainWindow()); pcAction->setMenuRole(QAction::NoRole); - pcAction->setDropDownMenu(true); - pcAction->setExclusive(false); - pcAction->setCheckable(true); + pcAction->setDropDownMenu(hasDropDownMenu()); + pcAction->setExclusive(isExclusive()); + pcAction->setCheckable(isCheckable()); pcAction->setWhatsThis(QString::fromLatin1(sWhatsThis)); for(auto &v : cmds) { diff --git a/src/Gui/Command.h b/src/Gui/Command.h index f2439d4b80..4a5679a44b 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -652,6 +652,12 @@ public: Command *getCommand(int idx) const; protected: + bool isCheckable() const; + void setCheckable(bool); + bool isExclusive() const; + void setExclusive(bool); + bool hasDropDownMenu() const; + void setDropDownMenu(bool); void activated(int iMsg) override; Gui::Action * createAction() override; void languageChange() override; @@ -659,6 +665,9 @@ protected: void setup(Action *); protected: + bool checkable = true; + bool exclusive = false; + bool dropDownMenu = true; std::vector > cmds; };