Qbs: Start using aspects for some bool items in install step

Change-Id: If5e702ba6cf9727fe209c96988701d76f373a78d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2020-08-17 10:30:36 +02:00
parent 119994c62d
commit f0d0591015
5 changed files with 73 additions and 176 deletions

View File

@@ -95,6 +95,7 @@ void LayoutBuilder::flushPendingItems()
// If there are more than two items, we cram the last ones in one hbox. // If there are more than two items, we cram the last ones in one hbox.
if (m_pendingItems.size() > 2) { if (m_pendingItems.size() > 2) {
auto hbox = new QHBoxLayout; auto hbox = new QHBoxLayout;
hbox->setContentsMargins(0, 0, 0, 0);
for (int i = 1; i < m_pendingItems.size(); ++i) { for (int i = 1; i < m_pendingItems.size(); ++i) {
if (QWidget *w = m_pendingItems.at(i).widget) if (QWidget *w = m_pendingItems.at(i).widget)
hbox->addWidget(w); hbox->addWidget(w);

View File

@@ -516,13 +516,19 @@ void BoolAspect::addToLayout(LayoutBuilder &builder)
{ {
QTC_CHECK(!d->m_checkBox); QTC_CHECK(!d->m_checkBox);
d->m_checkBox = new QCheckBox(); d->m_checkBox = new QCheckBox();
if (d->m_labelPlacement == LabelPlacement::AtCheckBox) { switch (d->m_labelPlacement) {
case LabelPlacement::AtCheckBoxWithoutDummyLabel:
d->m_checkBox->setText(d->m_labelText);
break;
case LabelPlacement::AtCheckBox:
d->m_checkBox->setText(d->m_labelText); d->m_checkBox->setText(d->m_labelText);
builder.addItem(new QLabel); builder.addItem(new QLabel);
} else { break;
case LabelPlacement::InExtraLabel:
d->m_label = new QLabel(d->m_labelText); d->m_label = new QLabel(d->m_labelText);
d->m_label->setToolTip(d->m_tooltip); d->m_label->setToolTip(d->m_tooltip);
builder.addItem(d->m_label.data()); builder.addItem(d->m_label.data());
break;
} }
d->m_checkBox->setChecked(d->m_value); d->m_checkBox->setChecked(d->m_value);
d->m_checkBox->setToolTip(d->m_tooltip); d->m_checkBox->setToolTip(d->m_tooltip);

View File

@@ -62,7 +62,7 @@ public:
bool defaultValue() const; bool defaultValue() const;
void setDefaultValue(bool defaultValue); void setDefaultValue(bool defaultValue);
enum class LabelPlacement { AtCheckBox, InExtraLabel }; enum class LabelPlacement { AtCheckBox, AtCheckBoxWithoutDummyLabel, InExtraLabel };
void setLabel(const QString &labelText, void setLabel(const QString &labelText,
LabelPlacement labelPlacement = LabelPlacement::InExtraLabel); LabelPlacement labelPlacement = LabelPlacement::InExtraLabel);
void setToolTip(const QString &tooltip); void setToolTip(const QString &tooltip);

View File

@@ -37,50 +37,30 @@
#include <projectexplorer/kit.h> #include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QCheckBox>
#include <QFileInfo>
#include <QFormLayout>
#include <QJsonObject> #include <QJsonObject>
#include <QLabel> #include <QLabel>
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QSpacerItem>
using namespace ProjectExplorer; using namespace ProjectExplorer;
namespace QbsProjectManager {
namespace Internal {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Constants: // Constants:
// -------------------------------------------------------------------- // --------------------------------------------------------------------
static const char QBS_REMOVE_FIRST[] = "Qbs.RemoveFirst"; const char QBS_REMOVE_FIRST[] = "Qbs.RemoveFirst";
static const char QBS_DRY_RUN[] = "Qbs.DryRun"; const char QBS_DRY_RUN[] = "Qbs.DryRun";
static const char QBS_KEEP_GOING[] = "Qbs.DryKeepGoing"; const char QBS_KEEP_GOING[] = "Qbs.DryKeepGoing";
namespace QbsProjectManager {
namespace Internal {
class QbsInstallStepConfigWidget : public ProjectExplorer::BuildStepConfigWidget class QbsInstallStepConfigWidget : public ProjectExplorer::BuildStepConfigWidget
{ {
public: public:
QbsInstallStepConfigWidget(QbsInstallStep *step); QbsInstallStepConfigWidget(QbsInstallStep *step);
private:
void updateState();
void changeRemoveFirst(bool rf) { m_step->setRemoveFirst(rf); }
void changeDryRun(bool dr) { m_step->setDryRun(dr); }
void changeKeepGoing(bool kg) { m_step->setKeepGoing(kg); }
private:
QbsInstallStep *m_step;
bool m_ignoreChange;
QCheckBox *m_dryRunCheckBox;
QCheckBox *m_keepGoingCheckBox;
QCheckBox *m_removeFirstCheckBox;
QPlainTextEdit *m_commandLineTextEdit;
QLabel *m_installRootValueLabel;
}; };
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@@ -92,12 +72,18 @@ QbsInstallStep::QbsInstallStep(BuildStepList *bsl, Core::Id id)
{ {
setDisplayName(tr("Qbs Install")); setDisplayName(tr("Qbs Install"));
const QbsBuildConfiguration * const bc = buildConfig(); const auto labelPlacement = BoolAspect::LabelPlacement::AtCheckBoxWithoutDummyLabel;
connect(bc, &QbsBuildConfiguration::qbsConfigurationChanged, this, &QbsInstallStep::changed); m_dryRun = addAspect<BoolAspect>();
if (bc->qbsStep()) { m_dryRun->setSettingsKey(QBS_DRY_RUN);
connect(bc->qbsStep(), &QbsBuildStep::qbsBuildOptionsChanged, m_dryRun->setLabel(tr("Dry run"), labelPlacement);
this, &QbsInstallStep::changed);
} m_keepGoing = addAspect<BoolAspect>();
m_keepGoing->setSettingsKey(QBS_KEEP_GOING);
m_keepGoing->setLabel(tr("Keep going"), labelPlacement);
m_cleanInstallRoot = addAspect<BoolAspect>();
m_cleanInstallRoot->setSettingsKey(QBS_REMOVE_FIRST);
m_cleanInstallRoot->setLabel(tr("Remove first"), labelPlacement);
} }
QbsInstallStep::~QbsInstallStep() QbsInstallStep::~QbsInstallStep()
@@ -120,9 +106,9 @@ void QbsInstallStep::doRun()
QJsonObject request; QJsonObject request;
request.insert("type", "install"); request.insert("type", "install");
request.insert("install-root", installRoot()); request.insert("install-root", installRoot());
request.insert("clean-install-root", m_cleanInstallRoot); request.insert("clean-install-root", m_cleanInstallRoot->value());
request.insert("keep-going", m_keepGoing); request.insert("keep-going", m_keepGoing->value());
request.insert("dry-run", m_dryRun); request.insert("dry-run", m_dryRun->value());
m_session->sendRequest(request); m_session->sendRequest(request);
m_maxProgress = 0; m_maxProgress = 0;
@@ -156,26 +142,6 @@ const QbsBuildConfiguration *QbsInstallStep::buildConfig() const
return static_cast<QbsBuildConfiguration *>(buildConfiguration()); return static_cast<QbsBuildConfiguration *>(buildConfiguration());
} }
bool QbsInstallStep::fromMap(const QVariantMap &map)
{
if (!ProjectExplorer::BuildStep::fromMap(map))
return false;
m_cleanInstallRoot = map.value(QBS_REMOVE_FIRST, false).toBool();
m_dryRun = map.value(QBS_DRY_RUN, false).toBool();
m_keepGoing = map.value(QBS_KEEP_GOING, false).toBool();
return true;
}
QVariantMap QbsInstallStep::toMap() const
{
QVariantMap map = ProjectExplorer::BuildStep::toMap();
map.insert(QBS_REMOVE_FIRST, m_cleanInstallRoot);
map.insert(QBS_DRY_RUN, m_dryRun);
map.insert(QBS_KEEP_GOING, m_keepGoing);
return map;
}
void QbsInstallStep::installDone(const ErrorInfo &error) void QbsInstallStep::installDone(const ErrorInfo &error)
{ {
m_session->disconnect(this); m_session->disconnect(this);
@@ -206,138 +172,73 @@ void QbsInstallStep::createTaskAndOutput(Task::TaskType type, const QString &mes
emit addTask(CompileTask(type, message, file, line), 1); emit addTask(CompileTask(type, message, file, line), 1);
} }
void QbsInstallStep::setRemoveFirst(bool rf)
{
if (m_cleanInstallRoot == rf)
return;
m_cleanInstallRoot = rf;
emit changed();
}
void QbsInstallStep::setDryRun(bool dr)
{
if (m_dryRun == dr)
return;
m_dryRun = dr;
emit changed();
}
void QbsInstallStep::setKeepGoing(bool kg)
{
if (m_keepGoing == kg)
return;
m_keepGoing = kg;
emit changed();
}
QbsBuildStepData QbsInstallStep::stepData() const QbsBuildStepData QbsInstallStep::stepData() const
{ {
QbsBuildStepData data; QbsBuildStepData data;
data.command = "install"; data.command = "install";
data.dryRun = dryRun(); data.dryRun = m_dryRun->value();
data.keepGoing = keepGoing(); data.keepGoing = m_keepGoing->value();
data.noBuild = true; data.noBuild = true;
data.cleanInstallRoot = removeFirst(); data.cleanInstallRoot = m_cleanInstallRoot->value();
data.isInstallStep = true; data.isInstallStep = true;
auto bs = static_cast<QbsBuildConfiguration *>(target()->activeBuildConfiguration())->qbsStep(); auto bs = static_cast<QbsBuildConfiguration *>(target()->activeBuildConfiguration())->qbsStep();
if (bs) if (bs)
data.installRoot = bs->installRoot(); data.installRoot = bs->installRoot();
return data; return data;
}; }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// QbsInstallStepConfigWidget: // QbsInstallStepConfigWidget:
// -------------------------------------------------------------------- // --------------------------------------------------------------------
QbsInstallStepConfigWidget::QbsInstallStepConfigWidget(QbsInstallStep *step) : QbsInstallStepConfigWidget::QbsInstallStepConfigWidget(QbsInstallStep *step) :
BuildStepConfigWidget(step), m_step(step), m_ignoreChange(false) BuildStepConfigWidget(step)
{ {
connect(m_step, &ProjectExplorer::ProjectConfiguration::displayNameChanged, setSummaryText(QbsInstallStep::tr("<b>Qbs:</b> %1").arg("install"));
this, &QbsInstallStepConfigWidget::updateState);
connect(m_step, &QbsInstallStep::changed,
this, &QbsInstallStepConfigWidget::updateState);
setContentsMargins(0, 0, 0, 0); auto installRootValueLabel = new QLabel(step->installRoot());
auto installRootLabel = new QLabel(this); auto commandLineKeyLabel = new QLabel(QbsInstallStep::tr("Equivalent command line:"));
commandLineKeyLabel->setAlignment(Qt::AlignTop);
auto flagsLabel = new QLabel(this); auto commandLineTextEdit = new QPlainTextEdit(this);
commandLineTextEdit->setReadOnly(true);
commandLineTextEdit->setTextInteractionFlags(Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse);
commandLineTextEdit->setMinimumHeight(QFontMetrics(font()).height() * 8);
m_dryRunCheckBox = new QCheckBox(this); LayoutBuilder builder(this);
m_keepGoingCheckBox = new QCheckBox(this); builder.addItems(new QLabel(QbsInstallStep::tr("Install root:")), installRootValueLabel);
m_removeFirstCheckBox = new QCheckBox(this);
auto horizontalLayout = new QHBoxLayout(); builder.startNewRow();
horizontalLayout->addWidget(m_dryRunCheckBox); builder.addItem(new QLabel(QbsInstallStep::tr("Flags:")));
horizontalLayout->addWidget(m_keepGoingCheckBox); step->m_dryRun->addToLayout(builder);
horizontalLayout->addWidget(m_removeFirstCheckBox); step->m_keepGoing->addToLayout(builder);
horizontalLayout->addStretch(1); step->m_cleanInstallRoot->addToLayout(builder);
auto commandLineKeyLabel = new QLabel(this); builder.startNewRow();
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); builder.addItems(commandLineKeyLabel, commandLineTextEdit);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(commandLineKeyLabel->sizePolicy().hasHeightForWidth());
commandLineKeyLabel->setSizePolicy(sizePolicy);
commandLineKeyLabel->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop);
m_commandLineTextEdit = new QPlainTextEdit(this); const auto updateState = [this, step, commandLineTextEdit, installRootValueLabel] {
QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Preferred); QString installRoot = step->installRoot();
sizePolicy1.setHorizontalStretch(0); installRootValueLabel->setText(installRoot);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(m_commandLineTextEdit->sizePolicy().hasHeightForWidth());
m_commandLineTextEdit->setSizePolicy(sizePolicy1);
m_commandLineTextEdit->setReadOnly(true);
m_commandLineTextEdit->setTextInteractionFlags(Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse);
m_installRootValueLabel = new QLabel(this); QString command = step->buildConfig()->equivalentCommandLine(step->stepData());
commandLineTextEdit->setPlainText(command);
};
auto formLayout = new QFormLayout(this); connect(step->target(), &Target::parsingFinished, this, updateState);
formLayout->setWidget(0, QFormLayout::LabelRole, installRootLabel); connect(step, &ProjectConfiguration::displayNameChanged, this, updateState);
formLayout->setWidget(0, QFormLayout::FieldRole, m_installRootValueLabel);
formLayout->setWidget(1, QFormLayout::LabelRole, flagsLabel);
formLayout->setLayout(1, QFormLayout::FieldRole, horizontalLayout);
formLayout->setWidget(2, QFormLayout::LabelRole, commandLineKeyLabel);
formLayout->setWidget(2, QFormLayout::FieldRole, m_commandLineTextEdit);
QWidget::setTabOrder(m_dryRunCheckBox, m_keepGoingCheckBox); connect(step->m_dryRun, &BoolAspect::changed, this, updateState);
QWidget::setTabOrder(m_keepGoingCheckBox, m_removeFirstCheckBox); connect(step->m_keepGoing, &BoolAspect::changed, this, updateState);
QWidget::setTabOrder(m_removeFirstCheckBox, m_commandLineTextEdit); connect(step->m_cleanInstallRoot, &BoolAspect::changed, this, updateState);
installRootLabel->setText(QbsInstallStep::tr("Install root:")); const QbsBuildConfiguration * const bc = step->buildConfig();
flagsLabel->setText(QbsInstallStep::tr("Flags:")); connect(bc, &QbsBuildConfiguration::qbsConfigurationChanged, this, updateState);
m_dryRunCheckBox->setText(QbsInstallStep::tr("Dry run")); if (bc->qbsStep())
m_keepGoingCheckBox->setText(QbsInstallStep::tr("Keep going")); connect(bc->qbsStep(), &QbsBuildStep::qbsBuildOptionsChanged, this, updateState);
m_removeFirstCheckBox->setText(QbsInstallStep::tr("Remove first"));
commandLineKeyLabel->setText(QbsInstallStep::tr("Equivalent command line:"));
m_installRootValueLabel->setText(QString());
connect(m_removeFirstCheckBox, &QAbstractButton::toggled,
this, &QbsInstallStepConfigWidget::changeRemoveFirst);
connect(m_dryRunCheckBox, &QAbstractButton::toggled,
this, &QbsInstallStepConfigWidget::changeDryRun);
connect(m_keepGoingCheckBox, &QAbstractButton::toggled,
this, &QbsInstallStepConfigWidget::changeKeepGoing);
connect(m_step->target(), &Target::parsingFinished,
this, &QbsInstallStepConfigWidget::updateState);
updateState(); updateState();
setSummaryText(QbsInstallStep::tr("<b>Qbs:</b> %1").arg("install"));
}
void QbsInstallStepConfigWidget::updateState()
{
if (!m_ignoreChange) {
m_installRootValueLabel->setText(m_step->installRoot());
m_removeFirstCheckBox->setChecked(m_step->removeFirst());
m_dryRunCheckBox->setChecked(m_step->dryRun());
m_keepGoingCheckBox->setChecked(m_step->keepGoing());
}
QString command = m_step->buildConfig()->equivalentCommandLine(m_step->stepData());
m_commandLineTextEdit->setPlainText(command);
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@@ -29,6 +29,7 @@
#include "qbssession.h" #include "qbssession.h"
#include <projectexplorer/buildstep.h> #include <projectexplorer/buildstep.h>
#include <projectexplorer/projectconfigurationaspects.h>
#include <projectexplorer/task.h> #include <projectexplorer/task.h>
namespace QbsProjectManager { namespace QbsProjectManager {
@@ -45,21 +46,13 @@ public:
~QbsInstallStep() override; ~QbsInstallStep() override;
QString installRoot() const; QString installRoot() const;
bool removeFirst() const { return m_cleanInstallRoot; }
bool dryRun() const { return m_dryRun; }
bool keepGoing() const { return m_keepGoing; }
QbsBuildStepData stepData() const; QbsBuildStepData stepData() const;
signals:
void changed();
private: private:
bool init() override; bool init() override;
void doRun() override; void doRun() override;
void doCancel() override; void doCancel() override;
ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override; ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
bool fromMap(const QVariantMap &map) override;
QVariantMap toMap() const override;
const QbsBuildConfiguration *buildConfig() const; const QbsBuildConfiguration *buildConfig() const;
void installDone(const ErrorInfo &error); void installDone(const ErrorInfo &error);
@@ -69,13 +62,9 @@ private:
void createTaskAndOutput(ProjectExplorer::Task::TaskType type, void createTaskAndOutput(ProjectExplorer::Task::TaskType type,
const QString &message, const Utils::FilePath &file, int line); const QString &message, const Utils::FilePath &file, int line);
void setRemoveFirst(bool rf); ProjectExplorer::BoolAspect *m_cleanInstallRoot = nullptr;
void setDryRun(bool dr); ProjectExplorer::BoolAspect *m_dryRun = nullptr;
void setKeepGoing(bool kg); ProjectExplorer::BoolAspect *m_keepGoing = nullptr;
bool m_cleanInstallRoot = false;
bool m_dryRun = false;
bool m_keepGoing = false;
QbsSession *m_session = nullptr; QbsSession *m_session = nullptr;
QString m_description; QString m_description;