Commit dbe5a6f3 authored by dt's avatar dt
Browse files

Rework the project settings.

This has still a few missing things, but this enough to start getting
some feedback. Missing are non qt projects, a solution for the
runconfiguration, a missing black line between the treeview on top and
the project settings at the bottom. Some flickering with removing/adding
widgets to the QScrollArea and not showing the expanded widget if the
Details button is right at the bottom.
parent 4e788157
......@@ -40,7 +40,7 @@ using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
CMakeBuildEnvironmentWidget::CMakeBuildEnvironmentWidget(CMakeProject *project)
: BuildStepConfigWidget(), m_pro(project)
: BuildConfigWidget(), m_pro(project)
{
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0);
......
......@@ -43,7 +43,7 @@ namespace CMakeProjectManager {
namespace Internal {
class CMakeProject;
class CMakeBuildEnvironmentWidget : public ProjectExplorer::BuildStepConfigWidget
class CMakeBuildEnvironmentWidget : public ProjectExplorer::BuildConfigWidget
{
Q_OBJECT
......
......@@ -512,14 +512,14 @@ QString CMakeProject::buildDirectory(const QString &buildConfiguration) const
return buildDirectory;
}
ProjectExplorer::BuildStepConfigWidget *CMakeProject::createConfigWidget()
ProjectExplorer::BuildConfigWidget *CMakeProject::createConfigWidget()
{
return new CMakeBuildSettingsWidget(this);
}
QList<ProjectExplorer::BuildStepConfigWidget*> CMakeProject::subConfigWidgets()
QList<ProjectExplorer::BuildConfigWidget*> CMakeProject::subConfigWidgets()
{
QList<ProjectExplorer::BuildStepConfigWidget*> list;
QList<ProjectExplorer::BuildConfigWidget*> list;
list << new CMakeBuildEnvironmentWidget(this);
return list;
}
......
......@@ -89,8 +89,8 @@ public:
virtual QString buildDirectory(const QString &buildConfiguration) const;
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
virtual QList<ProjectExplorer::BuildStepConfigWidget*> subConfigWidgets();
virtual ProjectExplorer::BuildConfigWidget *createConfigWidget();
virtual QList<ProjectExplorer::BuildConfigWidget*> subConfigWidgets();
// This method is called for new build configurations
// You should probably set some default values in this method
......@@ -204,7 +204,7 @@ private:
QString m_fileName;
};
class CMakeBuildSettingsWidget : public ProjectExplorer::BuildStepConfigWidget
class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
{
Q_OBJECT
public:
......
......@@ -145,6 +145,18 @@ void MakeStep::setAdditionalArguments(const QString &buildConfiguration, const Q
setValue(buildConfiguration, "additionalArguments", list);
}
// TODO
//QString MakeStep::oneLineSummary(const QString &buildConfiguration)
//{
// QStringList arguments = value(buildConfiguration, "buildTargets").toStringList();
// arguments << additionalArguments(buildConfiguration);
// return tr("<b>%1 %2</b> in %3").arg(
// m_pro->toolChain(buildConfiguration)->makeCommand(),
// arguments.join(" "),
// m_pro->buildDirectory(buildConfiguration));
//
//}
//
// MakeStepConfigWidget
//
......@@ -214,6 +226,12 @@ void MakeStepConfigWidget::init(const QString &buildConfiguration)
m_additionalArguments->setText(ProjectExplorer::Environment::joinArgumentList(m_makeStep->additionalArguments(m_buildConfiguration)));
}
QString MakeStepConfigWidget::summaryText() const
{
// TODO
return tr("<b>Make:</b>");
}
//
// MakeStepFactory
//
......
......@@ -78,6 +78,7 @@ public:
MakeStepConfigWidget(MakeStep *makeStep);
virtual QString displayName() const;
virtual void init(const QString &buildConfiguration);
virtual QString summaryText() const;
private slots:
void itemChanged(QListWidgetItem*);
void additionalArgumentsEdited();
......
......@@ -193,6 +193,12 @@ void GenericMakeStepConfigWidget::init(const QString &buildConfiguration)
connect(m_ui->targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
}
QString GenericMakeStepConfigWidget::summaryText() const
{
// TODO
return tr("<b>Make:</b>");
}
void GenericMakeStepConfigWidget::itemChanged(QListWidgetItem *item)
{
QTC_ASSERT(!m_buildConfiguration.isNull(), return);
......
......@@ -73,6 +73,7 @@ public:
GenericMakeStepConfigWidget(GenericMakeStep *makeStep);
virtual QString displayName() const;
virtual void init(const QString &buildConfiguration);
virtual QString summaryText() const;
private slots:
void itemChanged(QListWidgetItem*);
void makeLineEditTextEdited();
......
......@@ -427,14 +427,14 @@ QString GenericProject::buildDirectory(const QString &buildConfiguration) const
return buildDirectory;
}
ProjectExplorer::BuildStepConfigWidget *GenericProject::createConfigWidget()
ProjectExplorer::BuildConfigWidget *GenericProject::createConfigWidget()
{
return new GenericBuildSettingsWidget(this);
}
QList<ProjectExplorer::BuildStepConfigWidget*> GenericProject::subConfigWidgets()
QList<ProjectExplorer::BuildConfigWidget*> GenericProject::subConfigWidgets()
{
return QList<ProjectExplorer::BuildStepConfigWidget*>();
return QList<ProjectExplorer::BuildConfigWidget*>();
}
void GenericProject::newBuildConfiguration(const QString &buildConfiguration)
......
......@@ -82,8 +82,8 @@ public:
virtual ProjectExplorer::Environment environment(const QString &buildConfiguration) const;
virtual QString buildDirectory(const QString &buildConfiguration) const;
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
virtual QList<ProjectExplorer::BuildStepConfigWidget*> subConfigWidgets();
virtual ProjectExplorer::BuildConfigWidget *createConfigWidget();
virtual QList<ProjectExplorer::BuildConfigWidget*> subConfigWidgets();
virtual void newBuildConfiguration(const QString &buildConfiguration);
virtual GenericProjectNode *rootProjectNode() const;
......@@ -172,7 +172,7 @@ private:
QString m_fileName;
};
class GenericBuildSettingsWidget : public ProjectExplorer::BuildStepConfigWidget
class GenericBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
{
Q_OBJECT
......
......@@ -212,14 +212,14 @@ void BuildSettingsWidget::updateBuildSettings()
m_removeButton->setEnabled(m_project->buildConfigurations().size() > 1);
// Add pages
BuildStepConfigWidget *generalConfigWidget = m_project->createConfigWidget();
BuildConfigWidget *generalConfigWidget = m_project->createConfigWidget();
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));
QList<BuildStepConfigWidget *> subConfigWidgets = m_project->subConfigWidgets();
foreach (BuildStepConfigWidget *subConfigWidget, subConfigWidgets)
QList<BuildConfigWidget *> subConfigWidgets = m_project->subConfigWidgets();
foreach (BuildConfigWidget *subConfigWidget, subConfigWidgets)
m_subWidgets->addWidget(subConfigWidget->displayName(), subConfigWidget);
// Add tree items
......@@ -254,7 +254,7 @@ void BuildSettingsWidget::activeBuildConfigurationChanged()
}
}
foreach (QWidget *widget, m_subWidgets->widgets()) {
if (BuildStepConfigWidget *buildStepWidget = qobject_cast<BuildStepConfigWidget*>(widget)) {
if (BuildConfigWidget *buildStepWidget = qobject_cast<BuildConfigWidget*>(widget)) {
buildStepWidget->init(activeBuildConfiguration);
}
}
......
......@@ -131,8 +131,6 @@ Q_SIGNALS:
void addToTaskWindow(const QString &filename, int type, int linenumber, const QString &description);
void addToOutputWindow(const QString &string);
void displayNameChanged(BuildStep *, const QString &displayName);
private:
QList<Internal::BuildConfiguration *> buildConfigurations();
void addBuildConfiguration(const QString & name);
......@@ -164,22 +162,34 @@ public:
virtual QString displayNameForName(const QString &name) const = 0;
};
class PROJECTEXPLORER_EXPORT BuildStepConfigWidget
class PROJECTEXPLORER_EXPORT BuildConfigWidget
: public QWidget
{
Q_OBJECT
public:
BuildStepConfigWidget()
BuildConfigWidget()
:QWidget(0)
{}
virtual QString displayName() const = 0;
// This is called to set up the config widget before showing it
// buildConfiguration is QString::null for the non buildConfiguration specific page
virtual void init(const QString &buildConfiguration) = 0;
};
class PROJECTEXPLORER_EXPORT BuildStepConfigWidget
: public BuildConfigWidget
{
Q_OBJECT
public:
BuildStepConfigWidget()
: BuildConfigWidget()
{}
virtual QString summaryText() const = 0;
signals:
void updateSummary();
};
} // namespace ProjectExplorer
#endif // BUILDSTEP_H
......@@ -36,67 +36,80 @@
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
BuildStepsPage::BuildStepsPage(Project *project, bool clean) :
BuildStepConfigWidget(),
m_ui(new Ui::BuildStepsPage),
BuildConfigWidget(),
m_pro(project),
m_clean(clean)
{
m_ui->setupUi(this);
m_vbox = new QVBoxLayout(this);
m_vbox->setContentsMargins(20, 0, 0, 0);
const QList<BuildStep *> &steps = m_clean ? m_pro->cleanSteps() : m_pro->buildSteps();
foreach (BuildStep *bs, steps) {
addBuildStepWidget(-1, bs);
}
m_ui->buildStepAddButton->setMenu(new QMenu(this));
m_ui->buildStepAddButton->setIcon(QIcon(Core::Constants::ICON_PLUS));
m_ui->buildStepRemoveToolButton->setIcon(QIcon(Core::Constants::ICON_MINUS));
m_ui->buildStepUpToolButton->setArrowType(Qt::UpArrow);
m_ui->buildStepDownToolButton->setArrowType(Qt::DownArrow);
m_noStepsLabel = new QLabel(tr("No Build Steps"), this);
m_noStepsLabel->setVisible(steps.isEmpty());
m_vbox->addWidget(m_noStepsLabel);
connect(m_ui->buildSettingsList, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
this, SLOT(updateBuildStepWidget(QTreeWidgetItem *, QTreeWidgetItem *)));
QHBoxLayout *hboxLayout = new QHBoxLayout();
m_addButton = new QPushButton(this);
m_addButton->setText(tr("Add build step"));
m_addButton->setMenu(new QMenu(this));
hboxLayout->addWidget(m_addButton);
connect(m_ui->buildStepAddButton->menu(), SIGNAL(aboutToShow()),
this, SLOT(updateAddBuildStepMenu()));
m_removeButton = new QPushButton(this);
m_removeButton->setText(tr("Remove build step"));
m_removeButton->setMenu(new QMenu(this));
hboxLayout->addWidget(m_removeButton);
hboxLayout->addStretch(10);
connect(m_ui->buildStepAddButton, SIGNAL(clicked()),
this, SLOT(addBuildStep()));
connect(m_ui->buildStepRemoveToolButton, SIGNAL(clicked()),
this, SLOT(removeBuildStep()));
connect(m_ui->buildStepUpToolButton, SIGNAL(clicked()),
this, SLOT(upBuildStep()));
connect(m_ui->buildStepDownToolButton, SIGNAL(clicked()),
this, SLOT(downBuildStep()));
m_vbox->addLayout(hboxLayout);
// Remove dummy pages
while (QWidget *widget = m_ui->buildSettingsWidget->currentWidget()) {
m_ui->buildSettingsWidget->removeWidget(widget);
delete widget;
}
updateBuildStepButtonsState();
// Add buildsteps
const QList<BuildStep *> &steps = m_clean ? m_pro->cleanSteps() : m_pro->buildSteps();
foreach (BuildStep *bs, steps) {
connect(bs, SIGNAL(displayNameChanged(BuildStep *, QString)),
this, SLOT(displayNameChanged(BuildStep *,QString)));
connect(m_addButton->menu(), SIGNAL(aboutToShow()),
this, SLOT(updateAddBuildStepMenu()));
QTreeWidgetItem *buildStepItem = new QTreeWidgetItem();
buildStepItem->setText(0, bs->displayName());
m_ui->buildSettingsWidget->addWidget(bs->createConfigWidget());
m_ui->buildSettingsList->invisibleRootItem()->addChild(buildStepItem);
}
connect(m_removeButton->menu(), SIGNAL(aboutToShow()),
this, SLOT(updateRemoveBuildStepMenu()));
}
BuildStepsPage::~BuildStepsPage()
{
// Also deletes all added widgets
delete m_ui;
foreach(BuildStepsWidgetStruct s, m_buildSteps) {
delete s.detailsLabel;
delete s.upButton;
delete s.downButton;
delete s.detailsButton;
delete s.hbox;
delete s.widget;
}
m_buildSteps.clear();
}
void BuildStepsPage::displayNameChanged(BuildStep *bs, const QString & /* displayName */)
void BuildStepsPage::toggleDetails()
{
int index = m_clean ? m_pro->cleanSteps().indexOf(bs) : m_pro->buildSteps().indexOf(bs);
m_ui->buildSettingsList->invisibleRootItem()->child(index)->setText(0, bs->displayName());
QToolButton *tb = qobject_cast<QToolButton *>(sender());
if (tb)
foreach(const BuildStepsWidgetStruct &s, m_buildSteps)
if (s.detailsButton == tb)
s.widget->setVisible(!s.widget->isVisible());
}
void BuildStepsPage::updateSummary()
{
BuildStepConfigWidget *widget = qobject_cast<BuildStepConfigWidget *>(sender());
if (widget)
foreach(const BuildStepsWidgetStruct &s, m_buildSteps)
if (s.widget == widget)
s.detailsLabel->setText(widget->summaryText());
}
QString BuildStepsPage::displayName() const
......@@ -108,33 +121,13 @@ void BuildStepsPage::init(const QString &buildConfiguration)
{
m_configuration = buildConfiguration;
m_ui->buildSettingsList->setCurrentItem(m_ui->buildSettingsList->invisibleRootItem()->child(0));
// make sure widget is updated
if (m_ui->buildSettingsWidget->currentWidget()) {
BuildStepConfigWidget *widget = qobject_cast<BuildStepConfigWidget *>(m_ui->buildSettingsWidget->currentWidget());
widget->init(m_configuration);
foreach(BuildStepsWidgetStruct s, m_buildSteps) {
s.widget->init(m_configuration);
s.detailsLabel->setText(s.widget->summaryText());
}
}
/* switch from one tree item / build step to another */
void BuildStepsPage::updateBuildStepWidget(QTreeWidgetItem *newItem, QTreeWidgetItem *oldItem)
{
if (oldItem == newItem)
return;
Q_ASSERT(m_pro);
if (newItem) {
int row = m_ui->buildSettingsList->indexOfTopLevelItem(newItem);
m_ui->buildSettingsWidget->setCurrentIndex(row);
m_ui->groupBox->setTitle(newItem->text(0));
BuildStepConfigWidget *widget = qobject_cast<BuildStepConfigWidget *>(m_ui->buildSettingsWidget->currentWidget());
Q_ASSERT(widget);
widget->init(m_configuration);
}
updateBuildStepButtonsState();
}
void BuildStepsPage::updateAddBuildStepMenu()
{
QMap<QString, QPair<QString, IBuildStepFactory *> > map;
......@@ -148,7 +141,7 @@ void BuildStepsPage::updateAddBuildStepMenu()
}
// Ask the user which one to add
QMenu *menu = m_ui->buildStepAddButton->menu();
QMenu *menu = m_addButton->menu();
m_addBuildStepHash.clear();
menu->clear();
if (!map.isEmpty()) {
......@@ -164,119 +157,165 @@ void BuildStepsPage::updateAddBuildStepMenu()
}
}
void BuildStepsPage::addBuildStepWidget(int pos, BuildStep *step)
{
// create everything
BuildStepsWidgetStruct s;
s.widget = step->createConfigWidget();
s.detailsLabel = new QLabel(this);
s.detailsLabel->setText(s.widget->summaryText());
s.upButton = new QToolButton(this);
s.upButton->setArrowType(Qt::UpArrow);
s.downButton = new QToolButton(this);
s.downButton->setArrowType(Qt::DownArrow);
s.detailsButton = new QToolButton(this);
s.detailsButton->setText(tr("Details"));
// layout
s.hbox = new QHBoxLayout();
s.hbox->addWidget(s.detailsLabel);
s.hbox->addWidget(s.upButton);
s.hbox->addWidget(s.downButton);
s.hbox->addWidget(s.detailsButton);
if (pos == -1)
m_buildSteps.append(s);
else
m_buildSteps.insert(pos, s);
if (pos == -1) {
m_vbox->addLayout(s.hbox);
m_vbox->addWidget(s.widget);
} else {
m_vbox->insertLayout(pos *2, s.hbox);
m_vbox->insertWidget(pos *2 + 1, s.widget);
}
s.widget->hide();
// connect
connect(s.detailsButton, SIGNAL(clicked()),
this, SLOT(toggleDetails()));
connect(s.widget, SIGNAL(updateSummary()),
this, SLOT(updateSummary()));
connect(s.upButton, SIGNAL(clicked()),
this, SLOT(upBuildStep()));
connect(s.downButton, SIGNAL(clicked()),
this, SLOT(downBuildStep()));
}
void BuildStepsPage::addBuildStep()
{
if (QAction *action = qobject_cast<QAction *>(sender())) {
QPair<QString, IBuildStepFactory *> pair = m_addBuildStepHash.value(action);
BuildStep *newStep = pair.second->create(m_pro, pair.first);
m_clean ? m_pro->insertCleanStep(0, newStep) : m_pro->insertBuildStep(0, newStep);
QTreeWidgetItem *buildStepItem = new QTreeWidgetItem();
buildStepItem->setText(0, newStep->displayName());
m_ui->buildSettingsList->invisibleRootItem()->insertChild(0, buildStepItem);
m_ui->buildSettingsWidget->insertWidget(0, newStep->createConfigWidget());
m_ui->buildSettingsList->setCurrentItem(buildStepItem);
connect(newStep, SIGNAL(displayNameChanged(BuildStep *, QString)),
this, SLOT(displayNameChanged(BuildStep *,QString)));
int pos = m_clean ? m_pro->cleanSteps().count() : m_pro->buildSteps().count();
m_clean ? m_pro->insertCleanStep(pos, newStep) : m_pro->insertBuildStep(pos, newStep);
addBuildStepWidget(pos, newStep);
const BuildStepsWidgetStruct s = m_buildSteps.at(pos);
s.widget->init(m_configuration);
s.detailsLabel->setText(s.widget->summaryText());
}
}
void BuildStepsPage::updateRemoveBuildStepMenu()
{
QMenu *menu = m_removeButton->menu();
menu->clear();
const QList<BuildStep *> &steps = m_clean ? m_pro->cleanSteps() : m_pro->buildSteps();
foreach(BuildStep *step, steps) {
QAction *action = menu->addAction(step->displayName());
if (step->immutable())
action->setEnabled(false);
connect(action, SIGNAL(triggered()),
this, SLOT(removeBuildStep()));
}
}
void BuildStepsPage::removeBuildStep()
{
int pos = m_ui->buildSettingsList->currentIndex().row();
QAction *action = qobject_cast<QAction *>(sender());
if (action) {
int pos = m_removeButton->menu()->actions().indexOf(action);
qDebug()<<"pos:"<<pos;
const QList<BuildStep *> &steps = m_clean ? m_pro->cleanSteps() : m_pro->buildSteps();
if (steps.at(pos)->immutable())
return;
bool blockSignals = m_ui->buildSettingsList->blockSignals(true);
delete m_ui->buildSettingsList->invisibleRootItem()->takeChild(pos);
m_ui->buildSettingsList->blockSignals(blockSignals);
QWidget *widget = m_ui->buildSettingsWidget->widget(pos);
m_ui->buildSettingsWidget->removeWidget(widget);
delete widget;
if (pos < m_ui->buildSettingsList->invisibleRootItem()->childCount())
m_ui->buildSettingsList->setCurrentItem(m_ui->buildSettingsList->invisibleRootItem()->child(pos));
else
m_ui->buildSettingsList->setCurrentItem(m_ui->buildSettingsList->invisibleRootItem()->child(pos - 1));
BuildStepsWidgetStruct s = m_buildSteps.at(pos);
delete s.detailsLabel;
delete s.upButton;
delete s.downButton;
delete s.detailsButton;
delete s.hbox;
delete s.widget;
m_buildSteps.removeAt(pos);
m_clean ? m_pro->removeCleanStep(pos) : m_pro->removeBuildStep(pos);
updateBuildStepButtonsState();
}
}
void BuildStepsPage::upBuildStep()
{
int pos = m_ui->buildSettingsList->currentIndex().row();
if (pos < 1)
int pos = -1;
QToolButton *tb = qobject_cast<QToolButton *>(sender());
if (!tb)
return;
if (pos > m_ui->buildSettingsList->invisibleRootItem()->childCount()-1)
return;
const QList<BuildStep *> &steps = m_clean ? m_pro->cleanSteps() : m_pro->buildSteps();
if (steps.at(pos)->immutable() && steps.at(pos-1)->immutable())
for (int i=0; i<m_buildSteps.count(); ++i) {
if (m_buildSteps.at(i).upButton == tb) {
pos = i;
break;
}
}
if (pos == -1)
return;
bool blockSignals = m_ui->buildSettingsList->blockSignals(true);
m_clean ? m_pro->moveCleanStepUp(pos) : m_pro->moveBuildStepUp(pos);
stepMoveUp(pos);
QTreeWidgetItem *item = m_ui->buildSettingsList->invisibleRootItem()->child(pos - 1);
m_ui->buildSettingsList->blockSignals(blockSignals);
m_ui->buildSettingsList->setCurrentItem(item);
updateBuildStepButtonsState();
}
void BuildStepsPage::downBuildStep()
{
int pos = m_ui->buildSettingsList->currentIndex().row() + 1;
if (pos < 1)
int pos = -1;
QToolButton *tb = qobject_cast<QToolButton *>(sender());
if (!tb)
return;
if (pos > m_ui->buildSettingsList->invisibleRootItem()->childCount() - 1)
return;
const QList<BuildStep *> &steps = m_clean ? m_pro->cleanSteps() : m_pro->buildSteps();
if (steps.at(pos)->immutable() && steps.at(pos - 1)