From 33eeb5880b7d477887b714bf032884f3d5501096 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 3 Mar 2015 23:43:37 +0100 Subject: [PATCH] ProjectExplorer: Replace two uses of QAction::setData ... by a connection to a lambda. Change-Id: I32a276146cf6a4cfc79ae9c133a4cb5f0783c867 Reviewed-by: Daniel Teske --- .../kitmanagerconfigwidget.cpp | 19 +++++-------------- .../projectexplorer/kitmanagerconfigwidget.h | 1 - .../projectexplorer/projectexplorer.cpp | 19 ++++++++----------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/plugins/projectexplorer/kitmanagerconfigwidget.cpp b/src/plugins/projectexplorer/kitmanagerconfigwidget.cpp index 06f33d3f5b4..56476a45432 100644 --- a/src/plugins/projectexplorer/kitmanagerconfigwidget.cpp +++ b/src/plugins/projectexplorer/kitmanagerconfigwidget.cpp @@ -219,12 +219,15 @@ void KitManagerConfigWidget::addConfigWidget(KitConfigWidget *widget) QAction *action = new QAction(tr("Mark as Mutable"), 0); action->setCheckable(true); - action->setData(QVariant::fromValue(qobject_cast(widget))); action->setChecked(widget->isMutable()); action->setEnabled(!widget->isSticky()); widget->mainWidget()->addAction(action); widget->mainWidget()->setContextMenuPolicy(Qt::ActionsContextMenu); - connect(action, &QAction::toggled, this, &KitManagerConfigWidget::updateMutableState); + connect(action, &QAction::toggled, this, [this, widget, action] { + widget->setMutable(action->isChecked()); + emit dirty(); + }); + m_actions << action; int row = m_layout->rowCount(); @@ -363,18 +366,6 @@ void KitManagerConfigWidget::kitWasUpdated(Kit *k) updateVisibility(); } -void KitManagerConfigWidget::updateMutableState() -{ - QAction *action = qobject_cast(sender()); - if (!action) - return; - KitConfigWidget *widget = qobject_cast(action->data().value()); - if (!widget) - return; - widget->setMutable(action->isChecked()); - emit dirty(); -} - QLabel *KitManagerConfigWidget::createLabel(const QString &name, const QString &toolTip) { QLabel *label = new QLabel(name); diff --git a/src/plugins/projectexplorer/kitmanagerconfigwidget.h b/src/plugins/projectexplorer/kitmanagerconfigwidget.h index 750ed14eab4..2d00ef0c6b1 100644 --- a/src/plugins/projectexplorer/kitmanagerconfigwidget.h +++ b/src/plugins/projectexplorer/kitmanagerconfigwidget.h @@ -85,7 +85,6 @@ private slots: void setFileSystemFriendlyName(); void workingCopyWasUpdated(ProjectExplorer::Kit *k); void kitWasUpdated(ProjectExplorer::Kit *k); - void updateMutableState(); private: enum LayoutColumns { diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index faef1ed2cfb..97be5283c66 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -266,7 +266,7 @@ public: void updateRecentProjectMenu(); void clearRecentProjects(); - void openRecentProject(); + void openRecentProject(const QString &fileName); void updateUnloadProjectMenu(); void openTerminalHere(); @@ -2830,12 +2830,13 @@ void ProjectExplorerPluginPrivate::updateRecentProjectMenu() //projects (ignore sessions, they used to be in this list) const StringPairListConstIterator end = dd->m_recentProjects.constEnd(); for (StringPairListConstIterator it = dd->m_recentProjects.constBegin(); it != end; ++it) { - const QPair &s = *it; - if (s.first.endsWith(QLatin1String(".qws"))) + const QString fileName = it->first; + if (fileName.endsWith(QLatin1String(".qws"))) continue; - QAction *action = menu->addAction(Utils::withTildeHomePath(s.first)); - action->setData(s.first); - connect(action, &QAction::triggered, this, &ProjectExplorerPluginPrivate::openRecentProject); + QAction *action = menu->addAction(Utils::withTildeHomePath(fileName)); + connect(action, &QAction::triggered, this, [this, fileName] { + openRecentProject(fileName); + }); hasRecentProjects = true; } menu->setEnabled(hasRecentProjects); @@ -2856,15 +2857,11 @@ void ProjectExplorerPluginPrivate::clearRecentProjects() updateWelcomePage(); } -void ProjectExplorerPluginPrivate::openRecentProject() +void ProjectExplorerPluginPrivate::openRecentProject(const QString &fileName) { if (debug) qDebug() << "ProjectExplorerPlugin::openRecentProject()"; - QAction *a = qobject_cast(sender()); - if (!a) - return; - QString fileName = a->data().toString(); if (!fileName.isEmpty()) { QString errorMessage; ProjectExplorerPlugin::openProject(fileName, &errorMessage);