diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-08-26 01:44:03 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-08-26 01:44:03 (GMT) |
commit | 8bedba8ecb9cde3de68defea3e2b062504224aa6 (patch) | |
tree | 1cf7327df58f27869efae499f5a92a2786fa876d | |
parent | 407e131dfc2f85518e42be6ca7a2b43946d0413c (diff) | |
download | Qt-8bedba8ecb9cde3de68defea3e2b062504224aa6.zip Qt-8bedba8ecb9cde3de68defea3e2b062504224aa6.tar.gz Qt-8bedba8ecb9cde3de68defea3e2b062504224aa6.tar.bz2 |
Fix ListView.view attached property with VisualItemModel
We assumed that the attached object was created at the same time as
the item.
Task-number: QTBUG-13166
Reviewed-by: Aaron Kennedy
6 files changed, 26 insertions, 9 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index d67e69a..37beab5 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -64,7 +64,7 @@ public: FxGridItem(QDeclarativeItem *i, QDeclarativeGridView *v) : item(i), view(v) { attached = static_cast<QDeclarativeGridViewAttached*>(qmlAttachedPropertiesObject<QDeclarativeGridView>(item)); if (attached) - attached->m_view = view; + attached->setView(view); } ~FxGridItem() {} diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index d6bbaf3..fdb6f94 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -43,6 +43,7 @@ #define QDECLARATIVEGRIDVIEW_H #include "private/qdeclarativeflickable_p.h" +#include "private/qdeclarativeguard_p.h" QT_BEGIN_HEADER @@ -220,8 +221,14 @@ public: : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {} ~QDeclarativeGridViewAttached() {} - Q_PROPERTY(QDeclarativeGridView *view READ view CONSTANT) + Q_PROPERTY(QDeclarativeGridView *view READ view WRITE setView NOTIFY viewChanged) QDeclarativeGridView *view() { return m_view; } + void setView(QDeclarativeGridView *view) { + if (view != m_view) { + m_view = view; + emit viewChanged(); + } + } Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) bool isCurrentItem() const { return m_isCurrent; } @@ -249,9 +256,10 @@ Q_SIGNALS: void delayRemoveChanged(); void add(); void remove(); + void viewChanged(); public: - QDeclarativeGridView *m_view; + QDeclarativeGuard<QDeclarativeGridView> m_view; bool m_isCurrent : 1; bool m_delayRemove : 1; }; diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 2e2e08c..f80c73a 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -96,7 +96,7 @@ public: FxListItem(QDeclarativeItem *i, QDeclarativeListView *v) : item(i), section(0), view(v) { attached = static_cast<QDeclarativeListViewAttached*>(qmlAttachedPropertiesObject<QDeclarativeListView>(item)); if (attached) - attached->m_view = view; + attached->setView(view); } ~FxListItem() {} qreal position() const { diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index b264861..14925d7 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -43,6 +43,7 @@ #define QDECLARATIVELISTVIEW_H #include "private/qdeclarativeflickable_p.h" +#include "private/qdeclarativeguard_p.h" QT_BEGIN_HEADER @@ -268,8 +269,14 @@ public: : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {} ~QDeclarativeListViewAttached() {} - Q_PROPERTY(QDeclarativeListView *view READ view CONSTANT) + Q_PROPERTY(QDeclarativeListView *view READ view WRITE setView NOTIFY viewChanged) QDeclarativeListView *view() { return m_view; } + void setView(QDeclarativeListView *view) { + if (view != m_view) { + m_view = view; + emit viewChanged(); + } + } Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) bool isCurrentItem() const { return m_isCurrent; } @@ -327,9 +334,10 @@ Q_SIGNALS: void delayRemoveChanged(); void add(); void remove(); + void viewChanged(); public: - QDeclarativeListView *m_view; + QDeclarativeGuard<QDeclarativeListView> m_view; mutable QString m_section; QString m_prevSection; QString m_nextSection; diff --git a/tests/auto/declarative/qdeclarativelistview/data/itemlist.qml b/tests/auto/declarative/qdeclarativelistview/data/itemlist.qml index 66728d6..9ea5953 100644 --- a/tests/auto/declarative/qdeclarativelistview/data/itemlist.qml +++ b/tests/auto/declarative/qdeclarativelistview/data/itemlist.qml @@ -13,17 +13,17 @@ Rectangle { objectName: "itemModel" Rectangle { objectName: "item1" - height: view.height; width: view.width; color: "#FFFEF0" + height: ListView.view.height; width: view.width; color: "#FFFEF0" Text { objectName: "text1"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent } } Rectangle { objectName: "item2" - height: view.height; width: view.width; color: "#F0FFF7" + height: ListView.view.height; width: view.width; color: "#F0FFF7" Text { objectName: "text2"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent } } Rectangle { objectName: "item3" - height: view.height; width: view.width; color: "#F4F0FF" + height: ListView.view.height; width: view.width; color: "#F4F0FF" Text { objectName: "text3"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent } } } diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 9c24e03..491ac0f 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -1066,6 +1066,7 @@ void tst_QDeclarativeListView::itemList() QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "item1"); QTRY_VERIFY(item); QTRY_COMPARE(item->x(), 0.0); + QCOMPARE(item->height(), listview->height()); QDeclarativeText *text = findItem<QDeclarativeText>(contentItem, "text1"); QTRY_VERIFY(text); |