diff options
author | BogDan Vatra <bogdan.vatra.ford@kdab.com> | 2016-05-24 15:27:11 +0300 |
---|---|---|
committer | BogDan Vatra <bogdan@kdab.com> | 2016-05-24 12:46:18 +0000 |
commit | 1d896073761c8cc7e5c13918d55a6300225bdb9a (patch) | |
tree | 2b28db61d9cb96bf40f1392bf8f7f6a8d2611c90 /src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp | |
parent | 0495acc9935bbbe1280330195362b93feda51e56 (diff) |
Request only the cached data
The server side model might changed the data which is not in the client
LRU cache, so, there is no point to request that data because is not
visible.
Change-Id: I3aa4312f8113cb58e1df3bc4c70eeb61efb91c89
Reviewed-by: Continuous Integration (KDAB) <build@kdab.com>
Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
Diffstat (limited to 'src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp')
-rw-r--r-- | src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp b/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp index b4bf719..0abd55e 100644 --- a/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp +++ b/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp @@ -218,13 +218,45 @@ void QAbstractItemModelReplicaPrivate::onDataChanged(const IndexList &start, con qCDebug(QT_REMOTEOBJECT_MODELS) << Q_FUNC_INFO << "start=" << start << "end=" << end << "roles=" << roles; // we need to clear the cache to make sure the new remote data is fetched if the new data call is happening - RequestedData data; - data.start = start; - data.end = end; - data.roles = roles; if (clearCache(start, end, roles)) { - m_requestedData.append(data); - QMetaObject::invokeMethod(this, "fetchPendingData", Qt::QueuedConnection); + bool ok = true; + const QModelIndex startIndex = toQModelIndex(start, q, &ok); + if (!ok) + return; + const QModelIndex endIndex = toQModelIndex(end, q, &ok); + if (!ok) + return; + Q_ASSERT(startIndex.parent() == endIndex.parent()); + auto parentItem = cacheData(startIndex.parent()); + int startRow = start.last().row; + int endRow = end.last().row; + bool dataChanged = false; + while (startRow <= endRow) { + for (;startRow <= endRow; startRow++) { + if (parentItem->children.exists(startRow)) + break; + } + + if (startRow > endRow) + break; + + RequestedData data; + data.roles = roles; + data.start = start; + data.start.last().row = startRow; + + while (startRow <= endRow && parentItem->children.exists(startRow)) + ++startRow; + + data.end = end; + data.end.last().row = startRow -1; + + m_requestedData.append(data); + dataChanged = true; + } + + if (dataChanged) + QMetaObject::invokeMethod(this, "fetchPendingData", Qt::QueuedConnection); } } |