Commit d471406f authored by Kyle Edwards's avatar Kyle Edwards
Browse files

CMake GUI: Disable preset fields instead of hiding them

parent 1356230b
...@@ -43,6 +43,12 @@ ...@@ -43,6 +43,12 @@
#include "RegexExplorer.h" #include "RegexExplorer.h"
#include "WarningMessagesDialog.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) QCMakeThread::QCMakeThread(QObject* p)
: QThread(p) : QThread(p)
{ {
...@@ -92,6 +98,7 @@ CMakeSetupDialog::CMakeSetupDialog() ...@@ -92,6 +98,7 @@ CMakeSetupDialog::CMakeSetupDialog()
this->ProgressBar->reset(); this->ProgressBar->reset();
this->RemoveEntry->setEnabled(false); this->RemoveEntry->setEnabled(false);
this->AddEntry->setEnabled(false); this->AddEntry->setEnabled(false);
this->Preset->setStatusTip(PRESETS_DISABLED_TOOLTIP);
QByteArray p = settings.value("SplitterSizes").toByteArray(); QByteArray p = settings.value("SplitterSizes").toByteArray();
this->Splitter->restoreState(p); this->Splitter->restoreState(p);
...@@ -696,8 +703,8 @@ void CMakeSetupDialog::updatePresets(const QVector<QCMakePreset>& presets) ...@@ -696,8 +703,8 @@ void CMakeSetupDialog::updatePresets(const QVector<QCMakePreset>& presets)
this->Preset->blockSignals(false); this->Preset->blockSignals(false);
} }
this->Preset->setHidden(presets.isEmpty()); this->Preset->setDisabled(presets.isEmpty());
this->PresetLabel->setHidden(presets.isEmpty()); this->Preset->setToolTip(presets.isEmpty() ? PRESETS_DISABLED_TOOLTIP : "");
if (!this->DeferredPreset.isNull()) { if (!this->DeferredPreset.isNull()) {
this->Preset->setPresetName(this->DeferredPreset); this->Preset->setPresetName(this->DeferredPreset);
...@@ -823,7 +830,7 @@ void CMakeSetupDialog::setEnabledState(bool enabled) ...@@ -823,7 +830,7 @@ void CMakeSetupDialog::setEnabledState(bool enabled)
this->CacheValues->cacheModel()->setEditEnabled(enabled); this->CacheValues->cacheModel()->setEditEnabled(enabled);
this->SourceDirectory->setEnabled(enabled); this->SourceDirectory->setEnabled(enabled);
this->BrowseSourceDirectoryButton->setEnabled(enabled); this->BrowseSourceDirectoryButton->setEnabled(enabled);
this->Preset->setEnabled(enabled); this->Preset->setEnabled(enabled && !this->Preset->presets().isEmpty());
this->BinaryDirectory->setEnabled(enabled); this->BinaryDirectory->setEnabled(enabled);
this->BrowseBinaryDirectoryButton->setEnabled(enabled); this->BrowseBinaryDirectoryButton->setEnabled(enabled);
this->ReloadCacheAction->setEnabled(enabled); this->ReloadCacheAction->setEnabled(enabled);
......
...@@ -68,7 +68,11 @@ ...@@ -68,7 +68,11 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QCMakePresetComboBox" name="Preset"/> <widget class="QCMakePresetComboBox" name="Preset">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="BinaryLabel"> <widget class="QLabel" name="BinaryLabel">
......
...@@ -356,16 +356,14 @@ void CMakeGUITest::changingPresets() ...@@ -356,16 +356,14 @@ void CMakeGUITest::changingPresets()
QCOMPARE(this->m_window->Preset->presetName(), QString{}); QCOMPARE(this->m_window->Preset->presetName(), QString{});
QCOMPARE(this->m_window->Preset->presets().size(), 0); QCOMPARE(this->m_window->Preset->presets().size(), 0);
QCOMPARE(this->m_window->BinaryDirectory->currentText(), ""); QCOMPARE(this->m_window->BinaryDirectory->currentText(), "");
QCOMPARE(this->m_window->Preset->isHidden(), true); QCOMPARE(this->m_window->Preset->isEnabled(), false);
QCOMPARE(this->m_window->PresetLabel->isHidden(), true);
writePresets("build1", { "preset" }); writePresets("build1", { "preset" });
loopSleep(1500); loopSleep(1500);
QCOMPARE(this->m_window->Preset->presetName(), QString{}); QCOMPARE(this->m_window->Preset->presetName(), QString{});
QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->Preset->presets().size(), 1);
QCOMPARE(this->m_window->BinaryDirectory->currentText(), ""); QCOMPARE(this->m_window->BinaryDirectory->currentText(), "");
QCOMPARE(this->m_window->Preset->isHidden(), false); QCOMPARE(this->m_window->Preset->isEnabled(), true);
QCOMPARE(this->m_window->PresetLabel->isHidden(), false);
this->m_window->Preset->setPresetName("preset"); this->m_window->Preset->setPresetName("preset");
loopSleep(); loopSleep();
...@@ -373,8 +371,7 @@ void CMakeGUITest::changingPresets() ...@@ -373,8 +371,7 @@ void CMakeGUITest::changingPresets()
QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->Preset->presets().size(), 1);
QCOMPARE(this->m_window->BinaryDirectory->currentText(), QCOMPARE(this->m_window->BinaryDirectory->currentText(),
CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset"); CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset");
QCOMPARE(this->m_window->Preset->isHidden(), false); QCOMPARE(this->m_window->Preset->isEnabled(), true);
QCOMPARE(this->m_window->PresetLabel->isHidden(), false);
writePresets("build2", { "preset2", "preset" }); writePresets("build2", { "preset2", "preset" });
loopSleep(1500); loopSleep(1500);
...@@ -382,8 +379,7 @@ void CMakeGUITest::changingPresets() ...@@ -382,8 +379,7 @@ void CMakeGUITest::changingPresets()
QCOMPARE(this->m_window->Preset->presets().size(), 2); QCOMPARE(this->m_window->Preset->presets().size(), 2);
QCOMPARE(this->m_window->BinaryDirectory->currentText(), QCOMPARE(this->m_window->BinaryDirectory->currentText(),
CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset"); CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset");
QCOMPARE(this->m_window->Preset->isHidden(), false); QCOMPARE(this->m_window->Preset->isEnabled(), true);
QCOMPARE(this->m_window->PresetLabel->isHidden(), false);
writePresets("build3", { "preset2" }); writePresets("build3", { "preset2" });
loopSleep(1500); loopSleep(1500);
...@@ -391,8 +387,7 @@ void CMakeGUITest::changingPresets() ...@@ -391,8 +387,7 @@ void CMakeGUITest::changingPresets()
QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->Preset->presets().size(), 1);
QCOMPARE(this->m_window->BinaryDirectory->currentText(), QCOMPARE(this->m_window->BinaryDirectory->currentText(),
CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset"); CMakeGUITest_BINARY_DIR "/changingPresets/src/build1/preset");
QCOMPARE(this->m_window->Preset->isHidden(), false); QCOMPARE(this->m_window->Preset->isEnabled(), true);
QCOMPARE(this->m_window->PresetLabel->isHidden(), false);
this->m_window->Preset->setPresetName("preset2"); this->m_window->Preset->setPresetName("preset2");
loopSleep(); loopSleep();
...@@ -400,8 +395,7 @@ void CMakeGUITest::changingPresets() ...@@ -400,8 +395,7 @@ void CMakeGUITest::changingPresets()
QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->Preset->presets().size(), 1);
QCOMPARE(this->m_window->BinaryDirectory->currentText(), QCOMPARE(this->m_window->BinaryDirectory->currentText(),
CMakeGUITest_BINARY_DIR "/changingPresets/src/build3/preset2"); CMakeGUITest_BINARY_DIR "/changingPresets/src/build3/preset2");
QCOMPARE(this->m_window->Preset->isHidden(), false); QCOMPARE(this->m_window->Preset->isEnabled(), true);
QCOMPARE(this->m_window->PresetLabel->isHidden(), false);
QDir::root().mkpath(CMakeGUITest_BINARY_DIR "/changingPresets/src2"); QDir::root().mkpath(CMakeGUITest_BINARY_DIR "/changingPresets/src2");
QFile::copy(CMakeGUITest_BINARY_DIR "/changingPresets/src/CMakePresets.json", QFile::copy(CMakeGUITest_BINARY_DIR "/changingPresets/src/CMakePresets.json",
...@@ -414,8 +408,7 @@ void CMakeGUITest::changingPresets() ...@@ -414,8 +408,7 @@ void CMakeGUITest::changingPresets()
QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->Preset->presets().size(), 1);
QCOMPARE(this->m_window->BinaryDirectory->currentText(), QCOMPARE(this->m_window->BinaryDirectory->currentText(),
CMakeGUITest_BINARY_DIR "/changingPresets/src/build3/preset2"); CMakeGUITest_BINARY_DIR "/changingPresets/src/build3/preset2");
QCOMPARE(this->m_window->Preset->isHidden(), false); QCOMPARE(this->m_window->Preset->isEnabled(), true);
QCOMPARE(this->m_window->PresetLabel->isHidden(), false);
this->m_window->Preset->setPresetName("preset2"); this->m_window->Preset->setPresetName("preset2");
loopSleep(); loopSleep();
...@@ -423,8 +416,7 @@ void CMakeGUITest::changingPresets() ...@@ -423,8 +416,7 @@ void CMakeGUITest::changingPresets()
QCOMPARE(this->m_window->Preset->presets().size(), 1); QCOMPARE(this->m_window->Preset->presets().size(), 1);
QCOMPARE(this->m_window->BinaryDirectory->currentText(), QCOMPARE(this->m_window->BinaryDirectory->currentText(),
CMakeGUITest_BINARY_DIR "/changingPresets/src2/build3/preset2"); CMakeGUITest_BINARY_DIR "/changingPresets/src2/build3/preset2");
QCOMPARE(this->m_window->Preset->isHidden(), false); QCOMPARE(this->m_window->Preset->isEnabled(), true);
QCOMPARE(this->m_window->PresetLabel->isHidden(), false);
QFile(CMakeGUITest_BINARY_DIR "/changingPresets/src2/CMakePresets.json") QFile(CMakeGUITest_BINARY_DIR "/changingPresets/src2/CMakePresets.json")
.remove(); .remove();
...@@ -433,8 +425,7 @@ void CMakeGUITest::changingPresets() ...@@ -433,8 +425,7 @@ void CMakeGUITest::changingPresets()
QCOMPARE(this->m_window->Preset->presets().size(), 0); QCOMPARE(this->m_window->Preset->presets().size(), 0);
QCOMPARE(this->m_window->BinaryDirectory->currentText(), QCOMPARE(this->m_window->BinaryDirectory->currentText(),
CMakeGUITest_BINARY_DIR "/changingPresets/src2/build3/preset2"); CMakeGUITest_BINARY_DIR "/changingPresets/src2/build3/preset2");
QCOMPARE(this->m_window->Preset->isHidden(), true); QCOMPARE(this->m_window->Preset->isEnabled(), false);
QCOMPARE(this->m_window->PresetLabel->isHidden(), true);
} }
void SetupDefaultQSettings() void SetupDefaultQSettings()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment