From 0ea02d60c13cbcb836484eef4e26f36dc0ae3161 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 22 Jan 2025 15:28:46 +0100 Subject: [PATCH] Gui: Add Action::setBlockedChecked Remove the second parameter of Action::setChecked and provide Action::setBlockedChecked instead. --- src/Gui/Action.cpp | 21 +++++++++++++-------- src/Gui/Action.h | 3 ++- src/Gui/Command.cpp | 4 ++-- src/Gui/CommandView.cpp | 20 ++++++++++---------- src/Gui/CommandWindow.cpp | 4 ++-- src/Mod/TechDraw/Gui/CommandDecorate.cpp | 4 ++-- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index 395095c408..c839412deb 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -137,16 +137,21 @@ void Action::setCheckable(bool check) } } -void Action::setChecked(bool check, bool no_signal) +void Action::setChecked(bool check) { - bool blocked = false; - if (no_signal) { - blocked = _action->blockSignals(true); - } _action->setChecked(check); - if (no_signal) { - _action->blockSignals(blocked); - } +} + +/*! + * \brief Action::setBlockedChecked + * \param check + * Does the same as \ref setChecked but additionally blocks + * any signals. + */ +void Action::setBlockedChecked(bool check) +{ + QSignalBlocker block(_action); + _action->setChecked(check); } bool Action::isChecked() const diff --git a/src/Gui/Action.h b/src/Gui/Action.h index d31c8e4563..62222990fc 100644 --- a/src/Gui/Action.h +++ b/src/Gui/Action.h @@ -57,7 +57,8 @@ public: virtual void setVisible(bool); void setCheckable(bool); - void setChecked (bool, bool no_signal=false); + void setChecked(bool); + void setBlockedChecked(bool); bool isChecked() const; bool isEnabled() const; diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 4c01a4040c..9bf7ef88c1 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -385,7 +385,7 @@ void Command::setupCheckable(int iMsg) { action->setChecked(checked); action->blockSignals(blocked); if(action!=_pcAction->action()) - _pcAction->setChecked(checked,true); + _pcAction->setBlockedChecked(checked); } } @@ -1637,7 +1637,7 @@ Action * PythonGroupCommand::createAction() qtAction->blockSignals(false); }else if(qtAction->isCheckable()){ pcAction->setCheckable(true); - pcAction->setChecked(qtAction->isChecked(),true); + pcAction->setBlockedChecked(qtAction->isChecked()); } } } diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index c0e5c632aa..ccf00cb137 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -3301,7 +3301,7 @@ bool StdCmdSelForward::isActive() DEF_STD_CMD_AC(StdTree##_name) \ void StdTree##_name::activated(int){ \ TreeParams::setDocumentMode(_v);\ - if(_pcAction) _pcAction->setChecked(true,true);\ + if(_pcAction) _pcAction->setBlockedChecked(true);\ }\ Action * StdTree##_name::createAction(void) {\ Action *pcAction = Command::createAction();\ @@ -3314,7 +3314,7 @@ Action * StdTree##_name::createAction(void) {\ bool StdTree##_name::isActive() {\ bool checked = TreeParams::getDocumentMode()==_v;\ if(_pcAction && _pcAction->isChecked()!=checked)\ - _pcAction->setChecked(checked,true);\ + _pcAction->setBlockedChecked(checked);\ return true;\ } @@ -3374,9 +3374,9 @@ DEF_STD_CMD_AC(StdTree##_name) \ void StdTree##_name::activated(int){ \ auto checked = !TreeParams::get##_name();\ TreeParams::set##_name(checked);\ - if(_pcAction) _pcAction->setChecked(checked,true);\ + if(_pcAction) _pcAction->setBlockedChecked(checked);\ }\ -Action * StdTree##_name::createAction(void) {\ +Action * StdTree##_name::createAction() {\ Action *pcAction = Command::createAction();\ pcAction->setCheckable(true);\ pcAction->setIcon(QIcon());\ @@ -3387,7 +3387,7 @@ Action * StdTree##_name::createAction(void) {\ bool StdTree##_name::isActive() {\ bool checked = TreeParams::get##_name();\ if(_pcAction && _pcAction->isChecked()!=checked)\ - _pcAction->setChecked(checked,true);\ + _pcAction->setBlockedChecked(checked);\ return true;\ } @@ -3576,7 +3576,7 @@ void StdCmdSelBoundingBox::activated(int iMsg) if(checked != ViewParams::instance()->getShowSelectionBoundingBox()) { ViewParams::instance()->setShowSelectionBoundingBox(checked); if(_pcAction) - _pcAction->setChecked(checked,true); + _pcAction->setBlockedChecked(checked); } } @@ -3585,7 +3585,7 @@ bool StdCmdSelBoundingBox::isActive() if(_pcAction) { bool checked = _pcAction->isChecked(); if(checked != ViewParams::instance()->getShowSelectionBoundingBox()) - _pcAction->setChecked(!checked,true); + _pcAction->setBlockedChecked(!checked); } return true; } @@ -3819,10 +3819,10 @@ void StdCmdDockOverlayMouseTransparent::activated(int iMsg) bool checked = !OverlayManager::instance()->isMouseTransparent(); OverlayManager::instance()->setMouseTransparent(checked); if(_pcAction) - _pcAction->setChecked(checked,true); + _pcAction->setBlockedChecked(checked); } -Action * StdCmdDockOverlayMouseTransparent::createAction(void) { +Action * StdCmdDockOverlayMouseTransparent::createAction() { Action *pcAction = Command::createAction(); pcAction->setCheckable(true); pcAction->setIcon(QIcon()); @@ -3834,7 +3834,7 @@ Action * StdCmdDockOverlayMouseTransparent::createAction(void) { bool StdCmdDockOverlayMouseTransparent::isActive() { bool checked = OverlayManager::instance()->isMouseTransparent(); if(_pcAction && _pcAction->isChecked()!=checked) - _pcAction->setChecked(checked,true); + _pcAction->setBlockedChecked(checked); return true; } diff --git a/src/Gui/CommandWindow.cpp b/src/Gui/CommandWindow.cpp index b4e925aee5..284299abdb 100644 --- a/src/Gui/CommandWindow.cpp +++ b/src/Gui/CommandWindow.cpp @@ -362,7 +362,7 @@ Action* StdCmdToggleToolBarLock::createAction() Action* action = Command::createAction(); action->setCheckable(true); - action->setChecked(ToolBarManager::getInstance()->areToolBarsLocked(), true); + action->setBlockedChecked(ToolBarManager::getInstance()->areToolBarsLocked()); return action; } @@ -420,7 +420,7 @@ Action * StdCmdStatusBar::createAction() { Action *pcAction = Command::createAction(); pcAction->setCheckable(true); - pcAction->setChecked(false, true); + pcAction->setBlockedChecked(false); auto fsb = new FilterStatusBar(pcAction); getMainWindow()->statusBar()->installEventFilter(fsb); diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp index 3c7fb3bfcc..e2c0b35f72 100644 --- a/src/Mod/TechDraw/Gui/CommandDecorate.cpp +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -340,7 +340,7 @@ void CmdTechDrawToggleFrame::activated(int iMsg) Gui::Action *action = this->getAction(); if (action) { - action->setChecked(!vpPage->getFrameState(), true); + action->setBlockedChecked(!vpPage->getFrameState()); } } @@ -358,7 +358,7 @@ bool CmdTechDrawToggleFrame::isActive() Gui::Action* action = this->getAction(); if (action) { - action->setChecked(vpp && !vpp->getFrameState(), true); + action->setBlockedChecked(vpp && !vpp->getFrameState()); } return true;