Skip to content

Commit

Permalink
Gui: Allow ActionGroups to not remember choice
Browse files Browse the repository at this point in the history
This is fix to issue mentioned in the #11717, on discord and forum that
for smart dimension tool the chosen tool should not be remembered. This
will ensure that the "smart" tool is always visible on the toolbar and
other tools are accessible in case that such explicit choice is needed.
  • Loading branch information
kadet1090 authored and yorikvanhavre committed Dec 18, 2023
1 parent ac67cd2 commit a8f0f59
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/Gui/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,12 @@ void Action::setMenuRole(QAction::MenuRole menuRole)
* Constructs an action called \a name with parent \a parent. It also stores a pointer
* to the command object.
*/
ActionGroup::ActionGroup ( Command* pcCmd,QObject * parent)
: Action(pcCmd, parent)
, _group(nullptr)
, _dropDown(false)
, _isMode(false)
ActionGroup::ActionGroup(Command* pcCmd, QObject* parent)
: Action(pcCmd, parent)
, _group(nullptr)
, _dropDown(false)
, _isMode(false)
, _rememberLast(true)
{
_group = new QActionGroup(this);
connect(_group, &QActionGroup::triggered, this, qOverload<QAction*>(&ActionGroup::onActivated));
Expand Down Expand Up @@ -526,6 +527,16 @@ void ActionGroup::setVisible( bool check )
groupAction()->setVisible(check);
}

void ActionGroup::setRememberLast(bool remember)
{
_rememberLast = remember;
}

bool ActionGroup::doesRememberLast() const
{
return _rememberLast;
}

QAction* ActionGroup::addAction(QAction* action)
{
int index = groupAction()->actions().size();
Expand Down Expand Up @@ -585,14 +596,16 @@ void ActionGroup::onToggled(bool check)
*/
void ActionGroup::onActivated (QAction* act)
{
int index = groupAction()->actions().indexOf(act);
if (_rememberLast) {
int index = groupAction()->actions().indexOf(act);

this->setIcon(act->icon());
if (!this->_isMode) {
this->setToolTip(act->toolTip(), act->text());
this->setIcon(act->icon());
if (!this->_isMode) {
this->setToolTip(act->toolTip(), act->text());
}
this->setProperty("defaultAction", QVariant(index));
command()->invoke(index, Command::TriggerChildAction);
}
this->setProperty("defaultAction", QVariant(index));
command()->invoke(index, Command::TriggerChildAction);
}

void ActionGroup::onHovered (QAction *act)
Expand Down
4 changes: 4 additions & 0 deletions src/Gui/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class GuiExport ActionGroup : public Action
void setVisible (bool) override;
void setIsMode(bool check) { _isMode = check; }

void setRememberLast(bool);
bool doesRememberLast() const;

void setDropDownMenu(bool check) { _dropDown = check; }
QAction* addAction(QAction*);
QAction* addAction(const QString&);
Expand Down Expand Up @@ -171,6 +174,7 @@ public Q_SLOTS:
QActionGroup* _group;
bool _dropDown;
bool _isMode;
bool _rememberLast;

private:
Q_DISABLE_COPY(ActionGroup)
Expand Down
11 changes: 11 additions & 0 deletions src/Gui/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,16 @@ void GroupCommand::setExclusive(bool on)
exclusive = on;
}

bool GroupCommand::doesRememberLast() const
{
return rememberLast;
}

void GroupCommand::setRememberLast(bool on)
{
rememberLast = on;
}

bool GroupCommand::hasDropDownMenu() const
{
return dropDownMenu;
Expand Down Expand Up @@ -1063,6 +1073,7 @@ Action * GroupCommand::createAction() {
pcAction->setDropDownMenu(hasDropDownMenu());
pcAction->setExclusive(isExclusive());
pcAction->setCheckable(isCheckable());
pcAction->setRememberLast(doesRememberLast());
pcAction->setWhatsThis(QString::fromLatin1(sWhatsThis));

for(auto &v : cmds) {
Expand Down
3 changes: 3 additions & 0 deletions src/Gui/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@ class GuiExport GroupCommand : public Command {
void setCheckable(bool);
bool isExclusive() const;
void setExclusive(bool);
bool doesRememberLast() const;
void setRememberLast(bool);
bool hasDropDownMenu() const;
void setDropDownMenu(bool);
void activated(int iMsg) override;
Expand All @@ -667,6 +669,7 @@ class GuiExport GroupCommand : public Command {
protected:
bool checkable = true;
bool exclusive = false;
bool rememberLast = true;
bool dropDownMenu = true;
std::vector<std::pair<Command*,size_t> > cmds;
};
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Sketcher/Gui/CommandConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,7 @@ class CmdSketcherCompDimensionTools : public Gui::GroupCommand
eType = ForEdit;

setCheckable(false);
setRememberLast(false);

addCommand("Sketcher_Dimension");
addCommand(); //separator
Expand Down

0 comments on commit a8f0f59

Please sign in to comment.