ProjectExplorer: Add a QTextEdit based variant for BaseStringAspect

... and use the QbsCleanStep as guinea pig.

Change-Id: Ic0d62700bf48fc7971a290c90394c74b8860b9ff
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2018-10-16 07:59:52 +02:00
parent 372e239d2d
commit 50ce82d26a
4 changed files with 73 additions and 139 deletions

View File

@@ -43,6 +43,7 @@
#include <QFormLayout>
#include <QSpinBox>
#include <QToolButton>
#include <QTextEdit>
using namespace Utils;
@@ -76,6 +77,7 @@ public:
QPointer<QLabel> m_labelDisplay;
QPointer<FancyLineEdit> m_lineEditDisplay;
QPointer<PathChooser> m_pathChooserDisplay;
QPointer<QTextEdit> m_textEditDisplay;
QPixmap m_labelPixmap;
};
@@ -178,6 +180,8 @@ void BaseStringAspect::setPlaceHolderText(const QString &placeHolderText)
d->m_placeHolderText = placeHolderText;
if (d->m_lineEditDisplay)
d->m_lineEditDisplay->setPlaceholderText(placeHolderText);
if (d->m_textEditDisplay)
d->m_textEditDisplay->setPlaceholderText(placeHolderText);
}
void BaseStringAspect::setHistoryCompleter(const QString &historyCompleterKey)
@@ -234,6 +238,18 @@ void BaseStringAspect::addToConfigurationLayout(QFormLayout *layout)
this, &BaseStringAspect::setValue);
hbox->addWidget(d->m_lineEditDisplay);
break;
case TextEditDisplay:
d->m_textEditDisplay = new QTextEdit(parent);
d->m_textEditDisplay->setPlaceholderText(d->m_placeHolderText);
connect(d->m_textEditDisplay, &QTextEdit::textChanged, this, [this] {
const QString value = d->m_textEditDisplay->document()->toPlainText();
if (value != d->m_value) {
d->m_value = value;
emit changed();
}
});
hbox->addWidget(d->m_textEditDisplay);
break;
case LabelDisplay:
d->m_labelDisplay = new QLabel(parent);
d->m_labelDisplay->setTextInteractionFlags(Qt::TextSelectableByMouse);
@@ -270,6 +286,11 @@ void BaseStringAspect::update()
d->m_lineEditDisplay->setEnabled(enabled);
}
if (d->m_textEditDisplay) {
d->m_textEditDisplay->setText(displayedString);
d->m_textEditDisplay->setEnabled(enabled);
}
if (d->m_labelDisplay)
d->m_labelDisplay->setText(displayedString);

View File

@@ -93,7 +93,12 @@ public:
bool isChecked() const;
void makeCheckable(const QString &optionalLabel, const QString &optionalBaseKey);
enum DisplayStyle { LabelDisplay, LineEditDisplay, PathChooserDisplay };
enum DisplayStyle {
LabelDisplay,
LineEditDisplay,
TextEditDisplay,
PathChooserDisplay
};
void setDisplayStyle(DisplayStyle style);
void fromMap(const QVariantMap &map) override;

View File

