diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2010-09-30 09:38:14 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2010-10-05 03:04:29 (GMT) |
commit | fb439760468f55d7884f5b14172fff9cc0a2107f (patch) | |
tree | 16301be65702016eae5c443bd98bf04cdc4f3ce8 /src/gui/graphicsview | |
parent | 9dc4889b8ae8c598a671c0fab3b71cf128cd7311 (diff) | |
download | Qt-fb439760468f55d7884f5b14172fff9cc0a2107f.zip Qt-fb439760468f55d7884f5b14172fff9cc0a2107f.tar.gz Qt-fb439760468f55d7884f5b14172fff9cc0a2107f.tar.bz2 |
Fixed a layout issue where you could get NaN as dimensions
The problem is that with empty layouts we could sometimes divide by 0.
Note: This doesn't fix the whole task...
Task-number: QTBUG-13547
Reviewed-by: ogoffart
(cherry picked from commit c1f9978c9d61bcbdb2f280185a3abdea13d7f532)
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r-- | src/gui/graphicsview/qgridlayoutengine.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp index 4fba5ff..ae5bf90 100644 --- a/src/gui/graphicsview/qgridlayoutengine.cpp +++ b/src/gui/graphicsview/qgridlayoutengine.cpp @@ -306,20 +306,19 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz ultimatePreferredSize = ultimatePreferredSize * 3 / 2; ultimateSumPreferredSizes = ultimateSumPreferredSizes * 3 / 2; - qreal ultimateFactor = (stretch * ultimateSumPreferredSizes - / sumStretches) - - (box.q_preferredSize); - qreal transitionalFactor = sumCurrentAvailable - * (ultimatePreferredSize - box.q_preferredSize) - / (ultimateSumPreferredSizes - - sumPreferredSizes); - - qreal alpha = qMin(sumCurrentAvailable, - ultimateSumPreferredSizes - sumPreferredSizes); qreal beta = ultimateSumPreferredSizes - sumPreferredSizes; + if (!beta) { + factors[i] = 1; + } else { + qreal alpha = qMin(sumCurrentAvailable, beta); + qreal ultimateFactor = (stretch * ultimateSumPreferredSizes / sumStretches) + - (box.q_preferredSize); + qreal transitionalFactor = sumCurrentAvailable * (ultimatePreferredSize - box.q_preferredSize) / beta; + + factors[i] = ((alpha * ultimateFactor) + + ((beta - alpha) * transitionalFactor)) / beta; + } - factors[i] = ((alpha * ultimateFactor) - + ((beta - alpha) * transitionalFactor)) / beta; } sumFactors += factors[i]; if (desired < sumCurrentAvailable) |