diff options
author | Jan Arve Saether <jan-arve.saether@digia.com> | 2013-08-07 10:25:04 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-14 22:28:20 +0200 |
commit | 62802a6c60c89ca972f435a925434f2cbc793b48 (patch) | |
tree | 2a3bb58fa78f60e0065d36f22d40ae833e1f9866 | |
parent | a3fd33005769ed61b24bd9e979bf81bea6639963 (diff) | |
download | qtquickcontrols-62802a6c60c89ca972f435a925434f2cbc793b48.tar.gz |
GridLayout did not evaluate Layout.{row,column} changes on its items
Only the initial Layout.row and Layout.column values were
respected - any further changes were ignored.
Task-number: QTBUG-32767
Change-Id: I018800665e64158e8b38762fc29a5d3025776ff0
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-rw-r--r-- | src/layouts/qquicklayout.cpp | 16 | ||||
-rw-r--r-- | src/layouts/qquicklayout_p.h | 8 | ||||
-rw-r--r-- | src/layouts/qquicklinearlayout_p.h | 2 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_gridlayout.qml | 62 |
4 files changed, 83 insertions, 5 deletions
diff --git a/src/layouts/qquicklayout.cpp b/src/layouts/qquicklayout.cpp index 25991d36..dc3941b8 100644 --- a/src/layouts/qquicklayout.cpp +++ b/src/layouts/qquicklayout.cpp @@ -374,8 +374,11 @@ void QQuickLayoutAttached::setFillHeight(bool fill) */ void QQuickLayoutAttached::setRow(int row) { - if (row >= 0 && row != m_row) + if (row >= 0 && row != m_row) { m_row = row; + repopulateLayout(); + emit rowChanged(); + } } /*! @@ -392,8 +395,11 @@ void QQuickLayoutAttached::setRow(int row) */ void QQuickLayoutAttached::setColumn(int column) { - if (column >= 0 && column != m_column) + if (column >= 0 && column != m_column) { m_column = column; + repopulateLayout(); + emit columnChanged(); + } } @@ -453,6 +459,12 @@ void QQuickLayoutAttached::invalidateItem() } } +void QQuickLayoutAttached::repopulateLayout() +{ + if (QQuickLayout *layout = parentLayout()) + layout->updateLayoutItems(); +} + QQuickLayout *QQuickLayoutAttached::parentLayout() const { QQuickItem *parentItem = item(); diff --git a/src/layouts/qquicklayout_p.h b/src/layouts/qquicklayout_p.h index 357f9c98..7e1e5b05 100644 --- a/src/layouts/qquicklayout_p.h +++ b/src/layouts/qquicklayout_p.h @@ -77,6 +77,7 @@ public: void componentComplete(); virtual QSizeF sizeHint(Qt::SizeHint whichSizeHint) const = 0; virtual void invalidate(QQuickItem * childItem = 0); + virtual void updateLayoutItems() = 0; virtual void rearrange(const QSizeF &); bool arrangementIsDirty() const { return m_dirty; } protected: @@ -114,8 +115,8 @@ class QQuickLayoutAttached : public QObject Q_PROPERTY(qreal maximumHeight READ maximumHeight WRITE setMaximumHeight NOTIFY maximumHeightChanged) Q_PROPERTY(bool fillHeight READ fillHeight WRITE setFillHeight) Q_PROPERTY(bool fillWidth READ fillWidth WRITE setFillWidth) - Q_PROPERTY(int row READ row WRITE setRow) - Q_PROPERTY(int column READ column WRITE setColumn) + Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged) + Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged) Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan) Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan) Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) @@ -201,9 +202,12 @@ signals: void maximumHeightChanged(); void fillWidthChanged(); void fillHeightChanged(); + void rowChanged(); + void columnChanged(); private: void invalidateItem(); + void repopulateLayout(); QQuickLayout *parentLayout() const; QQuickItem *item() const; private: diff --git a/src/layouts/qquicklinearlayout_p.h b/src/layouts/qquicklinearlayout_p.h index 827767b3..beea6b9d 100644 --- a/src/layouts/qquicklinearlayout_p.h +++ b/src/layouts/qquicklinearlayout_p.h @@ -77,7 +77,7 @@ public: Qt::LayoutDirection effectiveLayoutDirection() const; protected: - void updateLayoutItems(); + void updateLayoutItems() Q_DECL_OVERRIDE; void rearrange(const QSizeF &size); virtual void insertLayoutItems() = 0; void removeLayoutItem(QQuickItem *item); diff --git a/tests/auto/controls/data/tst_gridlayout.qml b/tests/auto/controls/data/tst_gridlayout.qml index 7a8a55a4..1bdfacc4 100644 --- a/tests/auto/controls/data/tst_gridlayout.qml +++ b/tests/auto/controls/data/tst_gridlayout.qml @@ -648,5 +648,67 @@ Item { compare(itemRect(layout.children[3]), [10, 25, 10, 10]) } + Component { + id: layout_columnOrRowChanged_Component + GridLayout { + id: layout + rowSpacing: 0 + columnSpacing: 0 + Rectangle { + width: 10 + height: 10 + Layout.column: 0 + color: "#ff0000" + } + Rectangle { + Layout.column: 1 + width: 10 + height: 10 + color: "#ff0000" + } + Rectangle { + //Layout.column: 2 + width: 10 + height: 10 + color: "#ff0000" + } + } + } + + function test_columnOrRowChanged() + { + var layout = layout_columnOrRowChanged_Component.createObject(container); + layout.width = layout.implicitWidth + layout.height = layout.implicitHeight + waitForRendering(layout) + // c0-c1-c2 + compare(itemRect(layout.children[0]), [ 0, 0, 10, 10]) + compare(itemRect(layout.children[1]), [10, 0, 10, 10]) + compare(itemRect(layout.children[2]), [20, 0, 10, 10]) + + layout.children[0].Layout.column = 3 + waitForRendering(layout) + //c1-c2-c0 + compare(itemRect(layout.children[0]), [20, 0, 10, 10]) + compare(itemRect(layout.children[1]), [ 0, 0, 10, 10]) + compare(itemRect(layout.children[2]), [10, 0, 10, 10]) + + layout.children[2].Layout.column = 4 + waitForRendering(layout) + //c1-c0-c2 + compare(itemRect(layout.children[0]), [10, 0, 10, 10]) + compare(itemRect(layout.children[1]), [ 0, 0, 10, 10]) + compare(itemRect(layout.children[2]), [20, 0, 10, 10]) + + layout.children[0].Layout.row = 1 + // two rows, so we adjust it to its new implicitHeight + layout.height = layout.implicitHeight + waitForRendering(layout) + //c1 c2 + // c0 + compare(itemRect(layout.children[0]), [10, 10, 10, 10]) + compare(itemRect(layout.children[1]), [ 0, 0, 10, 10]) + compare(itemRect(layout.children[2]), [20, 0, 10, 10]) + } } } |