diff options
author | Brett Stottlemyer <bstottle@ford.com> | 2016-03-27 15:47:20 -0400 |
---|---|---|
committer | Brett Stottlemyer <bstottle@ford.com> | 2016-03-28 15:14:47 +0000 |
commit | da6aaf48211738b9256e1beb656691db0d533be0 (patch) | |
tree | d5070b9d9abff060b16eb25e61d12af5e5eed0c5 /src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp | |
parent | ced1b1ef1bfd319c97f1b472c58c03dd1bcdd33a (diff) |
[fix] Avoid rare crash in QAIM
Catch condition where multiple Replica's of the same model do not have
the same data cached. Only applies when a selectionModel is used.
Cleanup - convert OnConnectHandler to regular slot.
Change-Id: I7fb86e55560b36c20b84cd65fc34844006c3468b
Reviewed-by: Continuous Integration (KDAB) <build@kdab.com>
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp')
-rw-r--r-- | src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp b/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp index 05d6cc1..f113d74 100644 --- a/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp +++ b/src/remoteobjects/qremoteobjectabstractitemmodelreplica.cpp @@ -139,25 +139,20 @@ inline void removeIndexFromRow(const QModelIndex &index, const QVector<int> &rol } } -struct OnConnectHandler +void QAbstractItemModelReplicaPrivate::onReplicaCurrentChanged(const QModelIndex ¤t, const QModelIndex &previous) { - OnConnectHandler(QAbstractItemModelReplicaPrivate *rep) : m_rep(rep){} - void operator()(const QModelIndex ¤t, const QModelIndex &/*previous*/) - { - IndexList currentIndex = toModelIndexList(current, m_rep->q); - qCDebug(QT_REMOTEOBJECT_MODELS) << Q_FUNC_INFO << "current=" << currentIndex; - m_rep->replicaSetCurrentIndex(currentIndex, QItemSelectionModel::Clear|QItemSelectionModel::Select|QItemSelectionModel::Current); - } - - QAbstractItemModelReplicaPrivate *m_rep; -}; + Q_UNUSED(previous) + IndexList currentIndex = toModelIndexList(current, q); + qCDebug(QT_REMOTEOBJECT_MODELS) << Q_FUNC_INFO << "current=" << currentIndex; + replicaSetCurrentIndex(currentIndex, QItemSelectionModel::Clear|QItemSelectionModel::Select|QItemSelectionModel::Current); +} void QAbstractItemModelReplicaPrivate::setModel(QAbstractItemModelReplica *model) { q = model; setParent(model); m_selectionModel.reset(new QItemSelectionModel(model)); - connect(m_selectionModel.data(), &QItemSelectionModel::currentChanged, this, OnConnectHandler(this)); + connect(m_selectionModel.data(), &QItemSelectionModel::currentChanged, this, &QAbstractItemModelReplicaPrivate::onReplicaCurrentChanged); } bool QAbstractItemModelReplicaPrivate::clearCache(const IndexList &start, const IndexList &end, const QVector<int> &roles = QVector<int>()) @@ -294,8 +289,14 @@ void QAbstractItemModelReplicaPrivate::onCurrentChanged(IndexList current, Index qCDebug(QT_REMOTEOBJECT_MODELS) << Q_FUNC_INFO << "current=" << current << "previous=" << previous; Q_UNUSED(previous); Q_ASSERT(m_selectionModel); - const QModelIndex currentIndex = toQModelIndex(current, q); - m_selectionModel->setCurrentIndex(currentIndex, QItemSelectionModel::Clear|QItemSelectionModel::Select|QItemSelectionModel::Current); + bool ok; + // If we have several tree models sharing a selection model, we + // can't guarantee that all Replicas have the selected cell + // available. + const QModelIndex currentIndex = toQModelIndex(current, q, &ok); + // Ignore selection if we can't find the desired cell. + if (ok) + m_selectionModel->setCurrentIndex(currentIndex, QItemSelectionModel::Clear|QItemSelectionModel::Select|QItemSelectionModel::Current); } void QAbstractItemModelReplicaPrivate::handleInitDone(QRemoteObjectPendingCallWatcher *watcher) |