File indexing completed on 2024-05-12 03:54:10

0001 /*
0002     SPDX-FileCopyrightText: 2020 Kevin Ottens <kevin.ottens@enioka.com>
0003     SPDX-FileCopyrightText: 2020 Cyril Rossi <cyril.rossi@enioka.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef SETTINGSTATEPROXY_H
0009 #define SETTINGSTATEPROXY_H
0010 
0011 #include <QObject>
0012 #include <QPointer>
0013 
0014 #include <KCoreConfigSkeleton>
0015 
0016 /**
0017  * This element allows to represent in a declarative way the
0018  * state of a particular setting in a config object.
0019  *
0020  * @since 5.73
0021  */
0022 class SettingStateProxy : public QObject
0023 {
0024     Q_OBJECT
0025 
0026     /**
0027      * The config object which will be monitored for setting state changes
0028      */
0029     Q_PROPERTY(KCoreConfigSkeleton *configObject READ configObject WRITE setConfigObject NOTIFY configObjectChanged)
0030 
0031     /**
0032      * The name of the setting in the config object
0033      */
0034     Q_PROPERTY(QString settingName READ settingName WRITE setSettingName NOTIFY settingNameChanged)
0035 
0036     /**
0037      * Indicates if the setting is marked as immutable
0038      */
0039     Q_PROPERTY(bool immutable READ isImmutable NOTIFY immutableChanged)
0040 
0041     /**
0042      * Indicates if the setting differs from its default value
0043      */
0044     Q_PROPERTY(bool defaulted READ isDefaulted NOTIFY defaultedChanged)
0045 
0046 public:
0047     using QObject::QObject;
0048 
0049     KCoreConfigSkeleton *configObject() const;
0050     void setConfigObject(KCoreConfigSkeleton *configObject);
0051 
0052     QString settingName() const;
0053     void setSettingName(const QString &settingName);
0054 
0055     bool isImmutable() const;
0056     bool isDefaulted() const;
0057 
0058 Q_SIGNALS:
0059     void configObjectChanged();
0060     void settingNameChanged();
0061 
0062     void immutableChanged();
0063     void defaultedChanged();
0064 
0065 private Q_SLOTS:
0066     void updateState();
0067 
0068 private:
0069     void connectSetting();
0070 
0071     QPointer<KCoreConfigSkeleton> m_configObject;
0072     QString m_settingName;
0073     bool m_immutable = false;
0074     bool m_defaulted = true;
0075 };
0076 
0077 #endif