summaryrefslogtreecommitdiffstats
path: root/Source/QtDialog/CMakeSetupDialog.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2020-09-29 14:17:47 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2020-10-05 13:49:59 (GMT)
commita4382f72d7fb924f9649ae352d70a36df2d662a8 (patch)
tree15855284a47a3f3ab4a14f945559266ebabbb0a5 /Source/QtDialog/CMakeSetupDialog.cxx
parent8617479061039e2b357b7efc922f1b88648dce42 (diff)
downloadCMake-a4382f72d7fb924f9649ae352d70a36df2d662a8.zip
CMake-a4382f72d7fb924f9649ae352d70a36df2d662a8.tar.gz
CMake-a4382f72d7fb924f9649ae352d70a36df2d662a8.tar.bz2
CMake GUI: Add presets functionality
Diffstat (limited to 'Source/QtDialog/CMakeSetupDialog.cxx')
-rw-r--r--Source/QtDialog/CMakeSetupDialog.cxx86
1 files changed, 84 insertions, 2 deletions
diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx
index df22028..acd32ec 100644
--- a/Source/QtDialog/CMakeSetupDialog.cxx
+++ b/Source/QtDialog/CMakeSetupDialog.cxx
@@ -21,8 +21,10 @@
#include <QSettings>
#include <QShortcut>
#include <QStatusBar>
+#include <QString>
#include <QToolButton>
#include <QUrl>
+#include <QVector>
#ifdef QT_WINEXTRAS
# include <QWinTaskbarButton>
@@ -263,6 +265,8 @@ void CMakeSetupDialog::initialize()
&CMakeSetupDialog::onBinaryDirectoryChanged);
QObject::connect(this->SourceDirectory, &QLineEdit::textChanged, this,
&CMakeSetupDialog::onSourceDirectoryChanged);
+ QObject::connect(this->Preset, &QCMakePresetComboBox::presetChanged, this,
+ &CMakeSetupDialog::onBuildPresetChanged);
QObject::connect(this->CMakeThread->cmakeInstance(),
&QCMake::sourceDirChanged, this,
@@ -270,6 +274,13 @@ void CMakeSetupDialog::initialize()
QObject::connect(this->CMakeThread->cmakeInstance(),
&QCMake::binaryDirChanged, this,
&CMakeSetupDialog::updateBinaryDirectory);
+ QObject::connect(this->CMakeThread->cmakeInstance(), &QCMake::presetsChanged,
+ this, &CMakeSetupDialog::updatePresets);
+ QObject::connect(this->CMakeThread->cmakeInstance(), &QCMake::presetChanged,
+ this, &CMakeSetupDialog::updatePreset);
+ QObject::connect(this->CMakeThread->cmakeInstance(),
+ &QCMake::presetLoadError, this,
+ &CMakeSetupDialog::showPresetLoadError);
QObject::connect(this->CMakeThread->cmakeInstance(),
&QCMake::progressChanged, this,
@@ -314,9 +325,15 @@ void CMakeSetupDialog::initialize()
QObject::connect(this->WarnUninitializedAction, &QAction::triggered,
this->CMakeThread->cmakeInstance(),
&QCMake::setWarnUninitializedMode);
+ QObject::connect(this->CMakeThread->cmakeInstance(),
+ &QCMake::warnUninitializedModeChanged,
+ this->WarnUninitializedAction, &QAction::setChecked);
- if (!this->SourceDirectory->text().isEmpty() ||
- !this->BinaryDirectory->lineEdit()->text().isEmpty()) {
+ if (!this->SourceDirectory->text().isEmpty() &&
+ !this->DeferredPreset.isNull()) {
+ this->onSourceDirectoryChanged(this->SourceDirectory->text());
+ } else if (!this->SourceDirectory->text().isEmpty() ||
+ !this->BinaryDirectory->lineEdit()->text().isEmpty()) {
this->onSourceDirectoryChanged(this->SourceDirectory->text());
this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
} else {
@@ -671,6 +688,41 @@ void CMakeSetupDialog::updateBinaryDirectory(const QString& dir)
}
}
+void CMakeSetupDialog::updatePresets(const QVector<QCMakePreset>& presets)
+{
+ if (this->Preset->presets() != presets) {
+ this->Preset->blockSignals(true);
+ this->Preset->setPresets(presets);
+ this->Preset->blockSignals(false);
+ }
+
+ this->Preset->setHidden(presets.isEmpty());
+ this->PresetLabel->setHidden(presets.isEmpty());
+
+ if (!this->DeferredPreset.isNull()) {
+ this->Preset->setPresetName(this->DeferredPreset);
+ this->DeferredPreset = QString{};
+ }
+}
+
+void CMakeSetupDialog::updatePreset(const QString& name)
+{
+ if (this->Preset->presetName() != name) {
+ this->Preset->blockSignals(true);
+ this->Preset->setPresetName(name);
+ this->Preset->blockSignals(false);
+ }
+}
+
+void CMakeSetupDialog::showPresetLoadError(
+ const QString& dir, cmCMakePresetsFile::ReadFileResult result)
+{
+ QMessageBox::warning(
+ this, "Error Reading CMake Presets",
+ QString::fromLocal8Bit("Could not read presets from %1: %2")
+ .arg(dir, cmCMakePresetsFile::ResultToString(result)));
+}
+
void CMakeSetupDialog::doBinaryBrowse()
{
QString dir = QFileDialog::getExistingDirectory(
@@ -686,6 +738,11 @@ void CMakeSetupDialog::setBinaryDirectory(const QString& dir)
this->BinaryDirectory->setEditText(dir);
}
+void CMakeSetupDialog::setStartupBinaryDirectory(bool startup)
+{
+ this->StartupBinaryDirectory = startup;
+}
+
void CMakeSetupDialog::onSourceDirectoryChanged(const QString& dir)
{
this->Output->clear();
@@ -711,11 +768,24 @@ void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir)
Q_ARG(QString, dir));
}
+void CMakeSetupDialog::onBuildPresetChanged(const QString& name)
+{
+ QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "setPreset",
+ Qt::QueuedConnection, Q_ARG(QString, name),
+ Q_ARG(bool, !this->StartupBinaryDirectory));
+ this->StartupBinaryDirectory = false;
+}
+
void CMakeSetupDialog::setSourceDirectory(const QString& dir)
{
this->SourceDirectory->setText(dir);
}
+void CMakeSetupDialog::setDeferredPreset(const QString& preset)
+{
+ this->DeferredPreset = preset;
+}
+
void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
{
percent = (percent * ProgressFactor) + ProgressOffset;
@@ -753,6 +823,7 @@ void CMakeSetupDialog::setEnabledState(bool enabled)
this->CacheValues->cacheModel()->setEditEnabled(enabled);
this->SourceDirectory->setEnabled(enabled);
this->BrowseSourceDirectoryButton->setEnabled(enabled);
+ this->Preset->setEnabled(enabled);
this->BinaryDirectory->setEnabled(enabled);
this->BrowseBinaryDirectoryButton->setEnabled(enabled);
this->ReloadCacheAction->setEnabled(enabled);
@@ -777,6 +848,17 @@ bool CMakeSetupDialog::setupFirstConfigure()
// restore from settings
dialog.loadFromSettings();
+ auto presetData = this->Preset->currentData();
+ if (presetData.isValid()) {
+ auto preset = presetData.value<QCMakePreset>();
+ dialog.setCurrentGenerator(preset.generator);
+ if (preset.setGenConfig) {
+ dialog.setPlatform(preset.architecture);
+ dialog.setToolset(preset.toolset);
+ }
+ dialog.setCompilerOption(CompilerOption::DefaultNative);
+ }
+
if (dialog.exec() == QDialog::Accepted) {
dialog.saveToSettings();
this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator());