1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
41 #include <QtTest/QtTest>
42 #include <private/qlistmodelinterface_p.h>
43 #include <qdeclarativeview.h>
44 #include <qdeclarativeengine.h>
45 #include <private/qdeclarativerectangle_p.h>
46 #include <private/qdeclarativepositioners_p.h>
47 #include <private/qdeclarativetransition_p.h>
48 #include <private/qdeclarativeitem_p.h>
49 #include <qdeclarativeexpression.h>
50 #include <QtGui/qgraphicswidget.h>
51 #include "../../../shared/util.h"
54 // In Symbian OS test data is located in applications private dir
58 class tst_QDeclarativePositioners : public QObject
62 tst_QDeclarativePositioners();
65 void test_horizontal();
66 void test_horizontal_rtl();
67 void test_horizontal_spacing();
68 void test_horizontal_spacing_rightToLeft();
69 void test_horizontal_animated();
70 void test_horizontal_animated_rightToLeft();
72 void test_vertical_spacing();
73 void test_vertical_animated();
75 void test_grid_topToBottom();
76 void test_grid_rightToLeft();
77 void test_grid_spacing();
78 void test_grid_animated();
79 void test_grid_animated_rightToLeft();
80 void test_grid_zero_columns();
81 void test_propertychanges();
84 void test_flow_rightToLeft();
85 void test_flow_topToBottom();
86 void test_flow_resize();
87 void test_flow_resize_rightToLeft();
88 void test_flow_implicit_resize();
89 void test_conflictinganchors();
90 void test_vertical_qgraphicswidget();
91 void test_mirroring();
92 void testQtQuick11Attributes();
93 void testQtQuick11Attributes_data();
95 QDeclarativeView *createView(const QString &filename);
98 tst_QDeclarativePositioners::tst_QDeclarativePositioners()
102 void tst_QDeclarativePositioners::test_horizontal()
104 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal.qml");
106 canvas->rootObject()->setProperty("testRightToLeft", false);
108 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
111 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
114 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
117 QCOMPARE(one->x(), 0.0);
118 QCOMPARE(one->y(), 0.0);
119 QCOMPARE(two->x(), 50.0);
120 QCOMPARE(two->y(), 0.0);
121 QCOMPARE(three->x(), 70.0);
122 QCOMPARE(three->y(), 0.0);
124 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
125 QCOMPARE(row->width(), 110.0);
126 QCOMPARE(row->height(), 50.0);
131 void tst_QDeclarativePositioners::test_horizontal_rtl()
133 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal.qml");
135 canvas->rootObject()->setProperty("testRightToLeft", true);
137 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
140 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
143 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
146 QCOMPARE(one->x(), 60.0);
147 QCOMPARE(one->y(), 0.0);
148 QCOMPARE(two->x(), 40.0);
149 QCOMPARE(two->y(), 0.0);
150 QCOMPARE(three->x(), 0.0);
151 QCOMPARE(three->y(), 0.0);
153 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
154 QCOMPARE(row->width(), 110.0);
155 QCOMPARE(row->height(), 50.0);
157 // Change the width of the row and check that items stay to the right
159 QCOMPARE(one->x(), 150.0);
160 QCOMPARE(one->y(), 0.0);
161 QCOMPARE(two->x(), 130.0);
162 QCOMPARE(two->y(), 0.0);
163 QCOMPARE(three->x(), 90.0);
164 QCOMPARE(three->y(), 0.0);
169 void tst_QDeclarativePositioners::test_horizontal_spacing()
171 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml");
173 canvas->rootObject()->setProperty("testRightToLeft", false);
175 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
178 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
181 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
184 QCOMPARE(one->x(), 0.0);
185 QCOMPARE(one->y(), 0.0);
186 QCOMPARE(two->x(), 60.0);
187 QCOMPARE(two->y(), 0.0);
188 QCOMPARE(three->x(), 90.0);
189 QCOMPARE(three->y(), 0.0);
191 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
192 QCOMPARE(row->width(), 130.0);
193 QCOMPARE(row->height(), 50.0);
198 void tst_QDeclarativePositioners::test_horizontal_spacing_rightToLeft()
200 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml");
202 canvas->rootObject()->setProperty("testRightToLeft", true);
204 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
207 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
210 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
213 QCOMPARE(one->x(), 80.0);
214 QCOMPARE(one->y(), 0.0);
215 QCOMPARE(two->x(), 50.0);
216 QCOMPARE(two->y(), 0.0);
217 QCOMPARE(three->x(), 00.0);
218 QCOMPARE(three->y(), 0.0);
220 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
221 QCOMPARE(row->width(), 130.0);
222 QCOMPARE(row->height(), 50.0);
227 void tst_QDeclarativePositioners::test_horizontal_animated()
229 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-animated.qml");
231 canvas->rootObject()->setProperty("testRightToLeft", false);
233 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
236 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
239 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
242 //Note that they animate in
243 QCOMPARE(one->x(), -100.0);
244 QCOMPARE(two->x(), -100.0);
245 QCOMPARE(three->x(), -100.0);
247 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
249 QCOMPARE(row->width(), 100.0);
250 QCOMPARE(row->height(), 50.0);
252 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
253 //Note that this means the duration of the animation is NOT tested
255 QTRY_COMPARE(one->x(), 0.0);
256 QTRY_COMPARE(one->y(), 0.0);
257 QTRY_COMPARE(two->opacity(), 0.0);
258 QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet
259 QTRY_COMPARE(two->y(), 0.0);
260 QTRY_COMPARE(three->x(), 50.0);
261 QTRY_COMPARE(three->y(), 0.0);
264 two->setOpacity(1.0);
265 QCOMPARE(two->opacity(), 1.0);
267 // New size should be immediate
268 QCOMPARE(row->width(), 150.0);
269 QCOMPARE(row->height(), 50.0);
271 QTest::qWait(0);//Let the animation start
272 QCOMPARE(two->x(), -100.0);
273 QCOMPARE(three->x(), 50.0);
275 QTRY_COMPARE(two->x(), 50.0);
276 QTRY_COMPARE(three->x(), 100.0);
281 void tst_QDeclarativePositioners::test_horizontal_animated_rightToLeft()
283 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-animated.qml");
285 canvas->rootObject()->setProperty("testRightToLeft", true);
287 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
290 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
293 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
296 //Note that they animate in
297 QCOMPARE(one->x(), -100.0);
298 QCOMPARE(two->x(), -100.0);
299 QCOMPARE(three->x(), -100.0);
301 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
303 QCOMPARE(row->width(), 100.0);
304 QCOMPARE(row->height(), 50.0);
306 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
307 //Note that this means the duration of the animation is NOT tested
309 QTRY_COMPARE(one->x(), 50.0);
310 QTRY_COMPARE(one->y(), 0.0);
311 QTRY_COMPARE(two->opacity(), 0.0);
312 QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet
313 QTRY_COMPARE(two->y(), 0.0);
314 QTRY_COMPARE(three->x(), 0.0);
315 QTRY_COMPARE(three->y(), 0.0);
318 two->setOpacity(1.0);
319 QCOMPARE(two->opacity(), 1.0);
321 // New size should be immediate
322 QCOMPARE(row->width(), 150.0);
323 QCOMPARE(row->height(), 50.0);
325 QTest::qWait(0);//Let the animation start
326 QCOMPARE(one->x(), 50.0);
327 QCOMPARE(two->x(), -100.0);
329 QTRY_COMPARE(one->x(), 100.0);
330 QTRY_COMPARE(two->x(), 50.0);
335 void tst_QDeclarativePositioners::test_vertical()
337 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical.qml");
339 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
342 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
345 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
348 QCOMPARE(one->x(), 0.0);
349 QCOMPARE(one->y(), 0.0);
350 QCOMPARE(two->x(), 0.0);
351 QCOMPARE(two->y(), 50.0);
352 QCOMPARE(three->x(), 0.0);
353 QCOMPARE(three->y(), 60.0);
355 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
357 QCOMPARE(column->height(), 80.0);
358 QCOMPARE(column->width(), 50.0);
363 void tst_QDeclarativePositioners::test_vertical_spacing()
365 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical-spacing.qml");
367 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
370 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
373 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
376 QCOMPARE(one->x(), 0.0);
377 QCOMPARE(one->y(), 0.0);
378 QCOMPARE(two->x(), 0.0);
379 QCOMPARE(two->y(), 60.0);
380 QCOMPARE(three->x(), 0.0);
381 QCOMPARE(three->y(), 80.0);
383 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
384 QCOMPARE(column->height(), 100.0);
385 QCOMPARE(column->width(), 50.0);
390 void tst_QDeclarativePositioners::test_vertical_animated()
392 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical-animated.qml");
394 //Note that they animate in
395 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
397 QCOMPARE(one->y(), -100.0);
399 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
401 QCOMPARE(two->y(), -100.0);
403 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
405 QCOMPARE(three->y(), -100.0);
407 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
409 QCOMPARE(column->height(), 100.0);
410 QCOMPARE(column->width(), 50.0);
412 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
413 //Note that this means the duration of the animation is NOT tested
415 QTRY_COMPARE(one->y(), 0.0);
416 QTRY_COMPARE(one->x(), 0.0);
417 QTRY_COMPARE(two->opacity(), 0.0);
418 QTRY_COMPARE(two->y(), -100.0);//Not 'in' yet
419 QTRY_COMPARE(two->x(), 0.0);
420 QTRY_COMPARE(three->y(), 50.0);
421 QTRY_COMPARE(three->x(), 0.0);
424 two->setOpacity(1.0);
425 QTRY_COMPARE(two->opacity(), 1.0);
426 QCOMPARE(column->height(), 150.0);
427 QCOMPARE(column->width(), 50.0);
428 QTest::qWait(0);//Let the animation start
429 QCOMPARE(two->y(), -100.0);
430 QCOMPARE(three->y(), 50.0);
432 QTRY_COMPARE(two->y(), 50.0);
433 QTRY_COMPARE(three->y(), 100.0);
438 void tst_QDeclarativePositioners::test_grid()
440 QDeclarativeView *canvas = createView(SRCDIR "/data/gridtest.qml");
442 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
444 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
446 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
448 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
450 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
453 QCOMPARE(one->x(), 0.0);
454 QCOMPARE(one->y(), 0.0);
455 QCOMPARE(two->x(), 50.0);
456 QCOMPARE(two->y(), 0.0);
457 QCOMPARE(three->x(), 70.0);
458 QCOMPARE(three->y(), 0.0);
459 QCOMPARE(four->x(), 0.0);
460 QCOMPARE(four->y(), 50.0);
461 QCOMPARE(five->x(), 50.0);
462 QCOMPARE(five->y(), 50.0);
464 QDeclarativeGrid *grid = canvas->rootObject()->findChild<QDeclarativeGrid*>("grid");
465 QCOMPARE(grid->flow(), QDeclarativeGrid::LeftToRight);
466 QCOMPARE(grid->width(), 100.0);
467 QCOMPARE(grid->height(), 100.0);
472 void tst_QDeclarativePositioners::test_grid_topToBottom()
474 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-toptobottom.qml");
476 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
478 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
480 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
482 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
484 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
487 QCOMPARE(one->x(), 0.0);
488 QCOMPARE(one->y(), 0.0);
489 QCOMPARE(two->x(), 0.0);
490 QCOMPARE(two->y(), 50.0);
491 QCOMPARE(three->x(), 0.0);
492 QCOMPARE(three->y(), 100.0);
493 QCOMPARE(four->x(), 50.0);
494 QCOMPARE(four->y(), 0.0);
495 QCOMPARE(five->x(), 50.0);
496 QCOMPARE(five->y(), 50.0);
498 QDeclarativeGrid *grid = canvas->rootObject()->findChild<QDeclarativeGrid*>("grid");
499 QCOMPARE(grid->flow(), QDeclarativeGrid::TopToBottom);
500 QCOMPARE(grid->width(), 100.0);
501 QCOMPARE(grid->height(), 120.0);
506 void tst_QDeclarativePositioners::test_grid_rightToLeft()
508 QDeclarativeView *canvas = createView(SRCDIR "/data/gridtest.qml");
510 canvas->rootObject()->setProperty("testRightToLeft", true);
512 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
514 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
516 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
518 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
520 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
523 QCOMPARE(one->x(), 50.0);
524 QCOMPARE(one->y(), 0.0);
525 QCOMPARE(two->x(), 30.0);
526 QCOMPARE(two->y(), 0.0);
527 QCOMPARE(three->x(), 0.0);
528 QCOMPARE(three->y(), 0.0);
529 QCOMPARE(four->x(), 50.0);
530 QCOMPARE(four->y(), 50.0);
531 QCOMPARE(five->x(), 40.0);
532 QCOMPARE(five->y(), 50.0);
534 QDeclarativeGrid *grid = canvas->rootObject()->findChild<QDeclarativeGrid*>("grid");
535 QCOMPARE(grid->layoutDirection(), Qt::RightToLeft);
536 QCOMPARE(grid->width(), 100.0);
537 QCOMPARE(grid->height(), 100.0);
539 // Change the width of the grid and check that items stay to the right
541 QCOMPARE(one->x(), 150.0);
542 QCOMPARE(one->y(), 0.0);
543 QCOMPARE(two->x(), 130.0);
544 QCOMPARE(two->y(), 0.0);
545 QCOMPARE(three->x(), 100.0);
546 QCOMPARE(three->y(), 0.0);
547 QCOMPARE(four->x(), 150.0);
548 QCOMPARE(four->y(), 50.0);
549 QCOMPARE(five->x(), 140.0);
550 QCOMPARE(five->y(), 50.0);
555 void tst_QDeclarativePositioners::test_grid_spacing()
557 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-spacing.qml");
559 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
561 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
563 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
565 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
567 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
570 QCOMPARE(one->x(), 0.0);
571 QCOMPARE(one->y(), 0.0);
572 QCOMPARE(two->x(), 54.0);
573 QCOMPARE(two->y(), 0.0);
574 QCOMPARE(three->x(), 78.0);
575 QCOMPARE(three->y(), 0.0);
576 QCOMPARE(four->x(), 0.0);
577 QCOMPARE(four->y(), 54.0);
578 QCOMPARE(five->x(), 54.0);
579 QCOMPARE(five->y(), 54.0);
581 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
582 QCOMPARE(grid->width(), 128.0);
583 QCOMPARE(grid->height(), 104.0);
588 void tst_QDeclarativePositioners::test_grid_animated()
590 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-animated.qml");
592 canvas->rootObject()->setProperty("testRightToLeft", false);
594 //Note that all animate in
595 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
597 QCOMPARE(one->x(), -100.0);
598 QCOMPARE(one->y(), -100.0);
600 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
602 QCOMPARE(two->x(), -100.0);
603 QCOMPARE(two->y(), -100.0);
605 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
607 QCOMPARE(three->x(), -100.0);
608 QCOMPARE(three->y(), -100.0);
610 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
612 QCOMPARE(four->x(), -100.0);
613 QCOMPARE(four->y(), -100.0);
615 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
617 QCOMPARE(five->x(), -100.0);
618 QCOMPARE(five->y(), -100.0);
620 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
622 QCOMPARE(grid->width(), 150.0);
623 QCOMPARE(grid->height(), 100.0);
625 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
626 //Note that this means the duration of the animation is NOT tested
628 QTRY_COMPARE(one->y(), 0.0);
629 QTRY_COMPARE(one->x(), 0.0);
630 QTRY_COMPARE(two->opacity(), 0.0);
631 QTRY_COMPARE(two->y(), -100.0);
632 QTRY_COMPARE(two->x(), -100.0);
633 QTRY_COMPARE(three->y(), 0.0);
634 QTRY_COMPARE(three->x(), 50.0);
635 QTRY_COMPARE(four->y(), 0.0);
636 QTRY_COMPARE(four->x(), 100.0);
637 QTRY_COMPARE(five->y(), 50.0);
638 QTRY_COMPARE(five->x(), 0.0);
641 two->setOpacity(1.0);
642 QCOMPARE(two->opacity(), 1.0);
643 QCOMPARE(grid->width(), 150.0);
644 QCOMPARE(grid->height(), 100.0);
645 QTest::qWait(0);//Let the animation start
646 QCOMPARE(two->x(), -100.0);
647 QCOMPARE(two->y(), -100.0);
648 QCOMPARE(one->x(), 0.0);
649 QCOMPARE(one->y(), 0.0);
650 QCOMPARE(three->x(), 50.0);
651 QCOMPARE(three->y(), 0.0);
652 QCOMPARE(four->x(), 100.0);
653 QCOMPARE(four->y(), 0.0);
654 QCOMPARE(five->x(), 0.0);
655 QCOMPARE(five->y(), 50.0);
656 //Let the animation complete
657 QTRY_COMPARE(two->x(), 50.0);
658 QTRY_COMPARE(two->y(), 0.0);
659 QTRY_COMPARE(one->x(), 0.0);
660 QTRY_COMPARE(one->y(), 0.0);
661 QTRY_COMPARE(three->x(), 100.0);
662 QTRY_COMPARE(three->y(), 0.0);
663 QTRY_COMPARE(four->x(), 0.0);
664 QTRY_COMPARE(four->y(), 50.0);
665 QTRY_COMPARE(five->x(), 50.0);
666 QTRY_COMPARE(five->y(), 50.0);
671 void tst_QDeclarativePositioners::test_grid_animated_rightToLeft()
673 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-animated.qml");
675 canvas->rootObject()->setProperty("testRightToLeft", true);
677 //Note that all animate in
678 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
680 QCOMPARE(one->x(), -100.0);
681 QCOMPARE(one->y(), -100.0);
683 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
685 QCOMPARE(two->x(), -100.0);
686 QCOMPARE(two->y(), -100.0);
688 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
690 QCOMPARE(three->x(), -100.0);
691 QCOMPARE(three->y(), -100.0);
693 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
695 QCOMPARE(four->x(), -100.0);
696 QCOMPARE(four->y(), -100.0);
698 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
700 QCOMPARE(five->x(), -100.0);
701 QCOMPARE(five->y(), -100.0);
703 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
705 QCOMPARE(grid->width(), 150.0);
706 QCOMPARE(grid->height(), 100.0);
708 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
709 //Note that this means the duration of the animation is NOT tested
711 QTRY_COMPARE(one->y(), 0.0);
712 QTRY_COMPARE(one->x(), 100.0);
713 QTRY_COMPARE(two->opacity(), 0.0);
714 QTRY_COMPARE(two->y(), -100.0);
715 QTRY_COMPARE(two->x(), -100.0);
716 QTRY_COMPARE(three->y(), 0.0);
717 QTRY_COMPARE(three->x(), 50.0);
718 QTRY_COMPARE(four->y(), 0.0);
719 QTRY_COMPARE(four->x(), 0.0);
720 QTRY_COMPARE(five->y(), 50.0);
721 QTRY_COMPARE(five->x(), 100.0);
724 two->setOpacity(1.0);
725 QCOMPARE(two->opacity(), 1.0);
726 QCOMPARE(grid->width(), 150.0);
727 QCOMPARE(grid->height(), 100.0);
728 QTest::qWait(0);//Let the animation start
729 QCOMPARE(two->x(), -100.0);
730 QCOMPARE(two->y(), -100.0);
731 QCOMPARE(one->x(), 100.0);
732 QCOMPARE(one->y(), 0.0);
733 QCOMPARE(three->x(), 50.0);
734 QCOMPARE(three->y(), 0.0);
735 QCOMPARE(four->x(), 0.0);
736 QCOMPARE(four->y(), 0.0);
737 QCOMPARE(five->x(), 100.0);
738 QCOMPARE(five->y(), 50.0);
739 //Let the animation complete
740 QTRY_COMPARE(two->x(), 50.0);
741 QTRY_COMPARE(two->y(), 0.0);
742 QTRY_COMPARE(one->x(), 100.0);
743 QTRY_COMPARE(one->y(), 0.0);
744 QTRY_COMPARE(three->x(), 0.0);
745 QTRY_COMPARE(three->y(), 0.0);
746 QTRY_COMPARE(four->x(), 100.0);
747 QTRY_COMPARE(four->y(), 50.0);
748 QTRY_COMPARE(five->x(), 50.0);
749 QTRY_COMPARE(five->y(), 50.0);
754 void tst_QDeclarativePositioners::test_grid_zero_columns()
756 QDeclarativeView *canvas = createView(SRCDIR "/data/gridzerocolumns.qml");
758 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
760 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
762 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
764 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
766 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
769 QCOMPARE(one->x(), 0.0);
770 QCOMPARE(one->y(), 0.0);
771 QCOMPARE(two->x(), 50.0);
772 QCOMPARE(two->y(), 0.0);
773 QCOMPARE(three->x(), 70.0);
774 QCOMPARE(three->y(), 0.0);
775 QCOMPARE(four->x(), 120.0);
776 QCOMPARE(four->y(), 0.0);
777 QCOMPARE(five->x(), 0.0);
778 QCOMPARE(five->y(), 50.0);
780 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
781 QCOMPARE(grid->width(), 170.0);
782 QCOMPARE(grid->height(), 60.0);
787 void tst_QDeclarativePositioners::test_propertychanges()
789 QDeclarativeView *canvas = createView(SRCDIR "/data/propertychangestest.qml");
791 QDeclarativeGrid *grid = qobject_cast<QDeclarativeGrid*>(canvas->rootObject());
793 QDeclarativeTransition *rowTransition = canvas->rootObject()->findChild<QDeclarativeTransition*>("rowTransition");
794 QDeclarativeTransition *columnTransition = canvas->rootObject()->findChild<QDeclarativeTransition*>("columnTransition");
796 QSignalSpy addSpy(grid, SIGNAL(addChanged()));
797 QSignalSpy moveSpy(grid, SIGNAL(moveChanged()));
798 QSignalSpy columnsSpy(grid, SIGNAL(columnsChanged()));
799 QSignalSpy rowsSpy(grid, SIGNAL(rowsChanged()));
802 QVERIFY(rowTransition);
803 QVERIFY(columnTransition);
804 QCOMPARE(grid->add(), columnTransition);
805 QCOMPARE(grid->move(), columnTransition);
806 QCOMPARE(grid->columns(), 4);
807 QCOMPARE(grid->rows(), -1);
809 grid->setAdd(rowTransition);
810 grid->setMove(rowTransition);
811 QCOMPARE(grid->add(), rowTransition);
812 QCOMPARE(grid->move(), rowTransition);
813 QCOMPARE(addSpy.count(),1);
814 QCOMPARE(moveSpy.count(),1);
816 grid->setAdd(rowTransition);
817 grid->setMove(rowTransition);
818 QCOMPARE(addSpy.count(),1);
819 QCOMPARE(moveSpy.count(),1);
823 QCOMPARE(addSpy.count(),2);
824 QCOMPARE(moveSpy.count(),2);
826 grid->setColumns(-1);
828 QCOMPARE(grid->columns(), -1);
829 QCOMPARE(grid->rows(), 3);
830 QCOMPARE(columnsSpy.count(),1);
831 QCOMPARE(rowsSpy.count(),1);
833 grid->setColumns(-1);
835 QCOMPARE(columnsSpy.count(),1);
836 QCOMPARE(rowsSpy.count(),1);
840 QCOMPARE(columnsSpy.count(),2);
841 QCOMPARE(rowsSpy.count(),2);
846 void tst_QDeclarativePositioners::test_repeater()
848 QDeclarativeView *canvas = createView(SRCDIR "/data/repeatertest.qml");
850 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
853 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
856 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
859 QCOMPARE(one->x(), 0.0);
860 QCOMPARE(one->y(), 0.0);
861 QCOMPARE(two->x(), 50.0);
862 QCOMPARE(two->y(), 0.0);
863 QCOMPARE(three->x(), 100.0);
864 QCOMPARE(three->y(), 0.0);
869 void tst_QDeclarativePositioners::test_flow()
871 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
873 canvas->rootObject()->setProperty("testRightToLeft", false);
875 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
877 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
879 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
881 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
883 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
886 QCOMPARE(one->x(), 0.0);
887 QCOMPARE(one->y(), 0.0);
888 QCOMPARE(two->x(), 50.0);
889 QCOMPARE(two->y(), 0.0);
890 QCOMPARE(three->x(), 0.0);
891 QCOMPARE(three->y(), 50.0);
892 QCOMPARE(four->x(), 0.0);
893 QCOMPARE(four->y(), 70.0);
894 QCOMPARE(five->x(), 50.0);
895 QCOMPARE(five->y(), 70.0);
897 QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
899 QCOMPARE(flow->width(), 90.0);
900 QCOMPARE(flow->height(), 120.0);
905 void tst_QDeclarativePositioners::test_flow_rightToLeft()
907 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
909 canvas->rootObject()->setProperty("testRightToLeft", true);
911 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
913 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
915 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
917 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
919 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
922 QCOMPARE(one->x(), 40.0);
923 QCOMPARE(one->y(), 0.0);
924 QCOMPARE(two->x(), 20.0);
925 QCOMPARE(two->y(), 0.0);
926 QCOMPARE(three->x(), 40.0);
927 QCOMPARE(three->y(), 50.0);
928 QCOMPARE(four->x(), 40.0);
929 QCOMPARE(four->y(), 70.0);
930 QCOMPARE(five->x(), 30.0);
931 QCOMPARE(five->y(), 70.0);
933 QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
935 QCOMPARE(flow->width(), 90.0);
936 QCOMPARE(flow->height(), 120.0);
941 void tst_QDeclarativePositioners::test_flow_topToBottom()
943 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest-toptobottom.qml");
945 canvas->rootObject()->setProperty("testRightToLeft", false);
947 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
949 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
951 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
953 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
955 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
958 QCOMPARE(one->x(), 0.0);
959 QCOMPARE(one->y(), 0.0);
960 QCOMPARE(two->x(), 50.0);
961 QCOMPARE(two->y(), 0.0);
962 QCOMPARE(three->x(), 50.0);
963 QCOMPARE(three->y(), 50.0);
964 QCOMPARE(four->x(), 100.0);
965 QCOMPARE(four->y(), 00.0);
966 QCOMPARE(five->x(), 100.0);
967 QCOMPARE(five->y(), 50.0);
969 QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
971 QCOMPARE(flow->height(), 90.0);
972 QCOMPARE(flow->width(), 150.0);
974 canvas->rootObject()->setProperty("testRightToLeft", true);
977 QCOMPARE(flow->height(), 90.0);
978 QCOMPARE(flow->width(), 150.0);
980 QCOMPARE(one->x(), 100.0);
981 QCOMPARE(one->y(), 0.0);
982 QCOMPARE(two->x(), 80.0);
983 QCOMPARE(two->y(), 0.0);
984 QCOMPARE(three->x(), 50.0);
985 QCOMPARE(three->y(), 50.0);
986 QCOMPARE(four->x(), 0.0);
987 QCOMPARE(four->y(), 0.0);
988 QCOMPARE(five->x(), 40.0);
989 QCOMPARE(five->y(), 50.0);
994 void tst_QDeclarativePositioners::test_flow_resize()
996 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
998 QDeclarativeItem *root = qobject_cast<QDeclarativeItem*>(canvas->rootObject());
1000 root->setWidth(125);
1001 root->setProperty("testRightToLeft", false);
1003 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
1005 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
1007 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
1008 QVERIFY(three != 0);
1009 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
1011 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
1014 QCOMPARE(one->x(), 0.0);
1015 QCOMPARE(one->y(), 0.0);
1016 QCOMPARE(two->x(), 50.0);
1017 QCOMPARE(two->y(), 0.0);
1018 QCOMPARE(three->x(), 70.0);
1019 QCOMPARE(three->y(), 0.0);
1020 QCOMPARE(four->x(), 0.0);
1021 QCOMPARE(four->y(), 50.0);
1022 QCOMPARE(five->x(), 50.0);
1023 QCOMPARE(five->y(), 50.0);
1028 void tst_QDeclarativePositioners::test_flow_resize_rightToLeft()
1030 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
1032 QDeclarativeItem *root = qobject_cast<QDeclarativeItem*>(canvas->rootObject());
1034 root->setWidth(125);
1035 root->setProperty("testRightToLeft", true);
1037 QDeclarativeRectangle *one = canvas->rootObject()->findChild<QDeclarativeRectangle*>("one");
1039 QDeclarativeRectangle *two = canvas->rootObject()->findChild<QDeclarativeRectangle*>("two");
1041 QDeclarativeRectangle *three = canvas->rootObject()->findChild<QDeclarativeRectangle*>("three");
1042 QVERIFY(three != 0);
1043 QDeclarativeRectangle *four = canvas->rootObject()->findChild<QDeclarativeRectangle*>("four");
1045 QDeclarativeRectangle *five = canvas->rootObject()->findChild<QDeclarativeRectangle*>("five");
1048 QCOMPARE(one->x(), 75.0);
1049 QCOMPARE(one->y(), 0.0);
1050 QCOMPARE(two->x(), 55.0);
1051 QCOMPARE(two->y(), 0.0);
1052 QCOMPARE(three->x(), 5.0);
1053 QCOMPARE(three->y(), 0.0);
1054 QCOMPARE(four->x(), 75.0);
1055 QCOMPARE(four->y(), 50.0);
1056 QCOMPARE(five->x(), 65.0);
1057 QCOMPARE(five->y(), 50.0);
1062 void tst_QDeclarativePositioners::test_flow_implicit_resize()
1064 QDeclarativeView *canvas = createView(SRCDIR "/data/flow-testimplicitsize.qml");
1065 QVERIFY(canvas->rootObject() != 0);
1067 QDeclarativeFlow *flow = canvas->rootObject()->findChild<QDeclarativeFlow*>("flow");
1070 QCOMPARE(flow->width(), 100.0);
1071 QCOMPARE(flow->height(), 120.0);
1073 canvas->rootObject()->setProperty("flowLayout", 0);
1074 QCOMPARE(flow->flow(), QDeclarativeFlow::LeftToRight);
1075 QCOMPARE(flow->width(), 220.0);
1076 QCOMPARE(flow->height(), 50.0);
1078 canvas->rootObject()->setProperty("flowLayout", 1);
1079 QCOMPARE(flow->flow(), QDeclarativeFlow::TopToBottom);
1080 QCOMPARE(flow->width(), 100.0);
1081 QCOMPARE(flow->height(), 120.0);
1083 canvas->rootObject()->setProperty("flowLayout", 2);
1084 QCOMPARE(flow->layoutDirection(), Qt::RightToLeft);
1085 QCOMPARE(flow->width(), 220.0);
1086 QCOMPARE(flow->height(), 50.0);
1091 QString warningMessage;
1093 void interceptWarnings(QtMsgType type, const char *msg)
1096 warningMessage = msg;
1099 void tst_QDeclarativePositioners::test_conflictinganchors()
1101 QtMsgHandler oldMsgHandler = qInstallMsgHandler(interceptWarnings);
1102 QDeclarativeEngine engine;
1103 QDeclarativeComponent component(&engine);
1105 component.setData("import QtQuick 1.0\nColumn { Item {} }", QUrl::fromLocalFile(""));
1106 QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
1108 QVERIFY(warningMessage.isEmpty());
1110 component.setData("import QtQuick 1.0\nRow { Item {} }", QUrl::fromLocalFile(""));
1111 item = qobject_cast<QDeclarativeItem*>(component.create());
1113 QVERIFY(warningMessage.isEmpty());
1115 component.setData("import QtQuick 1.0\nGrid { Item {} }", QUrl::fromLocalFile(""));
1116 item = qobject_cast<QDeclarativeItem*>(component.create());
1118 QVERIFY(warningMessage.isEmpty());
1120 component.setData("import QtQuick 1.0\nFlow { Item {} }", QUrl::fromLocalFile(""));
1121 item = qobject_cast<QDeclarativeItem*>(component.create());
1123 QVERIFY(warningMessage.isEmpty());
1125 component.setData("import QtQuick 1.0\nColumn { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
1126 item = qobject_cast<QDeclarativeItem*>(component.create());
1128 QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
1129 warningMessage.clear();
1131 component.setData("import QtQuick 1.0\nColumn { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
1132 item = qobject_cast<QDeclarativeItem*>(component.create());
1134 QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
1135 warningMessage.clear();
1137 component.setData("import QtQuick 1.0\nColumn { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
1138 item = qobject_cast<QDeclarativeItem*>(component.create());
1140 QVERIFY(warningMessage.isEmpty());
1141 warningMessage.clear();
1143 component.setData("import QtQuick 1.0\nRow { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
1144 item = qobject_cast<QDeclarativeItem*>(component.create());
1146 QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
1147 warningMessage.clear();
1149 component.setData("import QtQuick 1.0\nRow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
1150 item = qobject_cast<QDeclarativeItem*>(component.create());
1152 QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
1153 warningMessage.clear();
1155 component.setData("import QtQuick 1.0\nRow { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
1156 item = qobject_cast<QDeclarativeItem*>(component.create());
1158 QVERIFY(warningMessage.isEmpty());
1159 warningMessage.clear();
1161 component.setData("import QtQuick 1.0\nGrid { Item { anchors.horizontalCenter: parent.horizontalCenter } }", QUrl::fromLocalFile(""));
1162 item = qobject_cast<QDeclarativeItem*>(component.create());
1164 QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
1165 warningMessage.clear();
1167 component.setData("import QtQuick 1.0\nGrid { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
1168 item = qobject_cast<QDeclarativeItem*>(component.create());
1170 QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
1171 warningMessage.clear();
1173 component.setData("import QtQuick 1.0\nFlow { Item { anchors.verticalCenter: parent.verticalCenter } }", QUrl::fromLocalFile(""));
1174 item = qobject_cast<QDeclarativeItem*>(component.create());
1176 QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
1178 component.setData("import QtQuick 1.0\nFlow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
1179 item = qobject_cast<QDeclarativeItem*>(component.create());
1181 QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
1182 qInstallMsgHandler(oldMsgHandler);
1185 void tst_QDeclarativePositioners::test_vertical_qgraphicswidget()
1187 QDeclarativeView *canvas = createView(SRCDIR "/data/verticalqgraphicswidget.qml");
1189 QGraphicsWidget *one = canvas->rootObject()->findChild<QGraphicsWidget*>("one");
1192 QGraphicsWidget *two = canvas->rootObject()->findChild<QGraphicsWidget*>("two");
1195 QGraphicsWidget *three = canvas->rootObject()->findChild<QGraphicsWidget*>("three");
1196 QVERIFY(three != 0);
1198 QCOMPARE(one->x(), 0.0);
1199 QCOMPARE(one->y(), 0.0);
1200 QCOMPARE(two->x(), 0.0);
1201 QCOMPARE(two->y(), 50.0);
1202 QCOMPARE(three->x(), 0.0);
1203 QCOMPARE(three->y(), 60.0);
1205 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
1207 QCOMPARE(column->height(), 80.0);
1208 QCOMPARE(column->width(), 50.0);
1210 two->resize(QSizeF(two->size().width(), 20.0));
1211 QCOMPARE(three->x(), 0.0);
1212 QCOMPARE(three->y(), 70.0);
1214 two->setOpacity(0.0);
1215 QCOMPARE(one->x(), 0.0);
1216 QCOMPARE(one->y(), 0.0);
1217 QCOMPARE(three->x(), 0.0);
1218 QCOMPARE(three->y(), 50.0);
1220 one->setVisible(false);
1221 QCOMPARE(three->x(), 0.0);
1222 QCOMPARE(three->y(), 0.0);
1227 void tst_QDeclarativePositioners::test_mirroring()
1229 QList<QString> qmlFiles;
1230 qmlFiles << "horizontal.qml" << "gridtest.qml" << "flowtest.qml";
1231 QList<QString> objectNames;
1232 objectNames << "one" << "two" << "three" << "four" << "five";
1234 foreach(const QString qmlFile, qmlFiles) {
1235 QDeclarativeView *canvasA = createView(QString(SRCDIR) + "/data/" + qmlFile);
1236 QDeclarativeItem *rootA = qobject_cast<QDeclarativeItem*>(canvasA->rootObject());
1238 QDeclarativeView *canvasB = createView(QString(SRCDIR) + "/data/" + qmlFile);
1239 QDeclarativeItem *rootB = qobject_cast<QDeclarativeItem*>(canvasB->rootObject());
1241 rootA->setProperty("testRightToLeft", true); // layoutDirection: Qt.RightToLeft
1244 foreach(const QString objectName, objectNames) {
1245 // horizontal.qml only has three items
1246 if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1248 QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1249 QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1250 QVERIFY(itemA->x() != itemB->x());
1253 QDeclarativeItemPrivate* rootPrivateB = QDeclarativeItemPrivate::get(rootB);
1255 rootPrivateB->effectiveLayoutMirror = true; // LayoutMirroring.enabled: true
1256 rootPrivateB->isMirrorImplicit = false;
1257 rootPrivateB->inheritMirrorFromItem = true; // LayoutMirroring.childrenInherit: true
1258 rootPrivateB->resolveLayoutMirror();
1261 foreach(const QString objectName, objectNames) {
1262 // horizontal.qml only has three items
1263 if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1265 QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1266 QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1267 QCOMPARE(itemA->x(), itemB->x());
1270 rootA->setProperty("testRightToLeft", false); // layoutDirection: Qt.LeftToRight
1271 rootB->setProperty("testRightToLeft", true); // layoutDirection: Qt.RightToLeft
1273 // LTR == RTL + mirror
1274 foreach(const QString objectName, objectNames) {
1275 // horizontal.qml only has three items
1276 if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1278 QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1279 QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1280 QCOMPARE(itemA->x(), itemB->x());
1287 void tst_QDeclarativePositioners::testQtQuick11Attributes()
1289 QFETCH(QString, code);
1290 QFETCH(QString, warning);
1291 QFETCH(QString, error);
1293 QDeclarativeEngine engine;
1296 QDeclarativeComponent valid(&engine);
1297 valid.setData("import QtQuick 1.1; " + code.toUtf8(), QUrl(""));
1298 obj = valid.create();
1300 QVERIFY(valid.errorString().isEmpty());
1303 QDeclarativeComponent invalid(&engine);
1304 invalid.setData("import QtQuick 1.0; " + code.toUtf8(), QUrl(""));
1305 QTest::ignoreMessage(QtWarningMsg, warning.toUtf8());
1306 obj = invalid.create();
1307 QCOMPARE(invalid.errorString(), error);
1311 void tst_QDeclarativePositioners::testQtQuick11Attributes_data()
1313 QTest::addColumn<QString>("code");
1314 QTest::addColumn<QString>("warning");
1315 QTest::addColumn<QString>("error");
1317 QTest::newRow("Flow.layoutDirection") << "Flow { layoutDirection: Qt.LeftToRight }"
1318 << "QDeclarativeComponent: Component is not ready"
1319 << ":1 \"Flow.layoutDirection\" is not available in QtQuick 1.0.\n";
1321 QTest::newRow("Row.layoutDirection") << "Row { layoutDirection: Qt.LeftToRight }"
1322 << "QDeclarativeComponent: Component is not ready"
1323 << ":1 \"Row.layoutDirection\" is not available in QtQuick 1.0.\n";
1325 QTest::newRow("Grid.layoutDirection") << "Grid { layoutDirection: Qt.LeftToRight }"
1326 << "QDeclarativeComponent: Component is not ready"
1327 << ":1 \"Grid.layoutDirection\" is not available in QtQuick 1.0.\n";
1330 QDeclarativeView *tst_QDeclarativePositioners::createView(const QString &filename)
1332 QDeclarativeView *canvas = new QDeclarativeView(0);
1334 canvas->setSource(QUrl::fromLocalFile(filename));
1340 QTEST_MAIN(tst_QDeclarativePositioners)
1342 #include "tst_qdeclarativepositioners.moc"