Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Support auto generate the Qt code for a dconfig's json #448

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zccrs
Copy link
Member

@zccrs zccrs commented Dec 3, 2024

使用方法:
自动使用:cmake 中调用 dtk_config_to_cpp(foo.example.json, SOURCES),会自动把生成的hpp文件加到SOURCES这个变量中
手动使用:dconfig2cpp foo.example.json

生成的代码:

/**
 * This file is generated by dconfig2cpp.
 * Command line arguments: /home/zccrs/projects/dtkcore/build/unknown-Debug/tools/dconfig2cpp/dconfig2cpp /home/zccrs/projects/treeland/misc/dconfig/org.deepin.treeland.json
 * Generation time: 2024-12-04T16:14:01
 * JSON file version: 1.0
 * 
 * WARNING: DO NOT MODIFY THIS FILE MANUALLY.
 * If you need to change the content, please modify the dconfig2cpp tool.
 */

#ifndef ORG_DEEPIN_TREELAND_H
#define ORG_DEEPIN_TREELAND_H

#include <QThread>
#include <QVariant>
#include <QAtomicPointer>
#include <QAtomicInteger>
#include <DConfig>

class org_deepin_treeland : public QObject {
    Q_OBJECT

    Q_PROPERTY(QString activeColor READ activeColor WRITE setActiveColor NOTIFY activeColorChanged)
    Q_PROPERTY(qint64 currentWorkspace READ currentWorkspace WRITE setCurrentWorkspace NOTIFY currentWorkspaceChanged)
    Q_PROPERTY(bool cursorBlink READ cursorBlink WRITE setCursorBlink NOTIFY cursorBlinkChanged)
    Q_PROPERTY(qint64 cursorBlinkTime READ cursorBlinkTime WRITE setCursorBlinkTime NOTIFY cursorBlinkTimeChanged)
    Q_PROPERTY(qint64 cursorSize READ cursorSize WRITE setCursorSize NOTIFY cursorSizeChanged)
    Q_PROPERTY(QString cursorThemeName READ cursorThemeName WRITE setCursorThemeName NOTIFY cursorThemeNameChanged)
    Q_PROPERTY(qint64 dndDragThreshold READ dndDragThreshold WRITE setDndDragThreshold NOTIFY dndDragThresholdChanged)
    Q_PROPERTY(qint64 doubleClickDistance READ doubleClickDistance WRITE setDoubleClickDistance NOTIFY doubleClickDistanceChanged)
    Q_PROPERTY(qint64 doubleClickTime READ doubleClickTime WRITE setDoubleClickTime NOTIFY doubleClickTimeChanged)
    Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged)
    Q_PROPERTY(qint64 fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
    Q_PROPERTY(bool forceSoftwareCursor READ forceSoftwareCursor WRITE setForceSoftwareCursor NOTIFY forceSoftwareCursorChanged)
    Q_PROPERTY(QString iconThemeName READ iconThemeName WRITE setIconThemeName NOTIFY iconThemeNameChanged)
    Q_PROPERTY(QString lostScreen READ lostScreen WRITE setLostScreen NOTIFY lostScreenChanged)
    Q_PROPERTY(qint64 maxWorkspace READ maxWorkspace WRITE setMaxWorkspace NOTIFY maxWorkspaceChanged)
    Q_PROPERTY(QString monoFont READ monoFont WRITE setMonoFont NOTIFY monoFontChanged)
    Q_PROPERTY(qint64 numWorkspace READ numWorkspace WRITE setNumWorkspace NOTIFY numWorkspaceChanged)
    Q_PROPERTY(bool preferDark READ preferDark WRITE setPreferDark NOTIFY preferDarkChanged)
    Q_PROPERTY(bool showOnLock READ showOnLock WRITE setShowOnLock NOTIFY showOnLockChanged)
    Q_PROPERTY(QString themeName READ themeName WRITE setThemeName NOTIFY themeNameChanged)
    Q_PROPERTY(qint64 windowOpacity READ windowOpacity WRITE setWindowOpacity NOTIFY windowOpacityChanged)
    Q_PROPERTY(qint64 windowRadius READ windowRadius WRITE setWindowRadius NOTIFY windowRadiusChanged)
    Q_PROPERTY(qint64 windowThemeType READ windowThemeType WRITE setWindowThemeType NOTIFY windowThemeTypeChanged)
    Q_PROPERTY(qint64 windowTitlebarHeight READ windowTitlebarHeight WRITE setWindowTitlebarHeight NOTIFY windowTitlebarHeightChanged)
public:
    explicit org_deepin_treeland(QThread *thread, const QString &appId, const QString &name, const QString &subpath, QObject *parent = nullptr)
        : QObject(parent) {

        if (!thread->isRunning()) {
            qWarning() << QStringLiteral("Warning: The provided thread is not running.");
        }
        Q_ASSERT(QThread::currentThread() != thread);
        auto worker = new QObject();
        worker->moveToThread(thread);
        QMetaObject::invokeMethod(worker, [=]() {
            auto config = DTK_CORE_NAMESPACE::DConfig::create(appId, name, subpath, nullptr);
            if (!config) {
                qWarning() << QStringLiteral("Failed to create DConfig instance.");
                worker->deleteLater();
                return;
            }
            config->moveToThread(QThread::currentThread());
            initialize(config);
            worker->deleteLater();
        });
    }
    explicit org_deepin_treeland(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &appId, const QString &name, const QString &subpath, QObject *parent = nullptr)
        : QObject(parent) {

        if (!thread->isRunning()) {
            qWarning() << QStringLiteral("Warning: The provided thread is not running.");
        }
        Q_ASSERT(QThread::currentThread() != thread);
        auto worker = new QObject();
        worker->moveToThread(thread);
        QMetaObject::invokeMethod(worker, [=]() {
            auto config = DTK_CORE_NAMESPACE::DConfig::create(backend, appId, name, subpath, nullptr);
            if (!config) {
                qWarning() << QStringLiteral("Failed to create DConfig instance.");
                worker->deleteLater();
                return;
            }
            config->moveToThread(QThread::currentThread());
            initialize(config);
            worker->deleteLater();
        });
    }
    explicit org_deepin_treeland(QThread *thread, const QString &name, const QString &subpath, QObject *parent = nullptr)
        : QObject(parent) {

        if (!thread->isRunning()) {
            qWarning() << QStringLiteral("Warning: The provided thread is not running.");
        }
        Q_ASSERT(QThread::currentThread() != thread);
        auto worker = new QObject();
        worker->moveToThread(thread);
        QMetaObject::invokeMethod(worker, [=]() {
            auto config = DTK_CORE_NAMESPACE::DConfig::create(name, subpath, nullptr);
            if (!config) {
                qWarning() << QStringLiteral("Failed to create DConfig instance.");
                worker->deleteLater();
                return;
            }
            config->moveToThread(QThread::currentThread());
            initialize(config);
            worker->deleteLater();
        });
    }
    explicit org_deepin_treeland(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &subpath, QObject *parent = nullptr)
        : QObject(parent) {

        if (!thread->isRunning()) {
            qWarning() << QStringLiteral("Warning: The provided thread is not running.");
        }
        Q_ASSERT(QThread::currentThread() != thread);
        auto worker = new QObject();
        worker->moveToThread(thread);
        QMetaObject::invokeMethod(worker, [=]() {
            auto config = DTK_CORE_NAMESPACE::DConfig::create(backend, name, subpath, nullptr);
            if (!config) {
                qWarning() << QStringLiteral("Failed to create DConfig instance.");
                worker->deleteLater();
                return;
            }
            config->moveToThread(QThread::currentThread());
            initialize(config);
            worker->deleteLater();
        });
    }
    ~org_deepin_treeland() {
        if (m_config.loadRelaxed()) {
            m_config.loadRelaxed()->deleteLater();
        }
    }

    QString activeColor() const {
        return p_activeColor;
    }
    void setActiveColor(const QString &value) {
        auto oldValue = p_activeColor;
        p_activeColor = value;
        markPropertySet(0);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("activeColor"), value);
            });
        }
        if (p_activeColor != oldValue) {
            Q_EMIT activeColorChanged();
        }
    }
    qint64 currentWorkspace() const {
        return p_currentWorkspace;
    }
    void setCurrentWorkspace(const qint64 &value) {
        auto oldValue = p_currentWorkspace;
        p_currentWorkspace = value;
        markPropertySet(1);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("currentWorkspace"), value);
            });
        }
        if (p_currentWorkspace != oldValue) {
            Q_EMIT currentWorkspaceChanged();
        }
    }
    bool cursorBlink() const {
        return p_cursorBlink;
    }
    void setCursorBlink(const bool &value) {
        auto oldValue = p_cursorBlink;
        p_cursorBlink = value;
        markPropertySet(2);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("cursorBlink"), value);
            });
        }
        if (p_cursorBlink != oldValue) {
            Q_EMIT cursorBlinkChanged();
        }
    }
    qint64 cursorBlinkTime() const {
        return p_cursorBlinkTime;
    }
    void setCursorBlinkTime(const qint64 &value) {
        auto oldValue = p_cursorBlinkTime;
        p_cursorBlinkTime = value;
        markPropertySet(3);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("cursorBlinkTime"), value);
            });
        }
        if (p_cursorBlinkTime != oldValue) {
            Q_EMIT cursorBlinkTimeChanged();
        }
    }
    qint64 cursorSize() const {
        return p_cursorSize;
    }
    void setCursorSize(const qint64 &value) {
        auto oldValue = p_cursorSize;
        p_cursorSize = value;
        markPropertySet(4);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("cursorSize"), value);
            });
        }
        if (p_cursorSize != oldValue) {
            Q_EMIT cursorSizeChanged();
        }
    }
    QString cursorThemeName() const {
        return p_cursorThemeName;
    }
    void setCursorThemeName(const QString &value) {
        auto oldValue = p_cursorThemeName;
        p_cursorThemeName = value;
        markPropertySet(5);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("cursorThemeName"), value);
            });
        }
        if (p_cursorThemeName != oldValue) {
            Q_EMIT cursorThemeNameChanged();
        }
    }
    qint64 dndDragThreshold() const {
        return p_dndDragThreshold;
    }
    void setDndDragThreshold(const qint64 &value) {
        auto oldValue = p_dndDragThreshold;
        p_dndDragThreshold = value;
        markPropertySet(6);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("dndDragThreshold"), value);
            });
        }
        if (p_dndDragThreshold != oldValue) {
            Q_EMIT dndDragThresholdChanged();
        }
    }
    qint64 doubleClickDistance() const {
        return p_doubleClickDistance;
    }
    void setDoubleClickDistance(const qint64 &value) {
        auto oldValue = p_doubleClickDistance;
        p_doubleClickDistance = value;
        markPropertySet(7);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("doubleClickDistance"), value);
            });
        }
        if (p_doubleClickDistance != oldValue) {
            Q_EMIT doubleClickDistanceChanged();
        }
    }
    qint64 doubleClickTime() const {
        return p_doubleClickTime;
    }
    void setDoubleClickTime(const qint64 &value) {
        auto oldValue = p_doubleClickTime;
        p_doubleClickTime = value;
        markPropertySet(8);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("doubleClickTime"), value);
            });
        }
        if (p_doubleClickTime != oldValue) {
            Q_EMIT doubleClickTimeChanged();
        }
    }
    QString font() const {
        return p_font;
    }
    void setFont(const QString &value) {
        auto oldValue = p_font;
        p_font = value;
        markPropertySet(9);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("font"), value);
            });
        }
        if (p_font != oldValue) {
            Q_EMIT fontChanged();
        }
    }
    qint64 fontSize() const {
        return p_fontSize;
    }
    void setFontSize(const qint64 &value) {
        auto oldValue = p_fontSize;
        p_fontSize = value;
        markPropertySet(10);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("fontSize"), value);
            });
        }
        if (p_fontSize != oldValue) {
            Q_EMIT fontSizeChanged();
        }
    }
    bool forceSoftwareCursor() const {
        return p_forceSoftwareCursor;
    }
    void setForceSoftwareCursor(const bool &value) {
        auto oldValue = p_forceSoftwareCursor;
        p_forceSoftwareCursor = value;
        markPropertySet(11);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("forceSoftwareCursor"), value);
            });
        }
        if (p_forceSoftwareCursor != oldValue) {
            Q_EMIT forceSoftwareCursorChanged();
        }
    }
    QString iconThemeName() const {
        return p_iconThemeName;
    }
    void setIconThemeName(const QString &value) {
        auto oldValue = p_iconThemeName;
        p_iconThemeName = value;
        markPropertySet(12);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("iconThemeName"), value);
            });
        }
        if (p_iconThemeName != oldValue) {
            Q_EMIT iconThemeNameChanged();
        }
    }
    QString lostScreen() const {
        return p_lostScreen;
    }
    void setLostScreen(const QString &value) {
        auto oldValue = p_lostScreen;
        p_lostScreen = value;
        markPropertySet(13);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("lostScreen"), value);
            });
        }
        if (p_lostScreen != oldValue) {
            Q_EMIT lostScreenChanged();
        }
    }
    qint64 maxWorkspace() const {
        return p_maxWorkspace;
    }
    void setMaxWorkspace(const qint64 &value) {
        auto oldValue = p_maxWorkspace;
        p_maxWorkspace = value;
        markPropertySet(14);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("maxWorkspace"), value);
            });
        }
        if (p_maxWorkspace != oldValue) {
            Q_EMIT maxWorkspaceChanged();
        }
    }
    QString monoFont() const {
        return p_monoFont;
    }
    void setMonoFont(const QString &value) {
        auto oldValue = p_monoFont;
        p_monoFont = value;
        markPropertySet(15);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("monoFont"), value);
            });
        }
        if (p_monoFont != oldValue) {
            Q_EMIT monoFontChanged();
        }
    }
    qint64 numWorkspace() const {
        return p_numWorkspace;
    }
    void setNumWorkspace(const qint64 &value) {
        auto oldValue = p_numWorkspace;
        p_numWorkspace = value;
        markPropertySet(16);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("numWorkspace"), value);
            });
        }
        if (p_numWorkspace != oldValue) {
            Q_EMIT numWorkspaceChanged();
        }
    }
    bool preferDark() const {
        return p_preferDark;
    }
    void setPreferDark(const bool &value) {
        auto oldValue = p_preferDark;
        p_preferDark = value;
        markPropertySet(17);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("preferDark"), value);
            });
        }
        if (p_preferDark != oldValue) {
            Q_EMIT preferDarkChanged();
        }
    }
    bool showOnLock() const {
        return p_showOnLock;
    }
    void setShowOnLock(const bool &value) {
        auto oldValue = p_showOnLock;
        p_showOnLock = value;
        markPropertySet(18);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("showOnLock"), value);
            });
        }
        if (p_showOnLock != oldValue) {
            Q_EMIT showOnLockChanged();
        }
    }
    QString themeName() const {
        return p_themeName;
    }
    void setThemeName(const QString &value) {
        auto oldValue = p_themeName;
        p_themeName = value;
        markPropertySet(19);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("themeName"), value);
            });
        }
        if (p_themeName != oldValue) {
            Q_EMIT themeNameChanged();
        }
    }
    qint64 windowOpacity() const {
        return p_windowOpacity;
    }
    void setWindowOpacity(const qint64 &value) {
        auto oldValue = p_windowOpacity;
        p_windowOpacity = value;
        markPropertySet(20);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("windowOpacity"), value);
            });
        }
        if (p_windowOpacity != oldValue) {
            Q_EMIT windowOpacityChanged();
        }
    }
    qint64 windowRadius() const {
        return p_windowRadius;
    }
    void setWindowRadius(const qint64 &value) {
        auto oldValue = p_windowRadius;
        p_windowRadius = value;
        markPropertySet(21);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("windowRadius"), value);
            });
        }
        if (p_windowRadius != oldValue) {
            Q_EMIT windowRadiusChanged();
        }
    }
    qint64 windowThemeType() const {
        return p_windowThemeType;
    }
    void setWindowThemeType(const qint64 &value) {
        auto oldValue = p_windowThemeType;
        p_windowThemeType = value;
        markPropertySet(22);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("windowThemeType"), value);
            });
        }
        if (p_windowThemeType != oldValue) {
            Q_EMIT windowThemeTypeChanged();
        }
    }
    qint64 windowTitlebarHeight() const {
        return p_windowTitlebarHeight;
    }
    void setWindowTitlebarHeight(const qint64 &value) {
        auto oldValue = p_windowTitlebarHeight;
        p_windowTitlebarHeight = value;
        markPropertySet(23);
        if (auto config = m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [this, value]() {
                m_config.loadRelaxed()->setValue(QStringLiteral("windowTitlebarHeight"), value);
            });
        }
        if (p_windowTitlebarHeight != oldValue) {
            Q_EMIT windowTitlebarHeightChanged();
        }
    }
