1414DCORE_USE_NAMESPACE;
1515
1616DQUICK_BEGIN_NAMESPACE
17+
18+ #ifndef QT_DEBUG
19+ Q_LOGGING_CATEGORY (settingLog, " dtk.dsg.settings" , QtInfoMsg);
20+ #else
21+ Q_LOGGING_CATEGORY (settingLog, " dtk.dsg.settings" );
22+ #endif
23+
1724static constexpr char const *settingsOptionObjectName = " _d_settings_option" ;
1825static constexpr char const *settingsGroupObjectName = " _d_settings_group" ;
1926
@@ -210,12 +217,12 @@ void SettingsContainer::onGroupVisibleChanged(bool visible)
210217 }
211218}
212219
213- DConfigWrapper *SettingsContainer::config () const
220+ QObject *SettingsContainer::config () const
214221{
215222 return m_config;
216223}
217224
218- void SettingsContainer::setConfig (DConfigWrapper *config)
225+ void SettingsContainer::setConfig (QObject *config)
219226{
220227 if (m_config == config)
221228 return ;
@@ -245,9 +252,10 @@ QString SettingsOption::name() const
245252
246253QVariant SettingsOption::value ()
247254{
248- if (!m_valueInitialized) {
249- if (m_config->isValid ()) {
250- m_value = m_config->value (m_key);
255+ if (!m_valueInitialized && m_config) {
256+ auto value = m_config->property (m_key.toLocal8Bit ());
257+ if (value.isValid ()) {
258+ m_value = value;
251259 m_valueInitialized = true ;
252260 }
253261 }
@@ -270,17 +278,16 @@ static int indexOfProperty(const QObject * obj, const QString &name)
270278 return -1 ;
271279}
272280
273- void SettingsOption::setConfig (DConfigWrapper *config)
281+ void SettingsOption::setConfig (QObject *config)
274282{
275283 m_config = config;
276284 int propertyIndex = indexOfProperty (m_config, m_key);
277285 if (propertyIndex < 0 ) {
278- connect (m_config, &DConfigWrapper::valueChanged, this , [this ](const QString &key){
279- if (key == m_key) {
280- setValue (m_config->value (key), false );
281- m_valueInitialized = true ;
282- }
283- });
286+ const auto ok = connect (m_config, SIGNAL (valueChanged (QString, QVariant)),
287+ this , SLOT (onValueChanged (QString, QVariant)));
288+ if (!ok) {
289+ qCWarning (settingLog) << " Failed to connect valueChanged signal from Config object:" << m_config;
290+ }
284291 } else {
285292 // valueChanged is not emitted when the key of Config defined in qml
286293 const auto mo = m_config->metaObject ();
@@ -305,10 +312,21 @@ SettingsOption *SettingsOption::qmlAttachedProperties(QObject *object)
305312
306313void SettingsOption::onConfigValueChanged ()
307314{
308- setValue (m_config->value (m_key), false );
315+ const auto value = m_config->property (m_key.toLocal8Bit ());
316+ if (!value.isValid ())
317+ return ;
318+ setValue (value, false );
309319 m_valueInitialized = true ;
310320}
311321
322+ void SettingsOption::onValueChanged (const QString &key, const QVariant &value)
323+ {
324+ if (key == m_key && value.isValid ()) {
325+ setValue (value, false );
326+ m_valueInitialized = true ;
327+ }
328+ }
329+
312330void SettingsOption::setValue (QVariant value)
313331{
314332 setValue (value, true );
@@ -321,14 +339,30 @@ void SettingsOption::setValue(const QVariant &value, bool updateConfig)
321339
322340 m_value = value;
323341 if (updateConfig && m_config)
324- m_config->setValue (m_key, value);
342+ m_config->setProperty (m_key. toLocal8Bit () , value);
325343
326344 Q_EMIT valueChanged (value);
327345}
328346
329347void SettingsOption::resetValue ()
330348{
331- m_config->resetValue (m_key);
349+ const auto index = indexOfProperty (m_config, m_key);
350+ if (index < 0 ) {
351+ qCWarning (settingLog) << " The key" << m_key << " not found in the Config object:" << m_config;
352+ return ;
353+ }
354+
355+ const auto mo = m_config->metaObject ();
356+ const auto p = mo->property (index);
357+
358+ if (!p.isResettable ()) {
359+ qCDebug (settingLog) << " The key" << m_key << " can't reset in the Config object:" << m_config;
360+ return ;
361+ }
362+
363+ if (!p.reset (m_config)) {
364+ qCWarning (settingLog) << " The key" << m_key << " reset failed in the Config object:" << m_config;
365+ }
332366}
333367
334368void SettingsOption::setKey (QString key)
@@ -404,7 +438,7 @@ void SettingsGroup::setBackground(QQmlComponent *background)
404438 Q_EMIT backgroundChanged ();
405439}
406440
407- void SettingsGroup::setConfig (DConfigWrapper *config)
441+ void SettingsGroup::setConfig (QObject *config)
408442{
409443 for (auto childGroup : qAsConst (m_children)) {
410444 childGroup->setConfig (config);
0 commit comments