[kdevelop/kdevelop] plugins/custom-definesandincludes/compilerprovider: custom-definesandincludes: when reading settings preserve includes order

Martin Bednar <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 95eeca07fd2666b5e3e905000624213e31cf0fed by Martin Bednar, on behalf of Benjamin ROBIN.
Committed on 21/07/2026 at 10:38.
Pushed by bednar into branch 'master'.

custom-definesandincludes: when reading settings preserve includes order

When saving the include paths in doWriteSettings(), each include path is
saved into a configuration entry which key is the index serialized to
string.
When loading the include paths from doReadSettings(), the associated QMap
is retrieved, which by default sort by key. But since the key is not longer
an integer, but a string, then "10" is between "1" and "2".
So to preserve the order, when reading the settings, create a new temporary
QMap which key is an integer.

BUG: 523168
FIXED-IN: 6.5.260800
Pick-to: release/26.08

M  +9    -3    plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp

https://invent.kde.org/kdevelop/kdevelop/-/commit/95eeca07fd2666b5e3e905000624213e31cf0fed

diff --git a/plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp b/plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp
index c24bfda0a4..49161ba456 100644
--- a/plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp
+++ b/plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp
@@ -224,10 +224,16 @@ QVector<ConfigEntry> doReadSettings( KConfigGroup grp, bool remove = false )
             } else {
                 KConfigGroup includes(pathgrp.group(ConfigConstants::includesKey()));
                 const QMap<QString, QString> incMap = includes.entryMap();
-                for (auto& value :incMap) {
-                    if(value.isEmpty()){
-                        continue;
+
+                // Create a new QMap with an integer as key, to preserve the order
+                QMap<int, QString> incMapSorted;
+                for (const auto [key, value] : incMap.asKeyValueRange()) {
+                    if (!value.isEmpty()) {
+                        incMapSorted[key.toInt()] = value;
                     }
+                }
+
+                for (auto& value: incMapSorted) {
                     path.includes += value;
                 }
             }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.