summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Arve Sæther <[email protected]>2023-12-19 10:48:25 +0100
committerQt Cherry-pick Bot <[email protected]>2023-12-20 22:58:42 +0000
commitea8aaf2bc364faef58433d1db7aad1ff8b2b7312 (patch)
treeaaa4c0dd10ed9bca920f39202af7a428c5c97cc4
parent55d4ee6586db8c5e254e11d0f5604168fbd686b3 (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.5 6.2 Task-number: QTBUG-116577 Change-Id: I49f79d288370bd93831ac9eda623ce4bbf587796 Reviewed-by: Santhosh Kumar <[email protected]> (cherry picked from commit 2a95ecf7e81fbdcfad50f8a1dd5c62b120e2ec27) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit c8df6e18df76a1a60986bfa2266e5c00789059bc)
-rw-r--r--src/gui/util/qgridlayoutengine.cpp8
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];
}