diff options
-rw-r--r-- | src/remoteobjects/qremoteobjectabstractitemmodeltypes.h | 2 | ||||
-rw-r--r-- | tests/auto/modelview/tst_modelview.cpp | 43 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/remoteobjects/qremoteobjectabstractitemmodeltypes.h b/src/remoteobjects/qremoteobjectabstractitemmodeltypes.h index 42773a5..385fdd0 100644 --- a/src/remoteobjects/qremoteobjectabstractitemmodeltypes.h +++ b/src/remoteobjects/qremoteobjectabstractitemmodeltypes.h @@ -179,6 +179,8 @@ inline QString modelIndexToString(const ModelIndex &index) inline QModelIndex toQModelIndex(const IndexList &list, const QAbstractItemModel *model, bool *ok = nullptr, bool ensureItem = false) { + if (ok) + *ok = true; QModelIndex result; for (int i = 0; i < list.count(); ++i) { const ModelIndex &index = list[i]; diff --git a/tests/auto/modelview/tst_modelview.cpp b/tests/auto/modelview/tst_modelview.cpp index bdc1de0..dbcfcfd 100644 --- a/tests/auto/modelview/tst_modelview.cpp +++ b/tests/auto/modelview/tst_modelview.cpp @@ -622,6 +622,9 @@ private slots: void testModelTest(); void testSortFilterModel(); + void testSelectionFromReplica(); + void testSelectionFromSource(); + void cleanup(); }; @@ -1173,6 +1176,46 @@ void TestModelView::testSetDataTree() compareData(&m_sourceModel, model.data()); } +void TestModelView::testSelectionFromReplica() +{ + QVector<int> roles = QVector<int>() << Qt::DisplayRole << Qt::BackgroundRole; + QStandardItemModel simpleModel; + for (int i = 0; i < 4; ++i) + simpleModel.appendRow(new QStandardItem(QString("item %0").arg(i))); + QItemSelectionModel selectionModel(&simpleModel); + m_basicServer.enableRemoting(&simpleModel, "simpleModel", roles, &selectionModel); + + QScopedPointer<QAbstractItemModelReplica> model(m_client.acquireModel("simpleModel")); + QItemSelectionModel *replicaSelectionModel = model->selectionModel(); + + FetchData f(model.data()); + f.addAll(); + QVERIFY(f.fetchAndWait()); + + replicaSelectionModel->setCurrentIndex(model->index(1,0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current); + QTRY_COMPARE(selectionModel.currentIndex().row(), 1); +} + +void TestModelView::testSelectionFromSource() +{ + QVector<int> roles = QVector<int>() << Qt::DisplayRole << Qt::BackgroundRole; + QStandardItemModel simpleModel; + for (int i = 0; i < 4; ++i) + simpleModel.appendRow(new QStandardItem(QString("item %0").arg(i))); + QItemSelectionModel selectionModel(&simpleModel); + m_basicServer.enableRemoting(&simpleModel, "simpleModel", roles, &selectionModel); + + QScopedPointer<QAbstractItemModelReplica> model(m_client.acquireModel("simpleModel")); + QItemSelectionModel *replicaSelectionModel = model->selectionModel(); + + FetchData f(model.data()); + f.addAll(); + QVERIFY(f.fetchAndWait()); + + selectionModel.setCurrentIndex(simpleModel.index(1,0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current); + QTRY_COMPARE(replicaSelectionModel->currentIndex().row(), 1); +} + void TestModelView::cleanup() { // wait for delivery of RemoveObject events to the source |