CMake: Improve handling of QML Debugging and Profiling option

The additional parameters to pass to CMake are set in a
"extraCMakeArguments" property, but we had two places where this was
set, overwriting each other: from the list widget where the user makes
changes, and from the QML debugging option.

Combine the two code paths. This has the additional advantage that the
changing QML Debugging and Profiling option behaves the same as changing
variables in the list - the "Apply Configuration Changes" button gets
enabled when changing the option, and one can use it to apply the
change.

Task-number: QTCREATORBUG-24988
Change-Id: I785c6804c9597a9eba471f56babaae966ce84b17
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Eike Ziller
2020-12-02 15:09:37 +01:00
parent f946e5b356
commit 7aa96780ed
2 changed files with 48 additions and 49 deletions

View File

@@ -115,8 +115,9 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
++row;
auto qmlDebugAspect = bc->aspect<QtSupport::QmlDebuggingAspect>();
connect(qmlDebugAspect, &QtSupport::QmlDebuggingAspect::changed,
this, [this]() { handleQmlDebugCxxFlags(); });
connect(qmlDebugAspect, &QtSupport::QmlDebuggingAspect::changed, this, [this]() {
updateButtonState();
});
auto widget = new QWidget;
LayoutBuilder builder(widget);
qmlDebugAspect->addToLayout(builder);
@@ -259,7 +260,6 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
m_configView->setEnabled(true);
stretcher->stretch();
updateButtonState();
handleQmlDebugCxxFlags();
m_showProgressTimer.stop();
m_progressIndicator->hide();
});
@@ -360,43 +360,44 @@ void CMakeBuildSettingsWidget::setWarning(const QString &message)
void CMakeBuildSettingsWidget::updateButtonState()
{
const bool isParsing = m_buildConfiguration->buildSystem()->isParsing();
const bool hasChanges = m_configModel->hasChanges();
m_resetButton->setEnabled(hasChanges && !isParsing);
m_reconfigureButton->setEnabled((hasChanges || m_configModel->hasCMakeChanges()) && !isParsing);
// Update extra data in buildconfiguration
const QList<ConfigModel::DataItem> changes = m_configModel->configurationForCMake();
const CMakeConfig configChanges = Utils::transform(changes, [](const ConfigModel::DataItem &i) {
CMakeConfigItem ni;
ni.key = i.key.toUtf8();
ni.value = i.value.toUtf8();
ni.documentation = i.description.toUtf8();
ni.isAdvanced = i.isAdvanced;
ni.isUnset = i.isUnset;
ni.inCMakeCache = i.inCMakeCache;
ni.values = i.values;
switch (i.type) {
case CMakeProjectManager::ConfigModel::DataItem::BOOLEAN:
ni.type = CMakeConfigItem::BOOL;
break;
case CMakeProjectManager::ConfigModel::DataItem::FILE:
ni.type = CMakeConfigItem::FILEPATH;
break;
case CMakeProjectManager::ConfigModel::DataItem::DIRECTORY:
ni.type = CMakeConfigItem::PATH;
break;
case CMakeProjectManager::ConfigModel::DataItem::STRING:
ni.type = CMakeConfigItem::STRING;
break;
case CMakeProjectManager::ConfigModel::DataItem::UNKNOWN:
default:
ni.type = CMakeConfigItem::INTERNAL;
break;
}
return ni;
});
const CMakeConfig configChanges
= getQmlDebugCxxFlags() + Utils::transform(changes, [](const ConfigModel::DataItem &i) {
CMakeConfigItem ni;
ni.key = i.key.toUtf8();
ni.value = i.value.toUtf8();
ni.documentation = i.description.toUtf8();
ni.isAdvanced = i.isAdvanced;
ni.isUnset = i.isUnset;
ni.inCMakeCache = i.inCMakeCache;
ni.values = i.values;
switch (i.type) {
case CMakeProjectManager::ConfigModel::DataItem::BOOLEAN:
ni.type = CMakeConfigItem::BOOL;
break;
case CMakeProjectManager::ConfigModel::DataItem::FILE:
ni.type = CMakeConfigItem::FILEPATH;
break;
case CMakeProjectManager::ConfigModel::DataItem::DIRECTORY:
ni.type = CMakeConfigItem::PATH;
break;
case CMakeProjectManager::ConfigModel::DataItem::STRING:
ni.type = CMakeConfigItem::STRING;
break;
case CMakeProjectManager::ConfigModel::DataItem::UNKNOWN:
default:
ni.type = CMakeConfigItem::INTERNAL;
break;
}
return ni;
});
m_resetButton->setEnabled(m_configModel->hasChanges() && !isParsing);
m_reconfigureButton->setEnabled((!configChanges.isEmpty() || m_configModel->hasCMakeChanges())
&& !isParsing);
m_buildConfiguration->setExtraCMakeArguments(
Utils::transform(configChanges, [](const CMakeConfigItem &i) { return i.toArgument(); }));
}
@@ -426,10 +427,12 @@ void CMakeBuildSettingsWidget::updateFromKit()
m_configModel->setConfigurationFromKit(configHash);
}
void CMakeBuildSettingsWidget::handleQmlDebugCxxFlags()
CMakeConfig CMakeBuildSettingsWidget::getQmlDebugCxxFlags()
{
bool changed = false;
const auto aspect = m_buildConfiguration->aspect<QtSupport::QmlDebuggingAspect>();
const TriState qmlDebuggingState = aspect->setting();
if (qmlDebuggingState == TriState::Default) // don't touch anything
return {};
const bool enable = aspect->setting() == TriState::Enabled;
const CMakeConfig configList = m_buildConfiguration->configurationFromCMake();
@@ -446,25 +449,19 @@ void CMakeBuildSettingsWidget::handleQmlDebugCxxFlags()
CMakeConfigItem it(item);
if (enable) {
if (!it.value.contains(qmlDebug)) {
it.value = it.value.append(' ').append(qmlDebug);
changed = true;
it.value = it.value.append(' ').append(qmlDebug).trimmed();
changedConfig.append(it);
}
} else {
int index = it.value.indexOf(qmlDebug);
if (index != -1) {
it.value.remove(index, qmlDebug.length());
changed = true;
it.value = it.value.trimmed();
changedConfig.append(it);
}
}
it.value = it.value.trimmed();
changedConfig.append(it);
}
if (changed) {
m_buildConfiguration->setExtraCMakeArguments(
Utils::transform(changedConfig,
[](const CMakeConfigItem &i) { return i.toArgument(); }));
}
return changedConfig;
}
void CMakeBuildSettingsWidget::updateSelection()

View File

@@ -25,6 +25,8 @@
#pragma once
#include "cmakeconfigitem.h"
#include <projectexplorer/namedwidget.h>
#include <QTimer>
@@ -66,7 +68,7 @@ private:
void updateButtonState();
void updateAdvancedCheckBox();
void updateFromKit();
void handleQmlDebugCxxFlags();
CMakeProjectManager::CMakeConfig getQmlDebugCxxFlags();
void updateSelection();
void setVariableUnsetFlag(bool unsetFlag);