From 05e492cf7ab30286087f579cefd9829da569f48f Mon Sep 17 00:00:00 2001 From: Jan Arve Saether <jan-arve.saether@digia.com> Date: Wed, 5 Jun 2013 13:48:27 +0200 Subject: [PATCH] Fixed a bug where a rearrange was not always done This happened only when the size of the layout didn't change. Task-number: QTBUG-31570 Change-Id: Ia090c0062fa8fc3eb6f648592529ee8fcd025593 Reviewed-by: J-P Nurmi <jpnurmi@digia.com> --- src/layouts/qquickgridlayoutengine_p.h | 10 ++++- src/layouts/qquicklayout_p.h | 3 +- tests/auto/controls/data/tst_rowlayout.qml | 45 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/layouts/qquickgridlayoutengine_p.h b/src/layouts/qquickgridlayoutengine_p.h index 29317ffbb..8842d36a7 100644 --- a/src/layouts/qquickgridlayoutengine_p.h +++ b/src/layouts/qquickgridlayoutengine_p.h @@ -112,8 +112,16 @@ public: void setGeometry(const QRectF &rect) { const QRect r(rect.toRect()); + const QSize newSize(r.size()); m_item->setPosition(r.topLeft()); - m_item->setSize(r.size()); + QSizeF oldSize(m_item->width(), m_item->height()); + if (newSize == oldSize) { + if (QQuickLayout *lay = qobject_cast<QQuickLayout *>(m_item)) + if (lay->arrangementIsDirty()) + lay->rearrange(newSize); + } else { + m_item->setSize(newSize); + } } QQuickItem *layoutItem() const { return m_item; } diff --git a/src/layouts/qquicklayout_p.h b/src/layouts/qquicklayout_p.h index 0239739a6..76c197173 100644 --- a/src/layouts/qquicklayout_p.h +++ b/src/layouts/qquicklayout_p.h @@ -77,9 +77,10 @@ public: void componentComplete(); virtual QSizeF sizeHint(Qt::SizeHint whichSizeHint) const = 0; virtual void invalidate(QQuickItem * childItem = 0); + virtual void rearrange(const QSizeF &); + bool arrangementIsDirty() const { return m_dirty; } protected: bool event(QEvent *e); - virtual void rearrange(const QSizeF &); enum Orientation { Vertical = 0, diff --git a/tests/auto/controls/data/tst_rowlayout.qml b/tests/auto/controls/data/tst_rowlayout.qml index e92dad47e..d04419f0f 100644 --- a/tests/auto/controls/data/tst_rowlayout.qml +++ b/tests/auto/controls/data/tst_rowlayout.qml @@ -658,5 +658,50 @@ Item { layout.visible = false layout.destroy() // Do not crash } + + + Component { + id: rearrangeNestedLayouts_Component + RowLayout { + id: layout + anchors.fill: parent + width: 200 + height: 20 + RowLayout { + id: row + spacing: 0 + + Rectangle { + id: fixed + color: 'red' + implicitWidth: 20 + implicitHeight: 20 + } + Rectangle { + id: filler + color: 'grey' + Layout.fillWidth: true + implicitHeight: 20 + } + } + } + } + + function test_rearrangeNestedLayouts() + { + var layout = rearrangeNestedLayouts_Component.createObject(container) + var fixed = layout.children[0].children[0] + var filler = layout.children[0].children[1] + + compare(itemRect(fixed), [0,0,20,20]) + compare(itemRect(filler), [20,0,180,20]) + + fixed.implicitWidth = 100 + wait(20); // wait for at least 20 ms (this matches the time between two frame + // repaints for 50hz displays) + compare(itemRect(fixed), [0,0,100,20]) + compare(itemRect(filler), [100,0,100,20]) + + } } } -- GitLab