tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     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
       
    14 ** this package.
       
    15 **
       
    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.
       
    23 **
       
    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.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QtGui>
       
    43 #include <QtTest/QtTest>
       
    44 #include <QTest>
       
    45 #include <QMetaType>
       
    46 #include <QtGui/qgraphicsanchorlayout.h>
       
    47 #include <private/qgraphicsanchorlayout_p.h>
       
    48 
       
    49 #define TEST_COMPLEX_CASES
       
    50 
       
    51 
       
    52 //---------------------- AnchorLayout helper class ----------------------------
       
    53 class TheAnchorLayout : public QGraphicsAnchorLayout
       
    54 {
       
    55 public:
       
    56     TheAnchorLayout() : QGraphicsAnchorLayout()
       
    57     {
       
    58         setContentsMargins( 0,0,0,0 );
       
    59         setSpacing( 0 );
       
    60     }
       
    61 
       
    62     bool isValid()
       
    63     {
       
    64         return !QGraphicsAnchorLayoutPrivate::get(this)->hasConflicts();
       
    65     }
       
    66 
       
    67     void setAnchor(
       
    68         QGraphicsLayoutItem *startItem,
       
    69         Qt::AnchorPoint startEdge,
       
    70         QGraphicsLayoutItem *endItem,
       
    71         Qt::AnchorPoint endEdge,
       
    72         qreal value)
       
    73         {
       
    74             QGraphicsAnchor *anchor = addAnchor( startItem, startEdge, endItem, endEdge);
       
    75             if (anchor)
       
    76                 anchor->setSpacing(value);
       
    77         }
       
    78 
       
    79     int indexOf(const QGraphicsLayoutItem* item) const
       
    80     {
       
    81         for ( int i=0; i< count(); i++) {
       
    82             if ( itemAt(i) == item ) {
       
    83                 return i;
       
    84             }
       
    85         }
       
    86         return -1;
       
    87     }
       
    88 
       
    89     void removeItem(QGraphicsLayoutItem* item)
       
    90     {
       
    91         removeAt(indexOf(item));
       
    92     }
       
    93 
       
    94     void removeAnchor(
       
    95         QGraphicsLayoutItem *startItem,
       
    96         Qt::AnchorPoint startEdge,
       
    97         QGraphicsLayoutItem *endItem,
       
    98         Qt::AnchorPoint endEdge)
       
    99         {
       
   100             delete QGraphicsAnchorLayout::anchor(startItem, startEdge, endItem, endEdge);
       
   101         }
       
   102 };
       
   103 //-----------------------------------------------------------------------------
       
   104 
       
   105 
       
   106 struct BasicLayoutTestData
       
   107 {
       
   108     inline BasicLayoutTestData(
       
   109         int index1, Qt::AnchorPoint edge1,
       
   110         int index2, Qt::AnchorPoint edge2,
       
   111         qreal distance)
       
   112         : firstIndex(index1), firstEdge(edge1),
       
   113           secondIndex(index2), secondEdge(edge2),
       
   114           spacing(distance)
       
   115         {
       
   116         }
       
   117 
       
   118     int firstIndex;
       
   119     Qt::AnchorPoint firstEdge;
       
   120     int secondIndex;
       
   121     Qt::AnchorPoint secondEdge;
       
   122     qreal spacing;
       
   123 };
       
   124 
       
   125 struct AnchorItemSizeHint
       
   126 {
       
   127     inline AnchorItemSizeHint(
       
   128         qreal hmin, qreal hpref, qreal hmax,
       
   129         qreal vmin, qreal vpref, qreal vmax )
       
   130         : hmin(hmin), hpref(hpref), hmax(hmax), vmin(vmin), vpref(vpref), vmax(vmax)
       
   131         {
       
   132         }
       
   133     qreal hmin, hpref, hmax;
       
   134     qreal vmin, vpref, vmax;
       
   135 };
       
   136 
       
   137 // some test results
       
   138 
       
   139 struct BasicLayoutTestResult
       
   140 {
       
   141     inline BasicLayoutTestResult(
       
   142         int resultIndex, const QRectF& resultRect )
       
   143         : index(resultIndex), rect(resultRect)
       
   144         {
       
   145         }
       
   146 
       
   147     int index;
       
   148     QRectF rect;
       
   149 };
       
   150 
       
   151 typedef QList<BasicLayoutTestData> BasicLayoutTestDataList;
       
   152 Q_DECLARE_METATYPE(BasicLayoutTestDataList)
       
   153 
       
   154 typedef QList<BasicLayoutTestResult> BasicLayoutTestResultList;
       
   155 Q_DECLARE_METATYPE(BasicLayoutTestResultList)
       
   156 
       
   157 typedef QList<AnchorItemSizeHint> AnchorItemSizeHintList;
       
   158 Q_DECLARE_METATYPE(AnchorItemSizeHintList)
       
   159 
       
   160 
       
   161 //---------------------- Test Widget used on all tests ------------------------
       
   162 class TestWidget : public QGraphicsWidget
       
   163 {
       
   164 public:
       
   165     inline TestWidget(QGraphicsItem *parent = 0)
       
   166         : QGraphicsWidget(parent)
       
   167         {
       
   168             setContentsMargins( 0,0,0,0 );
       
   169         }
       
   170     ~TestWidget()
       
   171         {
       
   172         }
       
   173 
       
   174 protected:
       
   175     QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
       
   176 };
       
   177 
       
   178 QSizeF TestWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
       
   179 {
       
   180     Q_UNUSED( constraint );
       
   181     if (which == Qt::MinimumSize) {
       
   182         return QSizeF(5,5);
       
   183     }
       
   184 
       
   185     if (which == Qt::PreferredSize) {
       
   186         return QSizeF(50,50);
       
   187     }
       
   188 
       
   189     return QSizeF(500,500);
       
   190 }
       
   191 //-----------------------------------------------------------------------------
       
   192 
       
   193 
       
   194 
       
   195 //----------------------------- Test class ------------------------------------
       
   196 class tst_QGraphicsAnchorLayout1 : public QObject
       
   197 {
       
   198     Q_OBJECT
       
   199 
       
   200 private slots:
       
   201     void testCount();
       
   202 
       
   203     void testRemoveAt();
       
   204     void testRemoveItem();
       
   205 
       
   206     void testItemAt();
       
   207     void testIndexOf();
       
   208 
       
   209     void testAddAndRemoveAnchor();
       
   210     void testIsValid();
       
   211     void testSpecialCases();
       
   212 
       
   213     void testBasicLayout_data();
       
   214     void testBasicLayout();
       
   215 
       
   216     void testNegativeSpacing_data();
       
   217     void testNegativeSpacing();
       
   218 
       
   219     void testMixedSpacing_data();
       
   220     void testMixedSpacing();
       
   221 
       
   222     void testMulti_data();
       
   223     void testMulti();
       
   224 
       
   225     void testCenterAnchors_data();
       
   226     void testCenterAnchors();
       
   227 
       
   228     void testRemoveCenterAnchor_data();
       
   229     void testRemoveCenterAnchor();
       
   230 
       
   231     void testSingleSizePolicy_data();
       
   232     void testSingleSizePolicy();
       
   233 
       
   234     void testDoubleSizePolicy_data();
       
   235     void testDoubleSizePolicy();
       
   236 
       
   237     void testSizeDistribution_data();
       
   238     void testSizeDistribution();
       
   239 
       
   240     void testSizeHint();
       
   241 
       
   242 #ifdef TEST_COMPLEX_CASES
       
   243     void testComplexCases_data();
       
   244     void testComplexCases();
       
   245 #endif
       
   246 };
       
   247 
       
   248 
       
   249 void tst_QGraphicsAnchorLayout1::testCount()
       
   250 {
       
   251     QGraphicsWidget *widget = new QGraphicsWidget;
       
   252 
       
   253     TheAnchorLayout *layout = new TheAnchorLayout();
       
   254     QVERIFY( layout->count() == 0 );
       
   255 
       
   256     TestWidget *widget1 = new TestWidget();
       
   257     layout->setAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 1);
       
   258     QCOMPARE( layout->count(), 1 );
       
   259 
       
   260     // adding one more anchor for already added widget should not increase the count
       
   261     layout->setAnchor(layout, Qt::AnchorRight, widget1, Qt::AnchorRight, 1);
       
   262     QCOMPARE( layout->count(), 1 );
       
   263 
       
   264     // create one more widget and attach with anchor layout
       
   265     TestWidget *widget2 = new TestWidget();
       
   266     layout->setAnchor(layout, Qt::AnchorLeft, widget2, Qt::AnchorLeft, 1);
       
   267     QCOMPARE( layout->count(), 2 );
       
   268 
       
   269     widget->setLayout(layout);
       
   270     delete widget;
       
   271 }
       
   272 
       
   273 void tst_QGraphicsAnchorLayout1::testRemoveAt()
       
   274 {
       
   275     TheAnchorLayout *layout = new TheAnchorLayout();
       
   276     QVERIFY( layout->count() == 0 );
       
   277 
       
   278     TestWidget *widget1 = new TestWidget();
       
   279     layout->setAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 2);
       
   280     QVERIFY( layout->count() == 1 );
       
   281 
       
   282     TestWidget *widget2 = new TestWidget();
       
   283     layout->setAnchor(widget2, Qt::AnchorLeft, layout, Qt::AnchorLeft, 0.1);
       
   284     QVERIFY( layout->count() == 2 );
       
   285 
       
   286     layout->removeAt(0);
       
   287     QVERIFY( layout->count() == 1 );
       
   288 
       
   289     layout->removeAt(-55);
       
   290     layout->removeAt(55);
       
   291     QVERIFY( layout->count() == 1 );
       
   292 
       
   293     layout->removeAt(0);
       
   294     QVERIFY( layout->count() == 0 );
       
   295 
       
   296     delete layout;
       
   297     delete widget1;
       
   298     delete widget2;
       
   299 }
       
   300 
       
   301 void tst_QGraphicsAnchorLayout1::testRemoveItem()
       
   302 {
       
   303     TheAnchorLayout *layout = new TheAnchorLayout();
       
   304     QCOMPARE( layout->count(), 0 );
       
   305 
       
   306     TestWidget *widget1 = new TestWidget();
       
   307     layout->setAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 2);
       
   308     QCOMPARE( layout->count(), 1 );
       
   309 
       
   310     TestWidget *widget2 = new TestWidget();
       
   311     layout->setAnchor(layout, Qt::AnchorLeft, widget2, Qt::AnchorLeft, 0.1);
       
   312     QCOMPARE( layout->count(), 2 );
       
   313 
       
   314     layout->removeItem(0);
       
   315     QCOMPARE( layout->count(), 2 );
       
   316 
       
   317     layout->removeItem(widget1);
       
   318     QCOMPARE( layout->count(), 1 );
       
   319     QCOMPARE( layout->indexOf(widget1), -1 );
       
   320     QCOMPARE( layout->indexOf(widget2), 0 );
       
   321 
       
   322     layout->removeItem(widget1);
       
   323     QCOMPARE( layout->count(), 1 );
       
   324 
       
   325     layout->removeItem(widget2);
       
   326     QVERIFY( layout->count() == 0 );
       
   327 
       
   328     delete layout;
       
   329     delete widget1;
       
   330     delete widget2;
       
   331 }
       
   332 
       
   333 void tst_QGraphicsAnchorLayout1::testItemAt()
       
   334 {
       
   335     QGraphicsWidget *widget = new QGraphicsWidget;
       
   336 
       
   337     TheAnchorLayout *layout = new TheAnchorLayout();
       
   338 
       
   339     TestWidget *widget1 = new TestWidget();
       
   340     TestWidget *widget2 = new TestWidget();
       
   341     TestWidget *widget3 = new TestWidget();
       
   342     TestWidget *widget4 = new TestWidget();
       
   343 
       
   344     layout->setAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 0.1);
       
   345     layout->setAnchor(layout, Qt::AnchorLeft, widget2, Qt::AnchorLeft, 0.1);
       
   346     layout->setAnchor(layout, Qt::AnchorLeft, widget3, Qt::AnchorLeft, 0.1);
       
   347     layout->setAnchor(layout, Qt::AnchorLeft, widget4, Qt::AnchorLeft, 0.1);
       
   348 
       
   349     QVERIFY( layout->itemAt(0) == widget1 );
       
   350 
       
   351     layout->removeAt(0);
       
   352 
       
   353     QVERIFY( layout->itemAt(0) == widget2 );
       
   354 
       
   355     widget->setLayout(layout);
       
   356     delete widget;
       
   357 }
       
   358 
       
   359 void tst_QGraphicsAnchorLayout1::testIndexOf()
       
   360 {
       
   361     QGraphicsWidget *widget = new QGraphicsWidget;
       
   362 
       
   363     TheAnchorLayout *layout = new TheAnchorLayout();
       
   364 
       
   365     TestWidget *widget1 = new TestWidget();
       
   366     TestWidget *widget2 = new TestWidget();
       
   367     TestWidget *widget3 = new TestWidget();
       
   368     TestWidget *widget4 = new TestWidget();
       
   369 
       
   370     QCOMPARE( layout->indexOf(widget1), -1 );
       
   371 
       
   372     layout->setAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 0.1);
       
   373     layout->setAnchor(layout, Qt::AnchorLeft, widget2, Qt::AnchorLeft, 0.1);
       
   374     layout->setAnchor(layout, Qt::AnchorLeft, widget3, Qt::AnchorLeft, 0.1);
       
   375 
       
   376     QCOMPARE( layout->indexOf(widget4), -1 );
       
   377     layout->setAnchor(layout, Qt::AnchorLeft, widget4, Qt::AnchorLeft, 0.1);
       
   378 
       
   379     QCOMPARE( layout->count(), 4 );
       
   380     for (int i = 0; i < layout->count(); ++i) {
       
   381         QCOMPARE(layout->indexOf(layout->itemAt(i)), i);
       
   382     }
       
   383 
       
   384     QCOMPARE( layout->indexOf(0), -1 );
       
   385     widget->setLayout(layout);
       
   386     delete widget;
       
   387 }
       
   388 
       
   389 void tst_QGraphicsAnchorLayout1::testAddAndRemoveAnchor()
       
   390 {
       
   391     QGraphicsWidget *widget = new QGraphicsWidget;
       
   392 
       
   393     TheAnchorLayout *layout = new TheAnchorLayout();
       
   394 
       
   395     TestWidget *widget1 = new TestWidget();
       
   396     TestWidget *widget2 = new TestWidget();
       
   397     TestWidget *widget3 = new TestWidget();
       
   398     TestWidget *widget4 = new TestWidget();
       
   399     TestWidget *widget5 = new TestWidget();
       
   400 
       
   401     layout->setAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 0.1);
       
   402     layout->setAnchor(layout, Qt::AnchorLeft, widget2, Qt::AnchorLeft, 0.5);
       
   403     layout->setAnchor(layout, Qt::AnchorLeft, widget3, Qt::AnchorLeft, 10);
       
   404     layout->setAnchor(layout, Qt::AnchorLeft, widget4, Qt::AnchorLeft, 0.1);
       
   405     QCOMPARE( layout->count(), 4 );
       
   406 
       
   407     // test setting invalid anchors
       
   408     QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor NULL items");
       
   409     layout->setAnchor(0, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 1);
       
   410     QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor NULL items");
       
   411     layout->setAnchor(layout, Qt::AnchorLeft, 0, Qt::AnchorLeft, 1);
       
   412     QCOMPARE( layout->count(), 4 );
       
   413 
       
   414     // test removing invalid anchors
       
   415     layout->removeAnchor(widget4, Qt::AnchorRight, widget1, Qt::AnchorRight);
       
   416 
       
   417     // anchor one horizontal edge with vertical edge. it should not add this widget as a child
       
   418     QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor edges of different orientations");
       
   419     layout->setAnchor(layout, Qt::AnchorLeft, widget5, Qt::AnchorTop, 10);
       
   420     QCOMPARE( layout->count(), 4 );
       
   421 
       
   422     // ###: NOT SUPPORTED
       
   423     // anchor two edges of a widget (to define width / height)
       
   424     QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
   425     layout->setAnchor(widget5, Qt::AnchorLeft, widget5, Qt::AnchorRight, 10);
       
   426     // QCOMPARE( layout->count(), 5 );
       
   427     QCOMPARE( layout->count(), 4 );
       
   428 
       
   429     // anchor yet new widget properly
       
   430     layout->setAnchor(layout, Qt::AnchorRight, widget5, Qt::AnchorRight, 20 );
       
   431     QCOMPARE( layout->count(), 5 );
       
   432 
       
   433     // remove anchor for widget1. widget1 should be removed from layout since the
       
   434     // last anchor was removed.
       
   435     layout->removeAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft);
       
   436 
       
   437     QCOMPARE( layout->count(), 4 );
       
   438     QVERIFY( !widget1->parentLayoutItem() );
       
   439 
       
   440     // test that item is not removed from layout if other anchors remain set
       
   441     layout->setAnchor(widget2, Qt::AnchorLeft, widget3, Qt::AnchorRight, 10);
       
   442     layout->removeAnchor(layout, Qt::AnchorLeft, widget2, Qt::AnchorLeft);
       
   443     QCOMPARE( layout->count(), 4 );
       
   444 
       
   445     // remove all the anchors
       
   446     layout->removeAnchor(widget2, Qt::AnchorLeft, widget3, Qt::AnchorRight);
       
   447     layout->removeAnchor(layout, Qt::AnchorLeft, widget3, Qt::AnchorLeft);
       
   448     layout->removeAnchor(layout, Qt::AnchorLeft, widget4, Qt::AnchorLeft);
       
   449     layout->removeAnchor(widget5, Qt::AnchorLeft, widget5, Qt::AnchorRight);
       
   450     layout->removeAnchor(layout, Qt::AnchorRight, widget5, Qt::AnchorRight);
       
   451 
       
   452     QCOMPARE( layout->count(), 0 );
       
   453 
       
   454     // set one anchor "another way round" to get full coverage for "removeAnchor"
       
   455     layout->setAnchor(widget1, Qt::AnchorLeft, layout, Qt::AnchorLeft, 0.1);
       
   456     layout->removeAnchor(widget1, Qt::AnchorLeft, layout, Qt::AnchorLeft);
       
   457 
       
   458     QCOMPARE( layout->count(), 0 );
       
   459 
       
   460     widget->setLayout(layout);
       
   461     delete widget;
       
   462 }
       
   463 
       
   464 void tst_QGraphicsAnchorLayout1::testIsValid()
       
   465 {
       
   466     // Empty, valid
       
   467     {
       
   468     QGraphicsWidget *widget = new QGraphicsWidget;
       
   469     TheAnchorLayout *layout = new TheAnchorLayout();
       
   470     widget->setLayout(layout);
       
   471     widget->setGeometry(QRectF(0,0,100,100));
       
   472 
       
   473     QCOMPARE(layout->isValid(), true);
       
   474     delete widget;
       
   475     }
       
   476 
       
   477     // One widget, valid
       
   478     {
       
   479     QGraphicsWidget *widget = new QGraphicsWidget;
       
   480     TheAnchorLayout *layout = new TheAnchorLayout();
       
   481 
       
   482     TestWidget *widget1 = new TestWidget();
       
   483 
       
   484     layout->setAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 0.1);
       
   485     layout->setAnchor(layout, Qt::AnchorTop, widget1, Qt::AnchorTop, 0.1);
       
   486     layout->setAnchor(widget1, Qt::AnchorRight, layout, Qt::AnchorRight, 0.1);
       
   487     layout->setAnchor(widget1, Qt::AnchorBottom, layout, Qt::AnchorBottom, 0.1);
       
   488 
       
   489     widget->setLayout(layout);
       
   490 
       
   491     widget->setGeometry(QRectF(0,0,100,100));
       
   492     QCOMPARE(layout->isValid(), true);
       
   493     delete widget;
       
   494     }
       
   495 
       
   496     // Overconstrained one widget, invalid
       
   497     // ### Our understanding is that this case is valid. What happens though,
       
   498     //     is that the layout minimum and maximum vertical size hints become
       
   499     //     the same, 10.1. That means its height is fixed.
       
   500     //     What will "fail" then is the "setGeometry(0, 0, 100, 100)" call,
       
   501     //     after which the layout geometry will be (0, 0, 100, 10.1).
       
   502 
       
   503     {
       
   504     QGraphicsWidget *widget = new QGraphicsWidget;
       
   505     TheAnchorLayout *layout = new TheAnchorLayout();
       
   506 
       
   507     TestWidget *widget1 = new TestWidget();
       
   508 
       
   509     layout->setAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 0.1);
       
   510     layout->setAnchor(layout, Qt::AnchorTop, widget1, Qt::AnchorTop, 0.1);
       
   511     layout->setAnchor(widget1, Qt::AnchorRight, layout, Qt::AnchorRight, 0.1);
       
   512     layout->setAnchor(widget1, Qt::AnchorBottom, layout, Qt::AnchorBottom, 0.1);
       
   513 
       
   514     layout->setAnchor(widget1, Qt::AnchorTop, layout, Qt::AnchorBottom, 10);
       
   515 
       
   516     widget->setLayout(layout);
       
   517 
       
   518     widget->setGeometry(QRectF(0,0,100,100));
       
   519     // ###: this shall change once isValid() is ready
       
   520     // QCOMPARE(layout->isValid(), false);
       
   521     QCOMPARE(layout->isValid(), true);
       
   522     delete widget;
       
   523     }
       
   524 
       
   525     // Underconstrained two widgets, valid
       
   526     {
       
   527     QGraphicsWidget *widget = new QGraphicsWidget;
       
   528     TheAnchorLayout *layout = new TheAnchorLayout();
       
   529 
       
   530     TestWidget *widget1 = new TestWidget();
       
   531     TestWidget *widget2 = new TestWidget();
       
   532 
       
   533     // Vertically the layout has floating items. Therefore, we have a conflict
       
   534     layout->setAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 0.1);
       
   535     layout->setAnchor(layout, Qt::AnchorRight, widget1, Qt::AnchorRight, -0.1);
       
   536 
       
   537     // Horizontally the layout has floating items. Therefore, we have a conflict
       
   538     layout->setAnchor(layout, Qt::AnchorTop, widget2, Qt::AnchorTop, 0.1);
       
   539     layout->setAnchor(layout, Qt::AnchorBottom, widget2, Qt::AnchorBottom, -0.1);
       
   540 
       
   541     widget->setLayout(layout);
       
   542 
       
   543     widget->setGeometry(QRectF(0,0,100,100));
       
   544     QCOMPARE(layout->isValid(), false);
       
   545     delete widget;
       
   546     }
       
   547 }
       
   548 
       
   549 void tst_QGraphicsAnchorLayout1::testSpecialCases()
       
   550 {
       
   551     // One widget, setLayout before defining layouts
       
   552     {
       
   553 #ifdef QT_DEBUG
       
   554     QTest::ignoreMessage(QtWarningMsg, "QGraphicsLayout::addChildLayoutItem: QGraphicsWidget \"\""
       
   555                                        " in wrong parent; moved to correct parent");
       
   556 #endif
       
   557     QGraphicsWidget *widget = new QGraphicsWidget;
       
   558     TheAnchorLayout *layout = new TheAnchorLayout();
       
   559     widget->setLayout(layout);
       
   560 
       
   561     TestWidget *widget1 = new TestWidget();
       
   562 
       
   563     layout->setAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 1);
       
   564     layout->setAnchor(layout, Qt::AnchorTop, widget1, Qt::AnchorTop, 1);
       
   565     layout->setAnchor(widget1, Qt::AnchorRight, layout, Qt::AnchorRight, 1);
       
   566     layout->setAnchor(widget1, Qt::AnchorBottom, layout, Qt::AnchorBottom, 1);
       
   567     widget->setGeometry(QRectF(0,0,100,100));
       
   568     QCOMPARE(widget1->geometry(), QRectF(1,1,98,98));
       
   569     delete widget1;
       
   570     delete widget;
       
   571     }
       
   572 
       
   573     // One widget, layout inside layout, layout inside layout inside layout
       
   574     {
       
   575 #ifdef QT_DEBUG
       
   576     QTest::ignoreMessage(QtWarningMsg, "QGraphicsLayout::addChildLayoutItem: QGraphicsWidget \"\""
       
   577                                        " in wrong parent; moved to correct parent");
       
   578 #endif
       
   579     QGraphicsWidget *widget = new QGraphicsWidget;
       
   580     TheAnchorLayout *layout = new TheAnchorLayout();
       
   581     widget->setLayout(layout);
       
   582 
       
   583     TheAnchorLayout *layout1 = new TheAnchorLayout();
       
   584     TestWidget *widget1 = new TestWidget();
       
   585     layout1->setAnchor(layout1, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 1);
       
   586     layout1->setAnchor(layout1, Qt::AnchorTop, widget1, Qt::AnchorTop, 1);
       
   587     layout1->setAnchor(widget1, Qt::AnchorRight, layout1, Qt::AnchorRight, 1);
       
   588     layout1->setAnchor(widget1, Qt::AnchorBottom, layout1, Qt::AnchorBottom, 1);
       
   589 
       
   590     TheAnchorLayout *layout2 = new TheAnchorLayout();
       
   591     TestWidget *widget2 = new TestWidget();
       
   592     layout2->setAnchor(layout2, Qt::AnchorLeft, widget2, Qt::AnchorLeft, 1);
       
   593     layout2->setAnchor(layout2, Qt::AnchorTop, widget2, Qt::AnchorTop, 1);
       
   594     layout2->setAnchor(widget2, Qt::AnchorRight, layout2, Qt::AnchorRight, 1);
       
   595     layout2->setAnchor(widget2, Qt::AnchorBottom, layout2, Qt::AnchorBottom, 1);
       
   596 
       
   597     layout1->setAnchor(layout1, Qt::AnchorLeft, layout2, Qt::AnchorLeft, 1);
       
   598     layout1->setAnchor(layout1, Qt::AnchorTop, layout2, Qt::AnchorTop, 1);
       
   599     layout1->setAnchor(layout2, Qt::AnchorRight, layout1, Qt::AnchorRight, 1);
       
   600     layout1->setAnchor(layout2, Qt::AnchorBottom, layout1, Qt::AnchorBottom, 1);
       
   601 
       
   602     layout->setAnchor(layout, Qt::AnchorLeft, layout1, Qt::AnchorLeft, 1);
       
   603     layout->setAnchor(layout, Qt::AnchorTop, layout1, Qt::AnchorTop, 1);
       
   604     layout->setAnchor(layout1, Qt::AnchorRight, layout, Qt::AnchorRight, 1);
       
   605     layout->setAnchor(layout1, Qt::AnchorBottom, layout, Qt::AnchorBottom, 1);
       
   606 
       
   607     // remove and add again to improve test coverage.
       
   608     layout->removeItem(layout1);
       
   609 
       
   610     layout->setAnchor(layout, Qt::AnchorLeft, layout1, Qt::AnchorLeft, 1);
       
   611     layout->setAnchor(layout, Qt::AnchorTop, layout1, Qt::AnchorTop, 1);
       
   612     layout->setAnchor(layout1, Qt::AnchorRight, layout, Qt::AnchorRight, 1);
       
   613     layout->setAnchor(layout1, Qt::AnchorBottom, layout, Qt::AnchorBottom, 1);
       
   614 
       
   615     widget->setGeometry(QRectF(0,0,100,100));
       
   616     QCOMPARE(widget1->geometry(), QRectF(2,2,96,96));
       
   617     QCOMPARE(widget2->geometry(), QRectF(3,3,94,94));
       
   618     delete widget;
       
   619     }
       
   620 
       
   621     // One widget, layout inside layout, setLayout after layout definition
       
   622     {
       
   623     QGraphicsWidget *widget = new QGraphicsWidget;
       
   624     TheAnchorLayout *layout = new TheAnchorLayout();
       
   625 
       
   626     TheAnchorLayout *layout1 = new TheAnchorLayout();
       
   627 
       
   628     TestWidget *widget1 = new TestWidget();
       
   629     layout1->setAnchor(layout1, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 1);
       
   630     layout1->setAnchor(layout1, Qt::AnchorTop, widget1, Qt::AnchorTop, 1);
       
   631     layout1->setAnchor(widget1, Qt::AnchorRight, layout1, Qt::AnchorRight, 1);
       
   632     layout1->setAnchor(widget1, Qt::AnchorBottom, layout1, Qt::AnchorBottom, 1);
       
   633 
       
   634     layout->setAnchor(layout, Qt::AnchorLeft, layout1, Qt::AnchorLeft, 1);
       
   635     layout->setAnchor(layout, Qt::AnchorTop, layout1, Qt::AnchorTop, 1);
       
   636     layout->setAnchor(layout1, Qt::AnchorRight, layout, Qt::AnchorRight, 1);
       
   637     layout->setAnchor(layout1, Qt::AnchorBottom, layout, Qt::AnchorBottom, 1);
       
   638 
       
   639     widget->setLayout(layout);
       
   640     widget->setGeometry(QRectF(0,0,100,100));
       
   641     QCOMPARE(widget1->geometry(), QRectF(2,2,96,96));
       
   642     delete widget;
       
   643     }
       
   644 
       
   645     // One widget, layout inside layout, setLayout after layout definition, widget transferred from
       
   646     // one layout to another
       
   647     {
       
   648     QGraphicsWidget *widget = new QGraphicsWidget;
       
   649     TheAnchorLayout *layout = new TheAnchorLayout();
       
   650     widget->setLayout(layout);
       
   651 
       
   652     TheAnchorLayout *layout1 = new TheAnchorLayout();
       
   653     TestWidget *widget1 = new TestWidget();
       
   654 
       
   655     // Additional layout + widget to improve coverage.
       
   656     TheAnchorLayout *layout0 = new TheAnchorLayout();
       
   657     TestWidget *widget0 = new TestWidget();
       
   658 
       
   659     // widget0 to layout0
       
   660     layout0->setAnchor(layout0, Qt::AnchorLeft, widget0, Qt::AnchorLeft, 1);
       
   661     layout0->setAnchor(layout0, Qt::AnchorTop, widget0, Qt::AnchorTop, 1);
       
   662     layout0->setAnchor(widget0, Qt::AnchorRight, layout0, Qt::AnchorRight, 1);
       
   663     layout0->setAnchor(widget0, Qt::AnchorBottom, layout0, Qt::AnchorBottom, 1);
       
   664 
       
   665     // layout0 to layout
       
   666     layout->setAnchor(layout, Qt::AnchorLeft, layout0, Qt::AnchorLeft, 1);
       
   667     layout->setAnchor(layout, Qt::AnchorTop, layout0, Qt::AnchorTop, 1);
       
   668     layout->setAnchor(layout0, Qt::AnchorRight, layout, Qt::AnchorRight, 50);
       
   669     layout->setAnchor(layout0, Qt::AnchorBottom, layout, Qt::AnchorBottom, 1);
       
   670 
       
   671     // widget1 to layout1
       
   672     layout1->setAnchor(layout1, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 1);
       
   673     layout1->setAnchor(layout1, Qt::AnchorTop, widget1, Qt::AnchorTop, 1);
       
   674     layout1->setAnchor(widget1, Qt::AnchorRight, layout1, Qt::AnchorRight, 1);
       
   675     layout1->setAnchor(widget1, Qt::AnchorBottom, layout1, Qt::AnchorBottom, 1);
       
   676 
       
   677     // layout1 to layout
       
   678     layout->setAnchor(layout, Qt::AnchorLeft, layout1, Qt::AnchorLeft, 1);
       
   679     layout->setAnchor(layout, Qt::AnchorTop, layout1, Qt::AnchorTop, 1);
       
   680     layout->setAnchor(layout1, Qt::AnchorRight, layout, Qt::AnchorRight, 50);
       
   681     layout->setAnchor(layout1, Qt::AnchorBottom, layout, Qt::AnchorBottom, 1);
       
   682 
       
   683     TheAnchorLayout *layout2 = new TheAnchorLayout();
       
   684 
       
   685     // layout2 to layout
       
   686     layout->setAnchor(layout, Qt::AnchorLeft, layout2, Qt::AnchorLeft, 50);
       
   687     layout->setAnchor(layout, Qt::AnchorTop, layout2, Qt::AnchorTop, 1);
       
   688     layout->setAnchor(layout2, Qt::AnchorRight, layout, Qt::AnchorRight, 1);
       
   689     layout->setAnchor(layout2, Qt::AnchorBottom, layout, Qt::AnchorBottom, 1);
       
   690 
       
   691     // transfer widget1 to layout2
       
   692     layout2->setAnchor(layout2, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 1);
       
   693     layout2->setAnchor(layout2, Qt::AnchorTop, widget1, Qt::AnchorTop, 1);
       
   694     layout2->setAnchor(widget1, Qt::AnchorRight, layout2, Qt::AnchorRight, 1);
       
   695     layout2->setAnchor(widget1, Qt::AnchorBottom, layout2, Qt::AnchorBottom, 1);
       
   696 
       
   697     // ###: uncomment when simplification bug is solved
       
   698     //widget->setGeometry(QRectF(0,0,100,100));
       
   699     //QCOMPARE(widget1->geometry(), QRectF(51,2,47,96));
       
   700     delete widget;
       
   701     }
       
   702 
       
   703     // One widget, set first to one layout then to another. Child reparented.
       
   704     // In addition widget as a direct child of another widget. Child reparented.
       
   705     {
       
   706     QGraphicsWidget *widget1 = new QGraphicsWidget;
       
   707     TheAnchorLayout *layout1 = new TheAnchorLayout();
       
   708     widget1->setLayout(layout1);
       
   709 
       
   710     TestWidget *childWidget = new TestWidget();
       
   711 
       
   712     // childWidget to layout1
       
   713     layout1->setAnchor(layout1, Qt::AnchorLeft, childWidget, Qt::AnchorLeft, 1);
       
   714     layout1->setAnchor(layout1, Qt::AnchorTop, childWidget, Qt::AnchorTop, 1);
       
   715     layout1->setAnchor(childWidget, Qt::AnchorRight, layout1, Qt::AnchorRight, 1);
       
   716     layout1->setAnchor(childWidget, Qt::AnchorBottom, layout1, Qt::AnchorBottom, 1);
       
   717 
       
   718     widget1->setGeometry(QRectF(0,0,100,100));
       
   719     QCOMPARE(childWidget->geometry(), QRectF(1,1,98,98));
       
   720     QVERIFY(childWidget->parentLayoutItem() == layout1);
       
   721     QGraphicsWidget *widget2 = new QGraphicsWidget;
       
   722     TheAnchorLayout *layout2 = new TheAnchorLayout();
       
   723     widget2->setLayout(layout2);
       
   724 
       
   725     // childWidget to layout2
       
   726     layout2->setAnchor(layout2, Qt::AnchorLeft, childWidget, Qt::AnchorLeft, 1);
       
   727     layout2->setAnchor(layout2, Qt::AnchorTop, childWidget, Qt::AnchorTop, 1);
       
   728     layout2->setAnchor(childWidget, Qt::AnchorRight, layout2, Qt::AnchorRight, 1);
       
   729     layout2->setAnchor(childWidget, Qt::AnchorBottom, layout2, Qt::AnchorBottom, 1);
       
   730 
       
   731     QGraphicsWidget *widget3 = new QGraphicsWidget;
       
   732     QGraphicsWidget *widget4 = new QGraphicsWidget;
       
   733     // widget4 is a direct child of widget3 (i.e. not in any layout)
       
   734     widget4->setParentItem(widget3);
       
   735 
       
   736     // widget4 to layout2
       
   737     layout2->setAnchor(layout2, Qt::AnchorLeft, widget4, Qt::AnchorLeft, 1);
       
   738     layout2->setAnchor(layout2, Qt::AnchorTop, widget4, Qt::AnchorTop, 1);
       
   739     layout2->setAnchor(widget4, Qt::AnchorRight, layout2, Qt::AnchorRight, 1);
       
   740     layout2->setAnchor(widget4, Qt::AnchorBottom, layout2, Qt::AnchorBottom, 1);
       
   741 
       
   742     widget2->setGeometry(QRectF(0,0,100,100));
       
   743     QCOMPARE(childWidget->geometry(), QRectF(1,1,98,98));
       
   744     QVERIFY(childWidget->parentLayoutItem() == layout2);
       
   745     QCOMPARE(widget4->geometry(), QRectF(1,1,98,98));
       
   746     QVERIFY(widget4->parentLayoutItem() == layout2);
       
   747     QVERIFY(widget4->parentItem() == widget2);
       
   748 
       
   749     delete widget4;
       
   750     delete widget3;
       
   751     delete widget1;
       
   752     delete childWidget;
       
   753     delete widget2;
       
   754     }
       
   755 }
       
   756 
       
   757 void tst_QGraphicsAnchorLayout1::testBasicLayout_data()
       
   758 {
       
   759     QTest::addColumn<QSizeF>("size");
       
   760     QTest::addColumn<BasicLayoutTestDataList>("data");
       
   761     QTest::addColumn<BasicLayoutTestResultList>("result");
       
   762 
       
   763     typedef BasicLayoutTestData BasicData;
       
   764     typedef BasicLayoutTestResult BasicResult;
       
   765 
       
   766     // One widget, basic
       
   767     {
       
   768         BasicLayoutTestDataList theData;
       
   769         BasicLayoutTestResultList theResult;
       
   770 
       
   771         theData
       
   772             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
   773             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 20)
       
   774             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 30)
       
   775             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 40)
       
   776             ;
       
   777 
       
   778         theResult
       
   779             << BasicResult(0, QRectF(20, 10, 150, 50) )
       
   780             ;
       
   781 
       
   782         QTest::newRow("One, simple") << QSizeF(200, 100) << theData << theResult;
       
   783     }
       
   784 
       
   785     // One widget, duplicates
       
   786     {
       
   787         BasicLayoutTestDataList theData;
       
   788         BasicLayoutTestResultList theResult;
       
   789 
       
   790         theData
       
   791             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
   792             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 20)
       
   793             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 30)
       
   794             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 40)
       
   795 
       
   796             << BasicData(0, Qt::AnchorTop, -1, Qt::AnchorTop, 0)
       
   797             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 0)
       
   798             << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorRight, 0)
       
   799             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 0)
       
   800             ;
       
   801 
       
   802         theResult
       
   803             << BasicResult(0, QRectF(0, 0, 200, 100) )
       
   804             ;
       
   805 
       
   806         QTest::newRow("One, duplicates") << QSizeF(200, 100) << theData << theResult;
       
   807     }
       
   808 
       
   809     // One widget, mixed
       
   810     {
       
   811         BasicLayoutTestDataList theData;
       
   812         BasicLayoutTestResultList theResult;
       
   813 
       
   814         theData
       
   815             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorBottom, 80)
       
   816             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorRight, 150)
       
   817             << BasicData(0, Qt::AnchorLeft, -1, Qt::AnchorRight, 150)
       
   818             << BasicData(0, Qt::AnchorTop, -1, Qt::AnchorBottom, 80)
       
   819             ;
       
   820 
       
   821         theResult
       
   822             << BasicResult(0, QRectF(50, 20, 100, 60) )
       
   823             ;
       
   824 
       
   825         QTest::newRow("One, mixed") << QSizeF(200, 100) << theData << theResult;
       
   826     }
       
   827 
       
   828     // Basic case - two widgets (same layout), different ordering
       
   829     {
       
   830         BasicLayoutTestDataList theData;
       
   831         BasicLayoutTestResultList theResult;
       
   832 
       
   833         theData
       
   834             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
   835             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
   836             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
   837             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
   838 
       
   839             << BasicData(1, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
   840             << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorLeft, 10)
       
   841             << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 10)
       
   842             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
   843             ;
       
   844 
       
   845         theResult
       
   846             << BasicResult(0, QRectF(10, 10, 180, 80) )
       
   847             << BasicResult(1, QRectF(10, 10, 180, 80) )
       
   848             ;
       
   849 
       
   850         QTest::newRow("Two, orderings") << QSizeF(200, 100) << theData << theResult;
       
   851     }
       
   852 
       
   853     // Basic case - two widgets, duplicate anchors
       
   854     {
       
   855         BasicLayoutTestDataList theData;
       
   856         BasicLayoutTestResultList theResult;
       
   857 
       
   858         theData
       
   859             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
   860             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
   861             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
   862             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
   863             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 30)
       
   864             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 20)
       
   865 
       
   866             << BasicData(1, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
   867             << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorLeft, 10)
       
   868             << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 10)
       
   869             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
   870             << BasicData(1, Qt::AnchorTop, -1, Qt::AnchorTop, 0)
       
   871             << BasicData(-1, Qt::AnchorRight, 1, Qt::AnchorRight, 0)
       
   872             ;
       
   873 
       
   874         theResult
       
   875             << BasicResult(0, QRectF(30, 10, 160, 70) )
       
   876             << BasicResult(1, QRectF(10, 0, 190, 90) )
       
   877             ;
       
   878 
       
   879         QTest::newRow("Two, duplicates") << QSizeF(200, 100) << theData << theResult;
       
   880     }
       
   881 
       
   882     // Basic case - two widgets, mixed
       
   883     {
       
   884         BasicLayoutTestDataList theData;
       
   885         BasicLayoutTestResultList theResult;
       
   886 
       
   887         theData
       
   888             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorBottom, 90)
       
   889             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorRight, 190)
       
   890             << BasicData(0, Qt::AnchorLeft, -1, Qt::AnchorRight, 190)
       
   891             << BasicData(0, Qt::AnchorTop, -1, Qt::AnchorBottom, 90)
       
   892 
       
   893             << BasicData(1, Qt::AnchorTop, -1, Qt::AnchorBottom, 20)
       
   894             << BasicData(1, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
   895             << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorLeft, 10)
       
   896             << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorRight, 20)
       
   897             ;
       
   898 
       
   899         // ### SIMPLIFICATION BUG FOR ITEM 1
       
   900         // ### remove this when bug is solved
       
   901 
       
   902         theResult
       
   903             << BasicResult(0, QRectF(10, 10, 180, 80) )
       
   904             << BasicResult(1, QRectF(10, 80, 10, 10) )
       
   905             ;
       
   906 
       
   907         QTest::newRow("Two, mixed") << QSizeF(200, 100) << theData << theResult;
       
   908     }
       
   909 
       
   910     // Basic case - two widgets, 1 horizontal connection, first completely defined
       
   911     {
       
   912         BasicLayoutTestDataList theData;
       
   913         BasicLayoutTestResultList theResult;
       
   914 
       
   915         theData
       
   916             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
   917             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
   918             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
   919             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 180)
       
   920 
       
   921             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorLeft, 10)
       
   922             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
   923             << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 10)
       
   924             << BasicData(1, Qt::AnchorBottom, -1, Qt::AnchorBottom, 20)
       
   925             ;
       
   926 
       
   927         theResult
       
   928             << BasicResult(0, QRectF(10, 10, 10, 80) )
       
   929             << BasicResult(1, QRectF(30, 10, 160, 70) )
       
   930             ;
       
   931 
       
   932         QTest::newRow("Two, 1h connected") << QSizeF(200, 100) << theData << theResult;
       
   933     }
       
   934 
       
   935     // Basic case - two widgets, 2 horizontal connections, first completely defined
       
   936     {
       
   937         BasicLayoutTestDataList theData;
       
   938         BasicLayoutTestResultList theResult;
       
   939 
       
   940         theData
       
   941             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
   942             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
   943             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
   944             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 180)
       
   945 
       
   946             // ### QGAL is not sensible to the argument order in this case
       
   947             //     To achieve the desired result we must explicitly set a negative
       
   948             //     spacing.
       
   949             // << BasicData(0, Qt::AnchorLeft, 1, Qt::AnchorRight, 100)
       
   950             << BasicData(0, Qt::AnchorLeft, 1, Qt::AnchorRight, -100)
       
   951 
       
   952             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorLeft, 30)
       
   953             << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 10)
       
   954             << BasicData(1, Qt::AnchorBottom, -1, Qt::AnchorBottom, 20)
       
   955             ;
       
   956 
       
   957         theResult
       
   958             << BasicResult(0, QRectF(10, 10, 10, 80) )
       
   959             << BasicResult(1, QRectF(50, 10, 60, 70) )
       
   960             ;
       
   961 
       
   962         QTest::newRow("Two, 2h connected") << QSizeF(200, 100) << theData << theResult;
       
   963     }
       
   964 
       
   965     // Basic case - two widgets, 1 vertical connection, first completely defined
       
   966     {
       
   967         BasicLayoutTestDataList theData;
       
   968         BasicLayoutTestResultList theResult;
       
   969 
       
   970         theData
       
   971             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
   972             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
   973             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
   974             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 180)
       
   975 
       
   976             << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorLeft, 30)
       
   977             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
   978             << BasicData(0, Qt::AnchorTop, 1, Qt::AnchorTop, 10)
       
   979             << BasicData(1, Qt::AnchorBottom, -1, Qt::AnchorBottom, 20)
       
   980             ;
       
   981 
       
   982         theResult
       
   983             << BasicResult(0, QRectF(10, 10, 10, 80) )
       
   984             << BasicResult(1, QRectF(30, 20, 160, 60) )
       
   985             ;
       
   986 
       
   987         QTest::newRow("Two, 1v connected") << QSizeF(200, 100) << theData << theResult;
       
   988     }
       
   989 
       
   990     // Basic case - two widgets, 2 vertical connections, first completely defined
       
   991     {
       
   992         BasicLayoutTestDataList theData;
       
   993         BasicLayoutTestResultList theResult;
       
   994 
       
   995         theData
       
   996             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
   997             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
   998             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
   999             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 180)
       
  1000 
       
  1001             << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorLeft, 30)
       
  1002             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  1003             << BasicData(0, Qt::AnchorTop, 1, Qt::AnchorTop, 10)
       
  1004             << BasicData(1, Qt::AnchorBottom, 0, Qt::AnchorBottom, 20)
       
  1005             ;
       
  1006 
       
  1007         theResult
       
  1008             << BasicResult(0, QRectF(10, 10, 10, 80) )
       
  1009             << BasicResult(1, QRectF(30, 20, 160, 50) )
       
  1010             ;
       
  1011 
       
  1012         QTest::newRow("Two, 2v connected") << QSizeF(200, 100) << theData << theResult;
       
  1013     }
       
  1014 
       
  1015     // Basic case - two widgets, 1 horizontal and 1 vertical connection, first completely defined
       
  1016     {
       
  1017         BasicLayoutTestDataList theData;
       
  1018         BasicLayoutTestResultList theResult;
       
  1019 
       
  1020         theData
       
  1021             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
  1022             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
  1023             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
  1024             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 180)
       
  1025 
       
  1026             << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorLeft, 80)
       
  1027             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorRight, 100)
       
  1028             << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 10)
       
  1029             << BasicData(1, Qt::AnchorBottom, 0, Qt::AnchorBottom, 10)
       
  1030             ;
       
  1031 
       
  1032         theResult
       
  1033             << BasicResult(0, QRectF(10, 10, 10, 80) )
       
  1034             << BasicResult(1, QRectF(80, 10, 40, 70) )
       
  1035             ;
       
  1036 
       
  1037         QTest::newRow("Two, 1h+1v connected") << QSizeF(200, 100) << theData << theResult;
       
  1038     }
       
  1039 
       
  1040     // Basic case - two widgets, 2 horizontal and 2 vertical connections, first completely defined
       
  1041     {
       
  1042         BasicLayoutTestDataList theData;
       
  1043         BasicLayoutTestResultList theResult;
       
  1044 
       
  1045         theData
       
  1046             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
  1047             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
  1048             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
  1049             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 180)
       
  1050 
       
  1051             << BasicData(0, Qt::AnchorLeft, 1, Qt::AnchorLeft, 80)
       
  1052             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorRight, 100)
       
  1053             << BasicData(0, Qt::AnchorTop, 1, Qt::AnchorTop, 10)
       
  1054             << BasicData(1, Qt::AnchorBottom, 0, Qt::AnchorBottom, 10)
       
  1055             ;
       
  1056 
       
  1057         theResult
       
  1058             << BasicResult(0, QRectF(10, 10, 10, 80) )
       
  1059             << BasicResult(1, QRectF(90, 20, 30, 60) )
       
  1060             ;
       
  1061 
       
  1062         QTest::newRow("Two, 2h+2v connected") << QSizeF(200, 100) << theData << theResult;
       
  1063     }
       
  1064 
       
  1065     // Basic case - two widgets, 2 horizontal and 2 vertical connections, dependent on each other.
       
  1066     {
       
  1067         BasicLayoutTestDataList theData;
       
  1068         BasicLayoutTestResultList theResult;
       
  1069 
       
  1070         theData
       
  1071             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
  1072             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorRight, 150)
       
  1073             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
  1074             << BasicData(0, Qt::AnchorBottom, 1, Qt::AnchorBottom, 10)
       
  1075 
       
  1076             << BasicData(0, Qt::AnchorLeft, 1, Qt::AnchorLeft, 90)
       
  1077             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  1078             << BasicData(0, Qt::AnchorTop, 1, Qt::AnchorTop, 10)
       
  1079             << BasicData(1, Qt::AnchorBottom, -1, Qt::AnchorBottom, 20)
       
  1080             ;
       
  1081 
       
  1082         theResult
       
  1083             << BasicResult(0, QRectF(10, 10, 30, 60) )
       
  1084             << BasicResult(1, QRectF(100, 20, 90, 60) )
       
  1085             ;
       
  1086 
       
  1087         QTest::newRow("Two, 2h+2v connected2") << QSizeF(200, 100) << theData << theResult;
       
  1088     }
       
  1089 
       
  1090     // Basic case - two widgets, connected, overlapping
       
  1091     {
       
  1092         BasicLayoutTestDataList theData;
       
  1093         BasicLayoutTestResultList theResult;
       
  1094 
       
  1095         theData
       
  1096             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
  1097             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
  1098             // << BasicData(1, Qt::AnchorLeft, 0, Qt::AnchorRight, 30)
       
  1099             // ### QGAL has different semantics and assumes right edges are always
       
  1100             //     to the left of left edges. Thus we need the minus sign here.
       
  1101             << BasicData(1, Qt::AnchorLeft, 0, Qt::AnchorRight, -30)
       
  1102             << BasicData(0, Qt::AnchorBottom, 1, Qt::AnchorBottom, 40)
       
  1103 
       
  1104             << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorLeft, 40)
       
  1105             << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 20)
       
  1106             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  1107             << BasicData(1, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
  1108             ;
       
  1109 
       
  1110         theResult
       
  1111             << BasicResult(0, QRectF(10, 10, 60, 40) )
       
  1112             << BasicResult(1, QRectF(40, 20, 150, 70) )
       
  1113             ;
       
  1114 
       
  1115         QTest::newRow("Two, connected overlapping") << QSizeF(200, 100) << theData << theResult;
       
  1116     }
       
  1117 }
       
  1118 
       
  1119 void tst_QGraphicsAnchorLayout1::testNegativeSpacing_data()
       
  1120 {
       
  1121     QTest::addColumn<QSizeF>("size");
       
  1122     QTest::addColumn<BasicLayoutTestDataList>("data");
       
  1123     QTest::addColumn<BasicLayoutTestResultList>("result");
       
  1124 
       
  1125     typedef BasicLayoutTestData BasicData;
       
  1126     typedef BasicLayoutTestResult BasicResult;
       
  1127 
       
  1128     // One widget, negative spacing
       
  1129     {
       
  1130         BasicLayoutTestDataList theData;
       
  1131         BasicLayoutTestResultList theResult;
       
  1132 
       
  1133         /// ### QGAL assumes items are always inside the layout.
       
  1134         //      In this case, the negative spacing would make the item
       
  1135         //      grow beyond the layout edges, which is OK, but gives a
       
  1136         //      different result.
       
  1137         //      Changing the direction of anchors (-1 to 0 or vice-versa)
       
  1138         //      has no effect in this case.
       
  1139 
       
  1140         theData
       
  1141             // << BasicData(0, Qt::AnchorTop, -1, Qt::AnchorTop, -10)
       
  1142             // << BasicData(0, Qt::AnchorLeft, -1, Qt::AnchorLeft, -20)
       
  1143             // << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorRight, -30)
       
  1144             // << BasicData(-1, Qt::AnchorBottom, 0, Qt::AnchorBottom, -40)
       
  1145 
       
  1146             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, -10)
       
  1147             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, -20)
       
  1148             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, -30)
       
  1149             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, -40)
       
  1150 
       
  1151             ;
       
  1152 
       
  1153         theResult
       
  1154             // << BasicResult(0, QRectF(20, 10, 150, 50) )
       
  1155             << BasicResult(0, QRectF(-20, -10, 250, 150) )
       
  1156             ;
       
  1157 
       
  1158         QTest::newRow("One, simple (n)") << QSizeF(200, 100) << theData << theResult;
       
  1159     }
       
  1160 
       
  1161     // One widget, duplicates, negative spacing
       
  1162     {
       
  1163         BasicLayoutTestDataList theData;
       
  1164         BasicLayoutTestResultList theResult;
       
  1165 
       
  1166         theData
       
  1167             << BasicData(0, Qt::AnchorTop, -1, Qt::AnchorTop, -20)
       
  1168             << BasicData(0, Qt::AnchorLeft, -1, Qt::AnchorLeft, -20)
       
  1169             << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorRight, -30)
       
  1170             << BasicData(-1, Qt::AnchorBottom, 0, Qt::AnchorBottom, -40)
       
  1171 
       
  1172             << BasicData(0, Qt::AnchorTop, -1, Qt::AnchorTop, -10)
       
  1173             << BasicData(0, Qt::AnchorLeft, -1, Qt::AnchorLeft, -10)
       
  1174             << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorRight, -10)
       
  1175             << BasicData(-1, Qt::AnchorBottom, 0, Qt::AnchorBottom, -10)
       
  1176             ;
       
  1177 
       
  1178         theResult
       
  1179             // ### Same as above...
       
  1180             // << BasicResult(0, QRectF(10, 10, 180, 80) )
       
  1181             << BasicResult(0, QRectF(-10, -10, 220, 120) )
       
  1182             ;
       
  1183 
       
  1184         QTest::newRow("One, duplicates (n)") << QSizeF(200, 100) << theData << theResult;
       
  1185     }
       
  1186 
       
  1187     // One widget, mixed, negative spacing
       
  1188     {
       
  1189         BasicLayoutTestDataList theData;
       
  1190         BasicLayoutTestResultList theResult;
       
  1191 
       
  1192         theData
       
  1193             // ### All anchors of negative spacing between the layout and an
       
  1194             //     item are handled as to make sure the item is _outside_ the
       
  1195             //     layout.
       
  1196             //     To keep it inside, one _must_ use positive spacings.
       
  1197             // << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorTop, -80)
       
  1198             // << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorLeft, -150)
       
  1199             // << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorLeft, -150)
       
  1200             // << BasicData(-1, Qt::AnchorBottom, 0, Qt::AnchorTop, -80)
       
  1201 
       
  1202             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorTop, 80)
       
  1203             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorLeft, 150)
       
  1204             << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorLeft, 150)
       
  1205             << BasicData(-1, Qt::AnchorBottom, 0, Qt::AnchorTop, 80)
       
  1206             ;
       
  1207 
       
  1208         theResult
       
  1209             << BasicResult(0, QRectF(50, 20, 100, 60) )
       
  1210             ;
       
  1211 
       
  1212         QTest::newRow("One, mixed (n)") << QSizeF(200, 100) << theData << theResult;
       
  1213     }
       
  1214 
       
  1215     // Basic case - two widgets, 1 horizontal connection, first completely defined, negative spacing
       
  1216     {
       
  1217         BasicLayoutTestDataList theData;
       
  1218         BasicLayoutTestResultList theResult;
       
  1219 
       
  1220         theData
       
  1221             // << BasicData(0, Qt::AnchorTop, -1, Qt::AnchorTop, -10)
       
  1222             // << BasicData(-1, Qt::AnchorBottom, 0, Qt::AnchorBottom, -10)
       
  1223             // << BasicData(0, Qt::AnchorLeft, -1, Qt::AnchorLeft, -10)
       
  1224             // << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorRight, -180)
       
  1225 
       
  1226             // << BasicData(1, Qt::AnchorLeft, 0, Qt::AnchorRight, -10)
       
  1227             // << BasicData(-1, Qt::AnchorRight, 1, Qt::AnchorRight, -10)
       
  1228             // << BasicData(1, Qt::AnchorTop, -1, Qt::AnchorTop, -10)
       
  1229             // << BasicData(-1, Qt::AnchorBottom, 1, Qt::AnchorBottom, -20)
       
  1230 
       
  1231             << BasicData(0, Qt::AnchorTop, -1, Qt::AnchorTop, -10)
       
  1232             << BasicData(-1, Qt::AnchorBottom, 0, Qt::AnchorBottom, -10)
       
  1233             << BasicData(0, Qt::AnchorLeft, -1, Qt::AnchorLeft, -10)
       
  1234             << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorRight, 180)
       
  1235 
       
  1236             << BasicData(1, Qt::AnchorLeft, 0, Qt::AnchorRight, -10)
       
  1237             << BasicData(-1, Qt::AnchorRight, 1, Qt::AnchorRight, -10)
       
  1238             << BasicData(1, Qt::AnchorTop, -1, Qt::AnchorTop, -10)
       
  1239             << BasicData(-1, Qt::AnchorBottom, 1, Qt::AnchorBottom, -20)
       
  1240 
       
  1241             ;
       
  1242 
       
  1243         theResult
       
  1244             // << BasicResult(0, QRectF(10, 10, 10, 80) )
       
  1245             // << BasicResult(1, QRectF(30, 10, 160, 70) )
       
  1246 
       
  1247             << BasicResult(0, QRectF(-10, -10, 30, 120) )
       
  1248             << BasicResult(1, QRectF(10, -10, 200, 130) )
       
  1249             ;
       
  1250 
       
  1251         QTest::newRow("Two, 1h connected (n)") << QSizeF(200, 100) << theData << theResult;
       
  1252     }
       
  1253 
       
  1254     // Basic case - two widgets, 2 horizontal and 2 vertical connections, dependent on each other, negative spacing
       
  1255     {
       
  1256         BasicLayoutTestDataList theData;
       
  1257         BasicLayoutTestResultList theResult;
       
  1258 
       
  1259         theData
       
  1260             << BasicData(0, Qt::AnchorLeft, -1, Qt::AnchorLeft, -10)
       
  1261             << BasicData(1, Qt::AnchorRight, 0, Qt::AnchorRight, -150)
       
  1262             << BasicData(0, Qt::AnchorTop, -1, Qt::AnchorTop, -10)
       
  1263             << BasicData(1, Qt::AnchorBottom, 0, Qt::AnchorBottom, -10)
       
  1264 
       
  1265             << BasicData(1, Qt::AnchorLeft, 0, Qt::AnchorLeft, -90)
       
  1266             << BasicData(-1, Qt::AnchorRight, 1, Qt::AnchorRight, -10)
       
  1267             << BasicData(1, Qt::AnchorTop, 0, Qt::AnchorTop, -10)
       
  1268             << BasicData(-1, Qt::AnchorBottom, 1, Qt::AnchorBottom, -20)
       
  1269             ;
       
  1270 
       
  1271         theResult
       
  1272             // << BasicResult(0, QRectF(10, 10, 30, 60) )
       
  1273             // << BasicResult(1, QRectF(100, 20, 90, 60) )
       
  1274             << BasicResult(0, QRectF(-10, -10, 70, 120) )
       
  1275             << BasicResult(1, QRectF(80, 0, 130, 120) )
       
  1276             ;
       
  1277 
       
  1278         QTest::newRow("Two, 2h+2v connected2 (n)") << QSizeF(200, 100) << theData << theResult;
       
  1279     }
       
  1280 }
       
  1281 
       
  1282 void tst_QGraphicsAnchorLayout1::testMixedSpacing_data()
       
  1283 {
       
  1284     QTest::addColumn<QSizeF>("size");
       
  1285     QTest::addColumn<BasicLayoutTestDataList>("data");
       
  1286     QTest::addColumn<BasicLayoutTestResultList>("result");
       
  1287 
       
  1288     typedef BasicLayoutTestData BasicData;
       
  1289     typedef BasicLayoutTestResult BasicResult;
       
  1290 
       
  1291     // Two widgets, partial overlapping
       
  1292     {
       
  1293         BasicLayoutTestDataList theData;
       
  1294         BasicLayoutTestResultList theResult;
       
  1295 
       
  1296         theData
       
  1297             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
  1298             << BasicData(0, Qt::AnchorLeft, -1, Qt::AnchorLeft, -50)
       
  1299             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 50)
       
  1300             << BasicData(1, Qt::AnchorRight, 0, Qt::AnchorRight, 15)
       
  1301 
       
  1302             // << BasicData(1, Qt::AnchorTop, 0, Qt::AnchorBottom, 5)
       
  1303             << BasicData(1, Qt::AnchorTop, 0, Qt::AnchorBottom, -5)
       
  1304             << BasicData(0, Qt::AnchorLeft, 1, Qt::AnchorLeft, -10)
       
  1305             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 20)
       
  1306             << BasicData(-1, Qt::AnchorBottom, 1, Qt::AnchorBottom, -5)
       
  1307             ;
       
  1308 
       
  1309         theResult
       
  1310             // << BasicResult(0, QRectF(50, 10, 45, 40) )
       
  1311             // << BasicResult(1, QRectF(40, 45, 40, 50) )
       
  1312             << BasicResult(0, QRectF(-50, 10, 145, 40) )
       
  1313             << BasicResult(1, QRectF(-60, 45, 140, 60) )
       
  1314             ;
       
  1315 
       
  1316         QTest::newRow("Two, partial overlap") << QSizeF(100, 100) << theData << theResult;
       
  1317     }
       
  1318 
       
  1319     // Two widgets, complete overlapping
       
  1320     {
       
  1321         BasicLayoutTestDataList theData;
       
  1322         BasicLayoutTestResultList theResult;
       
  1323 
       
  1324         theData
       
  1325             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 5)
       
  1326             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorRight, 0)
       
  1327             << BasicData(0, Qt::AnchorTop, 1, Qt::AnchorTop, 0)
       
  1328             << BasicData(1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 25)
       
  1329 
       
  1330             << BasicData(1, Qt::AnchorBottom, 0, Qt::AnchorBottom, 0)
       
  1331             << BasicData(1, Qt::AnchorBottom, -1, Qt::AnchorBottom, 5)
       
  1332             << BasicData(1, Qt::AnchorLeft, -1, Qt::AnchorRight, 50)
       
  1333             << BasicData(-1, Qt::AnchorRight, 1, Qt::AnchorRight, -10)
       
  1334             ;
       
  1335 
       
  1336         theResult
       
  1337             << BasicResult(0, QRectF(65, 5, 35, 35) )
       
  1338             << BasicResult(1, QRectF(40, 5, 60, 35) )
       
  1339             ;
       
  1340 
       
  1341         QTest::newRow("Two, complete overlap") << QSizeF(90, 45) << theData << theResult;
       
  1342     }
       
  1343 
       
  1344     // Five widgets, v shaped, edges shared
       
  1345     {
       
  1346         BasicLayoutTestDataList theData;
       
  1347         BasicLayoutTestResultList theResult;
       
  1348 
       
  1349         theData
       
  1350             // edges shared
       
  1351             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorLeft, 0)
       
  1352             << BasicData(1, Qt::AnchorRight, 2, Qt::AnchorLeft, 0)
       
  1353             << BasicData(2, Qt::AnchorRight, 3, Qt::AnchorLeft, 0)
       
  1354             << BasicData(3, Qt::AnchorRight, 4, Qt::AnchorLeft, 0)
       
  1355             << BasicData(1, Qt::AnchorBottom, 2, Qt::AnchorTop, 0)
       
  1356             << BasicData(0, Qt::AnchorBottom, 1, Qt::AnchorTop, 0)
       
  1357             << BasicData(3, Qt::AnchorBottom, 2, Qt::AnchorTop, 0)
       
  1358             << BasicData(4, Qt::AnchorBottom, 3, Qt::AnchorTop, 0)
       
  1359             << BasicData(0, Qt::AnchorBottom, 4, Qt::AnchorBottom, 0)
       
  1360             << BasicData(1, Qt::AnchorBottom, 3, Qt::AnchorBottom, 0)
       
  1361             << BasicData(0, Qt::AnchorTop, 4, Qt::AnchorTop, 0)
       
  1362             << BasicData(1, Qt::AnchorTop, 3, Qt::AnchorTop, 0)
       
  1363 
       
  1364             // margins
       
  1365             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 5)
       
  1366             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 5)
       
  1367             << BasicData(2, Qt::AnchorBottom, -1, Qt::AnchorBottom, 5)
       
  1368             // << BasicData(-1, Qt::AnchorRight, 4, Qt::AnchorRight, -5)
       
  1369             << BasicData(-1, Qt::AnchorRight, 4, Qt::AnchorRight, 5)
       
  1370 
       
  1371             // additional details for exact size determination easily
       
  1372             << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorLeft, 25)
       
  1373             << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorRight, 50)
       
  1374             // << BasicData(-1, Qt::AnchorRight, 3, Qt::AnchorRight, -25)
       
  1375             // << BasicData(-1, Qt::AnchorRight, 2, Qt::AnchorRight, -50)
       
  1376             << BasicData(-1, Qt::AnchorRight, 3, Qt::AnchorRight, 25)
       
  1377             << BasicData(-1, Qt::AnchorRight, 2, Qt::AnchorRight, 50)
       
  1378             << BasicData(-1, Qt::AnchorTop, 3, Qt::AnchorBottom, 50)
       
  1379             // << BasicData(-1, Qt::AnchorBottom, 3, Qt::AnchorTop, -50)
       
  1380             << BasicData(-1, Qt::AnchorBottom, 3, Qt::AnchorTop, 50)
       
  1381 
       
  1382             ;
       
  1383 
       
  1384         theResult
       
  1385             << BasicResult(0, QRectF(5,5,20,20))
       
  1386             << BasicResult(1, QRectF(25,25,25,25))
       
  1387             << BasicResult(2, QRectF(50,50,25,20))
       
  1388             << BasicResult(3, QRectF(75,25,25,25))
       
  1389             << BasicResult(4, QRectF(100,5,20,20))
       
  1390             ;
       
  1391 
       
  1392         QTest::newRow("Five, V shape") << QSizeF(125, 75) << theData << theResult;
       
  1393     }
       
  1394 
       
  1395     // ### The behavior is different in QGraphicsAnchorLayout. What happens here is
       
  1396     //     that when the above anchors are set, the layout size hints are changed.
       
  1397     //     In the example, the minimum item width is 5, thus the minimum layout width
       
  1398     //     becomes 105 (50 + 5 + 50). Once that size hint is set, trying to set
       
  1399     //     the widget size to (10, 10) is not possible because
       
  1400     //     QGraphicsWidget::setGeometry() will enforce the minimum is respected.
       
  1401     if (0)
       
  1402     // One widget, unsolvable
       
  1403     {
       
  1404         BasicLayoutTestDataList theData;
       
  1405         BasicLayoutTestResultList theResult;
       
  1406 
       
  1407         theData
       
  1408                 << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 50)
       
  1409                 << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 50)
       
  1410                 ;
       
  1411         theResult
       
  1412                 << BasicResult(0, QRectF(0,0,0,0))
       
  1413                 ;
       
  1414 
       
  1415         QTest::newRow("One widget, unsolvable") << QSizeF(10, 10) << theData << theResult;
       
  1416     }
       
  1417 
       
  1418     // Two widgets, one has fixed size
       
  1419     {
       
  1420         BasicLayoutTestDataList theData;
       
  1421         BasicLayoutTestResultList theResult;
       
  1422 
       
  1423         theData
       
  1424                 << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 50)
       
  1425                 << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 50)
       
  1426             // not supported, use sizePolicy instead
       
  1427             // << BasicData(0, Qt::AnchorLeft, 0, Qt::AnchorRight, 50)
       
  1428 
       
  1429                 << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorLeft, 50)
       
  1430                 << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 50)
       
  1431                 ;
       
  1432         theResult
       
  1433                 << BasicResult(0, QRectF(50,0,50,50))
       
  1434                 << BasicResult(1, QRectF(50,0,50,50))
       
  1435                 ;
       
  1436 
       
  1437         QTest::newRow("Two widgets, one has fixed size") << QSizeF(150, 150) << theData << theResult;
       
  1438     }
       
  1439 }
       
  1440 
       
  1441 void tst_QGraphicsAnchorLayout1::testMulti_data()
       
  1442 {
       
  1443     QTest::addColumn<QSizeF>("size");
       
  1444     QTest::addColumn<BasicLayoutTestDataList>("data");
       
  1445     QTest::addColumn<BasicLayoutTestResultList>("result");
       
  1446 
       
  1447     typedef BasicLayoutTestData BasicData;
       
  1448     typedef BasicLayoutTestResult BasicResult;
       
  1449 
       
  1450     // Multiple widgets, all overllapping
       
  1451     {
       
  1452         BasicLayoutTestDataList theData;
       
  1453         BasicLayoutTestResultList theResult;
       
  1454 
       
  1455         const int n = 30;
       
  1456         for ( int i = 0 ; i < n; i++ ) {
       
  1457             theData
       
  1458                 << BasicData(-1, Qt::AnchorTop, i, Qt::AnchorTop, 20)
       
  1459                 << BasicData(-1, Qt::AnchorLeft, i, Qt::AnchorLeft, 10)
       
  1460                 // << BasicData(-1, Qt::AnchorBottom, i, Qt::AnchorBottom, -40)
       
  1461                 // << BasicData(-1, Qt::AnchorRight, i, Qt::AnchorRight, -30);
       
  1462                 << BasicData(-1, Qt::AnchorBottom, i, Qt::AnchorBottom, 40)
       
  1463                 << BasicData(-1, Qt::AnchorRight, i, Qt::AnchorRight, 30);
       
  1464 
       
  1465             theResult
       
  1466                 << BasicResult(i, QRectF(10, 20, 160, 40) );
       
  1467         }
       
  1468 
       
  1469 
       
  1470         QTest::newRow("Overlapping multi") << QSizeF(200, 100) << theData << theResult;
       
  1471     }
       
  1472 
       
  1473     // Multiple widgets, linear order
       
  1474     {
       
  1475         BasicLayoutTestDataList theData;
       
  1476         BasicLayoutTestResultList theResult;
       
  1477 
       
  1478         const qreal height = 1000.f;
       
  1479         const qreal width = 2000.f;
       
  1480 
       
  1481         const int n = 30;
       
  1482 
       
  1483         const qreal verticalStep = height/qreal(n+2);
       
  1484         const qreal horizontalStep = width/qreal(n+2);
       
  1485 
       
  1486         for ( int i = 0 ; i < n; i++ ) {
       
  1487 
       
  1488             if ( i == 0 ) {
       
  1489                 // First item
       
  1490                 theData
       
  1491                     << BasicData(-1, Qt::AnchorTop, i, Qt::AnchorTop, verticalStep)
       
  1492                     << BasicData(-1, Qt::AnchorLeft, i, Qt::AnchorLeft, horizontalStep)
       
  1493                     << BasicData(i+1, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep)
       
  1494                     << BasicData(i+1, Qt::AnchorRight, i, Qt::AnchorRight, -horizontalStep);
       
  1495 
       
  1496             } else if ( i == n-1 ) {
       
  1497                 // Last item
       
  1498                 theData
       
  1499                     << BasicData(i-1, Qt::AnchorTop, i, Qt::AnchorTop, verticalStep)
       
  1500                     << BasicData(i-1, Qt::AnchorLeft, i, Qt::AnchorLeft, horizontalStep)
       
  1501                     << BasicData(-1, Qt::AnchorBottom, i, Qt::AnchorBottom, verticalStep)
       
  1502                     << BasicData(-1, Qt::AnchorRight, i, Qt::AnchorRight, horizontalStep);
       
  1503                     // << BasicData(-1, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep)
       
  1504                     // << BasicData(-1, Qt::AnchorRight, i, Qt::AnchorRight, -horizontalStep);
       
  1505 
       
  1506             } else {
       
  1507                 // items in the middle
       
  1508                 theData
       
  1509                     << BasicData(i-1, Qt::AnchorTop, i, Qt::AnchorTop, verticalStep)
       
  1510                     << BasicData(i-1, Qt::AnchorLeft, i, Qt::AnchorLeft, horizontalStep)
       
  1511                     << BasicData(i+1, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep)
       
  1512                     << BasicData(i+1, Qt::AnchorRight, i, Qt::AnchorRight, -horizontalStep);
       
  1513                     // << BasicData(i+1, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep)
       
  1514                     // << BasicData(i+1, Qt::AnchorRight, i, Qt::AnchorRight, -horizontalStep);
       
  1515 
       
  1516             }
       
  1517 
       
  1518             theResult
       
  1519                 << BasicResult(i, QRectF((i+1)*horizontalStep, (i+1)*verticalStep, horizontalStep, verticalStep) );
       
  1520         }
       
  1521 
       
  1522 
       
  1523         QTest::newRow("Linear multi") << QSizeF(width, height) << theData << theResult;
       
  1524     }
       
  1525 
       
  1526     // Multiple widgets, V shape
       
  1527     {
       
  1528         BasicLayoutTestDataList theData;
       
  1529         BasicLayoutTestResultList theResult;
       
  1530 
       
  1531         const qreal height = 100.f;
       
  1532         const qreal width = 200.f;
       
  1533 
       
  1534         const int n = 31; // odd number please (3,5,7... )
       
  1535 
       
  1536         const qreal verticalStep = height/(2.f+(n+1)/2.f);
       
  1537         const qreal horizontalStep = width/(n+2.f);
       
  1538 
       
  1539         for ( int i = 0 ; i < n; i++ ) {
       
  1540 
       
  1541             if ( i == 0 ) {
       
  1542                 // First item
       
  1543                 theData
       
  1544                     << BasicData(-1, Qt::AnchorTop, i, Qt::AnchorTop, verticalStep)
       
  1545                     << BasicData(-1, Qt::AnchorLeft, i, Qt::AnchorLeft, horizontalStep)
       
  1546                     << BasicData(i+1, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep)
       
  1547                     << BasicData(i, Qt::AnchorRight, i+1, Qt::AnchorRight, horizontalStep);
       
  1548 
       
  1549             } else if ( i == n-1 ) {
       
  1550                 // Last item
       
  1551                 theData
       
  1552                     << BasicData(i-1, Qt::AnchorTop, i, Qt::AnchorTop, -verticalStep)
       
  1553                     << BasicData(i-1, Qt::AnchorLeft, i, Qt::AnchorLeft, horizontalStep)
       
  1554                     << BasicData(i-1, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep)
       
  1555                     << BasicData(i, Qt::AnchorRight, -1, Qt::AnchorRight, horizontalStep);
       
  1556             } else if ( i == ((n-1)/2) ) {
       
  1557                 // midway
       
  1558                 theData
       
  1559                     << BasicData(i-1, Qt::AnchorTop, i, Qt::AnchorTop, verticalStep)
       
  1560                     << BasicData(i-1, Qt::AnchorLeft, i, Qt::AnchorLeft, horizontalStep)
       
  1561                     // << BasicData(-1, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep)
       
  1562                     << BasicData(-1, Qt::AnchorBottom, i, Qt::AnchorBottom, verticalStep)
       
  1563                     << BasicData(i, Qt::AnchorRight, i+1, Qt::AnchorRight, horizontalStep);
       
  1564             } else if ( i < ((n-1)/2) ) {
       
  1565                 // before midway - going down
       
  1566                 theData
       
  1567                     << BasicData(i-1, Qt::AnchorTop, i, Qt::AnchorTop, verticalStep)
       
  1568                     << BasicData(i-1, Qt::AnchorLeft, i, Qt::AnchorLeft, horizontalStep)
       
  1569                     << BasicData(i+1, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep)
       
  1570                     << BasicData(i, Qt::AnchorRight, i+1, Qt::AnchorRight, horizontalStep);
       
  1571 
       
  1572             } else {
       
  1573                 // after midway - going up
       
  1574                 theData
       
  1575                     << BasicData(i-1, Qt::AnchorTop, i, Qt::AnchorTop, -verticalStep)
       
  1576                     << BasicData(i-1, Qt::AnchorLeft, i, Qt::AnchorLeft, horizontalStep)
       
  1577                     << BasicData(i-1, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep)
       
  1578                     << BasicData(i, Qt::AnchorRight, i+1, Qt::AnchorRight, horizontalStep);
       
  1579 
       
  1580             }
       
  1581 
       
  1582             if ( i <= ((n-1)/2) ) {
       
  1583                 // until midway
       
  1584                 theResult
       
  1585                     << BasicResult(i, QRectF((i+1)*horizontalStep, (i+1)*verticalStep, horizontalStep, verticalStep) );
       
  1586             } else {
       
  1587                 // after midway
       
  1588                 theResult
       
  1589                     << BasicResult(i, QRectF((i+1)*horizontalStep, (n-i)*verticalStep, horizontalStep, verticalStep) );
       
  1590             }
       
  1591 
       
  1592         }
       
  1593         QTest::newRow("V multi") << QSizeF(width, height) << theData << theResult;
       
  1594     }
       
  1595 
       
  1596     // Multiple widgets, grid
       
  1597     {
       
  1598         BasicLayoutTestDataList theData;
       
  1599         BasicLayoutTestResultList theResult;
       
  1600 
       
  1601         const qreal height = 100.f;
       
  1602         const qreal width = 200.f;
       
  1603 
       
  1604         const int d = 10; // items per dimension
       
  1605         const int n = d*d;
       
  1606 
       
  1607         const qreal verticalStep = height/(d+2.f);
       
  1608         const qreal horizontalStep = width/(d+2.f);
       
  1609 
       
  1610         for ( int i = 0 ; i < n; i++ ) {
       
  1611             if ( i%d == 0 ) {
       
  1612                 // left side item
       
  1613                 theData
       
  1614                     << BasicData(-1, Qt::AnchorLeft, i, Qt::AnchorLeft, horizontalStep)
       
  1615                     << BasicData(i+1, Qt::AnchorRight, i, Qt::AnchorRight, -horizontalStep);
       
  1616             } else if ( (i+1)%d == 0 ) {
       
  1617                 // rigth side item
       
  1618                 theData
       
  1619                     << BasicData(i-1, Qt::AnchorLeft, i, Qt::AnchorLeft, horizontalStep)
       
  1620                     // << BasicData(-1, Qt::AnchorRight, i, Qt::AnchorRight, -horizontalStep);
       
  1621                     << BasicData(-1, Qt::AnchorRight, i, Qt::AnchorRight, horizontalStep);
       
  1622             } else {
       
  1623                 // horizontal middle
       
  1624                 theData
       
  1625                     << BasicData(i-1, Qt::AnchorLeft, i, Qt::AnchorLeft, horizontalStep)
       
  1626                     << BasicData(i+1, Qt::AnchorRight, i, Qt::AnchorRight, -horizontalStep);
       
  1627             }
       
  1628 
       
  1629             if ( i < d ) {
       
  1630                 // top line
       
  1631                 theData
       
  1632                     << BasicData(-1, Qt::AnchorTop, i, Qt::AnchorTop, verticalStep)
       
  1633                     << BasicData(i+d, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep);
       
  1634             } else if ( i >= (d-1)*d ){
       
  1635                 // bottom line
       
  1636                 theData
       
  1637                     << BasicData(i-d, Qt::AnchorTop, i, Qt::AnchorTop, verticalStep)
       
  1638                     // << BasicData(-1, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep)
       
  1639                     << BasicData(-1, Qt::AnchorBottom, i, Qt::AnchorBottom, verticalStep);
       
  1640             } else {
       
  1641                 // vertical middle
       
  1642                 theData
       
  1643                     << BasicData(i-d, Qt::AnchorTop, i, Qt::AnchorTop, verticalStep)
       
  1644                     << BasicData(i+d, Qt::AnchorBottom, i, Qt::AnchorBottom, -verticalStep);
       
  1645             }
       
  1646 
       
  1647             theResult
       
  1648                 << BasicResult(i, QRectF(((i%d)+1)*horizontalStep, ((i/d)+1)*verticalStep, horizontalStep, verticalStep) );
       
  1649         }
       
  1650 
       
  1651         QTest::newRow("Grid multi") << QSizeF(200, 100) << theData << theResult;
       
  1652     }
       
  1653 }
       
  1654 
       
  1655 inline QGraphicsLayoutItem *getItem(
       
  1656         int index,
       
  1657         const QList<QGraphicsWidget *>& widgets,
       
  1658         QGraphicsLayoutItem *defaultItem)
       
  1659 {
       
  1660     if (index < 0) {
       
  1661         return defaultItem;
       
  1662     }
       
  1663 
       
  1664     return widgets[index];
       
  1665 }
       
  1666 
       
  1667 void tst_QGraphicsAnchorLayout1::testBasicLayout()
       
  1668 {
       
  1669     QFETCH(QSizeF, size);
       
  1670     QFETCH(BasicLayoutTestDataList, data);
       
  1671     QFETCH(BasicLayoutTestResultList, result);
       
  1672 
       
  1673     QGraphicsWidget *widget = new QGraphicsWidget;
       
  1674 
       
  1675     // Determine amount of widgets to add.
       
  1676     int widgetCount = -1;
       
  1677     for (int i = 0; i < data.count(); ++i) {
       
  1678         const BasicLayoutTestData item = data[i];
       
  1679         widgetCount = qMax(widgetCount, item.firstIndex);
       
  1680         widgetCount = qMax(widgetCount, item.secondIndex);
       
  1681     }
       
  1682     ++widgetCount; // widgetCount is max of indices.
       
  1683 
       
  1684     // Create dummy widgets
       
  1685     QList<QGraphicsWidget *> widgets;
       
  1686     for (int i = 0; i < widgetCount; ++i) {
       
  1687         TestWidget *w = new TestWidget;
       
  1688         widgets << w;
       
  1689     }
       
  1690 
       
  1691     // Setup anchor layout
       
  1692     TheAnchorLayout *layout = new TheAnchorLayout;
       
  1693 
       
  1694     for (int i = 0; i < data.count(); ++i) {
       
  1695         const BasicLayoutTestData item = data[i];
       
  1696         layout->setAnchor(
       
  1697             getItem(item.firstIndex, widgets, layout),
       
  1698             item.firstEdge,
       
  1699             getItem(item.secondIndex, widgets, layout),
       
  1700             item.secondEdge,
       
  1701             item.spacing );
       
  1702     }
       
  1703 
       
  1704     widget->setLayout(layout);
       
  1705     widget->setContentsMargins(0,0,0,0);
       
  1706 
       
  1707     widget->setMinimumSize(size);
       
  1708     widget->setMaximumSize(size);
       
  1709 
       
  1710 //    QTest::qWait(500); // layouting is asynchronous..
       
  1711 
       
  1712     // Validate
       
  1713     for (int i = 0; i < result.count(); ++i) {
       
  1714         const BasicLayoutTestResult item = result[i];
       
  1715         QCOMPARE(widgets[item.index]->geometry(), item.rect);
       
  1716     }
       
  1717 
       
  1718     // ###: not supported yet
       
  1719 /*
       
  1720     // Test mirrored mode
       
  1721     widget->setLayoutDirection(Qt::RightToLeft);
       
  1722     layout->activate();
       
  1723     // Validate
       
  1724     for (int j = 0; j < result.count(); ++j) {
       
  1725         const BasicLayoutTestResult item = result[j];
       
  1726         QRectF mirroredRect(item.rect);
       
  1727         // only valid cases are mirrored
       
  1728         if (mirroredRect.isValid()){
       
  1729             mirroredRect.moveLeft(size.width()-item.rect.width()-item.rect.left());
       
  1730         }
       
  1731         QCOMPARE(widgets[item.index]->geometry(), mirroredRect);
       
  1732         delete widgets[item.index];
       
  1733     }
       
  1734 */
       
  1735     delete widget;
       
  1736 }
       
  1737 
       
  1738 void tst_QGraphicsAnchorLayout1::testNegativeSpacing()
       
  1739 {
       
  1740     // use the same frame
       
  1741     testBasicLayout();
       
  1742 }
       
  1743 
       
  1744 void tst_QGraphicsAnchorLayout1::testMixedSpacing()
       
  1745 {
       
  1746     // use the same frame
       
  1747     testBasicLayout();
       
  1748 }
       
  1749 
       
  1750 void tst_QGraphicsAnchorLayout1::testMulti()
       
  1751 {
       
  1752     // use the same frame
       
  1753     testBasicLayout();
       
  1754 }
       
  1755 
       
  1756 void tst_QGraphicsAnchorLayout1::testCenterAnchors_data()
       
  1757 {
       
  1758     QTest::addColumn<QSizeF>("size");
       
  1759     QTest::addColumn<BasicLayoutTestDataList>("data");
       
  1760     QTest::addColumn<BasicLayoutTestResultList>("result");
       
  1761 
       
  1762     typedef BasicLayoutTestData BasicData;
       
  1763     typedef BasicLayoutTestResult BasicResult;
       
  1764 
       
  1765     // Basic center case
       
  1766     {
       
  1767         BasicLayoutTestDataList theData;
       
  1768         BasicLayoutTestResultList theResult;
       
  1769 
       
  1770         theData
       
  1771             // << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorHorizontalCenter, -10)
       
  1772             << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorHorizontalCenter, 10)
       
  1773             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorRight, 15)
       
  1774             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorVerticalCenter, 10)
       
  1775             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 5);
       
  1776 
       
  1777         theResult
       
  1778             << BasicResult(0, QRectF(5, 5, 10, 10) );
       
  1779 
       
  1780         QTest::newRow("center, basic") << QSizeF(20, 20) << theData << theResult;
       
  1781     }
       
  1782 
       
  1783     // Basic center case, with invalid (shouldn't affect on result)
       
  1784     {
       
  1785         BasicLayoutTestDataList theData;
       
  1786         BasicLayoutTestResultList theResult;
       
  1787 
       
  1788         theData
       
  1789             // << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorHorizontalCenter, -10)
       
  1790             << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorHorizontalCenter, 10)
       
  1791             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorRight, 15)
       
  1792             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorVerticalCenter, 10)
       
  1793             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 5)
       
  1794 
       
  1795             // bogus definitions
       
  1796             << BasicData(0, Qt::AnchorHorizontalCenter, -1, Qt::AnchorBottom, 5)
       
  1797             << BasicData(0, Qt::AnchorHorizontalCenter, 1, Qt::AnchorVerticalCenter, 5)
       
  1798             << BasicData(0, Qt::AnchorVerticalCenter, -1, Qt::AnchorRight, 5)
       
  1799             << BasicData(0, Qt::AnchorVerticalCenter, 0, Qt::AnchorVerticalCenter, 666)
       
  1800             << BasicData(0, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, 999)
       
  1801             << BasicData(0, Qt::AnchorLeft, 0, Qt::AnchorLeft, 333)
       
  1802             << BasicData(-1, Qt::AnchorRight, -1, Qt::AnchorRight, 222)
       
  1803             << BasicData(0, Qt::AnchorTop, 0, Qt::AnchorTop, 111)
       
  1804             << BasicData(0, Qt::AnchorBottom, 0, Qt::AnchorBottom, 444);
       
  1805 
       
  1806         theResult
       
  1807             << BasicResult(0, QRectF(5, 5, 10, 10) );
       
  1808 
       
  1809         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor edges of different orientations");
       
  1810         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor edges of different orientations");
       
  1811         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor edges of different orientations");
       
  1812         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  1813         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  1814         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  1815         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  1816         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  1817         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  1818         QTest::newRow("center, basic with invalid") << QSizeF(20, 20) << theData << theResult;
       
  1819     }
       
  1820 
       
  1821     // Basic center case 2
       
  1822     {
       
  1823         BasicLayoutTestDataList theData;
       
  1824         BasicLayoutTestResultList theResult;
       
  1825 
       
  1826         theData
       
  1827             << BasicData(-1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, 0)
       
  1828             // Not supported << BasicData(0, Qt::AnchorHorizontalCenter, 0, Qt::AnchorRight, 5)
       
  1829             << BasicData(-1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorRight, 5)
       
  1830             << BasicData(-1, Qt::AnchorVerticalCenter, 0, Qt::AnchorVerticalCenter, 0)
       
  1831             << BasicData(-1, Qt::AnchorVerticalCenter, 0, Qt::AnchorTop, -5);
       
  1832 
       
  1833         theResult
       
  1834             << BasicResult(0, QRectF(5, 5, 10, 10) );
       
  1835 
       
  1836         QTest::newRow("center, basic 2") << QSizeF(20, 20) << theData << theResult;
       
  1837     }
       
  1838 
       
  1839     // Basic center case, overrides
       
  1840     {
       
  1841         BasicLayoutTestDataList theData;
       
  1842         BasicLayoutTestResultList theResult;
       
  1843 
       
  1844         theData
       
  1845             << BasicData(-1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, 10)
       
  1846             << BasicData(-1, Qt::AnchorVerticalCenter, 0, Qt::AnchorVerticalCenter, 20)
       
  1847             << BasicData(0, Qt::AnchorHorizontalCenter, -1, Qt::AnchorHorizontalCenter, 30)
       
  1848             << BasicData(0, Qt::AnchorVerticalCenter, -1, Qt::AnchorVerticalCenter, 40)
       
  1849             // actual data:
       
  1850             << BasicData(-1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, 0)
       
  1851             << BasicData(-1, Qt::AnchorVerticalCenter, 0, Qt::AnchorVerticalCenter, 0)
       
  1852             // << BasicData(0, Qt::AnchorHorizontalCenter, 0, Qt::AnchorRight, 5)
       
  1853             << BasicData(-1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorRight, 5)
       
  1854             << BasicData(-1, Qt::AnchorVerticalCenter, 0, Qt::AnchorTop, -5);
       
  1855 
       
  1856         theResult
       
  1857             << BasicResult(0, QRectF(5, 5, 10, 10) );
       
  1858 
       
  1859         QTest::newRow("center, overrides") << QSizeF(20, 20) << theData << theResult;
       
  1860     }
       
  1861 
       
  1862     // Two nested
       
  1863     {
       
  1864         BasicLayoutTestDataList theData;
       
  1865         BasicLayoutTestResultList theResult;
       
  1866 
       
  1867         theData
       
  1868             << BasicData(-1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorLeft, 0)
       
  1869             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 0)
       
  1870             << BasicData(-1, Qt::AnchorBottom, 0, Qt::AnchorBottom, 0)
       
  1871             << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorRight, 0)
       
  1872             << BasicData(0, Qt::AnchorVerticalCenter, 1, Qt::AnchorTop, 0)
       
  1873             << BasicData(0, Qt::AnchorLeft, 1, Qt::AnchorLeft, 0)
       
  1874             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorRight, 0)
       
  1875             << BasicData(0, Qt::AnchorBottom, 1, Qt::AnchorBottom, 0);
       
  1876 
       
  1877         theResult
       
  1878             << BasicResult(0, QRectF(20, 0, 20, 40))
       
  1879             << BasicResult(1, QRectF(20, 20, 20, 20));
       
  1880 
       
  1881         QTest::newRow("center, two nested") << QSizeF(40, 40) << theData << theResult;
       
  1882     }
       
  1883 
       
  1884     // Two overlap
       
  1885     {
       
  1886         BasicLayoutTestDataList theData;
       
  1887         BasicLayoutTestResultList theResult;
       
  1888 
       
  1889         // theData
       
  1890         //     // horizontal
       
  1891         //     << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 20)
       
  1892         //     << BasicData(0, Qt::AnchorHorizontalCenter, 1, Qt::AnchorLeft, 0)
       
  1893         //     << BasicData(1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorRight, -5)
       
  1894         //     << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  1895         //     << BasicData(0, Qt::AnchorHorizontalCenter, 0, Qt::AnchorRight, 10)
       
  1896         //     // vertical is pretty much same as horizontal, just roles swapped
       
  1897         //     << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 20)
       
  1898         //     << BasicData(1, Qt::AnchorVerticalCenter, 0, Qt::AnchorTop, 0)
       
  1899         //     << BasicData(0, Qt::AnchorVerticalCenter, 1, Qt::AnchorBottom, -5)
       
  1900         //     << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 10)
       
  1901         //     << BasicData(1, Qt::AnchorVerticalCenter, 1, Qt::AnchorBottom, 10);
       
  1902 
       
  1903         theData
       
  1904             // horizontal
       
  1905             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 20)
       
  1906             << BasicData(0, Qt::AnchorHorizontalCenter, 1, Qt::AnchorLeft, 0)
       
  1907             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorHorizontalCenter, 5)
       
  1908             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorRight, 20)
       
  1909             // vertical
       
  1910             << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 20)
       
  1911             << BasicData(1, Qt::AnchorVerticalCenter, 0, Qt::AnchorTop, 0)
       
  1912             << BasicData(1, Qt::AnchorBottom, 0, Qt::AnchorVerticalCenter, 5)
       
  1913             << BasicData(1, Qt::AnchorBottom, 0, Qt::AnchorBottom, 20);
       
  1914 
       
  1915         theResult
       
  1916             << BasicResult(0, QRectF(20, 30, 20, 30))
       
  1917             << BasicResult(1, QRectF(30, 20, 30, 20));
       
  1918 
       
  1919         QTest::newRow("center, two overlap") << QSizeF(70, 70) << theData << theResult;
       
  1920     }
       
  1921 
       
  1922     // Three
       
  1923     {
       
  1924         BasicLayoutTestDataList theData;
       
  1925         BasicLayoutTestResultList theResult;
       
  1926 
       
  1927         theData
       
  1928             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 0)
       
  1929             << BasicData(0, Qt::AnchorHorizontalCenter, 2, Qt::AnchorHorizontalCenter, 75)
       
  1930             << BasicData(1, Qt::AnchorRight, 2, Qt::AnchorLeft, 10)
       
  1931             << BasicData(1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, -30)
       
  1932             << BasicData(2, Qt::AnchorRight, -1, Qt::AnchorRight, 0)
       
  1933             << BasicData(1, Qt::AnchorLeft, 1, Qt::AnchorRight, 30)
       
  1934             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorLeft, 10)
       
  1935 
       
  1936             << BasicData(1, Qt::AnchorTop, -1, Qt::AnchorTop, 0)
       
  1937             << BasicData(1, Qt::AnchorVerticalCenter, 0, Qt::AnchorVerticalCenter, 35)
       
  1938             << BasicData(1, Qt::AnchorVerticalCenter, 2, Qt::AnchorVerticalCenter, 15)
       
  1939             << BasicData(1, Qt::AnchorBottom, 2, Qt::AnchorTop, 5)
       
  1940             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 0)
       
  1941             << BasicData(2, Qt::AnchorBottom, 0, Qt::AnchorTop, 5)
       
  1942             << BasicData(0, Qt::AnchorTop, 0, Qt::AnchorBottom, 20);
       
  1943 
       
  1944         theResult
       
  1945             << BasicResult(0, QRectF(0, 30, 10, 20))
       
  1946             << BasicResult(1, QRectF(20, 0, 30, 10))
       
  1947             << BasicResult(2, QRectF(60, 15, 40, 10));
       
  1948 
       
  1949         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  1950         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  1951 
       
  1952         QTest::newRow("center, three") << QSizeF(100, 50) << theData << theResult;
       
  1953     }
       
  1954 
       
  1955     // Two, parent center
       
  1956     {
       
  1957         BasicLayoutTestDataList theData;
       
  1958         BasicLayoutTestResultList theResult;
       
  1959 
       
  1960         theData
       
  1961             // vertical is pretty much same as horizontal, just roles swapped
       
  1962             << BasicData(-1, Qt::AnchorVerticalCenter, 1, Qt::AnchorVerticalCenter, -15)
       
  1963             << BasicData(-1, Qt::AnchorVerticalCenter, 0, Qt::AnchorVerticalCenter, 10)
       
  1964             << BasicData(-1, Qt::AnchorBottom, 0, Qt::AnchorBottom, 0)
       
  1965             << BasicData(1, Qt::AnchorTop, 0, Qt::AnchorTop, 0)
       
  1966             // horizontal
       
  1967             << BasicData(-1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, -15)
       
  1968             << BasicData(-1, Qt::AnchorHorizontalCenter, 1, Qt::AnchorHorizontalCenter, 10)
       
  1969             << BasicData(-1, Qt::AnchorRight, 1, Qt::AnchorRight, 0)
       
  1970             << BasicData(0, Qt::AnchorLeft, 1, Qt::AnchorLeft, 0);
       
  1971 
       
  1972         theResult
       
  1973             << BasicResult(0, QRectF(20, 20, 30, 80))
       
  1974             << BasicResult(1, QRectF(20, 20, 80, 30));
       
  1975 
       
  1976         QTest::newRow("center, parent") << QSizeF(100, 100) << theData << theResult;
       
  1977     }
       
  1978 
       
  1979     // Two, parent center 2
       
  1980     {
       
  1981         BasicLayoutTestDataList theData;
       
  1982         BasicLayoutTestResultList theResult;
       
  1983 
       
  1984         theData
       
  1985             // << BasicData(1, Qt::AnchorLeft, -1, Qt::AnchorHorizontalCenter, 15)
       
  1986             << BasicData(1, Qt::AnchorLeft, -1, Qt::AnchorHorizontalCenter, -15)
       
  1987             << BasicData(1, Qt::AnchorRight, 0, Qt::AnchorLeft, 10)
       
  1988             << BasicData(0, Qt::AnchorRight, -1, Qt::AnchorRight, 5)
       
  1989             << BasicData(-1, Qt::AnchorHorizontalCenter, 1, Qt::AnchorRight, -5)
       
  1990             // vertical
       
  1991             << BasicData(0, Qt::AnchorVerticalCenter, 1, Qt::AnchorVerticalCenter, 20)
       
  1992             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 10)
       
  1993             << BasicData(0, Qt::AnchorBottom, 1, Qt::AnchorBottom, 20)
       
  1994             << BasicData(0, Qt::AnchorTop, 1, Qt::AnchorTop, 20)
       
  1995             << BasicData(0, Qt::AnchorBottom, 1, Qt::AnchorTop, 10);
       
  1996 
       
  1997         theResult
       
  1998             << BasicResult(0, QRectF(30, 10, 15, 10))
       
  1999             << BasicResult(1, QRectF(10, 30, 10, 10));
       
  2000 
       
  2001         QTest::newRow("center, parent 2") << QSizeF(50, 50) << theData << theResult;
       
  2002     }
       
  2003 
       
  2004     // Two, parent center 3
       
  2005     {
       
  2006         BasicLayoutTestDataList theData;
       
  2007         BasicLayoutTestResultList theResult;
       
  2008 
       
  2009         theData
       
  2010             << BasicData(-1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorRight, -5)
       
  2011             << BasicData(-1, Qt::AnchorHorizontalCenter, 1, Qt::AnchorLeft, 5)
       
  2012             // << BasicData(0, Qt::AnchorLeft, 1, Qt::AnchorRight, 100)
       
  2013             << BasicData(0, Qt::AnchorLeft, 1, Qt::AnchorRight, -100)
       
  2014             << BasicData(0, Qt::AnchorLeft, -1, Qt::AnchorLeft, 0)
       
  2015 
       
  2016             // vertical
       
  2017             << BasicData(0, Qt::AnchorVerticalCenter, 1, Qt::AnchorVerticalCenter, 55)
       
  2018             << BasicData(0, Qt::AnchorTop, -1, Qt::AnchorTop, 0)
       
  2019             << BasicData(1, Qt::AnchorBottom, -1, Qt::AnchorBottom, 0)
       
  2020             << BasicData(0, Qt::AnchorBottom, 1, Qt::AnchorTop, 10)
       
  2021             // << BasicData(0, Qt::AnchorTop, 0, Qt::AnchorBottom, 45)
       
  2022             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorBottom, 45)
       
  2023             ;
       
  2024 
       
  2025         theResult
       
  2026             << BasicResult(0, QRectF(0, 0, 45, 45))
       
  2027             << BasicResult(1, QRectF(55, 55, 45, 45));
       
  2028 
       
  2029         QTest::newRow("center, parent 3") << QSizeF(100, 100) << theData << theResult;
       
  2030     }
       
  2031 
       
  2032 }
       
  2033 
       
  2034 void tst_QGraphicsAnchorLayout1::testCenterAnchors()
       
  2035 {
       
  2036     // use the same frame
       
  2037     testBasicLayout();
       
  2038 }
       
  2039 
       
  2040 void tst_QGraphicsAnchorLayout1::testRemoveCenterAnchor_data()
       
  2041 {
       
  2042     QTest::addColumn<QSizeF>("size");
       
  2043     QTest::addColumn<BasicLayoutTestDataList>("data");
       
  2044     QTest::addColumn<BasicLayoutTestDataList>("removeData");
       
  2045     QTest::addColumn<BasicLayoutTestResultList>("result");
       
  2046 
       
  2047     typedef BasicLayoutTestData BasicData;
       
  2048     typedef BasicLayoutTestResult BasicResult;
       
  2049 
       
  2050     {
       
  2051         BasicLayoutTestDataList theData;
       
  2052         BasicLayoutTestDataList theRemoveData;
       
  2053         BasicLayoutTestResultList theResult;
       
  2054 
       
  2055         theData
       
  2056             // << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorHorizontalCenter, -10)
       
  2057             << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorHorizontalCenter, 10)
       
  2058             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorRight, 15)
       
  2059             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorVerticalCenter, 10)
       
  2060             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 5)
       
  2061 
       
  2062             << BasicData(-1, Qt::AnchorHorizontalCenter, 1, Qt::AnchorHorizontalCenter, 66)
       
  2063             << BasicData(1, Qt::AnchorVerticalCenter, -1, Qt::AnchorVerticalCenter, 99)
       
  2064             << BasicData(0, Qt::AnchorHorizontalCenter, 1, Qt::AnchorHorizontalCenter, 33)
       
  2065             ;
       
  2066 
       
  2067         theRemoveData
       
  2068             << BasicData(-1, Qt::AnchorHorizontalCenter, 1, Qt::AnchorHorizontalCenter, 0)
       
  2069             << BasicData(1, Qt::AnchorVerticalCenter, -1, Qt::AnchorVerticalCenter, 0)
       
  2070             << BasicData(0, Qt::AnchorHorizontalCenter, 1, Qt::AnchorHorizontalCenter, 0);
       
  2071 
       
  2072         theResult
       
  2073             << BasicResult(0, QRectF(5, 5, 10, 10) );
       
  2074 
       
  2075         QTest::newRow("remove, center, basic") << QSizeF(20, 20) << theData
       
  2076             << theRemoveData << theResult;
       
  2077     }
       
  2078 
       
  2079     {
       
  2080         BasicLayoutTestDataList theData;
       
  2081         BasicLayoutTestDataList theRemoveData;
       
  2082         BasicLayoutTestResultList theResult;
       
  2083 
       
  2084         theData
       
  2085             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 0)
       
  2086             << BasicData(0, Qt::AnchorHorizontalCenter, 2, Qt::AnchorHorizontalCenter, 75)
       
  2087             << BasicData(1, Qt::AnchorRight, 2, Qt::AnchorLeft, 10)
       
  2088             << BasicData(1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, -30)
       
  2089             << BasicData(2, Qt::AnchorRight, -1, Qt::AnchorRight, 0)
       
  2090             << BasicData(1, Qt::AnchorLeft, 1, Qt::AnchorRight, 30)
       
  2091             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorLeft, 10)
       
  2092 
       
  2093             // extra:
       
  2094             << BasicData(-1, Qt::AnchorVerticalCenter, 0, Qt::AnchorVerticalCenter, 66)
       
  2095             << BasicData(-1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, 33)
       
  2096             << BasicData(0, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, 55)
       
  2097             << BasicData(1, Qt::AnchorVerticalCenter, 1, Qt::AnchorVerticalCenter, 55)
       
  2098 
       
  2099             << BasicData(1, Qt::AnchorTop, -1, Qt::AnchorTop, 0)
       
  2100             << BasicData(1, Qt::AnchorVerticalCenter, 0, Qt::AnchorVerticalCenter, 35)
       
  2101             << BasicData(1, Qt::AnchorVerticalCenter, 2, Qt::AnchorVerticalCenter, 15)
       
  2102             << BasicData(1, Qt::AnchorBottom, 2, Qt::AnchorTop, 5)
       
  2103             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 0)
       
  2104             << BasicData(2, Qt::AnchorBottom, 0, Qt::AnchorTop, 5)
       
  2105             << BasicData(0, Qt::AnchorTop, 0, Qt::AnchorBottom, 20);
       
  2106 
       
  2107         theRemoveData
       
  2108             << BasicData(-1, Qt::AnchorVerticalCenter, 0, Qt::AnchorVerticalCenter, 66)
       
  2109             << BasicData(-1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, 33)
       
  2110             << BasicData(0, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, 55)
       
  2111             << BasicData(1, Qt::AnchorVerticalCenter, 1, Qt::AnchorVerticalCenter, 55);
       
  2112 
       
  2113         theResult
       
  2114             << BasicResult(0, QRectF(0, 30, 10, 20))
       
  2115             << BasicResult(1, QRectF(20, 0, 30, 10))
       
  2116             << BasicResult(2, QRectF(60, 15, 40, 10));
       
  2117 
       
  2118         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  2119         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  2120         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  2121         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  2122 
       
  2123         QTest::newRow("remove, center, three") << QSizeF(100, 50) << theData << theRemoveData << theResult;
       
  2124     }
       
  2125 
       
  2126     // add edge (item0,edge0,item1,edge1), remove (item1,edge1,item0,edge0)
       
  2127     {
       
  2128         BasicLayoutTestDataList theData;
       
  2129         BasicLayoutTestDataList theRemoveData;
       
  2130         BasicLayoutTestResultList theResult;
       
  2131 
       
  2132         theData
       
  2133             // << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorHorizontalCenter, -10)
       
  2134             << BasicData(-1, Qt::AnchorRight, 0, Qt::AnchorHorizontalCenter, 10)
       
  2135             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorRight, 15)
       
  2136             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorVerticalCenter, 10)
       
  2137             << BasicData(0, Qt::AnchorBottom, -1, Qt::AnchorBottom, 5)
       
  2138 
       
  2139             << BasicData(-1, Qt::AnchorHorizontalCenter, 1, Qt::AnchorHorizontalCenter, 66)
       
  2140             << BasicData(1, Qt::AnchorVerticalCenter, -1, Qt::AnchorVerticalCenter, 99)
       
  2141             << BasicData(0, Qt::AnchorHorizontalCenter, 1, Qt::AnchorHorizontalCenter, 33)
       
  2142             << BasicData(0, Qt::AnchorLeft, 0, Qt::AnchorRight, 22)
       
  2143             << BasicData(0, Qt::AnchorTop, 0, Qt::AnchorBottom, 11)
       
  2144             ;
       
  2145 
       
  2146         theRemoveData
       
  2147             << BasicData(1, Qt::AnchorHorizontalCenter, -1, Qt::AnchorHorizontalCenter, 0)
       
  2148             << BasicData(-1, Qt::AnchorVerticalCenter, 1, Qt::AnchorVerticalCenter, 0)
       
  2149             << BasicData(1, Qt::AnchorHorizontalCenter, 0, Qt::AnchorHorizontalCenter, 0)
       
  2150             << BasicData(0, Qt::AnchorRight, 0, Qt::AnchorLeft, 0)
       
  2151             << BasicData(0, Qt::AnchorBottom, 0, Qt::AnchorTop, 0)
       
  2152             ;
       
  2153 
       
  2154         theResult
       
  2155             << BasicResult(0, QRectF(5, 5, 10, 10) );
       
  2156 
       
  2157         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  2158         QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself");
       
  2159         QTest::newRow("remove, center, basic 2") << QSizeF(20, 20) << theData
       
  2160             << theRemoveData << theResult;
       
  2161     }
       
  2162 
       
  2163 }
       
  2164 
       
  2165 void tst_QGraphicsAnchorLayout1::testRemoveCenterAnchor()
       
  2166 {
       
  2167     QFETCH(QSizeF, size);
       
  2168     QFETCH(BasicLayoutTestDataList, data);
       
  2169     QFETCH(BasicLayoutTestDataList, removeData);
       
  2170     QFETCH(BasicLayoutTestResultList, result);
       
  2171 
       
  2172     QGraphicsWidget *widget = new QGraphicsWidget;
       
  2173 
       
  2174     // Determine amount of widgets to add.
       
  2175     int widgetCount = -1;
       
  2176     for (int i = 0; i < data.count(); ++i) {
       
  2177         const BasicLayoutTestData item = data[i];
       
  2178         widgetCount = qMax(widgetCount, item.firstIndex);
       
  2179         widgetCount = qMax(widgetCount, item.secondIndex);
       
  2180     }
       
  2181     ++widgetCount; // widgetCount is max of indices.
       
  2182 
       
  2183     // Create dummy widgets
       
  2184     QList<QGraphicsWidget *> widgets;
       
  2185     for (int i = 0; i < widgetCount; ++i) {
       
  2186         TestWidget *w = new TestWidget;
       
  2187         widgets << w;
       
  2188     }
       
  2189 
       
  2190     // Setup anchor layout
       
  2191     TheAnchorLayout *layout = new TheAnchorLayout;
       
  2192 
       
  2193     for (int i = 0; i < data.count(); ++i) {
       
  2194         const BasicLayoutTestData item = data[i];
       
  2195         layout->setAnchor(
       
  2196             getItem(item.firstIndex, widgets, layout),
       
  2197             item.firstEdge,
       
  2198             getItem(item.secondIndex, widgets, layout),
       
  2199             item.secondEdge,
       
  2200             item.spacing );
       
  2201     }
       
  2202 
       
  2203     for (int i = 0; i < removeData.count(); ++i) {
       
  2204         const BasicLayoutTestData item = removeData[i];
       
  2205         layout->removeAnchor(
       
  2206             getItem(item.firstIndex, widgets, layout),
       
  2207             item.firstEdge,
       
  2208             getItem(item.secondIndex, widgets, layout),
       
  2209             item.secondEdge);
       
  2210     }
       
  2211 
       
  2212     widget->setLayout(layout);
       
  2213     widget->setContentsMargins(0,0,0,0);
       
  2214 
       
  2215     widget->setMinimumSize(size);
       
  2216     widget->setMaximumSize(size);
       
  2217 
       
  2218     // Validate
       
  2219     for (int i = 0; i < result.count(); ++i) {
       
  2220         const BasicLayoutTestResult item = result[i];
       
  2221 
       
  2222         QCOMPARE(widgets[item.index]->geometry(), item.rect);
       
  2223         delete widgets[item.index];
       
  2224     }
       
  2225     delete widget;
       
  2226 }
       
  2227 
       
  2228 void tst_QGraphicsAnchorLayout1::testSingleSizePolicy_data()
       
  2229 {
       
  2230     QTest::addColumn<QSizeF>("size");
       
  2231     QTest::addColumn<QSizePolicy>("policy");
       
  2232     QTest::addColumn<bool>("valid");
       
  2233 
       
  2234 // FIXED
       
  2235     {
       
  2236         QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2237         QTest::newRow("single size policy: fixed ok") << QSizeF(70, 70) << sizePolicy << true;
       
  2238     }
       
  2239 /*
       
  2240     {
       
  2241         QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2242         QTest::newRow("single size policy: fixed too big") << QSizeF(100, 100) << sizePolicy << false;
       
  2243     }
       
  2244 
       
  2245     {
       
  2246         QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2247         QTest::newRow("single size policy: fixed too small") << QSizeF(50, 50) << sizePolicy << false;
       
  2248     }
       
  2249 */
       
  2250 // MINIMUM
       
  2251     {
       
  2252         QSizePolicy sizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
       
  2253         QTest::newRow("single size policy: minimum bigger ok") << QSizeF(100, 100) << sizePolicy << true;
       
  2254     }
       
  2255 
       
  2256     {
       
  2257         QSizePolicy sizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
       
  2258         QTest::newRow("single size policy: minimum limit ok") << QSizeF(70, 70) << sizePolicy << true;
       
  2259     }
       
  2260 /*
       
  2261     {
       
  2262         QSizePolicy sizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
       
  2263         QTest::newRow("single size policy: minimum too small") << QSizeF(50, 50) << sizePolicy << false;
       
  2264     }
       
  2265 */
       
  2266 // MAXIMUM
       
  2267     {
       
  2268         QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
       
  2269         QTest::newRow("single size policy: maximum small ok") << QSizeF(50, 50) << sizePolicy << true;
       
  2270     }
       
  2271 
       
  2272     {
       
  2273         QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
       
  2274         QTest::newRow("single size policy: maximum limit ok") << QSizeF(70, 70) << sizePolicy << true;
       
  2275     }
       
  2276 /*
       
  2277     {
       
  2278         QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
       
  2279         QTest::newRow("single size policy: maximum bigger fail") << QSizeF(100, 100) << sizePolicy << false;
       
  2280     }
       
  2281 */
       
  2282 // PREFERRED
       
  2283     {
       
  2284         QSizePolicy sizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2285         QTest::newRow("single size policy: preferred bigger ok") << QSizeF(100, 100) << sizePolicy << true;
       
  2286     }
       
  2287 
       
  2288     {
       
  2289         QSizePolicy sizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2290         QTest::newRow("single size policy: preferred smaller ok") << QSizeF(50, 50)  << sizePolicy << true;
       
  2291     }
       
  2292 /*
       
  2293     {
       
  2294         QSizePolicy sizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2295         QTest::newRow("single size policy: preferred too big") << QSizeF(700, 700) << sizePolicy << false;
       
  2296     }
       
  2297 
       
  2298     {
       
  2299         QSizePolicy sizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2300         QTest::newRow("single size policy: preferred too small") << QSizeF(21, 21) << sizePolicy << false;
       
  2301     }
       
  2302 */
       
  2303 // MINIMUMEXPANDING
       
  2304 
       
  2305     {
       
  2306         QSizePolicy sizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
       
  2307         QTest::newRow("single size policy: min.expanding bigger ok") << QSizeF(100, 100) << sizePolicy << true;
       
  2308     }
       
  2309 
       
  2310     {
       
  2311         QSizePolicy sizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
       
  2312         QTest::newRow("single size policy: min.expanding limit ok") << QSizeF(70, 70) << sizePolicy << true;
       
  2313     }
       
  2314 
       
  2315     /*{
       
  2316         QSizePolicy sizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
       
  2317         QTest::newRow("single size policy: min.expanding too small") << QSizeF(50, 50) << sizePolicy << false;
       
  2318     }*/
       
  2319 
       
  2320 // EXPANDING
       
  2321 
       
  2322     {
       
  2323         QSizePolicy sizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
       
  2324         QTest::newRow("single size policy: expanding bigger ok") << QSizeF(100, 100) << sizePolicy << true;
       
  2325     }
       
  2326 
       
  2327     {
       
  2328         QSizePolicy sizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
       
  2329         QTest::newRow("single size policy: expanding smaller ok") << QSizeF(50, 50)  << sizePolicy << true;
       
  2330     }
       
  2331 
       
  2332  // IGNORED
       
  2333 
       
  2334     {
       
  2335         QSizePolicy sizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
       
  2336         QTest::newRow("single size policy: ignored bigger ok") << QSizeF(100, 100) << sizePolicy << true;
       
  2337     }
       
  2338 
       
  2339     {
       
  2340         QSizePolicy sizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
       
  2341         QTest::newRow("single size policy: ignored smaller ok") << QSizeF(50, 50)  << sizePolicy << true;
       
  2342     }
       
  2343 }
       
  2344 
       
  2345 void tst_QGraphicsAnchorLayout1::testSingleSizePolicy()
       
  2346 {
       
  2347     QFETCH(QSizeF, size);
       
  2348     QFETCH(QSizePolicy, policy);
       
  2349     QFETCH(bool, valid);
       
  2350 
       
  2351     // create objects
       
  2352     QGraphicsWidget *widget = new QGraphicsWidget;
       
  2353     TheAnchorLayout *layout = new TheAnchorLayout;
       
  2354     TestWidget *childWidget = new TestWidget;
       
  2355 
       
  2356     // set anchors
       
  2357     layout->setAnchor( layout, Qt::AnchorLeft, childWidget, Qt::AnchorLeft, 10 );
       
  2358     layout->setAnchor( childWidget, Qt::AnchorRight, layout, Qt::AnchorRight, 10 );
       
  2359     layout->setAnchor( layout, Qt::AnchorTop, childWidget, Qt::AnchorTop, 10 );
       
  2360     layout->setAnchor( childWidget, Qt::AnchorBottom, layout, Qt::AnchorBottom, 10 );
       
  2361 
       
  2362     widget->setLayout( layout );
       
  2363 
       
  2364     // set test case specific: policy and size
       
  2365     childWidget->setSizePolicy( policy );
       
  2366     widget->setGeometry( QRectF( QPoint(0,0), size ) );
       
  2367 
       
  2368     QCOMPARE( layout->isValid() , valid );
       
  2369 
       
  2370     const QRectF childRect = childWidget->geometry();
       
  2371     Q_UNUSED( childRect );
       
  2372 }
       
  2373 
       
  2374 void tst_QGraphicsAnchorLayout1::testDoubleSizePolicy_data()
       
  2375 {
       
  2376     // tests only horizontal direction
       
  2377     QTest::addColumn<QSizePolicy>("policy1");
       
  2378     QTest::addColumn<QSizePolicy>("policy2");
       
  2379     QTest::addColumn<qreal>("width1");
       
  2380     QTest::addColumn<qreal>("width2");
       
  2381 
       
  2382     // layout size always 100x100 and size hints for items are 5<50<500
       
  2383     // gabs: 10-item1-10-item2-10
       
  2384 
       
  2385     {
       
  2386         QSizePolicy sizePolicy1( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2387         QSizePolicy sizePolicy2( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2388         const qreal width1 = 50;
       
  2389         const qreal width2 = 100-10-10-10-width1;
       
  2390         QTest::newRow("double size policy: fixed-preferred") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2391     }
       
  2392 
       
  2393     {
       
  2394         QSizePolicy sizePolicy1( QSizePolicy::Minimum, QSizePolicy::Minimum );
       
  2395         QSizePolicy sizePolicy2( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2396         const qreal width1 = 50;
       
  2397         const qreal width2 = 100-10-10-10-width1;
       
  2398         QTest::newRow("double size policy: minimum-preferred") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2399     }
       
  2400 
       
  2401     {
       
  2402         QSizePolicy sizePolicy1( QSizePolicy::Maximum, QSizePolicy::Maximum );
       
  2403         QSizePolicy sizePolicy2( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2404         const qreal width1 = 35;
       
  2405         const qreal width2 = 100-10-10-10-width1;
       
  2406         QTest::newRow("double size policy: maximum-preferred") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2407     }
       
  2408 
       
  2409     {
       
  2410         QSizePolicy sizePolicy1( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2411         QSizePolicy sizePolicy2( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2412         const qreal width1 = 35;
       
  2413         const qreal width2 = 100-10-10-10-width1;
       
  2414         QTest::newRow("double size policy: preferred-preferred") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2415     }
       
  2416 
       
  2417     {
       
  2418         QSizePolicy sizePolicy1( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
       
  2419         QSizePolicy sizePolicy2( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2420         const qreal width1 = 50;
       
  2421         const qreal width2 = 100-10-10-10-width1;
       
  2422         QTest::newRow("double size policy: min.expanding-preferred") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2423     }
       
  2424 
       
  2425     {
       
  2426         QSizePolicy sizePolicy1( QSizePolicy::Expanding, QSizePolicy::Expanding );
       
  2427         QSizePolicy sizePolicy2( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2428         const qreal width1 = 35;
       
  2429         const qreal width2 = 100-10-10-10-width1;
       
  2430         QTest::newRow("double size policy: expanding-preferred") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2431     }
       
  2432 
       
  2433     {
       
  2434         QSizePolicy sizePolicy1( QSizePolicy::Ignored, QSizePolicy::Ignored );
       
  2435         QSizePolicy sizePolicy2( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2436         const qreal width1 = 35;
       
  2437         const qreal width2 = 100-10-10-10-width1;
       
  2438         QTest::newRow("double size policy: ignored-preferred") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2439     }
       
  2440 
       
  2441     /*{
       
  2442         QSizePolicy sizePolicy1( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2443         QSizePolicy sizePolicy2( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2444         const qreal width1 = -1;
       
  2445         const qreal width2 = 100-10-10-10-width1;
       
  2446         QTest::newRow("double size policy: fixed-fixed invalid") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2447     }*/
       
  2448 
       
  2449     /*{
       
  2450         QSizePolicy sizePolicy1( QSizePolicy::Minimum, QSizePolicy::Minimum );
       
  2451         QSizePolicy sizePolicy2( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2452         const qreal width1 = -1;
       
  2453         const qreal width2 = 100-10-10-10-width1;
       
  2454         QTest::newRow("double size policy: minimum-fixed invalid") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2455     }*/
       
  2456 
       
  2457     {
       
  2458         QSizePolicy sizePolicy1( QSizePolicy::Maximum, QSizePolicy::Maximum );
       
  2459         QSizePolicy sizePolicy2( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2460         const qreal width1 = 20;
       
  2461         const qreal width2 = 100-10-10-10-width1;
       
  2462         QTest::newRow("double size policy: maximum-fixed") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2463     }
       
  2464 
       
  2465     {
       
  2466         QSizePolicy sizePolicy1( QSizePolicy::Preferred, QSizePolicy::Preferred );
       
  2467         QSizePolicy sizePolicy2( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2468         const qreal width1 = 20;
       
  2469         const qreal width2 = 100-10-10-10-width1;
       
  2470         QTest::newRow("double size policy: preferred-fixed") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2471     }
       
  2472 
       
  2473     /*{
       
  2474         QSizePolicy sizePolicy1( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
       
  2475         QSizePolicy sizePolicy2( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2476         const qreal width1 = -1;
       
  2477         const qreal width2 = 100-10-10-10-width1;
       
  2478         QTest::newRow("double size policy: min.expanding-fixed invalid") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2479     }*/
       
  2480 
       
  2481     {
       
  2482         QSizePolicy sizePolicy1( QSizePolicy::Expanding, QSizePolicy::Expanding );
       
  2483         QSizePolicy sizePolicy2( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2484         const qreal width1 = 20;
       
  2485         const qreal width2 = 100-10-10-10-width1;
       
  2486         QTest::newRow("double size policy: expanding-fixed") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2487     }
       
  2488 
       
  2489     {
       
  2490         QSizePolicy sizePolicy1( QSizePolicy::Ignored, QSizePolicy::Ignored );
       
  2491         QSizePolicy sizePolicy2( QSizePolicy::Fixed, QSizePolicy::Fixed );
       
  2492         const qreal width1 = 20;
       
  2493         const qreal width2 = 100-10-10-10-width1;
       
  2494         QTest::newRow("double size policy: ignored-fixed") << sizePolicy1 << sizePolicy2 << width1 << width2;
       
  2495     }
       
  2496 }
       
  2497 
       
  2498 void tst_QGraphicsAnchorLayout1::testDoubleSizePolicy()
       
  2499 {
       
  2500     // ### Size policy is not yet supported
       
  2501     return;
       
  2502 
       
  2503     QFETCH(QSizePolicy, policy1);
       
  2504     QFETCH(QSizePolicy, policy2);
       
  2505     QFETCH(qreal, width1);
       
  2506     QFETCH(qreal, width2);
       
  2507 
       
  2508     // create objects
       
  2509     QGraphicsWidget *widget = new QGraphicsWidget;
       
  2510     TheAnchorLayout *layout = new TheAnchorLayout;
       
  2511     TestWidget *childWidget1 = new TestWidget;
       
  2512     TestWidget *childWidget2 = new TestWidget;
       
  2513 
       
  2514     // set anchors
       
  2515     layout->setAnchor( layout, Qt::AnchorLeft, childWidget1, Qt::AnchorLeft, 10 );
       
  2516     layout->setAnchor( childWidget1, Qt::AnchorRight, childWidget2, Qt::AnchorLeft, 10 );
       
  2517     layout->setAnchor( childWidget2, Qt::AnchorRight, layout, Qt::AnchorRight, 10 );
       
  2518 
       
  2519     widget->setLayout( layout );
       
  2520 
       
  2521     // set test case specific: policy
       
  2522     childWidget1->setSizePolicy( policy1 );
       
  2523     childWidget2->setSizePolicy( policy2 );
       
  2524 
       
  2525     widget->setGeometry( QRectF( QPoint(0,0), QSize( 100,100 ) ) );
       
  2526 
       
  2527     // check results:
       
  2528     if ( width1 == -1.0f ) {
       
  2529         // invalid
       
  2530         QCOMPARE( layout->isValid() , false );
       
  2531     } else {
       
  2532         // valid
       
  2533         QCOMPARE( childWidget1->geometry().width(), width1 );
       
  2534         QCOMPARE( childWidget2->geometry().width(), width2 );
       
  2535     }
       
  2536 }
       
  2537 
       
  2538 typedef QMap<int,qreal> SizeHintArray;
       
  2539 Q_DECLARE_METATYPE(SizeHintArray)
       
  2540 
       
  2541 void tst_QGraphicsAnchorLayout1::testSizeDistribution_data()
       
  2542 {
       
  2543     // tests only horizontal direction
       
  2544     QTest::addColumn<SizeHintArray>("sizeHints1");
       
  2545     QTest::addColumn<SizeHintArray>("sizeHints2");
       
  2546     QTest::addColumn<qreal>("width1");
       
  2547     QTest::addColumn<qreal>("width2");
       
  2548 
       
  2549     // layout size always 100x100 and size policy for items is preferred-preferred
       
  2550     // gabs: 10-item1-10-item2-10
       
  2551 
       
  2552     {
       
  2553         SizeHintArray sizeHints1;
       
  2554         sizeHints1.insert( Qt::MinimumSize, 30 );
       
  2555         sizeHints1.insert( Qt::PreferredSize, 35 );
       
  2556         sizeHints1.insert( Qt::MaximumSize, 40 );
       
  2557         Q_ASSERT( sizeHints1.value( Qt::MinimumSize ) <= sizeHints1.value( Qt::PreferredSize ) );
       
  2558         Q_ASSERT( sizeHints1.value( Qt::PreferredSize ) <= sizeHints1.value( Qt::MaximumSize ) );
       
  2559 
       
  2560         SizeHintArray sizeHints2;
       
  2561         sizeHints2.insert( Qt::MinimumSize, 5 );
       
  2562         sizeHints2.insert( Qt::PreferredSize, 35 );
       
  2563         sizeHints2.insert( Qt::MaximumSize, 300 );
       
  2564         Q_ASSERT( sizeHints2.value( Qt::MinimumSize ) <= sizeHints2.value( Qt::PreferredSize ) );
       
  2565         Q_ASSERT( sizeHints2.value( Qt::PreferredSize ) <= sizeHints2.value( Qt::MaximumSize ) );
       
  2566 
       
  2567         const qreal width1 = 35;
       
  2568         const qreal width2 = 100-10-10-10-width1;
       
  2569         QTest::newRow("size distribution: preferred equal") << sizeHints1 << sizeHints2 << width1 << width2;
       
  2570     }
       
  2571 
       
  2572     {
       
  2573         SizeHintArray sizeHints1;
       
  2574         sizeHints1.insert( Qt::MinimumSize, 0 );
       
  2575         sizeHints1.insert( Qt::PreferredSize, 20 );
       
  2576         sizeHints1.insert( Qt::MaximumSize, 100 );
       
  2577         Q_ASSERT( sizeHints1.value( Qt::MinimumSize ) <= sizeHints1.value( Qt::PreferredSize ) );
       
  2578         Q_ASSERT( sizeHints1.value( Qt::PreferredSize ) <= sizeHints1.value( Qt::MaximumSize ) );
       
  2579 
       
  2580         SizeHintArray sizeHints2;
       
  2581         sizeHints2.insert( Qt::MinimumSize, 0 );
       
  2582         sizeHints2.insert( Qt::PreferredSize, 50 );
       
  2583         sizeHints2.insert( Qt::MaximumSize, 100 );
       
  2584         Q_ASSERT( sizeHints2.value( Qt::MinimumSize ) <= sizeHints2.value( Qt::PreferredSize ) );
       
  2585         Q_ASSERT( sizeHints2.value( Qt::PreferredSize ) <= sizeHints2.value( Qt::MaximumSize ) );
       
  2586 
       
  2587         const qreal width1 = 20;
       
  2588         const qreal width2 = 100-10-10-10-width1;
       
  2589         QTest::newRow("size distribution: preferred non-equal") << sizeHints1 << sizeHints2 << width1 << width2;
       
  2590     }
       
  2591 
       
  2592     {
       
  2593         SizeHintArray sizeHints1;
       
  2594         sizeHints1.insert( Qt::MinimumSize, 0 );
       
  2595         sizeHints1.insert( Qt::PreferredSize, 40 );
       
  2596         sizeHints1.insert( Qt::MaximumSize, 100 );
       
  2597         Q_ASSERT( sizeHints1.value( Qt::MinimumSize ) <= sizeHints1.value( Qt::PreferredSize ) );
       
  2598         Q_ASSERT( sizeHints1.value( Qt::PreferredSize ) <= sizeHints1.value( Qt::MaximumSize ) );
       
  2599 
       
  2600         SizeHintArray sizeHints2;
       
  2601         sizeHints2.insert( Qt::MinimumSize, 0 );
       
  2602         sizeHints2.insert( Qt::PreferredSize, 60 );
       
  2603         sizeHints2.insert( Qt::MaximumSize, 100 );
       
  2604         Q_ASSERT( sizeHints2.value( Qt::MinimumSize ) <= sizeHints2.value( Qt::PreferredSize ) );
       
  2605         Q_ASSERT( sizeHints2.value( Qt::PreferredSize ) <= sizeHints2.value( Qt::MaximumSize ) );
       
  2606 
       
  2607         const qreal width1 = 28; // got from manual calculation
       
  2608         const qreal width2 = 100-10-10-10-width1;
       
  2609         QTest::newRow("size distribution: below preferred") << sizeHints1 << sizeHints2 << width1 << width2;
       
  2610     }
       
  2611 
       
  2612     {
       
  2613         SizeHintArray sizeHints1;
       
  2614         sizeHints1.insert( Qt::MinimumSize, 0 );
       
  2615         sizeHints1.insert( Qt::PreferredSize, 10 );
       
  2616         sizeHints1.insert( Qt::MaximumSize, 100 );
       
  2617         Q_ASSERT( sizeHints1.value( Qt::MinimumSize ) <= sizeHints1.value( Qt::PreferredSize ) );
       
  2618         Q_ASSERT( sizeHints1.value( Qt::PreferredSize ) <= sizeHints1.value( Qt::MaximumSize ) );
       
  2619 
       
  2620         SizeHintArray sizeHints2;
       
  2621         sizeHints2.insert( Qt::MinimumSize, 0 );
       
  2622         sizeHints2.insert( Qt::PreferredSize, 40 );
       
  2623         sizeHints2.insert( Qt::MaximumSize, 100 );
       
  2624         Q_ASSERT( sizeHints2.value( Qt::MinimumSize ) <= sizeHints2.value( Qt::PreferredSize ) );
       
  2625         Q_ASSERT( sizeHints2.value( Qt::PreferredSize ) <= sizeHints2.value( Qt::MaximumSize ) );
       
  2626 
       
  2627         const qreal width1 = 22; // got from manual calculation
       
  2628         const qreal width2 = 100-10-10-10-width1;
       
  2629         QTest::newRow("size distribution: above preferred") << sizeHints1 << sizeHints2 << width1 << width2;
       
  2630     }
       
  2631 
       
  2632 }
       
  2633 
       
  2634 void tst_QGraphicsAnchorLayout1::testSizeDistribution()
       
  2635 {
       
  2636     QFETCH(SizeHintArray, sizeHints1);
       
  2637     QFETCH(SizeHintArray, sizeHints2);
       
  2638     QFETCH(qreal, width1);
       
  2639     QFETCH(qreal, width2);
       
  2640 
       
  2641     // create objects
       
  2642     QGraphicsWidget *widget = new QGraphicsWidget;
       
  2643     TheAnchorLayout *layout = new TheAnchorLayout;
       
  2644     TestWidget *childWidget1 = new TestWidget;
       
  2645     TestWidget *childWidget2 = new TestWidget;
       
  2646 
       
  2647     // set anchors
       
  2648     layout->setAnchor( layout, Qt::AnchorLeft, childWidget1, Qt::AnchorLeft, 10 );
       
  2649     layout->setAnchor( childWidget1, Qt::AnchorRight, childWidget2, Qt::AnchorLeft, 10 );
       
  2650     layout->setAnchor( childWidget2, Qt::AnchorRight, layout, Qt::AnchorRight, 10 );
       
  2651 
       
  2652     widget->setLayout( layout );
       
  2653 
       
  2654     // set test case specific: size hints
       
  2655     childWidget1->setMinimumWidth( sizeHints1.value( Qt::MinimumSize ) );
       
  2656     childWidget1->setPreferredWidth( sizeHints1.value( Qt::PreferredSize ) );
       
  2657     childWidget1->setMaximumWidth( sizeHints1.value( Qt::MaximumSize ) );
       
  2658 
       
  2659     childWidget2->setMinimumWidth( sizeHints2.value( Qt::MinimumSize ) );
       
  2660     childWidget2->setPreferredWidth( sizeHints2.value( Qt::PreferredSize ) );
       
  2661     childWidget2->setMaximumWidth( sizeHints2.value( Qt::MaximumSize ) );
       
  2662 
       
  2663     widget->setGeometry( QRectF( QPoint(0,0), QSize( 100,100 ) ) );
       
  2664 
       
  2665     // check results:
       
  2666     if ( width1 == -1.0f ) {
       
  2667         // invalid
       
  2668         QCOMPARE( layout->isValid() , false );
       
  2669     } else {
       
  2670         // valid
       
  2671         QCOMPARE( float(childWidget1->geometry().width()), float(width1) );
       
  2672         QCOMPARE( float(childWidget2->geometry().width()), float(width2) );
       
  2673     }
       
  2674 }
       
  2675 
       
  2676 void tst_QGraphicsAnchorLayout1::testSizeHint()
       
  2677 {
       
  2678     QGraphicsWidget *widget[5];
       
  2679 
       
  2680     for( int i = 0; i < 5; i++ ) {
       
  2681         widget[i] = new QGraphicsWidget;
       
  2682         widget[i]->setMinimumSize( 10, 10 );
       
  2683         widget[i]->setPreferredSize( 20, 20 );
       
  2684         widget[i]->setMaximumSize( 40, 40 );
       
  2685     }
       
  2686 
       
  2687     // one, basic
       
  2688     {
       
  2689         TheAnchorLayout *layout = new TheAnchorLayout();
       
  2690 
       
  2691 
       
  2692         layout->setAnchor(layout, Qt::AnchorLeft, widget[0], Qt::AnchorLeft, 0 );
       
  2693         layout->setAnchor(layout, Qt::AnchorRight, widget[0], Qt::AnchorRight, 0 );
       
  2694 
       
  2695         layout->setAnchor(layout, Qt::AnchorTop, widget[0], Qt::AnchorTop, 0 );
       
  2696         layout->setAnchor(layout, Qt::AnchorBottom, widget[0], Qt::AnchorBottom, 0 );
       
  2697 
       
  2698         QCOMPARE( layout->minimumSize(), widget[0]->minimumSize() );
       
  2699         QCOMPARE( layout->preferredSize(), widget[0]->preferredSize() );
       
  2700         QCOMPARE( layout->maximumSize(), widget[0]->maximumSize() );
       
  2701 
       
  2702 
       
  2703         delete layout;
       
  2704     }
       
  2705 
       
  2706     // one, basic again
       
  2707     {
       
  2708         TheAnchorLayout *layout = new TheAnchorLayout();
       
  2709 
       
  2710 
       
  2711         layout->setAnchor(layout, Qt::AnchorLeft, widget[0], Qt::AnchorLeft, 10 );
       
  2712         // layout->setAnchor(layout, Qt::AnchorRight, widget[0], Qt::AnchorRight, -10 );
       
  2713         layout->setAnchor(layout, Qt::AnchorRight, widget[0], Qt::AnchorRight, 10 );
       
  2714 
       
  2715         layout->setAnchor(layout, Qt::AnchorTop, widget[0], Qt::AnchorTop, 10 );
       
  2716         // layout->setAnchor(layout, Qt::AnchorBottom, widget[0], Qt::AnchorBottom, -10 );
       
  2717         layout->setAnchor(layout, Qt::AnchorBottom, widget[0], Qt::AnchorBottom, 10 );
       
  2718 
       
  2719         QCOMPARE( layout->minimumSize(), widget[0]->minimumSize() + QSizeF( 20, 20 ) );
       
  2720         QCOMPARE( layout->preferredSize(), widget[0]->preferredSize() + QSizeF( 20, 20 ) );
       
  2721         QCOMPARE( layout->maximumSize(), widget[0]->maximumSize() + QSizeF( 20, 20 ) );
       
  2722 
       
  2723         delete layout;
       
  2724     }
       
  2725 
       
  2726     // two, serial
       
  2727     {
       
  2728         TheAnchorLayout *layout = new TheAnchorLayout();
       
  2729 
       
  2730 
       
  2731         layout->setAnchor(layout, Qt::AnchorLeft, widget[0], Qt::AnchorLeft, 0 );
       
  2732         layout->setAnchor(layout, Qt::AnchorTop, widget[0], Qt::AnchorTop, 0 );
       
  2733         layout->setAnchor(layout, Qt::AnchorBottom, widget[0], Qt::AnchorBottom, 0 );
       
  2734 
       
  2735         layout->setAnchor(widget[0], Qt::AnchorRight, widget[1], Qt::AnchorLeft, 0 );
       
  2736         layout->setAnchor(widget[1], Qt::AnchorRight, layout, Qt::AnchorRight, 0 );
       
  2737 
       
  2738 
       
  2739         QCOMPARE( layout->minimumSize(), widget[0]->minimumSize() + QSizeF( widget[1]->minimumWidth(), 0 ) );
       
  2740         QCOMPARE( layout->preferredSize(), widget[0]->preferredSize() + QSizeF( widget[1]->preferredWidth(), 0 ) );
       
  2741         QCOMPARE( layout->maximumSize(), widget[0]->maximumSize() + QSizeF( widget[1]->maximumWidth(), 0 ) );
       
  2742 
       
  2743         delete layout;
       
  2744     }
       
  2745 
       
  2746     // two, parallel
       
  2747     {
       
  2748         TheAnchorLayout *layout = new TheAnchorLayout();
       
  2749 
       
  2750 
       
  2751         layout->setAnchor(layout, Qt::AnchorLeft, widget[0], Qt::AnchorLeft, 0 );
       
  2752         layout->setAnchor(layout, Qt::AnchorTop, widget[0], Qt::AnchorTop, 0 );
       
  2753         layout->setAnchor(layout, Qt::AnchorBottom, widget[0], Qt::AnchorBottom, 0 );
       
  2754         layout->setAnchor(layout, Qt::AnchorRight, widget[0], Qt::AnchorRight, 0 );
       
  2755 
       
  2756         layout->setAnchor(layout, Qt::AnchorLeft, widget[1], Qt::AnchorLeft, 0 );
       
  2757         layout->setAnchor(layout, Qt::AnchorTop, widget[1], Qt::AnchorTop, 0 );
       
  2758         layout->setAnchor(layout, Qt::AnchorBottom, widget[1], Qt::AnchorBottom, 0 );
       
  2759         layout->setAnchor(layout, Qt::AnchorRight, widget[1], Qt::AnchorRight, 0 );
       
  2760 
       
  2761         QCOMPARE( layout->minimumSize(), widget[0]->minimumSize() );
       
  2762         QCOMPARE( layout->preferredSize(), widget[0]->preferredSize() );
       
  2763         QCOMPARE( layout->maximumSize(), widget[0]->maximumSize() );
       
  2764 
       
  2765         delete layout;
       
  2766     }
       
  2767 
       
  2768     // five, serial
       
  2769     {
       
  2770         TheAnchorLayout *layout = new TheAnchorLayout();
       
  2771 
       
  2772 
       
  2773         layout->setAnchor(layout, Qt::AnchorLeft, widget[0], Qt::AnchorLeft, 0 );
       
  2774         layout->setAnchor(layout, Qt::AnchorTop, widget[0], Qt::AnchorTop, 0 );
       
  2775         layout->setAnchor(layout, Qt::AnchorBottom, widget[0], Qt::AnchorBottom, 0 );
       
  2776 
       
  2777         layout->setAnchor(widget[0], Qt::AnchorRight, widget[1], Qt::AnchorLeft, 0 );
       
  2778         layout->setAnchor(widget[1], Qt::AnchorRight, widget[2], Qt::AnchorLeft, 0 );
       
  2779         layout->setAnchor(widget[2], Qt::AnchorRight, widget[3], Qt::AnchorLeft, 0 );
       
  2780         layout->setAnchor(widget[3], Qt::AnchorRight, widget[4], Qt::AnchorLeft, 0 );
       
  2781         layout->setAnchor(widget[4], Qt::AnchorRight, layout, Qt::AnchorRight, 0 );
       
  2782 
       
  2783 
       
  2784         QCOMPARE( layout->minimumSize(), widget[0]->minimumSize() +
       
  2785         QSizeF( widget[1]->minimumWidth() +
       
  2786         widget[2]->minimumWidth() +
       
  2787         widget[3]->minimumWidth() +
       
  2788         widget[4]->minimumWidth(), 0 ) );
       
  2789 
       
  2790         QCOMPARE( layout->preferredSize(), widget[0]->preferredSize() +
       
  2791         QSizeF( widget[1]->preferredWidth() +
       
  2792         widget[2]->preferredWidth() +
       
  2793         widget[3]->preferredWidth() +
       
  2794         widget[4]->preferredWidth(), 0 ) );
       
  2795 
       
  2796         QCOMPARE( layout->maximumSize(), widget[0]->maximumSize() +
       
  2797         QSizeF( widget[1]->maximumWidth() +
       
  2798         widget[2]->maximumWidth() +
       
  2799         widget[3]->maximumWidth() +
       
  2800         widget[4]->maximumWidth(), 0 ) );
       
  2801 
       
  2802         delete layout;
       
  2803     }
       
  2804 
       
  2805 
       
  2806     for( int i = 0; i < 5; i++ ) {
       
  2807         delete widget[i];
       
  2808     }
       
  2809 }
       
  2810 
       
  2811 #ifdef TEST_COMPLEX_CASES
       
  2812 
       
  2813 void tst_QGraphicsAnchorLayout1::testComplexCases_data()
       
  2814 {
       
  2815     QTest::addColumn<QSizeF>("size");
       
  2816     QTest::addColumn<BasicLayoutTestDataList>("data");
       
  2817     QTest::addColumn<AnchorItemSizeHintList>("sizehint");
       
  2818     QTest::addColumn<BasicLayoutTestResultList>("result");
       
  2819 
       
  2820     typedef BasicLayoutTestData BasicData;
       
  2821     typedef BasicLayoutTestResult BasicResult;
       
  2822 
       
  2823     // Three widgets, the same sizehint
       
  2824     {
       
  2825         BasicLayoutTestDataList theData;
       
  2826         AnchorItemSizeHintList theSizeHint;
       
  2827         BasicLayoutTestResultList theResult1;
       
  2828         BasicLayoutTestResultList theResult2;
       
  2829 
       
  2830         theData
       
  2831             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
  2832             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorLeft, 10)
       
  2833             << BasicData(0, Qt::AnchorRight, 2, Qt::AnchorLeft, 10)
       
  2834 
       
  2835             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  2836             << BasicData(2, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  2837 
       
  2838             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 0)
       
  2839             << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 0)
       
  2840             << BasicData(-1, Qt::AnchorTop, 2, Qt::AnchorTop, 0)
       
  2841          ;
       
  2842 
       
  2843         theSizeHint
       
  2844             << AnchorItemSizeHint( 0, 50, 100, 0, 50, 100 )
       
  2845             << AnchorItemSizeHint( 0, 50, 100, 0, 50, 100 )
       
  2846             << AnchorItemSizeHint( 0, 50, 100, 0, 50, 100 )
       
  2847          ;
       
  2848         theResult1
       
  2849             << BasicResult(0, QRectF(10, 0, 30, 50) )
       
  2850             << BasicResult(1, QRectF(50, 0, 30, 50) )
       
  2851             << BasicResult(2, QRectF(50, 0, 30, 50) )
       
  2852             ;
       
  2853 
       
  2854         theResult2
       
  2855             << BasicResult(0, QRectF(10, 0, 60, 50) )
       
  2856             << BasicResult(1, QRectF(80, 0, 60, 50) )
       
  2857             << BasicResult(2, QRectF(80, 0, 60, 50) )
       
  2858             ;
       
  2859 
       
  2860         QTest::newRow("Three, the same sizehint(1)") << QSizeF(90, 50) << theData << theSizeHint << theResult1;
       
  2861         QTest::newRow("Three, the same sizehint(2)") << QSizeF(150, 50) << theData << theSizeHint << theResult2;
       
  2862     }
       
  2863 
       
  2864     // Three widgets, serial is bigger
       
  2865     {
       
  2866         BasicLayoutTestDataList theData;
       
  2867         AnchorItemSizeHintList theSizeHint;
       
  2868         BasicLayoutTestResultList theResult;
       
  2869 
       
  2870         theData
       
  2871             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
  2872             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorLeft, 10)
       
  2873             << BasicData(0, Qt::AnchorRight, 2, Qt::AnchorLeft, 10)
       
  2874 
       
  2875             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  2876             << BasicData(2, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  2877 
       
  2878             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 0)
       
  2879             << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 0)
       
  2880             << BasicData(-1, Qt::AnchorTop, 2, Qt::AnchorTop, 0)
       
  2881          ;
       
  2882 
       
  2883         theSizeHint
       
  2884             << AnchorItemSizeHint( 0, 100, 200, 0, 50, 100 )
       
  2885             << AnchorItemSizeHint( 0, 50, 100, 0, 50, 100 )
       
  2886             << AnchorItemSizeHint( 0, 50, 100, 0, 50, 100 )
       
  2887          ;
       
  2888 
       
  2889         theResult
       
  2890             << BasicResult(0, QRectF(10, 0, 70, 50) )
       
  2891             << BasicResult(1, QRectF(90, 0, 35, 50) )
       
  2892             << BasicResult(2, QRectF(90, 0, 35, 50) );
       
  2893 
       
  2894         QTest::newRow("Three, serial is bigger") << QSizeF(135, 50) << theData << theSizeHint << theResult;
       
  2895 
       
  2896         // theResult
       
  2897         //     << BasicResult(0, QRectF(10, 0, 80, 50) )
       
  2898         //     << BasicResult(1, QRectF(100, 0, 60, 50) )
       
  2899         //     << BasicResult(2, QRectF(100, 0, 60, 50) )
       
  2900         // ;
       
  2901 
       
  2902         // QTest::newRow("Three, serial is bigger") << QSizeF(170, 50) << theData << theSizeHint << theResult;
       
  2903     }
       
  2904 
       
  2905 
       
  2906     // Three widgets, parallel is bigger
       
  2907     {
       
  2908         BasicLayoutTestDataList theData;
       
  2909         AnchorItemSizeHintList theSizeHint;
       
  2910         BasicLayoutTestResultList theResult;
       
  2911 
       
  2912         theData
       
  2913             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
  2914             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorLeft, 10)
       
  2915             << BasicData(0, Qt::AnchorRight, 2, Qt::AnchorLeft, 10)
       
  2916 
       
  2917             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  2918             << BasicData(2, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  2919 
       
  2920             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 0)
       
  2921             << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 0)
       
  2922             << BasicData(-1, Qt::AnchorTop, 2, Qt::AnchorTop, 0)
       
  2923          ;
       
  2924 
       
  2925         theSizeHint
       
  2926             << AnchorItemSizeHint( 0, 50, 100, 0, 50, 100 )
       
  2927             << AnchorItemSizeHint( 0, 100, 200, 0, 50, 100 )
       
  2928             << AnchorItemSizeHint( 0, 50, 100, 0, 50, 100 )
       
  2929          ;
       
  2930 
       
  2931         // ### QGAL uses a different preferred size calculation algorithm.
       
  2932         //     This algorithm was discussed with Jan-Arve and tries to grow
       
  2933         //     items instead of shrinking them.
       
  2934         //     In this case, the preferred size of each item becomes:
       
  2935         //     Item 0: 50
       
  2936         //     Item 1: 100 (grows to avoid shrinking item 2)
       
  2937         //     Item 2: 100
       
  2938         //     Therefore, the preferred size of the parent widget becomes
       
  2939         //     180 == (10 + 50 + 10 + 100 + 10)
       
  2940         //     As we set its size to 150, each widget is shrinked in the same
       
  2941         //     ratio, in order to achieve the width of 150 == (10 + 40 + 10 + 80 + 10)
       
  2942 
       
  2943         theResult
       
  2944             << BasicResult(0, QRectF(10, 0, 40, 50) )
       
  2945             << BasicResult(1, QRectF(60, 0, 80, 50) )
       
  2946             << BasicResult(2, QRectF(60, 0, 80, 50) )
       
  2947             ;
       
  2948 
       
  2949         QTest::newRow("Three, parallel is bigger") << QSizeF(150, 50) << theData << theSizeHint << theResult;
       
  2950 
       
  2951         // #ifdef PREFERRED_IS_AVERAGE
       
  2952         //         theResult
       
  2953         //             << BasicResult(0, QRectF(10, 0, 50, 50) )
       
  2954         //             << BasicResult(1, QRectF(70, 0, 75, 50) )
       
  2955         //             << BasicResult(2, QRectF(70, 0, 75, 50) )
       
  2956         //             ;
       
  2957 
       
  2958         //         QTest::newRow("Three, parallel is bigger") << QSizeF(155, 50) << theData << theSizeHint << theResult;
       
  2959         // #else
       
  2960         //         theResult
       
  2961         //             << BasicResult(0, QRectF(10, 0, 50, 50) )
       
  2962         //             << BasicResult(1, QRectF(70, 0, 66.66666666666666, 50) )
       
  2963         //             << BasicResult(2, QRectF(70, 0, 60.66666666666666, 50) )
       
  2964         //             ;
       
  2965 
       
  2966         //         QTest::newRow("Three, parallel is bigger") << QSizeF(146.66666666666666, 50) << theData << theSizeHint << theResult;
       
  2967         // #endif
       
  2968     }
       
  2969 
       
  2970     // Three widgets, the same sizehint, one center anchor
       
  2971     {
       
  2972         BasicLayoutTestDataList theData;
       
  2973         AnchorItemSizeHintList theSizeHint;
       
  2974         BasicLayoutTestResultList theResult;
       
  2975 
       
  2976         theData
       
  2977             << BasicData(-1, Qt::AnchorLeft, 0, Qt::AnchorLeft, 10)
       
  2978             << BasicData(0, Qt::AnchorRight, 1, Qt::AnchorLeft, 10)
       
  2979             << BasicData(0, Qt::AnchorHorizontalCenter, 2, Qt::AnchorLeft, 10)
       
  2980 
       
  2981             << BasicData(1, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  2982             << BasicData(2, Qt::AnchorRight, -1, Qt::AnchorRight, 10)
       
  2983 
       
  2984             << BasicData(-1, Qt::AnchorTop, 0, Qt::AnchorTop, 0)
       
  2985             << BasicData(-1, Qt::AnchorTop, 1, Qt::AnchorTop, 0)
       
  2986             << BasicData(-1, Qt::AnchorTop, 2, Qt::AnchorTop, 0)
       
  2987          ;
       
  2988 
       
  2989         theSizeHint
       
  2990             << AnchorItemSizeHint( 0, 50, 100, 0, 50, 100 )
       
  2991             << AnchorItemSizeHint( 0, 50, 100, 0, 50, 100 )
       
  2992             << AnchorItemSizeHint( 0, 50, 100, 0, 50, 100 )
       
  2993          ;
       
  2994         theResult
       
  2995             << BasicResult(0, QRectF(10, 0, 40, 50) )
       
  2996             << BasicResult(1, QRectF(60, 0, 40, 50) )
       
  2997             << BasicResult(2, QRectF(40, 0, 60, 50) )
       
  2998             ;
       
  2999 
       
  3000             ;
       
  3001 
       
  3002         QTest::newRow("Three, the same sizehint, one center anchor") << QSizeF(110, 50) << theData << theSizeHint << theResult;
       
  3003     }
       
  3004 }
       
  3005 
       
  3006 void tst_QGraphicsAnchorLayout1::testComplexCases()
       
  3007 {
       
  3008     QFETCH(QSizeF, size);
       
  3009     QFETCH(BasicLayoutTestDataList, data);
       
  3010     QFETCH(AnchorItemSizeHintList, sizehint);
       
  3011     QFETCH(BasicLayoutTestResultList, result);
       
  3012 
       
  3013     QGraphicsWidget *widget = new QGraphicsWidget;
       
  3014 
       
  3015     // Determine amount of widgets to add.
       
  3016     int widgetCount = -1;
       
  3017     for (int i = 0; i < data.count(); ++i) {
       
  3018         const BasicLayoutTestData item = data[i];
       
  3019         widgetCount = qMax(widgetCount, item.firstIndex);
       
  3020         widgetCount = qMax(widgetCount, item.secondIndex);
       
  3021     }
       
  3022     ++widgetCount; // widgetCount is max of indices.
       
  3023 
       
  3024     // Create dummy widgets
       
  3025     QList<QGraphicsWidget *> widgets;
       
  3026     for (int i = 0; i < widgetCount; ++i) {
       
  3027         TestWidget *w = new TestWidget;
       
  3028 
       
  3029         w->setMinimumWidth( sizehint[i].hmin );
       
  3030         w->setPreferredWidth( sizehint[i].hpref );
       
  3031         w->setMaximumWidth( sizehint[i].hmax );
       
  3032 
       
  3033         w->setMinimumHeight( sizehint[i].vmin );
       
  3034         w->setPreferredHeight( sizehint[i].vpref );
       
  3035         w->setMaximumHeight( sizehint[i].vmax );
       
  3036 
       
  3037         widgets << w;
       
  3038     }
       
  3039 
       
  3040     // Setup anchor layout
       
  3041     TheAnchorLayout *layout = new TheAnchorLayout;
       
  3042 
       
  3043     for (int i = 0; i < data.count(); ++i) {
       
  3044         const BasicLayoutTestData item = data[i];
       
  3045         layout->setAnchor(
       
  3046             getItem(item.firstIndex, widgets, layout),
       
  3047             item.firstEdge,
       
  3048             getItem(item.secondIndex, widgets, layout),
       
  3049             item.secondEdge,
       
  3050             item.spacing );
       
  3051     }
       
  3052 
       
  3053     widget->setLayout(layout);
       
  3054     widget->setContentsMargins(0,0,0,0);
       
  3055 
       
  3056     widget->setMinimumSize(size);
       
  3057     widget->setMaximumSize(size);
       
  3058 
       
  3059 //    QTest::qWait(500); // layouting is asynchronous..
       
  3060 
       
  3061     // Validate
       
  3062     for (int i = 0; i < result.count(); ++i) {
       
  3063         const BasicLayoutTestResult item = result[i];
       
  3064         QCOMPARE(widgets[item.index]->geometry(), item.rect);
       
  3065     }
       
  3066 
       
  3067     // Test mirrored mode
       
  3068     widget->setLayoutDirection(Qt::RightToLeft);
       
  3069     layout->activate();
       
  3070     // Validate
       
  3071     for (int j = 0; j < result.count(); ++j) {
       
  3072         const BasicLayoutTestResult item = result[j];
       
  3073         QRectF mirroredRect(item.rect);
       
  3074         // only valid cases are mirrored
       
  3075         if (mirroredRect.isValid()){
       
  3076             mirroredRect.moveLeft(size.width()-item.rect.width()-item.rect.left());
       
  3077         }
       
  3078         QCOMPARE(widgets[item.index]->geometry(), mirroredRect);
       
  3079         delete widgets[item.index];
       
  3080     }
       
  3081 
       
  3082     delete widget;
       
  3083 }
       
  3084 #endif //TEST_COMPLEX_CASES
       
  3085 
       
  3086 
       
  3087 QTEST_MAIN(tst_QGraphicsAnchorLayout1)
       
  3088 #include "tst_qgraphicsanchorlayout1.moc"
       
  3089 //-----------------------------------------------------------------------------
       
  3090