CrumblePath: Avoid using sender()

Change-Id: I4aa2e6646707e6f69bf0a69530638546b94162fd
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2022-07-19 17:52:32 +02:00
parent 98ba797f76
commit 54465acb15
2 changed files with 6 additions and 12 deletions

View File

@@ -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<QAction*>(element))
emit elementClicked(action->data());
else if (auto *button = qobject_cast<CrumblePathButton*>(element))
emit elementClicked(button->data());
}
} // namespace Utils
#include "crumblepath.moc"

View File

@@ -56,7 +56,6 @@ signals:
void elementClicked(const QVariant &data);
private:
void emitElementClicked();
void setBackgroundStyle();
private: