diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp index d7ecacc0668..4a39dd9d3b8 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp @@ -365,7 +365,6 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc) } connect(bc->buildSystem(), &BuildSystem::parsingFinished, this, [this, stretcher] { - m_configModel->flush(); m_configModel->setConfiguration(m_buildConfiguration->configurationFromCMake()); m_configModel->setInitialParametersConfiguration( m_buildConfiguration->initialCMakeConfiguration()); @@ -1622,6 +1621,8 @@ void InitialCMakeArgumentsAspect::setAllValues(const QString &values, QStringLis arg.replace("-T", "-DCMAKE_GENERATOR_TOOLSET:STRING="); } m_cmakeConfiguration = CMakeConfig::fromArguments(arguments, additionalArguments); + for (CMakeConfigItem &ci : m_cmakeConfiguration) + ci.isInitial = true; // Display the unknown arguments in "Additional CMake parameters" const QString additionalArgumentsValue = ProcessArgs::joinArgs(additionalArguments); @@ -1631,6 +1632,8 @@ void InitialCMakeArgumentsAspect::setAllValues(const QString &values, QStringLis void InitialCMakeArgumentsAspect::setCMakeConfiguration(const CMakeConfig &config) { m_cmakeConfiguration = config; + for (CMakeConfigItem &ci : m_cmakeConfiguration) + ci.isInitial = true; } void InitialCMakeArgumentsAspect::fromMap(const QVariantMap &map) diff --git a/src/plugins/cmakeprojectmanager/configmodel.cpp b/src/plugins/cmakeprojectmanager/configmodel.cpp index aa74f3986b6..fe11f9367b5 100644 --- a/src/plugins/cmakeprojectmanager/configmodel.cpp +++ b/src/plugins/cmakeprojectmanager/configmodel.cpp @@ -272,46 +272,61 @@ void ConfigModel::setInitialParametersConfiguration(const CMakeConfig &config) void ConfigModel::setConfiguration(const QList &config) { - QList tmp = config; - auto newIt = tmp.constBegin(); - auto newEndIt = tmp.constEnd(); - auto oldIt = m_configuration.constBegin(); - auto oldEndIt = m_configuration.constEnd(); + auto mergeLists = [](const QList &oldList, + const QList &newList) -> QList { + auto newIt = newList.constBegin(); + auto newEndIt = newList.constEnd(); + auto oldIt = oldList.constBegin(); + auto oldEndIt = oldList.constEnd(); - QList result; - while (newIt != newEndIt && oldIt != oldEndIt) { - if (oldIt->isUnset) { - ++oldIt; - } else if (newIt->isHidden || newIt->isUnset) { - ++newIt; - } else if (newIt->key < oldIt->key) { - // Add new entry: - result << *newIt; - ++newIt; - } else if (newIt->key > oldIt->key) { - // Keep old user settings, but skip other entries: - if (oldIt->isUserChanged || oldIt->isUserNew) - result << InternalDataItem(*oldIt); - ++oldIt; - } else { - // merge old/new entry: - InternalDataItem item(*newIt); - item.newValue = (newIt->value != oldIt->newValue) ? oldIt->newValue : QString(); - item.isUserChanged = !item.newValue.isEmpty() && (item.newValue != item.value); - result << item; - ++newIt; - ++oldIt; + QList result; + while (newIt != newEndIt && oldIt != oldEndIt) { + if (oldIt->isUnset) { + ++oldIt; + } else if (newIt->isHidden || newIt->isUnset) { + ++newIt; + } else if (newIt->key < oldIt->key) { + // Add new entry: + result << *newIt; + ++newIt; + } else if (newIt->key > oldIt->key) { + // Keep old user settings, but skip other entries: + if (oldIt->isUserChanged || oldIt->isUserNew) + result << InternalDataItem(*oldIt); + ++oldIt; + } else { + // merge old/new entry: + InternalDataItem item(*newIt); + item.newValue = (newIt->value != oldIt->newValue) ? oldIt->newValue : QString(); + item.isUserChanged = !item.newValue.isEmpty() && (item.newValue != item.value); + result << item; + ++newIt; + ++oldIt; + } } - } - // Add remaining new entries: - for (; newIt != newEndIt; ++newIt) { - if (newIt->isHidden) - continue; - result << InternalDataItem(*newIt); - } + // Add remaining new entries: + for (; newIt != newEndIt; ++newIt) { + if (newIt->isHidden) + continue; + result << InternalDataItem(*newIt); + } - m_configuration = result; + return result; + }; + + auto isInitial = [](const InternalDataItem &i) { return i.isInitial; }; + + QList initialOld; + QList currentOld; + std::tie(initialOld, currentOld) = Utils::partition(m_configuration, isInitial); + + QList initialNew; + QList currentNew; + std::tie(initialNew, currentNew) = Utils::partition(config, isInitial); + + m_configuration = mergeLists(initialOld, initialNew); + m_configuration.append(mergeLists(currentOld, currentNew)); generateTree(); }