From b30aa7fda5d0ef8a764b14f27c8e37e3fcdf9b97 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 19 Mar 2020 18:45:55 +0100 Subject: [PATCH] CMake: Use BuildDirectoryAspect for UI related to Build Directory Do not re-create the UI yourself. Change-Id: I8e7610ee6717105a3e05743d0451a3c6732197c5 Reviewed-by: hjk --- .../cmakebuildsettingswidget.cpp | 36 +++++++------------ .../cmakebuildsettingswidget.h | 1 - src/plugins/projectexplorer/buildaspects.h | 3 +- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp index 02812820f6a..21e77cc5ea5 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp @@ -31,8 +31,9 @@ #include "cmakeproject.h" #include "cmakebuildconfiguration.h" -#include #include +#include +#include #include #include #include @@ -105,20 +106,15 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc) mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setColumnStretch(1, 10); - auto project = bc->project(); - - auto buildDirChooser = new Utils::PathChooser; - buildDirChooser->setBaseDirectory(project->projectDirectory()); - buildDirChooser->setFileName(bc->buildDirectory()); - connect(buildDirChooser, &Utils::PathChooser::rawPathChanged, this, - [this](const QString &path) { - m_configModel->flush(); // clear out config cache... - m_buildConfiguration->setBuildDirectory(Utils::FilePath::fromString(path)); - }); - int row = 0; - mainLayout->addWidget(new QLabel(tr("Build directory:")), row, 0); - mainLayout->addWidget(buildDirChooser, row, 1, 1, 2); + auto buildDirAspect = bc->buildDirectoryAspect(); + connect(buildDirAspect, &ProjectConfigurationAspect::changed, this, [this]() { + m_configModel->flush(); // clear out config cache...; + }); + auto buildDirWidget = new QWidget; + LayoutBuilder buildDirWidgetBuilder(buildDirWidget); + buildDirAspect->addToLayout(buildDirWidgetBuilder); + mainLayout->addWidget(buildDirWidget, row, 0, 1, 2); ++row; auto qmlDebugAspect = bc->aspect(); @@ -132,11 +128,6 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc) ++row; mainLayout->addItem(new QSpacerItem(20, 10), row, 0); - ++row; - m_errorMessageLabel = new Utils::InfoLabel({}, Utils::InfoLabel::Error); - m_errorMessageLabel->setVisible(false); - mainLayout->addWidget(m_errorMessageLabel, row, 0, 1, -1, Qt::AlignHCenter); - ++row; m_warningMessageLabel = new Utils::InfoLabel({}, Utils::InfoLabel::Warning); m_warningMessageLabel->setVisible(false); @@ -257,13 +248,12 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc) m_configView->expandAll(); } - connect(bc->target(), &Target::parsingFinished, this, [this, buildDirChooser, stretcher] { + connect(bc->target(), &Target::parsingFinished, this, [this, stretcher] { m_configModel->setConfiguration(m_buildConfiguration->configurationFromCMake()); m_configView->expandAll(); m_configView->setEnabled(true); stretcher->stretch(); updateButtonState(); - buildDirChooser->triggerChanged(); // refresh valid state... handleQmlDebugCxxFlags(); m_showProgressTimer.stop(); m_progressIndicator->hide(); @@ -342,9 +332,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc) void CMakeBuildSettingsWidget::setError(const QString &message) { - bool showError = !message.isEmpty(); - m_errorMessageLabel->setVisible(showError); - m_errorMessageLabel->setText(message); + m_buildConfiguration->buildDirectoryAspect()->setProblem(message); } void CMakeBuildSettingsWidget::setWarning(const QString &message) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.h b/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.h index 9b315ce7dbe..ca68fe56328 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.h +++ b/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.h @@ -88,7 +88,6 @@ private: QPushButton *m_reconfigureButton; QTimer m_showProgressTimer; Utils::FancyLineEdit *m_filterEdit; - Utils::InfoLabel *m_errorMessageLabel; Utils::InfoLabel *m_warningMessageLabel; }; diff --git a/src/plugins/projectexplorer/buildaspects.h b/src/plugins/projectexplorer/buildaspects.h index 8e5674f2096..2933b5447f9 100644 --- a/src/plugins/projectexplorer/buildaspects.h +++ b/src/plugins/projectexplorer/buildaspects.h @@ -43,10 +43,11 @@ public: bool isShadowBuild() const; void setProblem(const QString &description); + void addToLayout(LayoutBuilder &builder) override; + private: void toMap(QVariantMap &map) const override; void fromMap(const QVariantMap &map) override; - void addToLayout(LayoutBuilder &builder) override; void updateProblemLabel();