summaryrefslogtreecommitdiffstats
path: root/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan.vatra.ford@kdab.com>2016-05-18 11:57:29 +0300
committerBogDan Vatra <bogdan@kdab.com>2016-05-24 12:46:03 +0000
commit6c6ae5be24c913d9cc9d64a5d50b30f5540dcc64 (patch)
tree21b939e5e2f8d182a01b51f44ba5630d3ad3825a /src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp
parent1ec5a79c839747ee479642fbc19bc99904d6d611 (diff)
Make sure the parent is cached when we try to insert a child.
Fix crash when we start with an empty tree modele and we insert a child of a child. Change-Id: I726e1806b737ba35a506fb7745d1432c3b249a18 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.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp b/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp
index 7142d39..f7d943c 100644
--- a/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp
+++ b/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp
@@ -233,7 +233,7 @@ void QAbstractItemModelReplicaPrivate::onRowsInserted(const IndexList &parent, i
qCDebug(QT_REMOTEOBJECT_MODELS) << Q_FUNC_INFO << "start=" << start << "end=" << end << "parent=" << parent;
bool treeFullyLazyLoaded = true;
- const QModelIndex parentIndex = toQModelIndex(parent, q, &treeFullyLazyLoaded);
+ const QModelIndex parentIndex = toQModelIndex(parent, q, &treeFullyLazyLoaded, true);
if (!treeFullyLazyLoaded)
return;
@@ -716,6 +716,16 @@ QItemSelectionModel* QAbstractItemModelReplica::selectionModel() const
bool QAbstractItemModelReplica::setData(const QModelIndex &index, const QVariant &value, int role)
{
+ if (role == Qt::UserRole - 1) {
+ auto parent = d->cacheData(index);
+ if (!parent)
+ return false;
+ bool ok = true;
+ auto row = value.toInt(&ok);
+ if (ok)
+ parent->ensureChildren(row, row);
+ return ok;
+ }
if (!index.isValid())
return false;
if (index.row() < 0 || index.row() >= rowCount(index.parent()))
@@ -763,7 +773,6 @@ QVariant QAbstractItemModelReplica::data(const QModelIndex & index, int role) co
IndexList parentList = toModelIndexList(index.parent(), this);
IndexList start = IndexList() << parentList << ModelIndex(row, 0);
IndexList end = IndexList() << parentList << ModelIndex(row, std::max(0, parentItem->columnCount - 1));
- parentItem->ensureChildren(row, row);
Q_ASSERT(toQModelIndex(start, this).isValid());
RequestedData data;