From d7630a80bdd52c2439d4f1c5c8fb4e8e8c0ed931 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 26 Jul 2011 16:47:09 +1000 Subject: [PATCH] Fix Column/Row size when no items being positioned Change-Id: I0bf55c13e55856dd7292e5eda159086096dea86b Reviewed-on: http://codereview.qt.nokia.com/2158 Reviewed-by: Qt Sanity Bot Reviewed-by: Michael Brasser --- src/declarative/items/qsgpositioners.cpp | 12 +++--- .../qsgpositioners/data/allInvisible.qml | 44 ++++++++++++++++++++++ .../qsgpositioners/tst_qsgpositioners.cpp | 19 ++++++++++ 3 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 tests/auto/declarative/qsgpositioners/data/allInvisible.qml diff --git a/src/declarative/items/qsgpositioners.cpp b/src/declarative/items/qsgpositioners.cpp index 3f6b24a..da3c7fe 100644 --- a/src/declarative/items/qsgpositioners.cpp +++ b/src/declarative/items/qsgpositioners.cpp @@ -211,7 +211,7 @@ void QSGBasePositioner::prePositioning() positionedItems.append(*item); } } - QSizeF contentSize; + QSizeF contentSize(0,0); doPositioning(&contentSize); if(d->addTransition || d->moveTransition) finishApplyTransitions(); @@ -288,10 +288,11 @@ void QSGColumn::doPositioning(QSizeF *contentSize) contentSize->setWidth(qMax(contentSize->width(), child.item->width())); voffset += child.item->height(); - voffset += spacing(); + if (ii != positionedItems.count() - 1) + voffset += spacing(); } - contentSize->setHeight(voffset - spacing()); + contentSize->setHeight(voffset); } void QSGColumn::reportConflictingAnchors() @@ -370,10 +371,11 @@ void QSGRow::doPositioning(QSizeF *contentSize) contentSize->setHeight(qMax(contentSize->height(), child.item->height())); hoffset += child.item->width(); - hoffset += spacing(); + if (ii != positionedItems.count() - 1) + hoffset += spacing(); } - contentSize->setWidth(hoffset - spacing()); + contentSize->setWidth(hoffset); if (d->isLeftToRight()) return; diff --git a/tests/auto/declarative/qsgpositioners/data/allInvisible.qml b/tests/auto/declarative/qsgpositioners/data/allInvisible.qml new file mode 100644 index 0000000..5894171 --- /dev/null +++ b/tests/auto/declarative/qsgpositioners/data/allInvisible.qml @@ -0,0 +1,44 @@ +import QtQuick 2.0 + +Item{ + width: 400 + height: 400 + Column{ + spacing: 20 + objectName: "column" + Item{ + width: 0 + height: 20 + visible: false + } + Item{ + width: 20 + height: 0 + visible: false + } + Item{ + width: 20 + height: 20 + visible: false + } + } + Row{ + spacing: 20 + objectName: "row" + Item{ + width: 0 + height: 20 + visible: false + } + Item{ + width: 20 + height: 0 + visible: false + } + Item{ + width: 20 + height: 20 + visible: false + } + } +} diff --git a/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp b/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp index 21b0ea1..a9bdf42 100644 --- a/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp +++ b/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp @@ -88,6 +88,7 @@ private slots: void test_flow_implicit_resize(); void test_conflictinganchors(); void test_mirroring(); + void test_allInvisible(); private: QSGView *createView(const QString &filename); }; @@ -1251,6 +1252,24 @@ void tst_qsgpositioners::test_mirroring() } } +void tst_qsgpositioners::test_allInvisible() +{ + //QTBUG-19361 + QSGView *canvas = createView(SRCDIR "/data/allInvisible.qml"); + + QSGItem *root = qobject_cast(canvas->rootObject()); + QVERIFY(root); + + QSGRow *row = canvas->rootObject()->findChild("row"); + QVERIFY(row != 0); + QVERIFY(row->width() == 0); + QVERIFY(row->height() == 0); + QSGColumn *column = canvas->rootObject()->findChild("column"); + QVERIFY(column != 0); + QVERIFY(column->width() == 0); + QVERIFY(column->height() == 0); +} + QSGView *tst_qsgpositioners::createView(const QString &filename) { QSGView *canvas = new QSGView(0); -- 2.7.4