summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2010-08-11 07:28:32 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2010-08-11 11:28:55 (GMT)
commit98b7e8ac793d95a6a8350c7fc25faebd6f44cd21 (patch)
treeff7f4e9428bc3c2e02704af8727cbcbed209a4ba
parentbb696453f6f87cad58982af3455335478fedb8cc (diff)
downloadQt-98b7e8ac793d95a6a8350c7fc25faebd6f44cd21.zip
Qt-98b7e8ac793d95a6a8350c7fc25faebd6f44cd21.tar.gz
Qt-98b7e8ac793d95a6a8350c7fc25faebd6f44cd21.tar.bz2
Layout items had the wrong size if the layout was resized to maximum.
The problem was that if targetSize was the layouts maximum size, then sumAvailable could be reduced to exactly 0 in the "while (keepGoing)" loop. That would mean that we would not enter the block that actually copied the new sizes from the temporary "newSizes" array to the output "sizes" array due to the "if (sumAvailable > 0)" condition. Task-number: none, discovered while fixing QT-3570 Reviewed-by: Frederik Gladhorn
-rw-r--r--src/gui/graphicsview/qgridlayoutengine.cpp15
-rw-r--r--tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp24
2 files changed, 20 insertions, 19 deletions
diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp
index a084647..4fba5ff 100644
--- a/src/gui/graphicsview/qgridlayoutengine.cpp
+++ b/src/gui/graphicsview/qgridlayoutengine.cpp
@@ -250,6 +250,7 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
sumAvailable = targetSize - totalBox.q_preferredSize;
if (sumAvailable > 0.0) {
+ qreal sumCurrentAvailable = sumAvailable;
bool somethingHasAMaximumSize = false;
qreal sumPreferredSizes = 0.0;
@@ -308,12 +309,12 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
qreal ultimateFactor = (stretch * ultimateSumPreferredSizes
/ sumStretches)
- (box.q_preferredSize);
- qreal transitionalFactor = sumAvailable
+ qreal transitionalFactor = sumCurrentAvailable
* (ultimatePreferredSize - box.q_preferredSize)
/ (ultimateSumPreferredSizes
- sumPreferredSizes);
- qreal alpha = qMin(sumAvailable,
+ qreal alpha = qMin(sumCurrentAvailable,
ultimateSumPreferredSizes - sumPreferredSizes);
qreal beta = ultimateSumPreferredSizes - sumPreferredSizes;
@@ -321,7 +322,7 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
+ ((beta - alpha) * transitionalFactor)) / beta;
}
sumFactors += factors[i];
- if (desired < sumAvailable)
+ if (desired < sumCurrentAvailable)
somethingHasAMaximumSize = true;
newSizes[i] = -1.0;
@@ -337,12 +338,12 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
continue;
const QGridLayoutBox &box = boxes.at(start + i);
- qreal avail = sumAvailable * factors[i] / sumFactors;
+ qreal avail = sumCurrentAvailable * factors[i] / sumFactors;
if (sizes[i] + avail >= box.q_maximumSize) {
newSizes[i] = box.q_maximumSize;
- sumAvailable -= box.q_maximumSize - sizes[i];
+ sumCurrentAvailable -= box.q_maximumSize - sizes[i];
sumFactors -= factors[i];
- keepGoing = (sumAvailable > 0.0);
+ keepGoing = (sumCurrentAvailable > 0.0);
if (!keepGoing)
break;
}
@@ -352,7 +353,7 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
for (int i = 0; i < n; ++i) {
if (newSizes[i] < 0.0) {
qreal delta = (sumFactors == 0.0) ? 0.0
- : sumAvailable * factors[i] / sumFactors;
+ : sumCurrentAvailable * factors[i] / sumFactors;
newSizes[i] = sizes[i] + delta;
}
}
diff --git a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
index d1d6860..5b03767 100644
--- a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
+++ b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
@@ -485,12 +485,12 @@ void tst_QGraphicsGridLayout::alignment()
widget->resize(widget->effectiveSizeHint(Qt::MaximumSize));
QApplication::processEvents();
- QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(0, 0, 50, 25));
- QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(0, 25, 50, 25));
- QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(125, 0, 50, 25));
- QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(125, 25, 50, 25));
- QCOMPARE(layout->itemAt(0,2)->geometry(), QRectF(250, 0, 50, 25));
- QCOMPARE(layout->itemAt(1,2)->geometry(), QRectF(250, 25, 50, 25));
+ QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(0, 0, 50, 50));
+ QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(0, 50, 50, 50));
+ QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(125, 0, 50, 50));
+ QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(125, 50, 50, 50));
+ QCOMPARE(layout->itemAt(0,2)->geometry(), QRectF(250, 0, 50, 50));
+ QCOMPARE(layout->itemAt(1,2)->geometry(), QRectF(250, 50, 50, 50));
delete widget;
}
@@ -544,12 +544,12 @@ void tst_QGraphicsGridLayout::columnAlignment()
| HCenter | Right | Left |
+---------------------------------+
*/
- QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(0, 0, 50, 25));
- QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(25, 26, 50, 25)); // item is king
- QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(126, 0, 50, 25));
- QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(151, 26, 50, 25)); // item is king
- QCOMPARE(layout->itemAt(0,2)->geometry(), QRectF(252, 0, 50, 25));
- QCOMPARE(layout->itemAt(1,2)->geometry(), QRectF(202, 26, 50, 25)); // item is king
+ QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(0, 0, 50, 50));
+ QCOMPARE(layout->itemAt(1,0)->geometry(), QRectF(25, 51, 50, 50)); // item is king
+ QCOMPARE(layout->itemAt(0,1)->geometry(), QRectF(126, 0, 50, 50));
+ QCOMPARE(layout->itemAt(1,1)->geometry(), QRectF(151, 51, 50, 50)); // item is king
+ QCOMPARE(layout->itemAt(0,2)->geometry(), QRectF(252, 0, 50, 50));
+ QCOMPARE(layout->itemAt(1,2)->geometry(), QRectF(202, 51, 50, 50)); // item is king
delete widget;
}