summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Arve Saether <jan-arve.saether@digia.com>2013-12-23 15:43:33 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-07 09:39:40 +0100
commit7e8dc84430426180c7489cf2d29c36ed8b54c0c3 (patch)
tree48275991756950682244ea7e8fc060e2b8614a89
parent6644897dc61f4a15141534c893fd08b12df89bbe (diff)
downloadqtquickcontrols-7e8dc84430426180c7489cf2d29c36ed8b54c0c3.tar.gz
Do not loop infinitely if a span is larger than the layout extent
There is no point in searching through all cells to see if an item of columnSpan 3 fits into a layout with 2 columns, since it won't ever fit. So instead we detect this case early and ignore the item for inclusion. Task-number: QTBUG-35778 Change-Id: I3f7963df17b05b3eb14ba0bae49e5a885d15b33b Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
-rw-r--r--src/layouts/qquicklinearlayout.cpp5
-rw-r--r--tests/auto/controls/data/tst_gridlayout.qml22
2 files changed, 26 insertions, 1 deletions
diff --git a/src/layouts/qquicklinearlayout.cpp b/src/layouts/qquicklinearlayout.cpp
index 2b1ce66e..4f776b1f 100644
--- a/src/layouts/qquicklinearlayout.cpp
+++ b/src/layouts/qquicklinearlayout.cpp
@@ -736,6 +736,9 @@ void QQuickGridLayout::insertLayoutItems()
Q_ASSERT(columnSpan >= 1);
Q_ASSERT(rowSpan >= 1);
+ const int sp = span[flowOrientation];
+ if (sp > flowBound)
+ return;
if (row >= 0)
nextRow = row;
@@ -758,7 +761,7 @@ void QQuickGridLayout::insertLayoutItems()
bool cellAcceptsItem;
while (true) {
// Check if the item does not span beyond the layout bound
- cellAcceptsItem = (flowColumn + span[flowOrientation]) <= flowBound;
+ cellAcceptsItem = (flowColumn + sp) <= flowBound;
// Check if all the required cells are not taken
for (int rs = 0; cellAcceptsItem && rs < rowSpan; ++rs) {
diff --git a/tests/auto/controls/data/tst_gridlayout.qml b/tests/auto/controls/data/tst_gridlayout.qml
index 0e4f8509..7e6240fd 100644
--- a/tests/auto/controls/data/tst_gridlayout.qml
+++ b/tests/auto/controls/data/tst_gridlayout.qml
@@ -438,6 +438,28 @@ Item {
layout.destroy();
}
+ Component {
+ id: layout_spanIsMoreThanColumns_Component
+
+ GridLayout {
+ columnSpacing: 1
+ rowSpacing: 1
+ columns: 2
+
+ Rectangle {
+ implicitWidth: 10
+ implicitHeight: 10
+ Layout.columnSpan: 3
+ }
+ }
+ }
+
+ function test_spanIsMoreThanColumns() {
+ var layout = layout_spanIsMoreThanColumns_Component.createObject(container);
+ // item was not added, therefore implicit width is 0
+ compare(layout.implicitWidth, 0);
+ layout.destroy();
+ }
function test_sizeHints() {
var layout = layout_spanAcrossEmptyRows_Component.createObject(container);