From c7a0fee1fd19773853788d7e46f51a16a7b56f13 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 25 Sep 2024 14:57:09 +0200 Subject: [PATCH] Axivion: Fix handling of default dashboard Update correctly after loading and set new id after changing the dashboard inside the settings. Limit updating the QC settings and respectively writing the Axivion settings to real changes. Change-Id: I9e04d8e8007caccdd6b081b52d1fd22641919c7e Reviewed-by: hjk Reviewed-by: Mohammad Mehdi Salem Naraghi --- src/plugins/axivion/axivionsettings.cpp | 25 ++++++++++++++++--------- src/plugins/axivion/axivionsettings.h | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/plugins/axivion/axivionsettings.cpp b/src/plugins/axivion/axivionsettings.cpp index c19748148f6..9112c728497 100644 --- a/src/plugins/axivion/axivionsettings.cpp +++ b/src/plugins/axivion/axivionsettings.cpp @@ -245,17 +245,17 @@ void AxivionSettings::disableCertificateValidation(const Utils::Id &id) m_allServers[index].validateCert = false; } -void AxivionSettings::updateDashboardServers(const QList &other) +bool AxivionSettings::updateDashboardServers(const QList &other, + const Utils::Id &selected) { - if (m_allServers == other) - return; - const Id oldDefault = defaultDashboardId(); - if (!Utils::anyOf(other, [&oldDefault](const AxivionServer &s) { return s.id == oldDefault; })) - m_defaultServerId.setValue(other.isEmpty() ? QString{} : other.first().id.toString()); + if (selected == oldDefault && m_allServers == other) + return false; + m_defaultServerId.setValue(selected.toString()); m_allServers = other; emit changed(); // should we be more detailed? (id) + return true; } const QList AxivionSettings::validPathMappings() const @@ -417,15 +417,22 @@ void AxivionSettingsWidget::apply() QList servers; for (int i = 0, end = m_dashboardServers->count(); i < end; ++i) servers.append(m_dashboardServers->itemData(i).value()); - settings().updateDashboardServers(servers); - settings().toSettings(); + if (settings().updateDashboardServers(servers, servers.at(m_dashboardServers->currentIndex()).id)) + settings().toSettings(); } void AxivionSettingsWidget::updateDashboardServers() { m_dashboardServers->clear(); - for (const AxivionServer &server : settings().allAvailableServers()) + const QList servers = settings().allAvailableServers(); + for (const AxivionServer &server : servers) m_dashboardServers->addItem(server.displayString(), QVariant::fromValue(server)); + int index = Utils::indexOf(servers, + [id = settings().defaultDashboardId()](const AxivionServer &s) { + return id == s.id; + }); + if (index != -1) + m_dashboardServers->setCurrentIndex(index); } void AxivionSettingsWidget::updateEnabledStates() diff --git a/src/plugins/axivion/axivionsettings.h b/src/plugins/axivion/axivionsettings.h index 3ca45d6026a..4bedfae7658 100644 --- a/src/plugins/axivion/axivionsettings.h +++ b/src/plugins/axivion/axivionsettings.h @@ -57,7 +57,7 @@ public: const AxivionServer serverForId(const Utils::Id &id) const; void disableCertificateValidation(const Utils::Id &id); const QList allAvailableServers() const { return m_allServers; }; - void updateDashboardServers(const QList &other); + bool updateDashboardServers(const QList &other, const Utils::Id &selected); const QList validPathMappings() const; Utils::BoolAspect highlightMarks{this};