Q_SIGNALS:
    void activeColorChanged();
    void currentWorkspaceChanged();
    void cursorBlinkChanged();
    void cursorBlinkTimeChanged();
    void cursorSizeChanged();
    void cursorThemeNameChanged();
    void dndDragThresholdChanged();
    void doubleClickDistanceChanged();
    void doubleClickTimeChanged();
    void fontChanged();
    void fontSizeChanged();
    void forceSoftwareCursorChanged();
    void iconThemeNameChanged();
    void lostScreenChanged();
    void maxWorkspaceChanged();
    void monoFontChanged();
    void numWorkspaceChanged();
    void preferDarkChanged();
    void showOnLockChanged();
    void themeNameChanged();
    void windowOpacityChanged();
    void windowRadiusChanged();
    void windowThemeTypeChanged();
    void windowTitlebarHeightChanged();
private:
    void initialize(DTK_CORE_NAMESPACE::DConfig *config) {
        Q_ASSERT(!m_config.loadRelaxed());
        m_config.storeRelaxed(config);
        if (testPropertySet(0)) {
            config->setValue(QStringLiteral("activeColor"), QVariant::fromValue(p_activeColor));
        } else {
            updateValue(QStringLiteral("activeColor"), QVariant::fromValue(p_activeColor));
        }
        if (testPropertySet(1)) {
            config->setValue(QStringLiteral("currentWorkspace"), QVariant::fromValue(p_currentWorkspace));
        } else {
            updateValue(QStringLiteral("currentWorkspace"), QVariant::fromValue(p_currentWorkspace));
        }
        if (testPropertySet(2)) {
            config->setValue(QStringLiteral("cursorBlink"), QVariant::fromValue(p_cursorBlink));
        } else {
            updateValue(QStringLiteral("cursorBlink"), QVariant::fromValue(p_cursorBlink));
        }
        if (testPropertySet(3)) {
            config->setValue(QStringLiteral("cursorBlinkTime"), QVariant::fromValue(p_cursorBlinkTime));
        } else {
            updateValue(QStringLiteral("cursorBlinkTime"), QVariant::fromValue(p_cursorBlinkTime));
        }
        if (testPropertySet(4)) {
            config->setValue(QStringLiteral("cursorSize"), QVariant::fromValue(p_cursorSize));
        } else {
            updateValue(QStringLiteral("cursorSize"), QVariant::fromValue(p_cursorSize));
        }
        if (testPropertySet(5)) {
            config->setValue(QStringLiteral("cursorThemeName"), QVariant::fromValue(p_cursorThemeName));
        } else {
            updateValue(QStringLiteral("cursorThemeName"), QVariant::fromValue(p_cursorThemeName));
        }
        if (testPropertySet(6)) {
            config->setValue(QStringLiteral("dndDragThreshold"), QVariant::fromValue(p_dndDragThreshold));
        } else {
            updateValue(QStringLiteral("dndDragThreshold"), QVariant::fromValue(p_dndDragThreshold));
        }
        if (testPropertySet(7)) {
            config->setValue(QStringLiteral("doubleClickDistance"), QVariant::fromValue(p_doubleClickDistance));
        } else {
            updateValue(QStringLiteral("doubleClickDistance"), QVariant::fromValue(p_doubleClickDistance));
        }
        if (testPropertySet(8)) {
            config->setValue(QStringLiteral("doubleClickTime"), QVariant::fromValue(p_doubleClickTime));
        } else {
            updateValue(QStringLiteral("doubleClickTime"), QVariant::fromValue(p_doubleClickTime));
        }
        if (testPropertySet(9)) {
            config->setValue(QStringLiteral("font"), QVariant::fromValue(p_font));
        } else {
            updateValue(QStringLiteral("font"), QVariant::fromValue(p_font));
        }
        if (testPropertySet(10)) {
            config->setValue(QStringLiteral("fontSize"), QVariant::fromValue(p_fontSize));
        } else {
            updateValue(QStringLiteral("fontSize"), QVariant::fromValue(p_fontSize));
        }
        if (testPropertySet(11)) {
            config->setValue(QStringLiteral("forceSoftwareCursor"), QVariant::fromValue(p_forceSoftwareCursor));
        } else {
            updateValue(QStringLiteral("forceSoftwareCursor"), QVariant::fromValue(p_forceSoftwareCursor));
        }
        if (testPropertySet(12)) {
            config->setValue(QStringLiteral("iconThemeName"), QVariant::fromValue(p_iconThemeName));
        } else {
            updateValue(QStringLiteral("iconThemeName"), QVariant::fromValue(p_iconThemeName));
        }
        if (testPropertySet(13)) {
            config->setValue(QStringLiteral("lostScreen"), QVariant::fromValue(p_lostScreen));
        } else {
            updateValue(QStringLiteral("lostScreen"), QVariant::fromValue(p_lostScreen));
        }
        if (testPropertySet(14)) {
            config->setValue(QStringLiteral("maxWorkspace"), QVariant::fromValue(p_maxWorkspace));
        } else {
            updateValue(QStringLiteral("maxWorkspace"), QVariant::fromValue(p_maxWorkspace));
        }
        if (testPropertySet(15)) {
            config->setValue(QStringLiteral("monoFont"), QVariant::fromValue(p_monoFont));
        } else {
            updateValue(QStringLiteral("monoFont"), QVariant::fromValue(p_monoFont));
        }
        if (testPropertySet(16)) {
            config->setValue(QStringLiteral("numWorkspace"), QVariant::fromValue(p_numWorkspace));
        } else {
            updateValue(QStringLiteral("numWorkspace"), QVariant::fromValue(p_numWorkspace));
        }
        if (testPropertySet(17)) {
            config->setValue(QStringLiteral("preferDark"), QVariant::fromValue(p_preferDark));
        } else {
            updateValue(QStringLiteral("preferDark"), QVariant::fromValue(p_preferDark));
        }
        if (testPropertySet(18)) {
            config->setValue(QStringLiteral("showOnLock"), QVariant::fromValue(p_showOnLock));
        } else {
            updateValue(QStringLiteral("showOnLock"), QVariant::fromValue(p_showOnLock));
        }
        if (testPropertySet(19)) {
            config->setValue(QStringLiteral("themeName"), QVariant::fromValue(p_themeName));
        } else {
            updateValue(QStringLiteral("themeName"), QVariant::fromValue(p_themeName));
        }
        if (testPropertySet(20)) {
            config->setValue(QStringLiteral("windowOpacity"), QVariant::fromValue(p_windowOpacity));
        } else {
            updateValue(QStringLiteral("windowOpacity"), QVariant::fromValue(p_windowOpacity));
        }
        if (testPropertySet(21)) {
            config->setValue(QStringLiteral("windowRadius"), QVariant::fromValue(p_windowRadius));
        } else {
            updateValue(QStringLiteral("windowRadius"), QVariant::fromValue(p_windowRadius));
        }
        if (testPropertySet(22)) {
            config->setValue(QStringLiteral("windowThemeType"), QVariant::fromValue(p_windowThemeType));
        } else {
            updateValue(QStringLiteral("windowThemeType"), QVariant::fromValue(p_windowThemeType));
        }
        if (testPropertySet(23)) {
            config->setValue(QStringLiteral("windowTitlebarHeight"), QVariant::fromValue(p_windowTitlebarHeight));
        } else {
            updateValue(QStringLiteral("windowTitlebarHeight"), QVariant::fromValue(p_windowTitlebarHeight));
        }

        connect(config, &DTK_CORE_NAMESPACE::DConfig::valueChanged, this, [this](const QString &key) {
            updateValue(key);
        }, Qt::DirectConnection);
    }
    void updateValue(const QString &key, const QVariant &fallback = QVariant()) {
        Q_ASSERT(QThread::currentThread() == m_config.loadRelaxed()->thread());
        const QVariant &value = m_config.loadRelaxed()->value(key, fallback);
        if (key == QStringLiteral("activeColor")) {
            auto newValue = qvariant_cast<QString>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_activeColor != newValue) {
                    p_activeColor = newValue;
                    Q_EMIT activeColorChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("currentWorkspace")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_currentWorkspace != newValue) {
                    p_currentWorkspace = newValue;
                    Q_EMIT currentWorkspaceChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("cursorBlink")) {
            auto newValue = qvariant_cast<bool>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_cursorBlink != newValue) {
                    p_cursorBlink = newValue;
                    Q_EMIT cursorBlinkChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("cursorBlinkTime")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_cursorBlinkTime != newValue) {
                    p_cursorBlinkTime = newValue;
                    Q_EMIT cursorBlinkTimeChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("cursorSize")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_cursorSize != newValue) {
                    p_cursorSize = newValue;
                    Q_EMIT cursorSizeChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("cursorThemeName")) {
            auto newValue = qvariant_cast<QString>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_cursorThemeName != newValue) {
                    p_cursorThemeName = newValue;
                    Q_EMIT cursorThemeNameChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("dndDragThreshold")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_dndDragThreshold != newValue) {
                    p_dndDragThreshold = newValue;
                    Q_EMIT dndDragThresholdChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("doubleClickDistance")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_doubleClickDistance != newValue) {
                    p_doubleClickDistance = newValue;
                    Q_EMIT doubleClickDistanceChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("doubleClickTime")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_doubleClickTime != newValue) {
                    p_doubleClickTime = newValue;
                    Q_EMIT doubleClickTimeChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("font")) {
            auto newValue = qvariant_cast<QString>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_font != newValue) {
                    p_font = newValue;
                    Q_EMIT fontChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("fontSize")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_fontSize != newValue) {
                    p_fontSize = newValue;
                    Q_EMIT fontSizeChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("forceSoftwareCursor")) {
            auto newValue = qvariant_cast<bool>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_forceSoftwareCursor != newValue) {
                    p_forceSoftwareCursor = newValue;
                    Q_EMIT forceSoftwareCursorChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("iconThemeName")) {
            auto newValue = qvariant_cast<QString>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_iconThemeName != newValue) {
                    p_iconThemeName = newValue;
                    Q_EMIT iconThemeNameChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("lostScreen")) {
            auto newValue = qvariant_cast<QString>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_lostScreen != newValue) {
                    p_lostScreen = newValue;
                    Q_EMIT lostScreenChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("maxWorkspace")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_maxWorkspace != newValue) {
                    p_maxWorkspace = newValue;
                    Q_EMIT maxWorkspaceChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("monoFont")) {
            auto newValue = qvariant_cast<QString>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_monoFont != newValue) {
                    p_monoFont = newValue;
                    Q_EMIT monoFontChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("numWorkspace")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_numWorkspace != newValue) {
                    p_numWorkspace = newValue;
                    Q_EMIT numWorkspaceChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("preferDark")) {
            auto newValue = qvariant_cast<bool>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_preferDark != newValue) {
                    p_preferDark = newValue;
                    Q_EMIT preferDarkChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("showOnLock")) {
            auto newValue = qvariant_cast<bool>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_showOnLock != newValue) {
                    p_showOnLock = newValue;
                    Q_EMIT showOnLockChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("themeName")) {
            auto newValue = qvariant_cast<QString>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_themeName != newValue) {
                    p_themeName = newValue;
                    Q_EMIT themeNameChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("windowOpacity")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_windowOpacity != newValue) {
                    p_windowOpacity = newValue;
                    Q_EMIT windowOpacityChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("windowRadius")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_windowRadius != newValue) {
                    p_windowRadius = newValue;
                    Q_EMIT windowRadiusChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("windowThemeType")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_windowThemeType != newValue) {
                    p_windowThemeType = newValue;
                    Q_EMIT windowThemeTypeChanged();
                }
            });
            return;
        }
        if (key == QStringLiteral("windowTitlebarHeight")) {
            auto newValue = qvariant_cast<qint64>(value);
            QMetaObject::invokeMethod(this, [this, newValue]() {
                if (p_windowTitlebarHeight != newValue) {
                    p_windowTitlebarHeight = newValue;
                    Q_EMIT windowTitlebarHeightChanged();
                }
            });
            return;
        }
    }
    inline void markPropertySet(const int index) {
        if (index < 32) {
            m_propertySetStatus0.fetchAndOrOrdered(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();
    }
    QAtomicPointer<DTK_CORE_NAMESPACE::DConfig> m_config = nullptr;
    QString p_activeColor { QStringLiteral("") };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_currentWorkspace { 0 };
    bool p_cursorBlink { true };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_cursorBlinkTime { 1200 };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_cursorSize { 24 };
    QString p_cursorThemeName { QStringLiteral("bloom") };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_dndDragThreshold { 8 };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_doubleClickDistance { 5 };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_doubleClickTime { 250 };
    QString p_font { QStringLiteral("Source Han Sans SC") };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_fontSize { 105 };
    bool p_forceSoftwareCursor { false };
    QString p_iconThemeName { QStringLiteral("bloom") };
    QString p_lostScreen { QStringLiteral("MoveToPrimary") };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_maxWorkspace { 6 };
    QString p_monoFont { QStringLiteral("Noto Mono") };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_numWorkspace { 2 };
    bool p_preferDark { false };
    bool p_showOnLock { false };
    QString p_themeName { QStringLiteral("") };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_windowOpacity { 100 };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_windowRadius { 18 };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_windowThemeType { 0 };
    // Note: If you expect a double type, add 'e' to the number in the JSON value field, e.g., "value": 1.0e, not just 1.0
    qint64 p_windowTitlebarHeight { 30 };
    QAtomicInteger<quint32> m_propertySetStatus0 = 0;
};

#endif // ORG_DEEPIN_TREELAND_H

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zccrs

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

deepin-ci-robot added a commit to linuxdeepin/dtk6core that referenced this pull request Dec 3, 2024
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#448
deepin-ci-robot added a commit to linuxdeepin/dtk6core that referenced this pull request Dec 4, 2024
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#448
deepin-ci-robot added a commit to linuxdeepin/dtk6core that referenced this pull request Dec 4, 2024
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#448
deepin-ci-robot added a commit to linuxdeepin/dtk6core that referenced this pull request Dec 4, 2024
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#448
deepin-ci-robot added a commit to linuxdeepin/dtk6core that referenced this pull request Dec 4, 2024
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#448
deepin-ci-robot added a commit to linuxdeepin/dtk6core that referenced this pull request Dec 4, 2024
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#448
deepin-ci-robot added a commit to linuxdeepin/dtk6core that referenced this pull request Dec 4, 2024
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#448
deepin-ci-robot added a commit to linuxdeepin/dtk6core that referenced this pull request Dec 4, 2024
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#448
@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 4, 2024

TAG Bot

New tag: 5.7.4
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #446

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 17, 2024

TAG Bot

New tag: 5.7.5
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #450

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 2, 2025

TAG Bot

New tag: 5.7.6
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #452

deepin-ci-robot added a commit to linuxdeepin/dtk6core that referenced this pull request Jan 2, 2025
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#448
@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 9, 2025

TAG Bot

New tag: 5.7.7
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #453

deepin-ci-robot added a commit to linuxdeepin/dtk6core that referenced this pull request Jan 10, 2025
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#448
@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

代码审查意见:

  1. CMakeLists.txt 文件:

    • tools/CMakeLists.txt 文件中添加了 dconfig2cpp 子目录,这是一个好的做法,但应确保 dconfig2cpp 目录中包含必要的构建文件和源代码。
  2. dconfig2cpp/CMakeLists.txt 文件:

    • set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 这一行是好的,因为它可以帮助开发者在构建时生成 compile_commands.json 文件,方便代码分析工具使用。
    • find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) 这一行确保了项目依赖于 Qt 库,但应检查 QT_VERSION_MAJOR 是否在项目配置中定义。
  3. main.cpp 文件:

    • jsonValueToCppCode 函数中,对于 QVariant 的处理逻辑较为复杂,建议添加注释说明每个分支的用途。
    • main 函数中,对 JSON 文件的读取和处理逻辑较为冗长,建议将这部分逻辑拆分成多个函数以提高代码的可读性和可维护性。
    • 在生成头文件时,使用了大量的字符串拼接,建议使用 QStringBuilder 来提高性能。
    • 在处理 JSON 文件时,没有对异常情况进行处理,例如文件不存在或 JSON 格式错误,建议添加相应的错误处理逻辑。
    • 在生成头文件时,使用了大量的 QStringLiteral,这可能会导致生成的文件较大,建议评估是否需要使用 QString 而不是 QStringLiteral
    • 在生成头文件时,使用了大量的 Q_ASSERT,这可能会导致在发布版本中产生不必要的断言失败,建议在调试版本中使用 Q_ASSERT,而在发布版本中移除。
  4. 代码风格和格式:

    • 代码中存在一些不一致的缩进和空格使用,建议统一代码风格,以提高代码的可读性。
    • main.cpp 文件中,注释的格式和位置不一致,建议统一注释的格式和位置。
  5. 安全性:

    • 在读取和解析 JSON 文件时,没有对输入进行验证,可能会导致安全漏洞,建议添加输入验证逻辑。
    • 在生成头文件时,使用了用户输入的值来生成文件名,这可能会导致文件名注入攻击,建议对用户输入进行验证和清理。
  6. 性能:

    • jsonValueToCppCode 函数中,对于 QVariant 的处理逻辑可能存在性能问题,建议评估是否需要优化。
    • 在生成头文件时,使用了大量的字符串拼接,这可能会导致性能问题,建议评估是否需要优化。
  7. 错误处理:

    • main 函数中,对于文件打开失败的情况,只是简单地打印了警告信息并返回了错误码,建议添加更详细的错误处理逻辑,例如记录日志或抛出异常。
  8. 代码重复:

    • main.cpp 文件中,生成构造函数的代码逻辑重复,建议提取公共逻辑到一个单独的函数中。
  9. 代码注释:

    • main.cpp 文件中,部分代码缺少注释,建议添加必要的注释以提高代码的可读性。
  10. 代码健壮性:

    • main.cpp 文件中,对于 JSON 文件的处理逻辑没有进行充分的测试,建议添加单元测试来验证代码的健壮性。

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 14, 2025

TAG Bot

New tag: 5.7.8
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #455

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 23, 2025

TAG Bot

New tag: 5.7.9
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants