2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "listviewwithpageheader.h"
19#include <QAbstractItemModel>
23#include <QSortFilterProxyModel>
25#include <private/qqmllistmodel_p.h>
26#include <private/qquickanimation_p.h>
27#include <private/qquickitem_p.h>
29class StringListModel : public QAbstractListModel
34 list << "A" << "B" << "C" << "D" << "E" << "F" << "G" << "H";
37 int rowCount(const QModelIndex &parent) const override
45 QVariant data(const QModelIndex &index, int role) const override
47 if (role == Qt::SizeHintRole) return 50;
48 else if (role == Qt::DisplayRole) return list[index.row()];
52 QHash<int, QByteArray> roleNames() const override
54 QHash<int, QByteArray> hash;
55 hash.insert(Qt::DisplayRole, "type");
56 hash.insert(Qt::SizeHintRole, "size");
60 void moveLastToFirst()
62 const int last = list.count() - 1;
63 beginMoveRows(QModelIndex(), last, last, QModelIndex(), 0);
71class ListViewWithPageHeaderTestSection : public QObject
76 void verifyItem(int visibleIndex, qreal pos, qreal height, bool culled, const QString §ionHeader, bool sectionHeaderCulled)
78 QTRY_VERIFY(visibleIndex < lvwph->m_visibleItems.count());
79 QTRY_COMPARE(lvwph->m_visibleItems[visibleIndex]->y(), pos);
80 QTRY_COMPARE(lvwph->m_visibleItems[visibleIndex]->height(), height);
81 QCOMPARE(QQuickItemPrivate::get(lvwph->m_visibleItems[visibleIndex]->m_item)->culled, culled);
82 QCOMPARE(section(lvwph->m_visibleItems[visibleIndex]->sectionItem()), sectionHeader);
83 if (!sectionHeader.isNull()) {
84 QCOMPARE(QQuickItemPrivate::get(lvwph->m_visibleItems[visibleIndex]->sectionItem())->culled, sectionHeaderCulled);
85 QCOMPARE(sectionDelegate(lvwph->m_visibleItems[visibleIndex]->sectionItem()), lvwph->m_visibleItems[visibleIndex]->m_item);
89 void changeContentY(qreal change)
91 const qreal dest = lvwph->contentY() + change;
92 if (dest > lvwph->contentY()) {
93 const qreal jump = 25;
94 while (lvwph->contentY() + jump < dest) {
95 lvwph->setContentY(lvwph->contentY() + jump);
99 const qreal jump = -25;
100 while (lvwph->contentY() + jump > dest) {
101 lvwph->setContentY(lvwph->contentY() + jump);
105 lvwph->setContentY(dest);
111 const qreal jump = -25;
112 while (!lvwph->isAtYBeginning()) {
113 if (lvwph->contentY() + jump > -lvwph->minYExtent()) {
114 lvwph->setContentY(lvwph->contentY() + jump);
116 lvwph->setContentY(lvwph->contentY() - 1);
122 void scrollToBottom()
124 const qreal jump = 25;
125 while (!lvwph->isAtYEnd()) {
126 if (lvwph->contentY() + lvwph->height() + jump < lvwph->contentHeight()) {
127 lvwph->setContentY(lvwph->contentY() + jump);
129 lvwph->setContentY(lvwph->contentY() + 1);
135 void verifyInitialTopPosition()
137 QTRY_COMPARE(lvwph->m_visibleItems.count(), 0);
138 QCOMPARE(lvwph->m_firstVisibleIndex, -1);
139 QCOMPARE(lvwph->m_minYExtent, 0.);
140 QCOMPARE(lvwph->m_clipItem->y(), 0.);
141 QCOMPARE(lvwph->m_clipItem->clip(), false);
142 QCOMPARE(lvwph->m_headerItem->y(), 0.);
143 QCOMPARE(lvwph->m_headerItem->height(), 50.);
144 QCOMPARE(lvwph->contentY(), 0.);
145 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
146 QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
149 QString section(QQuickItem *item)
151 return item ? item->property("text").toString() : QString();
154 QQuickItem *sectionDelegate(QQuickItem *item)
156 return item ? item->property("delegate").value<QQuickItem *>() : nullptr;
167 view = new QQuickView();
168 view->setSource(QUrl::fromLocalFile(DASHVIEWSTEST_FOLDER "/listviewwithpageheadertestsectionexternalmodel.qml"));
169 lvwph = static_cast<ListViewWithPageHeader*>(view->rootObject()->findChild<QQuickFlickable*>());
172 QTest::qWaitForWindowExposed(view);
174 verifyInitialTopPosition();
182 void testCreationDeletion()
184 // Nothing, init/cleanup already tests this
187 void testMoveWithProxy()
190 QSortFilterProxyModel proxy;
191 proxy.setSourceModel(&m);
193 lvwph->setModel(&proxy);
195 QTRY_COMPARE(lvwph->m_visibleItems.count(), 8);
196 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
197 verifyItem(0, 50., 90., false, "A", false);
198 verifyItem(1, 140., 90., false, "B", false);
199 verifyItem(2, 230., 90., false, "C", false);
200 verifyItem(3, 320., 90., false, "D", false);
201 verifyItem(4, 410., 90., false, "E", false);
202 verifyItem(5, 500., 90., false, "F", false);
203 verifyItem(6, 590., 90., true, "G", true);
204 verifyItem(7, 680., 90., true, "H", true);
205 QCOMPARE(lvwph->m_minYExtent, 0.);
206 QCOMPARE(lvwph->m_clipItem->y(), 0.);
207 QCOMPARE(lvwph->m_clipItem->clip(), false);
208 QCOMPARE(lvwph->m_headerItem->y(), 0.);
209 QCOMPARE(lvwph->m_headerItem->height(), 50.);
210 QCOMPARE(lvwph->contentY(), 0.);
211 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
212 QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
216 QTRY_COMPARE(lvwph->m_visibleItems.count(), 8);
217 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
218 verifyItem(0, 50., 90., false, "H", false);
219 verifyItem(1, 140., 90., false, "A", false);
220 verifyItem(2, 230., 90., false, "B", false);
221 verifyItem(3, 320., 90., false, "C", false);
222 verifyItem(4, 410., 90., false, "D", false);
223 verifyItem(5, 500., 90., false, "E", false);
224 verifyItem(6, 590., 90., true, "F", true);
225 verifyItem(7, 680., 90., true, "G", true);
226 QCOMPARE(lvwph->m_minYExtent, 0.);
227 QCOMPARE(lvwph->m_clipItem->y(), 0.);
228 QCOMPARE(lvwph->m_clipItem->clip(), false);
229 QCOMPARE(lvwph->m_headerItem->y(), 0.);
230 QCOMPARE(lvwph->m_headerItem->height(), 50.);
231 QCOMPARE(lvwph->contentY(), 0.);
232 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
233 QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
238 ListViewWithPageHeader *lvwph;
241QTEST_MAIN(ListViewWithPageHeaderTestSection)
243#include "listviewwithpageheadersectionexternalmodeltest.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list