From 9260a6d7f930e8235ea0df08b3f7f6e23ce0ee38 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 19 Aug 2016 16:49:23 +0200 Subject: [PATCH] ExtensionSystem: Simplify PluginCollection There is no reason why it should be more than just a list of plugin specs. Saves a few symbols. Also simplify some related code. Change-Id: Ibaff64735e78e1454e1aca0b49cadb9e1030ee3c Reviewed-by: hjk --- src/libs/extensionsystem/extensionsystem.pro | 2 - src/libs/extensionsystem/extensionsystem.qbs | 2 - src/libs/extensionsystem/plugincollection.cpp | 62 ------------------- src/libs/extensionsystem/plugincollection.h | 53 ---------------- src/libs/extensionsystem/pluginmanager.cpp | 19 ++---- src/libs/extensionsystem/pluginmanager.h | 3 +- src/libs/extensionsystem/pluginmanager_p.h | 3 +- src/libs/extensionsystem/pluginview.cpp | 25 ++------ 8 files changed, 11 insertions(+), 158 deletions(-) delete mode 100644 src/libs/extensionsystem/plugincollection.cpp delete mode 100644 src/libs/extensionsystem/plugincollection.h diff --git a/src/libs/extensionsystem/extensionsystem.pro b/src/libs/extensionsystem/extensionsystem.pro index dce2b19b17d..e1596836297 100644 --- a/src/libs/extensionsystem/extensionsystem.pro +++ b/src/libs/extensionsystem/extensionsystem.pro @@ -21,7 +21,6 @@ HEADERS += pluginerrorview.h \ pluginspec_p.h \ pluginview.h \ optionsparser.h \ - plugincollection.h \ pluginerroroverview.h SOURCES += pluginerrorview.cpp \ plugindetailsview.cpp \ @@ -31,7 +30,6 @@ SOURCES += pluginerrorview.cpp \ pluginspec.cpp \ pluginview.cpp \ optionsparser.cpp \ - plugincollection.cpp \ pluginerroroverview.cpp FORMS += \ pluginerrorview.ui \ diff --git a/src/libs/extensionsystem/extensionsystem.qbs b/src/libs/extensionsystem/extensionsystem.qbs index 62c5b26ed55..97a165800b3 100644 --- a/src/libs/extensionsystem/extensionsystem.qbs +++ b/src/libs/extensionsystem/extensionsystem.qbs @@ -24,8 +24,6 @@ Project { "iplugin_p.h", "optionsparser.cpp", "optionsparser.h", - "plugincollection.cpp", - "plugincollection.h", "plugindetailsview.cpp", "plugindetailsview.h", "plugindetailsview.ui", diff --git a/src/libs/extensionsystem/plugincollection.cpp b/src/libs/extensionsystem/plugincollection.cpp deleted file mode 100644 index 83cfe15b21d..00000000000 --- a/src/libs/extensionsystem/plugincollection.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "plugincollection.h" -#include "pluginspec.h" - -namespace ExtensionSystem { - -PluginCollection::PluginCollection(const QString& name) : - m_name(name) -{ - -} - -PluginCollection::~PluginCollection() -{ - -} - -QString PluginCollection::name() const -{ - return m_name; -} - -void PluginCollection::addPlugin(PluginSpec *spec) -{ - m_plugins.append(spec); -} - -void PluginCollection::removePlugin(PluginSpec *spec) -{ - m_plugins.removeOne(spec); -} - -QList PluginCollection::plugins() const -{ - return m_plugins; -} - -} diff --git a/src/libs/extensionsystem/plugincollection.h b/src/libs/extensionsystem/plugincollection.h deleted file mode 100644 index fd38bcedffe..00000000000 --- a/src/libs/extensionsystem/plugincollection.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "extensionsystem_global.h" - -#include -#include - -namespace ExtensionSystem { -class PluginSpec; - -class EXTENSIONSYSTEM_EXPORT PluginCollection -{ - -public: - explicit PluginCollection(const QString& name); - ~PluginCollection(); - - QString name() const; - void addPlugin(PluginSpec *spec); - void removePlugin(PluginSpec *spec); - QList plugins() const; -private: - QString m_name; - QList m_plugins; - -}; - -} // namespace ExtensionSystem diff --git a/src/libs/extensionsystem/pluginmanager.cpp b/src/libs/extensionsystem/pluginmanager.cpp index 554861729c9..5296de1c2d8 100644 --- a/src/libs/extensionsystem/pluginmanager.cpp +++ b/src/libs/extensionsystem/pluginmanager.cpp @@ -29,7 +29,6 @@ #include "pluginspec_p.h" #include "optionsparser.h" #include "iplugin.h" -#include "plugincollection.h" #include #include @@ -531,7 +530,7 @@ QList PluginManager::plugins() return d->pluginSpecs; } -QHash PluginManager::pluginCollections() +QHash > PluginManager::pluginCollections() { return d->pluginCategories; } @@ -852,7 +851,6 @@ PluginManagerPrivate::PluginManagerPrivate(PluginManager *pluginManager) : PluginManagerPrivate::~PluginManagerPrivate() { qDeleteAll(pluginSpecs); - qDeleteAll(pluginCategories); } /*! @@ -1421,13 +1419,12 @@ static QStringList pluginFiles(const QStringList &pluginPaths) */ void PluginManagerPrivate::readPluginPaths() { - qDeleteAll(pluginCategories); qDeleteAll(pluginSpecs); pluginSpecs.clear(); pluginCategories.clear(); - auto defaultCollection = new PluginCollection(QString()); - pluginCategories.insert(QString(), defaultCollection); + // default + pluginCategories.insert(QString(), QList()); foreach (const QString &pluginFile, pluginFiles(pluginPaths)) { PluginSpec *spec = new PluginSpec; @@ -1436,14 +1433,6 @@ void PluginManagerPrivate::readPluginPaths() continue; } - PluginCollection *collection = 0; - // find correct plugin collection or create a new one - if (pluginCategories.contains(spec->category())) { - collection = pluginCategories.value(spec->category()); - } else { - collection = new PluginCollection(spec->category()); - pluginCategories.insert(spec->category(), collection); - } // defaultDisabledPlugins and defaultEnabledPlugins from install settings // is used to override the defaults read from the plugin spec if (spec->isEnabledByDefault() && defaultDisabledPlugins.contains(spec->name())) { @@ -1458,7 +1447,7 @@ void PluginManagerPrivate::readPluginPaths() if (spec->isEnabledByDefault() && disabledPlugins.contains(spec->name())) spec->d->setEnabledBySettings(false); - collection->addPlugin(spec); + pluginCategories[spec->category()].append(spec); pluginSpecs.append(spec); } resolveDependencies(); diff --git a/src/libs/extensionsystem/pluginmanager.h b/src/libs/extensionsystem/pluginmanager.h index d427601fb53..fac52eaf071 100644 --- a/src/libs/extensionsystem/pluginmanager.h +++ b/src/libs/extensionsystem/pluginmanager.h @@ -37,7 +37,6 @@ class QSettings; QT_END_NAMESPACE namespace ExtensionSystem { -class PluginCollection; class IPlugin; class PluginSpec; @@ -116,7 +115,7 @@ public: static QString pluginIID(); static void setPluginIID(const QString &iid); static QList plugins(); - static QHash pluginCollections(); + static QHash> pluginCollections(); static bool hasError(); static QSet pluginsRequiringPlugin(PluginSpec *spec); static QSet pluginsRequiredByPlugin(PluginSpec *spec); diff --git a/src/libs/extensionsystem/pluginmanager_p.h b/src/libs/extensionsystem/pluginmanager_p.h index ec1f04e1286..f6b1bced362 100644 --- a/src/libs/extensionsystem/pluginmanager_p.h +++ b/src/libs/extensionsystem/pluginmanager_p.h @@ -45,7 +45,6 @@ QT_END_NAMESPACE namespace ExtensionSystem { class PluginManager; -class PluginCollection; namespace Internal { @@ -96,7 +95,7 @@ public: testSpecs = Utils::filtered(testSpecs, [pluginSpec](const TestSpec &s) { return s.pluginSpec != pluginSpec; }); } - QHash pluginCategories; + QHash> pluginCategories; QList pluginSpecs; QList testSpecs; QStringList pluginPaths; diff --git a/src/libs/extensionsystem/pluginview.cpp b/src/libs/extensionsystem/pluginview.cpp index 97be17a2745..02fde5917da 100644 --- a/src/libs/extensionsystem/pluginview.cpp +++ b/src/libs/extensionsystem/pluginview.cpp @@ -27,7 +27,6 @@ #include "pluginmanager.h" #include "pluginspec.h" #include "pluginspec_p.h" -#include "plugincollection.h" #include #include @@ -71,7 +70,6 @@ */ Q_DECLARE_METATYPE(ExtensionSystem::PluginSpec*) -Q_DECLARE_METATYPE(ExtensionSystem::PluginCollection*) using namespace Utils; @@ -371,26 +369,13 @@ void PluginView::updatePlugins() // Model. m_model->clear(); - PluginCollection *defaultCollection = 0; + QList collections; - foreach (PluginCollection *collection, PluginManager::pluginCollections()) { - if (collection->name().isEmpty() || collection->plugins().isEmpty()) { - defaultCollection = collection; - continue; - } - collections.append(new CollectionItem(collection->name(), collection->plugins(), this)); + auto end = PluginManager::pluginCollections().cend(); + for (auto it = PluginManager::pluginCollections().cbegin(); it != end; ++it) { + const QString name = it.key().isEmpty() ? tr("Utilities") : it.key(); + collections.append(new CollectionItem(name, it.value(), this)); } - - QList plugins; - if (defaultCollection) - plugins = defaultCollection->plugins(); - - if (!plugins.isEmpty()) { - // add all non-categorized plugins into utilities. could also be added as root items - // but that makes the tree ugly. - collections.append(new CollectionItem(tr("Utilities"), plugins, this)); - } - Utils::sort(collections, &CollectionItem::m_name); foreach (CollectionItem *collection, collections)