summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2018-07-03 11:49:25 +0200
committerTobias Hunger <tobias.hunger@qt.io>2018-07-11 08:29:19 +0000
commit05fb67fee72472f04991dc6579ace3b15e510177 (patch)
tree0a1a2b164f7da20651b8c208b36c3010250b2505
parent6aeb06c8d3889e03180d73db0a472ff619da887f (diff)
downloadqt-creator-05fb67fee72472f04991dc6579ace3b15e510177.tar.gz
ProjectExplorer: Use unique_ptr to store KitInformation
Change-Id: I406b6bed005fb7455e6ee41d81a2f314584a051a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/plugins/android/androidplugin.cpp2
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp6
-rw-r--r--src/plugins/debugger/debuggerplugin.cpp2
-rw-r--r--src/plugins/projectexplorer/kitmanager.cpp29
-rw-r--r--src/plugins/projectexplorer/kitmanager.h7
-rw-r--r--src/plugins/projectexplorer/projectexplorer.cpp10
-rw-r--r--src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp2
-rw-r--r--src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp2
-rw-r--r--src/plugins/qtsupport/qtsupportplugin.cpp2
9 files changed, 32 insertions, 30 deletions
diff --git a/src/plugins/android/androidplugin.cpp b/src/plugins/android/androidplugin.cpp
index eeee754605..2494ae79ba 100644
--- a/src/plugins/android/androidplugin.cpp
+++ b/src/plugins/android/androidplugin.cpp
@@ -117,7 +117,7 @@ bool AndroidPlugin::initialize(const QStringList &arguments, QString *errorMessa
d = new AndroidPluginPrivate;
- KitManager::registerKitInformation(new Internal::AndroidGdbServerKitInformation);
+ KitManager::registerKitInformation<Internal::AndroidGdbServerKitInformation>();
connect(KitManager::instance(), &KitManager::kitsLoaded,
this, &AndroidPlugin::kitsRestored);
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp
index da3b80d570..806c5f1ab8 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp
@@ -106,9 +106,9 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
new CMakeToolManager(this);
- KitManager::registerKitInformation(new CMakeKitInformation);
- KitManager::registerKitInformation(new CMakeGeneratorKitInformation);
- KitManager::registerKitInformation(new CMakeConfigurationKitInformation);
+ KitManager::registerKitInformation<CMakeKitInformation>();
+ KitManager::registerKitInformation<CMakeGeneratorKitInformation>();
+ KitManager::registerKitInformation<CMakeConfigurationKitInformation>();
//menus
ActionContainer *msubproject =
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 06041d474e..5a272201e8 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -3271,7 +3271,7 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
mstart->addSeparator(Constants::G_GENERAL);
mstart->addSeparator(Constants::G_SPECIAL);
- KitManager::registerKitInformation(new DebuggerKitInformation);
+ KitManager::registerKitInformation<DebuggerKitInformation>();
// Task integration.
//: Category under which Analyzer tasks are listed in Issues view
diff --git a/src/plugins/projectexplorer/kitmanager.cpp b/src/plugins/projectexplorer/kitmanager.cpp
index 4a25d19222..8485ee58d2 100644
--- a/src/plugins/projectexplorer/kitmanager.cpp
+++ b/src/plugins/projectexplorer/kitmanager.cpp
@@ -34,9 +34,9 @@
#include <coreplugin/icore.h>
-#include <utils/algorithm.h>
#include <utils/environment.h>
#include <utils/persistentsettings.h>
+#include <utils/pointeralgorithm.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
@@ -71,7 +71,7 @@ public:
Kit *m_defaultKit = nullptr;
bool m_initialized = false;
- QList<KitInformation *> m_informationList;
+ std::vector<std::unique_ptr<KitInformation>> m_informationList;
QList<Kit *> m_kitList;
PersistentSettingsWriter *m_writer = nullptr;
};
@@ -80,7 +80,6 @@ KitManagerPrivate::~KitManagerPrivate()
{
foreach (Kit *k, m_kitList)
delete k;
- qDeleteAll(m_informationList);
delete m_writer;
}
@@ -247,22 +246,20 @@ bool KitManager::isLoaded()
return d->m_initialized;
}
-static bool greaterPriority(KitInformation *a, KitInformation *b)
-{
- return a->priority() > b->priority();
-}
-
-void KitManager::registerKitInformation(KitInformation *ki)
+void KitManager::registerKitInformation(std::unique_ptr<KitInformation> &&ki)
{
QTC_CHECK(!isLoaded());
- QTC_ASSERT(!d->m_informationList.contains(ki), return );
QTC_ASSERT(ki->id().isValid(), return );
+ QTC_ASSERT(!Utils::contains(d->m_informationList, ki.get()), return );
- auto it = std::lower_bound(d->m_informationList.begin(),
- d->m_informationList.end(),
+ auto it = std::lower_bound(std::begin(d->m_informationList),
+ std::end(d->m_informationList),
ki,
- greaterPriority);
- d->m_informationList.insert(it, ki);
+ [](const std::unique_ptr<KitInformation> &a,
+ const std::unique_ptr<KitInformation> &b) {
+ return a->priority() > b->priority();
+ });
+ d->m_informationList.insert(it, std::move(ki));
if (!isLoaded())
return;
@@ -393,7 +390,7 @@ Kit *KitManager::defaultKit()
QList<KitInformation *> KitManager::kitInformation()
{
- return d->m_informationList;
+ return Utils::toRawPointer<QList>(d->m_informationList);
}
KitManagerConfigWidget *KitManager::createConfigWidget(Kit *k)
@@ -476,7 +473,7 @@ void KitManager::addKit(Kit *k)
{
KitGuard g(k);
- foreach (KitInformation *ki, d->m_informationList) {
+ for (const std::unique_ptr<KitInformation> &ki : d->m_informationList) {
ki->upgrade(k);
if (!k->hasValue(ki->id()))
k->setValue(ki->id(), ki->defaultValue(k));
diff --git a/src/plugins/projectexplorer/kitmanager.h b/src/plugins/projectexplorer/kitmanager.h
index 6c034db428..16377df37b 100644
--- a/src/plugins/projectexplorer/kitmanager.h
+++ b/src/plugins/projectexplorer/kitmanager.h
@@ -130,7 +130,10 @@ public:
static void deregisterKit(Kit *k);
static void setDefaultKit(Kit *k);
- static void registerKitInformation(KitInformation *ki);
+ template<typename KI, typename... Args>
+ static void registerKitInformation(Args&&... args) {
+ registerKitInformation(std::make_unique<KI>(std::forward<Args>(args)...));
+ }
static QSet<Core::Id> supportedPlatforms();
static QSet<Core::Id> availableFeatures(Core::Id platformId);
@@ -158,6 +161,8 @@ signals:
private:
explicit KitManager(QObject *parent = nullptr);
+ static void registerKitInformation(std::unique_ptr<KitInformation> &&ki);
+
// Make sure the this is only called after all
// KitInformation are registered!
void restoreKits();
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 74ae70c7b0..72f9eda205 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -556,11 +556,11 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
IWizardFactory::registerFeatureProvider(new KitFeatureProvider);
// Register KitInformation:
- KitManager::registerKitInformation(new DeviceTypeKitInformation);
- KitManager::registerKitInformation(new DeviceKitInformation);
- KitManager::registerKitInformation(new ToolChainKitInformation);
- KitManager::registerKitInformation(new SysRootKitInformation);
- KitManager::registerKitInformation(new EnvironmentKitInformation);
+ KitManager::registerKitInformation<DeviceTypeKitInformation>();
+ KitManager::registerKitInformation<DeviceKitInformation>();
+ KitManager::registerKitInformation<ToolChainKitInformation>();
+ KitManager::registerKitInformation<SysRootKitInformation>();
+ KitManager::registerKitInformation<EnvironmentKitInformation>();
IWizardFactory::registerFactoryCreator([]() -> QList<IWizardFactory *> {
QList<IWizardFactory *> result;
diff --git a/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp b/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp
index d75efe0186..e905ca9804 100644
--- a/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp
+++ b/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp
@@ -114,7 +114,7 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
Core::HelpManager::registerDocumentation({Core::ICore::documentationPath() + "/qbs.qch"});
ProjectManager::registerProjectType<QbsProject>(QmlJSTools::Constants::QBS_MIMETYPE);
- KitManager::registerKitInformation(new QbsKitInformation);
+ KitManager::registerKitInformation<QbsKitInformation>();
//menus
// Build Menu:
diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp
index 1703b5cc74..ccd4241c06 100644
--- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp
@@ -140,7 +140,7 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
//create and register objects
ProjectManager::registerProjectType<QmakeProject>(QmakeProjectManager::Constants::PROFILE_MIMETYPE);
- ProjectExplorer::KitManager::registerKitInformation(new QmakeKitInformation);
+ ProjectExplorer::KitManager::registerKitInformation<QmakeKitInformation>();
IWizardFactory::registerFactoryCreator([] {
return QList<IWizardFactory *> {
diff --git a/src/plugins/qtsupport/qtsupportplugin.cpp b/src/plugins/qtsupport/qtsupportplugin.cpp
index 30ac0e21e8..2d99d01e38 100644
--- a/src/plugins/qtsupport/qtsupportplugin.cpp
+++ b/src/plugins/qtsupport/qtsupportplugin.cpp
@@ -84,7 +84,7 @@ bool QtSupportPlugin::initialize(const QStringList &arguments, QString *errorMes
d = new QtSupportPluginPrivate;
- ProjectExplorer::KitManager::registerKitInformation(new QtKitInformation);
+ ProjectExplorer::KitManager::registerKitInformation<QtKitInformation>();
(void) new UicGeneratorFactory(this);
(void) new QScxmlcGeneratorFactory(this);