Skip to content

Commit

Permalink
fix: DPlatformTheme::property not work
Browse files Browse the repository at this point in the history
buildNativeSettings 之后 metaobject 被替换了
不会走原来的 read 方法了。
读写属性时如果不是 base 对象初始化时属性 fallback 到
base 对象的 qt_metacall  方法

Issue: linuxdeepin/dtk#101
  • Loading branch information
kegechen committed Nov 7, 2023
1 parent cf5dc84 commit 19a3876
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/dnativesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ void DNativeSettings::init(const QMetaObject *metaObject)
QMetaPropertyBuilder op;

switch (mp.type()) {
case QMetaType::QByteArray:
case QMetaType::QString:
case QMetaType::QColor:
case QMetaType::Int:
case QMetaType::Double:
case QMetaType::Bool:
case QVariant::ByteArray:
case QVariant::String:
case QVariant::Color:
case QVariant::Int:
case QVariant::Double:
case QVariant::Bool:
op = ob.addProperty(mp);
break;
default:
Expand Down Expand Up @@ -409,9 +409,12 @@ int DNativeSettings::metaCall(QMetaObject::Call _c, int _id, void ** _a)
if (AllCall & (1 << _c)) {
const QMetaProperty &p = property(_id);
const int index = p.propertyIndex();
// 对于本地属性,此处应该从m_settings中读写
if (Q_LIKELY(index != m_flagPropertyIndex && index != m_allKeysPropertyIndex
&& index >= m_firstProperty)) {
if (Q_LIKELY(index != m_flagPropertyIndex &&
index != m_allKeysPropertyIndex &&
// fix dtk#101
// base 原有的属性(m_firstProperty ~ m_propertyCount)回退到 base 对象的 qt_metacall
// 其他属性从 m_settings 中读写
index >= m_propertyCount)) {
switch (_c) {
case QMetaObject::ReadProperty:
*reinterpret_cast<QVariant*>(_a[1]) = m_settings->setting(p.name());
Expand Down

0 comments on commit 19a3876

Please sign in to comment.