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

View File

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

View File

@@ -17,12 +17,39 @@
#include <QTreeWidget> #include <QTreeWidget>
#include <QVBoxLayout> #include <QVBoxLayout>
using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
namespace Axivion::Internal { namespace Axivion::Internal {
const char PSK_PROJECTNAME[] = "Axivion.ProjectName"; 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) AxivionProjectSettings::AxivionProjectSettings(ProjectExplorer::Project *project)
: m_project{project} : m_project{project}
{ {
@@ -33,6 +60,16 @@ AxivionProjectSettings::AxivionProjectSettings(ProjectExplorer::Project *project
this, &AxivionProjectSettings::save); this, &AxivionProjectSettings::save);
} }
AxivionProjectSettings *AxivionProjectSettings::projectSettings(ProjectExplorer::Project *project)
{
return projectSettingsHandler().projectSettings(project);
}
void AxivionProjectSettings::destroyProjectSettings()
{
projectSettingsHandler().destroy();
}
void AxivionProjectSettings::load() void AxivionProjectSettings::load()
{ {
m_dashboardProjectName = m_project->namedSettings(PSK_PROJECTNAME).toString(); m_dashboardProjectName = m_project->namedSettings(PSK_PROJECTNAME).toString();
@@ -46,7 +83,7 @@ void AxivionProjectSettings::save()
AxivionProjectSettingsWidget::AxivionProjectSettingsWidget(ProjectExplorer::Project *project, AxivionProjectSettingsWidget::AxivionProjectSettingsWidget(ProjectExplorer::Project *project,
QWidget *parent) QWidget *parent)
: ProjectExplorer::ProjectSettingsWidget{parent} : ProjectExplorer::ProjectSettingsWidget{parent}
, m_projectSettings(AxivionPlugin::projectSettings(project)) , m_projectSettings(projectSettingsHandler().projectSettings(project))
{ {
setUseGlobalSettingsCheckBoxVisible(false); setUseGlobalSettingsCheckBoxVisible(false);
setUseGlobalSettingsLabelVisible(true); setUseGlobalSettingsLabelVisible(true);

View File

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