From b7702b2dcbc36f81759dea0ad74fb19e97b2358f Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 3 Aug 2010 15:31:58 +1000 Subject: Ensure dataChanged doesn't force request for unwanted data in QML views. If a model emits dataChanged() every role was be updated, rather than just the roles required. Now only roles which have been used are updated. Task-number: QTBUG-12598 Reviewed-by: Michael Brasser --- .../graphicsitems/qdeclarativevisualitemmodel.cpp | 15 ++++++++++----- src/declarative/util/qdeclarativeopenmetaobject.cpp | 12 ++++++++++++ src/declarative/util/qdeclarativeopenmetaobject_p.h | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 79c1c43..ceb1961 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -444,6 +444,9 @@ public: int propForRole(int) const; void setValue(int, const QVariant &); + bool hasValue(int id) const { + return m_meta->hasValue(id); + } void ensureProperties(); @@ -1216,11 +1219,13 @@ void QDeclarativeVisualDataModel::_q_itemsChanged(int index, int count, int role = roles.at(roleIdx); int propId = data->propForRole(role); if (propId != -1) { - if (d->m_listModelInterface) { - data->setValue(propId, d->m_listModelInterface->data(idx, QList() << role).value(role)); - } else if (d->m_abstractItemModel) { - QModelIndex index = d->m_abstractItemModel->index(idx, 0, d->m_root); - data->setValue(propId, d->m_abstractItemModel->data(index, role)); + if (data->hasValue(propId)) { + if (d->m_listModelInterface) { + data->setValue(propId, d->m_listModelInterface->data(idx, QList() << role).value(role)); + } else if (d->m_abstractItemModel) { + QModelIndex index = d->m_abstractItemModel->index(idx, 0, d->m_root); + data->setValue(propId, d->m_abstractItemModel->data(index, role)); + } } } else { QString roleName; diff --git a/src/declarative/util/qdeclarativeopenmetaobject.cpp b/src/declarative/util/qdeclarativeopenmetaobject.cpp index ba5d534..40485bd 100644 --- a/src/declarative/util/qdeclarativeopenmetaobject.cpp +++ b/src/declarative/util/qdeclarativeopenmetaobject.cpp @@ -161,6 +161,12 @@ public: prop.second = true; } + inline bool hasData(int idx) const { + if (idx >= data.count()) + return false; + return data[idx].second; + } + bool autoCreate; QDeclarativeOpenMetaObject *q; QAbstractDynamicMetaObject *parent; @@ -295,6 +301,12 @@ void QDeclarativeOpenMetaObject::setValue(const QByteArray &name, const QVariant activate(d->object, id + d->type->d->signalOffset, 0); } +// returns true if this value has been initialized by a call to either value() or setValue() +bool QDeclarativeOpenMetaObject::hasValue(int id) const +{ + return d->hasData(id); +} + void QDeclarativeOpenMetaObject::setCached(bool c) { if (c == d->cacheProperties || !d->type->d->engine) diff --git a/src/declarative/util/qdeclarativeopenmetaobject_p.h b/src/declarative/util/qdeclarativeopenmetaobject_p.h index 9bb4c34..c18fa3d 100644 --- a/src/declarative/util/qdeclarativeopenmetaobject_p.h +++ b/src/declarative/util/qdeclarativeopenmetaobject_p.h @@ -91,6 +91,7 @@ public: void setValue(int, const QVariant &); QVariant &operator[](const QByteArray &); QVariant &operator[](int); + bool hasValue(int) const; int count() const; QByteArray name(int) const; -- cgit v0.12 From a0b531163a79c9097185b580fdf4aa8157cead41 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 3 Aug 2010 15:43:48 +1000 Subject: Fix Flickable.StopAtBounds behavior when content size < flickable size Clip the content position to the beginning rather than the end, if both apply. Task-number: QTBUG-12573 Reviewed-by: Michael Brasser --- .../graphicsitems/qdeclarativeflickable.cpp | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 998b33a..19cabdd 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -681,12 +681,15 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent if (newY < maxY && maxY - minY <= 0) newY = maxY + (newY - maxY) / 2; if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && (newY > minY || newY < maxY)) { - if (newY > minY) - newY = minY; - else if (newY < maxY) + rejectY = true; + if (newY < maxY) { newY = maxY; - else - rejectY = true; + rejectY = false; + } + if (newY > minY) { + newY = minY; + rejectY = false; + } } if (!rejectY && stealMouse) { vData.move.setValue(qRound(newY)); @@ -708,12 +711,15 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent if (newX < maxX && maxX - minX <= 0) newX = maxX + (newX - maxX) / 2; if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && (newX > minX || newX < maxX)) { - if (newX > minX) - newX = minX; - else if (newX < maxX) + rejectX = true; + if (newX < maxX) { newX = maxX; - else - rejectX = true; + rejectX = false; + } + if (newX > minX) { + newX = minX; + rejectX = false; + } } if (!rejectX && stealMouse) { hData.move.setValue(qRound(newX)); -- cgit v0.12 From b5c6f77bf0a84e7411d64d6f486ffcbd79ad9494 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Aug 2010 16:30:53 +1000 Subject: Fix photo positioning bug in flickr demo. Task-number: QTBUG-3669 --- demos/declarative/flickr/flickr.qml | 22 ++-- demos/declarative/flickr/mobile/GridDelegate.qml | 130 +++++++++++------------ demos/declarative/flickr/mobile/ImageDetails.qml | 22 ++-- 3 files changed, 87 insertions(+), 87 deletions(-) diff --git a/demos/declarative/flickr/flickr.qml b/demos/declarative/flickr/flickr.qml index 48db476..152f9f9 100644 --- a/demos/declarative/flickr/flickr.qml +++ b/demos/declarative/flickr/flickr.qml @@ -57,21 +57,20 @@ Item { Item { id: views - x: 2; width: parent.width - 4 + width: parent.width anchors.top: titleBar.bottom; anchors.bottom: toolBar.top - Mobile.GridDelegate { id: gridDelegate } GridView { - x: (width/4-79)/2; y: x - id: photoGridView; model: rssModel; delegate: gridDelegate; cacheBuffer: 100 - cellWidth: (parent.width-2)/4; cellHeight: cellWidth; width: parent.width; height: parent.height - 1; z: 6 + id: photoGridView; model: rssModel; delegate: Mobile.GridDelegate {} + cacheBuffer: 100 + cellWidth: (parent.width-2)/4; cellHeight: cellWidth; width: parent.width; height: parent.height } - Mobile.ListDelegate { id: listDelegate } ListView { - id: photoListView; model: rssModel; delegate: listDelegate; z: 6 + id: photoListView; model: rssModel; delegate: Mobile.ListDelegate { } width: parent.width; height: parent.height; x: -(parent.width * 1.5); cacheBuffer: 100; } + states: State { name: "ListView"; when: screen.inListView == true PropertyChanges { target: photoListView; x: 0 } @@ -81,13 +80,16 @@ Item { transitions: Transition { NumberAnimation { properties: "x"; duration: 500; easing.type: Easing.InOutQuad } } + + Mobile.ImageDetails { id: imageDetails; width: parent.width; anchors.left: views.right; height: parent.height } + + Item { id: foreground; anchors.fill: parent } } - Mobile.ImageDetails { id: imageDetails; width: parent.width; anchors.left: views.right; height: parent.height; z:1 } - Mobile.TitleBar { id: titleBar; z: 5; width: parent.width; height: 40; opacity: 0.9 } + Mobile.TitleBar { id: titleBar; width: parent.width; height: 40; opacity: 0.9 } Mobile.ToolBar { - id: toolBar; z: 5 + id: toolBar height: 40; anchors.bottom: parent.bottom; width: parent.width; opacity: 0.9 button1Label: "Update"; button2Label: "View mode" onButton1Clicked: rssModel.reload() diff --git a/demos/declarative/flickr/mobile/GridDelegate.qml b/demos/declarative/flickr/mobile/GridDelegate.qml index cbb00a2..c368e95 100644 --- a/demos/declarative/flickr/mobile/GridDelegate.qml +++ b/demos/declarative/flickr/mobile/GridDelegate.qml @@ -39,75 +39,73 @@ ** ****************************************************************************/ - import Qt 4.7 +import Qt 4.7 - Component { - id: photoDelegate - Item { - id: wrapper; width: 79; height: 79 +Item { + id: wrapper; width: GridView.view.cellWidth; height: GridView.view.cellHeight - function photoClicked() { - imageDetails.photoTitle = title; - imageDetails.photoTags = tags; - imageDetails.photoWidth = photoWidth; - imageDetails.photoHeight = photoHeight; - imageDetails.photoType = photoType; - imageDetails.photoAuthor = photoAuthor; - imageDetails.photoDate = photoDate; - imageDetails.photoUrl = url; - imageDetails.rating = 0; - scaleMe.state = "Details"; - } + function photoClicked() { + imageDetails.photoTitle = title; + imageDetails.photoTags = tags; + imageDetails.photoWidth = photoWidth; + imageDetails.photoHeight = photoHeight; + imageDetails.photoType = photoType; + imageDetails.photoAuthor = photoAuthor; + imageDetails.photoDate = photoDate; + imageDetails.photoUrl = url; + imageDetails.rating = 0; + scaleMe.state = "Details"; + } - Item { - anchors.centerIn: parent - scale: 0.0 - Behavior on scale { NumberAnimation { easing.type: Easing.InOutQuad} } - id: scaleMe + Item { + anchors.centerIn: parent + scale: 0.0 + Behavior on scale { NumberAnimation { easing.type: Easing.InOutQuad} } + id: scaleMe - Rectangle { height: 79; width: 79; id: blackRect; anchors.centerIn: parent; color: "black"; smooth: true } - Rectangle { - id: whiteRect; width: 77; height: 77; anchors.centerIn: parent; color: "#dddddd"; smooth: true - Image { id: thumb; source: imagePath; x: 1; y: 1; smooth: true} - Image { source: "images/gloss.png" } - } + Item { + width: 77; height: 77; anchors.centerIn: parent + Rectangle { + id: whiteRect; width: 77; height: 77; color: "#dddddd"; smooth: true + Image { id: thumb; source: imagePath; x: 1; y: 1; smooth: true } + Image { source: "images/gloss.png" } + } + } - Connections { - target: toolBar - onButton2Clicked: if (scaleMe.state == 'Details' ) scaleMe.state = 'Show' - } + Connections { + target: toolBar + onButton2Clicked: if (scaleMe.state == 'Details' ) scaleMe.state = 'Show' + } + + states: [ + State { + name: "Show"; when: thumb.status == Image.Ready + PropertyChanges { target: scaleMe; scale: 1 } + }, + State { + name: "Details" + PropertyChanges { target: scaleMe; scale: 1 } + ParentChange { target: whiteRect; x: 10; y: 20; parent: imageDetails.frontContainer } + PropertyChanges { target: background; state: "DetailedView" } + } + ] + transitions: [ + Transition { + from: "Show"; to: "Details" + ParentAnimation { + via: foreground + NumberAnimation { properties: "x,y"; duration: 500; easing.type: Easing.InOutQuad } + } + }, + Transition { + from: "Details"; to: "Show" + ParentAnimation { + via: foreground + NumberAnimation { properties: "x,y"; duration: 500; easing.type: Easing.InOutQuad } + } + } + ] + } + MouseArea { anchors.fill: wrapper; onClicked: photoClicked() } +} - states: [ - State { - name: "Show"; when: thumb.status == Image.Ready - PropertyChanges { target: scaleMe; scale: 1 } - }, - State { - name: "Details" - PropertyChanges { target: scaleMe; scale: 1 } - ParentChange { target: wrapper; parent: imageDetails.frontContainer } - PropertyChanges { target: wrapper; x: 20; y: 60; z: 1000 } - PropertyChanges { target: background; state: "DetailedView" } - } - ] - transitions: [ - Transition { - from: "Show"; to: "Details" - ParentAnimation { - NumberAnimation { properties: "x,y"; duration: 500; easing.type: Easing.InOutQuad } - } - }, - Transition { - from: "Details"; to: "Show" - SequentialAnimation { - ParentAnimation { - NumberAnimation { properties: "x,y"; duration: 500; easing.type: Easing.InOutQuad } - } - PropertyAction { targets: wrapper; properties: "z" } - } - } - ] - } - MouseArea { anchors.fill: wrapper; onClicked: { photoClicked() } } - } - } diff --git a/demos/declarative/flickr/mobile/ImageDetails.qml b/demos/declarative/flickr/mobile/ImageDetails.qml index b1a7359..ff902ce 100644 --- a/demos/declarative/flickr/mobile/ImageDetails.qml +++ b/demos/declarative/flickr/mobile/ImageDetails.qml @@ -45,7 +45,7 @@ import "../common" as Common Flipable { id: container - property variant frontContainer: containerFront + property alias frontContainer: containerFront property string photoTitle: "" property string photoTags: "" property int photoWidth @@ -76,17 +76,17 @@ Flipable { Column { spacing: 10 anchors { - left: parent.left; leftMargin: 20 - right: parent.right; rightMargin: 20 - top: parent.top; topMargin: 180 + left: parent.left; leftMargin: 10 + right: parent.right; rightMargin: 10 + top: parent.top; topMargin: 120 } - Text { font.bold: true; color: "white"; elide: Text.ElideRight; text: container.photoTitle } - Text { color: "white"; elide: Text.ElideRight; text: "Size: " + container.photoWidth + 'x' + container.photoHeight } - Text { color: "white"; elide: Text.ElideRight; text: "Type: " + container.photoType } - Text { color: "white"; elide: Text.ElideRight; text: "Author: " + container.photoAuthor } - Text { color: "white"; elide: Text.ElideRight; text: "Published: " + container.photoDate } - Text { color: "white"; elide: Text.ElideRight; text: container.photoTags == "" ? "" : "Tags: " } - Text { color: "white"; elide: Text.ElideRight; text: container.photoTags } + Text { font.bold: true; color: "white"; elide: Text.ElideRight; text: container.photoTitle; width: parent.width } + Text { color: "white"; elide: Text.ElideRight; text: "Size: " + container.photoWidth + 'x' + container.photoHeight; width: parent.width } + Text { color: "white"; elide: Text.ElideRight; text: "Type: " + container.photoType; width: parent.width } + Text { color: "white"; elide: Text.ElideRight; text: "Author: " + container.photoAuthor; width: parent.width } + Text { color: "white"; elide: Text.ElideRight; text: "Published: " + container.photoDate; width: parent.width } + Text { color: "white"; elide: Text.ElideRight; text: container.photoTags == "" ? "" : "Tags: "; width: parent.width } + Text { color: "white"; elide: Text.ElideRight; text: container.photoTags; width: parent.width } } } -- cgit v0.12