summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2011-08-29 06:35:23 (GMT)
committerBea Lam <bea.lam@nokia.com>2011-08-29 06:35:23 (GMT)
commitb64817858484db6e7c280d41ed81d4c87dff2275 (patch)
treeb8bab6fd67f083e37dad4e459aca3bd79071953d /tests/auto/declarative
parentc1491c356f3cca92a359468ce37f38bc1873eec4 (diff)
downloadQt-b64817858484db6e7c280d41ed81d4c87dff2275.zip
Qt-b64817858484db6e7c280d41ed81d4c87dff2275.tar.gz
Qt-b64817858484db6e7c280d41ed81d4c87dff2275.tar.bz2
Fix conversion of QAbstractItemModel::rowsMoved() parameters
VisualDataModel was emitting itemsMoved() signal with incorrect "to" value when multiple items were moved forwards. Reviewed-by: Martin Jones
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp79
1 files changed, 76 insertions, 3 deletions
diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
index 39c3a94..ec22768 100644
--- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
+++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
@@ -38,6 +38,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include "../../../shared/util.h"
#include <qtest.h>
#include <QtTest/QSignalSpy>
#include <QStandardItemModel>
@@ -87,6 +88,13 @@ public:
list << "one" << "two" << "three" << "four";
}
+ void emitMove(int sourceFirst, int sourceLast, int destinationChild) {
+ emit beginMoveRows(QModelIndex(), sourceFirst, sourceLast, QModelIndex(), destinationChild);
+ emit endMoveRows();
+ }
+
+ QStringList list;
+
public slots:
void set(int idx, QString string) {
list[idx] = string;
@@ -102,9 +110,6 @@ protected:
return list.at(index.row());
return QVariant();
}
-
-private:
- QStringList list;
};
@@ -122,6 +127,8 @@ private slots:
void singleRole();
void modelProperties();
void noDelegate();
+ void qaimRowsMoved();
+ void qaimRowsMoved_data();
private:
QDeclarativeEngine engine;
@@ -501,6 +508,72 @@ void tst_qdeclarativevisualdatamodel::noDelegate()
}
+void tst_qdeclarativevisualdatamodel::qaimRowsMoved()
+{
+ // Test parameters passed in QAIM::rowsMoved() signal are converted correctly
+ // when translated and emitted as the QListModelInterface::itemsMoved() signal
+ QFETCH(int, sourceFirst);
+ QFETCH(int, sourceLast);
+ QFETCH(int, destinationChild);
+ QFETCH(int, expectFrom);
+ QFETCH(int, expectTo);
+ QFETCH(int, expectCount);
+
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/visualdatamodel.qml"));
+
+ SingleRoleModel model;
+ model.list.clear();
+ for (int i=0; i<30; i++)
+ model.list << ("item " + i);
+ engine.rootContext()->setContextProperty("myModel", &model);
+
+ QDeclarativeVisualDataModel *obj = qobject_cast<QDeclarativeVisualDataModel*>(c.create());
+ QVERIFY(obj != 0);
+
+ QSignalSpy spy(obj, SIGNAL(itemsMoved(int,int,int)));
+ model.emitMove(sourceFirst, sourceLast, destinationChild);
+ QTRY_COMPARE(spy.count(), 1);
+
+ QCOMPARE(spy[0].count(), 3);
+ QCOMPARE(spy[0][0].toInt(), expectFrom);
+ QCOMPARE(spy[0][1].toInt(), expectTo);
+ QCOMPARE(spy[0][2].toInt(), expectCount);
+
+ delete obj;
+}
+
+void tst_qdeclarativevisualdatamodel::qaimRowsMoved_data()
+{
+ QTest::addColumn<int>("sourceFirst");
+ QTest::addColumn<int>("sourceLast");
+ QTest::addColumn<int>("destinationChild");
+ QTest::addColumn<int>("expectFrom");
+ QTest::addColumn<int>("expectTo");
+ QTest::addColumn<int>("expectCount");
+
+ QTest::newRow("move 1 forward")
+ << 1 << 1 << 6
+ << 1 << 5 << 1;
+
+ QTest::newRow("move 1 backwards")
+ << 4 << 4 << 1
+ << 4 << 1 << 1;
+
+ QTest::newRow("move multiple forwards")
+ << 0 << 2 << 13
+ << 0 << 10 << 3;
+
+ QTest::newRow("move multiple forwards, with same to")
+ << 0 << 1 << 3
+ << 0 << 1 << 2;
+
+ QTest::newRow("move multiple backwards")
+ << 10 << 14 << 1
+ << 10 << 1 << 5;
+}
+
+
template<typename T>
T *tst_qdeclarativevisualdatamodel::findItem(QGraphicsObject *parent, const QString &objectName, int index)
{