Commit 269fe7f1 authored by dt's avatar dt
Browse files

New build and run settings ui.

Not finished 100%
parent 169f1b1b
...@@ -36,11 +36,10 @@ ...@@ -36,11 +36,10 @@
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QHash>
#include <QtCore/QPair> #include <QtCore/QPair>
#include <QtGui/QInputDialog> #include <QtGui/QInputDialog>
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QMenu> #include <QtGui/QVBoxLayout>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal; using namespace ProjectExplorer::Internal;
...@@ -84,6 +83,48 @@ QWidget *BuildSettingsPanel::widget() ...@@ -84,6 +83,48 @@ QWidget *BuildSettingsPanel::widget()
return m_widget; return m_widget;
} }
///
// BuildSettingsSubWidgets
///
BuildSettingsSubWidgets::~BuildSettingsSubWidgets()
{
clear();
}
void BuildSettingsSubWidgets::addWidget(const QString &name, QWidget *widget)
{
QLabel *label = new QLabel(this);
label->setText(name);
QFont f = label->font();
f.setBold(true);
f.setPointSizeF(f.pointSizeF() *1.2);
label->setFont(f);
layout()->addWidget(label);
layout()->addWidget(widget);
m_labels.append(label);
m_widgets.append(widget);
}
void BuildSettingsSubWidgets::clear()
{
qDeleteAll(m_widgets);
qDeleteAll(m_labels);
}
QList<QWidget *> BuildSettingsSubWidgets::widgets() const
{
return m_widgets;
}
BuildSettingsSubWidgets::BuildSettingsSubWidgets(QWidget *parent)
: QGroupBox(parent)
{
new QVBoxLayout(this);
}
/// ///
/// BuildSettingsWidget /// BuildSettingsWidget
/// ///
...@@ -95,62 +136,60 @@ BuildSettingsWidget::~BuildSettingsWidget() ...@@ -95,62 +136,60 @@ BuildSettingsWidget::~BuildSettingsWidget()
BuildSettingsWidget::BuildSettingsWidget(Project *project) BuildSettingsWidget::BuildSettingsWidget(Project *project)
: m_project(project) : m_project(project)
{ {
m_ui.setupUi(this); QVBoxLayout *vbox = new QVBoxLayout(this);
m_ui.splitter->setStretchFactor(1,10); QHBoxLayout *hbox = new QHBoxLayout();
m_ui.buildSettingsList->setContextMenuPolicy(Qt::CustomContextMenu); hbox->addWidget(new QLabel(tr("Build Configuration:"), this));
m_buildConfigurationComboBox = new QComboBox(this);
m_ui.addButton->setIcon(QIcon(Core::Constants::ICON_PLUS)); hbox->addWidget(m_buildConfigurationComboBox);
m_ui.addButton->setText("");
m_ui.removeButton->setIcon(QIcon(Core::Constants::ICON_MINUS)); m_addButton = new QPushButton(this);
m_ui.removeButton->setText(""); m_addButton->setText("Add");
m_addButton->setIcon(QIcon(Core::Constants::ICON_PLUS));
m_addButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
hbox->addWidget(m_addButton);
m_removeButton = new QPushButton(this);
m_removeButton->setText("Remove");
m_removeButton->setIcon(QIcon(Core::Constants::ICON_MINUS));
m_removeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
hbox->addWidget(m_removeButton);
hbox->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed));
vbox->addLayout(hbox);
m_subWidgets = new BuildSettingsSubWidgets(this);
vbox->addWidget(m_subWidgets);
QMenu *addButtonMenu = new QMenu(this); QMenu *addButtonMenu = new QMenu(this);
addButtonMenu->addAction(tr("Create &New"), addButtonMenu->addAction(tr("Create &New"),
this, SLOT(createConfiguration())); this, SLOT(createConfiguration()));
addButtonMenu->addAction(tr("&Clone Selected"), addButtonMenu->addAction(tr("&Clone Selected"),
this, SLOT(cloneConfiguration())); this, SLOT(cloneConfiguration()));
m_ui.addButton->setMenu(addButtonMenu); m_addButton->setMenu(addButtonMenu);
connect(m_buildConfigurationComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(currentIndexChanged(int)));
connect(m_ui.buildSettingsList, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), // TODO currentIndexChanged
this, SLOT(updateSettingsWidget(QTreeWidgetItem *, QTreeWidgetItem *))); // needs to change active configuration
connect(m_ui.buildSettingsList, SIGNAL(customContextMenuRequested (const QPoint &) ), // and set widgets
this, SLOT(showContextMenu(const QPoint &)));
connect(m_ui.buildSettingsList, SIGNAL(itemChanged(QTreeWidgetItem*,int) ),
this, SLOT(itemChanged(QTreeWidgetItem*)), Qt::QueuedConnection);
connect(m_ui.removeButton, SIGNAL(clicked()), connect(m_removeButton, SIGNAL(clicked()),
this, SLOT(deleteConfiguration())); this, SLOT(deleteConfiguration()));
connect(m_project, SIGNAL(activeBuildConfigurationChanged()), connect(m_project, SIGNAL(activeBuildConfigurationChanged()),
this, SLOT(updateBuildSettings())); this, SLOT(activeBuildConfigurationChanged()));
connect(m_project, SIGNAL(buildConfigurationDisplayNameChanged(const QString &)), connect(m_project, SIGNAL(buildConfigurationDisplayNameChanged(const QString &)),
this, SLOT(buildConfigurationDisplayNameChanged(const QString &))); this, SLOT(buildConfigurationDisplayNameChanged(const QString &)));
// remove dummy designer widget
while (QWidget *widget = m_ui.buildSettingsWidgets->currentWidget()) {
m_ui.buildSettingsWidgets->removeWidget(widget);
delete widget;
}
updateBuildSettings(); updateBuildSettings();
} }
void BuildSettingsWidget::buildConfigurationDisplayNameChanged(const QString &buildConfiguration) void BuildSettingsWidget::buildConfigurationDisplayNameChanged(const QString &buildConfiguration)
{ {
QTreeWidgetItem *rootItem = m_ui.buildSettingsList->invisibleRootItem();
for (int i = 0; i < rootItem->childCount(); ++i) { for (int i=0; i<m_buildConfigurationComboBox->count(); ++i) {
QTreeWidgetItem *child = rootItem->child(i); if (m_buildConfigurationComboBox->itemData(i).toString() == buildConfiguration) {
if (child->data(0, Qt::UserRole).toString() == buildConfiguration) { m_buildConfigurationComboBox->setItemText(i, m_project->displayNameFor(buildConfiguration));
child->setText(0, m_project->displayNameFor(buildConfiguration)); break;
if (m_ui.buildSettingsList->currentItem() == child) {
QWidget *widget = m_itemToWidget.value(child);
if (BuildStepConfigWidget *buildStepWidget = qobject_cast<BuildStepConfigWidget*>(widget)) {
QString title;
title = buildStepWidget->displayName();
m_ui.titleLabel->setText(tr("%1 - %2").arg(m_project->displayNameFor(buildConfiguration)).arg(title));
}
}
} }
} }
} }
...@@ -158,180 +197,64 @@ void BuildSettingsWidget::buildConfigurationDisplayNameChanged(const QString &bu ...@@ -158,180 +197,64 @@ void BuildSettingsWidget::buildConfigurationDisplayNameChanged(const QString &bu
void BuildSettingsWidget::updateBuildSettings() void BuildSettingsWidget::updateBuildSettings()
{ {
QTreeWidgetItem *rootItem = m_ui.buildSettingsList->invisibleRootItem();
// update buttons // TODO save position, entry from combbox
m_ui.removeButton->setEnabled(m_project->buildConfigurations().size() > 1);
// Save current selection
QString lastCurrentItem;
if (m_ui.buildSettingsList->currentItem())
lastCurrentItem = m_ui.buildSettingsList->currentItem()->text(0);
m_itemToWidget.clear();
// Delete old tree items // Delete old tree items
while (rootItem->childCount()) { m_buildConfigurationComboBox->blockSignals(true); // TODO ...
QTreeWidgetItem *configPageItem = rootItem->child(0); m_buildConfigurationComboBox->clear();
rootItem->removeChild(configPageItem); m_subWidgets->clear();
delete configPageItem; // does that delete also subitems?
}
// Delete old pages // update buttons
while (m_ui.buildSettingsWidgets->count()) { m_removeButton->setEnabled(m_project->buildConfigurations().size() > 1);
QWidget *w = m_ui.buildSettingsWidgets->widget(0);
m_ui.buildSettingsWidgets->removeWidget(w);
delete w;
}
// Add pages // Add pages
QWidget *dummyWidget = new QWidget(this);
QWidget *buildStepsWidget = new BuildStepsPage(m_project);
QWidget *cleanStepsWidget = new BuildStepsPage(m_project, true);
BuildStepConfigWidget *generalConfigWidget = m_project->createConfigWidget(); BuildStepConfigWidget *generalConfigWidget = m_project->createConfigWidget();
QList<BuildStepConfigWidget *> subConfigWidgets = m_project->subConfigWidgets(); m_subWidgets->addWidget(generalConfigWidget->displayName(), generalConfigWidget);
m_subWidgets->addWidget(tr("Build Steps"), new BuildStepsPage(m_project));
m_subWidgets->addWidget(tr("Clean Steps"), new BuildStepsPage(m_project, true));
m_ui.buildSettingsWidgets->addWidget(dummyWidget); QList<BuildStepConfigWidget *> subConfigWidgets = m_project->subConfigWidgets();
m_ui.buildSettingsWidgets->addWidget(buildStepsWidget);
m_ui.buildSettingsWidgets->addWidget(cleanStepsWidget);
m_ui.buildSettingsWidgets->addWidget(generalConfigWidget);
foreach (BuildStepConfigWidget *subConfigWidget, subConfigWidgets) foreach (BuildStepConfigWidget *subConfigWidget, subConfigWidgets)
m_ui.buildSettingsWidgets->addWidget(subConfigWidget); m_subWidgets->addWidget(subConfigWidget->displayName(), subConfigWidget);
// Add tree items // Add tree items
QTreeWidgetItem *activeConfigurationItem = 0;
QString activeBuildConfiguration = m_project->activeBuildConfiguration(); QString activeBuildConfiguration = m_project->activeBuildConfiguration();
foreach (const QString &buildConfiguration, m_project->buildConfigurations()) { foreach (const QString &buildConfiguration, m_project->buildConfigurations()) {
QString displayName = m_project->displayNameFor(buildConfiguration); m_buildConfigurationComboBox->addItem(m_project->displayNameFor(buildConfiguration), buildConfiguration);
QTreeWidgetItem *buildConfigItem = new QTreeWidgetItem(); if (buildConfiguration == activeBuildConfiguration)
m_itemToWidget.insert(buildConfigItem, generalConfigWidget); m_buildConfigurationComboBox->setCurrentIndex(m_buildConfigurationComboBox->count() - 1);
buildConfigItem->setText(0, displayName);
buildConfigItem->setData(0, Qt::UserRole, buildConfiguration);
buildConfigItem->setCheckState(0, Qt::Unchecked);
if (activeBuildConfiguration == buildConfiguration) {
QFont font = buildConfigItem->font(0);
font.setBold(true);
buildConfigItem->setFont(0, font);
buildConfigItem->setCheckState(0, Qt::Checked);
activeConfigurationItem = buildConfigItem;
}
rootItem->addChild(buildConfigItem);
QTreeWidgetItem *generalItem = new QTreeWidgetItem();
m_itemToWidget.insert(generalItem, generalConfigWidget);
generalItem->setText(0, tr("General"));
buildConfigItem->addChild(generalItem);
foreach (BuildStepConfigWidget *subConfigWidget, subConfigWidgets) {
QTreeWidgetItem *subConfigItem = new QTreeWidgetItem();
m_itemToWidget.insert(subConfigItem, subConfigWidget);
subConfigItem->setText(0, subConfigWidget->displayName());
buildConfigItem->addChild(subConfigItem);
}
QTreeWidgetItem *buildStepsItem = new QTreeWidgetItem();
m_itemToWidget.insert(buildStepsItem, buildStepsWidget);
buildStepsItem->setText(0, tr("Build Steps"));
buildConfigItem->addChild(buildStepsItem);
QTreeWidgetItem *cleanStepsItem = new QTreeWidgetItem();
m_itemToWidget.insert(cleanStepsItem, cleanStepsWidget);
cleanStepsItem->setText(0, tr("Clean Steps"));
buildConfigItem->addChild(cleanStepsItem);
} }
m_ui.buildSettingsList->expandAll(); // TODO ...
m_buildConfigurationComboBox->blockSignals(false);
// Restore selection // TODO Restore position, entry from combbox
if (!lastCurrentItem.isEmpty()) { // TODO? select entry from combobox ?
for (int i = rootItem->childCount() - 1; i >= 0; --i) { activeBuildConfigurationChanged();
if (rootItem->child(i)->text(0) == lastCurrentItem) {
m_ui.buildSettingsList->setCurrentItem(rootItem->child(i));
break;
}
}
}
if (!m_ui.buildSettingsList->currentItem()) {
if (activeConfigurationItem)
m_ui.buildSettingsList->setCurrentItem(activeConfigurationItem);
else
m_ui.buildSettingsList->setCurrentItem(m_ui.buildSettingsList->invisibleRootItem()->child(0));
}
} }
/* switch from one tree item / build step to another */ void BuildSettingsWidget::currentIndexChanged(int index)
void BuildSettingsWidget::updateSettingsWidget(QTreeWidgetItem *newItem, QTreeWidgetItem *oldItem)
{ {
if (oldItem == newItem) QString buildConfiguration = m_buildConfigurationComboBox->itemData(index).toString();
return; m_project->setActiveBuildConfiguration(buildConfiguration);
if (!newItem) {
QWidget *dummyWidget = m_ui.buildSettingsWidgets->widget(0);
m_ui.buildSettingsWidgets->setCurrentWidget(dummyWidget);
m_ui.titleLabel->clear();
return;
}
if (QWidget *widget = m_itemToWidget.value(newItem)) {
QString buildConfiguration;
{
QTreeWidgetItem *configurationItem = newItem;
while (configurationItem && configurationItem->parent())
configurationItem = configurationItem->parent();
if (configurationItem)
buildConfiguration = configurationItem->data(0, Qt::UserRole).toString();
}
QString title;
if (BuildStepConfigWidget *buildStepWidget = qobject_cast<BuildStepConfigWidget*>(widget)) {
title = buildStepWidget->displayName();
buildStepWidget->init(buildConfiguration);
}
m_ui.titleLabel->setText(tr("%1 - %2").arg(m_project->displayNameFor(buildConfiguration)).arg(title));
m_ui.buildSettingsWidgets->setCurrentWidget(widget);
}
} }
void BuildSettingsWidget::activeBuildConfigurationChanged()
void BuildSettingsWidget::showContextMenu(const QPoint &point)
{ {
if (QTreeWidgetItem *item = m_ui.buildSettingsList->itemAt(point)) { const QString &activeBuildConfiguration = m_project->activeBuildConfiguration();
if (!item->parent()) { for (int i = 0; i < m_buildConfigurationComboBox->count(); ++i) {
const QString buildConfiguration = item->data(0, Qt::UserRole).toString(); if (m_buildConfigurationComboBox->itemData(i).toString() == activeBuildConfiguration) {
m_buildConfigurationComboBox->setCurrentIndex(i);
QMenu menu; break;
QAction *setAsActiveAction = new QAction(tr("Set as Active"), &menu); }
QAction *cloneAction = new QAction(tr("Clone"), &menu); }
QAction *deleteAction = new QAction(tr("Delete"), &menu); foreach (QWidget *widget, m_subWidgets->widgets()) {
if (BuildStepConfigWidget *buildStepWidget = qobject_cast<BuildStepConfigWidget*>(widget)) {
if (m_project->activeBuildConfiguration() == buildConfiguration) buildStepWidget->init(activeBuildConfiguration);
setAsActiveAction->setEnabled(false);
if (m_project->buildConfigurations().size() < 2)
deleteAction->setEnabled(false);
menu.addActions(QList<QAction*>() << setAsActiveAction << cloneAction << deleteAction);
QPoint globalPoint = m_ui.buildSettingsList->mapToGlobal(point);
QAction *action = menu.exec(globalPoint);
if (action == setAsActiveAction) {
setActiveConfiguration(buildConfiguration);
} else if (action == cloneAction) {
cloneConfiguration(buildConfiguration);
} else if (action == deleteAction) {
deleteConfiguration(buildConfiguration);
}
updateBuildSettings();
} }
} }
}
void BuildSettingsWidget::setActiveConfiguration()
{
const QString configuration = m_ui.buildSettingsList->currentItem()->data(0, Qt::UserRole).toString();
setActiveConfiguration(configuration);
} }
void BuildSettingsWidget::createConfiguration() void BuildSettingsWidget::createConfiguration()
...@@ -373,40 +296,16 @@ void BuildSettingsWidget::createConfiguration() ...@@ -373,40 +296,16 @@ void BuildSettingsWidget::createConfiguration()
void BuildSettingsWidget::cloneConfiguration() void BuildSettingsWidget::cloneConfiguration()
{ {
QTreeWidgetItem *configItem = m_ui.buildSettingsList->currentItem(); const QString configuration = m_buildConfigurationComboBox->itemData(m_buildConfigurationComboBox->currentIndex()).toString();
while (configItem->parent())
configItem = configItem->parent();
const QString configuration = configItem->data(0, Qt::UserRole).toString();
cloneConfiguration(configuration); cloneConfiguration(configuration);
} }
void BuildSettingsWidget::deleteConfiguration() void BuildSettingsWidget::deleteConfiguration()
{ {
QTreeWidgetItem *configItem = m_ui.buildSettingsList->currentItem(); const QString configuration = m_buildConfigurationComboBox->itemData(m_buildConfigurationComboBox->currentIndex()).toString();
while (configItem->parent())
configItem = configItem->parent();
const QString configuration = configItem->data(0, Qt::UserRole).toString();
deleteConfiguration(configuration); deleteConfiguration(configuration);
} }
void BuildSettingsWidget::itemChanged(QTreeWidgetItem *item)
{
// do not allow unchecking
if (item->checkState(0) == Qt::Unchecked)
item->setCheckState(0, Qt::Checked);
else {
setActiveConfiguration(item->data(0, Qt::UserRole).toString());
}
}
void BuildSettingsWidget::setActiveConfiguration(const QString &configuration)
{
if (configuration.isEmpty())
return;
m_project->setActiveBuildConfiguration(configuration);
}
void BuildSettingsWidget::cloneConfiguration(const QString &sourceConfiguration) void BuildSettingsWidget::cloneConfiguration(const QString &sourceConfiguration)
{ {
if (sourceConfiguration.isEmpty()) if (sourceConfiguration.isEmpty())
...@@ -440,9 +339,10 @@ void BuildSettingsWidget::cloneConfiguration(const QString &sourceConfiguration) ...@@ -440,9 +339,10 @@ void BuildSettingsWidget::cloneConfiguration(const QString &sourceConfiguration)
m_project->copyBuildConfiguration(sourceConfiguration, newBuildConfiguration); m_project->copyBuildConfiguration(sourceConfiguration, newBuildConfiguration);
m_project->setDisplayNameFor(newBuildConfiguration, newDisplayName); m_project->setDisplayNameFor(newBuildConfiguration, newDisplayName);
m_project->setActiveBuildConfiguration(newBuildConfiguration);
updateBuildSettings(); updateBuildSettings();
m_project->setActiveBuildConfiguration(newBuildConfiguration);
} }
void BuildSettingsWidget::deleteConfiguration(const QString &deleteConfiguration) void BuildSettingsWidget::deleteConfiguration(const QString &deleteConfiguration)
......
...@@ -31,7 +31,12 @@ ...@@ -31,7 +31,12 @@
#define BUILDSETTINGSPROPERTIESPAGE_H #define BUILDSETTINGSPROPERTIESPAGE_H
#include "iprojectproperties.h" #include "iprojectproperties.h"
#include "ui_buildsettingspropertiespage.h"
#include <QtCore/QHash>
#include <QtGui/QComboBox>
#include <QtGui/QPushButton>
#include <QtGui/QLabel>
#include <QtGui/QGroupBox>
namespace ProjectExplorer { namespace ProjectExplorer {
...@@ -39,6 +44,20 @@ class IBuildStepFactory; ...@@ -39,6 +44,20 @@ class IBuildStepFactory;
namespace Internal { namespace Internal {
class BuildSettingsSubWidgets : public QGroupBox
{
Q_OBJECT
public:
BuildSettingsSubWidgets(QWidget *parent);
~BuildSettingsSubWidgets();
void clear();
void addWidget(const QString &name, QWidget *widget);
QList<QWidget *> widgets() const;
private:
QList<QWidget *> m_widgets;
QList<QLabel *> m_labels;
};
class BuildSettingsPanelFactory : public IPanelFactory class BuildSettingsPanelFactory : public IPanelFactory
{ {
public: public:
...@@ -73,24 +92,24 @@ public: ...@@ -73,24 +92,24 @@ public:
private slots: private slots:
void buildConfigurationDisplayNameChanged(const QString &buildConfiguration); void buildConfigurationDisplayNameChanged(const QString &buildConfiguration);
void updateBuildSettings(); void updateBuildSettings();
void updateSettingsWidget(QTreeWidgetItem *newItem, QTreeWidgetItem *oldItem); void currentIndexChanged(int index);
void showContextMenu(const QPoint & pos); void activeBuildConfigurationChanged();
void setActiveConfiguration();
void createConfiguration(); void createConfiguration();
void cloneConfiguration(); void cloneConfiguration();
void deleteConfiguration(); void deleteConfiguration();
void itemChanged(QTreeWidgetItem *item);
private: private:
void setActiveConfiguration(const QString &configuration); void setActiveConfiguration(const QString &configuration);
void cloneConfiguration(const QString &toClone); void cloneConfiguration(const QString &toClone);
void deleteConfiguration(const QString &toDelete); void deleteConfiguration(const QString &toDelete);
Ui::BuildSettingsPropertiesPage m_ui;
Project *m_project; Project *m_project;
QHash<QTreeWidgetItem*, QWidget*> m_itemToWidget; QPushButton *m_addButton;
QPushButton *m_removeButton;
QComboBox *m_buildConfigurationComboBox;
BuildSettingsSubWidgets *m_subWidgets;
}; };
} // namespace Internal