diff options
author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2019-11-12 18:00:52 +0100 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@qt.io> | 2019-11-13 15:11:13 +0100 |
commit | 554309a1c1127b4a614cdba4f9ece46fc85df7e1 (patch) | |
tree | 9ec566ef87a9afa8f4f01119b4e1e9ceb047f05a | |
parent | 34d1b179256706111703e557cd1d86b6f9a2180a (diff) |
Qt Quick Layouts: Do not assert when specifying an invalid row/column
We now print a warning and try to gracefully handle it
Change-Id: I66e79fe918808f5fede78a23df50e9e95b7b832d
Fixes: QTBUG-67204
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/imports/layouts/qquicklinearlayout.cpp | 18 | ||||
-rw-r--r-- | tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml | 33 |
2 files changed, 49 insertions, 2 deletions
diff --git a/src/imports/layouts/qquicklinearlayout.cpp b/src/imports/layouts/qquicklinearlayout.cpp index 2e3b12064b..c8d2ac5eb2 100644 --- a/src/imports/layouts/qquicklinearlayout.cpp +++ b/src/imports/layouts/qquicklinearlayout.cpp @@ -645,6 +645,7 @@ void QQuickGridLayout::insertLayoutItems() int &nextColumn = nextCellPos[0]; int &nextRow = nextCellPos[1]; + const QSize gridSize(columns(), rows()); const int flowOrientation = flow(); int &flowColumn = nextCellPos[flowOrientation]; int &flowRow = nextCellPos[1 - flowOrientation]; @@ -677,8 +678,21 @@ void QQuickGridLayout::insertLayoutItems() // the unspecified component of the cell position should default to 0 // The getters do this for us, as they will return 0 for an // unset (or negative) value. - row = info->row(); - column = info->column(); + // In addition, if \a rows is less than Layout.row, treat Layout.row as if it was not set + // This will basically make it find the next available cell (potentially wrapping to + // the next line). Likewise for an invalid Layout.column + + if (gridSize.height() >= 0 && row >= gridSize.height()) { + qmlWarning(child) << QString::fromLatin1("Layout: row (%1) should be less than the number of rows (%2)").arg(info->row()).arg(rows()); + } else { + row = info->row(); + } + + if (gridSize.width() >= 0 && info->column() >= gridSize.width()) { + qmlWarning(child) << QString::fromLatin1("Layout: column (%1) should be less than the number of columns (%2)").arg(info->column()).arg(columns()); + } else { + column = info->column(); + } } rowSpan = info->rowSpan(); columnSpan = info->columnSpan(); diff --git a/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml b/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml index e8b3960486..be94fca8d4 100644 --- a/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml +++ b/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml @@ -1073,5 +1073,38 @@ Item { layout[propName] = data.value compare(layout.spy.count, 1) } + + Component { + id: layout_columnIsOutsideGrid_Component + GridLayout { + columns: 2 + Item { + Layout.row: 0 + Layout.column: 1 + } + Item { + implicitWidth: 10 + implicitHeight: 10 + Layout.row: 0 + Layout.column: 2 + } + Item { + Layout.columnSpan: 2 + Layout.fillWidth: true + Layout.fillHeight: true + } + } + } + + function test_columnIsOutsideGrid() + { + ignoreWarning(/QML Item: Layout: column \(2\) should be less than the number of columns \(2\)/); + var layout = layout_columnIsOutsideGrid_Component.createObject(container); + layout.width = layout.implicitWidth + layout.height = layout.implicitHeight + waitForRendering(layout); + layout.destroy() + } + } } |