PE: Fix Kit enablement

The TargetSetupWidget::toggleEnabled(), called first, sets the enablement
for TargetSetupWidget's subcontrols, but not for TargetSetupWidget
itself.

In the scenario from the bugreport the toggleEnabled() was called
with false, but the enablement of TargetSetupWidget was still true.
Later, when selectAtLeastOneEnabledKit() is called, the internals
take TargetSetupWidget's enablement into account, not the state
set with previous call to toggleEnabled().

Rename toggleEnabled() into setValid(), store the flag internally,
and add a getter isValid(). Reuse this getter in
selectAtLeastOneEnabledKit().

Fixes: QTCREATORBUG-31879
Change-Id: I7b9be718cc6732afab6eb26387b2a88701a7fd67
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-10-23 10:13:24 +02:00
parent 9879446548
commit 37d8c1e44c
3 changed files with 14 additions and 11 deletions

View File

@@ -460,7 +460,7 @@ void TargetSetupPagePrivate::selectAtLeastOneEnabledKit()
auto isPreferred = [this](const TargetSetupWidget *w) { auto isPreferred = [this](const TargetSetupWidget *w) {
const Tasks tasks = m_tasksGenerator(w->kit()); const Tasks tasks = m_tasksGenerator(w->kit());
return w->isEnabled() && tasks.isEmpty(); return w->isValid() && tasks.isEmpty();
}; };
// Use default kit if that is preferred: // Use default kit if that is preferred:
@@ -476,14 +476,14 @@ void TargetSetupPagePrivate::selectAtLeastOneEnabledKit()
if (!toCheckWidget) { if (!toCheckWidget) {
// Use default kit if it is enabled: // Use default kit if it is enabled:
toCheckWidget = findOrDefault(m_widgets, [defaultKit](const TargetSetupWidget *w) { toCheckWidget = findOrDefault(m_widgets, [defaultKit](const TargetSetupWidget *w) {
return w->isEnabled() && w->kit() == defaultKit; return w->isValid() && w->kit() == defaultKit;
}); });
} }
if (!toCheckWidget) { if (!toCheckWidget) {
// Use the first enabled widget: // Use the first enabled widget:
toCheckWidget = findOrDefault(m_widgets, toCheckWidget = findOrDefault(m_widgets,
[](const TargetSetupWidget *w) { return w->isEnabled(); }); [](const TargetSetupWidget *w) { return w->isValid(); });
} }
if (toCheckWidget) { if (toCheckWidget) {

View File

@@ -217,12 +217,12 @@ void TargetSetupWidget::update(const TasksGenerator &generator)
// Kits that where the taskGenarator reports an error are not selectable, because we cannot // Kits that where the taskGenarator reports an error are not selectable, because we cannot
// guarantee that we can handle the project sensibly (e.g. qmake project without Qt). // guarantee that we can handle the project sensibly (e.g. qmake project without Qt).
if (!errorTask.isNull()) { if (!errorTask.isNull()) {
toggleEnabled(false); setValid(false);
m_infoStore.clear(); m_infoStore.clear();
return; return;
} }
toggleEnabled(true); setValid(true);
updateDefaultBuildDirectories(); updateDefaultBuildDirectories();
} }
@@ -241,12 +241,13 @@ bool TargetSetupWidget::hasSelectableBuildConfigurations() const
return !m_infoStore.empty(); return !m_infoStore.empty();
} }
void TargetSetupWidget::toggleEnabled(bool enabled) void TargetSetupWidget::setValid(bool valid)
{ {
m_detailsWidget->widget()->setEnabled(enabled); m_isValid = valid;
m_detailsWidget->setCheckable(enabled); m_detailsWidget->widget()->setEnabled(valid);
m_detailsWidget->setExpandable(enabled && hasSelectableBuildConfigurations()); m_detailsWidget->setCheckable(valid);
if (!enabled) { m_detailsWidget->setExpandable(valid && hasSelectableBuildConfigurations());
if (!valid) {
m_detailsWidget->setState(DetailsWidget::Collapsed); m_detailsWidget->setState(DetailsWidget::Collapsed);
m_detailsWidget->setChecked(false); m_detailsWidget->setChecked(false);
} }

View File

@@ -43,6 +43,7 @@ public:
bool isKitSelected() const; bool isKitSelected() const;
void setKitSelected(bool b); void setKitSelected(bool b);
bool isValid() const { return m_isValid; }
void addBuildInfo(const BuildInfo &info, bool isImport); void addBuildInfo(const BuildInfo &info, bool isImport);
@@ -59,7 +60,7 @@ private:
bool hasSelectableBuildConfigurations() const; bool hasSelectableBuildConfigurations() const;
void toggleEnabled(bool enabled); void setValid(bool valid);
void checkBoxToggled(QCheckBox *checkBox, bool b); void checkBoxToggled(QCheckBox *checkBox, bool b);
void pathChanged(Utils::PathChooser *pathChooser); void pathChanged(Utils::PathChooser *pathChooser);
void targetCheckBoxToggled(bool b); void targetCheckBoxToggled(bool b);
@@ -70,6 +71,7 @@ private:
void clear(); void clear();
void updateDefaultBuildDirectories(); void updateDefaultBuildDirectories();
bool m_isValid = false;
Kit *m_kit; Kit *m_kit;
Utils::FilePath m_projectPath; Utils::FilePath m_projectPath;
bool m_haveImported = false; bool m_haveImported = false;