summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2019-08-01 14:58:00 +0200
committerhjk <hjk@qt.io>2019-08-01 16:16:29 +0000
commit09e5c167bd19d8f93a26590487009e1c0fb35ff4 (patch)
tree9a56e689a839be07f7f38cb2ac7c93593c6b3d6a
parent72fe2c706ec0f3a1b23a91334af847517a283060 (diff)
downloadqt-creator-09e5c167bd19d8f93a26590487009e1c0fb35ff4.tar.gz
ProjectExplorer: Add convenience Project::addTargetFor{Default,}Kit
Less noise on the user side. Change-Id: I5cdf4af4910a3cc1ee0af1b43fcbc7329a6d59db Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/plugins/autotoolsprojectmanager/autotoolsproject.cpp6
-rw-r--r--src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp2
-rw-r--r--src/plugins/genericprojectmanager/genericproject.cpp6
-rw-r--r--src/plugins/projectexplorer/project.cpp32
-rw-r--r--src/plugins/projectexplorer/project.h6
-rw-r--r--src/plugins/projectexplorer/projectwindow.cpp8
-rw-r--r--src/plugins/projectexplorer/targetsettingspanel.cpp5
-rw-r--r--src/plugins/python/pythonplugin.cpp6
-rw-r--r--src/plugins/qmlprofiler/tests/qmlprofilerdetailsrewriter_test.cpp8
-rw-r--r--src/plugins/qmlprojectmanager/qmlproject.cpp6
10 files changed, 41 insertions, 44 deletions
diff --git a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp b/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp
index 89350e62cb..fa9c33f46a 100644
--- a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp
+++ b/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp
@@ -34,7 +34,6 @@
#include <projectexplorer/abi.h>
#include <projectexplorer/toolchain.h>
-#include <projectexplorer/kitmanager.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/buildsteplist.h>
@@ -105,9 +104,8 @@ Project::RestoreResult AutotoolsProject::fromMap(const QVariantMap &map, QString
// Load the project tree structure.
loadProjectTree();
- Kit *defaultKit = KitManager::defaultKit();
- if (!activeTarget() && defaultKit)
- addTarget(createTarget(defaultKit));
+ if (!activeTarget())
+ addTargetForDefaultKit();
return RestoreResult::Ok;
}
diff --git a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp
index 0dc865bd4e..a2d99b276e 100644
--- a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp
+++ b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp
@@ -405,7 +405,7 @@ CompilationDatabaseProject::CompilationDatabaseProject(const Utils::FilePath &pr
setPreferredKitPredicate([](const Kit *) { return false; });
m_kit.reset(KitManager::defaultKit()->clone());
- addTarget(createTarget(m_kit.get()));
+ addTargetForKit(m_kit.get());
connect(this, &CompilationDatabaseProject::rootProjectDirectoryChanged,
m_parseDelay, QOverload<>::of(&QTimer::start));
diff --git a/src/plugins/genericprojectmanager/genericproject.cpp b/src/plugins/genericprojectmanager/genericproject.cpp
index ffb1c7a3d6..0406c19749 100644
--- a/src/plugins/genericprojectmanager/genericproject.cpp
+++ b/src/plugins/genericprojectmanager/genericproject.cpp
@@ -45,7 +45,6 @@
#include <projectexplorer/deploymentdata.h>
#include <projectexplorer/headerpath.h>
#include <projectexplorer/kitinformation.h>
-#include <projectexplorer/kitmanager.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/target.h>
@@ -562,9 +561,8 @@ Project::RestoreResult GenericProject::fromMap(const QVariantMap &map, QString *
if (result != RestoreResult::Ok)
return result;
- Kit *defaultKit = KitManager::defaultKit();
- if (!activeTarget() && defaultKit)
- addTarget(createTarget(defaultKit));
+ if (!activeTarget())
+ addTargetForDefaultKit();
// Sanity check: We need both a buildconfiguration and a runconfiguration!
const QList<Target *> targetList = targets();
diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp
index 75349ef34c..b725481bbd 100644
--- a/src/plugins/projectexplorer/project.cpp
+++ b/src/plugins/projectexplorer/project.cpp
@@ -267,6 +267,27 @@ void Project::addTarget(std::unique_ptr<Target> &&t)
SessionManager::setActiveTarget(this, pointer, SetActive::Cascade);
}
+Target *Project::addTargetForDefaultKit()
+{
+ return addTargetForKit(KitManager::defaultKit());
+}
+
+Target *Project::addTargetForKit(Kit *kit)
+{
+ if (!kit || target(kit))
+ return nullptr;
+
+ auto t = std::make_unique<Target>(this, kit, Target::_constructor_tag{});
+ Target *pointer = t.get();
+
+ if (!setupTarget(pointer))
+ return {};
+
+ addTarget(std::move(t));
+
+ return pointer;
+}
+
bool Project::removeTarget(Target *target)
{
QTC_ASSERT(target && Utils::contains(d->m_targets, target), return false);
@@ -336,17 +357,6 @@ Tasks Project::projectIssues(const Kit *k) const
return {};
}
-std::unique_ptr<Target> Project::createTarget(Kit *k)
-{
- if (!k || target(k))
- return nullptr;
-
- auto t = std::make_unique<Target>(this, k, Target::_constructor_tag{});
- if (!setupTarget(t.get()))
- return {};
- return t;
-}
-
bool Project::copySteps(Target *sourceTarget, Target *newTarget)
{
QTC_ASSERT(newTarget, return false);
diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h
index 1703d92b9d..57dcb7cd6f 100644
--- a/src/plugins/projectexplorer/project.h
+++ b/src/plugins/projectexplorer/project.h
@@ -122,7 +122,8 @@ public:
EditorConfiguration *editorConfiguration() const;
// Target:
- void addTarget(std::unique_ptr<Target> &&target);
+ Target *addTargetForDefaultKit();
+ Target *addTargetForKit(Kit *kit);
bool removeTarget(Target *target);
QList<Target *> targets() const;
@@ -132,7 +133,6 @@ public:
Target *target(Kit *k) const;
virtual Tasks projectIssues(const Kit *k) const;
- std::unique_ptr<Target> createTarget(Kit *k);
static bool copySteps(Target *sourceTarget, Target *newTarget);
void saveSettings();
@@ -268,6 +268,8 @@ protected:
Utils::Environment activeBuildEnvironment() const;
private:
+ void addTarget(std::unique_ptr<Target> &&target);
+
void handleSubTreeChanged(FolderNode *node);
void setActiveTarget(Target *target);
ProjectPrivate *d;
diff --git a/src/plugins/projectexplorer/projectwindow.cpp b/src/plugins/projectexplorer/projectwindow.cpp
index 065de1e715..96cfc251d3 100644
--- a/src/plugins/projectexplorer/projectwindow.cpp
+++ b/src/plugins/projectexplorer/projectwindow.cpp
@@ -552,12 +552,8 @@ public:
BuildConfiguration *lastBc = nullptr;
for (const BuildInfo &info : projectImporter->import(path, false)) {
Target *target = project->target(info.kitId);
- if (!target) {
- std::unique_ptr<Target> newTarget = project->createTarget(KitManager::kit(info.kitId));
- target = newTarget.get();
- if (newTarget)
- project->addTarget(std::move(newTarget));
- }
+ if (!target)
+ target = project->addTargetForKit(KitManager::kit(info.kitId));
if (target) {
projectImporter->makePersistent(target->kit());
BuildConfiguration *bc = info.factory()->create(target, info);
diff --git a/src/plugins/projectexplorer/targetsettingspanel.cpp b/src/plugins/projectexplorer/targetsettingspanel.cpp
index c39d6f4969..3377c12ee0 100644
--- a/src/plugins/projectexplorer/targetsettingspanel.cpp
+++ b/src/plugins/projectexplorer/targetsettingspanel.cpp
@@ -407,8 +407,7 @@ public:
QTC_ASSERT(!data.isValid(), return false);
if (!isEnabled()) {
m_currentChild = DefaultPage;
- Kit *k = KitManager::kit(m_kitId);
- m_project->addTarget(m_project->createTarget(k));
+ m_project->addTargetForKit(KitManager::kit(m_kitId));
} else {
// Go to Run page, when on Run previously etc.
TargetItem *previousItem = parent()->currentTargetItem();
@@ -450,7 +449,7 @@ public:
QAction *enableAction = menu->addAction(tr("Enable Kit \"%1\" for Project \"%2\"").arg(kitName, projectName));
enableAction->setEnabled(isSelectable && m_kitId.isValid() && !isEnabled());
QObject::connect(enableAction, &QAction::triggered, [this, kit] {
- m_project->addTarget(m_project->createTarget(kit));
+ m_project->addTargetForKit(kit);
});
QAction *disableAction = menu->addAction(tr("Disable Kit \"%1\" for Project \"%2\"").arg(kitName, projectName));
diff --git a/src/plugins/python/pythonplugin.cpp b/src/plugins/python/pythonplugin.cpp
index 3dff835fc9..475062022b 100644
--- a/src/plugins/python/pythonplugin.cpp
+++ b/src/plugins/python/pythonplugin.cpp
@@ -38,7 +38,6 @@
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/buildtargetinfo.h>
-#include <projectexplorer/kitmanager.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/runcontrol.h>
#include <projectexplorer/runconfiguration.h>
@@ -726,9 +725,8 @@ Project::RestoreResult PythonProject::fromMap(const QVariantMap &map, QString *e
if (res == RestoreResult::Ok) {
refresh();
- Kit *defaultKit = KitManager::defaultKit();
- if (!activeTarget() && defaultKit)
- addTarget(createTarget(defaultKit));
+ if (!activeTarget())
+ addTargetForDefaultKit();
}
return res;
diff --git a/src/plugins/qmlprofiler/tests/qmlprofilerdetailsrewriter_test.cpp b/src/plugins/qmlprofiler/tests/qmlprofilerdetailsrewriter_test.cpp
index e189656a79..b3d1cbb511 100644
--- a/src/plugins/qmlprofiler/tests/qmlprofilerdetailsrewriter_test.cpp
+++ b/src/plugins/qmlprofiler/tests/qmlprofilerdetailsrewriter_test.cpp
@@ -223,13 +223,7 @@ void QmlProfilerDetailsRewriterTest::seedRewriter()
DummyProject *project = new DummyProject(Utils::FilePath::fromString(filename));
ProjectExplorer::SessionManager::addProject(project);
- {
- // Make sure the uniqe_ptr gets deleted before the project.
- // Otherwise we'll get a double free because the target is also parented to the project
- // and unique_ptr doesn't know anything about QObject parent/child relationships.
- std::unique_ptr<ProjectExplorer::Target> target = project->createTarget(kit.get());
- m_rewriter.populateFileFinder(target.get());
- }
+ m_rewriter.populateFileFinder(project->addTargetForKit(kit.get()));
ProjectExplorer::SessionManager::removeProject(project);
}
diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp
index 114676b315..2dd251d2a5 100644
--- a/src/plugins/qmlprojectmanager/qmlproject.cpp
+++ b/src/plugins/qmlprojectmanager/qmlproject.cpp
@@ -341,8 +341,10 @@ Project::RestoreResult QmlProject::fromMap(const QVariantMap &map, QString *erro
});
if (!kits.isEmpty()) {
- Kit *kit = kits.contains(KitManager::defaultKit()) ? KitManager::defaultKit() : kits.first();
- addTarget(createTarget(kit));
+ if (kits.contains(KitManager::defaultKit()))
+ addTargetForDefaultKit();
+ else
+ addTargetForKit(kits.first());
}
}