summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp51
-rw-r--r--tests/auto/shared/testmodel.h2
2 files changed, 52 insertions, 1 deletions
diff --git a/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp b/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp
index 13a92ea7..34c8f7cc 100644
--- a/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp
+++ b/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp
@@ -81,6 +81,7 @@ private slots:
void moveRows_data();
void moveRows();
+ void reparentOnSameRow();
void selectionForRowRange();
@@ -1160,6 +1161,56 @@ void tst_QQuickTreeModelAdaptor::moveRows()
compareModels(tma, model);
}
+void tst_QQuickTreeModelAdaptor::reparentOnSameRow()
+{
+ TestModel model(2, 1);
+ model.alternateChildlessRows = false;
+ QQuickTreeModelAdaptor tma;
+ tma.setModel(&model);
+
+ const QModelIndex &destParent = model.index(0, 0);
+ const QModelIndex &sourceParent = QModelIndex();
+ QVERIFY(destParent.isValid());
+ tma.expand(destParent);
+ QVERIFY(tma.isExpanded(destParent));
+
+ QSignalSpy dataChangedSpy(&tma, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
+ QSignalSpy rowsMovedSpy(&tma, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)));
+ QVERIFY(rowsMovedSpy.isValid());
+ QVERIFY(dataChangedSpy.isValid());
+
+ QVERIFY(model.moveRows(sourceParent, 1, 1, destParent, 2));
+
+ QModelIndex movedIndex = tma.index(3, 0, QModelIndex());
+ QVERIFY(movedIndex.isValid());
+ QCOMPARE(movedIndex.data(QQuickTreeModelAdaptor::DepthRole).toInt(), 1);
+ QCOMPARE(tma.data(movedIndex, QQuickTreeModelAdaptor::ModelIndexRole).toModelIndex(), model.index(2, 0, destParent));
+
+ // at least DepthRole and ModeIndexRole changes should have happened for the affected row
+ bool depthChanged = false;
+ bool modelIndexChanged = false;
+ QList<QList<QVariant> > &changes = dataChangedSpy;
+ foreach (QList<QVariant> change, changes) {
+ if (change.at(0) == movedIndex) {
+ if (change.at(2).value<QVector<int> >().contains(QQuickTreeModelAdaptor::DepthRole))
+ depthChanged = true;
+ if (change.at(2).value<QVector<int> >().contains(QQuickTreeModelAdaptor::ModelIndexRole))
+ modelIndexChanged = true;
+ }
+ }
+
+ QCOMPARE(depthChanged, true);
+ QCOMPARE(modelIndexChanged, true);
+
+ QCOMPARE(rowsMovedSpy.count(), 0);
+
+ model.moveRow(destParent, 2, QModelIndex(), 1);
+
+ QCOMPARE(rowsMovedSpy.count(), 0);
+ QVERIFY(tma.testConsistency());
+ compareModels(tma, model);
+}
+
void tst_QQuickTreeModelAdaptor::selectionForRowRange()
{
const int ModelRowCount = 9;
diff --git a/tests/auto/shared/testmodel.h b/tests/auto/shared/testmodel.h
index 00e74129..d1f49a4d 100644
--- a/tests/auto/shared/testmodel.h
+++ b/tests/auto/shared/testmodel.h
@@ -238,7 +238,7 @@ public:
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
{
Q_ASSERT_X(sourceRow >= 0 && sourceRow < rowCount(sourceParent)
- && count > 0 && sourceRow + count < rowCount(sourceParent)
+ && count > 0 && sourceRow + count - 1 < rowCount(sourceParent)
&& destinationChild >= 0 && destinationChild <= rowCount(destinationParent),
Q_FUNC_INFO, "Rows out of range.");
Q_ASSERT_X(!(sourceParent == destinationParent && destinationChild >= sourceRow && destinationChild < sourceRow + count),