| 1 |
/** |
| 2 |
* This file is generated by dconfig2cpp. |
| 3 |
* Command line arguments: ./dconfig2cpp -p ./dtkcore/toolGenerate/dconfig2cpp ./dtkcore/tests/data/dconf-example_other_app_configure.meta.json |
| 4 |
* Generation time: 2025-01-14T10:54:59 |
| 5 |
* JSON file version: 1.0 |
| 6 |
* |
| 7 |
* WARNING: DO NOT MODIFY THIS FILE MANUALLY. |
| 8 |
* If you need to change the content, please modify the dconfig2cpp tool. |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifndef DCONF-EXAMPLE_OTHER_APP_CONFIGURE_META_H |
| 12 |
#define DCONF-EXAMPLE_OTHER_APP_CONFIGURE_META_H |
| 13 |
|
| 14 |
#include <QThread> |
| 15 |
#include <QVariant> |
| 16 |
#include <QDebug> |
| 17 |
#include <QAtomicPointer> |
| 18 |
#include <QAtomicInteger> |
| 19 |
#include <DConfig> |
| 20 |
|
| 21 |
class dconf-example_other_app_configure_meta : public QObject { |
| 22 |
Q_OBJECT |
| 23 |
|
| 24 |
Q_PROPERTY(QString appPrivate READ appPrivate WRITE setAppPrivate NOTIFY appPrivateChanged) |
| 25 |
Q_PROPERTY(QString appPublic READ appPublic WRITE setAppPublic NOTIFY appPublicChanged) |
| 26 |
public: |
| 27 |
explicit dconf-example_other_app_configure_meta(QThread *thread, const QString &appId, const QString &name, const QString &subpath, QObject *parent = nullptr) |
| 28 |
: QObject(parent) { |
| 29 |
|
| 30 |
if (!thread->isRunning()) { |
| 31 |
qWarning() << QStringLiteral("Warning: The provided thread is not running."); |
| 32 |
} |
| 33 |
Q_ASSERT(QThread::currentThread() != thread); |
| 34 |
auto worker = new QObject(); |
| 35 |
worker->moveToThread(thread); |
| 36 |
QMetaObject::invokeMethod(worker, [=]() { |
| 37 |
auto config = DTK_CORE_NAMESPACE::DConfig::create(appId, name, subpath, nullptr); |
| 38 |
if (!config) { |
| 39 |
qWarning() << QStringLiteral("Failed to create DConfig instance."); |
| 40 |
worker->deleteLater(); |
| 41 |
return; |
| 42 |
} |
| 43 |
config->moveToThread(QThread::currentThread()); |
| 44 |
initialize(config); |
| 45 |
worker->deleteLater(); |
| 46 |
}); |
| 47 |
} |
| 48 |
explicit dconf-example_other_app_configure_meta(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &appId, const QString &name, const QString &subpath, QObject *parent = nullptr) |
| 49 |
: QObject(parent) { |
| 50 |
|
| 51 |
if (!thread->isRunning()) { |
| 52 |
qWarning() << QStringLiteral("Warning: The provided thread is not running."); |
| 53 |
} |
| 54 |
Q_ASSERT(QThread::currentThread() != thread); |
| 55 |
auto worker = new QObject(); |
| 56 |
worker->moveToThread(thread); |
| 57 |
QMetaObject::invokeMethod(worker, [=]() { |
| 58 |
auto config = DTK_CORE_NAMESPACE::DConfig::create(backend, appId, name, subpath, nullptr); |
| 59 |
if (!config) { |
| 60 |
qWarning() << QStringLiteral("Failed to create DConfig instance."); |
| 61 |
worker->deleteLater(); |
| 62 |
return; |
| 63 |
} |
| 64 |
config->moveToThread(QThread::currentThread()); |
| 65 |
initialize(config); |
| 66 |
worker->deleteLater(); |
| 67 |
}); |
| 68 |
} |
| 69 |
explicit dconf-example_other_app_configure_meta(QThread *thread, const QString &name, const QString &subpath, QObject *parent = nullptr) |
| 70 |
: QObject(parent) { |
| 71 |
|
| 72 |
if (!thread->isRunning()) { |
| 73 |
qWarning() << QStringLiteral("Warning: The provided thread is not running."); |
| 74 |
} |
| 75 |
Q_ASSERT(QThread::currentThread() != thread); |
| 76 |
auto worker = new QObject(); |
| 77 |
worker->moveToThread(thread); |
| 78 |
QMetaObject::invokeMethod(worker, [=]() { |
| 79 |
auto config = DTK_CORE_NAMESPACE::DConfig::create(name, subpath, nullptr); |
| 80 |
if (!config) { |
| 81 |
qWarning() << QStringLiteral("Failed to create DConfig instance."); |
| 82 |
worker->deleteLater(); |
| 83 |
return; |
| 84 |
} |
| 85 |
config->moveToThread(QThread::currentThread()); |
| 86 |
initialize(config); |
| 87 |
worker->deleteLater(); |
| 88 |
}); |
| 89 |
} |
| 90 |
explicit dconf-example_other_app_configure_meta(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &subpath, QObject *parent = nullptr) |
| 91 |
: QObject(parent) { |
| 92 |
|
| 93 |
if (!thread->isRunning()) { |
| 94 |
qWarning() << QStringLiteral("Warning: The provided thread is not running."); |
| 95 |
} |
| 96 |
Q_ASSERT(QThread::currentThread() != thread); |
| 97 |
auto worker = new QObject(); |
| 98 |
worker->moveToThread(thread); |
| 99 |
QMetaObject::invokeMethod(worker, [=]() { |
| 100 |
auto config = DTK_CORE_NAMESPACE::DConfig::create(backend, name, subpath, nullptr); |
| 101 |
if (!config) { |
| 102 |
qWarning() << QStringLiteral("Failed to create DConfig instance."); |
| 103 |
worker->deleteLater(); |
| 104 |
return; |
| 105 |
} |
| 106 |
config->moveToThread(QThread::currentThread()); |
| 107 |
initialize(config); |
| 108 |
worker->deleteLater(); |
| 109 |
}); |
| 110 |
} |
| 111 |
~dconf-example_other_app_configure_meta() { |
| 112 |
if (m_config.loadRelaxed()) { |
| 113 |
m_config.loadRelaxed()->deleteLater(); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
QString appPrivate() const { |
| 118 |
return p_appPrivate; |
| 119 |
} |
| 120 |
void setAppPrivate(const QString &value) { |
| 121 |
auto oldValue = p_appPrivate; |
| 122 |
p_appPrivate = value; |
| 123 |
markPropertySet(0); |
| 124 |
if (auto config = m_config.loadRelaxed()) { |
| 125 |
QMetaObject::invokeMethod(config, [this, value]() { |
| 126 |
m_config.loadRelaxed()->setValue(QStringLiteral("appPrivate"), value); |
| 127 |
}); |
| 128 |
} |
| 129 |
if (p_appPrivate != oldValue) { |
| 130 |
Q_EMIT appPrivateChanged(); |
| 131 |
} |
| 132 |
} |
| 133 |
QString appPublic() const { |
| 134 |
return p_appPublic; |
| 135 |
} |
| 136 |
void setAppPublic(const QString &value) { |
| 137 |
auto oldValue = p_appPublic; |
| 138 |
p_appPublic = value; |
| 139 |
markPropertySet(1); |
| 140 |
if (auto config = m_config.loadRelaxed()) { |
| 141 |
QMetaObject::invokeMethod(config, [this, value]() { |
| 142 |
m_config.loadRelaxed()->setValue(QStringLiteral("appPublic"), value); |
| 143 |
}); |
| 144 |
} |
| 145 |
if (p_appPublic != oldValue) { |
| 146 |
Q_EMIT appPublicChanged(); |
| 147 |
} |
| 148 |
} |
| 149 |
Q_SIGNALS: |
| 150 |
void appPrivateChanged(); |
| 151 |
void appPublicChanged(); |
| 152 |
private: |
| 153 |
void initialize(DTK_CORE_NAMESPACE::DConfig *config) { |
| 154 |
Q_ASSERT(!m_config.loadRelaxed()); |
| 155 |
m_config.storeRelaxed(config); |
| 156 |
if (testPropertySet(0)) { |
| 157 |
config->setValue(QStringLiteral("appPrivate"), QVariant::fromValue(p_appPrivate)); |
| 158 |
} else { |
| 159 |
updateValue(QStringLiteral("appPrivate"), QVariant::fromValue(p_appPrivate)); |
| 160 |
} |
| 161 |
if (testPropertySet(1)) { |
| 162 |
config->setValue(QStringLiteral("appPublic"), QVariant::fromValue(p_appPublic)); |
| 163 |
} else { |
| 164 |
updateValue(QStringLiteral("appPublic"), QVariant::fromValue(p_appPublic)); |
| 165 |
} |
| 166 |
|
| 167 |
connect(config, &DTK_CORE_NAMESPACE::DConfig::valueChanged, this, [this](const QString &key) { |
| 168 |
updateValue(key); |
| 169 |
}, Qt::DirectConnection); |
| 170 |
} |
| 171 |
void updateValue(const QString &key, const QVariant &fallback = QVariant()) { |
| 172 |
Q_ASSERT(QThread::currentThread() == m_config.loadRelaxed()->thread()); |
| 173 |
const QVariant &value = m_config.loadRelaxed()->value(key, fallback); |
| 174 |
if (key == QStringLiteral("appPrivate")) { |
| 175 |
auto newValue = qvariant_cast<QString>(value); |
| 176 |
QMetaObject::invokeMethod(this, [this, newValue]() { |
| 177 |
if (p_appPrivate != newValue) { |
| 178 |
p_appPrivate = newValue; |
| 179 |
Q_EMIT appPrivateChanged(); |
| 180 |
} |
| 181 |
}); |
| 182 |
return; |
| 183 |
} |
| 184 |
if (key == QStringLiteral("appPublic")) { |
| 185 |
auto newValue = qvariant_cast<QString>(value); |
| 186 |
QMetaObject::invokeMethod(this, [this, newValue]() { |
| 187 |
if (p_appPublic != newValue) { |
| 188 |
p_appPublic = newValue; |
| 189 |
Q_EMIT appPublicChanged(); |
| 190 |
} |
| 191 |
}); |
| 192 |
return; |
| 193 |
} |
| 194 |
} |
| 195 |
inline void markPropertySet(const int index) { |
| 196 |
if (index < 32) { |
| 197 |
m_propertySetStatus0.fetchAndOrOrdered(1 << (index - 0)); |
| 198 |
return; |
| 199 |
} |
| 200 |
Q_UNREACHABLE(); |
| 201 |
} |
| 202 |
inline bool testPropertySet(const int index) const { |
| 203 |
if (index < 32) { |
| 204 |
return (m_propertySetStatus0.loadRelaxed() & (1 << (index - 0))); |
| 205 |
} |
| 206 |
Q_UNREACHABLE(); |
| 207 |
} |
| 208 |
QAtomicPointer<DTK_CORE_NAMESPACE::DConfig> m_config = nullptr; |
| 209 |
QString p_appPrivate { QStringLiteral("appPrivate") }; |
| 210 |
QString p_appPublic { QStringLiteral("publicValue") }; |
| 211 |
QAtomicInteger<quint32> m_propertySetStatus0 = 0; |
| 212 |
}; |
| 213 |
|
| 214 |
#endif // DCONF-EXAMPLE_OTHER_APP_CONFIGURE_META_H |