/**
 * This file is generated by dconfig2cpp.
 * Command line arguments: ./build/tools/dconfig2cpp/dconfig2cpp /usr/share/dsg/configs/org.deepin.dtk.preference.json -o ./src/log/dconfig_org_deepin_dtk_preference.hpp
 * Generation time: 2026-01-22T14:49:01
 * JSON file version: 1.0
 * Tool version: 1.1
 *
 * WARNING: DO NOT MODIFY THIS FILE MANUALLY.
 * If you need to change the content, please modify the dconfig2cpp tool.
 */

#ifndef DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_H
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_H

#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_VERSION_MAJOR 1
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_VERSION_MINOR 1
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_autoDisplayFeature
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_colorMode
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_defaultColorMode
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_enableDtkAnimations
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_featureUpdated
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_keyboardsearchDisabled
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_rules
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_scrollBarPolicy
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_sizeMode
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_themeType
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_titlebarHeight
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_underlineShortcut

#include <QThread>
#include <QVariant>
#include <QPointer>
#include <QDebug>
#include <QAtomicPointer>
#include <QAtomicInteger>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QProperty>
#endif
#include <QEvent>
#include <DSGApplication>
#include <DConfig>

class dconfig_org_deepin_dtk_preference : public QObject {
    Q_OBJECT

