ProjectExplorer: Replace two uses of QAction::setData

... by a connection to a lambda.

Change-Id: I32a276146cf6a4cfc79ae9c133a4cb5f0783c867
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
hjk
2015-03-03 23:43:37 +01:00
parent e36b40161e
commit 33eeb5880b
3 changed files with 13 additions and 26 deletions

View File

@@ -219,12 +219,15 @@ void KitManagerConfigWidget::addConfigWidget(KitConfigWidget *widget)
QAction *action = new QAction(tr("Mark as Mutable"), 0); QAction *action = new QAction(tr("Mark as Mutable"), 0);
action->setCheckable(true); action->setCheckable(true);
action->setData(QVariant::fromValue(qobject_cast<QObject *>(widget)));
action->setChecked(widget->isMutable()); action->setChecked(widget->isMutable());
action->setEnabled(!widget->isSticky()); action->setEnabled(!widget->isSticky());
widget->mainWidget()->addAction(action); widget->mainWidget()->addAction(action);
widget->mainWidget()->setContextMenuPolicy(Qt::ActionsContextMenu); 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; m_actions << action;
int row = m_layout->rowCount(); int row = m_layout->rowCount();
@@ -363,18 +366,6 @@ void KitManagerConfigWidget::kitWasUpdated(Kit *k)
updateVisibility(); updateVisibility();
} }
void KitManagerConfigWidget::updateMutableState()
{
QAction *action = qobject_cast<QAction *>(sender());
if (!action)
return;
KitConfigWidget *widget = qobject_cast<KitConfigWidget *>(action->data().value<QObject *>());
if (!widget)
return;
widget->setMutable(action->isChecked());
emit dirty();
}
QLabel *KitManagerConfigWidget::createLabel(const QString &name, const QString &toolTip) QLabel *KitManagerConfigWidget::createLabel(const QString &name, const QString &toolTip)
{ {
QLabel *label = new QLabel(name); QLabel *label = new QLabel(name);

View File

@@ -85,7 +85,6 @@ private slots:
void setFileSystemFriendlyName(); void setFileSystemFriendlyName();
void workingCopyWasUpdated(ProjectExplorer::Kit *k); void workingCopyWasUpdated(ProjectExplorer::Kit *k);
void kitWasUpdated(ProjectExplorer::Kit *k); void kitWasUpdated(ProjectExplorer::Kit *k);
void updateMutableState();
private: private:
enum LayoutColumns { enum LayoutColumns {

View File

@@ -266,7 +266,7 @@ public:
void updateRecentProjectMenu(); void updateRecentProjectMenu();
void clearRecentProjects(); void clearRecentProjects();
void openRecentProject(); void openRecentProject(const QString &fileName);
void updateUnloadProjectMenu(); void updateUnloadProjectMenu();
void openTerminalHere(); void openTerminalHere();
@@ -2830,12 +2830,13 @@ void ProjectExplorerPluginPrivate::updateRecentProjectMenu()
//projects (ignore sessions, they used to be in this list) //projects (ignore sessions, they used to be in this list)
const StringPairListConstIterator end = dd->m_recentProjects.constEnd(); const StringPairListConstIterator end = dd->m_recentProjects.constEnd();
for (StringPairListConstIterator it = dd->m_recentProjects.constBegin(); it != end; ++it) { for (StringPairListConstIterator it = dd->m_recentProjects.constBegin(); it != end; ++it) {
const QPair<QString, QString> &s = *it; const QString fileName = it->first;
if (s.first.endsWith(QLatin1String(".qws"))) if (fileName.endsWith(QLatin1String(".qws")))
continue; continue;
QAction *action = menu->addAction(Utils::withTildeHomePath(s.first)); QAction *action = menu->addAction(Utils::withTildeHomePath(fileName));
action->setData(s.first); connect(action, &QAction::triggered, this, [this, fileName] {
connect(action, &QAction::triggered, this, &ProjectExplorerPluginPrivate::openRecentProject); openRecentProject(fileName);
});
hasRecentProjects = true; hasRecentProjects = true;
} }
menu->setEnabled(hasRecentProjects); menu->setEnabled(hasRecentProjects);
@@ -2856,15 +2857,11 @@ void ProjectExplorerPluginPrivate::clearRecentProjects()
updateWelcomePage(); updateWelcomePage();
} }
void ProjectExplorerPluginPrivate::openRecentProject() void ProjectExplorerPluginPrivate::openRecentProject(const QString &fileName)
{ {
if (debug) if (debug)
qDebug() << "ProjectExplorerPlugin::openRecentProject()"; qDebug() << "ProjectExplorerPlugin::openRecentProject()";
QAction *a = qobject_cast<QAction*>(sender());
if (!a)
return;
QString fileName = a->data().toString();
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
QString errorMessage; QString errorMessage;
ProjectExplorerPlugin::openProject(fileName, &errorMessage); ProjectExplorerPlugin::openProject(fileName, &errorMessage);