Skip to content

Commit

Permalink
fix: valid properties read faild
Browse files Browse the repository at this point in the history
  • Loading branch information
kegechen committed Jan 12, 2024
1 parent 859044f commit 7d10f93
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/dnativesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@

#define VALID_PROPERTIES "validProperties"
#define ALL_KEYS "allKeys"
#define PROXY_OBJ "_d_proxyObject"

DPP_BEGIN_NAMESPACE

static inline QObject *proxyObject(QObject *obj)
{
if (qintptr ptr = qvariant_cast<qintptr>(obj->property(PROXY_OBJ)))
return reinterpret_cast<QObject*>(ptr);

return obj;
}

QHash<QObject*, DNativeSettings*> DNativeSettings::mapped;
/*
* 通过覆盖QObject的qt_metacall虚函数,检测base object中自定义的属性列表,将xwindow对应的设置和object对象中的属性绑定到一起使用
Expand Down Expand Up @@ -192,7 +201,7 @@ void DNativeSettings::init(const QMetaObject *metaObject)
}

// 将属性状态设置给对象
m_base->setProperty(VALID_PROPERTIES, validProperties);
proxyObject(m_base)->setProperty(VALID_PROPERTIES, validProperties);

// 将所有属性名称设置给对象
if (allKeyPropertyTyep == qMetaTypeId<QSet<QByteArray>>()) {
Expand Down Expand Up @@ -360,20 +369,20 @@ void DNativeSettings::onPropertyChanged(const QByteArray &name, const QVariant &

{
bool ok = false;
qint64 flags = handle->m_base->property(VALID_PROPERTIES).toLongLong(&ok);
qint64 flags = proxyObject(handle->m_base)->property(VALID_PROPERTIES).toLongLong(&ok);
// 更新有效属性的标志位
if (ok) {
qint64 flag = (1 << property_index);
flags = property.isValid() ? flags | flag : flags & ~flag;
handle->m_base->setProperty(VALID_PROPERTIES, flags);
proxyObject(handle->m_base)->setProperty(VALID_PROPERTIES, flags);
}
}

const QMetaProperty &p = handle->property(handle->m_firstProperty + property_index);

if (p.hasNotifySignal()) {
// 通知属性改变
p.notifySignal().invoke(handle->m_base);
p.notifySignal().invoke(proxyObject(handle->m_base));
}
}

Expand Down Expand Up @@ -415,7 +424,7 @@ int DNativeSettings::metaCall(QMetaObject::Call _c, int _id, void ** _a)
const int index = p.propertyIndex();
// 对于本地属性,此处应该从m_settings中读写
if (Q_LIKELY(index != m_flagPropertyIndex && index != m_allKeysPropertyIndex
&& index >= m_firstProperty + m_propertyCount)) {
&& index >= m_firstProperty)) {
switch (_c) {
case QMetaObject::ReadProperty:
*reinterpret_cast<QVariant*>(_a[1]) = m_settings->setting(p.name());
Expand Down

0 comments on commit 7d10f93

Please sign in to comment.