Skip to content

Commit

Permalink
ProjectExplorer: Add a QTextEdit based variant for BaseStringAspect
Browse files Browse the repository at this point in the history
... and use the QbsCleanStep as guinea pig.

Change-Id: Ic0d62700bf48fc7971a290c90394c74b8860b9ff
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
  • Loading branch information
hjk committed Jan 18, 2019
1 parent 372e239 commit 50ce82d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 139 deletions.
21 changes: 21 additions & 0 deletions src/plugins/projectexplorer/projectconfigurationaspects.cpp
Expand Up @@ -43,6 +43,7 @@
#include <QFormLayout>
#include <QSpinBox>
#include <QToolButton>
#include <QTextEdit>

using namespace Utils;

Expand Down Expand Up @@ -76,6 +77,7 @@ class BaseStringAspectPrivate
QPointer<QLabel> m_labelDisplay;
QPointer<FancyLineEdit> m_lineEditDisplay;
QPointer<PathChooser> m_pathChooserDisplay;
QPointer<QTextEdit> m_textEditDisplay;
QPixmap m_labelPixmap;
};

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion src/plugins/projectexplorer/projectconfigurationaspects.h
Expand Up @@ -93,7 +93,12 @@ class PROJECTEXPLORER_EXPORT BaseStringAspect : public ProjectConfigurationAspec
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;
Expand Down
143 changes: 38 additions & 105 deletions src/plugins/qbsprojectmanager/qbscleanstep.cpp
Expand Up @@ -29,17 +29,14 @@
#include "qbsproject.h"
#include "qbsprojectmanagerconstants.h"

#include "ui_qbscleanstepconfigwidget.h"

#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/buildmanager.h>
#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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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);
Expand All @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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:
// --------------------------------------------------------------------
Expand Down
41 changes: 8 additions & 33 deletions src/plugins/qbsprojectmanager/qbscleanstep.h
Expand Up @@ -28,15 +28,14 @@
#include "qbsbuildconfiguration.h"

#include <projectexplorer/buildstep.h>
#include <projectexplorer/projectconfigurationaspects.h>
#include <projectexplorer/task.h>

#include <qbs.h>

namespace QbsProjectManager {
namespace Internal {

class QbsCleanStepConfigWidget;

class QbsCleanStep : public ProjectExplorer::BuildStep
{
Q_OBJECT
Expand All @@ -52,56 +51,32 @@ class QbsCleanStep : public ProjectExplorer::BuildStep

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;
qbs::CleanJob *m_job = nullptr;
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
Expand Down

0 comments on commit 50ce82d

Please sign in to comment.