1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
41 #include <QtTest/QtTest>
42 #include <QtQuick1/qdeclarativeview.h>
43 #include <qdeclarativeengine.h>
44 #include <QtQuick1/private/qdeclarativerectangle_p.h>
45 #include <QtQuick1/private/qdeclarativepositioners_p.h>
46 #include <QtQuick1/private/qdeclarativetransition_p.h>
47 #include <QtQuick1/private/qdeclarativeitem_p.h>
48 #include <qdeclarativeexpression.h>
49 #include <QtWidgets/qgraphicswidget.h>
51 class tst_QDeclarativePositioners : public QObject
55 tst_QDeclarativePositioners();
58 void test_horizontal();
59 void test_horizontal_rtl();
60 void test_horizontal_spacing();
61 void test_horizontal_spacing_rightToLeft();
62 void test_horizontal_animated();
63 void test_horizontal_animated_rightToLeft();
65 void test_vertical_spacing();
66 void test_vertical_animated();
68 void test_grid_topToBottom();
69 void test_grid_rightToLeft();
70 void test_grid_spacing();
71 void test_grid_animated();
72 void test_grid_animated_rightToLeft();
73 void test_grid_zero_columns();
74 void test_propertychanges();
77 void test_flow_rightToLeft();
78 void test_flow_topToBottom();
79 void test_flow_resize();
80 void test_flow_resize_rightToLeft();
81 void test_flow_implicit_resize();
82 void test_conflictinganchors();
83 void test_vertical_qgraphicswidget();
84 void test_mirroring();
85 void testQtQuick11Attributes();
86 void testQtQuick11Attributes_data();
88 QDeclarativeView *createView(const QString &filename);
91 tst_QDeclarativePositioners::tst_QDeclarativePositioners()
95 void tst_QDeclarativePositioners::test_horizontal()
97 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal.qml");
99 canvas->rootObject()->setProperty("testRightToLeft", false);
101 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
104 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
107 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
110 QCOMPARE(one->x(), 0.0);
111 QCOMPARE(one->y(), 0.0);
112 QCOMPARE(two->x(), 50.0);
113 QCOMPARE(two->y(), 0.0);
114 QCOMPARE(three->x(), 70.0);
115 QCOMPARE(three->y(), 0.0);
117 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
118 QCOMPARE(row->width(), 110.0);
119 QCOMPARE(row->height(), 50.0);
124 void tst_QDeclarativePositioners::test_horizontal_rtl()
126 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal.qml");
128 canvas->rootObject()->setProperty("testRightToLeft", true);
130 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
133 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
136 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
139 QCOMPARE(one->x(), 60.0);
140 QCOMPARE(one->y(), 0.0);
141 QCOMPARE(two->x(), 40.0);
142 QCOMPARE(two->y(), 0.0);
143 QCOMPARE(three->x(), 0.0);
144 QCOMPARE(three->y(), 0.0);
146 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
147 QCOMPARE(row->width(), 110.0);
148 QCOMPARE(row->height(), 50.0);
150 // Change the width of the row and check that items stay to the right
152 QCOMPARE(one->x(), 150.0);
153 QCOMPARE(one->y(), 0.0);
154 QCOMPARE(two->x(), 130.0);
155 QCOMPARE(two->y(), 0.0);
156 QCOMPARE(three->x(), 90.0);
157 QCOMPARE(three->y(), 0.0);
162 void tst_QDeclarativePositioners::test_horizontal_spacing()
164 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml");
166 canvas->rootObject()->setProperty("testRightToLeft", false);
168 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
171 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
174 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
177 QCOMPARE(one->x(), 0.0);
178 QCOMPARE(one->y(), 0.0);
179 QCOMPARE(two->x(), 60.0);
180 QCOMPARE(two->y(), 0.0);
181 QCOMPARE(three->x(), 90.0);
182 QCOMPARE(three->y(), 0.0);
184 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
185 QCOMPARE(row->width(), 130.0);
186 QCOMPARE(row->height(), 50.0);
191 void tst_QDeclarativePositioners::test_horizontal_spacing_rightToLeft()
193 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml");
195 canvas->rootObject()->setProperty("testRightToLeft", true);
197 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
200 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
203 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
206 QCOMPARE(one->x(), 80.0);
207 QCOMPARE(one->y(), 0.0);
208 QCOMPARE(two->x(), 50.0);
209 QCOMPARE(two->y(), 0.0);
210 QCOMPARE(three->x(), 00.0);
211 QCOMPARE(three->y(), 0.0);
213 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
214 QCOMPARE(row->width(), 130.0);
215 QCOMPARE(row->height(), 50.0);
220 void tst_QDeclarativePositioners::test_horizontal_animated()
222 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-animated.qml");
224 canvas->rootObject()->setProperty("testRightToLeft", false);
226 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
229 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
232 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
235 //Note that they animate in
236 QCOMPARE(one->x(), -100.0);
237 QCOMPARE(two->x(), -100.0);
238 QCOMPARE(three->x(), -100.0);
240 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
242 QCOMPARE(row->width(), 100.0);
243 QCOMPARE(row->height(), 50.0);
245 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
246 //Note that this means the duration of the animation is NOT tested
248 QTRY_COMPARE(one->x(), 0.0);
249 QTRY_COMPARE(one->y(), 0.0);
250 QTRY_COMPARE(two->opacity(), 0.0);
251 QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet
252 QTRY_COMPARE(two->y(), 0.0);
253 QTRY_COMPARE(three->x(), 50.0);
254 QTRY_COMPARE(three->y(), 0.0);
257 two->setOpacity(1.0);
258 QCOMPARE(two->opacity(), 1.0);
260 // New size should be immediate
261 QCOMPARE(row->width(), 150.0);
262 QCOMPARE(row->height(), 50.0);
264 QTest::qWait(0);//Let the animation start
265 QCOMPARE(two->x(), -100.0);
266 QCOMPARE(three->x(), 50.0);
268 QTRY_COMPARE(two->x(), 50.0);
269 QTRY_COMPARE(three->x(), 100.0);
274 void tst_QDeclarativePositioners::test_horizontal_animated_rightToLeft()
276 QDeclarativeView *canvas = createView(SRCDIR "/data/horizontal-animated.qml");
278 canvas->rootObject()->setProperty("testRightToLeft", true);
280 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
283 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
286 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
289 //Note that they animate in
290 QCOMPARE(one->x(), -100.0);
291 QCOMPARE(two->x(), -100.0);
292 QCOMPARE(three->x(), -100.0);
294 QDeclarativeItem *row = canvas->rootObject()->findChild<QDeclarativeItem*>("row");
296 QCOMPARE(row->width(), 100.0);
297 QCOMPARE(row->height(), 50.0);
299 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
300 //Note that this means the duration of the animation is NOT tested
302 QTRY_COMPARE(one->x(), 50.0);
303 QTRY_COMPARE(one->y(), 0.0);
304 QTRY_COMPARE(two->opacity(), 0.0);
305 QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet
306 QTRY_COMPARE(two->y(), 0.0);
307 QTRY_COMPARE(three->x(), 0.0);
308 QTRY_COMPARE(three->y(), 0.0);
311 two->setOpacity(1.0);
312 QCOMPARE(two->opacity(), 1.0);
314 // New size should be immediate
315 QCOMPARE(row->width(), 150.0);
316 QCOMPARE(row->height(), 50.0);
318 QTest::qWait(0);//Let the animation start
319 QCOMPARE(one->x(), 50.0);
320 QCOMPARE(two->x(), -100.0);
322 QTRY_COMPARE(one->x(), 100.0);
323 QTRY_COMPARE(two->x(), 50.0);
328 void tst_QDeclarativePositioners::test_vertical()
330 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical.qml");
332 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
335 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
338 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
341 QCOMPARE(one->x(), 0.0);
342 QCOMPARE(one->y(), 0.0);
343 QCOMPARE(two->x(), 0.0);
344 QCOMPARE(two->y(), 50.0);
345 QCOMPARE(three->x(), 0.0);
346 QCOMPARE(three->y(), 60.0);
348 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
350 QCOMPARE(column->height(), 80.0);
351 QCOMPARE(column->width(), 50.0);
356 void tst_QDeclarativePositioners::test_vertical_spacing()
358 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical-spacing.qml");
360 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
363 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
366 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
369 QCOMPARE(one->x(), 0.0);
370 QCOMPARE(one->y(), 0.0);
371 QCOMPARE(two->x(), 0.0);
372 QCOMPARE(two->y(), 60.0);
373 QCOMPARE(three->x(), 0.0);
374 QCOMPARE(three->y(), 80.0);
376 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
377 QCOMPARE(column->height(), 100.0);
378 QCOMPARE(column->width(), 50.0);
383 void tst_QDeclarativePositioners::test_vertical_animated()
385 QDeclarativeView *canvas = createView(SRCDIR "/data/vertical-animated.qml");
387 //Note that they animate in
388 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
390 QCOMPARE(one->y(), -100.0);
392 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
394 QCOMPARE(two->y(), -100.0);
396 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
398 QCOMPARE(three->y(), -100.0);
400 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
402 QCOMPARE(column->height(), 100.0);
403 QCOMPARE(column->width(), 50.0);
405 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
406 //Note that this means the duration of the animation is NOT tested
408 QTRY_COMPARE(one->y(), 0.0);
409 QTRY_COMPARE(one->x(), 0.0);
410 QTRY_COMPARE(two->opacity(), 0.0);
411 QTRY_COMPARE(two->y(), -100.0);//Not 'in' yet
412 QTRY_COMPARE(two->x(), 0.0);
413 QTRY_COMPARE(three->y(), 50.0);
414 QTRY_COMPARE(three->x(), 0.0);
417 two->setOpacity(1.0);
418 QTRY_COMPARE(two->opacity(), 1.0);
419 QCOMPARE(column->height(), 150.0);
420 QCOMPARE(column->width(), 50.0);
421 QTest::qWait(0);//Let the animation start
422 QCOMPARE(two->y(), -100.0);
423 QCOMPARE(three->y(), 50.0);
425 QTRY_COMPARE(two->y(), 50.0);
426 QTRY_COMPARE(three->y(), 100.0);
431 void tst_QDeclarativePositioners::test_grid()
433 QDeclarativeView *canvas = createView(SRCDIR "/data/gridtest.qml");
435 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
437 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
439 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
441 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
443 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
446 QCOMPARE(one->x(), 0.0);
447 QCOMPARE(one->y(), 0.0);
448 QCOMPARE(two->x(), 50.0);
449 QCOMPARE(two->y(), 0.0);
450 QCOMPARE(three->x(), 70.0);
451 QCOMPARE(three->y(), 0.0);
452 QCOMPARE(four->x(), 0.0);
453 QCOMPARE(four->y(), 50.0);
454 QCOMPARE(five->x(), 50.0);
455 QCOMPARE(five->y(), 50.0);
457 QDeclarative1Grid *grid = canvas->rootObject()->findChild<QDeclarative1Grid*>("grid");
458 QCOMPARE(grid->flow(), QDeclarative1Grid::LeftToRight);
459 QCOMPARE(grid->width(), 100.0);
460 QCOMPARE(grid->height(), 100.0);
465 void tst_QDeclarativePositioners::test_grid_topToBottom()
467 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-toptobottom.qml");
469 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
471 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
473 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
475 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
477 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
480 QCOMPARE(one->x(), 0.0);
481 QCOMPARE(one->y(), 0.0);
482 QCOMPARE(two->x(), 0.0);
483 QCOMPARE(two->y(), 50.0);
484 QCOMPARE(three->x(), 0.0);
485 QCOMPARE(three->y(), 100.0);
486 QCOMPARE(four->x(), 50.0);
487 QCOMPARE(four->y(), 0.0);
488 QCOMPARE(five->x(), 50.0);
489 QCOMPARE(five->y(), 50.0);
491 QDeclarative1Grid *grid = canvas->rootObject()->findChild<QDeclarative1Grid*>("grid");
492 QCOMPARE(grid->flow(), QDeclarative1Grid::TopToBottom);
493 QCOMPARE(grid->width(), 100.0);
494 QCOMPARE(grid->height(), 120.0);
499 void tst_QDeclarativePositioners::test_grid_rightToLeft()
501 QDeclarativeView *canvas = createView(SRCDIR "/data/gridtest.qml");
503 canvas->rootObject()->setProperty("testRightToLeft", true);
505 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
507 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
509 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
511 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
513 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
516 QCOMPARE(one->x(), 50.0);
517 QCOMPARE(one->y(), 0.0);
518 QCOMPARE(two->x(), 30.0);
519 QCOMPARE(two->y(), 0.0);
520 QCOMPARE(three->x(), 0.0);
521 QCOMPARE(three->y(), 0.0);
522 QCOMPARE(four->x(), 50.0);
523 QCOMPARE(four->y(), 50.0);
524 QCOMPARE(five->x(), 40.0);
525 QCOMPARE(five->y(), 50.0);
527 QDeclarative1Grid *grid = canvas->rootObject()->findChild<QDeclarative1Grid*>("grid");
528 QCOMPARE(grid->layoutDirection(), Qt::RightToLeft);
529 QCOMPARE(grid->width(), 100.0);
530 QCOMPARE(grid->height(), 100.0);
532 // Change the width of the grid and check that items stay to the right
534 QCOMPARE(one->x(), 150.0);
535 QCOMPARE(one->y(), 0.0);
536 QCOMPARE(two->x(), 130.0);
537 QCOMPARE(two->y(), 0.0);
538 QCOMPARE(three->x(), 100.0);
539 QCOMPARE(three->y(), 0.0);
540 QCOMPARE(four->x(), 150.0);
541 QCOMPARE(four->y(), 50.0);
542 QCOMPARE(five->x(), 140.0);
543 QCOMPARE(five->y(), 50.0);
548 void tst_QDeclarativePositioners::test_grid_spacing()
550 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-spacing.qml");
552 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
554 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
556 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
558 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
560 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
563 QCOMPARE(one->x(), 0.0);
564 QCOMPARE(one->y(), 0.0);
565 QCOMPARE(two->x(), 54.0);
566 QCOMPARE(two->y(), 0.0);
567 QCOMPARE(three->x(), 78.0);
568 QCOMPARE(three->y(), 0.0);
569 QCOMPARE(four->x(), 0.0);
570 QCOMPARE(four->y(), 54.0);
571 QCOMPARE(five->x(), 54.0);
572 QCOMPARE(five->y(), 54.0);
574 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
575 QCOMPARE(grid->width(), 128.0);
576 QCOMPARE(grid->height(), 104.0);
581 void tst_QDeclarativePositioners::test_grid_animated()
583 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-animated.qml");
585 canvas->rootObject()->setProperty("testRightToLeft", false);
587 //Note that all animate in
588 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
590 QCOMPARE(one->x(), -100.0);
591 QCOMPARE(one->y(), -100.0);
593 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
595 QCOMPARE(two->x(), -100.0);
596 QCOMPARE(two->y(), -100.0);
598 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
600 QCOMPARE(three->x(), -100.0);
601 QCOMPARE(three->y(), -100.0);
603 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
605 QCOMPARE(four->x(), -100.0);
606 QCOMPARE(four->y(), -100.0);
608 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
610 QCOMPARE(five->x(), -100.0);
611 QCOMPARE(five->y(), -100.0);
613 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
615 QCOMPARE(grid->width(), 150.0);
616 QCOMPARE(grid->height(), 100.0);
618 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
619 //Note that this means the duration of the animation is NOT tested
621 QTRY_COMPARE(one->y(), 0.0);
622 QTRY_COMPARE(one->x(), 0.0);
623 QTRY_COMPARE(two->opacity(), 0.0);
624 QTRY_COMPARE(two->y(), -100.0);
625 QTRY_COMPARE(two->x(), -100.0);
626 QTRY_COMPARE(three->y(), 0.0);
627 QTRY_COMPARE(three->x(), 50.0);
628 QTRY_COMPARE(four->y(), 0.0);
629 QTRY_COMPARE(four->x(), 100.0);
630 QTRY_COMPARE(five->y(), 50.0);
631 QTRY_COMPARE(five->x(), 0.0);
634 two->setOpacity(1.0);
635 QCOMPARE(two->opacity(), 1.0);
636 QCOMPARE(grid->width(), 150.0);
637 QCOMPARE(grid->height(), 100.0);
638 QTest::qWait(0);//Let the animation start
639 QCOMPARE(two->x(), -100.0);
640 QCOMPARE(two->y(), -100.0);
641 QCOMPARE(one->x(), 0.0);
642 QCOMPARE(one->y(), 0.0);
643 QCOMPARE(three->x(), 50.0);
644 QCOMPARE(three->y(), 0.0);
645 QCOMPARE(four->x(), 100.0);
646 QCOMPARE(four->y(), 0.0);
647 QCOMPARE(five->x(), 0.0);
648 QCOMPARE(five->y(), 50.0);
649 //Let the animation complete
650 QTRY_COMPARE(two->x(), 50.0);
651 QTRY_COMPARE(two->y(), 0.0);
652 QTRY_COMPARE(one->x(), 0.0);
653 QTRY_COMPARE(one->y(), 0.0);
654 QTRY_COMPARE(three->x(), 100.0);
655 QTRY_COMPARE(three->y(), 0.0);
656 QTRY_COMPARE(four->x(), 0.0);
657 QTRY_COMPARE(four->y(), 50.0);
658 QTRY_COMPARE(five->x(), 50.0);
659 QTRY_COMPARE(five->y(), 50.0);
664 void tst_QDeclarativePositioners::test_grid_animated_rightToLeft()
666 QDeclarativeView *canvas = createView(SRCDIR "/data/grid-animated.qml");
668 canvas->rootObject()->setProperty("testRightToLeft", true);
670 //Note that all animate in
671 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
673 QCOMPARE(one->x(), -100.0);
674 QCOMPARE(one->y(), -100.0);
676 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
678 QCOMPARE(two->x(), -100.0);
679 QCOMPARE(two->y(), -100.0);
681 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
683 QCOMPARE(three->x(), -100.0);
684 QCOMPARE(three->y(), -100.0);
686 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
688 QCOMPARE(four->x(), -100.0);
689 QCOMPARE(four->y(), -100.0);
691 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
693 QCOMPARE(five->x(), -100.0);
694 QCOMPARE(five->y(), -100.0);
696 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
698 QCOMPARE(grid->width(), 150.0);
699 QCOMPARE(grid->height(), 100.0);
701 //QTRY_COMPARE used instead of waiting for the expected time of animation completion
702 //Note that this means the duration of the animation is NOT tested
704 QTRY_COMPARE(one->y(), 0.0);
705 QTRY_COMPARE(one->x(), 100.0);
706 QTRY_COMPARE(two->opacity(), 0.0);
707 QTRY_COMPARE(two->y(), -100.0);
708 QTRY_COMPARE(two->x(), -100.0);
709 QTRY_COMPARE(three->y(), 0.0);
710 QTRY_COMPARE(three->x(), 50.0);
711 QTRY_COMPARE(four->y(), 0.0);
712 QTRY_COMPARE(four->x(), 0.0);
713 QTRY_COMPARE(five->y(), 50.0);
714 QTRY_COMPARE(five->x(), 100.0);
717 two->setOpacity(1.0);
718 QCOMPARE(two->opacity(), 1.0);
719 QCOMPARE(grid->width(), 150.0);
720 QCOMPARE(grid->height(), 100.0);
721 QTest::qWait(0);//Let the animation start
722 QCOMPARE(two->x(), -100.0);
723 QCOMPARE(two->y(), -100.0);
724 QCOMPARE(one->x(), 100.0);
725 QCOMPARE(one->y(), 0.0);
726 QCOMPARE(three->x(), 50.0);
727 QCOMPARE(three->y(), 0.0);
728 QCOMPARE(four->x(), 0.0);
729 QCOMPARE(four->y(), 0.0);
730 QCOMPARE(five->x(), 100.0);
731 QCOMPARE(five->y(), 50.0);
732 //Let the animation complete
733 QTRY_COMPARE(two->x(), 50.0);
734 QTRY_COMPARE(two->y(), 0.0);
735 QTRY_COMPARE(one->x(), 100.0);
736 QTRY_COMPARE(one->y(), 0.0);
737 QTRY_COMPARE(three->x(), 0.0);
738 QTRY_COMPARE(three->y(), 0.0);
739 QTRY_COMPARE(four->x(), 100.0);
740 QTRY_COMPARE(four->y(), 50.0);
741 QTRY_COMPARE(five->x(), 50.0);
742 QTRY_COMPARE(five->y(), 50.0);
747 void tst_QDeclarativePositioners::test_grid_zero_columns()
749 QDeclarativeView *canvas = createView(SRCDIR "/data/gridzerocolumns.qml");
751 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
753 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
755 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
757 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
759 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
762 QCOMPARE(one->x(), 0.0);
763 QCOMPARE(one->y(), 0.0);
764 QCOMPARE(two->x(), 50.0);
765 QCOMPARE(two->y(), 0.0);
766 QCOMPARE(three->x(), 70.0);
767 QCOMPARE(three->y(), 0.0);
768 QCOMPARE(four->x(), 120.0);
769 QCOMPARE(four->y(), 0.0);
770 QCOMPARE(five->x(), 0.0);
771 QCOMPARE(five->y(), 50.0);
773 QDeclarativeItem *grid = canvas->rootObject()->findChild<QDeclarativeItem*>("grid");
774 QCOMPARE(grid->width(), 170.0);
775 QCOMPARE(grid->height(), 60.0);
780 void tst_QDeclarativePositioners::test_propertychanges()
782 QDeclarativeView *canvas = createView(SRCDIR "/data/propertychangestest.qml");
784 QDeclarative1Grid *grid = qobject_cast<QDeclarative1Grid*>(canvas->rootObject());
786 QDeclarative1Transition *rowTransition = canvas->rootObject()->findChild<QDeclarative1Transition*>("rowTransition");
787 QDeclarative1Transition *columnTransition = canvas->rootObject()->findChild<QDeclarative1Transition*>("columnTransition");
789 QSignalSpy addSpy(grid, SIGNAL(addChanged()));
790 QSignalSpy moveSpy(grid, SIGNAL(moveChanged()));
791 QSignalSpy columnsSpy(grid, SIGNAL(columnsChanged()));
792 QSignalSpy rowsSpy(grid, SIGNAL(rowsChanged()));
795 QVERIFY(rowTransition);
796 QVERIFY(columnTransition);
797 QCOMPARE(grid->add(), columnTransition);
798 QCOMPARE(grid->move(), columnTransition);
799 QCOMPARE(grid->columns(), 4);
800 QCOMPARE(grid->rows(), -1);
802 grid->setAdd(rowTransition);
803 grid->setMove(rowTransition);
804 QCOMPARE(grid->add(), rowTransition);
805 QCOMPARE(grid->move(), rowTransition);
806 QCOMPARE(addSpy.count(),1);
807 QCOMPARE(moveSpy.count(),1);
809 grid->setAdd(rowTransition);
810 grid->setMove(rowTransition);
811 QCOMPARE(addSpy.count(),1);
812 QCOMPARE(moveSpy.count(),1);
816 QCOMPARE(addSpy.count(),2);
817 QCOMPARE(moveSpy.count(),2);
819 grid->setColumns(-1);
821 QCOMPARE(grid->columns(), -1);
822 QCOMPARE(grid->rows(), 3);
823 QCOMPARE(columnsSpy.count(),1);
824 QCOMPARE(rowsSpy.count(),1);
826 grid->setColumns(-1);
828 QCOMPARE(columnsSpy.count(),1);
829 QCOMPARE(rowsSpy.count(),1);
833 QCOMPARE(columnsSpy.count(),2);
834 QCOMPARE(rowsSpy.count(),2);
839 void tst_QDeclarativePositioners::test_repeater()
841 QDeclarativeView *canvas = createView(SRCDIR "/data/repeatertest.qml");
843 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
846 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
849 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
852 QCOMPARE(one->x(), 0.0);
853 QCOMPARE(one->y(), 0.0);
854 QCOMPARE(two->x(), 50.0);
855 QCOMPARE(two->y(), 0.0);
856 QCOMPARE(three->x(), 100.0);
857 QCOMPARE(three->y(), 0.0);
862 void tst_QDeclarativePositioners::test_flow()
864 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
866 canvas->rootObject()->setProperty("testRightToLeft", false);
868 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
870 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
872 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
874 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
876 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
879 QCOMPARE(one->x(), 0.0);
880 QCOMPARE(one->y(), 0.0);
881 QCOMPARE(two->x(), 50.0);
882 QCOMPARE(two->y(), 0.0);
883 QCOMPARE(three->x(), 0.0);
884 QCOMPARE(three->y(), 50.0);
885 QCOMPARE(four->x(), 0.0);
886 QCOMPARE(four->y(), 70.0);
887 QCOMPARE(five->x(), 50.0);
888 QCOMPARE(five->y(), 70.0);
890 QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
892 QCOMPARE(flow->width(), 90.0);
893 QCOMPARE(flow->height(), 120.0);
898 void tst_QDeclarativePositioners::test_flow_rightToLeft()
900 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
902 canvas->rootObject()->setProperty("testRightToLeft", true);
904 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
906 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
908 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
910 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
912 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
915 QCOMPARE(one->x(), 40.0);
916 QCOMPARE(one->y(), 0.0);
917 QCOMPARE(two->x(), 20.0);
918 QCOMPARE(two->y(), 0.0);
919 QCOMPARE(three->x(), 40.0);
920 QCOMPARE(three->y(), 50.0);
921 QCOMPARE(four->x(), 40.0);
922 QCOMPARE(four->y(), 70.0);
923 QCOMPARE(five->x(), 30.0);
924 QCOMPARE(five->y(), 70.0);
926 QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
928 QCOMPARE(flow->width(), 90.0);
929 QCOMPARE(flow->height(), 120.0);
934 void tst_QDeclarativePositioners::test_flow_topToBottom()
936 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest-toptobottom.qml");
938 canvas->rootObject()->setProperty("testRightToLeft", false);
940 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
942 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
944 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
946 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
948 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
951 QCOMPARE(one->x(), 0.0);
952 QCOMPARE(one->y(), 0.0);
953 QCOMPARE(two->x(), 50.0);
954 QCOMPARE(two->y(), 0.0);
955 QCOMPARE(three->x(), 50.0);
956 QCOMPARE(three->y(), 50.0);
957 QCOMPARE(four->x(), 100.0);
958 QCOMPARE(four->y(), 00.0);
959 QCOMPARE(five->x(), 100.0);
960 QCOMPARE(five->y(), 50.0);
962 QDeclarativeItem *flow = canvas->rootObject()->findChild<QDeclarativeItem*>("flow");
964 QCOMPARE(flow->height(), 90.0);
965 QCOMPARE(flow->width(), 150.0);
967 canvas->rootObject()->setProperty("testRightToLeft", true);
970 QCOMPARE(flow->height(), 90.0);
971 QCOMPARE(flow->width(), 150.0);
973 QCOMPARE(one->x(), 100.0);
974 QCOMPARE(one->y(), 0.0);
975 QCOMPARE(two->x(), 80.0);
976 QCOMPARE(two->y(), 0.0);
977 QCOMPARE(three->x(), 50.0);
978 QCOMPARE(three->y(), 50.0);
979 QCOMPARE(four->x(), 0.0);
980 QCOMPARE(four->y(), 0.0);
981 QCOMPARE(five->x(), 40.0);
982 QCOMPARE(five->y(), 50.0);
987 void tst_QDeclarativePositioners::test_flow_resize()
989 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
991 QDeclarativeItem *root = qobject_cast<QDeclarativeItem*>(canvas->rootObject());
994 root->setProperty("testRightToLeft", false);
996 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
998 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
1000 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
1001 QVERIFY(three != 0);
1002 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
1004 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
1007 QCOMPARE(one->x(), 0.0);
1008 QCOMPARE(one->y(), 0.0);
1009 QCOMPARE(two->x(), 50.0);
1010 QCOMPARE(two->y(), 0.0);
1011 QCOMPARE(three->x(), 70.0);
1012 QCOMPARE(three->y(), 0.0);
1013 QCOMPARE(four->x(), 0.0);
1014 QCOMPARE(four->y(), 50.0);
1015 QCOMPARE(five->x(), 50.0);
1016 QCOMPARE(five->y(), 50.0);
1021 void tst_QDeclarativePositioners::test_flow_resize_rightToLeft()
1023 QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml");
1025 QDeclarativeItem *root = qobject_cast<QDeclarativeItem*>(canvas->rootObject());
1027 root->setWidth(125);
1028 root->setProperty("testRightToLeft", true);
1030 QDeclarative1Rectangle *one = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("one");
1032 QDeclarative1Rectangle *two = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("two");
1034 QDeclarative1Rectangle *three = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("three");
1035 QVERIFY(three != 0);
1036 QDeclarative1Rectangle *four = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("four");
1038 QDeclarative1Rectangle *five = canvas->rootObject()->findChild<QDeclarative1Rectangle*>("five");
1041 QCOMPARE(one->x(), 75.0);
1042 QCOMPARE(one->y(), 0.0);
1043 QCOMPARE(two->x(), 55.0);
1044 QCOMPARE(two->y(), 0.0);
1045 QCOMPARE(three->x(), 5.0);
1046 QCOMPARE(three->y(), 0.0);
1047 QCOMPARE(four->x(), 75.0);
1048 QCOMPARE(four->y(), 50.0);
1049 QCOMPARE(five->x(), 65.0);
1050 QCOMPARE(five->y(), 50.0);
1055 void tst_QDeclarativePositioners::test_flow_implicit_resize()
1057 QDeclarativeView *canvas = createView(SRCDIR "/data/flow-testimplicitsize.qml");
1058 QVERIFY(canvas->rootObject() != 0);
1060 QDeclarative1Flow *flow = canvas->rootObject()->findChild<QDeclarative1Flow*>("flow");
1063 QCOMPARE(flow->width(), 100.0);
1064 QCOMPARE(flow->height(), 120.0);
1066 canvas->rootObject()->setProperty("flowLayout", 0);
1067 QCOMPARE(flow->flow(), QDeclarative1Flow::LeftToRight);
1068 QCOMPARE(flow->width(), 220.0);
1069 QCOMPARE(flow->height(), 50.0);
1071 canvas->rootObject()->setProperty("flowLayout", 1);
1072 QCOMPARE(flow->flow(), QDeclarative1Flow::TopToBottom);
1073 QCOMPARE(flow->width(), 100.0);
1074 QCOMPARE(flow->height(), 120.0);
1076 canvas->rootObject()->setProperty("flowLayout", 2);
1077 QCOMPARE(flow->layoutDirection(), Qt::RightToLeft);
1078 QCOMPARE(flow->width(), 220.0);
1079 QCOMPARE(flow->height(), 50.0);
1084 QString warningMessage;
1086 void interceptWarnings(QtMsgType type, const char *msg)
1089 warningMessage = msg;
1092 void tst_QDeclarativePositioners::test_conflictinganchors()
1094 QtMsgHandler oldMsgHandler = qInstallMsgHandler(interceptWarnings);
1095 QDeclarativeEngine engine;
1096 QDeclarativeComponent component(&engine);
1098 component.setData("import QtQuick 1.0\nColumn { Item {} }", QUrl::fromLocalFile(""));
1099 QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
1101 QVERIFY(warningMessage.isEmpty());
1104 component.setData("import QtQuick 1.0\nRow { Item {} }", QUrl::fromLocalFile(""));
1105 item = qobject_cast<QDeclarativeItem*>(component.create());
1107 QVERIFY(warningMessage.isEmpty());
1110 component.setData("import QtQuick 1.0\nGrid { Item {} }", QUrl::fromLocalFile(""));
1111 item = qobject_cast<QDeclarativeItem*>(component.create());
1113 QVERIFY(warningMessage.isEmpty());
1116 component.setData("import QtQuick 1.0\nFlow { Item {} }", QUrl::fromLocalFile(""));
1117 item = qobject_cast<QDeclarativeItem*>(component.create());
1119 QVERIFY(warningMessage.isEmpty());
1122 component.setData("import QtQuick 1.0\nColumn { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
1123 item = qobject_cast<QDeclarativeItem*>(component.create());
1125 QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
1126 warningMessage.clear();
1129 component.setData("import QtQuick 1.0\nColumn { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
1130 item = qobject_cast<QDeclarativeItem*>(component.create());
1132 QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
1133 warningMessage.clear();
1136 component.setData("import QtQuick 1.0\nColumn { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
1137 item = qobject_cast<QDeclarativeItem*>(component.create());
1139 QVERIFY(warningMessage.isEmpty());
1140 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();
1150 component.setData("import QtQuick 1.0\nRow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
1151 item = qobject_cast<QDeclarativeItem*>(component.create());
1153 QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
1154 warningMessage.clear();
1157 component.setData("import QtQuick 1.0\nRow { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
1158 item = qobject_cast<QDeclarativeItem*>(component.create());
1160 QVERIFY(warningMessage.isEmpty());
1161 warningMessage.clear();
1164 component.setData("import QtQuick 1.0\nGrid { Item { anchors.horizontalCenter: parent.horizontalCenter } }", QUrl::fromLocalFile(""));
1165 item = qobject_cast<QDeclarativeItem*>(component.create());
1167 QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
1168 warningMessage.clear();
1171 component.setData("import QtQuick 1.0\nGrid { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
1172 item = qobject_cast<QDeclarativeItem*>(component.create());
1174 QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
1175 warningMessage.clear();
1178 component.setData("import QtQuick 1.0\nFlow { Item { anchors.verticalCenter: parent.verticalCenter } }", 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"));
1184 component.setData("import QtQuick 1.0\nFlow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
1185 item = qobject_cast<QDeclarativeItem*>(component.create());
1187 QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
1188 qInstallMsgHandler(oldMsgHandler);
1192 void tst_QDeclarativePositioners::test_vertical_qgraphicswidget()
1194 QDeclarativeView *canvas = createView(SRCDIR "/data/verticalqgraphicswidget.qml");
1196 QGraphicsWidget *one = canvas->rootObject()->findChild<QGraphicsWidget*>("one");
1199 QGraphicsWidget *two = canvas->rootObject()->findChild<QGraphicsWidget*>("two");
1202 QGraphicsWidget *three = canvas->rootObject()->findChild<QGraphicsWidget*>("three");
1203 QVERIFY(three != 0);
1205 QCOMPARE(one->x(), 0.0);
1206 QCOMPARE(one->y(), 0.0);
1207 QCOMPARE(two->x(), 0.0);
1208 QCOMPARE(two->y(), 50.0);
1209 QCOMPARE(three->x(), 0.0);
1210 QCOMPARE(three->y(), 60.0);
1212 QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column");
1214 QCOMPARE(column->height(), 80.0);
1215 QCOMPARE(column->width(), 50.0);
1217 two->resize(QSizeF(two->size().width(), 20.0));
1218 QCOMPARE(three->x(), 0.0);
1219 QCOMPARE(three->y(), 70.0);
1221 two->setOpacity(0.0);
1222 QCOMPARE(one->x(), 0.0);
1223 QCOMPARE(one->y(), 0.0);
1224 QCOMPARE(three->x(), 0.0);
1225 QCOMPARE(three->y(), 50.0);
1227 one->setVisible(false);
1228 QCOMPARE(three->x(), 0.0);
1229 QCOMPARE(three->y(), 0.0);
1234 void tst_QDeclarativePositioners::test_mirroring()
1236 QList<QString> qmlFiles;
1237 qmlFiles << "horizontal.qml" << "gridtest.qml" << "flowtest.qml";
1238 QList<QString> objectNames;
1239 objectNames << "one" << "two" << "three" << "four" << "five";
1241 foreach(const QString qmlFile, qmlFiles) {
1242 QDeclarativeView *canvasA = createView(QString(SRCDIR) + "/data/" + qmlFile);
1243 QDeclarativeItem *rootA = qobject_cast<QDeclarativeItem*>(canvasA->rootObject());
1245 QDeclarativeView *canvasB = createView(QString(SRCDIR) + "/data/" + qmlFile);
1246 QDeclarativeItem *rootB = qobject_cast<QDeclarativeItem*>(canvasB->rootObject());
1248 rootA->setProperty("testRightToLeft", true); // layoutDirection: Qt.RightToLeft
1251 foreach(const QString objectName, objectNames) {
1252 // horizontal.qml only has three items
1253 if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1255 QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1256 QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1257 QVERIFY(itemA->x() != itemB->x());
1260 QDeclarativeItemPrivate* rootPrivateB = QDeclarativeItemPrivate::get(rootB);
1262 rootPrivateB->effectiveLayoutMirror = true; // LayoutMirroring.enabled: true
1263 rootPrivateB->isMirrorImplicit = false;
1264 rootPrivateB->inheritMirrorFromItem = true; // LayoutMirroring.childrenInherit: true
1265 rootPrivateB->resolveLayoutMirror();
1268 foreach(const QString objectName, objectNames) {
1269 // horizontal.qml only has three items
1270 if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1272 QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1273 QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1274 QCOMPARE(itemA->x(), itemB->x());
1277 rootA->setProperty("testRightToLeft", false); // layoutDirection: Qt.LeftToRight
1278 rootB->setProperty("testRightToLeft", true); // layoutDirection: Qt.RightToLeft
1280 // LTR == RTL + mirror
1281 foreach(const QString objectName, objectNames) {
1282 // horizontal.qml only has three items
1283 if (qmlFile == QString("horizontal.qml") && objectName == QString("four"))
1285 QDeclarativeItem *itemA = rootA->findChild<QDeclarativeItem*>(objectName);
1286 QDeclarativeItem *itemB = rootB->findChild<QDeclarativeItem*>(objectName);
1287 QCOMPARE(itemA->x(), itemB->x());
1294 void tst_QDeclarativePositioners::testQtQuick11Attributes()
1296 QFETCH(QString, code);
1297 QFETCH(QString, warning);
1298 QFETCH(QString, error);
1300 QDeclarativeEngine engine;
1303 QDeclarativeComponent valid(&engine);
1304 valid.setData("import QtQuick 1.1; " + code.toUtf8(), QUrl(""));
1305 obj = valid.create();
1307 QVERIFY(valid.errorString().isEmpty());
1310 QDeclarativeComponent invalid(&engine);
1311 invalid.setData("import QtQuick 1.0; " + code.toUtf8(), QUrl(""));
1312 QTest::ignoreMessage(QtWarningMsg, warning.toUtf8());
1313 obj = invalid.create();
1314 QCOMPARE(invalid.errorString(), error);
1318 void tst_QDeclarativePositioners::testQtQuick11Attributes_data()
1320 QTest::addColumn<QString>("code");
1321 QTest::addColumn<QString>("warning");
1322 QTest::addColumn<QString>("error");
1324 QTest::newRow("Flow.layoutDirection") << "Flow { layoutDirection: Qt.LeftToRight }"
1325 << "QDeclarativeComponent: Component is not ready"
1326 << ":1 \"Flow.layoutDirection\" is not available in QtQuick 1.0.\n";
1328 QTest::newRow("Row.layoutDirection") << "Row { layoutDirection: Qt.LeftToRight }"
1329 << "QDeclarativeComponent: Component is not ready"
1330 << ":1 \"Row.layoutDirection\" is not available in QtQuick 1.0.\n";
1332 QTest::newRow("Grid.layoutDirection") << "Grid { layoutDirection: Qt.LeftToRight }"
1333 << "QDeclarativeComponent: Component is not ready"
1334 << ":1 \"Grid.layoutDirection\" is not available in QtQuick 1.0.\n";
1337 QDeclarativeView *tst_QDeclarativePositioners::createView(const QString &filename)
1339 QDeclarativeView *canvas = new QDeclarativeView(0);
1341 canvas->setSource(QUrl::fromLocalFile(filename));
1347 QTEST_MAIN(tst_QDeclarativePositioners)
1349 #include "tst_qdeclarativepositioners.moc"