From a077d075eafa947b48cf0824146d8dc6873b10ed Mon Sep 17 00:00:00 2001 From: Jan Arve Saether <jan-arve.saether@digia.com> Date: Fri, 5 Apr 2013 10:09:13 +0200 Subject: [PATCH] Fixed a bug where spans across empty cells got broken. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a row/column is only used only because of the spanning of an item, the cell should be treated as it didn't exist. We keep track of this with the "ignore" bit array. The old code would always start from the row/column at position 1. In the attached testcase this made the effectiveRowSpan become larger than actually needed. Task-number: QTBUG-30255 Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com> Change-Id: I410ed373f408014333d3964e2ddbcfeb25bec3a6 (cherry picked from qtbase/4f072e2d3d7e429359ff15a615d02712bff7ee51) Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com> --- src/layouts/qgridlayoutengine.cpp | 2 +- tests/auto/controls/data/tst_gridlayout.qml | 52 +++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/layouts/qgridlayoutengine.cpp b/src/layouts/qgridlayoutengine.cpp index c5a1b5ce6..f72bffe26 100644 --- a/src/layouts/qgridlayoutengine.cpp +++ b/src/layouts/qgridlayoutengine.cpp @@ -1419,7 +1419,7 @@ void QGridLayoutEngine::fillRowData(QGridLayoutRowData *rowData, int effectiveRowSpan = 1; for (int i = 1; i < itemRowSpan; ++i) { - if (!rowData->ignore.testBit(i)) + if (!rowData->ignore.testBit(i + itemRow)) ++effectiveRowSpan; } diff --git a/tests/auto/controls/data/tst_gridlayout.qml b/tests/auto/controls/data/tst_gridlayout.qml index da1cd8149..2315dc14e 100644 --- a/tests/auto/controls/data/tst_gridlayout.qml +++ b/tests/auto/controls/data/tst_gridlayout.qml @@ -322,5 +322,57 @@ Item { layout.destroy(); } + + Component { + id: layout_spans_Component + GridLayout { + columnSpacing: 0 + rowSpacing: 0 + // black rectangles are explicitly positioned with row,column + Rectangle { + // (0,0) + id: r0 + color: "black" + width: 20 + height: 20 + Layout.row: 0 + Layout.column: 0 + } + Rectangle { + // (0,1) + id: r1 + color: "black" + width: 20 + height: 20 + Layout.row: 0 + Layout.column: 1 + Layout.columnSpan: 2 + Layout.rowSpan: 2 + } + Rectangle { + // (99,99) + id: r2 + color: "black" + width: 20 + height: 20 + Layout.row: 99 + Layout.column: 99 + } + } + } + + function test_spans() { + var layout = layout_spans_Component.createObject(container); + compare(layout.children[0].x, 0); + compare(layout.children[0].y, 0); + compare(layout.children[1].x, 20); + compare(layout.children[1].y, 0); + compare(layout.children[2].x, 40); + compare(layout.children[2].y, 20); + + layout.destroy(); + } + + } } -- GitLab