CMake: Use BuildDirectoryAspect for UI related to Build Directory

Do not re-create the UI yourself.

Change-Id: I8e7610ee6717105a3e05743d0451a3c6732197c5
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Tobias Hunger
2020-03-19 18:45:55 +01:00
parent 10e79cebc9
commit b30aa7fda5
3 changed files with 14 additions and 26 deletions

View File

@@ -31,8 +31,9 @@
#include "cmakeproject.h" #include "cmakeproject.h"
#include "cmakebuildconfiguration.h" #include "cmakebuildconfiguration.h"
#include <coreplugin/icore.h>
#include <coreplugin/find/itemviewfind.h> #include <coreplugin/find/itemviewfind.h>
#include <coreplugin/icore.h>
#include <projectexplorer/buildaspects.h>
#include <projectexplorer/kitmanager.h> #include <projectexplorer/kitmanager.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
@@ -105,20 +106,15 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setColumnStretch(1, 10); 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; int row = 0;
mainLayout->addWidget(new QLabel(tr("Build directory:")), row, 0); auto buildDirAspect = bc->buildDirectoryAspect();
mainLayout->addWidget(buildDirChooser, row, 1, 1, 2); 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; ++row;
auto qmlDebugAspect = bc->aspect<QtSupport::QmlDebuggingAspect>(); auto qmlDebugAspect = bc->aspect<QtSupport::QmlDebuggingAspect>();
@@ -132,11 +128,6 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
++row; ++row;
mainLayout->addItem(new QSpacerItem(20, 10), row, 0); 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; ++row;
m_warningMessageLabel = new Utils::InfoLabel({}, Utils::InfoLabel::Warning); m_warningMessageLabel = new Utils::InfoLabel({}, Utils::InfoLabel::Warning);
m_warningMessageLabel->setVisible(false); m_warningMessageLabel->setVisible(false);
@@ -257,13 +248,12 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
m_configView->expandAll(); 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_configModel->setConfiguration(m_buildConfiguration->configurationFromCMake());
m_configView->expandAll(); m_configView->expandAll();
m_configView->setEnabled(true); m_configView->setEnabled(true);
stretcher->stretch(); stretcher->stretch();
updateButtonState(); updateButtonState();
buildDirChooser->triggerChanged(); // refresh valid state...
handleQmlDebugCxxFlags(); handleQmlDebugCxxFlags();
m_showProgressTimer.stop(); m_showProgressTimer.stop();
m_progressIndicator->hide(); m_progressIndicator->hide();
@@ -342,9 +332,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
void CMakeBuildSettingsWidget::setError(const QString &message) void CMakeBuildSettingsWidget::setError(const QString &message)
{ {
bool showError = !message.isEmpty(); m_buildConfiguration->buildDirectoryAspect()->setProblem(message);
m_errorMessageLabel->setVisible(showError);
m_errorMessageLabel->setText(message);
} }
void CMakeBuildSettingsWidget::setWarning(const QString &message) void CMakeBuildSettingsWidget::setWarning(const QString &message)

View File

@@ -88,7 +88,6 @@ private:
QPushButton *m_reconfigureButton; QPushButton *m_reconfigureButton;
QTimer m_showProgressTimer; QTimer m_showProgressTimer;
Utils::FancyLineEdit *m_filterEdit; Utils::FancyLineEdit *m_filterEdit;
Utils::InfoLabel *m_errorMessageLabel;
Utils::InfoLabel *m_warningMessageLabel; Utils::InfoLabel *m_warningMessageLabel;
}; };

View File

@@ -43,10 +43,11 @@ public:
bool isShadowBuild() const; bool isShadowBuild() const;
void setProblem(const QString &description); void setProblem(const QString &description);
void addToLayout(LayoutBuilder &builder) override;
private: private:
void toMap(QVariantMap &map) const override; void toMap(QVariantMap &map) const override;
void fromMap(const QVariantMap &map) override; void fromMap(const QVariantMap &map) override;
void addToLayout(LayoutBuilder &builder) override;
void updateProblemLabel(); void updateProblemLabel();