|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Container for pan (drag) gesture -related data and logic. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 #include <QMetaType> |
|
20 #include <QModelIndex> |
|
21 #include "hbautotest.h" |
|
22 #include <hbapplication.h> |
|
23 #include <hbmainwindow.h> |
|
24 #include <hbscrollbar> |
|
25 #include <hgwidgets/hgwidgets.h> |
|
26 #include <hgwidgets/hggrid.h> |
|
27 #include <hgwidgets/hgmediawall.h> |
|
28 |
|
29 Q_DECLARE_METATYPE(QItemSelection) |
|
30 Q_DECLARE_METATYPE(QModelIndex) |
|
31 |
|
32 static const QPointF grid_portrait_pos0(70, 30); |
|
33 static const QPointF grid_portrait_pos1(180, 30); |
|
34 static const QPointF grid_portrait_pos2(280, 30); |
|
35 static const QPointF grid_portrait_pos3(70, 120); |
|
36 static const QPointF grid_portrait_pos4(180, 120); |
|
37 static const QPointF grid_portrait_pos5(280, 120); |
|
38 static const QPointF grid_portrait_pos6(70, 200); |
|
39 static const QPointF grid_portrait_pos7(180, 200); |
|
40 static const QPointF grid_portrait_pos8(280, 200); |
|
41 |
|
42 class TestGanesWidgets : public QObject |
|
43 { |
|
44 Q_OBJECT |
|
45 |
|
46 public: |
|
47 |
|
48 TestGanesWidgets(); |
|
49 virtual ~TestGanesWidgets(); |
|
50 |
|
51 private slots: |
|
52 void initTestCase(); |
|
53 void cleanupTestCase(); |
|
54 void init(); |
|
55 void cleanup(); |
|
56 |
|
57 private slots: |
|
58 void test_panGridLandscape(); |
|
59 void test_panGridPortrait(); |
|
60 void test_panCoverFlowLandscape(); |
|
61 void test_panCoverFlowPortrait(); |
|
62 void test_scrollbarGridLandscape(); |
|
63 void test_scrollbarGridPortrait(); |
|
64 void test_scrollbarCoverFlowLandscape(); |
|
65 void test_scrollbarCoverFlowPortrait(); |
|
66 void test_addRemoveItemsGrid(); |
|
67 void test_addRemoveItemsCoverflow(); |
|
68 void test_updateData(); |
|
69 void test_tap(); |
|
70 void test_currentItemCoverflow(); |
|
71 void test_currentItemGrid(); |
|
72 void test_selectionMode(); |
|
73 void test_selectionModel(); |
|
74 void test_scrollTo(); |
|
75 void test_addItemsCoverFlow(); |
|
76 void test_removeItemsCoverFlow(); |
|
77 void test_moveItemsCoverFlow(); |
|
78 |
|
79 private: |
|
80 |
|
81 void pan( Qt::Orientation, TBool begin ); |
|
82 |
|
83 private: |
|
84 |
|
85 HbMainWindow* mWindow; |
|
86 HgWidget* mWidget; |
|
87 |
|
88 }; |
|
89 |
|
90 class TestModel : public QAbstractListModel |
|
91 { |
|
92 Q_OBJECT |
|
93 |
|
94 public: |
|
95 |
|
96 explicit TestModel(QList<QModelIndex> *requestedIndexes = 0); |
|
97 virtual ~TestModel(); |
|
98 |
|
99 int rowCount(const QModelIndex &parent=QModelIndex()) const; |
|
100 QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const; |
|
101 |
|
102 void generateItems(int count); |
|
103 void appendItem(); |
|
104 void insertItems(int index, int count=1); |
|
105 void removeItems(int index, int count=1); |
|
106 void moveItems(int from, int to, int count=1); |
|
107 void changeItem(int index); |
|
108 void reset(); |
|
109 |
|
110 QImage mImage; |
|
111 QStringList mItems; |
|
112 bool mValidData; |
|
113 |
|
114 QList<QModelIndex> *mRequestedIndexes; |
|
115 }; |
|
116 |
|
117 TestModel::TestModel(QList<QModelIndex> *requestedIndexes) : |
|
118 mValidData(true), |
|
119 mRequestedIndexes(requestedIndexes) |
|
120 { |
|
121 mImage = QImage(":icons/startupHG.jpg"); |
|
122 } |
|
123 |
|
124 TestModel::~TestModel() |
|
125 { |
|
126 |
|
127 } |
|
128 |
|
129 void TestModel::generateItems(int count) |
|
130 { |
|
131 for (int i=0; i<count; i++) { |
|
132 mItems.append(QString("Item %0").arg(i)); |
|
133 } |
|
134 } |
|
135 |
|
136 void TestModel::appendItem() |
|
137 { |
|
138 insertItems(mItems.count(),1); |
|
139 } |
|
140 |
|
141 void TestModel::insertItems(int index, int count) |
|
142 { |
|
143 beginInsertRows(QModelIndex(), index, index+count-1); // Inclusive |
|
144 int end = index+count; |
|
145 for ( ;index<end; index++) { |
|
146 mItems.insert(index, QString("Item %0").arg(mItems.count())); |
|
147 } |
|
148 endInsertRows(); |
|
149 } |
|
150 |
|
151 void TestModel::removeItems(int index, int count) |
|
152 { |
|
153 if (index >= 0 && index < mItems.count()) { |
|
154 beginRemoveRows(QModelIndex(), index, index+count-1); // Inclusive |
|
155 int end = index+count; |
|
156 for (; index<end; index++) { |
|
157 mItems.removeAt(index); |
|
158 } |
|
159 endRemoveRows(); |
|
160 } |
|
161 } |
|
162 |
|
163 void TestModel::moveItems(int from, int to, int count) |
|
164 { |
|
165 if (beginMoveRows(QModelIndex(), from, from+count-1, QModelIndex(), to)) { // Inclusive |
|
166 // No need to actually move rows here |
|
167 endMoveRows(); |
|
168 } |
|
169 else { |
|
170 qDebug() << "Cannot move" << from << "-" << from+count-1 << "to" << to; |
|
171 } |
|
172 } |
|
173 |
|
174 void TestModel::reset() |
|
175 { |
|
176 beginResetModel(); |
|
177 mItems.clear(); |
|
178 endResetModel(); |
|
179 } |
|
180 |
|
181 |
|
182 void TestModel::changeItem(int index) |
|
183 { |
|
184 if ( index >= 0 && index < mItems.count() ) { |
|
185 QModelIndex modelIndex = QAbstractItemModel::createIndex(index, 0); |
|
186 emit dataChanged(modelIndex, modelIndex); |
|
187 } |
|
188 } |
|
189 |
|
190 int TestModel::rowCount(const QModelIndex &parent) const |
|
191 { |
|
192 return mItems.count(); |
|
193 } |
|
194 |
|
195 QVariant TestModel::data(const QModelIndex &index, int role) const |
|
196 { |
|
197 QVariant returnValue; |
|
198 |
|
199 if( !mValidData) |
|
200 return returnValue; |
|
201 |
|
202 int row = index.row(); |
|
203 |
|
204 switch ( role ) |
|
205 { |
|
206 case Qt::DisplayRole: |
|
207 { |
|
208 QStringList texts; |
|
209 QString text("Primary %0"); |
|
210 text.arg(row); |
|
211 texts << text; |
|
212 text = "Secondary %0"; |
|
213 text.arg(row); |
|
214 texts << text; |
|
215 returnValue = texts; |
|
216 break; |
|
217 } |
|
218 case Qt::DecorationRole: |
|
219 { |
|
220 returnValue = mImage; |
|
221 if (mRequestedIndexes && !mRequestedIndexes->contains(index)) { |
|
222 mRequestedIndexes->append(index); |
|
223 qSort(*mRequestedIndexes); |
|
224 } |
|
225 break; |
|
226 } |
|
227 default: |
|
228 break; |
|
229 |
|
230 } |
|
231 |
|
232 return returnValue; |
|
233 } |
|
234 |
|
235 |
|
236 TestGanesWidgets::TestGanesWidgets() |
|
237 { |
|
238 } |
|
239 |
|
240 TestGanesWidgets::~TestGanesWidgets() |
|
241 { |
|
242 |
|
243 } |
|
244 |
|
245 void TestGanesWidgets::initTestCase() |
|
246 { |
|
247 |
|
248 } |
|
249 |
|
250 void TestGanesWidgets::cleanupTestCase() |
|
251 { |
|
252 |
|
253 } |
|
254 |
|
255 void TestGanesWidgets::init() |
|
256 { |
|
257 |
|
258 } |
|
259 |
|
260 void TestGanesWidgets::cleanup() |
|
261 { |
|
262 |
|
263 } |
|
264 |
|
265 void TestGanesWidgets::pan( Qt::Orientation orientation, TBool begin ) |
|
266 { |
|
267 QPointF start(100,100); |
|
268 QPointF move; |
|
269 QPointF end; |
|
270 if (orientation==Qt::Horizontal){ |
|
271 move = QPointF(100,0); |
|
272 } |
|
273 else { |
|
274 move = QPointF(0,100); |
|
275 } |
|
276 |
|
277 if( begin ) |
|
278 end = start - move; |
|
279 else |
|
280 end = start + move; |
|
281 |
|
282 HbAutoTest::mousePress( (HbAutoTestMainWindow*)mWindow, mWidget, start, -1 ); |
|
283 HbAutoTest::mouseMove( (HbAutoTestMainWindow*)mWindow, mWidget, end, -1 ); |
|
284 HbAutoTest::mouseRelease( (HbAutoTestMainWindow*)mWindow, mWidget, end, 100 ); |
|
285 } |
|
286 |
|
287 void TestGanesWidgets::test_panGridLandscape() |
|
288 { |
|
289 mWindow = new HbMainWindow; |
|
290 mWidget = new HgGrid(Qt::Horizontal); |
|
291 TestModel model; |
|
292 model.generateItems(30); |
|
293 mWindow->addView( mWidget ); |
|
294 QVERIFY( mWidget->model() == 0 ); |
|
295 mWidget->setModel( &model ); |
|
296 QVERIFY( &model == mWidget->model() ); |
|
297 |
|
298 mWindow->show(); |
|
299 |
|
300 QTest::qWait( 2000 ); |
|
301 |
|
302 pan( Qt::Horizontal, true ); |
|
303 |
|
304 model.reset(); |
|
305 model.generateItems(5); |
|
306 |
|
307 QTest::qWait( 2000 ); |
|
308 |
|
309 pan( Qt::Horizontal, false ); |
|
310 |
|
311 model.reset(); |
|
312 |
|
313 QTest::qWait( 2000 ); |
|
314 |
|
315 pan( Qt::Horizontal, true ); |
|
316 |
|
317 QTest::qWait(4000); |
|
318 |
|
319 delete mWindow; |
|
320 mWindow = 0; |
|
321 } |
|
322 |
|
323 void TestGanesWidgets::test_panGridPortrait() |
|
324 { |
|
325 mWindow = new HbMainWindow; |
|
326 mWidget = new HgGrid(Qt::Vertical ); |
|
327 TestModel model; |
|
328 model.generateItems(30); |
|
329 mWindow->addView( mWidget ); |
|
330 QVERIFY( mWidget->model() == 0 ); |
|
331 mWidget->setModel( &model ); |
|
332 QVERIFY( &model == mWidget->model() ); |
|
333 mWindow->show(); |
|
334 |
|
335 QTest::qWait( 2000 ); |
|
336 |
|
337 pan( Qt::Vertical, true ); |
|
338 |
|
339 model.reset(); |
|
340 model.generateItems(5); |
|
341 |
|
342 QTest::qWait( 2000 ); |
|
343 |
|
344 pan( Qt::Vertical, false ); |
|
345 |
|
346 model.reset(); |
|
347 |
|
348 QTest::qWait( 2000 ); |
|
349 |
|
350 pan( Qt::Vertical, true ); |
|
351 |
|
352 QTest::qWait(4000); |
|
353 |
|
354 delete mWindow; |
|
355 mWindow = 0; |
|
356 } |
|
357 |
|
358 void TestGanesWidgets::test_panCoverFlowLandscape() |
|
359 { |
|
360 mWindow = new HbMainWindow; |
|
361 mWidget = new HgMediawall(); |
|
362 TestModel model; |
|
363 model.generateItems(30); |
|
364 mWindow->addView( mWidget ); |
|
365 QVERIFY( mWidget->model() == 0 ); |
|
366 mWidget->setModel( &model ); |
|
367 QVERIFY( &model == mWidget->model() ); |
|
368 mWindow->show(); |
|
369 |
|
370 QTest::qWait( 2000 ); |
|
371 |
|
372 pan( Qt::Horizontal, true ); |
|
373 |
|
374 model.reset(); |
|
375 model.generateItems(5); |
|
376 |
|
377 QTest::qWait( 2000 ); |
|
378 |
|
379 pan( Qt::Horizontal, false ); |
|
380 |
|
381 model.reset(); |
|
382 |
|
383 QTest::qWait( 2000 ); |
|
384 |
|
385 pan( Qt::Horizontal, true ); |
|
386 |
|
387 QTest::qWait(4000); |
|
388 |
|
389 delete mWindow; |
|
390 mWindow = 0; |
|
391 } |
|
392 |
|
393 void TestGanesWidgets::test_panCoverFlowPortrait() |
|
394 { |
|
395 mWindow = new HbMainWindow; |
|
396 mWidget = new HgMediawall(); |
|
397 TestModel model; |
|
398 model.generateItems(30); |
|
399 mWindow->addView( mWidget ); |
|
400 QVERIFY( mWidget->model() == 0 ); |
|
401 mWidget->setModel( &model ); |
|
402 QVERIFY( &model == mWidget->model() ); |
|
403 mWindow->show(); |
|
404 |
|
405 QTest::qWait( 2000 ); |
|
406 |
|
407 pan( Qt::Vertical, true ); |
|
408 |
|
409 model.reset(); |
|
410 model.generateItems(5); |
|
411 |
|
412 QTest::qWait( 2000 ); |
|
413 |
|
414 pan( Qt::Vertical, false ); |
|
415 |
|
416 model.reset(); |
|
417 |
|
418 QTest::qWait( 2000 ); |
|
419 |
|
420 pan( Qt::Vertical, true ); |
|
421 |
|
422 QTest::qWait(4000); |
|
423 |
|
424 delete mWindow; |
|
425 mWindow = 0; |
|
426 } |
|
427 |
|
428 void TestGanesWidgets::test_scrollbarGridLandscape() |
|
429 { |
|
430 mWindow = new HbMainWindow; |
|
431 mWidget = new HgMediawall(); |
|
432 TestModel model; |
|
433 model.generateItems(200); |
|
434 mWindow->addView( mWidget ); |
|
435 mWidget->setModel( &model ); |
|
436 mWindow->show(); |
|
437 |
|
438 QTest::qWait( 2000 ); |
|
439 |
|
440 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAutoHide); |
|
441 |
|
442 mWidget->setScrollBarPolicy(HgWidget::ScrollBarAlwaysOn); |
|
443 mWidget->scrollBar()->setInteractive(true); |
|
444 QRectF rect = mWidget->scrollBar()->rect(); |
|
445 |
|
446 QTest::qWait(1000); |
|
447 |
|
448 QPointF move( 20,0 ); |
|
449 |
|
450 HbAutoTest::mousePress( (HbAutoTestMainWindow*)mWindow, mWidget->scrollBar(), rect.topLeft()+move, -1 ); |
|
451 HbAutoTest::mouseMove( (HbAutoTestMainWindow*)mWindow, mWidget->scrollBar(), rect.topRight()-move, 50 ); |
|
452 HbAutoTest::mouseRelease( (HbAutoTestMainWindow*)mWindow, mWidget->scrollBar(), rect.topRight()-move, 100 ); |
|
453 |
|
454 QTest::qWait(3000); |
|
455 |
|
456 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOn ); |
|
457 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAlwaysOn); |
|
458 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOff ); |
|
459 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAlwaysOff); |
|
460 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAutoHide ); |
|
461 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAutoHide); |
|
462 |
|
463 QVERIFY(mWidget->scrollBar() != 0); |
|
464 HbScrollBar* scrollBar = new HbScrollBar(); |
|
465 mWidget->setScrollBar(scrollBar); |
|
466 QVERIFY(mWidget->scrollBar()==scrollBar); |
|
467 mWidget->setScrollBar(0); |
|
468 QVERIFY(mWidget->scrollBar()!= 0); |
|
469 |
|
470 QTest::qWait(2000); |
|
471 |
|
472 delete mWindow; |
|
473 mWindow = 0; |
|
474 |
|
475 } |
|
476 |
|
477 void TestGanesWidgets::test_scrollbarGridPortrait() |
|
478 { |
|
479 mWindow = new HbMainWindow; |
|
480 mWidget = new HgMediawall(); |
|
481 TestModel model; |
|
482 model.generateItems(200); |
|
483 mWindow->addView( mWidget ); |
|
484 mWidget->setModel( &model ); |
|
485 mWindow->show(); |
|
486 |
|
487 QTest::qWait( 2000 ); |
|
488 |
|
489 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAutoHide); |
|
490 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOn ); |
|
491 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAlwaysOn); |
|
492 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOff ); |
|
493 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAlwaysOff); |
|
494 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAutoHide ); |
|
495 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAutoHide); |
|
496 |
|
497 QVERIFY(mWidget->scrollBar() != 0); |
|
498 HbScrollBar* scrollBar = new HbScrollBar(); |
|
499 mWidget->setScrollBar(scrollBar); |
|
500 QVERIFY(mWidget->scrollBar()==scrollBar); |
|
501 mWidget->setScrollBar(0); |
|
502 QVERIFY(mWidget->scrollBar()!= 0); |
|
503 |
|
504 QTest::qWait(2000); |
|
505 |
|
506 delete mWindow; |
|
507 mWindow = 0; |
|
508 |
|
509 } |
|
510 |
|
511 void TestGanesWidgets::test_scrollbarCoverFlowLandscape() |
|
512 { |
|
513 mWindow = new HbMainWindow; |
|
514 mWidget = new HgMediawall(); |
|
515 TestModel model; |
|
516 model.generateItems(200); |
|
517 mWindow->addView( mWidget ); |
|
518 mWidget->setModel( &model ); |
|
519 mWindow->show(); |
|
520 |
|
521 QTest::qWait( 2000 ); |
|
522 |
|
523 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAutoHide); |
|
524 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOn ); |
|
525 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAlwaysOn); |
|
526 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOff ); |
|
527 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAlwaysOff); |
|
528 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAutoHide ); |
|
529 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAutoHide); |
|
530 |
|
531 QVERIFY(mWidget->scrollBar() != 0); |
|
532 HbScrollBar* scrollBar = new HbScrollBar(); |
|
533 mWidget->setScrollBar(scrollBar); |
|
534 QVERIFY(mWidget->scrollBar()==scrollBar); |
|
535 mWidget->setScrollBar(0); |
|
536 QVERIFY(mWidget->scrollBar()!= 0); |
|
537 |
|
538 QTest::qWait(2000); |
|
539 |
|
540 delete mWindow; |
|
541 mWindow = 0; |
|
542 |
|
543 } |
|
544 |
|
545 void TestGanesWidgets::test_scrollbarCoverFlowPortrait() |
|
546 { |
|
547 mWindow = new HbMainWindow; |
|
548 mWidget = new HgMediawall(); |
|
549 TestModel model; |
|
550 model.generateItems(200); |
|
551 mWindow->addView( mWidget ); |
|
552 mWidget->setModel( &model ); |
|
553 mWindow->show(); |
|
554 |
|
555 QTest::qWait( 2000 ); |
|
556 |
|
557 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAutoHide); |
|
558 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOn ); |
|
559 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAlwaysOn); |
|
560 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAlwaysOff ); |
|
561 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAlwaysOff); |
|
562 mWidget->setScrollBarPolicy( HgWidget::ScrollBarAutoHide ); |
|
563 QVERIFY(mWidget->scrollBarPolicy() == HgWidget::ScrollBarAutoHide); |
|
564 |
|
565 QVERIFY(mWidget->scrollBar() != 0); |
|
566 HbScrollBar* scrollBar = new HbScrollBar(); |
|
567 mWidget->setScrollBar(scrollBar); |
|
568 QVERIFY(mWidget->scrollBar()==scrollBar); |
|
569 mWidget->setScrollBar(0); |
|
570 QVERIFY(mWidget->scrollBar()!= 0); |
|
571 |
|
572 QTest::qWait(2000); |
|
573 |
|
574 delete mWindow; |
|
575 mWindow = 0; |
|
576 |
|
577 } |
|
578 |
|
579 void TestGanesWidgets::test_addRemoveItemsGrid() |
|
580 { |
|
581 mWindow = new HbMainWindow; |
|
582 mWidget = new HgMediawall(); |
|
583 TestModel model; |
|
584 model.generateItems(2); |
|
585 mWindow->addView( mWidget ); |
|
586 mWidget->setModel( &model ); |
|
587 mWindow->show(); |
|
588 |
|
589 QTest::qWait( 2000 ); |
|
590 |
|
591 model.appendItem(); |
|
592 model.appendItem(); |
|
593 model.removeItems(0); |
|
594 model.removeItems(3); |
|
595 model.removeItems(0); |
|
596 model.removeItems(0); |
|
597 |
|
598 QTest::qWait(2000); |
|
599 |
|
600 delete mWindow; |
|
601 mWindow = 0; |
|
602 } |
|
603 |
|
604 void TestGanesWidgets::test_addRemoveItemsCoverflow() |
|
605 { |
|
606 mWindow = new HbMainWindow; |
|
607 mWidget = new HgMediawall(); |
|
608 TestModel model; |
|
609 model.generateItems(2); |
|
610 mWindow->addView( mWidget ); |
|
611 mWidget->setModel( &model ); |
|
612 mWindow->show(); |
|
613 |
|
614 QTest::qWait( 2000 ); |
|
615 |
|
616 model.appendItem(); |
|
617 model.appendItem(); |
|
618 model.removeItems(0); |
|
619 model.removeItems(3); |
|
620 model.removeItems(0); |
|
621 model.removeItems(0); |
|
622 |
|
623 QTest::qWait(2000); |
|
624 |
|
625 delete mWindow; |
|
626 mWindow = 0; |
|
627 } |
|
628 |
|
629 void TestGanesWidgets::test_tap() |
|
630 { |
|
631 mWindow = new HbMainWindow; |
|
632 mWidget = new HgMediawall(); |
|
633 TestModel model; |
|
634 model.generateItems(50); |
|
635 mWindow->addView( mWidget ); |
|
636 mWidget->setModel( &model ); |
|
637 mWindow->show(); |
|
638 |
|
639 QTest::qWait( 2000 ); |
|
640 |
|
641 QSignalSpy stateSpy( mWidget, SIGNAL( activated(QModelIndex) ) ); |
|
642 QSignalSpy stateSpy2( mWidget, SIGNAL( longPressed(QModelIndex) ) ); |
|
643 |
|
644 QPointF pos(100,100); |
|
645 HbAutoTest::mouseClick( (HbAutoTestMainWindow*)mWindow, mWidget, pos, 100 ); |
|
646 |
|
647 QTest::qWait(1000); |
|
648 |
|
649 // Generating gestures doesn't work so enable this condition later. |
|
650 // QCOMPARE(stateSpy.count(),1); |
|
651 |
|
652 QVERIFY(!mWidget->longPressEnabled()); |
|
653 mWidget->setLongPressEnabled(true); |
|
654 QVERIFY(mWidget->longPressEnabled()); |
|
655 |
|
656 HbAutoTest::mousePress( (HbAutoTestMainWindow*)mWindow, mWidget, pos, -1 ); |
|
657 HbAutoTest::mouseRelease( (HbAutoTestMainWindow*)mWindow, mWidget, pos, 2000 ); |
|
658 |
|
659 // Generating gestures doesn't work so enable this condition later. |
|
660 // QCOMPARE( stateSpy2.count(),1 ); |
|
661 |
|
662 mWidget->setLongPressEnabled(false); |
|
663 QVERIFY(!mWidget->longPressEnabled()); |
|
664 |
|
665 QTest::qWait(2000); |
|
666 |
|
667 delete mWindow; |
|
668 mWindow = 0; |
|
669 } |
|
670 |
|
671 void TestGanesWidgets::test_updateData() |
|
672 { |
|
673 mWindow = new HbMainWindow; |
|
674 mWidget = new HgGrid( Qt::Vertical ); |
|
675 TestModel model; |
|
676 model.generateItems(50); |
|
677 mWindow->addView( mWidget ); |
|
678 model.mValidData = false; |
|
679 mWidget->setModel( &model ); |
|
680 mWindow->show(); |
|
681 |
|
682 QTest::qWait( 2000 ); |
|
683 |
|
684 model.mValidData = true; |
|
685 for(int i=0;i<50;i++){ |
|
686 model.changeItem(i); |
|
687 } |
|
688 |
|
689 QTest::qWait(2000); |
|
690 |
|
691 delete mWindow; |
|
692 mWindow = 0; |
|
693 } |
|
694 |
|
695 void TestGanesWidgets::test_currentItemCoverflow() |
|
696 { |
|
697 const QPointF pos1(160, 300); |
|
698 const QPointF pos2(300, 300); |
|
699 const QPointF pos3(20, 300); |
|
700 |
|
701 mWindow = new HbMainWindow; |
|
702 mWindow->viewport()->grabGesture(Qt::PanGesture); |
|
703 mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working |
|
704 mWidget = new HgMediawall(); |
|
705 |
|
706 TestModel model; |
|
707 model.generateItems(50); |
|
708 mWindow->addView(mWidget); |
|
709 mWidget->setModel(&model); |
|
710 mWindow->show(); |
|
711 |
|
712 QVERIFY(mWidget->selectionModel()); |
|
713 qRegisterMetaType<QModelIndex>("QModelIndex"); |
|
714 QSignalSpy currentItemSpy(mWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex))); |
|
715 |
|
716 QTest::qWait(2000); |
|
717 |
|
718 QVERIFY(mWidget->currentIndex() == model.index(0, 0)); |
|
719 |
|
720 mWidget->setCurrentIndex(model.index(7, 0)); |
|
721 QVERIFY(mWidget->currentIndex() == model.index(7, 0)); |
|
722 |
|
723 mWidget->setCurrentIndex(QModelIndex()); |
|
724 QVERIFY(!mWidget->currentIndex().isValid()); |
|
725 |
|
726 currentItemSpy.clear(); |
|
727 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos1, 100); |
|
728 QTest::qWait(1000); |
|
729 QVERIFY(mWidget->currentIndex() == model.index(0, 0)); |
|
730 QVERIFY(currentItemSpy.count() == 1); |
|
731 QVERIFY(currentItemSpy.at(0).count() > 0); |
|
732 QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(0, 0)); |
|
733 |
|
734 currentItemSpy.clear(); |
|
735 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos2, 100); |
|
736 QTest::qWait(1000); |
|
737 QVERIFY(mWidget->currentIndex() == model.index(1, 0)); |
|
738 QVERIFY(currentItemSpy.count() == 1); |
|
739 QVERIFY(currentItemSpy.at(0).count() > 0); |
|
740 QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(1, 0)); |
|
741 |
|
742 currentItemSpy.clear(); |
|
743 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos2, 100); |
|
744 QTest::qWait(1000); |
|
745 QVERIFY(mWidget->currentIndex() == model.index(2, 0)); |
|
746 QVERIFY(currentItemSpy.count() == 1); |
|
747 QVERIFY(currentItemSpy.at(0).count() > 0); |
|
748 QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(2, 0)); |
|
749 |
|
750 currentItemSpy.clear(); |
|
751 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos2, 100); |
|
752 QTest::qWait(1000); |
|
753 QVERIFY(mWidget->currentIndex() == model.index(3, 0)); |
|
754 QVERIFY(currentItemSpy.count() == 1); |
|
755 QVERIFY(currentItemSpy.at(0).count() > 0); |
|
756 QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(3, 0)); |
|
757 |
|
758 currentItemSpy.clear(); |
|
759 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100); |
|
760 QTest::qWait(1000); |
|
761 QVERIFY(mWidget->currentIndex() == model.index(2, 0)); |
|
762 QVERIFY(currentItemSpy.count() == 1); |
|
763 QVERIFY(currentItemSpy.at(0).count() > 0); |
|
764 QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(2, 0)); |
|
765 |
|
766 currentItemSpy.clear(); |
|
767 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100); |
|
768 QTest::qWait(1000); |
|
769 QVERIFY(mWidget->currentIndex() == model.index(1, 0)); |
|
770 QVERIFY(currentItemSpy.count() == 1); |
|
771 QVERIFY(currentItemSpy.at(0).count() > 0); |
|
772 QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(1, 0)); |
|
773 |
|
774 currentItemSpy.clear(); |
|
775 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100); |
|
776 QTest::qWait(1000); |
|
777 QVERIFY(mWidget->currentIndex() == model.index(0, 0)); |
|
778 QVERIFY(currentItemSpy.count() == 1); |
|
779 QVERIFY(currentItemSpy.at(0).count() > 0); |
|
780 QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(0, 0)); |
|
781 |
|
782 currentItemSpy.clear(); |
|
783 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100); |
|
784 QTest::qWait(1000); |
|
785 QVERIFY(mWidget->currentIndex() == model.index(0, 0)); |
|
786 QVERIFY(currentItemSpy.count() == 0); |
|
787 |
|
788 QTest::qWait(2000); |
|
789 |
|
790 delete mWindow; |
|
791 mWindow = 0; |
|
792 } |
|
793 |
|
794 void TestGanesWidgets::test_currentItemGrid() |
|
795 { |
|
796 mWindow = new HbMainWindow; |
|
797 mWindow->viewport()->grabGesture(Qt::PanGesture); |
|
798 mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working |
|
799 mWidget = new HgGrid( Qt::Vertical); |
|
800 |
|
801 TestModel model; |
|
802 model.generateItems(50); |
|
803 mWindow->addView(mWidget); |
|
804 mWidget->setModel(&model); |
|
805 mWindow->show(); |
|
806 |
|
807 QVERIFY(mWidget->selectionModel()); |
|
808 qRegisterMetaType<QModelIndex>("QModelIndex"); |
|
809 QSignalSpy currentItemSpy(mWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex))); |
|
810 |
|
811 QTest::qWait(2000); |
|
812 |
|
813 QVERIFY(mWidget->currentIndex() == model.index(0, 0)); |
|
814 |
|
815 mWidget->setCurrentIndex(model.index(7, 0)); |
|
816 QVERIFY(mWidget->currentIndex() == model.index(7, 0)); |
|
817 |
|
818 mWidget->setCurrentIndex(QModelIndex()); |
|
819 QVERIFY(!mWidget->currentIndex().isValid()); |
|
820 |
|
821 currentItemSpy.clear(); |
|
822 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos1, 100); |
|
823 QTest::qWait(1000); |
|
824 QVERIFY(mWidget->currentIndex() == model.index(1, 0)); |
|
825 QVERIFY(currentItemSpy.count() == 1); |
|
826 QVERIFY(currentItemSpy.at(0).count() > 0); |
|
827 QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(1, 0)); |
|
828 |
|
829 currentItemSpy.clear(); |
|
830 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos4, 100); |
|
831 QTest::qWait(1000); |
|
832 QVERIFY(mWidget->currentIndex() == model.index(4, 0)); |
|
833 QVERIFY(currentItemSpy.count() == 1); |
|
834 QVERIFY(currentItemSpy.at(0).count() > 0); |
|
835 QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(4, 0)); |
|
836 |
|
837 currentItemSpy.clear(); |
|
838 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos4, 100); |
|
839 QTest::qWait(1000); |
|
840 QVERIFY(mWidget->currentIndex() == model.index(4, 0)); |
|
841 QVERIFY(currentItemSpy.count() == 0); |
|
842 |
|
843 currentItemSpy.clear(); |
|
844 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos8, 100); |
|
845 QTest::qWait(1000); |
|
846 QVERIFY(mWidget->currentIndex() == model.index(8, 0)); |
|
847 QVERIFY(currentItemSpy.count() == 1); |
|
848 QVERIFY(currentItemSpy.at(0).count() > 0); |
|
849 QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(8, 0)); |
|
850 |
|
851 QTest::qWait(2000); |
|
852 |
|
853 delete mWindow; |
|
854 mWindow = 0; |
|
855 } |
|
856 |
|
857 void TestGanesWidgets::test_selectionMode() |
|
858 { |
|
859 mWindow = new HbMainWindow; |
|
860 mWindow->viewport()->grabGesture(Qt::PanGesture); |
|
861 mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working |
|
862 mWidget = new HgGrid( Qt::Vertical); |
|
863 |
|
864 mWindow->addView(mWidget); |
|
865 mWindow->show(); |
|
866 |
|
867 QTest::qWait(2000); |
|
868 |
|
869 // Widget does not have selection model yet |
|
870 QVERIFY(mWidget->selectionModel() == 0); |
|
871 |
|
872 // Selection methods should have no effect unless there is a model |
|
873 mWidget->setSelectionMode(HgWidget::MultiSelection); |
|
874 QVERIFY(mWidget->selectionMode() == HgWidget::MultiSelection); |
|
875 QVERIFY(mWidget->selectionModel() == 0); |
|
876 mWidget->selectAll(); |
|
877 QVERIFY(mWidget->selectionModel() == 0); |
|
878 |
|
879 TestModel model; |
|
880 model.generateItems(9); |
|
881 mWidget->setModel(&model); |
|
882 QVERIFY(mWidget->selectionModel() != 0); |
|
883 |
|
884 qRegisterMetaType<QItemSelection>("QItemSelection"); |
|
885 QSignalSpy selectionSpy(mWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection))); |
|
886 |
|
887 QTest::qWait(2000); |
|
888 |
|
889 mWidget->setSelectionMode(HgWidget::NoSelection); |
|
890 QVERIFY(mWidget->selectionMode() == HgWidget::NoSelection); |
|
891 // Default selection mode: no selection |
|
892 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos0, 100); |
|
893 QTest::qWait(1000); |
|
894 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 0); |
|
895 QVERIFY(selectionSpy.count() == 0); |
|
896 |
|
897 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos1, 100); |
|
898 QTest::qWait(1000); |
|
899 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 0); |
|
900 QVERIFY(selectionSpy.count() == 0); |
|
901 |
|
902 mWidget->selectAll(); |
|
903 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 0); |
|
904 QVERIFY(selectionSpy.count() == 0); |
|
905 |
|
906 // Single selection mode: at most 1 item selected at a time |
|
907 mWidget->setSelectionMode(HgWidget::SingleSelection); |
|
908 QVERIFY(mWidget->selectionMode() == HgWidget::SingleSelection); |
|
909 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 0); |
|
910 |
|
911 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos1, 100); |
|
912 QTest::qWait(1000); |
|
913 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 1); |
|
914 QVERIFY(mWidget->selectionModel()->isSelected(model.index(1, 0))); |
|
915 QVERIFY(selectionSpy.count() == 1); |
|
916 QVERIFY(selectionSpy.at(0).count() > 0); |
|
917 QItemSelection selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); |
|
918 QVERIFY(selection.indexes().count() == 1); |
|
919 QVERIFY(selection.contains(model.index(1, 0))); |
|
920 |
|
921 selectionSpy.clear(); |
|
922 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos3, 100); |
|
923 QTest::qWait(1000); |
|
924 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 1); |
|
925 QVERIFY(mWidget->selectionModel()->isSelected(model.index(3, 0))); |
|
926 QVERIFY(selectionSpy.count() == 1); |
|
927 QVERIFY(selectionSpy.at(0).count() > 1); |
|
928 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); // new selected |
|
929 QVERIFY(selection.indexes().count() == 1); |
|
930 QVERIFY(selection.contains(model.index(3, 0))); |
|
931 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(1)); // deselected |
|
932 QVERIFY(selection.indexes().count() == 1); |
|
933 QVERIFY(selection.contains(model.index(1, 0))); |
|
934 |
|
935 selectionSpy.clear(); |
|
936 mWidget->clearSelection(); |
|
937 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 0); |
|
938 QVERIFY(selectionSpy.count() == 1); |
|
939 QVERIFY(selectionSpy.at(0).count() > 0); |
|
940 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); |
|
941 QVERIFY(selection.indexes().count() == 0); |
|
942 |
|
943 selectionSpy.clear(); |
|
944 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos8, 100); |
|
945 QTest::qWait(1000); |
|
946 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 1); |
|
947 QVERIFY(mWidget->selectionModel()->isSelected(model.index(8, 0))); |
|
948 QVERIFY(selectionSpy.count() == 1); |
|
949 QVERIFY(selectionSpy.at(0).count() > 0); |
|
950 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); |
|
951 QVERIFY(selection.indexes().count() == 1); |
|
952 QVERIFY(selection.contains(model.index(8, 0))); |
|
953 |
|
954 selectionSpy.clear(); |
|
955 // Changing selection mode with default parameter should clear the selection |
|
956 mWidget->setSelectionMode(HgWidget::ContiguousSelection); |
|
957 QVERIFY(mWidget->selectionMode() == HgWidget::ContiguousSelection); |
|
958 |
|
959 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 0); |
|
960 QVERIFY(selectionSpy.count() == 1); |
|
961 QVERIFY(selectionSpy.at(0).count() > 0); |
|
962 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); |
|
963 QVERIFY(selection.indexes().count() == 0); |
|
964 |
|
965 selectionSpy.clear(); |
|
966 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos2, 100); |
|
967 QTest::qWait(1000); |
|
968 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 1); |
|
969 QVERIFY(mWidget->selectionModel()->isSelected(model.index(2, 0))); |
|
970 QVERIFY(selectionSpy.count() == 1); |
|
971 QVERIFY(selectionSpy.at(0).count() > 0); |
|
972 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); |
|
973 QVERIFY(selection.indexes().count() == 1); |
|
974 QVERIFY(selection.contains(model.index(2, 0))); |
|
975 |
|
976 selectionSpy.clear(); |
|
977 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos3, 100); |
|
978 QTest::qWait(1000); |
|
979 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 2); |
|
980 QVERIFY(mWidget->selectionModel()->isSelected(model.index(3, 0))); |
|
981 QVERIFY(selectionSpy.count() == 1); |
|
982 QVERIFY(selectionSpy.at(0).count() > 0); |
|
983 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); |
|
984 QVERIFY(selection.indexes().count() == 1); |
|
985 QVERIFY(selection.contains(model.index(3, 0))); |
|
986 |
|
987 selectionSpy.clear(); |
|
988 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos5, 100); |
|
989 QTest::qWait(1000); |
|
990 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 4); |
|
991 QVERIFY(mWidget->selectionModel()->isSelected(model.index(4, 0))); |
|
992 QVERIFY(mWidget->selectionModel()->isSelected(model.index(5, 0))); |
|
993 QVERIFY(selectionSpy.count() == 1); |
|
994 QVERIFY(selectionSpy.at(0).count() > 0); |
|
995 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); |
|
996 QVERIFY(selection.indexes().count() == 2); |
|
997 QVERIFY(selection.contains(model.index(4, 0))); |
|
998 QVERIFY(selection.contains(model.index(5, 0))); |
|
999 |
|
1000 selectionSpy.clear(); |
|
1001 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos0, 100); |
|
1002 QTest::qWait(1000); |
|
1003 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 6); |
|
1004 QVERIFY(mWidget->selectionModel()->isSelected(model.index(0, 0))); |
|
1005 QVERIFY(mWidget->selectionModel()->isSelected(model.index(1, 0))); |
|
1006 QVERIFY(selectionSpy.count() == 1); |
|
1007 QVERIFY(selectionSpy.at(0).count() > 0); |
|
1008 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); |
|
1009 QVERIFY(selection.indexes().count() == 2); |
|
1010 QVERIFY(selection.contains(model.index(0, 0))); |
|
1011 QVERIFY(selection.contains(model.index(1, 0))); |
|
1012 |
|
1013 // In contiguous selection mode, clicking a selected item does nothing |
|
1014 selectionSpy.clear(); |
|
1015 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos5, 100); |
|
1016 QTest::qWait(1000); |
|
1017 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 6); |
|
1018 QVERIFY(selectionSpy.count() == 0); |
|
1019 |
|
1020 selectionSpy.clear(); |
|
1021 mWidget->selectAll(); |
|
1022 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 9); |
|
1023 QVERIFY(selectionSpy.count() == 1); |
|
1024 |
|
1025 selectionSpy.clear(); |
|
1026 // Changing selection mode with resetSelection = false should NOT clear the selection |
|
1027 mWidget->setSelectionMode(HgWidget::MultiSelection, false); |
|
1028 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 9); |
|
1029 QVERIFY(selectionSpy.count() == 0); |
|
1030 |
|
1031 selectionSpy.clear(); |
|
1032 // In multiselection mode, clicking a selected item deselects it |
|
1033 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos5, 100); |
|
1034 QTest::qWait(1000); |
|
1035 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 8); |
|
1036 QVERIFY(!(mWidget->selectionModel()->isSelected(model.index(5, 0)))); |
|
1037 QVERIFY(selectionSpy.count() == 1); |
|
1038 QVERIFY(selectionSpy.at(0).count() > 1); |
|
1039 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); // new selected |
|
1040 QVERIFY(selection.indexes().count() == 0); |
|
1041 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(1)); // deselected |
|
1042 QVERIFY(selection.indexes().count() == 1); |
|
1043 QVERIFY(selection.contains(model.index(5, 0))); |
|
1044 |
|
1045 selectionSpy.clear(); |
|
1046 mWidget->clearSelection(); |
|
1047 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 0); |
|
1048 QVERIFY(selectionSpy.count() == 1); |
|
1049 QVERIFY(selectionSpy.at(0).count() > 1); |
|
1050 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); // new selected |
|
1051 QVERIFY(selection.indexes().count() == 0); |
|
1052 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(1)); // deselected |
|
1053 QVERIFY(selection.indexes().count() == 8); |
|
1054 |
|
1055 selectionSpy.clear(); |
|
1056 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos3, 100); |
|
1057 QTest::qWait(1000); |
|
1058 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 1); |
|
1059 QVERIFY(mWidget->selectionModel()->isSelected(model.index(3, 0))); |
|
1060 QVERIFY(selectionSpy.count() == 1); |
|
1061 QVERIFY(selectionSpy.at(0).count() > 0); |
|
1062 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); |
|
1063 QVERIFY(selection.indexes().count() == 1); |
|
1064 |
|
1065 selectionSpy.clear(); |
|
1066 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos5, 100); |
|
1067 QTest::qWait(1000); |
|
1068 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 2); |
|
1069 QVERIFY(mWidget->selectionModel()->isSelected(model.index(5, 0))); |
|
1070 QVERIFY(selectionSpy.count() == 1); |
|
1071 QVERIFY(selectionSpy.at(0).count() > 0); |
|
1072 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); |
|
1073 QVERIFY(selection.indexes().count() == 1); |
|
1074 QVERIFY(selection.contains(model.index(5, 0))); |
|
1075 |
|
1076 selectionSpy.clear(); |
|
1077 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos8, 100); |
|
1078 QTest::qWait(1000); |
|
1079 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 3); |
|
1080 QVERIFY(mWidget->selectionModel()->isSelected(model.index(8, 0))); |
|
1081 QVERIFY(selectionSpy.count() == 1); |
|
1082 QVERIFY(selectionSpy.at(0).count() > 0); |
|
1083 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); |
|
1084 QVERIFY(selection.indexes().count() == 1); |
|
1085 QVERIFY(selection.contains(model.index(8, 0))); |
|
1086 |
|
1087 selectionSpy.clear(); |
|
1088 // Setting the same mode does nothing |
|
1089 mWidget->setSelectionMode(HgWidget::MultiSelection); |
|
1090 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 3); |
|
1091 QVERIFY(selectionSpy.count() == 0); |
|
1092 |
|
1093 selectionSpy.clear(); |
|
1094 // Keep the selection, even if it is not suitable for the new selection mode |
|
1095 mWidget->setSelectionMode(HgWidget::SingleSelection, false); |
|
1096 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 3); |
|
1097 QVERIFY(selectionSpy.count() == 0); |
|
1098 |
|
1099 selectionSpy.clear(); |
|
1100 // First click resets the selection to a valid setup |
|
1101 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos5, 100); |
|
1102 QTest::qWait(1000); |
|
1103 QVERIFY(mWidget->selectionModel()->selectedIndexes().count() == 1); |
|
1104 QVERIFY(mWidget->selectionModel()->isSelected(model.index(5, 0))); |
|
1105 QVERIFY(selectionSpy.count() == 1); |
|
1106 QVERIFY(selectionSpy.at(0).count() > 1); |
|
1107 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(0)); // new selected |
|
1108 QVERIFY(selection.indexes().count() == 0); |
|
1109 selection = qvariant_cast<QItemSelection>(selectionSpy.at(0).at(1)); // deselected |
|
1110 QVERIFY(selection.indexes().count() == 2); |
|
1111 QVERIFY(selection.contains(model.index(3, 0))); |
|
1112 QVERIFY(selection.contains(model.index(8, 0))); |
|
1113 |
|
1114 QTest::qWait(2000); |
|
1115 |
|
1116 delete mWindow; |
|
1117 mWindow = 0; |
|
1118 } |
|
1119 |
|
1120 void TestGanesWidgets::test_selectionModel() |
|
1121 { |
|
1122 mWindow = new HbMainWindow; |
|
1123 mWindow->viewport()->grabGesture(Qt::PanGesture); |
|
1124 mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working |
|
1125 mWidget = new HgGrid( Qt::Vertical); |
|
1126 TestModel model; |
|
1127 model.generateItems(9); |
|
1128 mWidget->setModel(&model); |
|
1129 mWindow->addView(mWidget); |
|
1130 mWindow->show(); |
|
1131 QTest::qWait(2000); |
|
1132 |
|
1133 QVERIFY(mWidget->selectionModel() != 0); |
|
1134 |
|
1135 QItemSelectionModel *defaultSelectionModel = mWidget->selectionModel(); |
|
1136 QSignalSpy defaultSelectionSpy(defaultSelectionModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection))); |
|
1137 |
|
1138 QItemSelectionModel *testSelectionModel1 = new QItemSelectionModel(&model); |
|
1139 QSignalSpy testSelectionSpy1(testSelectionModel1, SIGNAL(selectionChanged(QItemSelection, QItemSelection))); |
|
1140 |
|
1141 QItemSelectionModel *testSelectionModel2 = new QItemSelectionModel(&model); |
|
1142 QSignalSpy testSelectionSpy2(testSelectionModel2, SIGNAL(selectionChanged(QItemSelection, QItemSelection))); |
|
1143 |
|
1144 mWidget->setSelectionMode(HgWidget::MultiSelection); |
|
1145 |
|
1146 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos2, 100); |
|
1147 QTest::qWait(1000); |
|
1148 QVERIFY(defaultSelectionModel->selectedIndexes().count() == 1); |
|
1149 QVERIFY(defaultSelectionSpy.count() == 1); |
|
1150 QVERIFY(testSelectionModel1->selectedIndexes().count() == 0); |
|
1151 QVERIFY(testSelectionSpy1.count() == 0); |
|
1152 QVERIFY(testSelectionModel2->selectedIndexes().count() == 0); |
|
1153 QVERIFY(testSelectionSpy2.count() == 0); |
|
1154 |
|
1155 defaultSelectionSpy.clear(); |
|
1156 testSelectionSpy1.clear(); |
|
1157 testSelectionSpy2.clear(); |
|
1158 |
|
1159 mWidget->setSelectionModel(testSelectionModel1); |
|
1160 HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, grid_portrait_pos5, 100); |
|
1161 QTest::qWait(1000); |
|
1162 // Default selection model is not valid any more |
|
1163 QVERIFY(defaultSelectionSpy.count() == 0); |
|
1164 QVERIFY(testSelectionModel1->selectedIndexes().count() == 1); |
|
1165 QVERIFY(testSelectionSpy1.count() == 1); |
|
1166 QVERIFY(testSelectionModel2->selectedIndexes().count() == 0); |
|
1167 QVERIFY(testSelectionSpy2.count() == 0); |
|
1168 |
|
1169 defaultSelectionSpy.clear(); |
|
1170 testSelectionSpy1.clear(); |
|
1171 testSelectionSpy2.clear(); |
|
1172 |
|
1173 mWidget->setSelectionModel(testSelectionModel2); |
|
1174 mWidget->selectAll(); |
|
1175 QVERIFY(testSelectionModel1->selectedIndexes().count() == 1); |
|
1176 QVERIFY(testSelectionSpy1.count() == 0); |
|
1177 QVERIFY(testSelectionModel2->selectedIndexes().count() == 9); |
|
1178 QVERIFY(testSelectionSpy2.count() == 1); |
|
1179 |
|
1180 defaultSelectionSpy.clear(); |
|
1181 testSelectionSpy1.clear(); |
|
1182 testSelectionSpy2.clear(); |
|
1183 |
|
1184 // Setting the same selection model again does nothing |
|
1185 mWidget->setSelectionModel(testSelectionModel2); |
|
1186 QVERIFY(testSelectionModel1->selectedIndexes().count() == 1); |
|
1187 QVERIFY(testSelectionSpy1.count() == 0); |
|
1188 QVERIFY(testSelectionModel2->selectedIndexes().count() == 9); |
|
1189 QVERIFY(testSelectionSpy2.count() == 0); |
|
1190 |
|
1191 defaultSelectionSpy.clear(); |
|
1192 testSelectionSpy1.clear(); |
|
1193 testSelectionSpy2.clear(); |
|
1194 |
|
1195 mWidget->setSelectionModel(testSelectionModel1); |
|
1196 mWidget->clearSelection(); |
|
1197 QVERIFY(testSelectionModel1->selectedIndexes().count() == 0); |
|
1198 QVERIFY(testSelectionSpy1.count() == 1); |
|
1199 QVERIFY(testSelectionModel2->selectedIndexes().count() == 9); |
|
1200 QVERIFY(testSelectionSpy2.count() == 0); |
|
1201 |
|
1202 QTest::qWait(2000); |
|
1203 |
|
1204 delete testSelectionModel1; |
|
1205 delete testSelectionModel2; |
|
1206 |
|
1207 delete mWindow; |
|
1208 mWindow = 0; |
|
1209 } |
|
1210 |
|
1211 void TestGanesWidgets::test_scrollTo() |
|
1212 { |
|
1213 qRegisterMetaType<QModelIndex>("QModelIndex"); |
|
1214 qRegisterMetaType<QModelIndex>("QItemSelection"); |
|
1215 // TODO: How to verify that items are freed? |
|
1216 |
|
1217 mWindow = new HbMainWindow; |
|
1218 mWindow->viewport()->grabGesture(Qt::PanGesture); |
|
1219 mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working |
|
1220 mWidget = new HgGrid( Qt::Vertical); |
|
1221 QList<QModelIndex> requestedIndexes; |
|
1222 TestModel model(&requestedIndexes); |
|
1223 model.generateItems(1024); |
|
1224 mWidget->setModel(&model); |
|
1225 mWindow->addView(mWidget); |
|
1226 mWindow->show(); |
|
1227 QTest::qWait(2000); |
|
1228 |
|
1229 QVERIFY(requestedIndexes.count() == 120); // Scroll buffer size in grid mode is assumed to be 120 |
|
1230 QVERIFY(requestedIndexes.front() == model.index(0, 0)); |
|
1231 QVERIFY(requestedIndexes.back() == model.index(119, 0)); |
|
1232 requestedIndexes.clear(); |
|
1233 |
|
1234 QSignalSpy activatedSpy(mWidget, SIGNAL(activated(QModelIndex))); |
|
1235 QSignalSpy currentSpy(mWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex))); |
|
1236 QSignalSpy selectionSpy(mWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection))); |
|
1237 |
|
1238 mWidget->scrollTo(model.index(100, 0)); |
|
1239 QTest::qWait(1000); |
|
1240 QVERIFY(activatedSpy.count() == 0); // scrollto doesn't activate item |
|
1241 QVERIFY(currentSpy.count() == 0); // scrollto doesn't change the current |
|
1242 QVERIFY(selectionSpy.count() == 0); // scrollto doesn't change the selection |
|
1243 QVERIFY(requestedIndexes.count() == 40); // The whole scroll buffer should be updated |
|
1244 QVERIFY(requestedIndexes.front() == model.index(120, 0)); |
|
1245 QVERIFY(requestedIndexes.back() == model.index(159, 0)); |
|
1246 requestedIndexes.clear(); |
|
1247 |
|
1248 mWidget->scrollTo(model.index(1023, 0)); |
|
1249 QTest::qWait(1000); |
|
1250 QVERIFY(activatedSpy.count() == 0); // scrollto doesn't activate item |
|
1251 QVERIFY(currentSpy.count() == 0); // scrollto doesn't change the current |
|
1252 QVERIFY(selectionSpy.count() == 0); // scrollto doesn't change the selection |
|
1253 QVERIFY(requestedIndexes.count() == 120); // The whole scroll buffer should be updated |
|
1254 QVERIFY(requestedIndexes.front() == model.index(904, 0)); |
|
1255 QVERIFY(requestedIndexes.back() == model.index(1023, 0)); |
|
1256 requestedIndexes.clear(); |
|
1257 |
|
1258 mWidget->scrollTo(QModelIndex()); |
|
1259 QTest::qWait(1000); |
|
1260 QVERIFY(activatedSpy.count() == 0); // scrollto doesn't activate item |
|
1261 QVERIFY(currentSpy.count() == 0); // scrollto doesn't change the current |
|
1262 QVERIFY(selectionSpy.count() == 0); // scrollto doesn't change the selection |
|
1263 QVERIFY(requestedIndexes.count() == 0); // Items are not re-fetched from model |
|
1264 |
|
1265 QTest::qWait(2000); |
|
1266 |
|
1267 delete mWindow; |
|
1268 mWindow = 0; |
|
1269 } |
|
1270 |
|
1271 void TestGanesWidgets::test_addItemsCoverFlow() |
|
1272 { |
|
1273 // TODO: How to verify that items are freed? |
|
1274 |
|
1275 mWindow = new HbMainWindow; |
|
1276 mWindow->viewport()->grabGesture(Qt::PanGesture); |
|
1277 mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working |
|
1278 mWidget = new HgMediawall(); |
|
1279 |
|
1280 QList<QModelIndex> requestedIndexes; |
|
1281 TestModel model(&requestedIndexes); |
|
1282 model.generateItems(120); |
|
1283 mWidget->setModel(&model); |
|
1284 mWindow->addView(mWidget); |
|
1285 mWindow->show(); |
|
1286 |
|
1287 QTest::qWait(2000); |
|
1288 |
|
1289 QVERIFY(requestedIndexes.count() == 40); // Scroll buffer size in coverflow mode is assumed to be 40 |
|
1290 QVERIFY(requestedIndexes.front() == model.index(0, 0)); |
|
1291 QVERIFY(requestedIndexes.back() == model.index(39, 0)); |
|
1292 requestedIndexes.clear(); |
|
1293 |
|
1294 // Move buffer to the end of items |
|
1295 mWidget->scrollTo(model.index(119, 0)); |
|
1296 QTest::qWait(1000); |
|
1297 requestedIndexes.clear(); |
|
1298 |
|
1299 // Add one item to beginning of buffer |
|
1300 model.insertItems(80, 1); |
|
1301 QTest::qWait(1000); |
|
1302 QVERIFY(requestedIndexes.count() == 0); // New item falls outside of buffer as buffer is moved up |
|
1303 requestedIndexes.clear(); |
|
1304 // Last item is now 120 |
|
1305 |
|
1306 // Add many items to beginning of buffer |
|
1307 model.insertItems(81, 4); |
|
1308 QTest::qWait(1000); |
|
1309 QVERIFY(requestedIndexes.count() == 0); // New items falls outside of buffer as buffer is moved up |
|
1310 requestedIndexes.clear(); |
|
1311 // Last item is now 124 |
|
1312 |
|
1313 // Add one item to the end |
|
1314 model.insertItems(124, 1); |
|
1315 QTest::qWait(1000); |
|
1316 QVERIFY(requestedIndexes.count() == 1); // The new item is requested |
|
1317 QVERIFY(requestedIndexes.front() == model.index(124, 0)); |
|
1318 requestedIndexes.clear(); |
|
1319 // Last item is now 125 |
|
1320 |
|
1321 // Add many items to the end |
|
1322 model.insertItems(125, 4); |
|
1323 QTest::qWait(1000); |
|
1324 QVERIFY(requestedIndexes.count() == 4); // The new items are requested |
|
1325 QVERIFY(requestedIndexes.front() == model.index(125, 0)); |
|
1326 QVERIFY(requestedIndexes.back() == model.index(128, 0)); |
|
1327 requestedIndexes.clear(); |
|
1328 // Last item is now 129 |
|
1329 |
|
1330 // Add one item to middle of buffer |
|
1331 model.insertItems(110, 1); |
|
1332 QTest::qWait(1000); |
|
1333 QVERIFY(requestedIndexes.count() == 1); // The new item is requested |
|
1334 QVERIFY(requestedIndexes.front() == model.index(110, 0)); |
|
1335 requestedIndexes.clear(); |
|
1336 // Last item is now 130 |
|
1337 |
|
1338 // Add many items to middle of buffer |
|
1339 model.insertItems(110, 4); |
|
1340 QTest::qWait(1000); |
|
1341 QVERIFY(requestedIndexes.count() == 4); // The new items are requested |
|
1342 QVERIFY(requestedIndexes.front() == model.index(110, 0)); |
|
1343 QVERIFY(requestedIndexes.back() == model.index(113, 0)); |
|
1344 requestedIndexes.clear(); |
|
1345 // Last item is now 134 |
|
1346 |
|
1347 // Add items to the buffer limit (beginning of buffer) |
|
1348 model.insertItems(90, 20); |
|
1349 QTest::qWait(1000); |
|
1350 QVERIFY(requestedIndexes.count() == 0); // New item falls outside of buffer as buffer is moved up |
|
1351 // Last item is now 154 |
|
1352 |
|
1353 // Add items to outside of buffer (before buffer) |
|
1354 model.insertItems(0, 10); |
|
1355 QTest::qWait(1000); |
|
1356 QVERIFY(requestedIndexes.count() == 0); // The new items are not requested |
|
1357 requestedIndexes.clear(); |
|
1358 |
|
1359 // Move buffer to the beginning of items |
|
1360 mWidget->scrollTo(model.index(0, 0)); |
|
1361 QTest::qWait(1000); |
|
1362 requestedIndexes.clear(); |
|
1363 |
|
1364 // Add one item to beginning |
|
1365 model.insertItems(0, 1); |
|
1366 QTest::qWait(1000); |
|
1367 QVERIFY(requestedIndexes.count() == 1); // The new item is requested |
|
1368 QVERIFY(requestedIndexes.front() == model.index(0, 0)); |
|
1369 requestedIndexes.clear(); |
|
1370 |
|
1371 // Add many items to beginning |
|
1372 model.insertItems(0, 5); |
|
1373 QTest::qWait(1000); |
|
1374 QVERIFY(requestedIndexes.count() == 5); // The new items are requested |
|
1375 QVERIFY(requestedIndexes.front() == model.index(0, 0)); |
|
1376 QVERIFY(requestedIndexes.back() == model.index(4, 0)); |
|
1377 requestedIndexes.clear(); |
|
1378 |
|
1379 // Add one item to middle of buffer |
|
1380 model.insertItems(20, 1); |
|
1381 QTest::qWait(1000); |
|
1382 QVERIFY(requestedIndexes.count() == 1); // The new item is requested |
|
1383 QVERIFY(requestedIndexes.front() == model.index(20, 0)); |
|
1384 requestedIndexes.clear(); |
|
1385 |
|
1386 // Add many items to middle of buffer |
|
1387 model.insertItems(20, 5); |
|
1388 QTest::qWait(1000); |
|
1389 QVERIFY(requestedIndexes.count() == 5); // The new items are requested |
|
1390 QVERIFY(requestedIndexes.front() == model.index(20, 0)); |
|
1391 QVERIFY(requestedIndexes.back() == model.index(24, 0)); |
|
1392 requestedIndexes.clear(); |
|
1393 |
|
1394 // Add one item to end of buffer |
|
1395 model.insertItems(39, 1); |
|
1396 QTest::qWait(1000); |
|
1397 QVERIFY(requestedIndexes.count() == 1); // The new item is requested |
|
1398 QVERIFY(requestedIndexes.front() == model.index(39, 0)); |
|
1399 requestedIndexes.clear(); |
|
1400 |
|
1401 // Add many items to end of buffer |
|
1402 model.insertItems(30, 10); |
|
1403 QTest::qWait(1000); |
|
1404 QVERIFY(requestedIndexes.count() == 10); // The new items are requested |
|
1405 QVERIFY(requestedIndexes.front() == model.index(30, 0)); |
|
1406 QVERIFY(requestedIndexes.back() == model.index(39, 0)); |
|
1407 requestedIndexes.clear(); |
|
1408 |
|
1409 // Add items to outside of buffer (after buffer) |
|
1410 model.insertItems(40, 10); |
|
1411 QTest::qWait(1000); |
|
1412 QVERIFY(requestedIndexes.count() == 0); // The new items are not requested |
|
1413 requestedIndexes.clear(); |
|
1414 |
|
1415 // Add items to the buffer limit (end of buffer) |
|
1416 model.insertItems(35, 10); |
|
1417 QTest::qWait(1000); |
|
1418 QVERIFY(requestedIndexes.count() == 5); // The new items inside buffer are requested |
|
1419 QVERIFY(requestedIndexes.front() == model.index(35, 0)); |
|
1420 QVERIFY(requestedIndexes.back() == model.index(39, 0)); |
|
1421 |
|
1422 // Move buffer to the middle of items |
|
1423 mWidget->scrollTo(model.index(60, 0)); |
|
1424 QTest::qWait(1000); |
|
1425 requestedIndexes.clear(); |
|
1426 |
|
1427 // Add items to the buffer limit (beginning of buffer) |
|
1428 model.insertItems(35, 10); |
|
1429 QTest::qWait(1000); |
|
1430 QVERIFY(requestedIndexes.count() == 5); // The new items inside buffer are requested |
|
1431 QVERIFY(requestedIndexes.front() == model.index(40, 0)); |
|
1432 QVERIFY(requestedIndexes.back() == model.index(44, 0)); |
|
1433 |
|
1434 // Add items over the whole buffer |
|
1435 model.insertItems(35, 50); |
|
1436 QTest::qWait(1000); |
|
1437 QVERIFY(requestedIndexes.count() == 40); // The new items inside buffer are requested |
|
1438 QVERIFY(requestedIndexes.front() == model.index(40, 0)); |
|
1439 QVERIFY(requestedIndexes.back() == model.index(79, 0)); |
|
1440 |
|
1441 QTest::qWait(2000); |
|
1442 |
|
1443 delete mWindow; |
|
1444 mWindow = 0; |
|
1445 } |
|
1446 |
|
1447 void TestGanesWidgets::test_removeItemsCoverFlow() |
|
1448 { |
|
1449 // TODO: How to verify that items are freed? |
|
1450 |
|
1451 mWindow = new HbMainWindow; |
|
1452 mWindow->viewport()->grabGesture(Qt::PanGesture); |
|
1453 mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working |
|
1454 mWidget = new HgMediawall(); |
|
1455 |
|
1456 QList<QModelIndex> requestedIndexes; |
|
1457 TestModel model(&requestedIndexes); |
|
1458 model.generateItems(240); |
|
1459 mWidget->setModel(&model); |
|
1460 mWindow->addView(mWidget); |
|
1461 mWindow->show(); |
|
1462 |
|
1463 QTest::qWait(2000); |
|
1464 |
|
1465 QVERIFY(requestedIndexes.count() == 40); // Scroll buffer size in coverflow mode is assumed to be 40 |
|
1466 QVERIFY(requestedIndexes.front() == model.index(0, 0)); |
|
1467 QVERIFY(requestedIndexes.back() == model.index(39, 0)); |
|
1468 requestedIndexes.clear(); |
|
1469 |
|
1470 // Move buffer to the end of items |
|
1471 mWidget->scrollTo(model.index(239, 0)); |
|
1472 QTest::qWait(1000); |
|
1473 requestedIndexes.clear(); |
|
1474 |
|
1475 // Remove one item from the beginning of buffer |
|
1476 model.removeItems(200, 1); |
|
1477 QTest::qWait(1000); |
|
1478 QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one |
|
1479 QVERIFY(requestedIndexes.front() == model.index(199, 0)); |
|
1480 requestedIndexes.clear(); |
|
1481 // Last item is now 238 |
|
1482 |
|
1483 // Remove many items from beginning of buffer |
|
1484 model.removeItems(199, 4); |
|
1485 QTest::qWait(1000); |
|
1486 QVERIFY(requestedIndexes.count() == 4); // New items are fetched to replace the removed ones |
|
1487 QVERIFY(requestedIndexes.front() == model.index(195, 0)); |
|
1488 QVERIFY(requestedIndexes.back() == model.index(198, 0)); |
|
1489 requestedIndexes.clear(); |
|
1490 // Last item is now 234 |
|
1491 |
|
1492 // Remove one item from the end |
|
1493 model.removeItems(234, 1); |
|
1494 QTest::qWait(1000); |
|
1495 QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one |
|
1496 QVERIFY(requestedIndexes.front() == model.index(194, 0)); |
|
1497 requestedIndexes.clear(); |
|
1498 // Last item is now 233 |
|
1499 |
|
1500 // Remove many items from the end |
|
1501 model.removeItems(230, 4); |
|
1502 QTest::qWait(1000); |
|
1503 QVERIFY(requestedIndexes.count() == 4); // New items are fetched to replace the removed ones |
|
1504 QVERIFY(requestedIndexes.front() == model.index(190, 0)); |
|
1505 QVERIFY(requestedIndexes.back() == model.index(193, 0)); |
|
1506 requestedIndexes.clear(); |
|
1507 // Last item is now 229 |
|
1508 |
|
1509 // Remove one item from the middle of buffer |
|
1510 model.removeItems(210, 1); |
|
1511 QTest::qWait(1000); |
|
1512 QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one |
|
1513 QVERIFY(requestedIndexes.front() == model.index(189, 0)); |
|
1514 requestedIndexes.clear(); |
|
1515 // Last item is now 228 |
|
1516 |
|
1517 // Remove many items from the middle of buffer |
|
1518 model.removeItems(210, 4); |
|
1519 QTest::qWait(1000); |
|
1520 QVERIFY(requestedIndexes.count() == 4); // New items are fetched to replace the removed ones |
|
1521 QVERIFY(requestedIndexes.front() == model.index(185, 0)); |
|
1522 QVERIFY(requestedIndexes.back() == model.index(188, 0)); |
|
1523 requestedIndexes.clear(); |
|
1524 // Last item is now 224 |
|
1525 |
|
1526 // Remove items from the buffer limit (beginning of buffer) |
|
1527 model.removeItems(180, 10); |
|
1528 QTest::qWait(1000); |
|
1529 QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the removed ones |
|
1530 QVERIFY(requestedIndexes.front() == model.index(175, 0)); |
|
1531 QVERIFY(requestedIndexes.back() == model.index(179, 0)); |
|
1532 requestedIndexes.clear(); |
|
1533 // Last item is now 214 |
|
1534 |
|
1535 // Remove items from outside of buffer (before buffer) |
|
1536 model.removeItems(0, 10); |
|
1537 QTest::qWait(1000); |
|
1538 QVERIFY(requestedIndexes.count() == 0); // Buffer is not moved |
|
1539 requestedIndexes.clear(); |
|
1540 // Last item is now 204 |
|
1541 |
|
1542 // Move buffer to the beginning of items |
|
1543 mWidget->scrollTo(model.index(0, 0)); |
|
1544 QTest::qWait(1000); |
|
1545 requestedIndexes.clear(); |
|
1546 |
|
1547 // Remove one item from beginning |
|
1548 model.removeItems(0, 1); |
|
1549 QTest::qWait(1000); |
|
1550 QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one |
|
1551 QVERIFY(requestedIndexes.front() == model.index(39, 0)); |
|
1552 requestedIndexes.clear(); |
|
1553 // Last item is now 203 |
|
1554 |
|
1555 // Remove many items from beginning |
|
1556 model.removeItems(0, 5); |
|
1557 QTest::qWait(1000); |
|
1558 QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the removed ones |
|
1559 QVERIFY(requestedIndexes.front() == model.index(35, 0)); |
|
1560 QVERIFY(requestedIndexes.back() == model.index(39, 0)); |
|
1561 requestedIndexes.clear(); |
|
1562 // Last item is now 198 |
|
1563 |
|
1564 // Remove one item from the middle of buffer |
|
1565 model.removeItems(20, 1); |
|
1566 QTest::qWait(1000); |
|
1567 QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one |
|
1568 QVERIFY(requestedIndexes.front() == model.index(39, 0)); |
|
1569 requestedIndexes.clear(); |
|
1570 // Last item is now 197 |
|
1571 |
|
1572 // Remove many items from the middle of buffer |
|
1573 model.removeItems(20, 5); |
|
1574 QTest::qWait(1000); |
|
1575 QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the removed ones |
|
1576 QVERIFY(requestedIndexes.front() == model.index(35, 0)); |
|
1577 QVERIFY(requestedIndexes.back() == model.index(39, 0)); |
|
1578 requestedIndexes.clear(); |
|
1579 // Last item is now 192 |
|
1580 |
|
1581 // Remove one item from the end of buffer |
|
1582 model.removeItems(39, 1); |
|
1583 QTest::qWait(1000); |
|
1584 QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one |
|
1585 QVERIFY(requestedIndexes.front() == model.index(39, 0)); |
|
1586 requestedIndexes.clear(); |
|
1587 // Last item is now 191 |
|
1588 |
|
1589 // Remove many items from the end of buffer |
|
1590 model.removeItems(30, 10); |
|
1591 QTest::qWait(1000); |
|
1592 QVERIFY(requestedIndexes.count() == 10); // New items are fetched to replace the removed ones |
|
1593 QVERIFY(requestedIndexes.front() == model.index(30, 0)); |
|
1594 QVERIFY(requestedIndexes.back() == model.index(39, 0)); |
|
1595 requestedIndexes.clear(); |
|
1596 // Last item is now 181 |
|
1597 |
|
1598 // Remove items from outside of buffer (after buffer) |
|
1599 model.removeItems(50, 10); |
|
1600 QTest::qWait(1000); |
|
1601 QVERIFY(requestedIndexes.count() == 0); // Buffer is not updated |
|
1602 requestedIndexes.clear(); |
|
1603 // Last item is now 171 |
|
1604 |
|
1605 // Remove items from the buffer limit (end of buffer) |
|
1606 model.insertItems(35, 10); |
|
1607 QTest::qWait(1000); |
|
1608 QVERIFY(requestedIndexes.count() == 5); // The new items inside buffer are requested |
|
1609 QVERIFY(requestedIndexes.front() == model.index(35, 0)); |
|
1610 QVERIFY(requestedIndexes.back() == model.index(39, 0)); |
|
1611 // Last item is now 161 |
|
1612 |
|
1613 // Move buffer to the middle of items |
|
1614 mWidget->scrollTo(model.index(80, 0)); |
|
1615 QTest::qWait(1000); |
|
1616 requestedIndexes.clear(); |
|
1617 |
|
1618 // Remove items from the buffer limit (beginning of buffer) |
|
1619 model.removeItems(59, 2); |
|
1620 QTest::qWait(1000); |
|
1621 QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the one removed from the buffer |
|
1622 QVERIFY(requestedIndexes.front() == model.index(99, 0)); |
|
1623 // Last item is now 159 |
|
1624 |
|
1625 // Remove items over the whole buffer |
|
1626 model.removeItems(55, 50); |
|
1627 QTest::qWait(1000); |
|
1628 QVERIFY(requestedIndexes.count() == 40); // Whole buffer is updated |
|
1629 QVERIFY(requestedIndexes.front() == model.index(60, 0)); |
|
1630 QVERIFY(requestedIndexes.back() == model.index(99, 0)); |
|
1631 |
|
1632 QTest::qWait(2000); |
|
1633 |
|
1634 delete mWindow; |
|
1635 mWindow = 0; |
|
1636 } |
|
1637 |
|
1638 void TestGanesWidgets::test_moveItemsCoverFlow() |
|
1639 { |
|
1640 // TODO: How to verify that items are freed? |
|
1641 |
|
1642 mWindow = new HbMainWindow; |
|
1643 mWindow->viewport()->grabGesture(Qt::PanGesture); |
|
1644 mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working |
|
1645 mWidget = new HgMediawall(); |
|
1646 |
|
1647 QList<QModelIndex> requestedIndexes; |
|
1648 TestModel model(&requestedIndexes); |
|
1649 model.generateItems(120); |
|
1650 mWidget->setModel(&model); |
|
1651 mWindow->addView(mWidget); |
|
1652 mWindow->show(); |
|
1653 |
|
1654 QTest::qWait(2000); |
|
1655 |
|
1656 QVERIFY(requestedIndexes.count() == 40); // Scroll buffer size in coverflow mode is assumed to be 40 |
|
1657 QVERIFY(requestedIndexes.front() == model.index(0, 0)); |
|
1658 QVERIFY(requestedIndexes.back() == model.index(39, 0)); |
|
1659 requestedIndexes.clear(); |
|
1660 |
|
1661 // Move one item forward |
|
1662 model.moveItems(0, 20, 1); |
|
1663 QTest::qWait(1000); |
|
1664 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1665 |
|
1666 model.moveItems(0, 2, 1); |
|
1667 QTest::qWait(1000); |
|
1668 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1669 |
|
1670 model.moveItems(0, 39, 1); |
|
1671 QTest::qWait(1000); |
|
1672 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1673 |
|
1674 // Move many items forward |
|
1675 model.moveItems(0, 20, 5); |
|
1676 QTest::qWait(1000); |
|
1677 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1678 |
|
1679 // Move one item backward |
|
1680 model.moveItems(39, 20, 1); |
|
1681 QTest::qWait(1000); |
|
1682 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1683 |
|
1684 model.moveItems(39, 38, 1); |
|
1685 QTest::qWait(1000); |
|
1686 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1687 |
|
1688 model.moveItems(39, 0, 1); |
|
1689 QTest::qWait(1000); |
|
1690 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1691 |
|
1692 // Move many items backward |
|
1693 model.moveItems(30, 20, 10); |
|
1694 QTest::qWait(1000); |
|
1695 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1696 |
|
1697 // This should do nothing |
|
1698 model.moveItems(20, 20, 1); |
|
1699 QTest::qWait(1000); |
|
1700 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1701 |
|
1702 // Move items from the border of the buffer forward |
|
1703 model.moveItems(35, 50, 10); |
|
1704 QTest::qWait(1000); |
|
1705 QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the moved ones |
|
1706 QVERIFY(requestedIndexes.front() == model.index(35, 0)); |
|
1707 QVERIFY(requestedIndexes.back() == model.index(39, 0)); |
|
1708 requestedIndexes.clear(); |
|
1709 |
|
1710 // Move items from the border of the buffer backward |
|
1711 model.moveItems(35, 20, 10); |
|
1712 QTest::qWait(1000); |
|
1713 QVERIFY(requestedIndexes.count() == 5); // Items that were originally outside of buffer are fetched |
|
1714 QVERIFY(requestedIndexes.front() == model.index(25, 0)); |
|
1715 QVERIFY(requestedIndexes.back() == model.index(29, 0)); |
|
1716 requestedIndexes.clear(); |
|
1717 |
|
1718 // Move items from the buffer outside it |
|
1719 model.moveItems(20, 90, 10); |
|
1720 QTest::qWait(1000); |
|
1721 QVERIFY(requestedIndexes.count() == 10); // New items are fetched to replace the moved ones |
|
1722 QVERIFY(requestedIndexes.front() == model.index(30, 0)); |
|
1723 QVERIFY(requestedIndexes.back() == model.index(39, 0)); |
|
1724 requestedIndexes.clear(); |
|
1725 |
|
1726 // Move items from outside the buffer inside it |
|
1727 model.moveItems(90, 20, 10); |
|
1728 QTest::qWait(1000); |
|
1729 QVERIFY(requestedIndexes.count() == 10); // Moved items are fetched |
|
1730 QVERIFY(requestedIndexes.front() == model.index(20, 0)); |
|
1731 QVERIFY(requestedIndexes.back() == model.index(29, 0)); |
|
1732 requestedIndexes.clear(); |
|
1733 |
|
1734 // Move buffer to the end of items |
|
1735 mWidget->scrollTo(model.index(119, 0)); |
|
1736 QTest::qWait(1000); |
|
1737 requestedIndexes.clear(); |
|
1738 |
|
1739 // Move one item forward |
|
1740 model.moveItems(80, 100, 1); |
|
1741 QTest::qWait(1000); |
|
1742 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1743 |
|
1744 model.moveItems(80, 82, 1); |
|
1745 QTest::qWait(1000); |
|
1746 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1747 |
|
1748 model.moveItems(80, 119, 1); |
|
1749 QTest::qWait(1000); |
|
1750 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1751 |
|
1752 // Move many items forward |
|
1753 model.moveItems(80, 100, 5); |
|
1754 QTest::qWait(1000); |
|
1755 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1756 |
|
1757 // Move one item backward |
|
1758 model.moveItems(119, 100, 1); |
|
1759 QTest::qWait(1000); |
|
1760 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1761 |
|
1762 model.moveItems(119, 118, 1); |
|
1763 QTest::qWait(1000); |
|
1764 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1765 |
|
1766 model.moveItems(119, 80, 1); |
|
1767 QTest::qWait(1000); |
|
1768 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1769 |
|
1770 // Move many items backward |
|
1771 model.moveItems(110, 95, 10); |
|
1772 QTest::qWait(1000); |
|
1773 QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer |
|
1774 |
|
1775 // Move items from the border of the buffer backward |
|
1776 model.moveItems(75, 60, 10); |
|
1777 QTest::qWait(1000); |
|
1778 QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the moved ones |
|
1779 QVERIFY(requestedIndexes.front() == model.index(80, 0)); |
|
1780 QVERIFY(requestedIndexes.back() == model.index(84, 0)); |
|
1781 requestedIndexes.clear(); |
|
1782 |
|
1783 // Move items from the border of the buffer forward |
|
1784 model.moveItems(75, 100, 10); |
|
1785 QTest::qWait(1000); |
|
1786 QVERIFY(requestedIndexes.count() == 5); // Items that were originally outside of buffer are fetched |
|
1787 QVERIFY(requestedIndexes.front() == model.index(100, 0)); |
|
1788 QVERIFY(requestedIndexes.back() == model.index(104, 0)); |
|
1789 requestedIndexes.clear(); |
|
1790 |
|
1791 // Move items from the buffer outside it |
|
1792 model.moveItems(100, 10, 10); |
|
1793 QTest::qWait(1000); |
|
1794 QVERIFY(requestedIndexes.count() == 10); // New items are fetched to replace the moved ones |
|
1795 QVERIFY(requestedIndexes.front() == model.index(80, 0)); |
|
1796 QVERIFY(requestedIndexes.back() == model.index(89, 0)); |
|
1797 requestedIndexes.clear(); |
|
1798 |
|
1799 // Move items from outside the buffer inside it |
|
1800 model.moveItems(10, 100, 10); |
|
1801 QTest::qWait(1000); |
|
1802 QVERIFY(requestedIndexes.count() == 10); // Moved items are fetched |
|
1803 QVERIFY(requestedIndexes.front() == model.index(100, 0)); |
|
1804 QVERIFY(requestedIndexes.back() == model.index(109, 0)); |
|
1805 requestedIndexes.clear(); |
|
1806 |
|
1807 // Move buffer to the middle of items |
|
1808 mWidget->scrollTo(model.index(60, 0)); |
|
1809 QTest::qWait(1000); |
|
1810 requestedIndexes.clear(); |
|
1811 |
|
1812 // Move items over the whole buffer forward |
|
1813 model.moveItems(35, 110, 50); |
|
1814 QTest::qWait(1000); |
|
1815 QVERIFY(requestedIndexes.count() == 40); // Whole buffer is updated |
|
1816 QVERIFY(requestedIndexes.front() == model.index(40, 0)); |
|
1817 QVERIFY(requestedIndexes.back() == model.index(79, 0)); |
|
1818 |
|
1819 // Move items over the whole buffer backward |
|
1820 model.moveItems(35, 10, 50); |
|
1821 QTest::qWait(1000); |
|
1822 QVERIFY(requestedIndexes.count() == 40); // Whole buffer is updated |
|
1823 QVERIFY(requestedIndexes.front() == model.index(40, 0)); |
|
1824 QVERIFY(requestedIndexes.back() == model.index(79, 0)); |
|
1825 |
|
1826 QTest::qWait(2000); |
|
1827 |
|
1828 delete mWindow; |
|
1829 mWindow = 0; |
|
1830 } |
|
1831 |
|
1832 #ifdef _UNITTEST_GANESWIDGETS_LOG_TO_C_ |
|
1833 int main (int argc, char* argv[]) |
|
1834 { |
|
1835 HbApplication app(argc, argv); |
|
1836 TestGanesWidgets tc; |
|
1837 // int c = 3; |
|
1838 // char* v[] = {argv[0], "-o", "c:/test.txt"}; |
|
1839 return QTest::qExec(&tc, argc, argv); |
|
1840 // return QTest::qExec(&tc, c, v); |
|
1841 } |
|
1842 #else |
|
1843 QTEST_MAIN(TestGanesWidgets) |
|
1844 #endif |
|
1845 |
|
1846 #include "unittest_ganeswidgets.moc" |
|
1847 |
|
1848 // EOF |