diff options
-rw-r--r-- | src/quick/items/qquickgridview.cpp | 10 | ||||
-rw-r--r-- | src/quick/items/qquickgridview_p.h | 19 | ||||
-rw-r--r-- | src/quick/items/qquickitemview.cpp | 6 | ||||
-rw-r--r-- | src/quick/items/qquickitemview_p.h | 12 | ||||
-rw-r--r-- | src/quick/items/qquickitemview_p_p.h | 2 | ||||
-rw-r--r-- | src/quick/items/qquicklistview.cpp | 15 | ||||
-rw-r--r-- | src/quick/items/qquicklistview_p.h | 16 | ||||
-rw-r--r-- | tests/auto/quick/qquickgridview/data/attachedProperties.qml | 74 | ||||
-rw-r--r-- | tests/auto/quick/qquickgridview/tst_qquickgridview.cpp | 31 | ||||
-rw-r--r-- | tests/auto/quick/qquicklistview/data/attachedProperties.qml | 82 | ||||
-rw-r--r-- | tests/auto/quick/qquicklistview/tst_qquicklistview.cpp | 35 |
11 files changed, 258 insertions, 44 deletions
diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp index 8587da5ac3..f97229a76a 100644 --- a/src/quick/items/qquickgridview.cpp +++ b/src/quick/items/qquickgridview.cpp @@ -65,8 +65,8 @@ QT_BEGIN_NAMESPACE class FxGridItemSG : public FxViewItem { public: - FxGridItemSG(QQuickItem *i, QQuickGridView *v, bool own) : FxViewItem(i, v, own), view(v) { - attached = static_cast<QQuickGridViewAttached*>(qmlAttachedPropertiesObject<QQuickGridView>(item)); + FxGridItemSG(QQuickItem *i, QQuickGridView *v, bool own) : FxViewItem(i, v, own, static_cast<QQuickItemViewAttached*>(qmlAttachedPropertiesObject<QQuickGridView>(i))), view(v) + { } qreal position() const { @@ -1283,7 +1283,8 @@ void QQuickGridView::setHighlightFollowsCurrentItem(bool autoHighlight) \qmlattachedproperty GridView QtQuick::GridView::view This attached property holds the view that manages this delegate instance. - It is attached to each instance of the delegate. + It is attached to each instance of the delegate and also to the header, the footer + and the highlight delegates. \snippet qml/gridview/gridview.qml isCurrentItem */ @@ -2127,6 +2128,9 @@ void QQuickGridView::geometryChanged(const QRectF &newGeometry, const QRectF &ol void QQuickGridView::initItem(int index, QObject *obj) { QQuickItemView::initItem(index, obj); + + // setting the view from the FxViewItem wrapper is too late if the delegate + // needs access to the view in Component.onCompleted QQuickItem *item = qmlobject_cast<QQuickItem*>(obj); if (item) { QQuickGridViewAttached *attached = static_cast<QQuickGridViewAttached *>( diff --git a/src/quick/items/qquickgridview_p.h b/src/quick/items/qquickgridview_p.h index 8f41f39919..ff0e2217fa 100644 --- a/src/quick/items/qquickgridview_p.h +++ b/src/quick/items/qquickgridview_p.h @@ -42,8 +42,6 @@ #ifndef QQUICKGRIDVIEW_P_H #define QQUICKGRIDVIEW_P_H -#include <QtCore/qpointer.h> - #include "qquickitemview_p.h" @@ -118,23 +116,8 @@ class QQuickGridViewAttached : public QQuickItemViewAttached Q_OBJECT public: QQuickGridViewAttached(QObject *parent) - : QQuickItemViewAttached(parent), m_view(0) {} + : QQuickItemViewAttached(parent) {} ~QQuickGridViewAttached() {} - - Q_PROPERTY(QQuickGridView *view READ view NOTIFY viewChanged) - QQuickGridView *view() { return m_view; } - void setView(QQuickGridView *view) { - if (view != m_view) { - m_view = view; - Q_EMIT viewChanged(); - } - } - -Q_SIGNALS: - void viewChanged(); - -public: - QPointer<QQuickGridView> m_view; }; diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index 30d0619f7a..020d48613b 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -51,15 +51,17 @@ QT_BEGIN_NAMESPACE #define QML_VIEW_DEFAULTCACHEBUFFER 320 #endif -FxViewItem::FxViewItem(QQuickItem *i, QQuickItemView *v, bool own) +FxViewItem::FxViewItem(QQuickItem *i, QQuickItemView *v, bool own, QQuickItemViewAttached *attached) : item(i) , view(v) , transitionableItem(0) - , attached(0) + , attached(attached) , ownItem(own) , releaseAfterTransition(false) , trackGeom(false) { + if (attached) // can be null for default components (see createComponentItem) + attached->setView(view); } FxViewItem::~FxViewItem() diff --git a/src/quick/items/qquickitemview_p.h b/src/quick/items/qquickitemview_p.h index ad026a3152..57635d7780 100644 --- a/src/quick/items/qquickitemview_p.h +++ b/src/quick/items/qquickitemview_p.h @@ -43,6 +43,7 @@ #define QQUICKITEMVIEW_P_H #include "qquickflickable_p.h" +#include <qpointer.h> QT_BEGIN_NAMESPACE @@ -282,6 +283,7 @@ class Q_AUTOTEST_EXPORT QQuickItemViewAttached : public QObject { Q_OBJECT + Q_PROPERTY(QQuickItemView *view READ view NOTIFY viewChanged) Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged) @@ -294,6 +296,14 @@ public: : QObject(parent), m_isCurrent(false), m_delayRemove(false) {} ~QQuickItemViewAttached() {} + QQuickItemView *view() { return m_view; } + void setView(QQuickItemView *view) { + if (view != m_view) { + m_view = view; + Q_EMIT viewChanged(); + } + } + bool isCurrentItem() const { return m_isCurrent; } void setIsCurrentItem(bool c) { if (m_isCurrent != c) { @@ -353,6 +363,7 @@ public: void emitRemove() { Q_EMIT remove(); } Q_SIGNALS: + void viewChanged(); void currentItemChanged(); void delayRemoveChanged(); @@ -364,6 +375,7 @@ Q_SIGNALS: void nextSectionChanged(); public: + QPointer<QQuickItemView> m_view; bool m_isCurrent : 1; bool m_delayRemove : 1; diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h index af7c23c02e..a0d17b3bf9 100644 --- a/src/quick/items/qquickitemview_p_p.h +++ b/src/quick/items/qquickitemview_p_p.h @@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE class FxViewItem { public: - FxViewItem(QQuickItem *, QQuickItemView *, bool own); + FxViewItem(QQuickItem *, QQuickItemView *, bool own, QQuickItemViewAttached *attached); virtual ~FxViewItem(); qreal itemX() const; diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 2dd61e386f..3ac28f438b 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -247,16 +247,14 @@ void QQuickViewSection::setLabelPositioning(int l) class FxListItemSG : public FxViewItem { public: - FxListItemSG(QQuickItem *i, QQuickListView *v, bool own) : FxViewItem(i, v, own), view(v) { - attached = static_cast<QQuickListViewAttached*>(qmlAttachedPropertiesObject<QQuickListView>(item)); + FxListItemSG(QQuickItem *i, QQuickListView *v, bool own) : FxViewItem(i, v, own, static_cast<QQuickItemViewAttached*>(qmlAttachedPropertiesObject<QQuickListView>(i))), view(v) + { } inline QQuickItem *section() const { return attached ? static_cast<QQuickListViewAttached*>(attached)->m_sectionItem : 0; } void setSection(QQuickItem *s) { - if (!attached) - attached = static_cast<QQuickListViewAttached*>(qmlAttachedPropertiesObject<QQuickListView>(item)); static_cast<QQuickListViewAttached*>(attached)->m_sectionItem = s; } @@ -972,6 +970,9 @@ QQuickItem * QQuickListViewPrivate::getSectionItem(const QString §ion) QQml_setParent_noEvent(sectionItem, contentItem); sectionItem->setParentItem(contentItem); } + // sections are not controlled by FxListItemSG, so apply attached properties here + QQuickItemViewAttached *attached = static_cast<QQuickItemViewAttached*>(qmlAttachedPropertiesObject<QQuickListView>(sectionItem)); + attached->setView(q); } else { delete context; } @@ -1787,7 +1788,8 @@ QQuickListView::~QQuickListView() \qmlattachedproperty ListView QtQuick::ListView::view This attached property holds the view that manages this delegate instance. - It is attached to each instance of the delegate. + It is attached to each instance of the delegate and also to the header, the footer, + the section and the highlight delegates. */ /*! @@ -2855,6 +2857,9 @@ void QQuickListView::geometryChanged(const QRectF &newGeometry, const QRectF &ol void QQuickListView::initItem(int index, QObject *object) { QQuickItemView::initItem(index, object); + + // setting the view from the FxViewItem wrapper is too late if the delegate + // needs access to the view in Component.onCompleted QQuickItem *item = qmlobject_cast<QQuickItem*>(object); if (item) { QQuickListViewAttached *attached = static_cast<QQuickListViewAttached *>( diff --git a/src/quick/items/qquicklistview_p.h b/src/quick/items/qquicklistview_p.h index b00501d274..2494e101cd 100644 --- a/src/quick/items/qquicklistview_p.h +++ b/src/quick/items/qquicklistview_p.h @@ -43,7 +43,6 @@ #define QQUICKLISTVIEW_P_H #include "qquickitemview_p.h" -#include <qpointer.h> QT_BEGIN_NAMESPACE @@ -175,23 +174,10 @@ class QQuickListViewAttached : public QQuickItemViewAttached public: QQuickListViewAttached(QObject *parent) - : QQuickItemViewAttached(parent), m_view(0), m_sectionItem(0) {} + : QQuickItemViewAttached(parent), m_sectionItem(0) {} ~QQuickListViewAttached() {} - Q_PROPERTY(QQuickListView *view READ view NOTIFY viewChanged) - QQuickListView *view() { return m_view; } - void setView(QQuickListView *view) { - if (view != m_view) { - m_view = view; - Q_EMIT viewChanged(); - } - } - -Q_SIGNALS: - void viewChanged(); - public: - QPointer<QQuickListView> m_view; QQuickItem *m_sectionItem; }; diff --git a/tests/auto/quick/qquickgridview/data/attachedProperties.qml b/tests/auto/quick/qquickgridview/data/attachedProperties.qml new file mode 100644 index 0000000000..5fbd2db716 --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/attachedProperties.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +GridView { + width: 100 + height: 100 + + Component.onCompleted: currentIndex = 0 + + model: ListModel { + ListElement { + name: "A" + } + ListElement { + name: "B" + } + } + + delegate: Text { + width: GridView.view.width + text: model.name + } + + header: Rectangle { + width: GridView.view.width + } + + footer: Rectangle { + width: GridView.view.width + } + + highlight: Rectangle { + width: GridView.view.width + } +} diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index 2ee98c6c61..f4eec18690 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -136,6 +136,7 @@ private slots: void onAdd_data(); void onRemove(); void onRemove_data(); + void attachedProperties_QTBUG_32836(); void columnCount(); void margins(); void creationContext(); @@ -4041,6 +4042,36 @@ void tst_QQuickGridView::onRemove_data() QTest::newRow("ten items, remove 4-10") << 10 << 4 << 6; } +void tst_QQuickGridView::attachedProperties_QTBUG_32836() +{ + QQuickView *window = createView(); + + window->setSource(testFileUrl("attachedProperties.qml")); + window->show(); + qApp->processEvents(); + + QQuickGridView *gridview = qobject_cast<QQuickGridView*>(window->rootObject()); + QVERIFY(gridview != 0); + + QQuickItem *header = gridview->headerItem(); + QVERIFY(header); + QCOMPARE(header->width(), gridview->width()); + + QQuickItem *footer = gridview->footerItem(); + QVERIFY(footer); + QCOMPARE(footer->width(), gridview->width()); + + QQuickItem *highlight = gridview->highlightItem(); + QVERIFY(highlight); + QCOMPARE(highlight->width(), gridview->width()); + + QQuickItem *currentItem = gridview->currentItem(); + QVERIFY(currentItem); + QCOMPARE(currentItem->width(), gridview->width()); + + delete window; +} + void tst_QQuickGridView::columnCount() { QQuickView window; diff --git a/tests/auto/quick/qquicklistview/data/attachedProperties.qml b/tests/auto/quick/qquicklistview/data/attachedProperties.qml new file mode 100644 index 0000000000..54b40a1032 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/attachedProperties.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +ListView { + width: 100 + height: 100 + + Component.onCompleted: currentIndex = 0 + + model: ListModel { + ListElement { + name: "A" + } + ListElement { + name: "B" + } + } + + delegate: Text { + width: ListView.view.width + text: model.name + } + + header: Rectangle { + width: ListView.view.width + } + + footer: Rectangle { + width: ListView.view.width + } + + highlight: Rectangle { + width: ListView.view.width + } + + section.property: "name" + section.criteria: ViewSection.FirstCharacter + section.delegate: Rectangle { + objectName: "sectionItem" + width: ListView.view.width + } + +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 7d0b76ad63..5651806a33 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -172,6 +172,7 @@ private slots: void onAdd_data(); void onRemove(); void onRemove_data(); + void attachedProperties_QTBUG_32836(); void rightToLeft(); void test_mirroring(); void margins(); @@ -5440,6 +5441,40 @@ void tst_QQuickListView::snapOneItem() releaseView(window); } +void tst_QQuickListView::attachedProperties_QTBUG_32836() +{ + QQuickView *window = createView(); + + window->setSource(testFileUrl("attachedProperties.qml")); + window->show(); + qApp->processEvents(); + + QQuickListView *listview = qobject_cast<QQuickListView*>(window->rootObject()); + QVERIFY(listview != 0); + + QQuickItem *header = listview->headerItem(); + QVERIFY(header); + QCOMPARE(header->width(), listview->width()); + + QQuickItem *footer = listview->footerItem(); + QVERIFY(footer); + QCOMPARE(footer->width(), listview->width()); + + QQuickItem *highlight = listview->highlightItem(); + QVERIFY(highlight); + QCOMPARE(highlight->width(), listview->width()); + + QQuickItem *currentItem = listview->currentItem(); + QVERIFY(currentItem); + QCOMPARE(currentItem->width(), listview->width()); + + QQuickItem *sectionItem = findItem<QQuickItem>(window->rootObject(), "sectionItem"); + QVERIFY(sectionItem); + QCOMPARE(sectionItem->width(), listview->width()); + + delete window; +} + void tst_QQuickListView::unrequestedVisibility() { QaimModel model; |