From 024dbd18b646f7989a7d5021e1d3f417abe1977c Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 21 Jul 2022 16:47:30 +0200 Subject: [PATCH] DockWidget: Avoid using sender() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The toggleView() was used as a signal handler for m_toggleViewAction and as a public method. In the latter case checking the sender doesn't make any sense. Add a lambda as a direct signal handler for m_toggleViewAction and perform a custom modification of the open arg before calling toggleView(). Simplify setToggleViewActionChecked() implementation. Change-Id: If3799110b3f1dcf6fe0c653ebcfd23f9716cb2f3 Reviewed-by: Qt CI Bot Reviewed-by: Henning Gründl Reviewed-by: --- src/libs/advanceddockingsystem/dockwidget.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/libs/advanceddockingsystem/dockwidget.cpp b/src/libs/advanceddockingsystem/dockwidget.cpp index 1c6947f7b5f..2fc28ff7575 100644 --- a/src/libs/advanceddockingsystem/dockwidget.cpp +++ b/src/libs/advanceddockingsystem/dockwidget.cpp @@ -204,7 +204,11 @@ namespace ADS d->m_tabWidget = componentsFactory()->createDockWidgetTab(this); d->m_toggleViewAction = new QAction(uniqueId, this); d->m_toggleViewAction->setCheckable(true); - connect(d->m_toggleViewAction, &QAction::triggered, this, &DockWidget::toggleView); + connect(d->m_toggleViewAction, &QAction::triggered, this, [this](bool open) { + // If the toggle view action mode is ActionModeShow (== m_toggleViewAction isn't + // checkable, see setToggleViewActionMode()), then open is always true + toggleView(open || !d->m_toggleViewAction->isCheckable()); + }); setToolbarFloatingStyle(false); if (DockManager::testConfigFlag(DockManager::FocusHighlighting)) @@ -219,10 +223,7 @@ namespace ADS void DockWidget::setToggleViewActionChecked(bool checked) { - QAction *action = d->m_toggleViewAction; - //action->blockSignals(true); - action->setChecked(checked); - //action->blockSignals(false); + d->m_toggleViewAction->setChecked(checked); } void DockWidget::setWidget(QWidget *widget, eInsertMode insertMode) @@ -344,12 +345,6 @@ namespace ADS void DockWidget::toggleView(bool open) { - // If the toggle view action mode is ActionModeShow, then Open is always - // true if the sender is the toggle view action - QAction *action = qobject_cast(sender()); - if (action == d->m_toggleViewAction && !d->m_toggleViewAction->isCheckable()) - open = true; - // If the dock widget state is different, then we really need to toggle // the state. If we are in the right state, then we simply make this // dock widget the current dock widget