diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-03-23 15:40:01 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-03-24 09:08:15 +0100 |
commit | 55a67d9b16aa089134a2636be29de96341efb932 (patch) | |
tree | 510d3057295f93a388eebbce5f0673a54ca5398e /src/qmlmodels | |
parent | 861f53d60cc2dd8bd8529c65863af881dbdd8db8 (diff) |
Trade memory for performance in PropertyUpdater::doUpdate
Change-Id: I0117029ecbe7fc369c15fcd8a44f93797e95ab3e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmlmodels')
-rw-r--r-- | src/qmlmodels/qqmldelegatemodel.cpp | 18 | ||||
-rw-r--r-- | src/qmlmodels/qqmldelegatemodel_p_p.h | 1 |
2 files changed, 8 insertions, 11 deletions
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<int, QMetaObject::Connection> senderToConnection; + QHash<int, int> changeSignalIndexToPropertyIndex; int updateCount = 0; public Q_SLOTS: void doUpdate(); |