From 55a67d9b16aa089134a2636be29de96341efb932 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 23 Mar 2020 15:40:01 +0100 Subject: Trade memory for performance in PropertyUpdater::doUpdate Change-Id: I0117029ecbe7fc369c15fcd8a44f93797e95ab3e Reviewed-by: Ulf Hermann --- src/qmlmodels/qqmldelegatemodel.cpp | 18 +++++++----------- src/qmlmodels/qqmldelegatemodel_p_p.h | 1 + 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'src/qmlmodels') diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp index 12678696cc..cee096035a 100644 --- a/src/qmlmodels/qqmldelegatemodel.cpp +++ b/src/qmlmodels/qqmldelegatemodel.cpp @@ -926,17 +926,11 @@ void PropertyUpdater::doUpdate() auto mo = sender->metaObject(); auto signalIndex = QObject::senderSignalIndex(); ++updateCount; - // start at 0 instead of propertyOffset to handle properties from parent hierarchy - for (auto i = 0; i < mo->propertyCount() + mo->propertyOffset(); ++i) { - auto property = mo->property(i); - if (property.notifySignal().methodIndex() == signalIndex) { - // we synchronize between required properties and model rolenames by name - // that's why the QQmlProperty and the metaobject property must have the same name - QQmlProperty qmlProp(parent(), QString::fromLatin1(property.name())); - qmlProp.write(property.read(QObject::sender())); - return; - } - } + auto property = mo->property(changeSignalIndexToPropertyIndex[signalIndex]); + // we synchronize between required properties and model rolenames by name + // that's why the QQmlProperty and the metaobject property must have the same name + QQmlProperty qmlProp(parent(), QString::fromLatin1(property.name())); + qmlProp.write(property.read(QObject::sender())); } void PropertyUpdater::breakBinding() @@ -1016,8 +1010,10 @@ void QQDMIncubationTask::initializeRequiredProperties(QQmlDelegateModelItem *mod QMetaMethod changeSignal = prop.notifySignal(); static QMetaMethod updateSlot = PropertyUpdater::staticMetaObject.method( PropertyUpdater::staticMetaObject.indexOfSlot("doUpdate()")); + QMetaObject::Connection conn = QObject::connect(itemOrProxy, changeSignal, updater, updateSlot); + updater->changeSignalIndexToPropertyIndex[changeSignal.methodIndex()] = i; auto propIdx = object->metaObject()->indexOfProperty(propName.toUtf8()); QMetaMethod writeToPropSignal = object->metaObject()->property(propIdx).notifySignal(); diff --git a/src/qmlmodels/qqmldelegatemodel_p_p.h b/src/qmlmodels/qqmldelegatemodel_p_p.h index 40c6bcdb21..2dc409b222 100644 --- a/src/qmlmodels/qqmldelegatemodel_p_p.h +++ b/src/qmlmodels/qqmldelegatemodel_p_p.h @@ -475,6 +475,7 @@ class PropertyUpdater : public QObject public: PropertyUpdater(QObject *parent); QHash senderToConnection; + QHash changeSignalIndexToPropertyIndex; int updateCount = 0; public Q_SLOTS: void doUpdate(); -- cgit v1.2.3