summaryrefslogtreecommitdiff
path: root/tests/auto/qquicktreemodeladaptor
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>2015-07-21 17:07:14 +0200
committerMitch Curtis <mitch.curtis@theqtcompany.com>2015-07-27 10:39:44 +0000
commit09d9ce27ab9ac29aaa36c6d54fe89064dfcde69f (patch)
treefb03cccd2afc67155362d7d6980a89b4633efff2 /tests/auto/qquicktreemodeladaptor
parentdd9f2665b1f84f0ba8ed21f5c47b532b2dc4db87 (diff)
downloadqtquickcontrols-09d9ce27ab9ac29aaa36c6d54fe89064dfcde69f.tar.gz
TreeView: Add rootIndex property
Its purpose is the same as QAbstractItemView::rootIndex and allows to display only the part of the model data that is descendant of this index. The filesystembrowser example has been updated to only show files reachable from the user's home directory. [ChangeLog][TreeView] Added rootIndex property Change-Id: Ib8d9af4ce9d1f341ab509de3cc991773830ba9f4 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'tests/auto/qquicktreemodeladaptor')
-rw-r--r--tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp47
1 files changed, 42 insertions, 5 deletions
diff --git a/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp b/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp
index b484665d..13a92ea7 100644
--- a/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp
+++ b/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp
@@ -57,6 +57,8 @@ private slots:
void modelDestroyed();
void modelReset();
+ void rootIndex();
+
void dataAccess();
void dataChange();
void groupedDataChange();
@@ -96,9 +98,10 @@ void tst_QQuickTreeModelAdaptor::cleanup()
void tst_QQuickTreeModelAdaptor::compareData(int row, QQuickTreeModelAdaptor &tma, const QModelIndex &modelIdx, TestModel &model, bool expanded)
{
const QModelIndex &tmaIdx = tma.index(row);
+ const int indexDepth = model.level(modelIdx) - model.level(tma.rootIndex()) - 1;
QCOMPARE(tma.mapToModel(tmaIdx), modelIdx);
QCOMPARE(tma.data(tmaIdx, Qt::DisplayRole).toString(), model.displayData(modelIdx));
- QCOMPARE(tma.data(tmaIdx, QQuickTreeModelAdaptor::DepthRole).toInt(), model.level(modelIdx));
+ QCOMPARE(tma.data(tmaIdx, QQuickTreeModelAdaptor::DepthRole).toInt(), indexDepth);
QCOMPARE(tma.data(tmaIdx, QQuickTreeModelAdaptor::ExpandedRole).toBool(), expanded);
QCOMPARE(tma.data(tmaIdx, QQuickTreeModelAdaptor::HasChildrenRole).toBool(), model.hasChildren(modelIdx));
}
@@ -117,7 +120,7 @@ void tst_QQuickTreeModelAdaptor::expandAndTest(const QModelIndex &idx, QQuickTre
const QModelIndex &tmaIdx = tma.index(tma.itemIndex(idx));
QCOMPARE(tma.data(tmaIdx, QQuickTreeModelAdaptor::ExpandedRole).toBool(), expandable);
- if (expandable) {
+ if (expandable && expectedRowCountDifference != 0) {
// Rows were added below the parent
QCOMPARE(tma.rowCount(), oldRowCount + expectedRowCountDifference);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), rowsInsertedSpy.count());
@@ -160,7 +163,7 @@ void tst_QQuickTreeModelAdaptor::collapseAndTest(const QModelIndex &idx, QQuickT
if (tmaIdx.isValid())
QCOMPARE(tma.data(tmaIdx, QQuickTreeModelAdaptor::ExpandedRole).toBool(), false);
- if (expandable) {
+ if (expandable && expectedRowCountDifference != 0) {
// Rows were removed below the parent
QCOMPARE(tma.rowCount(), oldRowCount - expectedRowCountDifference);
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1);
@@ -188,9 +191,9 @@ void tst_QQuickTreeModelAdaptor::collapseAndTest(const QModelIndex &idx, QQuickT
void tst_QQuickTreeModelAdaptor::compareModels(QQuickTreeModelAdaptor &tma, TestModel &model)
{
- QModelIndex parent;
+ QModelIndex parent = tma.rootIndex();
QStack<QModelIndex> parents;
- QModelIndex idx = model.index(0, 0);
+ QModelIndex idx = model.index(0, 0, parent);
int modelVisibleRows = model.rowCount(parent);
for (int i = 0; i < tma.rowCount(); i++) {
bool expanded = tma.isExpanded(i);
@@ -283,6 +286,40 @@ void tst_QQuickTreeModelAdaptor::modelReset()
compareModels(tma, model);
}
+void tst_QQuickTreeModelAdaptor::rootIndex()
+{
+ TestModel model(5, 1);
+
+ QQuickTreeModelAdaptor tma;
+ tma.setModel(&model);
+
+ QVERIFY(!tma.rootIndex().isValid());
+ compareModels(tma, model);
+
+ QSignalSpy rootIndexSpy(&tma, SIGNAL(rootIndexChanged()));
+ QModelIndex rootIndex = model.index(0, 0);
+ tma.setRootIndex(rootIndex);
+ QCOMPARE(tma.rootIndex(), rootIndex);
+ QCOMPARE(rootIndexSpy.count(), 1);
+ compareModels(tma, model);
+
+ rootIndexSpy.clear();
+ rootIndex = model.index(2, 2, tma.rootIndex());
+ tma.setRootIndex(rootIndex);
+ QCOMPARE(tma.rootIndex(), rootIndex);
+ QCOMPARE(rootIndexSpy.count(), 1);
+ compareModels(tma, model);
+
+ // Expand 1st visible item, business as usual
+ expandAndTest(model.index(0, 0, rootIndex), tma, true /*expandable*/, 5);
+ // Expand non root item descendant item, nothing should happen
+ expandAndTest(model.index(0, 0), tma, true /*expandable*/, 0);
+ // Collapse 1st visible item, business as usual
+ collapseAndTest(model.index(0, 0, rootIndex), tma, true /*expandable*/, 5);
+ // Collapse non root item descendant item, nothing should happen
+ collapseAndTest(model.index(0, 0), tma, true /*expandable*/, 0);
+}
+
void tst_QQuickTreeModelAdaptor::dataAccess()
{
TestModel model(5, 1);