MauiKit Controls

appsettings.h
1#pragma once
2#include <QObject>
3#include <QSettings>
4#include <QString>
5#include <QUrl>
6#include <QVariant>
7
8#include "mauikit_export.h"
9#include <QCoreApplication>
10
11class SettingSection : public QObject
12{
14 Q_PROPERTY(QString key READ key WRITE setKey NOTIFY keyChanged)
15 Q_PROPERTY(QString group READ group WRITE setGroup NOTIFY groupChanged)
16 Q_PROPERTY(QVariant defaultValue READ defaultValue WRITE setDefaultValue NOTIFY defaultValueChanged)
17
18private:
19 QString m_key;
20 QString m_group;
21 QVariant m_defaultValue;
22
23public:
24 explicit SettingSection(QObject *parent = nullptr);
25 QString key() const;
26 QString group() const;
27 QVariant defaultValue() const;
28 QVariant value() const;
29
30public Q_SLOTS:
31 void setKey(QString key);
32 void setGroup(QString group);
33 void setValue(QVariant value);
34 void setDefaultValue(QVariant defaultValue);
35
37 void keyChanged(QString key);
38 void groupChanged(QString group);
39 void defaultValueChanged(QVariant defaultValue);
40};
41
42/**
43 * @brief The AppSettings class
44 */
45
46class MAUIKIT_EXPORT AppSettings : public QObject
47{
49public:
50 /**
51 * @brief local
52 * @return
53 */
54 static AppSettings &local()
55 {
56 static AppSettings settings;
57 return settings;
58 }
59
60 /**
61 * @brief global
62 * @return
63 */
64 static AppSettings &global()
65 {
66 static AppSettings settings(QStringLiteral("mauiproject"));
67 return settings;
68 }
69
70 AppSettings(const AppSettings &) = delete;
71 AppSettings &operator=(const AppSettings &) = delete;
72 AppSettings(AppSettings &&) = delete;
73 AppSettings &operator=(AppSettings &&) = delete;
74
75 /**
76 * @brief url
77 * @return
78 */
79 QUrl url() const;
80
81 /**
82 * @brief load
83 * @param key
84 * @param group
85 * @param defaultValue
86 * @return
87 */
88 QVariant load(const QString &key, const QString &group, const QVariant &defaultValue) const;
89
90 /**
91 * @brief save
92 * @param key
93 * @param value
94 * @param group
95 */
96 void save(const QString &key, const QVariant &value, const QString &group);
97
98private:
99 explicit AppSettings(QString app = qApp->applicationName(), QString org = qApp->organizationName().isEmpty() ? QStringLiteral("org.kde.maui") : qApp->organizationName());
100
101 QString m_app;
102 QString m_org;
103 QSettings *m_settings;
104
105Q_SIGNALS:
106 /**
107 * @brief settingChanged
108 * @param url
109 * @param key
110 * @param value
111 * @param group
112 */
113 void settingChanged(QUrl url, QString key, QVariant value, QString group);
114};
115
The AppSettings class.
Definition appsettings.h:47
static AppSettings & local()
local
Definition appsettings.h:54
static AppSettings & global()
global
Definition appsettings.h:64
QUrl url() const
url
void settingChanged(QUrl url, QString key, QVariant value, QString group)
settingChanged
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 11:57:11 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.