diff --git a/src/plugins/axivion/CMakeLists.txt b/src/plugins/axivion/CMakeLists.txt index 561ad680e61..2eb2a9d197f 100644 --- a/src/plugins/axivion/CMakeLists.txt +++ b/src/plugins/axivion/CMakeLists.txt @@ -6,7 +6,6 @@ add_qtc_plugin(Axivion axivion.qrc axivionoutputpane.cpp axivionoutputpane.h axivionplugin.cpp axivionplugin.h - axivionprojectsettings.cpp axivionprojectsettings.h axivionsettings.cpp axivionsettings.h axiviontr.h credentialquery.h credentialquery.cpp diff --git a/src/plugins/axivion/axivion.qbs b/src/plugins/axivion/axivion.qbs index 0e808f65806..c5b2a8223e9 100644 --- a/src/plugins/axivion/axivion.qbs +++ b/src/plugins/axivion/axivion.qbs @@ -18,8 +18,6 @@ QtcPlugin { "axivionoutputpane.h", "axivionplugin.cpp", "axivionplugin.h", - "axivionprojectsettings.h", - "axivionprojectsettings.cpp", "axivionsettings.cpp", "axivionsettings.h", "axiviontr.h", diff --git a/src/plugins/axivion/axivionoutputpane.cpp b/src/plugins/axivion/axivionoutputpane.cpp index 5cb9ddc9e31..1f138cea0f3 100644 --- a/src/plugins/axivion/axivionoutputpane.cpp +++ b/src/plugins/axivion/axivionoutputpane.cpp @@ -133,12 +133,17 @@ class IssuesWidget : public QScrollArea public: explicit IssuesWidget(QWidget *parent = nullptr); void updateUi(const QString &kind); + void initDashboardList(const QString &preferredProject = {}); + void resetDashboard(); const std::optional currentTableInfo() const { return m_currentTableInfo; } IssueListSearch searchFromUi() const; void showOverlay(const QString &errorMessage = {}); +protected: + void showEvent(QShowEvent *event) override; private: + void reinitProjectList(const QString ¤tProject); void updateTable(); void addIssues(const Dto::IssueTableDto &dto, int startRow); void onSearchParameterChanged(); @@ -156,6 +161,8 @@ private: QButtonGroup *m_typesButtonGroup = nullptr; QPushButton *m_addedFilter = nullptr; QPushButton *m_removedFilter = nullptr; + QComboBox *m_dashboards = nullptr; + QComboBox *m_dashboardProjects = nullptr; QComboBox *m_ownerFilter = nullptr; QComboBox *m_versionStart = nullptr; QComboBox *m_versionEnd = nullptr; @@ -170,12 +177,31 @@ private: QStringList m_versionDates; TaskTreeRunner m_taskTreeRunner; OverlayWidget *m_overlay = nullptr; + bool m_dashboardListUninitialized = true; }; IssuesWidget::IssuesWidget(QWidget *parent) : QScrollArea(parent) { QWidget *widget = new QWidget(this); + m_dashboards = new QComboBox(this); + m_dashboards->setMinimumContentsLength(15); + connect(m_dashboards, &QComboBox::currentIndexChanged, this, [this] { + if (m_signalBlocker.isLocked()) + return; + reinitProjectList(m_dashboardProjects->currentText()); + }); + + m_dashboardProjects = new QComboBox(this); + m_dashboardProjects->setMinimumContentsLength(25); + connect(m_dashboardProjects, &QComboBox::currentIndexChanged, this, [this] { + if (m_signalBlocker.isLocked()) + return; + m_currentPrefix.clear(); + m_currentProject.clear(); + m_issuesModel->clear(); + fetchProjectInfo(m_dashboardProjects->currentText()); + }); // row with issue types (-> depending on choice, tables below change) // and a selectable range (start version, end version) // row with added/removed and some filters (assignee, path glob, (named filter)) @@ -256,7 +282,7 @@ IssuesWidget::IssuesWidget(QWidget *parent) using namespace Layouting; Column { - Row { m_typesLayout, st, m_versionStart, m_versionEnd, st }, + Row { m_dashboards, m_dashboardProjects, empty, m_typesLayout, st, m_versionStart, m_versionEnd, st }, Row { m_addedFilter, m_removedFilter, Space(1), m_ownerFilter, m_pathGlobFilter }, m_issuesView, Row { st, m_totalRows } @@ -265,6 +291,9 @@ IssuesWidget::IssuesWidget(QWidget *parent) setWidget(widget); setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setWidgetResizable(true); + + connect(&settings(), &AxivionSettings::changed, + this, [this] { initDashboardList(); }); } void IssuesWidget::updateUi(const QString &kind) @@ -308,6 +337,63 @@ void IssuesWidget::updateUi(const QString &kind) fetchTable(); } +void IssuesWidget::resetDashboard() +{ + setFiltersEnabled(false); + updateBasicProjectInfo(std::nullopt); + GuardLocker lock(m_signalBlocker); + m_dashboardProjects->clear(); + m_dashboards->clear(); + m_dashboardListUninitialized = true; +} + +void IssuesWidget::initDashboardList(const QString &preferredProject) +{ + const QString currentProject = preferredProject.isEmpty() ? m_dashboardProjects->currentText() + : preferredProject; + resetDashboard(); + m_dashboardListUninitialized = false; + GuardLocker lock(m_signalBlocker); + const QList servers = settings().allAvailableServers(); + if (servers.isEmpty()) { + switchActiveDashboardId({}); + return; + } + for (const AxivionServer &server : servers) + m_dashboards->addItem(server.displayString(), QVariant::fromValue(server)); + + Id activeId = activeDashboardId(); + if (!activeId.isValid()) + activeId = settings().defaultDashboardId(); + if (activeId.isValid()) { + int index = Utils::indexOf(servers, Utils::equal(&AxivionServer::id, activeId)); + if (index < 0) { + activeId = settings().defaultDashboardId(); + index = Utils::indexOf(servers, Utils::equal(&AxivionServer::id, activeId)); + } + m_dashboards->setCurrentIndex(index); + } + switchActiveDashboardId(activeId); + reinitProjectList(currentProject); +} + +void IssuesWidget::reinitProjectList(const QString ¤tProject) +{ + const auto onDashboardInfoFetched + = [this, currentProject] (const expected_str &info) { + if (!info) + return; + GuardLocker lock(m_signalBlocker); + m_dashboardProjects->clear(); + m_dashboardProjects->addItems(info->projects); + if (!currentProject.isEmpty() && info->projects.contains(currentProject)) + m_dashboardProjects->setCurrentText(currentProject); + // FIXME ugly.. any better solution? + QTimer::singleShot(0, this, [this]() { fetchProjectInfo(m_dashboardProjects->currentText()); }); + }; + fetchDashboardInfo(onDashboardInfoFetched); +} + static Qt::Alignment alignmentFromString(const QString &str) { if (str == "left") @@ -319,6 +405,13 @@ static Qt::Alignment alignmentFromString(const QString &str) return Qt::AlignLeft; } +void IssuesWidget::showEvent(QShowEvent *event) +{ + if (m_dashboardListUninitialized) + initDashboardList(); + QWidget::showEvent(event); +} + void IssuesWidget::updateTable() { if (!m_currentTableInfo) @@ -509,6 +602,7 @@ void IssuesWidget::updateBasicProjectInfo(const std::optionalbutton(1)) firstButton->setChecked(true); + GuardLocker lock(m_signalBlocker); m_userNames.clear(); m_ownerFilter->clear(); QStringList userDisplayNames; @@ -516,9 +610,7 @@ void IssuesWidget::updateBasicProjectInfo(const std::optionaladdItems(userDisplayNames); - m_signalBlocker.unlock(); m_versionDates.clear(); m_versionStart->clear(); @@ -530,11 +622,9 @@ void IssuesWidget::updateBasicProjectInfo(const std::optionaladdItems(versionLabels); m_versionEnd->addItems(versionLabels); m_versionStart->setCurrentIndex(m_versionDates.count() - 1); - m_signalBlocker.unlock(); } void IssuesWidget::setFiltersEnabled(bool enabled) @@ -751,6 +841,20 @@ public: issues->showOverlay(errorMessage); } + void reinitDashboardList(const QString &preferredProject) + { + QTC_ASSERT(m_outputWidget, return); + if (auto issues = static_cast(m_outputWidget->widget(0))) + issues->initDashboardList(preferredProject); + } + + void resetDashboard() + { + QTC_ASSERT(m_outputWidget, return); + if (auto issues = static_cast(m_outputWidget->widget(0))) + issues->resetDashboard(); + } + bool handleContextMenu(const QString &issue, const ItemViewEvent &e) { auto issues = static_cast(m_outputWidget->widget(0)); @@ -814,6 +918,18 @@ void updateDashboard() theAxivionOutputPane->flash(); } +void reinitDashboard(const QString &preferredProject) +{ + QTC_ASSERT(theAxivionOutputPane, return); + theAxivionOutputPane->reinitDashboardList(preferredProject); +} + +void resetDashboard() +{ + QTC_ASSERT(theAxivionOutputPane, return); + theAxivionOutputPane->resetDashboard(); +} + static bool issueListContextMenuEvent(const ItemViewEvent &ev) { QTC_ASSERT(theAxivionOutputPane, return false); diff --git a/src/plugins/axivion/axivionoutputpane.h b/src/plugins/axivion/axivionoutputpane.h index 6e8f34df4da..8b3aef3a2d8 100644 --- a/src/plugins/axivion/axivionoutputpane.h +++ b/src/plugins/axivion/axivionoutputpane.h @@ -10,5 +10,7 @@ namespace Axivion::Internal { void setupAxivionOutputPane(QObject *guard); void updateDashboard(); void showFilterException(const QString &errorMessage); +void reinitDashboard(const QString &projectName); +void resetDashboard(); } // Axivion::Internal diff --git a/src/plugins/axivion/axivionplugin.cpp b/src/plugins/axivion/axivionplugin.cpp index 345c328097c..c670b6a2f55 100644 --- a/src/plugins/axivion/axivionplugin.cpp +++ b/src/plugins/axivion/axivionplugin.cpp @@ -4,7 +4,6 @@ #include "axivionplugin.h" #include "axivionoutputpane.h" -#include "axivionprojectsettings.h" #include "axivionsettings.h" #include "axiviontr.h" #include "credentialquery.h" @@ -17,6 +16,7 @@ #include #include #include +#include #include @@ -214,6 +214,7 @@ public: AxivionPluginPrivate(); void handleSslErrors(QNetworkReply *reply, const QList &errors); void onStartupProjectChanged(Project *project); + void fetchDashboardInfo(const DashboardInfoHandler &handler); void fetchProjectInfo(const QString &projectName); void handleOpenedDocs(); void onDocumentOpened(IDocument *doc); @@ -226,6 +227,9 @@ public: void setIssueDetails(const QString &issueDetailsHtml); void handleAnchorClicked(const QUrl &url); + void onSessionLoaded(const QString &sessionName); + void onAboutToSaveSession(); + signals: void issueDetailsChanged(const QString &issueDetailsHtml); @@ -279,6 +283,12 @@ public: } }; +void fetchDashboardInfo(const DashboardInfoHandler &handler) +{ + QTC_ASSERT(dd, return); + dd->fetchDashboardInfo(handler); +} + void fetchProjectInfo(const QString &projectName) { QTC_ASSERT(dd, return); @@ -319,6 +329,11 @@ AxivionPluginPrivate::AxivionPluginPrivate() #endif // ssl connect(&settings().highlightMarks, &BoolAspect::changed, this, &AxivionPluginPrivate::updateExistingMarks); + connect(SessionManager::instance(), &SessionManager::sessionLoaded, + this, &AxivionPluginPrivate::onSessionLoaded); + connect(SessionManager::instance(), &SessionManager::aboutToSaveSession, + this, &AxivionPluginPrivate::onAboutToSaveSession); + } void AxivionPluginPrivate::handleSslErrors(QNetworkReply *reply, const QList &errors) @@ -367,9 +382,6 @@ void AxivionPluginPrivate::onStartupProjectChanged(Project *project) m_fileFinder.setProjectFiles(m_project->files(Project::AllFiles)); handleOpenedDocs(); }); - const AxivionProjectSettings *projSettings = AxivionProjectSettings::projectSettings(m_project); - switchActiveDashboardId(projSettings->dashboardId()); - fetchProjectInfo(projSettings->dashboardProjectName()); } static QUrl constructUrl(const QString &projectName, const QString &subPath, const QUrlQuery &query) @@ -854,15 +866,17 @@ Group issueHtmlRecipe(const QString &issueId, const HtmlHandler &handler) return fetchHtmlRecipe(url, handler); } +void AxivionPluginPrivate::fetchDashboardInfo(const DashboardInfoHandler &handler) +{ + m_taskTreeRunner.start(dashboardInfoRecipe(handler)); +} + void AxivionPluginPrivate::fetchProjectInfo(const QString &projectName) { - if (!m_project) - return; - clearAllMarks(); + m_currentProjectInfo = {}; + m_analysisVersion = {}; if (projectName.isEmpty()) { - m_currentProjectInfo = {}; - m_analysisVersion = {}; updateDashboard(); return; } @@ -1064,6 +1078,39 @@ void AxivionPluginPrivate::handleAnchorClicked(const QUrl &url) EditorManager::openEditorAt(link); } +static constexpr char SV_PROJECTNAME[] = "Axivion.ProjectName"; +static constexpr char SV_DASHBOARDID[] = "Axivion.DashboardId"; + +void AxivionPluginPrivate::onSessionLoaded(const QString &sessionName) +{ + // explicitly ignore default session to avoid triggering dialogs at startup + if (sessionName == "default") + return; + + const QString projectName = SessionManager::sessionValue(SV_PROJECTNAME).toString(); + const Id dashboardId = Id::fromSetting(SessionManager::sessionValue(SV_DASHBOARDID)); + if (!dashboardId.isValid()) { + switchActiveDashboardId({}); + resetDashboard(); + return; + } + + if (activeDashboardId() != dashboardId) + switchActiveDashboardId(dashboardId); + reinitDashboard(projectName); +} + +void AxivionPluginPrivate::onAboutToSaveSession() +{ + // explicitly ignore default session + if (SessionManager::startupSession() == "default") + return; + + SessionManager::setSessionValue(SV_DASHBOARDID, activeDashboardId().toSetting()); + const QString projectName = m_currentProjectInfo ? m_currentProjectInfo->name : QString(); + SessionManager::setSessionValue(SV_PROJECTNAME, projectName); +} + class AxivionIssueWidgetFactory final : public INavigationWidgetFactory { public: @@ -1104,7 +1151,6 @@ class AxivionPlugin final : public ExtensionSystem::IPlugin ~AxivionPlugin() final { - AxivionProjectSettings::destroyProjectSettings(); delete dd; dd = nullptr; } @@ -1115,7 +1161,6 @@ class AxivionPlugin final : public ExtensionSystem::IPlugin dd = new AxivionPluginPrivate; - AxivionProjectSettings::setupProjectPanel(); setupAxivionIssueWidgetFactory(); connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged, @@ -1148,6 +1193,12 @@ const std::optional currentDashboardInfo() return dd->m_dashboardInfo; } +const Id activeDashboardId() +{ + QTC_ASSERT(dd, return {}); + return dd->m_dashboardServerId; +} + void setAnalysisVersion(const QString &version) { QTC_ASSERT(dd, return); @@ -1168,6 +1219,8 @@ void disableInlineIssues(bool disable) Utils::FilePath findFileForIssuePath(const Utils::FilePath &issuePath) { QTC_ASSERT(dd, return {}); + if (!dd->m_project || !dd->m_currentProjectInfo) + return {}; const FilePaths result = dd->m_fileFinder.findFile(issuePath.toUrl()); if (result.size() == 1) return dd->m_project->projectDirectory().resolvePath(result.first()); diff --git a/src/plugins/axivion/axivionplugin.h b/src/plugins/axivion/axivionplugin.h index 322e92caca1..10535a3f2f0 100644 --- a/src/plugins/axivion/axivionplugin.h +++ b/src/plugins/axivion/axivionplugin.h @@ -78,6 +78,7 @@ Tasking::Group lineMarkerRecipe(const Utils::FilePath &filePath, const LineMarke using HtmlHandler = std::function; Tasking::Group issueHtmlRecipe(const QString &issueId, const HtmlHandler &handler); +void fetchDashboardInfo(const DashboardInfoHandler &handler); void fetchProjectInfo(const QString &projectName); std::optional projectInfo(); bool handleCertificateIssue(); @@ -87,6 +88,7 @@ QString anyToSimpleString(const Dto::Any &any); void fetchIssueInfo(const QString &id); void switchActiveDashboardId(const Utils::Id &toDashboardId); +const Utils::Id activeDashboardId(); const std::optional currentDashboardInfo(); void setAnalysisVersion(const QString &version); void disableInlineIssues(bool disable); diff --git a/src/plugins/axivion/axivionprojectsettings.cpp b/src/plugins/axivion/axivionprojectsettings.cpp deleted file mode 100644 index 83969a62185..00000000000 --- a/src/plugins/axivion/axivionprojectsettings.cpp +++ /dev/null @@ -1,309 +0,0 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include "axivionprojectsettings.h" - -#include "axivionplugin.h" -#include "axivionsettings.h" -#include "axiviontr.h" - -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -using namespace ProjectExplorer; -using namespace Tasking; -using namespace Utils; - -namespace Axivion::Internal { - -const char PSK_PROJECTNAME[] = "Axivion.ProjectName"; -const char PSK_DASHBOARDID[] = "Axivion.DashboardId"; - -// AxivionProjectSettingsHandler - -class AxivionProjectSettingsHandler : public QObject -{ -public: - AxivionProjectSettings *projectSettings(Project *project) - { - auto &settings = m_axivionProjectSettings[project]; - if (!settings) - settings = new AxivionProjectSettings(project); - return settings; - } - - void destroy() - { - qDeleteAll(m_axivionProjectSettings); - m_axivionProjectSettings.clear(); - } - - QHash m_axivionProjectSettings; -}; - -static AxivionProjectSettingsHandler &projectSettingsHandler() -{ - static AxivionProjectSettingsHandler theProjectSettingsHandler; - return theProjectSettingsHandler; -} - -// AxivionProjectSettings - -AxivionProjectSettings::AxivionProjectSettings(Project *project) - : m_project{project} -{ - load(); - connect(project, &Project::settingsLoaded, this, &AxivionProjectSettings::load); - connect(project, &Project::aboutToSaveSettings, this, &AxivionProjectSettings::save); -} - -AxivionProjectSettings *AxivionProjectSettings::projectSettings(Project *project) -{ - return projectSettingsHandler().projectSettings(project); -} - -void AxivionProjectSettings::destroyProjectSettings() -{ - projectSettingsHandler().destroy(); -} - -void AxivionProjectSettings::load() -{ - m_dashboardProjectName = m_project->namedSettings(PSK_PROJECTNAME).toString(); - m_dashboardId = Id::fromSetting(m_project->namedSettings(PSK_DASHBOARDID)); - if (!m_dashboardId.isValid()) - m_dashboardId = settings().defaultDashboardId(); -} - -void AxivionProjectSettings::save() -{ - m_project->setNamedSettings(PSK_PROJECTNAME, m_dashboardProjectName); - m_project->setNamedSettings(PSK_DASHBOARDID, m_dashboardId.toSetting()); -} - -// AxivionProjectSettingsWidget - -class AxivionProjectSettingsWidget : public ProjectSettingsWidget -{ -public: - explicit AxivionProjectSettingsWidget(Project *project); - -private: - void fetchProjects(); - void onSettingsChanged(); - void onServerChanged(); - void linkProject(); - void unlinkProject(); - void updateUi(); - void updateEnabledStates(); - void updateServers(); - - AxivionProjectSettings *m_projectSettings = nullptr; - QLabel *m_linkedProject = nullptr; - QComboBox *m_dashboardServers = nullptr; - QTreeWidget *m_dashboardProjects = nullptr; - QPushButton *m_fetchProjects = nullptr; - QPushButton *m_link = nullptr; - QPushButton *m_unlink = nullptr; - InfoLabel *m_infoLabel = nullptr; - TaskTreeRunner m_taskTreeRunner; -}; - -AxivionProjectSettingsWidget::AxivionProjectSettingsWidget(Project *project) - : m_projectSettings(projectSettingsHandler().projectSettings(project)) -{ - setUseGlobalSettingsCheckBoxVisible(false); - setUseGlobalSettingsLabelVisible(true); - setGlobalSettingsId("Axivion.Settings.General"); // FIXME move id to constants - - m_linkedProject = new QLabel(this); - - m_dashboardServers = new QComboBox(this); - m_dashboardServers->setSizeAdjustPolicy(QComboBox::AdjustToContents); - updateServers(); - - m_dashboardProjects = new QTreeWidget(this); - m_dashboardProjects->setHeaderHidden(true); - m_dashboardProjects->setRootIsDecorated(false); - - m_infoLabel = new InfoLabel(this); - m_infoLabel->setVisible(false); - - m_fetchProjects = new QPushButton(Tr::tr("Fetch Projects")); - - m_link = new QPushButton(Tr::tr("Link Project")); - m_link->setEnabled(false); - - m_unlink = new QPushButton(Tr::tr("Unlink Project")); - m_unlink->setEnabled(false); - - using namespace Layouting; - Column { - noMargin, - m_dashboardServers, - m_linkedProject, - Tr::tr("Dashboard projects:"), - Core::ItemViewFind::createSearchableWrapper(m_dashboardProjects), - m_infoLabel, - Row { m_fetchProjects, m_link, m_unlink, st } - }.attachTo(this); - - connect(m_dashboardServers, &QComboBox::currentIndexChanged, - this, &AxivionProjectSettingsWidget::onServerChanged); - connect(m_dashboardProjects, &QTreeWidget::itemSelectionChanged, - this, &AxivionProjectSettingsWidget::updateEnabledStates); - connect(m_fetchProjects, &QPushButton::clicked, - this, &AxivionProjectSettingsWidget::fetchProjects); - connect(m_link, &QPushButton::clicked, - this, &AxivionProjectSettingsWidget::linkProject); - connect(m_unlink, &QPushButton::clicked, - this, &AxivionProjectSettingsWidget::unlinkProject); - connect(&settings(), &AspectContainer::changed, - this, &AxivionProjectSettingsWidget::onSettingsChanged); - - updateUi(); -} - -void AxivionProjectSettingsWidget::fetchProjects() -{ - m_dashboardProjects->clear(); - m_fetchProjects->setEnabled(false); - m_infoLabel->setVisible(false); - - const auto onDashboardInfo = [this](const expected_str &info) { - if (!info) { - m_infoLabel->setText(info.error()); - m_infoLabel->setType(InfoLabel::Error); - m_infoLabel->setVisible(true); - } else { - for (const QString &project : info->projects) - new QTreeWidgetItem(m_dashboardProjects, {project}); - } - updateEnabledStates(); - }; - - m_taskTreeRunner.start(dashboardInfoRecipe(onDashboardInfo)); -} - -void AxivionProjectSettingsWidget::onSettingsChanged() -{ - m_dashboardProjects->clear(); - m_infoLabel->setVisible(false); - // check if serverId vanished - reset to default - const Id serverId = settings().defaultDashboardId(); - if (m_projectSettings->dashboardId() != serverId) { - m_projectSettings->setDashboardId(serverId); - switchActiveDashboardId(serverId); - } - updateServers(); - updateUi(); -} - -void AxivionProjectSettingsWidget::onServerChanged() -{ - m_dashboardProjects->clear(); - m_infoLabel->setVisible(false); - const Id id = m_dashboardServers->currentData().value().id; - m_projectSettings->setDashboardId(id); - switchActiveDashboardId(id); - updateUi(); -} - -void AxivionProjectSettingsWidget::linkProject() -{ - const QList selected = m_dashboardProjects->selectedItems(); - QTC_ASSERT(selected.size() == 1, return); - - const QString projectName = selected.first()->text(0); - m_projectSettings->setDashboardProjectName(projectName); - updateUi(); - fetchProjectInfo(projectName); -} - -void AxivionProjectSettingsWidget::unlinkProject() -{ - QTC_ASSERT(!m_projectSettings->dashboardProjectName().isEmpty(), return); - - m_projectSettings->setDashboardProjectName({}); - updateUi(); - fetchProjectInfo({}); -} - -void AxivionProjectSettingsWidget::updateUi() -{ - const QString projectName = m_projectSettings->dashboardProjectName(); - if (projectName.isEmpty()) - m_linkedProject->setText(Tr::tr("This project is not linked to a dashboard project.")); - else - m_linkedProject->setText(Tr::tr("This project is linked to \"%1\".").arg(projectName)); - updateEnabledStates(); -} - -void AxivionProjectSettingsWidget::updateEnabledStates() -{ - const bool hasDashboardSettings = !settings().serverForId(m_projectSettings->dashboardId()) - .dashboard.isEmpty(); - const bool linked = !m_projectSettings->dashboardProjectName().isEmpty(); - const bool linkable = m_dashboardProjects->topLevelItemCount() - && !m_dashboardProjects->selectedItems().isEmpty(); - - m_dashboardServers->setEnabled(!linked); - m_fetchProjects->setEnabled(hasDashboardSettings); - m_link->setEnabled(!linked && linkable); - m_unlink->setEnabled(linked); - - if (!hasDashboardSettings) { - m_infoLabel->setText(Tr::tr("Incomplete or misconfigured settings.")); - m_infoLabel->setType(InfoLabel::NotOk); - m_infoLabel->setVisible(true); - } -} - -void AxivionProjectSettingsWidget::updateServers() -{ - const QList available = settings().allAvailableServers(); - m_dashboardServers->clear(); - for (const AxivionServer &server : available) - m_dashboardServers->addItem(server.displayString(), QVariant::fromValue(server)); - const Id id = m_projectSettings->dashboardId(); - const int index = Utils::indexOf(available, [&id](const AxivionServer &s) { - return s.id == id; - }); - if (index != -1) - m_dashboardServers->setCurrentIndex(index); -} - -class AxivionProjectPanelFactory : public ProjectPanelFactory -{ -public: - AxivionProjectPanelFactory() - { - setPriority(250); - setDisplayName(Tr::tr("Axivion")); - setCreateWidgetFunction([](Project *project) { - return new AxivionProjectSettingsWidget(project); - }); - } -}; - -void AxivionProjectSettings::setupProjectPanel() -{ - static AxivionProjectPanelFactory theAxivionProjectPanelFactory; -} - -} // Axivion::Internal diff --git a/src/plugins/axivion/axivionprojectsettings.h b/src/plugins/axivion/axivionprojectsettings.h deleted file mode 100644 index 7639213e877..00000000000 --- a/src/plugins/axivion/axivionprojectsettings.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#pragma once - -#include - -#include - -namespace ProjectExplorer { class Project; } - -namespace Axivion::Internal { - -class AxivionProjectSettings : public QObject -{ -public: - explicit AxivionProjectSettings(ProjectExplorer::Project *project); - - void setDashboardProjectName(const QString &name) { m_dashboardProjectName = name; } - QString dashboardProjectName() const { return m_dashboardProjectName; } - void setDashboardId(const Utils::Id &dashboardId) { m_dashboardId = dashboardId; } - Utils::Id dashboardId() const { return m_dashboardId; } - - static AxivionProjectSettings *projectSettings(ProjectExplorer::Project *project); - static void destroyProjectSettings(); - static void setupProjectPanel(); - -private: - void load(); - void save(); - - ProjectExplorer::Project *m_project = nullptr; - QString m_dashboardProjectName; - // id of the dashboard in use for this project, or default from settings on initialization - Utils::Id m_dashboardId; -}; - -} // Axivion::Internal