Gui: Allow ActionGroups to not remember choice

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.
This commit is contained in:
Kacper Donat
2023-12-16 21:29:28 +01:00
committed by Yorik van Havre
parent ca49337425
commit 34c85e26da
5 changed files with 43 additions and 11 deletions

View File

@@ -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));
@@ -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();
@@ -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)