summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Arve Saether <jan-arve.saether@digia.com>2014-01-10 13:46:46 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-16 16:02:12 +0100
commitbc973dcf2163b25f2db74d974b252384bbee8d80 (patch)
tree42a34b52ee5be529336482ee057f690de0108a46
parent768e190b5d74ddb20135d37e6b17639896e18ee6 (diff)
downloadqtquickcontrols-bc973dcf2163b25f2db74d974b252384bbee8d80.tar.gz
Support negative layout spacings (do not assert)
This tests * default spacing * explicit positive spacing * negative spacings Negative spacings that causes the layout to shrink down to 0 or a negative spacing are not supported. (But make sure they don't crash the whole engine) Task-number: QTBUG-35741 Change-Id: I69521dffb03c35a63db37ab51a2e99152d88272b Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
-rw-r--r--src/layouts/qgridlayoutengine.cpp1
-rw-r--r--tests/auto/controls/data/tst_gridlayout.qml41
2 files changed, 41 insertions, 1 deletions
diff --git a/src/layouts/qgridlayoutengine.cpp b/src/layouts/qgridlayoutengine.cpp
index 910e34a0..35aa04f1 100644
--- a/src/layouts/qgridlayoutengine.cpp
+++ b/src/layouts/qgridlayoutengine.cpp
@@ -813,7 +813,6 @@ int QGridLayoutEngine::effectiveLastRow(Qt::Orientation orientation) const
void QGridLayoutEngine::setSpacing(qreal spacing, Qt::Orientations orientations)
{
- Q_ASSERT(spacing >= 0.0);
if (orientations & Qt::Horizontal)
q_defaultSpacings[Hor].setUserValue(spacing);
if (orientations & Qt::Vertical)
diff --git a/tests/auto/controls/data/tst_gridlayout.qml b/tests/auto/controls/data/tst_gridlayout.qml
index 7e6240fd..22784aa7 100644
--- a/tests/auto/controls/data/tst_gridlayout.qml
+++ b/tests/auto/controls/data/tst_gridlayout.qml
@@ -786,5 +786,46 @@ Item {
layout.destroy();
}
+
+ Component {
+ id: layout_spacings_Component
+ GridLayout {
+ id: layout
+ Repeater {
+ model: 2
+ Rectangle {
+ implicitWidth: 10
+ implicitHeight: 10
+ }
+ }
+ }
+ }
+
+ function test_spacings()
+ {
+ var layout = layout_spacings_Component.createObject(container);
+ waitForRendering(layout)
+
+ // breaks down below -19. This is acceptable, since it means that the implicit size of the layout is negative
+ var testSpacings = [Number.NaN, 0, 10, -5, -19]
+ layout.rowSpacing = 0
+ for (var i = 0; i < testSpacings.length; ++i) {
+ var sp = testSpacings[i]
+ if (isNaN(sp)) {
+ sp = 5 // Test defaults
+ } else {
+ layout.columnSpacing = sp
+ }
+ compare(itemRect(layout.children[0]), [ 0, 0, 10, 10])
+ compare(itemRect(layout.children[1]), [10 + sp, 0, 10, 10])
+ compare(layout.implicitWidth, 20 + sp)
+ }
+
+ // do not crash
+ layout.columnSpacing = -100
+ waitForRendering(layout)
+ verify(isFinite(layout.implicitWidth))
+ layout.destroy();
+ }
}
}