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