    Q_PROPERTY(bool autoDisplayFeature READ autoDisplayFeature WRITE setAutoDisplayFeature NOTIFY autoDisplayFeatureChanged RESET resetAutoDisplayFeature)
    Q_PROPERTY(QString colorMode READ colorMode WRITE setColorMode NOTIFY colorModeChanged RESET resetColorMode)
    Q_PROPERTY(QString defaultColorMode READ defaultColorMode WRITE setDefaultColorMode NOTIFY defaultColorModeChanged RESET resetDefaultColorMode)
    Q_PROPERTY(bool enableDtkAnimations READ enableDtkAnimations WRITE setEnableDtkAnimations NOTIFY enableDtkAnimationsChanged RESET resetEnableDtkAnimations)
    Q_PROPERTY(bool featureUpdated READ featureUpdated WRITE setFeatureUpdated NOTIFY featureUpdatedChanged RESET resetFeatureUpdated)
    Q_PROPERTY(bool keyboardsearchDisabled READ keyboardsearchDisabled WRITE setKeyboardsearchDisabled NOTIFY keyboardsearchDisabledChanged RESET resetKeyboardsearchDisabled)
    Q_PROPERTY(QString rules READ rules WRITE setRules NOTIFY rulesChanged RESET resetRules)
    Q_PROPERTY(qlonglong scrollBarPolicy READ scrollBarPolicy WRITE setScrollBarPolicy NOTIFY scrollBarPolicyChanged RESET resetScrollBarPolicy)
    Q_PROPERTY(qlonglong sizeMode READ sizeMode WRITE setSizeMode NOTIFY sizeModeChanged RESET resetSizeMode)
    Q_PROPERTY(qlonglong themeType READ themeType WRITE setThemeType NOTIFY themeTypeChanged RESET resetThemeType)
    Q_PROPERTY(qlonglong titlebarHeight READ titlebarHeight WRITE setTitlebarHeight NOTIFY titlebarHeightChanged RESET resetTitlebarHeight)
    Q_PROPERTY(bool underlineShortcut READ underlineShortcut WRITE setUnderlineShortcut NOTIFY underlineShortcutChanged RESET resetUnderlineShortcut)
    Q_CLASSINFO("DConfigKeyList", "autoDisplayFeature;colorMode;defaultColorMode;enableDtkAnimations;featureUpdated;keyboardsearchDisabled;rules;scrollBarPolicy;sizeMode;themeType;titlebarHeight;underlineShortcut")
    Q_CLASSINFO("DConfigFileName", "org.deepin.dtk.preference")
    Q_CLASSINFO("DConfigFileVersion", "1.0")

public:
    explicit dconfig_org_deepin_dtk_preference(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend,
                        const QString &name, const QString &appId, const QString &subpath,
                        bool isGeneric, QObject *parent)
                  : QObject(parent), m_data(new Data) {
        m_data->m_userConfig = this;
        m_data->moveToThread(this->thread());

        if (!thread->isRunning()) {
            qWarning() << QLatin1String("Warning: The provided thread is not running.");
        }
        Q_ASSERT(QThread::currentThread() != thread);
        auto worker = new QObject();
        worker->moveToThread(thread);

        QPointer<Data> safeData(m_data);

        QMetaObject::invokeMethod(worker, [safeData, backend, name, appId, subpath, isGeneric, worker]() mutable {
            delete worker;
            worker = nullptr;

            if (!safeData->m_status.testAndSetOrdered(static_cast<int>(Data::Status::Invalid),
                                                      static_cast<int>(Data::Status::Initializing))) {
                // CAS failed: status changed (e.g., set to Destroyed by destructor)
                // Schedule deletion of Data object via deleteLater to avoid direct delete in Config thread
                safeData->deleteLater();
                return;
            }

            DTK_CORE_NAMESPACE::DConfig *config = nullptr;
            if (isGeneric) {
                if (backend) {
                    config = DTK_CORE_NAMESPACE::DConfig::createGeneric(backend, name, subpath, nullptr);
                } else {
                    config = DTK_CORE_NAMESPACE::DConfig::createGeneric(name, subpath, nullptr);
                }
            } else {
                if (backend) {
                    if (appId.isNull()) {
                        config = DTK_CORE_NAMESPACE::DConfig::create(backend, DTK_CORE_NAMESPACE::DSGApplication::id(),
                                                                     name, subpath, nullptr);
                    } else {
                        config = DTK_CORE_NAMESPACE::DConfig::create(backend, appId, name, subpath, nullptr);
                    }
                } else {
                    if (appId.isNull()) {
                        config = DTK_CORE_NAMESPACE::DConfig::create(DTK_CORE_NAMESPACE::DSGApplication::id(),
                                                                     name, subpath, nullptr);
                    } else {
                        config = DTK_CORE_NAMESPACE::DConfig::create(appId, name, subpath, nullptr);
                    }
                }
            }

            if (!config || !config->isValid()) {
                qWarning() << QLatin1String("Failed to create DConfig instance.");

                QMetaObject::invokeMethod(safeData, [safeData]() {
                    if (safeData->m_status.testAndSetOrdered(static_cast<int>(Data::Status::Initializing),
                                                             static_cast<int>(Data::Status::Failed))) {
                        Q_EMIT safeData->m_userConfig->configInitializeFailed();
                    } else {
                        // CAS failed, destroy data object
                        delete safeData;
                    }
                }, Qt::QueuedConnection);

                if (config)
                    delete config;

                return;
            }
            config->moveToThread(QThread::currentThread());
            // Initialize through Data class
            safeData->initializeInConfigThread(config);

            // Queue state transition to main thread, to ensure config values are fully initialized.
            QMetaObject::invokeMethod(safeData, [safeData, config]() {
                // Try to transition from Initializing to Succeeded
                if (safeData->m_status.testAndSetOrdered(static_cast<int>(Data::Status::Initializing),
                                                         static_cast<int>(Data::Status::Succeeded))) {
                    // CAS succeeded: connect config destroyed signal to cleanup Data, then emit success signal to main thread
                    QObject::connect(config, &QObject::destroyed, safeData, &QObject::deleteLater);
                    if (safeData->m_userConfig) {
                        Q_EMIT safeData->m_userConfig->configInitializeSucceed(config);
                    }
                } else {
                    // CAS failed - state changed (e.g., set to Destroyed)
                    // We must clean up the config we just created
                    config->deleteLater();
                    safeData->deleteLater();
                }
            }, Qt::QueuedConnection);
        });
    }
    static dconfig_org_deepin_dtk_preference* create(const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new dconfig_org_deepin_dtk_preference(thread, nullptr, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), appId, subpath, false, parent); }
    static dconfig_org_deepin_dtk_preference* create(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new dconfig_org_deepin_dtk_preference(thread, backend, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), appId, subpath, false, parent); }
    static dconfig_org_deepin_dtk_preference* createByName(const QString &name, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new dconfig_org_deepin_dtk_preference(thread, nullptr, name, appId, subpath, false, parent); }
    static dconfig_org_deepin_dtk_preference* createByName(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new dconfig_org_deepin_dtk_preference(thread, backend, name, appId, subpath, false, parent); }
    static dconfig_org_deepin_dtk_preference* createGeneric(const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new dconfig_org_deepin_dtk_preference(thread, nullptr, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), {}, subpath, true, parent); }
    static dconfig_org_deepin_dtk_preference* create(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new dconfig_org_deepin_dtk_preference(thread, backend, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), {}, subpath, true, parent); }
    static dconfig_org_deepin_dtk_preference* createGenericByName(const QString &name, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new dconfig_org_deepin_dtk_preference(thread, nullptr, name, {}, subpath, true, parent); }
    static dconfig_org_deepin_dtk_preference* createGenericByName(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new dconfig_org_deepin_dtk_preference(thread, backend, name, {}, subpath, true, parent); }
    ~dconfig_org_deepin_dtk_preference() {
        m_data->m_userConfig = nullptr;
        int oldStatus = m_data->m_status.fetchAndStoreOrdered(static_cast<int>(Data::Status::Destroyed));
        if (oldStatus == static_cast<int>(Data::Status::Succeeded)) {
            // When Succeeded, release config object only
            auto config = m_data->m_config.loadRelaxed();
            Q_ASSERT(config);
            config->deleteLater();
            // m_data will be deleted by config's destroyed signal
        } else if (oldStatus == static_cast<int>(Data::Status::Failed)) {
            // When Failed state, schedule cleanup of Data object
            m_data->deleteLater();
        }
    }

    Q_INVOKABLE DTK_CORE_NAMESPACE::DConfig *config() const {
        return m_data->m_config.loadRelaxed();
    }
    // Deprecated: Use isInitializeSucceeded() instead
    Q_INVOKABLE Q_DECL_DEPRECATED_X("Use isInitializeSucceeded() instead")
    bool isInitializeSucceed() const {
        return isInitializeSucceeded();
    }
    Q_INVOKABLE bool isInitializeSucceeded() const {
        return m_data->m_status.loadRelaxed() == static_cast<int>(Data::Status::Succeeded);
    }
    Q_INVOKABLE bool isInitializeFailed() const {
        return m_data->m_status.loadRelaxed() == static_cast<int>(Data::Status::Failed);
    }
    Q_INVOKABLE bool isInitializing() const {
        return m_data->m_status.loadRelaxed() == static_cast<int>(Data::Status::Initializing);
    }

    Q_INVOKABLE QStringList keyList() const {
        return { QStringLiteral("autoDisplayFeature"),
                 QStringLiteral("colorMode"),
                 QStringLiteral("defaultColorMode"),
                 QStringLiteral("enableDtkAnimations"),
                 QStringLiteral("featureUpdated"),
                 QStringLiteral("keyboardsearchDisabled"),
                 QStringLiteral("rules"),
                 QStringLiteral("scrollBarPolicy"),
                 QStringLiteral("sizeMode"),
                 QStringLiteral("themeType"),
                 QStringLiteral("titlebarHeight"),
                 QStringLiteral("underlineShortcut")};
    }

    Q_INVOKABLE bool isDefaultValue(const QString &key) const {
        if (key == QStringLiteral("autoDisplayFeature"))
            return autoDisplayFeatureIsDefaultValue();
        if (key == QStringLiteral("colorMode"))
            return colorModeIsDefaultValue();
        if (key == QStringLiteral("defaultColorMode"))
            return defaultColorModeIsDefaultValue();
        if (key == QStringLiteral("enableDtkAnimations"))
            return enableDtkAnimationsIsDefaultValue();
        if (key == QStringLiteral("featureUpdated"))
            return featureUpdatedIsDefaultValue();
        if (key == QStringLiteral("keyboardsearchDisabled"))
            return keyboardsearchDisabledIsDefaultValue();
        if (key == QStringLiteral("rules"))
            return rulesIsDefaultValue();
        if (key == QStringLiteral("scrollBarPolicy"))
            return scrollBarPolicyIsDefaultValue();
        if (key == QStringLiteral("sizeMode"))
            return sizeModeIsDefaultValue();
        if (key == QStringLiteral("themeType"))
            return themeTypeIsDefaultValue();
        if (key == QStringLiteral("titlebarHeight"))
            return titlebarHeightIsDefaultValue();
        if (key == QStringLiteral("underlineShortcut"))
            return underlineShortcutIsDefaultValue();
        return false;
    }

    bool autoDisplayFeature() const {
        return m_data->p_autoDisplayFeature;
    }
    void setAutoDisplayFeature(const bool &value) {
        auto oldValue = m_data->p_autoDisplayFeature;
        m_data->p_autoDisplayFeature = value;
        m_data->markPropertySet(0);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("autoDisplayFeature"), value);
            });
        }
        if (m_data->p_autoDisplayFeature != oldValue) {
            Q_EMIT autoDisplayFeatureChanged();
            Q_EMIT valueChanged(QStringLiteral("autoDisplayFeature"), value);
        }
    }
    void resetAutoDisplayFeature() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("autoDisplayFeature"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<bool> bindableAutoDisplayFeature() {
        return QBindable<bool>(this, "autoDisplayFeature");
    }
#endif
    Q_INVOKABLE bool autoDisplayFeatureIsDefaultValue() const {
        return !m_data->testPropertySet(0);
    }
    QString colorMode() const {
        return m_data->p_colorMode;
    }
    void setColorMode(const QString &value) {
        auto oldValue = m_data->p_colorMode;
        m_data->p_colorMode = value;
        m_data->markPropertySet(1);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("colorMode"), value);
            });
        }
        if (m_data->p_colorMode != oldValue) {
            Q_EMIT colorModeChanged();
            Q_EMIT valueChanged(QStringLiteral("colorMode"), value);
        }
    }
    void resetColorMode() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("colorMode"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<QString> bindableColorMode() {
        return QBindable<QString>(this, "colorMode");
    }
#endif
    Q_INVOKABLE bool colorModeIsDefaultValue() const {
        return !m_data->testPropertySet(1);
    }
    QString defaultColorMode() const {
        return m_data->p_defaultColorMode;
    }
    void setDefaultColorMode(const QString &value) {
        auto oldValue = m_data->p_defaultColorMode;
        m_data->p_defaultColorMode = value;
        m_data->markPropertySet(2);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("defaultColorMode"), value);
            });
        }
        if (m_data->p_defaultColorMode != oldValue) {
            Q_EMIT defaultColorModeChanged();
            Q_EMIT valueChanged(QStringLiteral("defaultColorMode"), value);
        }
    }
    void resetDefaultColorMode() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("defaultColorMode"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<QString> bindableDefaultColorMode() {
        return QBindable<QString>(this, "defaultColorMode");
    }
#endif
    Q_INVOKABLE bool defaultColorModeIsDefaultValue() const {
        return !m_data->testPropertySet(2);
    }
    bool enableDtkAnimations() const {
        return m_data->p_enableDtkAnimations;
    }
    void setEnableDtkAnimations(const bool &value) {
        auto oldValue = m_data->p_enableDtkAnimations;
        m_data->p_enableDtkAnimations = value;
        m_data->markPropertySet(3);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("enableDtkAnimations"), value);
            });
        }
        if (m_data->p_enableDtkAnimations != oldValue) {
            Q_EMIT enableDtkAnimationsChanged();
            Q_EMIT valueChanged(QStringLiteral("enableDtkAnimations"), value);
        }
    }
    void resetEnableDtkAnimations() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("enableDtkAnimations"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<bool> bindableEnableDtkAnimations() {
        return QBindable<bool>(this, "enableDtkAnimations");
    }
#endif
    Q_INVOKABLE bool enableDtkAnimationsIsDefaultValue() const {
        return !m_data->testPropertySet(3);
    }
    bool featureUpdated() const {
        return m_data->p_featureUpdated;
    }
    void setFeatureUpdated(const bool &value) {
        auto oldValue = m_data->p_featureUpdated;
        m_data->p_featureUpdated = value;
        m_data->markPropertySet(4);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("featureUpdated"), value);
            });
        }
        if (m_data->p_featureUpdated != oldValue) {
            Q_EMIT featureUpdatedChanged();
            Q_EMIT valueChanged(QStringLiteral("featureUpdated"), value);
        }
    }
    void resetFeatureUpdated() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("featureUpdated"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<bool> bindableFeatureUpdated() {
        return QBindable<bool>(this, "featureUpdated");
    }
#endif
    Q_INVOKABLE bool featureUpdatedIsDefaultValue() const {
        return !m_data->testPropertySet(4);
    }
    bool keyboardsearchDisabled() const {
        return m_data->p_keyboardsearchDisabled;
    }
    void setKeyboardsearchDisabled(const bool &value) {
        auto oldValue = m_data->p_keyboardsearchDisabled;
        m_data->p_keyboardsearchDisabled = value;
        m_data->markPropertySet(5);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("keyboardsearchDisabled"), value);
            });
        }
        if (m_data->p_keyboardsearchDisabled != oldValue) {
            Q_EMIT keyboardsearchDisabledChanged();
            Q_EMIT valueChanged(QStringLiteral("keyboardsearchDisabled"), value);
        }
    }
    void resetKeyboardsearchDisabled() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("keyboardsearchDisabled"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<bool> bindableKeyboardsearchDisabled() {
        return QBindable<bool>(this, "keyboardsearchDisabled");
    }
#endif
    Q_INVOKABLE bool keyboardsearchDisabledIsDefaultValue() const {
        return !m_data->testPropertySet(5);
    }
    QString rules() const {
        return m_data->p_rules;
    }
    void setRules(const QString &value) {
        auto oldValue = m_data->p_rules;
        m_data->p_rules = value;
        m_data->markPropertySet(6);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("rules"), value);
            });
        }
        if (m_data->p_rules != oldValue) {
            Q_EMIT rulesChanged();
            Q_EMIT valueChanged(QStringLiteral("rules"), value);
        }
    }
    void resetRules() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("rules"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<QString> bindableRules() {
        return QBindable<QString>(this, "rules");
    }
#endif
    Q_INVOKABLE bool rulesIsDefaultValue() const {
        return !m_data->testPropertySet(6);
    }
    qlonglong scrollBarPolicy() const {
        return m_data->p_scrollBarPolicy;
    }
    void setScrollBarPolicy(const qlonglong &value) {
        auto oldValue = m_data->p_scrollBarPolicy;
        m_data->p_scrollBarPolicy = value;
        m_data->markPropertySet(7);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("scrollBarPolicy"), value);
            });
        }
        if (m_data->p_scrollBarPolicy != oldValue) {
            Q_EMIT scrollBarPolicyChanged();
            Q_EMIT valueChanged(QStringLiteral("scrollBarPolicy"), value);
        }
    }
    void resetScrollBarPolicy() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("scrollBarPolicy"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<qlonglong> bindableScrollBarPolicy() {
        return QBindable<qlonglong>(this, "scrollBarPolicy");
    }
#endif
    Q_INVOKABLE bool scrollBarPolicyIsDefaultValue() const {
        return !m_data->testPropertySet(7);
    }
    qlonglong sizeMode() const {
        return m_data->p_sizeMode;
    }
    void setSizeMode(const qlonglong &value) {
        auto oldValue = m_data->p_sizeMode;
        m_data->p_sizeMode = value;
        m_data->markPropertySet(8);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("sizeMode"), value);
            });
        }
        if (m_data->p_sizeMode != oldValue) {
            Q_EMIT sizeModeChanged();
            Q_EMIT valueChanged(QStringLiteral("sizeMode"), value);
        }
    }
    void resetSizeMode() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("sizeMode"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<qlonglong> bindableSizeMode() {
        return QBindable<qlonglong>(this, "sizeMode");
    }
#endif
    Q_INVOKABLE bool sizeModeIsDefaultValue() const {
        return !m_data->testPropertySet(8);
    }
    qlonglong themeType() const {
        return m_data->p_themeType;
    }
    void setThemeType(const qlonglong &value) {
        auto oldValue = m_data->p_themeType;
        m_data->p_themeType = value;
        m_data->markPropertySet(9);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("themeType"), value);
            });
        }
        if (m_data->p_themeType != oldValue) {
            Q_EMIT themeTypeChanged();
            Q_EMIT valueChanged(QStringLiteral("themeType"), value);
        }
    }
    void resetThemeType() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("themeType"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<qlonglong> bindableThemeType() {
        return QBindable<qlonglong>(this, "themeType");
    }
#endif
    Q_INVOKABLE bool themeTypeIsDefaultValue() const {
        return !m_data->testPropertySet(9);
    }
    qlonglong titlebarHeight() const {
        return m_data->p_titlebarHeight;
    }
    void setTitlebarHeight(const qlonglong &value) {
        auto oldValue = m_data->p_titlebarHeight;
        m_data->p_titlebarHeight = value;
        m_data->markPropertySet(10);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("titlebarHeight"), value);
            });
        }
        if (m_data->p_titlebarHeight != oldValue) {
            Q_EMIT titlebarHeightChanged();
            Q_EMIT valueChanged(QStringLiteral("titlebarHeight"), value);
        }
    }
    void resetTitlebarHeight() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("titlebarHeight"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<qlonglong> bindableTitlebarHeight() {
        return QBindable<qlonglong>(this, "titlebarHeight");
    }
#endif
    Q_INVOKABLE bool titlebarHeightIsDefaultValue() const {
        return !m_data->testPropertySet(10);
    }
    bool underlineShortcut() const {
        return m_data->p_underlineShortcut;
    }
    void setUnderlineShortcut(const bool &value) {
        auto oldValue = m_data->p_underlineShortcut;
        m_data->p_underlineShortcut = value;
        m_data->markPropertySet(11);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("underlineShortcut"), value);
            });
        }
        if (m_data->p_underlineShortcut != oldValue) {
            Q_EMIT underlineShortcutChanged();
            Q_EMIT valueChanged(QStringLiteral("underlineShortcut"), value);
        }
    }
    void resetUnderlineShortcut() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("underlineShortcut"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<bool> bindableUnderlineShortcut() {
        return QBindable<bool>(this, "underlineShortcut");
    }
#endif
    Q_INVOKABLE bool underlineShortcutIsDefaultValue() const {
        return !m_data->testPropertySet(11);
    }
protected:
    bool event(QEvent *e) override {
        if (e->type() == QEvent::ThreadChange) {
            Q_ASSERT(this->thread() == m_data->thread());
        }
        return QObject::event(e);
    }
Q_SIGNALS:
    void configInitializeFailed();
    void configInitializeSucceed(DTK_CORE_NAMESPACE::DConfig *config);
    void valueChanged(const QString &key, const QVariant &value);
    void autoDisplayFeatureChanged();
    void colorModeChanged();
    void defaultColorModeChanged();
    void enableDtkAnimationsChanged();
    void featureUpdatedChanged();
    void keyboardsearchDisabledChanged();
    void rulesChanged();
    void scrollBarPolicyChanged();
    void sizeModeChanged();
    void themeTypeChanged();
    void titlebarHeightChanged();
    void underlineShortcutChanged();

private:
    // Prevent external moveToThread calls
    using QObject::moveToThread;
    class Data : public QObject {
    public:
        enum class Status {
            Invalid = 0,
            Initializing = 1,
            Succeeded = 2,
            Failed = 3,
            Destroyed = 4
        };

        explicit Data()
            : QObject(nullptr) {}

        inline void initializeInConfigThread(DTK_CORE_NAMESPACE::DConfig *config) {
            Q_ASSERT(!m_config.loadRelaxed());
            m_config.storeRelaxed(config);
            if (testPropertySet(0)) {
                config->setValue(QStringLiteral("autoDisplayFeature"), QVariant::fromValue(p_autoDisplayFeature));
            } else {
                updateValue(QStringLiteral("autoDisplayFeature"), QVariant::fromValue(p_autoDisplayFeature));
            }
            if (testPropertySet(1)) {
                config->setValue(QStringLiteral("colorMode"), QVariant::fromValue(p_colorMode));
            } else {
                updateValue(QStringLiteral("colorMode"), QVariant::fromValue(p_colorMode));
            }
            if (testPropertySet(2)) {
                config->setValue(QStringLiteral("defaultColorMode"), QVariant::fromValue(p_defaultColorMode));
            } else {
                updateValue(QStringLiteral("defaultColorMode"), QVariant::fromValue(p_defaultColorMode));
            }
            if (testPropertySet(3)) {
                config->setValue(QStringLiteral("enableDtkAnimations"), QVariant::fromValue(p_enableDtkAnimations));
            } else {
                updateValue(QStringLiteral("enableDtkAnimations"), QVariant::fromValue(p_enableDtkAnimations));
            }
            if (testPropertySet(4)) {
                config->setValue(QStringLiteral("featureUpdated"), QVariant::fromValue(p_featureUpdated));
            } else {
                updateValue(QStringLiteral("featureUpdated"), QVariant::fromValue(p_featureUpdated));
            }
            if (testPropertySet(5)) {
                config->setValue(QStringLiteral("keyboardsearchDisabled"), QVariant::fromValue(p_keyboardsearchDisabled));
            } else {
                updateValue(QStringLiteral("keyboardsearchDisabled"), QVariant::fromValue(p_keyboardsearchDisabled));
            }
            if (testPropertySet(6)) {
                config->setValue(QStringLiteral("rules"), QVariant::fromValue(p_rules));
            } else {
                updateValue(QStringLiteral("rules"), QVariant::fromValue(p_rules));
            }
            if (testPropertySet(7)) {
                config->setValue(QStringLiteral("scrollBarPolicy"), QVariant::fromValue(p_scrollBarPolicy));
            } else {
                updateValue(QStringLiteral("scrollBarPolicy"), QVariant::fromValue(p_scrollBarPolicy));
            }
            if (testPropertySet(8)) {
                config->setValue(QStringLiteral("sizeMode"), QVariant::fromValue(p_sizeMode));
            } else {
                updateValue(QStringLiteral("sizeMode"), QVariant::fromValue(p_sizeMode));
            }
            if (testPropertySet(9)) {
                config->setValue(QStringLiteral("themeType"), QVariant::fromValue(p_themeType));
            } else {
                updateValue(QStringLiteral("themeType"), QVariant::fromValue(p_themeType));
            }
            if (testPropertySet(10)) {
                config->setValue(QStringLiteral("titlebarHeight"), QVariant::fromValue(p_titlebarHeight));
            } else {
                updateValue(QStringLiteral("titlebarHeight"), QVariant::fromValue(p_titlebarHeight));
            }
            if (testPropertySet(11)) {
                config->setValue(QStringLiteral("underlineShortcut"), QVariant::fromValue(p_underlineShortcut));
            } else {
                updateValue(QStringLiteral("underlineShortcut"), QVariant::fromValue(p_underlineShortcut));
            }
            connect(config, &DTK_CORE_NAMESPACE::DConfig::valueChanged, this, [this](const QString &key) {
                updateValue(key);
            }, Qt::DirectConnection);
        }

        inline void updateValue(const QString &key, const QVariant &fallback = QVariant()) {
            if (!m_config.loadRelaxed())
                return;
            Q_ASSERT(QThread::currentThread() == m_config.loadRelaxed()->thread());
            const QVariant &value = m_config.loadRelaxed()->value(key, fallback);
            if (key == QStringLiteral("autoDisplayFeature")) {
                markPropertySet(0, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<bool>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_autoDisplayFeature != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_autoDisplayFeature = newValue;
                        Q_EMIT m_userConfig->autoDisplayFeatureChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("colorMode")) {
                markPropertySet(1, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<QString>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_colorMode != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_colorMode = newValue;
                        Q_EMIT m_userConfig->colorModeChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("defaultColorMode")) {
                markPropertySet(2, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<QString>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_defaultColorMode != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_defaultColorMode = newValue;
                        Q_EMIT m_userConfig->defaultColorModeChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("enableDtkAnimations")) {
                markPropertySet(3, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<bool>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_enableDtkAnimations != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_enableDtkAnimations = newValue;
                        Q_EMIT m_userConfig->enableDtkAnimationsChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("featureUpdated")) {
                markPropertySet(4, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<bool>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_featureUpdated != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_featureUpdated = newValue;
                        Q_EMIT m_userConfig->featureUpdatedChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("keyboardsearchDisabled")) {
                markPropertySet(5, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<bool>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_keyboardsearchDisabled != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_keyboardsearchDisabled = newValue;
                        Q_EMIT m_userConfig->keyboardsearchDisabledChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("rules")) {
                markPropertySet(6, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<QString>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_rules != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_rules = newValue;
                        Q_EMIT m_userConfig->rulesChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("scrollBarPolicy")) {
                markPropertySet(7, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<qlonglong>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_scrollBarPolicy != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_scrollBarPolicy = newValue;
                        Q_EMIT m_userConfig->scrollBarPolicyChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("sizeMode")) {
                markPropertySet(8, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<qlonglong>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_sizeMode != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_sizeMode = newValue;
                        Q_EMIT m_userConfig->sizeModeChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("themeType")) {
                markPropertySet(9, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<qlonglong>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_themeType != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_themeType = newValue;
                        Q_EMIT m_userConfig->themeTypeChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("titlebarHeight")) {
                markPropertySet(10, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<qlonglong>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_titlebarHeight != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_titlebarHeight = newValue;
                        Q_EMIT m_userConfig->titlebarHeightChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("underlineShortcut")) {
                markPropertySet(11, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<bool>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_underlineShortcut != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_underlineShortcut = newValue;
                        Q_EMIT m_userConfig->underlineShortcutChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
        }
        inline void markPropertySet(const int index, bool on = true) {
            if (index < 32) {
                if (on)
                    m_propertySetStatus0.fetchAndOrOrdered(1 << (index - 0));
                else
                    m_propertySetStatus0.fetchAndAndOrdered(~(1 << (index - 0)));
                return;
            }
            Q_UNREACHABLE();
        }
        inline bool testPropertySet(const int index) const {
            if (index < 32) {
                return (m_propertySetStatus0.loadRelaxed() & (1 << (index - 0)));
            }
            Q_UNREACHABLE();
        }
        // Member variables
        QAtomicPointer<DTK_CORE_NAMESPACE::DConfig> m_config = nullptr;
        QAtomicInteger<int> m_status = static_cast<int>(Status::Invalid);
        QPointer<dconfig_org_deepin_dtk_preference> m_userConfig = nullptr;
        QAtomicInteger<quint32> m_propertySetStatus0 = 0;

        // Property storage
        bool p_autoDisplayFeature { false };
        // Default value: ""
        QString p_colorMode { QLatin1String("") };
        // Default value: "color"
        QString p_defaultColorMode { QStringLiteral(u"\u0063\u006f\u006c\u006f\u0072") };
        bool p_enableDtkAnimations { false };
        bool p_featureUpdated { false };
        bool p_keyboardsearchDisabled { false };
        // Default value: "*.debug=false"
        QString p_rules { QStringLiteral(u"\u002a\u002e\u0064\u0065\u0062\u0075\u0067\u003d\u0066\u0061\u006c\u0073\u0065") };
        qlonglong p_scrollBarPolicy { 0 };
        qlonglong p_sizeMode { 0 };
        qlonglong p_themeType { 0 };
        qlonglong p_titlebarHeight { -1 };
        bool p_underlineShortcut { false };
    };

    QPointer<Data> m_data;
};

#endif // DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_H
