diff options
author | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2015-01-15 19:19:26 +0100 |
---|---|---|
committer | Caroline Chao <caroline.chao@theqtcompany.com> | 2015-02-03 18:40:19 +0000 |
commit | 7ab29c4ebb5bfc66a544a966da0b49f0e739f08c (patch) | |
tree | ce8ff92cfe4ff87a416c10d07796dc1ccf8ee673 /tests/auto | |
parent | ae9d3f4c6c1a732788cd1f24c6a928cee16c3991 (diff) |
Allow exposing QItemSelectionModel to QML
This requires being able to create a QItemSelectionModel
without specifiying its model, and also setting the model
later. Also, several classes, like QPersistentModelIndex,
need to be declared as meta-type.
Finally, and in order to introduce the 'model' property,
we need to have a type compatible getter. Hence the new,
non-const model() function.
Where needed, meta-type declarations have been removed from
auto-tests.
[ChangeLog][QtCore][Item Models] QItemSelectionModel
can now be created without a model and have one set later.
Change-Id: If49bed061a5d1012331f335ca7f6e3959ecd3f1c
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'tests/auto')
3 files changed, 16 insertions, 4 deletions
diff --git a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp index b6a0cc923d..67be1b1e45 100644 --- a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp @@ -211,7 +211,6 @@ void tst_QAbstractProxyModel::mapFromSource() QCOMPARE(model.mapFromSource(sourceIndex), mapFromSource); } -Q_DECLARE_METATYPE(QItemSelection) void tst_QAbstractProxyModel::mapSelectionFromSource_data() { QTest::addColumn<QItemSelection>("selection"); diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index ef0ce77bbb..5a4d88d373 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -86,6 +86,7 @@ private slots: void deselectRemovedMiddleRange(); void rangeOperatorLessThan_data(); void rangeOperatorLessThan(); + void setModel(); void testDifferentModels(); @@ -107,8 +108,6 @@ typedef QList<int> IntList; typedef QPair<int, int> IntPair; typedef QList<IntPair> PairList; -Q_DECLARE_METATYPE(QItemSelection) - class QStreamHelper: public QAbstractItemModel { public: @@ -2561,6 +2560,21 @@ void tst_QItemSelectionModel::rangeOperatorLessThan() QVERIFY(r4 < r2); } +void tst_QItemSelectionModel::setModel() +{ + QItemSelectionModel sel; + QVERIFY(!sel.model()); + QSignalSpy modelChangedSpy(&sel, SIGNAL(modelChanged(QAbstractItemModel*))); + QStringListModel model(QStringList() << "Blah" << "Blah" << "Blah"); + sel.setModel(&model); + QCOMPARE(sel.model(), &model); + QCOMPARE(modelChangedSpy.count(), 1); + sel.select(model.index(0), QItemSelectionModel::Select); + QVERIFY(!sel.selection().isEmpty()); + sel.setModel(0); + QVERIFY(sel.selection().isEmpty()); +} + void tst_QItemSelectionModel::testDifferentModels() { QStandardItemModel model1; diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index 10b278c7f5..930367e580 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -1827,7 +1827,6 @@ void tst_QAbstractItemView::testFocusPolicy() QVERIFY(!qApp->focusWidget()); } -Q_DECLARE_METATYPE(QItemSelection) void tst_QAbstractItemView::QTBUG31411_noSelection() { QWidget window; |