Fixed a bug where the MaximumSizeHint of a layout with spans was wrong

This was spotted while tracking down a similar bug related to spans.
This now also eliminates the Q_EXPECT_FAILs in
heightForWidthWithSpanning(), since it now finally works.

The problem was only for the maximum size, since the size of an ignored
row/column was min: 0, pref: 0, max: FLT_MAX (the default constructed
values for a QGridLayoutBox).

Change-Id: Ibb33c26ede40ed02edd26f596ba6133d59c9962f
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
This commit is contained in:
Jan Arve Saether 2013-04-02 15:05:30 +02:00 committed by The Qt Project
parent 0f532b29bb
commit 9d7ae6dfbe
2 changed files with 7 additions and 5 deletions

View File

@ -432,6 +432,8 @@ QGridLayoutBox QGridLayoutRowData::totalBox(int start, int end) const
result.q_maximumSize = 0.0; result.q_maximumSize = 0.0;
qreal nextSpacing = 0.0; qreal nextSpacing = 0.0;
for (int i = start; i < end; ++i) { for (int i = start; i < end; ++i) {
if (ignore.testBit(i))
continue;
result.add(boxes.at(i), stretches.at(i), nextSpacing); result.add(boxes.at(i), stretches.at(i), nextSpacing);
nextSpacing = spacings.at(i); nextSpacing = spacings.at(i);
} }

View File

@ -3181,23 +3181,19 @@ void tst_QGraphicsGridLayout::heightForWidthWithSpanning()
QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)), QSizeF(1, 1)); QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)), QSizeF(1, 1));
QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1)), QSizeF(200, 100)); QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1)), QSizeF(200, 100));
QEXPECT_FAIL("", "Due to an old bug this wrongly returns QWIDGETSIZE_MAX", Continue);
QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(-1, -1)), QSizeF(30000, 30000)); QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(-1, -1)), QSizeF(30000, 30000));
QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(200, -1)), QSizeF(200, 100)); QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(200, -1)), QSizeF(200, 100));
QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(200, -1)), QSizeF(200, 100)); QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(200, -1)), QSizeF(200, 100));
QEXPECT_FAIL("", "Due to an old bug this wrongly returns QWIDGETSIZE_MAX", Continue);
QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, 100)); QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, 100));
QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(2, -1)), QSizeF(2, 10000)); QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(2, -1)), QSizeF(2, 10000));
QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(2, -1)), QSizeF(2, 10000)); QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(2, -1)), QSizeF(2, 10000));
QEXPECT_FAIL("", "Due to an old bug this wrongly returns QWIDGETSIZE_MAX", Continue);
QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(2, -1)), QSizeF(2, 10000)); QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(2, -1)), QSizeF(2, 10000));
QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(200, -1)), QSizeF(200, 100)); QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(200, -1)), QSizeF(200, 100));
QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(200, -1)), QSizeF(200, 100)); QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(200, -1)), QSizeF(200, 100));
QEXPECT_FAIL("", "Due to an old bug this wrongly returns QWIDGETSIZE_MAX", Continue); QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, 100));
QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, 10000));
} }
Q_DECLARE_METATYPE(QSizePolicy::Policy) Q_DECLARE_METATYPE(QSizePolicy::Policy)
@ -3378,6 +3374,10 @@ void tst_QGraphicsGridLayout::spanAcrossEmptyRow()
QCOMPARE(w1->geometry(), QRectF( 0, 0, 20, 20)); QCOMPARE(w1->geometry(), QRectF( 0, 0, 20, 20));
QCOMPARE(w2->geometry(), QRectF(20, 0, 20, 20)); QCOMPARE(w2->geometry(), QRectF(20, 0, 20, 20));
QCOMPARE(w3->geometry(), QRectF(40, 0, 20, 20)); QCOMPARE(w3->geometry(), QRectF(40, 0, 20, 20));
QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize), QSizeF(30, 10));
QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize), QSizeF(60, 20));
QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize), QSizeF(120, 40));
} }
void tst_QGraphicsGridLayout::stretchAndHeightForWidth() void tst_QGraphicsGridLayout::stretchAndHeightForWidth()