@@ -29,8 +29,6 @@
#include "qbsproject.h"
#include "qbsprojectmanagerconstants.h"
#include "ui_qbscleanstepconfigwidget.h"
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorerconstants.h>
@@ -38,8 +36,7 @@
#include <projectexplorer/target.h>
#include <utils/qtcassert.h>
static const char QBS_DRY_RUN[] = "Qbs.DryRun";
static const char QBS_KEEP_GOING[] = "Qbs.DryKeepGoing";
using namespace ProjectExplorer;
namespace QbsProjectManager {
namespace Internal {
@@ -53,6 +50,27 @@ QbsCleanStep::QbsCleanStep(ProjectExplorer::BuildStepList *bsl) :
{
setDisplayName(tr("Qbs Clean"));
setRunInGuiThread(true);
m_dryRunAspect = addAspect<BaseBoolAspect>();
m_dryRunAspect->setSettingsKey("Qbs.DryRun");
m_dryRunAspect->setLabel(tr("Dry run"));
m_keepGoingAspect = addAspect<BaseBoolAspect>();
m_keepGoingAspect->setSettingsKey("Qbs.DryKeepGoing");
m_keepGoingAspect->setLabel(tr("Keep going"));
m_effectiveCommandAspect = addAspect<BaseStringAspect>();
m_effectiveCommandAspect->setDisplayStyle(BaseStringAspect::TextEditDisplay);
m_effectiveCommandAspect->setLabelText(tr("Equivalent command line:"));
updateState();
connect(this, &ProjectExplorer::ProjectConfiguration::displayNameChanged,
this, &QbsCleanStep::updateState);
connect(m_dryRunAspect, &BaseBoolAspect::changed,
this, &QbsCleanStep::updateState);
connect(m_keepGoingAspect, &BaseBoolAspect::changed,
this, &QbsCleanStep::updateState);
}
QbsCleanStep::~QbsCleanStep()
@@ -83,7 +101,9 @@ void QbsCleanStep::run(QFutureInterface<bool> &fi)
m_fi = &fi;
auto pro = static_cast<QbsProject *>(project());
qbs::CleanOptions options(m_qbsCleanOptions);
qbs::CleanOptions options;
options.setDryRun(m_dryRunAspect->value());
options.setKeepGoing(m_keepGoingAspect->value());
QString error;
m_job = pro->clean(options, m_products, error);
@@ -104,7 +124,11 @@ void QbsCleanStep::run(QFutureInterface<bool> &fi)
ProjectExplorer::BuildStepConfigWidget *QbsCleanStep::createConfigWidget()
{
return new QbsCleanStepConfigWidget(this);
auto w = BuildStep::createConfigWidget();
connect(this, &QbsCleanStep::stateChanged, w, [this, w] {
w->setSummaryText(tr("<b>Qbs:</b> %1").arg(m_effectiveCommandAspect->value()));
});
return w;
}
void QbsCleanStep::cancel()
@@ -113,36 +137,6 @@ void QbsCleanStep::cancel()
m_job->cancel();
}
bool QbsCleanStep::dryRun() const
{
return m_qbsCleanOptions.dryRun();
}
bool QbsCleanStep::keepGoing() const
{
return m_qbsCleanOptions.keepGoing();
}
bool QbsCleanStep::fromMap(const QVariantMap &map)
{
if (!ProjectExplorer::BuildStep::fromMap(map))
return false;
m_qbsCleanOptions.setDryRun(map.value(QLatin1String(QBS_DRY_RUN)).toBool());
m_qbsCleanOptions.setKeepGoing(map.value(QLatin1String(QBS_KEEP_GOING)).toBool());
return true;
}
QVariantMap QbsCleanStep::toMap() const
{
QVariantMap map = ProjectExplorer::BuildStep::toMap();
map.insert(QLatin1String(QBS_DRY_RUN), m_qbsCleanOptions.dryRun());
map.insert(QLatin1String(QBS_KEEP_GOING), m_qbsCleanOptions.keepGoing());
return map;
}
void QbsCleanStep::cleaningDone(bool success)
{
// Report errors:
@@ -172,6 +166,14 @@ void QbsCleanStep::handleProgress(int value)
m_fi->setProgressValue(m_progressBase + value);
}
void QbsCleanStep::updateState()
{
QString command = static_cast<QbsBuildConfiguration *>(buildConfiguration())
->equivalentCommandLine(this);
m_effectiveCommandAspect->setValue(command);
emit stateChanged();
}
void QbsCleanStep::createTaskAndOutput(ProjectExplorer::Task::TaskType type, const QString &message, const QString &file, int line)
{
ProjectExplorer::Task task = ProjectExplorer::Task(type, message,
@@ -181,75 +183,6 @@ void QbsCleanStep::createTaskAndOutput(ProjectExplorer::Task::TaskType type, con
emit addOutput(message, OutputFormat::Stdout);
}
void QbsCleanStep::setDryRun(bool dr)
{
if (m_qbsCleanOptions.dryRun() == dr)
return;
m_qbsCleanOptions.setDryRun(dr);
emit changed();
}
void QbsCleanStep::setKeepGoing(bool kg)
{
if (m_qbsCleanOptions.keepGoing() == kg)
return;
m_qbsCleanOptions.setKeepGoing(kg);
emit changed();
}
// --------------------------------------------------------------------
// QbsCleanStepConfigWidget:
// --------------------------------------------------------------------
QbsCleanStepConfigWidget::QbsCleanStepConfigWidget(QbsCleanStep *step) :
BuildStepConfigWidget(step), m_step(step)
{
connect(m_step, &ProjectExplorer::ProjectConfiguration::displayNameChanged,
this, &QbsCleanStepConfigWidget::updateState);
connect(m_step, &QbsCleanStep::changed,
this, &QbsCleanStepConfigWidget::updateState);
setContentsMargins(0, 0, 0, 0);
m_ui = new Ui::QbsCleanStepConfigWidget;
m_ui->setupUi(this);
connect(m_ui->dryRunCheckBox, &QAbstractButton::toggled,
this, &QbsCleanStepConfigWidget::changeDryRun);
connect(m_ui->keepGoingCheckBox, &QAbstractButton::toggled,
this, &QbsCleanStepConfigWidget::changeKeepGoing);
updateState();
}
QbsCleanStepConfigWidget::~QbsCleanStepConfigWidget()
{
delete m_ui;
}
void QbsCleanStepConfigWidget::updateState()
{
m_ui->dryRunCheckBox->setChecked(m_step->dryRun());
m_ui->keepGoingCheckBox->setChecked(m_step->keepGoing());
QString command = static_cast<QbsBuildConfiguration *>(m_step->buildConfiguration())
->equivalentCommandLine(m_step);
m_ui->commandLineTextEdit->setPlainText(command);
setSummaryText(tr("<b>Qbs:</b> %1").arg(command));
}
void QbsCleanStepConfigWidget::changeDryRun(bool dr)
{
m_step->setDryRun(dr);
}
void QbsCleanStepConfigWidget::changeKeepGoing(bool kg)
{
m_step->setKeepGoing(kg);
}
// --------------------------------------------------------------------
// QbsCleanStepFactory:
// --------------------------------------------------------------------

View File

@@ -28,6 +28,7 @@
#include "qbsbuildconfiguration.h"
#include <projectexplorer/buildstep.h>
#include <projectexplorer/projectconfigurationaspects.h>
#include <projectexplorer/task.h>
#include <qbs.h>
@@ -35,8 +36,6 @@
namespace QbsProjectManager {
namespace Internal {
class QbsCleanStepConfigWidget;
class QbsCleanStep : public ProjectExplorer::BuildStep
{
Q_OBJECT
@@ -52,27 +51,25 @@ public:
void cancel() override;
bool fromMap(const QVariantMap &map) override;
QVariantMap toMap() const override;
bool dryRun() const;
bool keepGoing() const;
bool dryRun() const { return m_dryRunAspect->value(); }
bool keepGoing() const { return m_keepGoingAspect->value(); }
signals:
void changed();
void stateChanged();
private:
void cleaningDone(bool success);
void handleTaskStarted(const QString &desciption, int max);
void handleProgress(int value);
void updateState();
void createTaskAndOutput(ProjectExplorer::Task::TaskType type,
const QString &message, const QString &file, int line);
void setDryRun(bool dr);
void setKeepGoing(bool kg);
ProjectExplorer::BaseBoolAspect *m_dryRunAspect = nullptr;
ProjectExplorer::BaseBoolAspect *m_keepGoingAspect = nullptr;
ProjectExplorer::BaseStringAspect *m_effectiveCommandAspect = nullptr;
qbs::CleanOptions m_qbsCleanOptions;
QStringList m_products;
QFutureInterface<bool> *m_fi = nullptr;
@@ -80,28 +77,6 @@ private:
int m_progressBase;
bool m_showCompilerOutput = true;
ProjectExplorer::IOutputParser *m_parser = nullptr;
friend class QbsCleanStepConfigWidget;
};
namespace Ui { class QbsCleanStepConfigWidget; }
class QbsCleanStepConfigWidget : public ProjectExplorer::BuildStepConfigWidget
{
Q_OBJECT
public:
QbsCleanStepConfigWidget(QbsCleanStep *step);
~QbsCleanStepConfigWidget() override;
private:
void updateState();
void changeDryRun(bool dr);
void changeKeepGoing(bool kg);
Ui::QbsCleanStepConfigWidget *m_ui;
QbsCleanStep *m_step;
};
class QbsCleanStepFactory : public ProjectExplorer::BuildStepFactory