Axivion: Move project settings storage closer to project settings

Change-Id: I52122147f8d5ca24dd73db1408b60f8199878bdd
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-08-17 16:27:44 +02:00
parent 26db9f2c95
commit c96867655a
4 changed files with 43 additions and 28 deletions

View File

@@ -37,7 +37,6 @@ namespace Axivion::Internal {
class AxivionPluginPrivate : public QObject
{
public:
AxivionProjectSettings *projectSettings(ProjectExplorer::Project *project);
void onStartupProjectChanged();
void fetchProjectInfo(const QString &projectName);
void handleProjectInfo(const ProjectInfo &info);
@@ -49,7 +48,6 @@ public:
void fetchRuleInfo(const QString &id);
AxivionOutputPane m_axivionOutputPane;
QHash<ProjectExplorer::Project *, AxivionProjectSettings *> m_axivionProjectSettings;
ProjectInfo m_currentProjectInfo;
bool m_runningQuery = false;
};
@@ -86,10 +84,7 @@ AxivionTextMark::AxivionTextMark(const Utils::FilePath &filePath, const ShortIss
AxivionPlugin::~AxivionPlugin()
{
if (dd && !dd->m_axivionProjectSettings.isEmpty()) {
qDeleteAll(dd->m_axivionProjectSettings);
dd->m_axivionProjectSettings.clear();
}
AxivionProjectSettings::destroyProjectSettings();
delete dd;
dd = nullptr;
}
@@ -114,14 +109,6 @@ void AxivionPlugin::initialize()
dd, &AxivionPluginPrivate::onDocumentClosed);
}
AxivionProjectSettings *AxivionPlugin::projectSettings(ProjectExplorer::Project *project)
{
QTC_ASSERT(project, return nullptr);
QTC_ASSERT(dd, return nullptr);
return dd->projectSettings(project);
}
void AxivionPlugin::fetchProjectInfo(const QString &projectName)
{
QTC_ASSERT(dd, return);
@@ -134,14 +121,6 @@ ProjectInfo AxivionPlugin::projectInfo()
return dd->m_currentProjectInfo;
}
AxivionProjectSettings *AxivionPluginPrivate::projectSettings(ProjectExplorer::Project *project)
{
auto &settings = m_axivionProjectSettings[project];
if (!settings)
settings = new AxivionProjectSettings(project);
return settings;
}
void AxivionPluginPrivate::onStartupProjectChanged()
{
ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject();
@@ -152,7 +131,7 @@ void AxivionPluginPrivate::onStartupProjectChanged()
return;
}
const AxivionProjectSettings *projSettings = projectSettings(project);
const AxivionProjectSettings *projSettings = AxivionProjectSettings::projectSettings(project);
fetchProjectInfo(projSettings->dashboardProjectName());
}

View File

@@ -21,8 +21,6 @@ public:
AxivionPlugin() {}
~AxivionPlugin() final;
static AxivionProjectSettings *projectSettings(ProjectExplorer::Project *project);
static void fetchProjectInfo(const QString &projectName);
static ProjectInfo projectInfo();

View File

@@ -17,12 +17,39 @@
#include <QTreeWidget>
#include <QVBoxLayout>
using namespace ProjectExplorer;
using namespace Utils;
namespace Axivion::Internal {
const char PSK_PROJECTNAME[] = "Axivion.ProjectName";
class AxivionProjectSettingsHandler : public QObject
{
public:
AxivionProjectSettings *projectSettings(ProjectExplorer::Project *project)
{
auto &settings = m_axivionProjectSettings[project];
if (!settings)
settings = new AxivionProjectSettings(project);
return settings;
}
void destroy()
{
qDeleteAll(m_axivionProjectSettings);
m_axivionProjectSettings.clear();
}
QHash<ProjectExplorer::Project *, AxivionProjectSettings *> m_axivionProjectSettings;
};
static AxivionProjectSettingsHandler &projectSettingsHandler()
{
static AxivionProjectSettingsHandler theProjectSettingsHandler;
return theProjectSettingsHandler;
}
AxivionProjectSettings::AxivionProjectSettings(ProjectExplorer::Project *project)
: m_project{project}
{
@@ -33,6 +60,16 @@ AxivionProjectSettings::AxivionProjectSettings(ProjectExplorer::Project *project
this, &AxivionProjectSettings::save);
}
AxivionProjectSettings *AxivionProjectSettings::projectSettings(ProjectExplorer::Project *project)
{
return projectSettingsHandler().projectSettings(project);
}
void AxivionProjectSettings::destroyProjectSettings()
{
projectSettingsHandler().destroy();
}
void AxivionProjectSettings::load()
{
m_dashboardProjectName = m_project->namedSettings(PSK_PROJECTNAME).toString();
@@ -46,7 +83,7 @@ void AxivionProjectSettings::save()
AxivionProjectSettingsWidget::AxivionProjectSettingsWidget(ProjectExplorer::Project *project,
QWidget *parent)
: ProjectExplorer::ProjectSettingsWidget{parent}
, m_projectSettings(AxivionPlugin::projectSettings(project))
, m_projectSettings(projectSettingsHandler().projectSettings(project))
{
setUseGlobalSettingsCheckBoxVisible(false);
setUseGlobalSettingsLabelVisible(true);

View File

@@ -3,8 +3,6 @@
#pragma once
#include "axivionsettings.h"
#include <projectexplorer/projectsettingswidget.h>
#include <QObject>
@@ -31,6 +29,9 @@ public:
void setDashboardProjectName(const QString &name) { m_dashboardProjectName = name; }
QString dashboardProjectName() const { return m_dashboardProjectName; }
static AxivionProjectSettings *projectSettings(ProjectExplorer::Project *project);
static void destroyProjectSettings();
private:
void load();
void save();