From d471406f0b41b99579cb07770302555c138d47a0 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Wed, 14 Oct 2020 15:30:45 -0400 Subject: CMake GUI: Disable preset fields instead of hiding them --- Source/QtDialog/CMakeSetupDialog.cxx | 13 ++++++++++--- Source/QtDialog/CMakeSetupDialog.ui | 6 +++++- Tests/CMakeGUI/CMakeGUITest.cxx | 27 +++++++++------------------ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index acd32ec..7a04daa 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -43,6 +43,12 @@ #include "RegexExplorer.h" #include "WarningMessagesDialog.h" +namespace { +const QString PRESETS_DISABLED_TOOLTIP = + "This option is disabled because there are no available presets in " + "CMakePresets.json or CMakeUserPresets.json."; +} + QCMakeThread::QCMakeThread(QObject* p) : QThread(p) { @@ -92,6 +98,7 @@ CMakeSetupDialog::CMakeSetupDialog() this->ProgressBar->reset(); this->RemoveEntry->setEnabled(false); this->AddEntry->setEnabled(false); + this->Preset->setStatusTip(PRESETS_DISABLED_TOOLTIP); QByteArray p = settings.value("SplitterSizes").toByteArray(); this->Splitter->restoreState(p); @@ -696,8 +703,8 @@ void CMakeSetupDialog::updatePresets(const QVector& presets) this->Preset->blockSignals(false); } - this->Preset->setHidden(presets.isEmpty()); - this->PresetLabel->setHidden(presets.isEmpty()); + this->Preset->setDisabled(presets.isEmpty()); + this->Preset->setToolTip(presets.isEmpty() ? PRESETS_DISABLED_TOOLTIP : ""); if (!this->DeferredPreset.isNull()) { this->Preset->setPresetName(this->DeferredPreset); @@ -823,7 +830,7 @@ void CMakeSetupDialog::setEnabledState(bool enabled) this->CacheValues->cacheModel()->setEditEnabled(enabled); this->SourceDirectory->setEnabled(enabled); this->BrowseSourceDirectoryButton->setEnabled(enabled); - this->Preset->setEnabled(enabled); + this->Preset->setEnabled(enabled && !this->Preset->presets().isEmpty()); this->BinaryDirectory->setEnabled(enabled); this->BrowseBinaryDirectoryButton->setEnabled(enabled); this->ReloadCacheAction->setEnabled(enabled); diff --git a/Source/QtDialog/CMakeSetupDialog.ui b/Source/QtDialog/CMakeSetupDialog.ui index afb25eb..a5c35b1 100644 --- a/Source/QtDialog/CMakeSetupDialog.ui +++ b/Source/QtDialog/CMakeSetupDialog.ui @@ -68,7 +68,11 @@ - + + + false + + diff --git a/Tests/CMakeGUI/CMakeGUITest.cxx b/Tests/CMakeGUI/CMakeGUITest.cxx index 5a6bec3..2b5d973 100644 --- a/Tests/CMakeGUI/CMakeGUITest.cxx +++ b/Tests/CMakeGUI/CMakeGUITest.cxx @@ -356,16 +356,14 @@ void CMakeGUITest::changingPresets() QCOMPARE(this->m_window->Preset->presetName(), QString{}); QCOMPARE(this->m_window->Preset->presets().size(), 0); QCOMPARE(this->m_window->BinaryDirectory->currentText(), ""); - QCOMPARE(this->m_window->Preset->isHidden(), true); - QCOMPARE(this->m_window->PresetLabel->isHidden(), true); + QCOMPARE(this->m_window->Preset->isEnabled(), false); writePresets("build1", { "preset" }); loopSleep(1500); QCOMPARE(this->m_window->Preset->presetName(), QString{}); QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->BinaryDirectory->currentText(), ""); - QCOMPARE(this->m_window->Preset->isHidden(), false); - QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + QCOMPARE(this->m_window->Preset->isEnabled(), true); this->m_window->Preset->setPresetName("preset"); loopSleep(); @@ -373,8 +371,7 @@ void CMakeGUITest::changingPresets() QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->BinaryDirectory->currentText(), CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset"); - QCOMPARE(this->m_window->Preset->isHidden(), false); - QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + QCOMPARE(this->m_window->Preset->isEnabled(), true); writePresets("build2", { "preset2", "preset" }); loopSleep(1500); @@ -382,8 +379,7 @@ void CMakeGUITest::changingPresets() QCOMPARE(this->m_window->Preset->presets().size(), 2); QCOMPARE(this->m_window->BinaryDirectory->currentText(), CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset"); - QCOMPARE(this->m_window->Preset->isHidden(), false); - QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + QCOMPARE(this->m_window->Preset->isEnabled(), true); writePresets("build3", { "preset2" }); loopSleep(1500); @@ -391,8 +387,7 @@ void CMakeGUITest::changingPresets() QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->BinaryDirectory->currentText(), CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset"); - QCOMPARE(this->m_window->Preset->isHidden(), false); - QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + QCOMPARE(this->m_window->Preset->isEnabled(), true); this->m_window->Preset->setPresetName("preset2"); loopSleep(); @@ -400,8 +395,7 @@ void CMakeGUITest::changingPresets() QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->BinaryDirectory->currentText(), CMakeGUITest_BINARY_DIR "/changingPresets/src/build3/preset2"); - QCOMPARE(this->m_window->Preset->isHidden(), false); - QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + QCOMPARE(this->m_window->Preset->isEnabled(), true); QDir::root().mkpath(CMakeGUITest_BINARY_DIR "/changingPresets/src2"); QFile::copy(CMakeGUITest_BINARY_DIR "/changingPresets/src/CMakePresets.json", @@ -414,8 +408,7 @@ void CMakeGUITest::changingPresets() QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->BinaryDirectory->currentText(), CMakeGUITest_BINARY_DIR "/changingPresets/src/build3/preset2"); - QCOMPARE(this->m_window->Preset->isHidden(), false); - QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + QCOMPARE(this->m_window->Preset->isEnabled(), true); this->m_window->Preset->setPresetName("preset2"); loopSleep(); @@ -423,8 +416,7 @@ void CMakeGUITest::changingPresets() QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->BinaryDirectory->currentText(), CMakeGUITest_BINARY_DIR "/changingPresets/src2/build3/preset2"); - QCOMPARE(this->m_window->Preset->isHidden(), false); - QCOMPARE(this->m_window->PresetLabel->isHidden(), false); + QCOMPARE(this->m_window->Preset->isEnabled(), true); QFile(CMakeGUITest_BINARY_DIR "/changingPresets/src2/CMakePresets.json") .remove(); @@ -433,8 +425,7 @@ void CMakeGUITest::changingPresets() QCOMPARE(this->m_window->Preset->presets().size(), 0); QCOMPARE(this->m_window->BinaryDirectory->currentText(), CMakeGUITest_BINARY_DIR "/changingPresets/src2/build3/preset2"); - QCOMPARE(this->m_window->Preset->isHidden(), true); - QCOMPARE(this->m_window->PresetLabel->isHidden(), true); + QCOMPARE(this->m_window->Preset->isEnabled(), false); } void SetupDefaultQSettings() -- cgit v0.12