diff options
author | Jan Arve Sæther <[email protected]> | 2023-12-19 10:48:25 +0100 |
---|---|---|
committer | Jan Arve Sæther <[email protected]> | 2023-12-20 18:40:32 +0000 |
commit | 2a95ecf7e81fbdcfad50f8a1dd5c62b120e2ec27 (patch) | |
tree | b64a42ecd08a5c93eb65dc7f942dc251f00b797f | |
parent | c0d6b22a39f20bb4f6da9510acae704cf6be91a5 (diff) |
Do not assert when preferred{Width|Height} is infinity
There's two alternative strategies for fixing this:
1. When fetching the preferred sizes from an item, the number is bounded
to a smaller (but still very large) value - not subject to overflow.
In practice this will result in the correct layout, but the
consequence is a small inconsistency: The preferred size of the
layout will be less than infinite despite that one of its items have
a preferred size of infinite.
2. Do not bound the fetched preferred sizes from items, but instead
let the rest of the code handle infinity.
This will result in the correct layout, and also a correct preferred
size of the layout.
This patch uses the second strategy, by applying a bound when needed.
Autotest will be submitted to qtdeclarative, since QGraphicsLayouts are
not affected by this.
Pick-to: 6.7 6.6 6.5 6.2
Task-number: QTBUG-116577
Change-Id: I49f79d288370bd93831ac9eda623ce4bbf587796
Reviewed-by: Santhosh Kumar <[email protected]>
-rw-r--r-- | src/gui/util/qgridlayoutengine.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/gui/util/qgridlayoutengine.cpp b/src/gui/util/qgridlayoutengine.cpp index 9d64c87bded..83def02f7e5 100644 --- a/src/gui/util/qgridlayoutengine.cpp +++ b/src/gui/util/qgridlayoutengine.cpp @@ -13,6 +13,8 @@ QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; +#define LAYOUTITEMSIZE_MAX (1 << 24) + template<typename T> static void insertOrRemoveItems(QList<T> &items, int index, int delta) { @@ -194,7 +196,8 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz sumAvailable = targetSize - totalBox.q_minimumSize; if (sumAvailable > 0.0) { - qreal sumDesired = totalBox.q_preferredSize - totalBox.q_minimumSize; + const qreal totalBox_preferredSize = qMin(totalBox.q_preferredSize, qreal(LAYOUTITEMSIZE_MAX)); + qreal sumDesired = totalBox_preferredSize - totalBox.q_minimumSize; for (int i = 0; i < n; ++i) { if (ignore.testBit(start + i)) { @@ -203,7 +206,8 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz } const QGridLayoutBox &box = boxes.at(start + i); - qreal desired = box.q_preferredSize - box.q_minimumSize; + const qreal box_preferredSize = qMin(box.q_preferredSize, qreal(LAYOUTITEMSIZE_MAX)); + qreal desired = box_preferredSize - box.q_minimumSize; factors[i] = growthFactorBelowPreferredSize(desired, sumAvailable, sumDesired); sumFactors += factors[i]; } |