Commit 70dc7599 authored by dt's avatar dt

Simplfy code dealing with the projects page

Distinguish between pages that are target specific and project specific.
Do the magic hierarchy reduction if only one target is supported just in
the projectwindow. Treat the targets page specially.

Reviewed-By: hunger
parent 184fd353
......@@ -65,23 +65,11 @@ QString BuildSettingsPanelFactory::displayName() const
return QCoreApplication::translate("BuildSettingsPanelFactory", "Build Settings");
}
bool BuildSettingsPanelFactory::supports(Project *project)
{
return project->targets().count() == 1;
}
bool BuildSettingsPanelFactory::supports(Target *target)
{
return target->buildConfigurationFactory();
}
IPropertiesPanel *BuildSettingsPanelFactory::createPanel(Project *project)
{
Q_ASSERT(supports(project));
return new BuildSettingsPanel(project->activeTarget());
}
IPropertiesPanel *BuildSettingsPanelFactory::createPanel(Target *target)
{
return new BuildSettingsPanel(target);
......
......@@ -51,14 +51,13 @@ namespace Internal {
const char * const BUILDSETTINGS_PANEL_ID("ProjectExplorer.BuildSettingsPanel");
class BuildSettingsPanelFactory : public IPanelFactory
class BuildSettingsPanelFactory : public ITargetPanelFactory
{
public:
QString id() const;
QString displayName() const;
bool supports(Project *project);
bool supports(Target *target);
IPropertiesPanel *createPanel(Project *project);
IPropertiesPanel *createPanel(Target *target);
};
......
......@@ -308,22 +308,10 @@ bool DependenciesPanelFactory::supports(Project *project)
return true;
}
bool DependenciesPanelFactory::supports(Target *target)
{
Q_UNUSED(target);
return false;
}
IPropertiesPanel *DependenciesPanelFactory::createPanel(Project *project)
{
return new DependenciesPanel(m_session, project);
}
IPropertiesPanel *DependenciesPanelFactory::createPanel(Target *target)
{
Q_UNUSED(target);
return 0;
}
} // namespace Internal
} // namespace ProjectExplorer
......@@ -51,7 +51,7 @@ const char * const DEPENDENCIES_PANEL_ID("ProjectExplorer.DependenciesPanel");
class DependenciesWidget;
class DependenciesPanelFactory : public IPanelFactory
class DependenciesPanelFactory : public IProjectPanelFactory
{
public:
DependenciesPanelFactory(SessionManager *session);
......@@ -59,10 +59,7 @@ public:
QString id() const;
QString displayName() const;
bool supports(Project *project);
bool supports(Target *target);
IPropertiesPanel *createPanel(Project *project);
IPropertiesPanel *createPanel(Target *target);
private:
SessionManager *m_session;
};
......
......@@ -54,23 +54,11 @@ bool EditorSettingsPanelFactory::supports(Project *project)
return true;
}
bool EditorSettingsPanelFactory::supports(Target *target)
{
Q_UNUSED(target);
return false;
}
IPropertiesPanel *EditorSettingsPanelFactory::createPanel(Project *project)
{
return new EditorSettingsPanel(project);
}
IPropertiesPanel *EditorSettingsPanelFactory::createPanel(Target *target)
{
Q_UNUSED(target);
return 0;
}
EditorSettingsPanel::EditorSettingsPanel(Project *project) :
m_widget(new EditorSettingsWidget(project)),
m_icon(":/projectexplorer/images/EditorSettings.png")
......
......@@ -39,15 +39,13 @@ namespace Internal {
const char * const EDITORSETTINGS_PANEL_ID("ProjectExplorer.EditorSettingsPanel");
class EditorSettingsPanelFactory : public IPanelFactory
class EditorSettingsPanelFactory : public IProjectPanelFactory
{
public:
QString id() const;
QString displayName() const;
bool supports(Project *project);
bool supports(Target *target);
IPropertiesPanel *createPanel(Project *project);
IPropertiesPanel *createPanel(Target *target);
bool supports(Project *project);
};
class EditorSettingsWidget;
......
......@@ -47,8 +47,7 @@ class PROJECTEXPLORER_EXPORT IPropertiesPanel
public:
enum PanelFlag {
NoFlag = 0x00,
NoLeftMargin = 0x01,
NoAutomaticStyle = 0x02
NoLeftMargin = 0x01
};
Q_DECLARE_FLAGS(PanelFlags, PanelFlag)
......@@ -69,9 +68,21 @@ class PROJECTEXPLORER_EXPORT IPanelFactory : public QObject
public:
virtual QString id() const = 0;
virtual QString displayName() const = 0;
};
class PROJECTEXPLORER_EXPORT IProjectPanelFactory : public IPanelFactory
{
Q_OBJECT
public:
virtual bool supports(Project *project) = 0;
virtual bool supports(Target *target) = 0;
virtual IPropertiesPanel *createPanel(Project *project) = 0;
};
class PROJECTEXPLORER_EXPORT ITargetPanelFactory : public IPanelFactory
{
Q_OBJECT
public:
virtual bool supports(Target *target) = 0;
virtual IPropertiesPanel *createPanel(Target *target) = 0;
};
......
......@@ -304,7 +304,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
addAutoReleasedObject(new BuildSettingsPanelFactory);
addAutoReleasedObject(new RunSettingsPanelFactory);
addAutoReleasedObject(new TargetSettingsPanelFactory);
addAutoReleasedObject(new EditorSettingsPanelFactory);
addAutoReleasedObject(new DependenciesPanelFactory(d->m_session));
......
......@@ -72,28 +72,7 @@ const int ABOVE_HEADING_MARGIN(10);
const int ABOVE_CONTENTS_MARGIN(4);
const int BELOW_CONTENTS_MARGIN(16);
bool skipPanelFactory(Project *project, IPanelFactory *factory)
{
bool simplifyTargets(project->supportedTargetIds().count() <= 1);
if (simplifyTargets) {
// Do not show the targets list:
if (factory->id() == QLatin1String(TARGETSETTINGS_PANEL_ID))
return true;
// Skip build settigns if none are available anyway:
if (project->activeTarget() &&
!project->activeTarget()->buildConfigurationFactory() &&
factory->id() == QLatin1String(BUILDSETTINGS_PANEL_ID))
return true;
} else {
// Skip panels embedded into the targets panel:
if (factory->id() == QLatin1String(BUILDSETTINGS_PANEL_ID) ||
factory->id() == QLatin1String(RUNSETTINGS_PANEL_ID))
return true;
}
return false;
}
} // namespace
} // anonymous namespace
///
// OnePixelBlackLine
......@@ -251,8 +230,7 @@ void PanelsWidget::addPanelWidget(IPropertiesPanel *panel, int row)
ProjectWindow::ProjectWindow(QWidget *parent)
: QWidget(parent),
m_currentWidget(0),
m_currentPanel(0)
m_currentWidget(0)
{
ProjectExplorer::SessionManager *session = ProjectExplorerPlugin::instance()->session();
......@@ -314,10 +292,26 @@ void ProjectWindow::registerProject(ProjectExplorer::Project *project)
}
QStringList subtabs;
foreach (IPanelFactory *panelFactory, ExtensionSystem::PluginManager::instance()->getObjects<IPanelFactory>()) {
if (skipPanelFactory(project, panelFactory))
continue;
subtabs << panelFactory->displayName();
if (project->supportedTargetIds().count() <= 1) {
// Show the target specific pages directly
QList<ITargetPanelFactory *> factories =
ExtensionSystem::PluginManager::instance()->getObjects<ITargetPanelFactory>();
foreach (ITargetPanelFactory *factory, factories) {
if (factory->supports(project->activeTarget()))
subtabs << factory->displayName();
}
} else {
// Use the Targets page
subtabs << QCoreApplication::translate("TargetSettingsPanelFactory", "Targets");
}
// Add the project specific pages
QList<IProjectPanelFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<IProjectPanelFactory>();
foreach (IProjectPanelFactory *panelFactory, factories) {
if (panelFactory->supports(project))
subtabs << panelFactory->displayName();
}
m_tabIndexToProject.insert(index, project);
......@@ -378,26 +372,59 @@ void ProjectWindow::showProperties(int index, int subIndex)
// Set up custom panels again:
int pos = 0;
foreach (IPanelFactory *panelFactory, ExtensionSystem::PluginManager::instance()->getObjects<IPanelFactory>()) {
if (skipPanelFactory(project, panelFactory))
continue;
if (pos == subIndex) {
IPanelFactory *fac = 0;
if (project->supportedTargetIds().count() > 1) {
if (subIndex == 0) {
// Targets page
removeCurrentWidget();
IPropertiesPanel *panel(panelFactory->createPanel(project));
if (panel->flags() & IPropertiesPanel::NoAutomaticStyle) {
m_currentWidget = panel->widget();
m_currentPanel = panel;
} else {
PanelsWidget *panelsWidget = new PanelsWidget(m_centralWidget);
panelsWidget->addPropertiesPanel(panel);
m_currentWidget = panelsWidget;
}
m_currentWidget = new TargetSettingsPanelWidget(project);
m_centralWidget->addWidget(m_currentWidget);
m_centralWidget->setCurrentWidget(m_currentWidget);
break;
}
++pos;
} else {
// No Targets page, target specific pages are first in the list
foreach (ITargetPanelFactory *panelFactory, ExtensionSystem::PluginManager::instance()->getObjects<ITargetPanelFactory>()) {
if (panelFactory->supports(project->activeTarget())) {
if (subIndex == pos) {
fac = panelFactory;
break;
}
++pos;
}
}
}
if (!fac) {
foreach (IProjectPanelFactory *panelFactory, ExtensionSystem::PluginManager::instance()->getObjects<IProjectPanelFactory>()) {
if (panelFactory->supports(project)) {
if (subIndex == pos) {
fac = panelFactory;
break;
}
++pos;
}
}
}
if (fac) {
removeCurrentWidget();
IPropertiesPanel *panel;
if (ITargetPanelFactory *ipf = qobject_cast<ITargetPanelFactory *>(fac))
panel = ipf->createPanel(project->activeTarget());
else if (IProjectPanelFactory *ipf = qobject_cast<IProjectPanelFactory *>(fac))
panel = ipf->createPanel(project);
Q_ASSERT(panel);
PanelsWidget *panelsWidget = new PanelsWidget(m_centralWidget);
panelsWidget->addPropertiesPanel(panel);
m_currentWidget = panelsWidget;
m_centralWidget->addWidget(m_currentWidget);
m_centralWidget->setCurrentWidget(m_currentWidget);
}
ProjectExplorerPlugin::instance()->session()->setStartupProject(project);
}
......@@ -405,11 +432,7 @@ void ProjectWindow::removeCurrentWidget()
{
if (m_currentWidget) {
m_centralWidget->removeWidget(m_currentWidget);
if (m_currentPanel) {
delete m_currentPanel;
m_currentPanel = 0;
m_currentWidget = 0; // is deleted by the panel
} else if (m_currentWidget) {
if (m_currentWidget) {
delete m_currentWidget;
m_currentWidget = 0;
}
......
......@@ -102,7 +102,6 @@ private:
DoubleTabWidget *m_tabWidget;
QStackedWidget *m_centralWidget;
QWidget *m_currentWidget;
IPropertiesPanel *m_currentPanel;
QList<ProjectExplorer::Project *> m_tabIndexToProject;
};
......
......@@ -74,23 +74,12 @@ QString RunSettingsPanelFactory::displayName() const
return QCoreApplication::translate("RunSettingsPanelFactory", "Run Settings");
}
bool RunSettingsPanelFactory::supports(Project *project)
{
return project->targets().count() == 1;
}
bool RunSettingsPanelFactory::supports(Target *target)
{
Q_UNUSED(target);
return true;
}
IPropertiesPanel *RunSettingsPanelFactory::createPanel(Project *project)
{
Q_ASSERT(supports(project));
return new RunSettingsPanel(project->activeTarget());
}
IPropertiesPanel *RunSettingsPanelFactory::createPanel(Target *target)
{
return new RunSettingsPanel(target);
......
......@@ -55,14 +55,12 @@ class RunSettingsPropertiesPage;
class RunConfigurationsModel;
class RunSettingsWidget;
class RunSettingsPanelFactory : public IPanelFactory
class RunSettingsPanelFactory : public ITargetPanelFactory
{
public:
QString id() const;
QString displayName() const;
bool supports(Project *project);
bool supports(Target *target);
IPropertiesPanel *createPanel(Project *project);
IPropertiesPanel *createPanel(Target *target);
};
......
......@@ -47,71 +47,6 @@
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
///
// TargetSettingsPanelFactory
///
QString TargetSettingsPanelFactory::id() const
{
return QLatin1String(TARGETSETTINGS_PANEL_ID);
}
QString TargetSettingsPanelFactory::displayName() const
{
return QCoreApplication::translate("TargetSettingsPanelFactory", "Targets");
}
bool TargetSettingsPanelFactory::supports(Project *project)
{
Q_UNUSED(project);
return true;
}
bool TargetSettingsPanelFactory::supports(Target *target)
{
Q_UNUSED(target);
return false;
}
IPropertiesPanel *TargetSettingsPanelFactory::createPanel(Project *project)
{
return new TargetSettingsPanel(project);
}
IPropertiesPanel *TargetSettingsPanelFactory::createPanel(Target *target)
{
Q_UNUSED(target);
return 0;
}
///
// TargetSettingsPanel
///
TargetSettingsPanel::TargetSettingsPanel(Project *project) :
m_widget(new TargetSettingsPanelWidget(project))
{
}
TargetSettingsPanel::~TargetSettingsPanel()
{
delete m_widget;
}
QString TargetSettingsPanel::displayName() const
{
return QCoreApplication::translate("TargetSettingsPanel", "Targets");
}
QWidget *TargetSettingsPanel::widget() const
{
return m_widget;
}
QIcon TargetSettingsPanel::icon() const
{
return QIcon();
}
///
// TargetSettingsWidget
......@@ -223,7 +158,7 @@ void TargetSettingsPanelWidget::currentTargetChanged(int targetIndex, int subInd
PanelsWidget *buildPanel(new PanelsWidget(m_centralWidget));
PanelsWidget *runPanel(new PanelsWidget(m_centralWidget));
foreach (IPanelFactory *panelFactory, ExtensionSystem::PluginManager::instance()->getObjects<IPanelFactory>()) {
foreach (ITargetPanelFactory *panelFactory, ExtensionSystem::PluginManager::instance()->getObjects<ITargetPanelFactory>()) {
if (panelFactory->id() == QLatin1String(BUILDSETTINGS_PANEL_ID)) {
IPropertiesPanel *panel = panelFactory->createPanel(target);
buildPanel->addPropertiesPanel(panel);
......
......@@ -41,38 +41,9 @@ class Target;
namespace Internal {
const char * const TARGETSETTINGS_PANEL_ID("ProjectExplorer.TargetSettingsPanel");
class TargetSettingsWidget;
class PanelsWidget;
class TargetSettingsPanelFactory : public IPanelFactory
{
public:
QString id() const;
QString displayName() const;
bool supports(Project *project);
bool supports(Target *target);
IPropertiesPanel *createPanel(Project *project);
IPropertiesPanel *createPanel(Target *target);
};
class TargetSettingsPanelWidget;
class TargetSettingsPanel : public IPropertiesPanel
{
public:
TargetSettingsPanel(Project *project);
~TargetSettingsPanel();
QString displayName() const;
QWidget *widget() const;
QIcon icon() const;
PanelFlags flags() const { return IPropertiesPanel::NoAutomaticStyle; }
private:
TargetSettingsPanelWidget *m_widget;
};
class TargetSettingsPanelWidget : public QWidget
{
Q_OBJECT
......
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