Commit e83847d7 authored by Daniel Teske's avatar Daniel Teske

IProjectPanelFactores: Use own registration method instead of object pool

Change-Id: I8bfe793e5b5f2ebbb953c986249e4d30261b5e24
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 5aa1b506
......@@ -31,6 +31,8 @@
using namespace ProjectExplorer;
QList<IProjectPanelFactory *> IProjectPanelFactory::s_factories;
IProjectPanelFactory::IProjectPanelFactory()
: m_priority(0),
m_supportsFunction(&supportsAllProjects)
......@@ -67,6 +69,17 @@ bool IProjectPanelFactory::supportsAllProjects(Project *)
return true;
}
void IProjectPanelFactory::registerFactory(IProjectPanelFactory *factory)
{
auto it = std::lower_bound(s_factories.begin(), s_factories.end(), factory, &IProjectPanelFactory::prioritySort);
s_factories.insert(it, factory);
}
QList<IProjectPanelFactory *> IProjectPanelFactory::factories()
{
return s_factories;
}
bool IProjectPanelFactory::supports(Project *project)
{
return m_supportsFunction(project);
......
......@@ -34,7 +34,6 @@
#include "propertiespanel.h"
#include "panelswidget.h"
#include <QObject>
#include <QIcon>
#include <QWidget>
......@@ -44,9 +43,8 @@ namespace ProjectExplorer {
class Project;
class Target;
class PROJECTEXPLORER_EXPORT IProjectPanelFactory : public QObject
class PROJECTEXPLORER_EXPORT IProjectPanelFactory
{
Q_OBJECT
public:
IProjectPanelFactory();
// simple properties
......@@ -93,11 +91,16 @@ public:
static bool supportsAllProjects(Project *);
static void registerFactory(IProjectPanelFactory *factory);
static QList<IProjectPanelFactory *> factories();
private:
int m_priority;
QString m_displayName;
std::function<bool (Project *)> m_supportsFunction;
std::function<QWidget *(Project *)> m_createWidgetFunction;
static QList<IProjectPanelFactory *> s_factories;
};
} // namespace ProjectExplorer
......
......@@ -321,6 +321,7 @@ ProjectExplorerPlugin::~ProjectExplorerPlugin()
// Force sequence of deletion:
delete d->m_kitManager; // remove all the profile informations
delete d->m_toolChainManager;
qDeleteAll(IProjectPanelFactory::s_factories);
delete d;
}
......@@ -476,7 +477,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
editorSettingsPanelFactory->setDisplayName(displayName);
QIcon icon = QIcon(QLatin1String(":/projectexplorer/images/EditorSettings.png"));
editorSettingsPanelFactory->setSimpleCreateWidgetFunction<EditorSettingsWidget>(icon);
addAutoReleasedObject(editorSettingsPanelFactory);
IProjectPanelFactory::registerFactory(editorSettingsPanelFactory);
auto codeStyleSettingsPanelFactory = new IProjectPanelFactory;
codeStyleSettingsPanelFactory->setPriority(40);
......@@ -484,7 +485,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
codeStyleSettingsPanelFactory->setDisplayName(displayName);
icon = QIcon(QLatin1String(":/projectexplorer/images/CodeStyleSettings.png"));
codeStyleSettingsPanelFactory->setSimpleCreateWidgetFunction<CodeStyleSettingsWidget>(icon);
addAutoReleasedObject(codeStyleSettingsPanelFactory);
IProjectPanelFactory::registerFactory(codeStyleSettingsPanelFactory);
auto dependenciesPanelFactory = new IProjectPanelFactory;
dependenciesPanelFactory->setPriority(50);
......@@ -492,7 +493,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
dependenciesPanelFactory->setDisplayName(displayName);
icon = QIcon(QLatin1String(":/projectexplorer/images/ProjectDependencies.png"));
dependenciesPanelFactory->setSimpleCreateWidgetFunction<DependenciesWidget>(icon);
addAutoReleasedObject(dependenciesPanelFactory);
IProjectPanelFactory::registerFactory(dependenciesPanelFactory);
auto unconfiguredProjectPanel = new IProjectPanelFactory;
unconfiguredProjectPanel->setPriority(-10);
......@@ -502,7 +503,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
});
icon = QIcon(QLatin1String(":/projectexplorer/images/unconfigured.png"));
unconfiguredProjectPanel->setSimpleCreateWidgetFunction<TargetSetupPageWrapper>(icon);
addAutoReleasedObject(unconfiguredProjectPanel);
IProjectPanelFactory::registerFactory(unconfiguredProjectPanel);
auto targetSettingsPanelFactory = new IProjectPanelFactory;
targetSettingsPanelFactory->setPriority(-10);
......@@ -515,7 +516,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
targetSettingsPanelFactory->setCreateWidgetFunction([](Project *project) {
return new TargetSettingsPanelWidget(project);
});
addAutoReleasedObject(targetSettingsPanelFactory);
IProjectPanelFactory::registerFactory(targetSettingsPanelFactory);
addAutoReleasedObject(new ProcessStepFactory);
......
......@@ -120,10 +120,8 @@ void ProjectWindow::projectUpdated(Project *p)
QStringList ProjectWindow::tabDisplayNamesFor(Project *project)
{
QList<IProjectPanelFactory *> factories = ExtensionSystem::PluginManager::getObjects<IProjectPanelFactory>();
Utils::sort(factories, &IProjectPanelFactory::prioritySort);
QStringList subTabs;
foreach (IProjectPanelFactory *panelFactory, factories) {
foreach (IProjectPanelFactory *panelFactory, IProjectPanelFactory::factories()) {
if (panelFactory->supports(project))
subTabs << panelFactory->displayName();
}
......@@ -218,9 +216,7 @@ void ProjectWindow::showProperties(int index, int subIndex)
int pos = 0;
IProjectPanelFactory *fac = 0;
QList<IProjectPanelFactory *> factories = ExtensionSystem::PluginManager::getObjects<IProjectPanelFactory>();
Utils::sort(factories, &IProjectPanelFactory::prioritySort);
foreach (IProjectPanelFactory *panelFactory, factories) {
foreach (IProjectPanelFactory *panelFactory, IProjectPanelFactory::factories()) {
if (panelFactory->supports(project)) {
if (subIndex == pos) {
fac = panelFactory;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment