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 1 commit 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
Copy link
Contributor

deepin pr auto review

代码审查意见:

  1. CMakeLists.txt 文件:

    • tools/CMakeLists.txt 文件中添加了 dconfig2cpp 子目录,这是一个好的做法,因为它有助于模块化和组织代码。
    • 确保在 dconfig2cpp/CMakeLists.txt 文件中正确设置了 QT_VERSION_MAJORDTK_VERSION_MAJOR,以避免潜在的编译错误。
  2. dconfig2cpp 工具:

    • dconfig2cpp 工具的 main.cpp 文件中,jsonValueToCppCode 函数处理了多种 JSON 值类型,并将其转换为 C++ 代码。这个函数的实现看起来是正确的,但建议添加更多的注释来解释每个分支的作用。
    • main.cpp 中,QCoreApplication 的实例 app 被创建,但并没有被使用。如果这个实例不需要,应该移除它以避免不必要的资源消耗。
    • main.cpp 中使用了 qWarning()qDebug() 来输出错误信息,建议使用 qFatal()qCritical() 来处理致命错误,以确保程序在遇到严重问题时能够立即停止。
  3. 信号和槽:

    • main.cpp 中,Q_SIGNALSQ_EMIT 被用于生成信号和槽的代码。这是一个好的做法,因为它有助于保持代码的清晰和可维护性。
    • 确保在生成信号和槽的代码时,所有相关的信号和槽都被正确地连接,以避免潜在的内存泄漏或未处理的信号。
  4. 线程安全:

    • main.cpp 中使用了 QAtomicPointerQAtomicInteger 来确保线程安全。这是一个好的做法,但需要确保所有对原子变量的访问都是线程安全的,并且没有竞态条件。
  5. 错误处理:

    • main.cpp 中在打开文件时使用了 QFile::open() 方法,但没有检查返回值。应该检查返回值以确保文件成功打开。
    • 在处理 JSON 文件时,应该添加更多的错误处理逻辑,以处理无效的 JSON 数据或缺少必要的字段。
  6. 代码风格和格式:

    • main.cpp 中的代码风格和格式看起来比较混乱,建议使用代码格式化工具(如 clang-format)来统一代码风格。
    • 在生成 C++ 代码时,建议使用模板字符串来提高代码的可读性,而不是使用多个字符串连接操作。
  7. 性能优化:

    • main.cpp 中使用了 QJsonDocumentQJsonObject 来解析 JSON 数据。如果 JSON 数据较大,可以考虑使用更高效的解析方法,如 QJsonParseErrorQJsonStreamReader
  8. 安全性:

    • main.cpp 中没有明显的安全漏洞,但建议在处理用户输入时进行适当的验证和清理,以防止注入攻击。

总体来说,代码实现是正确的,但存在一些可以改进的地方,以提高代码的可读性、可维护性和性能。

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

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