summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <mbrasser@ford.com>2017-03-29 13:47:40 -0500
committerMichael Brasser <michael.brasser@live.com>2017-03-30 15:30:19 +0000
commit330e73ccf1c7b541c81eae9347260a7ef383843a (patch)
tree0a8867f7a9ac6536d4915ca3c4a09b0137536114
parent777b8bbb516bc744eb6837c8cc189886fc1e0add (diff)
Ensure selection model updates when changed at sourcev5.9.0-beta1
Change-Id: I37d037428107c7ab1666d6b181fb0c9e465c6348 Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
-rw-r--r--src/remoteobjects/qremoteobjectabstractitemmodeltypes.h2
-rw-r--r--tests/auto/modelview/tst_modelview.cpp43
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