summaryrefslogtreecommitdiffstats
path: root/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-08-18 08:36:42 +0200
committerAndy Shaw <andy.shaw@qt.io>2021-05-05 12:43:27 +0000
commitfcd250521b67f1ca1a2205ab566a1c405c2f0529 (patch)
treea57962361c54a5426110d1991dac6d848c2d3227 /src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp
parent10cfbd2e34e7234d37ef2a9f3b0a587c0709407d (diff)
Update the replica when the layoutChanged signal is emitted
When a sort() is done on a QSortFilterProxyModel then it will emit the layoutChanged() signal, so it should ensure that the replica is updated in that case accordingly. Pick-to: 5.15 Fixes: QTBUG-85795 Change-Id: I7f34b24f4fab78c18655e986f54a0eb61db3a7b7 Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
Diffstat (limited to 'src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp')
-rw-r--r--src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp b/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp
index d1233bb..5d28920 100644
--- a/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp
+++ b/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp
@@ -137,6 +137,8 @@ void QAbstractItemModelReplicaImplementation::initializeModelConnections()
connect(this, &QAbstractItemModelReplicaImplementation::currentChanged, this, &QAbstractItemModelReplicaImplementation::onCurrentChanged);
connect(this, &QAbstractItemModelReplicaImplementation::modelReset, this, &QAbstractItemModelReplicaImplementation::onModelReset);
connect(this, &QAbstractItemModelReplicaImplementation::headerDataChanged, this, &QAbstractItemModelReplicaImplementation::onHeaderDataChanged);
+ connect(this, &QAbstractItemModelReplicaImplementation::layoutChanged, this, &QAbstractItemModelReplicaImplementation::onLayoutChanged);
+
}
inline void removeIndexFromRow(const QModelIndex &index, const QList<int> &roles, CachedRowEntry *entry)
@@ -689,6 +691,41 @@ void QAbstractItemModelReplicaImplementation::fetchPendingHeaderData()
m_pendingRequests.push_back(watcher);
}
+void QAbstractItemModelReplicaImplementation::onLayoutChanged(const IndexList &parents,
+ QAbstractItemModel::LayoutChangeHint hint)
+{
+ QList<QPersistentModelIndex> indexes;
+ for (const ModelIndex &parent : qAsConst(parents)) {
+ const QModelIndex parentIndex = toQModelIndex(IndexList{parent}, q);
+ indexes << QPersistentModelIndex(parentIndex);
+ }
+ QRemoteObjectPendingCallWatcher *watcher;
+ auto call = replicaCacheRequest(m_rootItem.children.cacheSize, m_initialFetchRolesHint);
+ watcher = new QRemoteObjectPendingCallWatcher(call);
+ m_pendingRequests.push_back(watcher);
+ connect(watcher, &QRemoteObjectPendingCallWatcher::finished, this, [this, watcher, indexes, hint]() {
+ Q_ASSERT(watcher->returnValue().canConvert<MetaAndDataEntries>());
+ const QSize size = watcher->returnValue().value<MetaAndDataEntries>().size;
+
+ q->layoutAboutToBeChanged(indexes, hint);
+ m_rootItem.clear();
+ if (size.height() > 0) {
+ m_rootItem.rowCount = size.height();
+ m_rootItem.hasChildren = true;
+ }
+
+ m_rootItem.columnCount = size.width();
+ if (m_initialAction == QtRemoteObjects::PrefetchData) {
+ auto entries = watcher->returnValue().value<MetaAndDataEntries>();
+ for (int i = 0; i < entries.data.size(); ++i)
+ fillCache(entries.data[i], entries.roles);
+ }
+ m_pendingRequests.removeAll(watcher);
+ watcher->deleteLater();
+ emit q->layoutChanged(indexes, hint);
+ });
+}
+
static inline QList<QPair<int, int>> listRanges(const QList<int> &list)
{
QList<QPair<int, int>> result;