fix: use private constructor for singleton
This commit is contained in:
parent
8d73d6037d
commit
f7aec30ad2
2 changed files with 13 additions and 7 deletions
|
|
@ -4,12 +4,14 @@
|
||||||
|
|
||||||
namespace caelestia::config {
|
namespace caelestia::config {
|
||||||
|
|
||||||
static GlobalConfig* s_instance = nullptr;
|
namespace {
|
||||||
|
|
||||||
static QString configDir() {
|
QString configDir() {
|
||||||
return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/caelestia/");
|
return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/caelestia/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
GlobalConfig::GlobalConfig(QObject* parent)
|
GlobalConfig::GlobalConfig(QObject* parent)
|
||||||
: ConfigObject(parent)
|
: ConfigObject(parent)
|
||||||
, m_appearance(new AppearanceConfig(this))
|
, m_appearance(new AppearanceConfig(this))
|
||||||
|
|
@ -30,8 +32,6 @@ GlobalConfig::GlobalConfig(QObject* parent)
|
||||||
, m_services(new ServiceConfig(this))
|
, m_services(new ServiceConfig(this))
|
||||||
, m_paths(new UserPaths(this))
|
, m_paths(new UserPaths(this))
|
||||||
, m_advanced(new AdvancedConfig(this)) {
|
, m_advanced(new AdvancedConfig(this)) {
|
||||||
s_instance = this;
|
|
||||||
|
|
||||||
// Bind token base values from advanced config to appearance computed properties
|
// Bind token base values from advanced config to appearance computed properties
|
||||||
auto* adv = m_advanced->appearance();
|
auto* adv = m_advanced->appearance();
|
||||||
m_appearance->rounding()->bindTokens(adv->rounding());
|
m_appearance->rounding()->bindTokens(adv->rounding());
|
||||||
|
|
@ -46,7 +46,12 @@ GlobalConfig::GlobalConfig(QObject* parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalConfig* GlobalConfig::instance() {
|
GlobalConfig* GlobalConfig::instance() {
|
||||||
return s_instance;
|
static GlobalConfig instance;
|
||||||
|
return &instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalConfig* GlobalConfig::create(QQmlEngine*, QJSEngine*) {
|
||||||
|
return instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalConfig::save() {
|
void GlobalConfig::save() {
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,8 @@ class GlobalConfig : public ConfigObject {
|
||||||
Q_PROPERTY(AdvancedConfig* advanced READ advanced CONSTANT)
|
Q_PROPERTY(AdvancedConfig* advanced READ advanced CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GlobalConfig(QObject* parent = nullptr);
|
|
||||||
|
|
||||||
static GlobalConfig* instance();
|
static GlobalConfig* instance();
|
||||||
|
static GlobalConfig* create(QQmlEngine*, QJSEngine*);
|
||||||
|
|
||||||
[[nodiscard]] AdvancedConfig* advanced() const { return m_advanced; }
|
[[nodiscard]] AdvancedConfig* advanced() const { return m_advanced; }
|
||||||
|
|
||||||
|
|
@ -60,6 +59,8 @@ public:
|
||||||
Q_INVOKABLE void reload();
|
Q_INVOKABLE void reload();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit GlobalConfig(QObject* parent = nullptr);
|
||||||
|
|
||||||
AdvancedConfig* m_advanced = nullptr;
|
AdvancedConfig* m_advanced = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue