diff options
Diffstat (limited to 'tests/auto/declarative/qdeclarativelistview')
4 files changed, 189 insertions, 2 deletions
diff --git a/tests/auto/declarative/qdeclarativelistview/incrementalmodel.cpp b/tests/auto/declarative/qdeclarativelistview/incrementalmodel.cpp new file mode 100644 index 0000000..b2c9df5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelistview/incrementalmodel.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "incrementalmodel.h" +#include <QApplication> +#include <QDebug> + +IncrementalModel::IncrementalModel(QObject *parent) + : QAbstractListModel(parent), count(0) +{ + for (int i = 0; i < 100; ++i) + list.append("Item " + QString::number(i)); +} + +int IncrementalModel::rowCount(const QModelIndex & /* parent */) const +{ + return count; +} + +QVariant IncrementalModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() >= list.size() || index.row() < 0) + return QVariant(); + + if (role == Qt::DisplayRole) + return list.at(index.row()); + return QVariant(); +} + +bool IncrementalModel::canFetchMore(const QModelIndex & /* index */) const +{ + if (count < list.size()) + return true; + else + return false; +} + +void IncrementalModel::fetchMore(const QModelIndex & /* index */) +{ + int remainder = list.size() - count; + int itemsToFetch = qMin(5, remainder); + + beginInsertRows(QModelIndex(), count, count+itemsToFetch-1); + + count += itemsToFetch; + + endInsertRows(); +} diff --git a/tests/auto/declarative/qdeclarativelistview/incrementalmodel.h b/tests/auto/declarative/qdeclarativelistview/incrementalmodel.h new file mode 100644 index 0000000..b1f7407 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelistview/incrementalmodel.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IncrementalModel_H +#define IncrementalModel_H + +#include <QAbstractListModel> +#include <QList> +#include <QStringList> + +class IncrementalModel : public QAbstractListModel +{ + Q_OBJECT + +public: + IncrementalModel(QObject *parent = 0); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + +protected: + bool canFetchMore(const QModelIndex &parent) const; + void fetchMore(const QModelIndex &parent); + +private: + QStringList list; + int count; +}; + +#endif diff --git a/tests/auto/declarative/qdeclarativelistview/qdeclarativelistview.pro b/tests/auto/declarative/qdeclarativelistview/qdeclarativelistview.pro index 468474a..1633ffc 100644 --- a/tests/auto/declarative/qdeclarativelistview/qdeclarativelistview.pro +++ b/tests/auto/declarative/qdeclarativelistview/qdeclarativelistview.pro @@ -2,7 +2,8 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative macx:CONFIG -= app_bundle -SOURCES += tst_qdeclarativelistview.cpp +HEADERS += incrementalmodel.h +SOURCES += tst_qdeclarativelistview.cpp incrementalmodel.cpp symbian: { importFiles.files = data diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 3df10a9..e76cb15 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -51,6 +51,7 @@ #include <QtDeclarative/private/qdeclarativelistmodel_p.h> #include <QtDeclarative/private/qlistmodelinterface_p.h> #include "../../../shared/util.h" +#include "incrementalmodel.h" #ifdef Q_OS_SYMBIAN // In Symbian OS test data is located in applications private dir @@ -106,6 +107,7 @@ private slots: void resizeDelegate(); void QTBUG_16037(); void indexAt(); + void incrementalModel(); private: template <class T> void items(); @@ -667,7 +669,8 @@ void tst_QDeclarativeListView::removed(bool animated) listview->setContentY(80); QTest::qWait(300); - model.removeItems(1, 17); + // remove all visible items + model.removeItems(1, 18); QTest::qWait(300); // Confirm items positioned correctly @@ -1997,6 +2000,32 @@ void tst_QDeclarativeListView::indexAt() delete canvas; } +void tst_QDeclarativeListView::incrementalModel() +{ + QDeclarativeView *canvas = createView(); + + IncrementalModel model; + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/displaylist.qml")); + qApp->processEvents(); + + QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); + QTRY_VERIFY(listview != 0); + + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + QTRY_COMPARE(listview->count(), 20); + + listview->positionViewAtIndex(10, QDeclarativeListView::Beginning); + + QTRY_COMPARE(listview->count(), 25); + + delete canvas; +} + void tst_QDeclarativeListView::qListModelInterface_items() { items<TestModel>(); |