From 54465acb15b372e2783b041b2b68f50218884b70 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 19 Jul 2022 17:52:32 +0200 Subject: [PATCH] CrumblePath: Avoid using sender() Change-Id: I4aa2e6646707e6f69bf0a69530638546b94162fd Reviewed-by: Eike Ziller Reviewed-by: --- src/libs/utils/crumblepath.cpp | 17 ++++++----------- src/libs/utils/crumblepath.h | 1 - 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/libs/utils/crumblepath.cpp b/src/libs/utils/crumblepath.cpp index fbf7586575d..d53dd3b992a 100644 --- a/src/libs/utils/crumblepath.cpp +++ b/src/libs/utils/crumblepath.cpp @@ -210,7 +210,9 @@ void CrumblePath::pushElement(const QString &title, const QVariant &data) auto *newButton = new CrumblePathButton(title, this); newButton->setData(data); m_buttonsLayout->addWidget(newButton); - connect(newButton, &QAbstractButton::clicked, this, &CrumblePath::emitElementClicked); + connect(newButton, &QAbstractButton::clicked, this, [this, newButton] { + emit elementClicked(newButton->data()); + }); if (m_buttons.empty()) { newButton->setSegmentType(CrumblePathButton::SingleSegment); @@ -235,7 +237,9 @@ void CrumblePath::addChild(const QString &title, const QVariant &data) auto *childAction = new QAction(title, lastButton); childAction->setData(data); - connect(childAction, &QAction::triggered, this, &CrumblePath::emitElementClicked); + connect(childAction, &QAction::triggered, this, [this, childAction] { + emit elementClicked(childAction->data()); + }); childList->addAction(childAction); lastButton->setMenu(childList); } @@ -262,15 +266,6 @@ void CrumblePath::clear() popElement(); } -void CrumblePath::emitElementClicked() -{ - QObject *element = sender(); - if (auto *action = qobject_cast(element)) - emit elementClicked(action->data()); - else if (auto *button = qobject_cast(element)) - emit elementClicked(button->data()); -} - } // namespace Utils #include "crumblepath.moc" diff --git a/src/libs/utils/crumblepath.h b/src/libs/utils/crumblepath.h index 990522d7337..88be75ceeb5 100644 --- a/src/libs/utils/crumblepath.h +++ b/src/libs/utils/crumblepath.h @@ -56,7 +56,6 @@ signals: void elementClicked(const QVariant &data); private: - void emitElementClicked(); void setBackgroundStyle(); private: