forked from qt-creator/qt-creator
Make IProjectPanelFactory a value based class
Change-Id: I40f9411f305ab7764b904306bbccd45887dc7432 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -54,7 +54,12 @@ bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *err
|
||||
Q_UNUSED(arguments)
|
||||
Q_UNUSED(errorMessage)
|
||||
|
||||
addAutoReleasedObject(new ClangProjectSettingsPanelFactory);
|
||||
auto panelFactory = new ProjectExplorer::IProjectPanelFactory();
|
||||
panelFactory->setPriority(60);
|
||||
panelFactory->setDisplayName(ClangProjectSettingsWidget::tr("Clang Settings"));
|
||||
panelFactory->setSimpleCreatePanelFunction<ClangProjectSettingsWidget>(QIcon());
|
||||
|
||||
addAutoReleasedObject(panelFactory);
|
||||
|
||||
ClangCodeModel::Internal::initializeClang();
|
||||
|
||||
|
@@ -38,31 +38,6 @@
|
||||
using namespace ProjectExplorer;
|
||||
using namespace ClangCodeModel::Internal;
|
||||
|
||||
QString ClangProjectSettingsPanelFactory::displayName() const
|
||||
{
|
||||
return ClangProjectSettingsWidget::tr("Clang Settings");
|
||||
}
|
||||
|
||||
int ClangProjectSettingsPanelFactory::priority() const
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
bool ClangProjectSettingsPanelFactory::supports(Project *project)
|
||||
{
|
||||
Q_UNUSED(project);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
PropertiesPanel *ClangProjectSettingsPanelFactory::createPanel(Project *project)
|
||||
{
|
||||
PropertiesPanel *panel = new PropertiesPanel;
|
||||
panel->setDisplayName(ClangProjectSettingsWidget::tr("Clang Settings"));
|
||||
panel->setWidget(new ClangProjectSettingsWidget(project));
|
||||
return panel;
|
||||
}
|
||||
|
||||
ClangProjectSettingsWidget::ClangProjectSettingsWidget(Project *project)
|
||||
: m_project(project)
|
||||
{
|
||||
|
@@ -39,15 +39,6 @@
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
class ClangProjectSettingsPanelFactory: public ProjectExplorer::IProjectPanelFactory
|
||||
{
|
||||
public:
|
||||
QString displayName() const;
|
||||
int priority() const;
|
||||
bool supports(ProjectExplorer::Project *project);
|
||||
ProjectExplorer::PropertiesPanel *createPanel(ProjectExplorer::Project *project);
|
||||
};
|
||||
|
||||
class ClangProjectSettingsWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@@ -38,31 +38,6 @@ using namespace TextEditor;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace ProjectExplorer::Internal;
|
||||
|
||||
QString CodeStyleSettingsPanelFactory::displayName() const
|
||||
{
|
||||
return QCoreApplication::translate("CodeStyleSettingsPanelFactory", "Code Style");
|
||||
}
|
||||
|
||||
int CodeStyleSettingsPanelFactory::priority() const
|
||||
{
|
||||
return 40;
|
||||
}
|
||||
|
||||
bool CodeStyleSettingsPanelFactory::supports(Project *project)
|
||||
{
|
||||
Q_UNUSED(project);
|
||||
return true;
|
||||
}
|
||||
|
||||
PropertiesPanel *CodeStyleSettingsPanelFactory::createPanel(Project *project)
|
||||
{
|
||||
PropertiesPanel *panel = new PropertiesPanel;
|
||||
panel->setWidget(new CodeStyleSettingsWidget(project));
|
||||
panel->setIcon(QIcon(QLatin1String(":/projectexplorer/images/CodeStyleSettings.png")));
|
||||
panel->setDisplayName(QCoreApplication::translate("CodeStyleSettingsPanel", "Code Style"));
|
||||
return panel;
|
||||
}
|
||||
|
||||
CodeStyleSettingsWidget::CodeStyleSettingsWidget(Project *project) : QWidget(), m_project(project)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
|
@@ -39,17 +39,6 @@ class EditorConfiguration;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class CodeStyleSettingsPanelFactory : public IProjectPanelFactory
|
||||
{
|
||||
public:
|
||||
QString displayName() const;
|
||||
int priority() const;
|
||||
PropertiesPanel *createPanel(Project *project);
|
||||
bool supports(Project *project);
|
||||
};
|
||||
|
||||
class CodeStyleSettingsWidget;
|
||||
|
||||
class CodeStyleSettingsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@@ -231,34 +231,5 @@ DependenciesWidget::DependenciesWidget(Project *project, QWidget *parent)
|
||||
layout->addSpacerItem(new QSpacerItem(0, 0 , QSizePolicy::Expanding, QSizePolicy::Fixed));
|
||||
}
|
||||
|
||||
//
|
||||
// DependenciesPanelFactory
|
||||
//
|
||||
|
||||
QString DependenciesPanelFactory::displayName() const
|
||||
{
|
||||
return QCoreApplication::translate("DependenciesPanelFactory", "Dependencies");
|
||||
}
|
||||
|
||||
int DependenciesPanelFactory::priority() const
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
|
||||
bool DependenciesPanelFactory::supports(Project *project)
|
||||
{
|
||||
Q_UNUSED(project);
|
||||
return true;
|
||||
}
|
||||
|
||||
PropertiesPanel *DependenciesPanelFactory::createPanel(Project *project)
|
||||
{
|
||||
PropertiesPanel *panel = new PropertiesPanel;
|
||||
panel->setWidget(new DependenciesWidget(project));
|
||||
panel->setIcon(QIcon(QLatin1String(":/projectexplorer/images/ProjectDependencies.png")));
|
||||
panel->setDisplayName(QCoreApplication::translate("DependenciesPanel", "Dependencies"));
|
||||
return panel;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -44,18 +44,6 @@ class Project;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class DependenciesPanelFactory : public IProjectPanelFactory
|
||||
{
|
||||
public:
|
||||
DependenciesPanelFactory() {}
|
||||
|
||||
QString displayName() const;
|
||||
int priority() const;
|
||||
bool supports(Project *project);
|
||||
PropertiesPanel *createPanel(Project *project);
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// DependenciesModel
|
||||
//
|
||||
|
@@ -37,31 +37,6 @@
|
||||
using namespace ProjectExplorer;
|
||||
using namespace ProjectExplorer::Internal;
|
||||
|
||||
QString EditorSettingsPanelFactory::displayName() const
|
||||
{
|
||||
return QCoreApplication::translate("EditorSettingsPanelFactory", "Editor");
|
||||
}
|
||||
|
||||
int EditorSettingsPanelFactory::priority() const
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
|
||||
bool EditorSettingsPanelFactory::supports(Project *project)
|
||||
{
|
||||
Q_UNUSED(project);
|
||||
return true;
|
||||
}
|
||||
|
||||
PropertiesPanel *EditorSettingsPanelFactory::createPanel(Project *project)
|
||||
{
|
||||
PropertiesPanel *panel = new PropertiesPanel;
|
||||
panel->setDisplayName(QCoreApplication::translate("EditorSettingsPanel", "Editor"));
|
||||
panel->setWidget(new EditorSettingsWidget(project)),
|
||||
panel->setIcon(QIcon(QLatin1String(":/projectexplorer/images/EditorSettings.png")));
|
||||
return panel;
|
||||
}
|
||||
|
||||
EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_project(project)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
|
@@ -39,15 +39,6 @@ class EditorConfiguration;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class EditorSettingsPanelFactory : public IProjectPanelFactory
|
||||
{
|
||||
public:
|
||||
QString displayName() const;
|
||||
int priority() const;
|
||||
PropertiesPanel *createPanel(Project *project);
|
||||
bool supports(Project *project);
|
||||
};
|
||||
|
||||
class EditorSettingsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
84
src/plugins/projectexplorer/iprojectproperties.cpp
Normal file
84
src/plugins/projectexplorer/iprojectproperties.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "iprojectproperties.h"
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
|
||||
IProjectPanelFactory::IProjectPanelFactory()
|
||||
: m_priority(0),
|
||||
m_supportsFunction(&supportsAllProjects)
|
||||
{}
|
||||
|
||||
int IProjectPanelFactory::priority() const
|
||||
{
|
||||
return m_priority;
|
||||
}
|
||||
|
||||
void IProjectPanelFactory::setPriority(int priority)
|
||||
{
|
||||
m_priority = priority;
|
||||
}
|
||||
|
||||
QString IProjectPanelFactory::displayName() const
|
||||
{
|
||||
return m_displayName;
|
||||
}
|
||||
|
||||
void IProjectPanelFactory::setDisplayName(const QString &name)
|
||||
{
|
||||
m_displayName = name;
|
||||
}
|
||||
|
||||
bool IProjectPanelFactory::prioritySort(IProjectPanelFactory *a, IProjectPanelFactory *b)
|
||||
{
|
||||
return (a->priority() == b->priority() && a < b)
|
||||
|| a->priority() < b->priority();
|
||||
}
|
||||
|
||||
bool IProjectPanelFactory::supportsAllProjects(Project *)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IProjectPanelFactory::supports(Project *project)
|
||||
{
|
||||
return m_supportsFunction(project);
|
||||
}
|
||||
|
||||
void IProjectPanelFactory::setSupportsFunction(std::function<bool (Project *)> function)
|
||||
{
|
||||
m_supportsFunction = function;
|
||||
}
|
||||
|
||||
PropertiesPanel *IProjectPanelFactory::createPanel(Project *project)
|
||||
{
|
||||
return m_createPanelFunction(project);
|
||||
}
|
@@ -70,14 +70,49 @@ class PROJECTEXPLORER_EXPORT IProjectPanelFactory : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual bool supports(Project *project) = 0;
|
||||
virtual PropertiesPanel *createPanel(Project *project) = 0;
|
||||
IProjectPanelFactory();
|
||||
// simple properties
|
||||
QString displayName() const;
|
||||
void setDisplayName(const QString &name);
|
||||
int priority() const;
|
||||
void setPriority(int priority);
|
||||
|
||||
virtual QString displayName() const = 0;
|
||||
virtual int priority() const = 0;
|
||||
static bool prioritySort(IProjectPanelFactory *a, IProjectPanelFactory *b)
|
||||
{ return (a->priority() == b->priority() && a < b)
|
||||
|| a->priority() < b->priority(); }
|
||||
// helper to sort by priority
|
||||
static bool prioritySort(IProjectPanelFactory *a, IProjectPanelFactory *b);
|
||||
|
||||
// interface for users of IProjectPanelFactory
|
||||
bool supports(Project *project);
|
||||
ProjectExplorer::PropertiesPanel *createPanel(ProjectExplorer::Project *project);
|
||||
|
||||
// interface for "implementations" of IProjectPanelFactory
|
||||
// by default all projects are supported, only set a custom supports function
|
||||
// if you need something different
|
||||
void setSupportsFunction(std::function<bool (Project *)> function);
|
||||
|
||||
// the simpleCreatePanelFunction creates new instance of T
|
||||
// wraps that into a PropertiesPanel
|
||||
// sets the passed in icon on it
|
||||
// and uses displayName() for the displayname
|
||||
// Note: call setDisplayName before calling this
|
||||
template<typename T>
|
||||
void setSimpleCreatePanelFunction(const QIcon &icon)
|
||||
{
|
||||
m_createPanelFunction = [icon, this](Project *project) -> PropertiesPanel * {
|
||||
PropertiesPanel *panel = new PropertiesPanel;
|
||||
panel->setDisplayName(this->displayName());
|
||||
panel->setWidget(new T(project)),
|
||||
panel->setIcon(icon);
|
||||
return panel;
|
||||
};
|
||||
}
|
||||
|
||||
static bool supportsAllProjects(Project *);
|
||||
|
||||
private:
|
||||
int m_priority;
|
||||
QString m_displayName;
|
||||
std::function<bool (Project *)> m_supportsFunction;
|
||||
std::function<ProjectExplorer::PropertiesPanel *(Project *)> m_createPanelFunction;
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT ITargetPanelFactory : public QObject
|
||||
|
@@ -469,12 +469,43 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
|
||||
addAutoReleasedObject(new BuildSettingsPanelFactory);
|
||||
addAutoReleasedObject(new RunSettingsPanelFactory);
|
||||
addAutoReleasedObject(new EditorSettingsPanelFactory);
|
||||
addAutoReleasedObject(new CodeStyleSettingsPanelFactory);
|
||||
addAutoReleasedObject(new DependenciesPanelFactory);
|
||||
|
||||
// ProjectPanelFactories
|
||||
auto editorSettingsPanelFactory = new IProjectPanelFactory;
|
||||
editorSettingsPanelFactory->setPriority(30);
|
||||
QString displayName = QCoreApplication::translate("EditorSettingsPanelFactory", "Editor");
|
||||
editorSettingsPanelFactory->setDisplayName(displayName);
|
||||
QIcon icon = QIcon(QLatin1String(":/projectexplorer/images/EditorSettings.png"));
|
||||
editorSettingsPanelFactory->setSimpleCreatePanelFunction<EditorSettingsWidget>(icon);
|
||||
addAutoReleasedObject(editorSettingsPanelFactory);
|
||||
|
||||
auto codeStyleSettingsPanelFactory = new IProjectPanelFactory;
|
||||
codeStyleSettingsPanelFactory->setPriority(40);
|
||||
displayName = QCoreApplication::translate("CodeStyleSettingsPanelFactory", "Code Style");
|
||||
codeStyleSettingsPanelFactory->setDisplayName(displayName);
|
||||
icon = QIcon(QLatin1String(":/projectexplorer/images/CodeStyleSettings.png"));
|
||||
codeStyleSettingsPanelFactory->setSimpleCreatePanelFunction<CodeStyleSettingsWidget>(icon);
|
||||
addAutoReleasedObject(codeStyleSettingsPanelFactory);
|
||||
|
||||
auto dependenciesPanelFactory = new IProjectPanelFactory;
|
||||
dependenciesPanelFactory->setPriority(50);
|
||||
displayName = QCoreApplication::translate("DependenciesPanelFactory", "Dependencies");
|
||||
dependenciesPanelFactory->setDisplayName(displayName);
|
||||
icon = QIcon(QLatin1String(":/projectexplorer/images/ProjectDependencies.png"));
|
||||
dependenciesPanelFactory->setSimpleCreatePanelFunction<DependenciesWidget>(icon);
|
||||
addAutoReleasedObject(dependenciesPanelFactory);
|
||||
|
||||
auto unconfiguredProjectPanel = new IProjectPanelFactory;
|
||||
unconfiguredProjectPanel->setPriority(-10);
|
||||
unconfiguredProjectPanel->setDisplayName(tr("Configure Project"));
|
||||
unconfiguredProjectPanel->setSupportsFunction([](Project *project){
|
||||
return project->targets().isEmpty() && !project->requiresTargetPanel();
|
||||
});
|
||||
icon = QIcon(QLatin1String(":/projectexplorer/images/unconfigured.png"));
|
||||
unconfiguredProjectPanel->setSimpleCreatePanelFunction<TargetSetupPageWrapper>(icon);
|
||||
addAutoReleasedObject(unconfiguredProjectPanel);
|
||||
|
||||
addAutoReleasedObject(new ProcessStepFactory);
|
||||
addAutoReleasedObject(new UnconfiguredProjectPanel);
|
||||
|
||||
addAutoReleasedObject(new AllProjectsFind);
|
||||
addAutoReleasedObject(new CurrentProjectFind);
|
||||
|
@@ -281,7 +281,8 @@ SOURCES += projectexplorer.cpp \
|
||||
ipotentialkit.cpp \
|
||||
selectablefilesmodel.cpp \
|
||||
addnewmodel.cpp \
|
||||
xcodebuildparser.cpp
|
||||
xcodebuildparser.cpp \
|
||||
iprojectproperties.cpp
|
||||
|
||||
FORMS += processstep.ui \
|
||||
editorsettingspropertiespage.ui \
|
||||
|
@@ -85,7 +85,7 @@ QtcPlugin {
|
||||
"ipotentialkit.cpp",
|
||||
"ipotentialkit.h",
|
||||
"iprojectmanager.h",
|
||||
"iprojectproperties.h",
|
||||
"iprojectproperties.cpp", "iprojectproperties.h",
|
||||
"itaskhandler.h",
|
||||
"kit.cpp", "kit.h",
|
||||
"kitchooser.cpp", "kitchooser.h",
|
||||
|
@@ -48,36 +48,6 @@
|
||||
namespace ProjectExplorer {
|
||||
namespace Internal {
|
||||
|
||||
UnconfiguredProjectPanel::UnconfiguredProjectPanel()
|
||||
{
|
||||
}
|
||||
|
||||
QString UnconfiguredProjectPanel::displayName() const
|
||||
{
|
||||
return tr("Configure Project");
|
||||
}
|
||||
|
||||
int UnconfiguredProjectPanel::priority() const
|
||||
{
|
||||
return -10;
|
||||
}
|
||||
|
||||
bool UnconfiguredProjectPanel::supports(Project *project)
|
||||
{
|
||||
return project->targets().isEmpty() && !project->requiresTargetPanel();
|
||||
}
|
||||
|
||||
PropertiesPanel *UnconfiguredProjectPanel::createPanel(Project *project)
|
||||
{
|
||||
PropertiesPanel *panel = new PropertiesPanel;
|
||||
panel->setDisplayName(displayName());
|
||||
panel->setIcon(QIcon(QLatin1String(":/projectexplorer/images/unconfigured.png")));
|
||||
|
||||
TargetSetupPageWrapper *w = new TargetSetupPageWrapper(project);
|
||||
panel->setWidget(w);
|
||||
return panel;
|
||||
}
|
||||
|
||||
/////////
|
||||
/// TargetSetupPageWrapper
|
||||
////////
|
||||
|
@@ -42,17 +42,6 @@ class TargetSetupPage;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class UnconfiguredProjectPanel : public IProjectPanelFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UnconfiguredProjectPanel();
|
||||
virtual QString displayName() const;
|
||||
int priority() const;
|
||||
virtual bool supports(Project *project);
|
||||
virtual PropertiesPanel *createPanel(Project *project);
|
||||
};
|
||||
|
||||
class TargetSetupPageWrapper : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
Reference in New Issue
Block a user