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>
This commit is contained in:
Jan Arve Sæther 2019-11-12 18:00:52 +01:00
parent 34d1b17925
commit 554309a1c1
2 changed files with 49 additions and 2 deletions

View File

@ -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();

View File

@ -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()
}
}
}