Commit 2dc9a4d7 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Refactor some code in buildstepspage

 * Rename m_buildSteps to m_buildStepsData
 * Turn BuildStepsWidgetStruct into class and rename it to
   BuildStepsWidgetData
 * Use constructor/destructor for that class
 * Turn m_buildStepsData into a QList<... *> to have the
   necessary control about when destruction happens

Reviewed-by: Fawzi Mohamed
parent e8dcccbb
......@@ -57,6 +57,63 @@
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
BuildStepsWidgetData::BuildStepsWidgetData(BuildStep *s) :
step(s), widget(0), detailsWidget(0), upButton(0), downButton(0), removeButton(0)
{
widget = s->createConfigWidget();
Q_ASSERT(widget);
widget->init();
detailsWidget = new Utils::DetailsWidget;
detailsWidget->setWidget(widget);
Utils::FadingPanel *toolWidget = new Utils::FadingPanel(detailsWidget);
#ifdef Q_WS_MAC
QSize buttonSize(20, 20);
#else
QSize buttonSize(20, 26);
#endif
upButton = new QToolButton(toolWidget);
upButton->setAutoRaise(true);
upButton->setToolTip(BuildStepListWidget::tr("Move Up"));
upButton->setFixedSize(buttonSize);
upButton->setIcon(QIcon(QLatin1String(":/core/images/darkarrowup.png")));
downButton = new QToolButton(toolWidget);
downButton->setAutoRaise(true);
downButton->setToolTip(BuildStepListWidget::tr("Move Down"));
downButton->setFixedSize(buttonSize);
downButton->setIcon(QIcon(QLatin1String(":/core/images/darkarrowdown.png")));
removeButton = new QToolButton(toolWidget);
removeButton->setAutoRaise(true);
removeButton->setToolTip(BuildStepListWidget::tr("Remove Item"));
removeButton->setFixedSize(buttonSize);
removeButton->setIcon(QIcon(QLatin1String(":/core/images/darkclose.png")));
toolWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
QHBoxLayout *hbox = new QHBoxLayout();
toolWidget->setLayout(hbox);
hbox->setMargin(4);
hbox->setSpacing(0);
hbox->addWidget(upButton);
hbox->addWidget(downButton);
hbox->addWidget(removeButton);
detailsWidget->setToolWidget(toolWidget);
detailsWidget->setContentsMargins(0, 0, 0, 1);
detailsWidget->setSummaryText(widget->summaryText());
}
BuildStepsWidgetData::~BuildStepsWidgetData()
{
delete detailsWidget; // other widgets are children of that!
// We do not own the step
}
BuildStepListWidget::BuildStepListWidget(QWidget *parent) :
NamedWidget(parent),
m_buildStepList(0),
......@@ -67,20 +124,17 @@ BuildStepListWidget::BuildStepListWidget(QWidget *parent) :
BuildStepListWidget::~BuildStepListWidget()
{
foreach(const BuildStepsWidgetStruct &s, m_buildSteps) {
delete s.widget;
delete s.detailsWidget;
}
m_buildSteps.clear();
qDeleteAll(m_buildStepsData);
m_buildStepsData.clear();
}
void BuildStepListWidget::updateSummary()
{
BuildStepConfigWidget *widget = qobject_cast<BuildStepConfigWidget *>(sender());
if (widget) {
foreach(const BuildStepsWidgetStruct &s, m_buildSteps) {
if (s.widget == widget) {
s.detailsWidget->setSummaryText(widget->summaryText());
foreach (const BuildStepsWidgetData *s, m_buildStepsData) {
if (s->widget == widget) {
s->detailsWidget->setSummaryText(widget->summaryText());
break;
}
}
......@@ -90,6 +144,8 @@ void BuildStepListWidget::updateSummary()
void BuildStepListWidget::init(BuildStepList *bsl)
{
Q_ASSERT(bsl);
if (bsl == m_buildStepList)
return;
setupUi();
......@@ -103,18 +159,17 @@ void BuildStepListWidget::init(BuildStepList *bsl)
connect(bsl, SIGNAL(stepRemoved(int)), this, SLOT(removeBuildStep(int)));
connect(bsl, SIGNAL(stepMoved(int,int)), this, SLOT(stepMoved(int,int)));
foreach (const BuildStepsWidgetStruct &s, m_buildSteps) {
delete s.widget;
delete s.detailsWidget;
}
m_buildSteps.clear();
qDeleteAll(m_buildStepsData);
m_buildStepsData.clear();
m_buildStepList = bsl;
//: %1 is the name returned by BuildStepList::displayName
setDisplayName(tr("%1 Steps").arg(m_buildStepList->displayName()));
for (int i = 0; i < bsl->count(); ++i)
addBuildStepWidget(i, m_buildStepList->at(i));
for (int i = 0; i < bsl->count(); ++i) {
addBuildStep(i);
m_buildStepsData.at(i)->detailsWidget->setState(Utils::DetailsWidget::Collapsed);
}
m_noStepsLabel->setVisible(bsl->isEmpty());
m_noStepsLabel->setText(tr("No %1 Steps").arg(m_buildStepList->displayName()));
......@@ -161,66 +216,19 @@ void BuildStepListWidget::updateAddBuildStepMenu()
void BuildStepListWidget::addBuildStepWidget(int pos, BuildStep *step)
{
// create everything
BuildStepsWidgetStruct s;
s.widget = step->createConfigWidget();
Q_ASSERT(s.widget);
s.widget->init();
s.detailsWidget = new Utils::DetailsWidget(this);
s.detailsWidget->setSummaryText(s.widget->summaryText());
s.detailsWidget->setWidget(s.widget);
// layout
Utils::FadingPanel *toolWidget = new Utils::FadingPanel(s.detailsWidget);
#ifdef Q_WS_MAC
QSize buttonSize(20, 20);
#else
QSize buttonSize(20, 26);
#endif
s.upButton = new QToolButton(toolWidget);
s.upButton->setAutoRaise(true);
s.upButton->setToolTip(tr("Move Up"));
s.upButton->setFixedSize(buttonSize);
s.upButton->setIcon(QIcon(QLatin1String(":/core/images/darkarrowup.png")));
BuildStepsWidgetData *s = new BuildStepsWidgetData(step);
m_buildStepsData.insert(pos, s);
s.downButton = new QToolButton(toolWidget);
s.downButton->setAutoRaise(true);
s.downButton->setToolTip(tr("Move Down"));
s.downButton->setFixedSize(buttonSize);
s.downButton->setIcon(QIcon(QLatin1String(":/core/images/darkarrowdown.png")));
m_vbox->insertWidget(pos, s->detailsWidget);
s.removeButton = new QToolButton(toolWidget);
s.removeButton->setAutoRaise(true);
s.removeButton->setToolTip(tr("Remove Item"));
s.removeButton->setFixedSize(buttonSize);
s.removeButton->setIcon(QIcon(QLatin1String(":/core/images/darkclose.png")));
toolWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
QHBoxLayout *hbox = new QHBoxLayout();
toolWidget->setLayout(hbox);
hbox->setMargin(4);
hbox->setSpacing(0);
hbox->addWidget(s.upButton);
hbox->addWidget(s.downButton);
hbox->addWidget(s.removeButton);
s.detailsWidget->setToolWidget(toolWidget);
s.detailsWidget->setContentsMargins(0, 0, 0, 1);
m_buildSteps.insert(pos, s);
m_vbox->insertWidget(pos, s.detailsWidget);
connect(s.widget, SIGNAL(updateSummary()),
connect(s->widget, SIGNAL(updateSummary()),
this, SLOT(updateSummary()));
connect(s.upButton, SIGNAL(clicked()),
connect(s->upButton, SIGNAL(clicked()),
m_upMapper, SLOT(map()));
connect(s.downButton, SIGNAL(clicked()),
connect(s->downButton, SIGNAL(clicked()),
m_downMapper, SLOT(map()));
connect(s.removeButton, SIGNAL(clicked()),
connect(s->removeButton, SIGNAL(clicked()),
m_removeMapper, SLOT(map()));
}
......@@ -238,8 +246,8 @@ void BuildStepListWidget::addBuildStep(int pos)
{
BuildStep *newStep = m_buildStepList->at(pos);
addBuildStepWidget(pos, newStep);
const BuildStepsWidgetStruct s = m_buildSteps.at(pos);
s.detailsWidget->setState(Utils::DetailsWidget::Expanded);
BuildStepsWidgetData *s = m_buildStepsData.at(pos);
s->detailsWidget->setState(Utils::DetailsWidget::Expanded);
m_noStepsLabel->setVisible(false);
updateBuildStepButtonsState();
......@@ -252,11 +260,11 @@ void BuildStepListWidget::triggerStepMoveUp(int pos)
void BuildStepListWidget::stepMoved(int from, int to)
{
m_vbox->insertWidget(to, m_buildSteps.at(from).detailsWidget);
m_vbox->insertWidget(to, m_buildStepsData.at(from)->detailsWidget);
Internal::BuildStepsWidgetStruct data = m_buildSteps.at(from);
m_buildSteps.removeAt(from);
m_buildSteps.insert(to, data);
Internal::BuildStepsWidgetData *data = m_buildStepsData.at(from);
m_buildStepsData.removeAt(from);
m_buildStepsData.insert(to, data);
updateBuildStepButtonsState();
}
......@@ -278,10 +286,7 @@ void BuildStepListWidget::triggerRemoveBuildStep(int pos)
void BuildStepListWidget::removeBuildStep(int pos)
{
BuildStepsWidgetStruct s = m_buildSteps.at(pos);
delete s.widget;
delete s.detailsWidget;
m_buildSteps.removeAt(pos);
delete m_buildStepsData.takeAt(pos);
updateBuildStepButtonsState();
......@@ -332,23 +337,25 @@ void BuildStepListWidget::setupUi()
void BuildStepListWidget::updateBuildStepButtonsState()
{
for(int i = 0; i < m_buildSteps.count(); ++i) {
BuildStepsWidgetStruct s = m_buildSteps.at(i);
s.removeButton->setEnabled(!m_buildStepList->at(i)->immutable());
m_removeMapper->setMapping(s.removeButton, i);
if (m_buildStepsData.count() != m_buildStepList->count())
return;
for (int i = 0; i < m_buildStepsData.count(); ++i) {
BuildStepsWidgetData *s = m_buildStepsData.at(i);
s->removeButton->setEnabled(!m_buildStepList->at(i)->immutable());
m_removeMapper->setMapping(s->removeButton, i);
s.upButton->setEnabled((i > 0)
s->upButton->setEnabled((i > 0)
&& !(m_buildStepList->at(i)->immutable()
&& m_buildStepList->at(i - 1)));
m_upMapper->setMapping(s.upButton, i);
s.downButton->setEnabled((i + 1 < m_buildStepList->count())
m_upMapper->setMapping(s->upButton, i);
s->downButton->setEnabled((i + 1 < m_buildStepList->count())
&& !(m_buildStepList->at(i)->immutable()
&& m_buildStepList->at(i + 1)->immutable()));
m_downMapper->setMapping(s.downButton, i);
m_downMapper->setMapping(s->downButton, i);
// Only show buttons when needed
s.downButton->setVisible(m_buildStepList->count() != 1);
s.upButton->setVisible(m_buildStepList->count() != 1);
s->downButton->setVisible(m_buildStepList->count() != 1);
s->upButton->setVisible(m_buildStepList->count() != 1);
}
}
......
......@@ -56,8 +56,13 @@ class BuildConfiguration;
namespace Internal {
struct BuildStepsWidgetStruct
class BuildStepsWidgetData
{
public:
BuildStepsWidgetData(BuildStep *s);
~BuildStepsWidgetData();
BuildStep *step;
BuildStepConfigWidget *widget;
Utils::DetailsWidget *detailsWidget;
QToolButton *upButton;
......@@ -94,7 +99,7 @@ private:
BuildStepList *m_buildStepList;
QHash<QAction *, QPair<QString, ProjectExplorer::IBuildStepFactory *> > m_addBuildStepHash;
QList<Internal::BuildStepsWidgetStruct> m_buildSteps;
QList<Internal::BuildStepsWidgetData *> m_buildStepsData;
QVBoxLayout *m_vbox;
......
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