Skip to content

Commit f3b2241

Browse files
deepin-ci-robot18202781743
authored andcommitted
sync: from linuxdeepin/dtkdeclarative
Synchronize source files from linuxdeepin/dtkdeclarative. Source-pull-request: linuxdeepin/dtkdeclarative#474
1 parent 02af19e commit f3b2241

6 files changed

Lines changed: 67 additions & 31 deletions

File tree

qt6/src/qml/settings/SettingsDialog.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DialogWindow {
1212
id: control
1313

1414
property list<Settings.SettingsGroup> groups
15-
property D.Config config
15+
property QtObject config
1616
property Settings.SettingsContainer container : Settings.SettingsContainer {
1717
id: settingsContainer
1818
config: control.config

src/private/dconfigwrapper.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,11 @@ void DConfigWrapper::initializeProperties() const
363363
// Must fallback to the initial value, in the sync mode, the DConfigWrapperMetaObject's
364364
// properties is not initialize.
365365
const auto value = impl->value(key, initialValue);
366-
callInGuiThread(wrapper, [wrapper, key, value] {
367-
if (value.isValid())
366+
callInGuiThread(wrapper, [wrapper, key, value, currentValue] {
367+
if (value.isValid() && value != currentValue) {
368368
wrapper->mo->setValue(key.toLocal8Bit(), value);
369+
Q_EMIT wrapper->valueChanged(key, value);
370+
}
369371
});
370372
}
371373
}
@@ -387,8 +389,8 @@ void DConfigWrapper::initializeProperties() const
387389
wrapper->mo->setValue(propName, value);
388390
});
389391

390-
QMetaObject::invokeMethod(wrapper, [wrapper, key] {
391-
Q_EMIT wrapper->valueChanged(key);
392+
QMetaObject::invokeMethod(wrapper, [wrapper, key, value] {
393+
Q_EMIT wrapper->valueChanged(key, value);
392394
});
393395
}, Qt::DirectConnection);
394396

src/private/dconfigwrapper_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Q_SLOTS:
4747
bool isDefaultValue(const QString &key) const;
4848

4949
Q_SIGNALS:
50-
void valueChanged(const QString &key);
50+
void valueChanged(const QString &key, const QVariant &value);
5151
void initialized();
5252

5353
private:

src/private/dsettingscontainer.cpp

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
DCORE_USE_NAMESPACE;
1515

1616
DQUICK_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+
1724
static constexpr char const *settingsOptionObjectName = "_d_settings_option";
1825
static 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

246253
QVariant 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

306313
void 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+
312330
void 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

329347
void 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

334368
void 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);

src/private/dsettingscontainer_p.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <QQmlParserStatus>
1111
#include <QQmlComponent>
1212
#include <private/qqmlobjectmodel_p.h>
13-
#include "dconfigwrapper_p.h"
1413

1514
DQUICK_BEGIN_NAMESPACE
1615

@@ -40,7 +39,7 @@ class SettingsOption : public QObject
4039

4140
QQmlComponent *delegate() const;
4241
void setDelegate(QQmlComponent *delegate);
43-
void setConfig(DConfigWrapper *config);
42+
void setConfig(QObject *config);
4443

4544
static SettingsOption *qmlAttachedProperties(QObject *object);
4645

@@ -52,6 +51,7 @@ class SettingsOption : public QObject
5251

5352
private Q_SLOTS:
5453
void onConfigValueChanged();
54+
void onValueChanged(const QString &key, const QVariant &value);
5555

5656
private:
5757
void setValue(const QVariant &value, bool updateConfig);
@@ -61,7 +61,7 @@ private Q_SLOTS:
6161
QVariant m_value;
6262
bool m_valueInitialized = false;
6363
QQmlComponent *m_delegate = nullptr;
64-
DConfigWrapper *m_config = nullptr;
64+
QObject *m_config = nullptr;
6565
};
6666

6767
class SettingsGroup : public QObject
@@ -97,7 +97,7 @@ class SettingsGroup : public QObject
9797
QQmlListProperty<DTK_QUICK_NAMESPACE::SettingsGroup> children();
9898
QQmlComponent *background() const;
9999
void setBackground(QQmlComponent *background);
100-
void setConfig(DConfigWrapper *config);
100+
void setConfig(QObject *config);
101101
SettingsGroup *parentGroup() const;
102102
void setParentGroup(SettingsGroup *parentGroup);
103103
int index() const;
@@ -190,7 +190,7 @@ class SettingsContainer : public QObject, public QQmlParserStatus
190190
{
191191
Q_OBJECT
192192
Q_INTERFACES(QQmlParserStatus)
193-
Q_PROPERTY(DConfigWrapper *config READ config WRITE setConfig NOTIFY configChanged)
193+
Q_PROPERTY(QObject *config READ config WRITE setConfig NOTIFY configChanged)
194194
Q_PROPERTY(QQmlListProperty<DTK_QUICK_NAMESPACE::SettingsGroup> groups READ groups NOTIFY groupsChanged)
195195
Q_PROPERTY(SettingsContentModel *contentModel READ contentModel NOTIFY contentModelChanged)
196196
Q_PROPERTY(QQmlComponent *contentTitle READ contentTitle WRITE setContentTitle NOTIFY contentTitleChanged)
@@ -206,8 +206,8 @@ class SettingsContainer : public QObject, public QQmlParserStatus
206206
explicit SettingsContainer(QObject *parent = nullptr);
207207
virtual ~SettingsContainer() override;
208208

209-
DConfigWrapper *config() const;
210-
void setConfig(DConfigWrapper *config);
209+
QObject *config() const;
210+
void setConfig(QObject *config);
211211
QQmlListProperty<DTK_QUICK_NAMESPACE::SettingsGroup> groups();
212212
SettingsContentModel *contentModel() const;
213213
SettingsNavigationModel *navigationModel() const;
@@ -248,7 +248,7 @@ private Q_SLOTS:
248248
QQmlComponent *m_contentTitle = nullptr;
249249
QQmlComponent *m_navigationTitle = nullptr;
250250
QQmlComponent * m_contentBackground = nullptr;
251-
DConfigWrapper *m_config = nullptr;
251+
QObject *m_config = nullptr;
252252
};
253253

254254
DQUICK_END_NAMESPACE

src/qml/settings/SettingsDialog.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DialogWindow {
1212
id: control
1313

1414
property list<Settings.SettingsGroup> groups
15-
property D.Config config
15+
property QtObject config
1616
property Settings.SettingsContainer container : Settings.SettingsContainer {
1717
id: settingsContainer
1818
config: control.config

0 commit comments

Comments
 (0)