[education/kstars] kstars/ekos: Fix -1 corrupting persisted combo settings before device connects

Jasem Mutlaq <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit a671443ed5eb82f580099b3331dc2eb81bfb948f by Jasem Mutlaq.
Committed on 29/07/2026 at 10:31.
Pushed by mutlaqja into branch 'master'.

Fix -1 corrupting persisted combo settings before device connects

Commit ed45dee63 made setAllSettings() persist QComboBox::currentIndex()
to the global kcfg options for every combo in the settings map. Several
combos (e.g. guide/CCD binning) are only populated once a device connects
via INDI, so when setAllSettings() runs during module init the combo is
still empty and currentIndex() returns -1, which then overwrites the
previously saved option (e.g. GuideBinning) with -1 instead of leaving it
untouched. Downstream, an invalid binning index corrupts guide star SNR
and StarMass metrics on every frame.

Only write the combo's index when it is actually populated and has a
valid selection; otherwise leave the persisted option alone. Applied
identically in guide.cpp, mount.cpp, align_settings.cpp, darklibrary.cpp
and focus.cpp, which all share the same pattern introduced in ed45dee63.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

M  +6    -1    kstars/ekos/align/align_settings.cpp
M  +6    -1    kstars/ekos/auxiliary/darklibrary.cpp
M  +6    -1    kstars/ekos/focus/focus.cpp
M  +6    -1    kstars/ekos/guide/guide.cpp
M  +6    -1    kstars/ekos/mount/mount.cpp

https://invent.kde.org/education/kstars/-/commit/a671443ed5eb82f580099b3331dc2eb81bfb948f

diff --git a/kstars/ekos/align/align_settings.cpp b/kstars/ekos/align/align_settings.cpp
index d7760524c2..b26af7051f 100644
--- a/kstars/ekos/align/align_settings.cpp
+++ b/kstars/ekos/align/align_settings.cpp
@@ -624,8 +624,13 @@ void Align::setAllSettings(const QVariantMap &settings)
     for (auto &key : comboKeys)
     {
         auto cb = findChild<QComboBox*>(key);
-        if (cb)
+        // Skip combos that aren't populated yet (e.g. device-dependent combos
+        // before the device connects). currentIndex() would be -1 in that
+        // case, which must not overwrite the persisted option.
+        if (cb && cb->count() > 0 && cb->currentIndex() >= 0)
             optionValues[key] = cb->currentIndex();
+        else
+            optionValues.remove(key);
     }
     KSUtils::setGlobalSettings(optionValues);
 
diff --git a/kstars/ekos/auxiliary/darklibrary.cpp b/kstars/ekos/auxiliary/darklibrary.cpp
index 6317a5e1f3..85adb58c84 100644
--- a/kstars/ekos/auxiliary/darklibrary.cpp
+++ b/kstars/ekos/auxiliary/darklibrary.cpp
@@ -1920,8 +1920,13 @@ void DarkLibrary::setAllSettings(const QVariantMap &settings)
     for (auto &key : comboKeys)
     {
         auto cb = findChild<QComboBox*>(key);
-        if (cb)
+        // Skip combos that aren't populated yet (e.g. device-dependent combos
+        // before the device connects). currentIndex() would be -1 in that
+        // case, which must not overwrite the persisted option.
+        if (cb && cb->count() > 0 && cb->currentIndex() >= 0)
             optionValues[key] = cb->currentIndex();
+        else
+            optionValues.remove(key);
     }
     KSUtils::setGlobalSettings(optionValues);
 
diff --git a/kstars/ekos/focus/focus.cpp b/kstars/ekos/focus/focus.cpp
index 79153a8976..665baeeba1 100644
--- a/kstars/ekos/focus/focus.cpp
+++ b/kstars/ekos/focus/focus.cpp
@@ -7936,8 +7936,13 @@ void Focus::setAllSettings(QVariantMap &settings)
     for (auto &key : comboKeys)
     {
         auto cb = findChild<QComboBox*>(key);
-        if (cb)
+        // Skip combos that aren't populated yet (e.g. device-dependent combos
+        // before the device connects). currentIndex() would be -1 in that
+        // case, which must not overwrite the persisted option.
+        if (cb && cb->count() > 0 && cb->currentIndex() >= 0)
             optionValues[key] = cb->currentIndex();
+        else
+            optionValues.remove(key);
     }
     KSUtils::setGlobalSettings(optionValues);
 
diff --git a/kstars/ekos/guide/guide.cpp b/kstars/ekos/guide/guide.cpp
index bfa52d0cad..25253c967b 100644
--- a/kstars/ekos/guide/guide.cpp
+++ b/kstars/ekos/guide/guide.cpp
@@ -3758,8 +3758,13 @@ void Guide::setAllSettings(const QVariantMap &settings)
     for (auto &key : comboKeys)
     {
         auto cb = findChild<QComboBox*>(key);
-        if (cb)
+        // Skip combos that aren't populated yet (e.g. device-dependent combos
+        // like guide binning before the camera connects). currentIndex() would
+        // be -1 in that case, which must not overwrite the persisted option.
+        if (cb && cb->count() > 0 && cb->currentIndex() >= 0)
             optionValues[key] = cb->currentIndex();
+        else
+            optionValues.remove(key);
     }
     KSUtils::setGlobalSettings(optionValues);
 
diff --git a/kstars/ekos/mount/mount.cpp b/kstars/ekos/mount/mount.cpp
index f4f42acab7..f5945c6075 100644
--- a/kstars/ekos/mount/mount.cpp
+++ b/kstars/ekos/mount/mount.cpp
@@ -1539,8 +1539,13 @@ void Mount::setAllSettings(const QVariantMap &settings)
     for (auto &key : comboKeys)
     {
         auto cb = findChild<QComboBox*>(key);
-        if (cb)
+        // Skip combos that aren't populated yet (e.g. device-dependent combos
+        // before the device connects). currentIndex() would be -1 in that
+        // case, which must not overwrite the persisted option.
+        if (cb && cb->count() > 0 && cb->currentIndex() >= 0)
             optionValues[key] = cb->currentIndex();
+        else
+            optionValues.remove(key);
     }
     KSUtils::setGlobalSettings(optionValues);
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.