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};