diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-08-17 07:28:56 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-08-17 07:28:56 (GMT) |
commit | 87e9034caf90fb02ae2564947b9cbf464b3ca97c (patch) | |
tree | 10310b5918a8096a726122fc12dcb33b5f0d303e | |
parent | 50eefbaad10c217eeff5ac0d4b3581176e88e492 (diff) | |
parent | 59d2b0a0a1c836d3371c18a2a857d88c2d28621f (diff) | |
download | Qt-87e9034caf90fb02ae2564947b9cbf464b3ca97c.zip Qt-87e9034caf90fb02ae2564947b9cbf464b3ca97c.tar.gz Qt-87e9034caf90fb02ae2564947b9cbf464b3ca97c.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml:
Add missing file
Docs - clarify use of PropertyChanges for immediate property changes in
Update QtDeclarative def files
Update QtGui def files
Add missing auto test files.
Fix game could not be restarted
Handle QGraphicsWidgets in Flickable
More positioners with QGraphicsWidgets fixes.
Make positioners work with QGraphicsWidgets also
emit countChanged where appropriate in Repeater
22 files changed, 567 insertions, 199 deletions
diff --git a/demos/declarative/snake/content/snake.js b/demos/declarative/snake/content/snake.js index 0f0dbf7..fab7834 100644 --- a/demos/declarative/snake/content/snake.js +++ b/demos/declarative/snake/content/snake.js @@ -35,9 +35,12 @@ function startNewGame() if (heartbeat.running) { endGame(); startNewGameTimer.running = true; + state = "starting"; return; } + state = "starting"; + numRows = numRowsAvailable; numColumns = numColumnsAvailable; board = new Array(numRows * numColumns); @@ -80,7 +83,6 @@ function startNewGame() waitForCookie = 5; score = 0; startHeartbeatTimer.running = true; - heartbeat.running = true; } function endGame() @@ -94,6 +96,7 @@ function endGame() } lastScore = score; highScores.saveScore(lastScore); + state = ""; } function move() { diff --git a/demos/declarative/snake/snake.qml b/demos/declarative/snake/snake.qml index b1344af..ed3bac9 100644 --- a/demos/declarative/snake/snake.qml +++ b/demos/declarative/snake/snake.qml @@ -94,6 +94,7 @@ Rectangle { Timer { id: startHeartbeatTimer; interval: 1000 ; + onTriggered: { state = "running"; heartbeat.running = true; } } @@ -208,21 +209,6 @@ Rectangle { Keys.onUpPressed: if (state == "starting" || direction != 2) Logic.scheduleDirection(0); Keys.onDownPressed: if (state == "starting" || direction != 0) Logic.scheduleDirection(2); - Connections { - target: startHeartbeatTimer - onRunningChanged: { - if (startHeartbeatTimer.running) - screen.state = "starting"; - else - screen.state = "running" - } - } - Connections { - target: heartbeat - onRunningChanged: if (!heartbeat.running) screen.state = ""; - } - - states: [ State { name: "starting" diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc index 7416341..53a0c55 100644 --- a/doc/src/declarative/animation.qdoc +++ b/doc/src/declarative/animation.qdoc @@ -156,11 +156,13 @@ The \l {PropertyAnimation::}{to} property is also required to specify the new \section2 Standalone Animations Animations can also be created as ordinary QML objects that are not bound to -any particular objects and properties. An example: +any particular objects and properties. Here is an example, using a +PropertyAnimation object. The animation is explicitly started when the +\l Rectangle is clicked: \snippet doc/src/snippets/declarative/animation-standalone.qml 0 -A standalone animation is not running by default and must be started explicitly +A standalone animation object is not running by default and must be started explicitly using the \l {Animation::}{running} property or \l {Animation::}{start()} and \l {Animation::}{stop()} methods. Since the animation is not bound to a particular object or property, it must define the \l @@ -183,10 +185,13 @@ object and add it to an item's \l {Item::}{transitions} property. An example: \snippet doc/src/snippets/declarative/animation-transitions.qml 0 -When the \l Rectangle changes to the \e moved state, its \c x and \c y property -values are changed by the PropertyChanges object, and the PropertyAnimation -defined within the \l Transition is triggered on these properties. The -animation will not be applied at any time other than during the state change. +The PropertyChanges object in the \e moved state defines that when the +\l Rectangle is in this state, its position should be changed +to (50, 50). When the \l Rectangle changes to the \e moved state, the +\l Transition will be triggered, and the transition's \l PropertyAnimation will +animate the changes in the \c x and \c y properties to their new values. +The animation will not be applied at any time other than during the state +change. Notice the example does not set any \l {PropertyAnimation::}{from} and \l {PropertyAnimation::}{to} values for the PropertyAnimation. As a convenience, @@ -234,7 +239,7 @@ and rotation changes. A ColorAnimation allows color values for the \l {ColorAnimation::}{from} and \l {ColorAnimation::}{to} properties. The -following animates the rectangle's \l {Rectangle::color} property: +following animates the rectangle's \l {Rectangle::}{color} property: \snippet doc/src/snippets/declarative/animation-elements.qml color diff --git a/doc/src/snippets/declarative/propertyaction.qml b/doc/src/snippets/declarative/propertyaction.qml new file mode 100644 index 0000000..1a15469 --- /dev/null +++ b/doc/src/snippets/declarative/propertyaction.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import Qt 4.7 + +Row { + +//![transition] +Item { + width: 400; height: 400 + + Rectangle { + id: rect + width: 200; height: 100 + color: "red" + + states: State { + name: "rotated" + PropertyChanges { target: rect; rotation: 180; transformOrigin: Item.BottomRight } + } + + transitions: Transition { + RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise } + } + + MouseArea { + anchors.fill: parent + onClicked: rect.state = "rotated" + } + } +} +//![transition] + +Item { + width: 300; height: 300 + + Image { id: img; source: "pics/qt.png" } + +//![standalone] +SequentialAnimation { + PropertyAction { target: img; property: "smooth"; value: "true" } + NumberAnimation { target: img; property: "width"; to: 300; duration: 1000 } + PropertyAction { target: img; property: "smooth"; value: "false" } +} +//![standalone] +} + +} + diff --git a/doc/src/snippets/declarative/propertychanges.qml b/doc/src/snippets/declarative/propertychanges.qml new file mode 100644 index 0000000..9f119bf --- /dev/null +++ b/doc/src/snippets/declarative/propertychanges.qml @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +//![import] +import Qt 4.7 +//![import] + +Column { + +//![0] +Item { + id: container + width: 300; height: 300 + + Rectangle { + id: rect + width: 100; height: 100 + color: "red" + + MouseArea { + id: mouseArea + anchors.fill: parent + } + + states: State { + name: "resized"; when: mouseArea.pressed + PropertyChanges { target: rect; color: "blue"; height: container.height } + } + } +} +//![0] + +//![reset] +Rectangle { + width: 300; height: 200 + + Text { + id: myText + width: 50 + wrapMode: Text.WordWrap + text: "a text string that is longer than 50 pixels" + + states: State { + name: "widerText" + PropertyChanges { target: myText; width: undefined } + } + } + + MouseArea { + anchors.fill: parent + onClicked: myText.state = "widerText" + } +} +//![reset] +} diff --git a/doc/src/snippets/declarative/rotationanimation.qml b/doc/src/snippets/declarative/rotationanimation.qml index c81395a..b56cb3f 100644 --- a/doc/src/snippets/declarative/rotationanimation.qml +++ b/doc/src/snippets/declarative/rotationanimation.qml @@ -52,7 +52,8 @@ Item { smooth: true states: State { - name: "rotated"; PropertyChanges { target: rect; rotation: 180 } + name: "rotated" + PropertyChanges { target: rect; rotation: 180 } } transitions: Transition { diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 31f7707..7fee44e 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -1029,7 +1029,7 @@ void QDeclarativeFlickable::cancelFlick() void QDeclarativeFlickablePrivate::data_append(QDeclarativeListProperty<QObject> *prop, QObject *o) { - QDeclarativeItem *i = qobject_cast<QDeclarativeItem *>(o); + QGraphicsObject *i = qobject_cast<QGraphicsObject *>(o); if (i) i->setParentItem(static_cast<QDeclarativeFlickablePrivate*>(prop->data)->contentItem); else diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 5c21b03..4ceb5d9 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -61,16 +61,37 @@ static const QDeclarativeItemPrivate::ChangeTypes watchedChanges | QDeclarativeItemPrivate::Opacity | QDeclarativeItemPrivate::Destroyed; -void QDeclarativeBasePositionerPrivate::watchChanges(QDeclarativeItem *other) +void QDeclarativeBasePositionerPrivate::watchChanges(QGraphicsObject *other) { - QDeclarativeItemPrivate *otherPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(other)); - otherPrivate->addItemChangeListener(this, watchedChanges); + if (QGraphicsItemPrivate::get(other)->isDeclarativeItem) { + QDeclarativeItemPrivate *otherPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(other)); + otherPrivate->addItemChangeListener(this, watchedChanges); + } else { + Q_Q(QDeclarativeBasePositioner); + QObject::connect(other, SIGNAL(widthChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + QObject::connect(other, SIGNAL(heightChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + QObject::connect(other, SIGNAL(opacityChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + QObject::connect(other, SIGNAL(visibleChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + } } -void QDeclarativeBasePositionerPrivate::unwatchChanges(QDeclarativeItem* other) +void QDeclarativeBasePositionerPrivate::unwatchChanges(QGraphicsObject* other) { - QDeclarativeItemPrivate *otherPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(other)); - otherPrivate->removeItemChangeListener(this, watchedChanges); + if (QGraphicsItemPrivate::get(other)->isDeclarativeItem) { + QDeclarativeItemPrivate *otherPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(other)); + otherPrivate->removeItemChangeListener(this, watchedChanges); + } else { + Q_Q(QDeclarativeBasePositioner); + QObject::disconnect(other, SIGNAL(widthChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + QObject::disconnect(other, SIGNAL(heightChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + QObject::disconnect(other, SIGNAL(opacityChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + QObject::disconnect(other, SIGNAL(visibleChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + } +} + +void QDeclarativeBasePositioner::graphicsWidgetGeometryChanged() +{ + prePositioning(); } /*! @@ -174,16 +195,16 @@ QVariant QDeclarativeBasePositioner::itemChange(GraphicsItemChange change, Q_D(QDeclarativeBasePositioner); if (change == ItemChildAddedChange){ QGraphicsItem* item = value.value<QGraphicsItem*>(); - QDeclarativeItem* child = 0; + QGraphicsObject* child = 0; if(item) - child = qobject_cast<QDeclarativeItem*>(item->toGraphicsObject()); + child = item->toGraphicsObject(); if (child) prePositioning(); } else if (change == ItemChildRemovedChange) { QGraphicsItem* item = value.value<QGraphicsItem*>(); - QDeclarativeItem* child = 0; + QGraphicsObject* child = 0; if(item) - child = qobject_cast<QDeclarativeItem*>(item->toGraphicsObject()); + child = item->toGraphicsObject(); if (child) { QDeclarativeBasePositioner::PositionedItem posItem(child); int idx = positionedItems.find(posItem); @@ -194,7 +215,6 @@ QVariant QDeclarativeBasePositioner::itemChange(GraphicsItemChange change, prePositioning(); } } - return QDeclarativeItem::itemChange(change, value); } @@ -216,10 +236,10 @@ void QDeclarativeBasePositioner::prePositioning() QPODVector<PositionedItem,8> oldItems; positionedItems.copyAndClear(oldItems); for (int ii = 0; ii < children.count(); ++ii) { - QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(ii)); + QGraphicsObject *child = children.at(ii)->toGraphicsObject(); if (!child) continue; - QDeclarativeItemPrivate *childPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(child)); + QGraphicsItemPrivate *childPrivate = static_cast<QGraphicsItemPrivate*>(QGraphicsItemPrivate::get(child)); PositionedItem *item = 0; PositionedItem posItem(child); int wIdx = oldItems.find(posItem); @@ -302,10 +322,10 @@ void QDeclarativeBasePositioner::finishApplyTransitions() d->moveActions.clear(); } -static inline bool isInvisible(QDeclarativeItem *child) +static inline bool isInvisible(QGraphicsObject *child) { - QDeclarativeItemPrivate *childPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(child)); - return child->opacity() == 0.0 || childPrivate->explicitlyHidden || !child->width() || !child->height(); + QGraphicsItemPrivate *childPrivate = static_cast<QGraphicsItemPrivate*>(QGraphicsItemPrivate::get(child)); + return child->opacity() == 0.0 || childPrivate->explicitlyHidden || !childPrivate->width() || !childPrivate->height(); } /*! @@ -441,9 +461,9 @@ void QDeclarativeColumn::doPositioning(QSizeF *contentSize) if(child.item->y() != voffset) positionY(voffset, child); - contentSize->setWidth(qMax(contentSize->width(), child.item->width())); + contentSize->setWidth(qMax(contentSize->width(), QGraphicsItemPrivate::get(child.item)->width())); - voffset += child.item->height(); + voffset += QGraphicsItemPrivate::get(child.item)->height(); voffset += spacing(); } @@ -455,8 +475,8 @@ void QDeclarativeColumn::reportConflictingAnchors() QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this)); for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); - if (child.item) { - QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; + if (child.item && QGraphicsItemPrivate::get(child.item)->isDeclarativeItem) { + QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(static_cast<QDeclarativeItem *>(child.item))->_anchors; if (anchors) { QDeclarativeAnchors::Anchors usedAnchors = anchors->usedAnchors(); if (usedAnchors & QDeclarativeAnchors::TopAnchor || @@ -581,9 +601,9 @@ void QDeclarativeRow::doPositioning(QSizeF *contentSize) if(child.item->x() != hoffset) positionX(hoffset, child); - contentSize->setHeight(qMax(contentSize->height(), child.item->height())); + contentSize->setHeight(qMax(contentSize->height(), QGraphicsItemPrivate::get(child.item)->height())); - hoffset += child.item->width(); + hoffset += QGraphicsItemPrivate::get(child.item)->width(); hoffset += spacing(); } @@ -595,8 +615,8 @@ void QDeclarativeRow::reportConflictingAnchors() QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this)); for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); - if (child.item) { - QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; + if (child.item && QGraphicsItemPrivate::get(child.item)->isDeclarativeItem) { + QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(static_cast<QDeclarativeItem *>(child.item))->_anchors; if (anchors) { QDeclarativeAnchors::Anchors usedAnchors = anchors->usedAnchors(); if (usedAnchors & QDeclarativeAnchors::LeftAnchor || @@ -817,10 +837,11 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize) const PositionedItem &child = positionedItems.at(childIndex++); if (!child.item || isInvisible(child.item)) continue; - if (child.item->width() > maxColWidth[j]) - maxColWidth[j] = child.item->width(); - if (child.item->height() > maxRowHeight[i]) - maxRowHeight[i] = child.item->height(); + QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item); + if (childPrivate->width() > maxColWidth[j]) + maxColWidth[j] = childPrivate->width(); + if (childPrivate->height() > maxRowHeight[i]) + maxRowHeight[i] = childPrivate->height(); } } } else { @@ -836,10 +857,11 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize) const PositionedItem &child = positionedItems.at(childIndex++); if (!child.item || isInvisible(child.item)) continue; - if (child.item->width() > maxColWidth[j]) - maxColWidth[j] = child.item->width(); - if (child.item->height() > maxRowHeight[i]) - maxRowHeight[i] = child.item->height(); + QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item); + if (childPrivate->width() > maxColWidth[j]) + maxColWidth[j] = childPrivate->width(); + if (childPrivate->height() > maxRowHeight[i]) + maxRowHeight[i] = childPrivate->height(); } } } @@ -858,7 +880,7 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize) } if (m_flow == LeftToRight) { - contentSize->setWidth(qMax(contentSize->width(), xoffset + child.item->width())); + contentSize->setWidth(qMax(contentSize->width(), xoffset + QGraphicsItemPrivate::get(child.item)->width())); contentSize->setHeight(yoffset + maxRowHeight[curRow]); xoffset+=maxColWidth[curCol]+spacing(); @@ -872,7 +894,7 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize) break; } } else { - contentSize->setHeight(qMax(contentSize->height(), yoffset + child.item->height())); + contentSize->setHeight(qMax(contentSize->height(), yoffset + QGraphicsItemPrivate::get(child.item)->height())); contentSize->setWidth(xoffset + maxColWidth[curCol]); yoffset+=maxRowHeight[curRow]+spacing(); @@ -894,8 +916,8 @@ void QDeclarativeGrid::reportConflictingAnchors() QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this)); for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); - if (child.item) { - QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; + if (child.item && QGraphicsItemPrivate::get(child.item)->isDeclarativeItem) { + QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(static_cast<QDeclarativeItem *>(child.item))->_anchors; if (anchors && (anchors->usedAnchors() || anchors->fill() || anchors->centerIn())) { d->anchorConflict = true; break; @@ -1030,14 +1052,15 @@ void QDeclarativeFlow::doPositioning(QSizeF *contentSize) if (!child.item || isInvisible(child.item)) continue; + QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child.item); if (d->flow == LeftToRight) { - if (widthValid() && hoffset && hoffset + child.item->width() > width()) { + if (widthValid() && hoffset && hoffset + childPrivate->width() > width()) { hoffset = 0; voffset += linemax + spacing(); linemax = 0; } } else { - if (heightValid() && voffset && voffset + child.item->height() > height()) { + if (heightValid() && voffset && voffset + childPrivate->height() > height()) { voffset = 0; hoffset += linemax + spacing(); linemax = 0; @@ -1049,17 +1072,17 @@ void QDeclarativeFlow::doPositioning(QSizeF *contentSize) positionY(voffset, child); } - contentSize->setWidth(qMax(contentSize->width(), hoffset + child.item->width())); - contentSize->setHeight(qMax(contentSize->height(), voffset + child.item->height())); + contentSize->setWidth(qMax(contentSize->width(), hoffset + childPrivate->width())); + contentSize->setHeight(qMax(contentSize->height(), voffset + childPrivate->height())); if (d->flow == LeftToRight) { - hoffset += child.item->width(); + hoffset += childPrivate->width(); hoffset += spacing(); - linemax = qMax(linemax, qCeil(child.item->height())); + linemax = qMax(linemax, qCeil(childPrivate->height())); } else { - voffset += child.item->height(); + voffset += childPrivate->height(); voffset += spacing(); - linemax = qMax(linemax, qCeil(child.item->width())); + linemax = qMax(linemax, qCeil(childPrivate->width())); } } } @@ -1069,8 +1092,8 @@ void QDeclarativeFlow::reportConflictingAnchors() Q_D(QDeclarativeFlow); for (int ii = 0; ii < positionedItems.count(); ++ii) { const PositionedItem &child = positionedItems.at(ii); - if (child.item) { - QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors; + if (child.item && QGraphicsItemPrivate::get(child.item)->isDeclarativeItem) { + QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(static_cast<QDeclarativeItem *>(child.item))->_anchors; if (anchors && (anchors->usedAnchors() || anchors->fill() || anchors->centerIn())) { d->anchorConflict = true; break; diff --git a/src/declarative/graphicsitems/qdeclarativepositioners_p.h b/src/declarative/graphicsitems/qdeclarativepositioners_p.h index c03e518..f9ecc0a 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners_p.h +++ b/src/declarative/graphicsitems/qdeclarativepositioners_p.h @@ -91,14 +91,16 @@ Q_SIGNALS: protected Q_SLOTS: void prePositioning(); + void graphicsWidgetGeometryChanged(); protected: virtual void doPositioning(QSizeF *contentSize)=0; virtual void reportConflictingAnchors()=0; - struct PositionedItem { - PositionedItem(QDeclarativeItem *i) : item(i), isNew(false), isVisible(true) {} + class PositionedItem { + public : + PositionedItem(QGraphicsObject *i) : item(i), isNew(false), isVisible(true) {} bool operator==(const PositionedItem &other) const { return other.item == item; } - QDeclarativeItem *item; + QGraphicsObject *item; bool isNew; bool isVisible; }; diff --git a/src/declarative/graphicsitems/qdeclarativepositioners_p_p.h b/src/declarative/graphicsitems/qdeclarativepositioners_p_p.h index 822079b..35946e9 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativepositioners_p_p.h @@ -94,8 +94,8 @@ public: QDeclarativeTransitionManager addTransitionManager; QDeclarativeTransitionManager moveTransitionManager; - void watchChanges(QDeclarativeItem *other); - void unwatchChanges(QDeclarativeItem* other); + void watchChanges(QGraphicsObject *other); + void unwatchChanges(QGraphicsObject* other); bool queuedPositioning : 1; bool doingPositioning : 1; bool anchorConflict : 1; @@ -123,6 +123,7 @@ public: if (newGeometry.size() != oldGeometry.size()) q->prePositioning(); } + virtual void itemVisibilityChanged(QDeclarativeItem *) { schedulePositioning(); diff --git a/src/declarative/graphicsitems/qdeclarativerepeater.cpp b/src/declarative/graphicsitems/qdeclarativerepeater.cpp index 8828d3e..4a951a2 100644 --- a/src/declarative/graphicsitems/qdeclarativerepeater.cpp +++ b/src/declarative/graphicsitems/qdeclarativerepeater.cpp @@ -246,8 +246,8 @@ void QDeclarativeRepeater::setModel(const QVariant &model) connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); */ regenerate(); - emit countChanged(); } + emit countChanged(); } /*! @@ -378,6 +378,7 @@ void QDeclarativeRepeater::itemsInserted(int index, int count) d->deletables.insert(modelIndex, item); } } + emit countChanged(); } void QDeclarativeRepeater::itemsRemoved(int index, int count) @@ -392,6 +393,7 @@ void QDeclarativeRepeater::itemsRemoved(int index, int count) else break; } + emit countChanged(); } void QDeclarativeRepeater::itemsMoved(int from, int to, int count) @@ -421,6 +423,7 @@ void QDeclarativeRepeater::modelReset() if (!isComponentComplete()) return; regenerate(); + emit countChanged(); } QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 3b8cb37..4e9e8d5 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -694,9 +694,12 @@ QDeclarativeColorAnimation::~QDeclarativeColorAnimation() } \endqml - If this value is not set and the ColorAnimation is defined within - a \l Transition, it defaults to the value defined in the starting - state of the \l Transition. + If the ColorAnimation is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the starting state of the + \l Transition, or the current value of the property at the moment the + \l Behavior is triggered. + + \sa {QML Animation} */ QColor QDeclarativeColorAnimation::from() const { @@ -714,9 +717,12 @@ void QDeclarativeColorAnimation::setFrom(const QColor &f) This property holds the color value at which the animation should end. - If this value is not set and the ColorAnimation is defined within - a \l Transition or \l Behavior, it defaults to the value defined in the end - state of the \l Transition or \l Behavior. + If the ColorAnimation is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the end state of the + \l Transition, or the value of the property change that triggered the + \l Behavior. + + \sa {QML Animation} */ QColor QDeclarativeColorAnimation::to() const { @@ -887,29 +893,45 @@ QAbstractAnimation *QDeclarativeScriptAction::qtAnimation() \inherits Animation \brief The PropertyAction element allows immediate property changes during animation. - PropertyAction is used to specify an immediate property change - during an animation. The property change is not animated. + PropertyAction is used to specify an immediate property change during an + animation. The property change is not animated. - For example, to explicitly set \c {theImage.smooth = true} during a \l Transition: - \code - transitions: Transition { - ... - PropertyAction { target: theImage; property: "smooth"; value: true } - ... - } - \endcode + It is useful for setting non-animated property values during an animation. - Or, to set \c theWebView.url to the value set for the destination state: - \code + For example, here is a SequentialAnimation that sets the image's + \l {Image::}{smooth} property to \c true, animates the width of the image, + then sets \l {Image::}{smooth} back to \c false: + + \snippet doc/src/snippets/declarative/propertyaction.qml standalone + + PropertyAction is also useful for setting the exact point at which a property + change should occur during a \l Transition. For example, if PropertyChanges + was used in a \l State to rotate an item around a particular + \l {Item::}{transformOrigin}, it might be implemented like this: + + \snippet doc/src/snippets/declarative/propertyaction.qml transition + + However, with this code, the \c transformOrigin is not set until \e after + the animation, as a \l State is taken to define the values at the \e end of + a transition. The animation would rotate at the default \c transformOrigin, + then jump to \c Item.BottomRight. To fix this, insert a PropertyChanges + before the RotationAnimation begins: + + \qml transitions: Transition { - ... - PropertyAction { target: theWebView; property: "url" } - ... + SequentialAnimation { + PropertyAction { target: rect; property: "transformOrigin" } + RotationAnimation { ... } + } } - \endcode - + \endqml + + This immediately sets the \c transformOrigin property to the value defined + in the end state of the \l Transition (i.e. the value defined in the + PropertyChanges object) so that the rotation animation begins with the + correct transform origin. - \sa QtDeclarative + \sa {QML Animation}, QtDeclarative */ /*! \internal @@ -1014,7 +1036,11 @@ QDeclarativeListProperty<QObject> QDeclarativePropertyAction::exclude() /*! \qmlproperty any PropertyAction::value This property holds the value to be set on the property. - If not set, then the value defined for the end state of the transition. + + If the PropertyAction is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the end state of the + \l Transition, or the value of the property change that triggered the + \l Behavior. */ QVariant QDeclarativePropertyAction::value() const { @@ -1190,7 +1216,7 @@ void QDeclarativeNumberAnimation::init() /*! \qmlproperty real NumberAnimation::from - This property holds the starting number value. + This property holds the starting value for the animation. For example, the following animation is not applied until the \c x value has reached 100: @@ -1205,9 +1231,12 @@ void QDeclarativeNumberAnimation::init() } \endqml - If this value is not set and the NumberAnimation is defined within - a \l Transition, it defaults to the value defined in the start - state of the \l Transition. + If the NumberAnimation is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the starting state of the + \l Transition, or the current value of the property at the moment the + \l Behavior is triggered. + + \sa {QML Animation} */ qreal QDeclarativeNumberAnimation::from() const @@ -1223,11 +1252,14 @@ void QDeclarativeNumberAnimation::setFrom(qreal f) /*! \qmlproperty real NumberAnimation::to - This property holds the ending number value. + This property holds the end value for the animation. - If this value is not set and the NumberAnimation is defined within - a \l Transition or \l Behavior, it defaults to the value defined in the end - state of the \l Transition or \l Behavior. + If the NumberAnimation is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the end state of the + \l Transition, or the value of the property change that triggered the + \l Behavior. + + \sa {QML Animation} */ qreal QDeclarativeNumberAnimation::to() const { @@ -1280,10 +1312,14 @@ QDeclarativeVector3dAnimation::~QDeclarativeVector3dAnimation() /*! \qmlproperty real Vector3dAnimation::from - This property holds the starting value. + This property holds the starting value for the animation. + + If the Vector3dAnimation is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the starting state of the + \l Transition, or the current value of the property at the moment the + \l Behavior is triggered. - If this value is not set, it defaults to the value defined in the start - state of the \l Transition. + \sa {QML Animation} */ QVector3D QDeclarativeVector3dAnimation::from() const { @@ -1298,10 +1334,14 @@ void QDeclarativeVector3dAnimation::setFrom(QVector3D f) /*! \qmlproperty real Vector3dAnimation::to - This property holds the ending value. + This property holds the end value for the animation. - If this value is not set, it defaults to the value defined in the end - state of the \l Transition or \l Behavior. + If the Vector3dAnimation is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the end state of the + \l Transition, or the value of the property change that triggered the + \l Behavior. + + \sa {QML Animation} */ QVector3D QDeclarativeVector3dAnimation::to() const { @@ -1343,6 +1383,12 @@ void QDeclarativeVector3dAnimation::setTo(QVector3D t) your own properties via \l {PropertyAnimation::properties}{properties} or \l {PropertyAnimation::property}{property}. + Also, note the \l Rectangle will be rotated around its default + \l {Item::}{transformOrigin} (which is \c Item.Center). To use a different + transform origin, set the origin in the PropertyChanges object and apply + the change at the start of the animation using PropertyAction. See the + PropertyAction documentation for more details. + Like any other animation element, a RotationAnimation can be applied in a number of ways, including transitions, behaviors and property value sources. The \l {QML Animation} documentation shows a variety of methods @@ -1408,7 +1454,7 @@ QDeclarativeRotationAnimation::~QDeclarativeRotationAnimation() /*! \qmlproperty real RotationAnimation::from - This property holds the starting number value. + This property holds the starting value for the animation. For example, the following animation is not applied until the \c angle value has reached 100: @@ -1423,8 +1469,12 @@ QDeclarativeRotationAnimation::~QDeclarativeRotationAnimation() } \endqml - If this value is not set, it defaults to the value defined in the start - state of the \l Transition. + If the RotationAnimation is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the starting state of the + \l Transition, or the current value of the property at the moment the + \l Behavior is triggered. + + \sa {QML Animation} */ qreal QDeclarativeRotationAnimation::from() const { @@ -1439,10 +1489,14 @@ void QDeclarativeRotationAnimation::setFrom(qreal f) /*! \qmlproperty real RotationAnimation::to - This property holds the ending value. + This property holds the end value for the animation.. + + If the RotationAnimation is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the end state of the + \l Transition, or the value of the property change that triggered the + \l Behavior. - If this value is not set, it defaults to the value defined in the end - state of the \l Transition or \l Behavior. + \sa {QML Animation} */ qreal QDeclarativeRotationAnimation::to() const { @@ -1854,8 +1908,14 @@ void QDeclarativePropertyAnimation::setDuration(int duration) /*! \qmlproperty real PropertyAnimation::from - This property holds the starting value. - If not set, then the value defined in the start state of the transition. + This property holds the starting value for the animation. + + If the PropertyAnimation is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the starting state of the + \l Transition, or the current value of the property at the moment the + \l Behavior is triggered. + + \sa {QML Animation} */ QVariant QDeclarativePropertyAnimation::from() const { @@ -1875,8 +1935,14 @@ void QDeclarativePropertyAnimation::setFrom(const QVariant &f) /*! \qmlproperty real PropertyAnimation::to - This property holds the ending value. - If not set, then the value defined in the end state of the transition or \l Behavior. + This property holds the end value for the animation. + + If the PropertyAnimation is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the end state of the + \l Transition, or the value of the property change that triggered the + \l Behavior. + + \sa {QML Animation} */ QVariant QDeclarativePropertyAnimation::to() const { @@ -2502,7 +2568,10 @@ void QDeclarativeParentAnimation::setTarget(QDeclarativeItem *target) \qmlproperty Item ParentAnimation::newParent The new parent to animate to. - If not set, then the parent defined in the end state of the transition. + If the ParentAnimation is defined within a \l Transition or \l Behavior, + this value defaults to the value defined in the end state of the + \l Transition, or the value of the property change that triggered the + \l Behavior. */ QDeclarativeItem *QDeclarativeParentAnimation::newParent() const { diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp index 25edd35..c28ada3 100644 --- a/src/declarative/util/qdeclarativepropertychanges.cpp +++ b/src/declarative/util/qdeclarativepropertychanges.cpp @@ -65,48 +65,30 @@ QT_BEGIN_NAMESPACE \since 4.7 \brief The PropertyChanges element describes new property bindings or values for a state. - PropertyChanges provides a state change that modifies the properties of an item. + PropertyChanges is used to define the property values or bindings in a + \l State. This enables an item's property values to be changed when it + \l {QML States}{changes between states}. - Here is a property change that modifies the text and color of a \l Text element - when it is clicked: + To create a PropertyChanges object, specify the \l target item whose + properties are to be modified, and define the new property values or + bindings. For example: - \qml - Text { - id: myText - width: 100; height: 100 - text: "Hello" - color: "blue" - - states: State { - name: "myState" - - PropertyChanges { - target: myText - text: "Goodbye" - color: "red" - } - } - - MouseArea { anchors.fill: parent; onClicked: myText.state = 'myState' } - } - \endqml - - By default, PropertyChanges will establish new bindings where appropriate. - For example, the following creates a new binding for myItem's \c height property. - - \qml - PropertyChanges { - target: myItem - height: parent.height - } - \endqml - - If you don't want a binding to be established (and instead just want to assign - the value of the binding at the time the state is entered), - you should set the PropertyChange's \l{PropertyChanges::explicit}{explicit} + \snippet doc/src/snippets/declarative/propertychanges.qml import + \codeline + \snippet doc/src/snippets/declarative/propertychanges.qml 0 + + When the mouse is pressed, the \l Rectangle changes to the \e resized + state. In this state, the PropertyChanges object sets the rectangle's + color to blue and the \c height value to that of \c container.height. + + Note this automatically binds \c rect.height to \c container.height + in the \e resized state. If a property binding should not be + established, and the height should just be set to the value of + \c container.height at the time of the state change, set the \l explicit property to \c true. - - State-specific script for signal handlers can also be specified: + + A PropertyChanges object can also override the default signal handler + for an object to implement a signal handler specific to the new state: \qml PropertyChanges { @@ -115,36 +97,31 @@ QT_BEGIN_NAMESPACE } \endqml - You can reset a property in a state change by assigning \c undefined. In the following - example we reset \c theText's width when we enter state1. This will give the text its - natural width (which is the whole string on one line). + \note PropertyChanges can be used to change anchor margins, but not other anchor + values; use AnchorChanges for this instead. Similarly, to change an \l Item's + \l {Item::}{parent} value, use ParentChanges instead. - \qml - import Qt 4.7 - - Rectangle { - width: 640 - height: 480 - Text { - id: theText - width: 50 - wrapMode: Text.WordWrap - text: "a text string that is longer than 50 pixels" - } - states: State { - name: "state1" - PropertyChanges { - target: theText - width: undefined - } - } - } - \endqml + \section2 Resetting property values - Anchor margins should be changed with PropertyChanges, but other anchor changes or changes to - an Item's parent should be done using the associated change elements - (ParentChange and AnchorChanges, respectively). + The \c undefined value can be used to reset the property value for a state. + In the following example, when \c theText changes to the \e widerText + state, its \c width property is reset, giving the text its natural width + and displaying the whole string on a single line. + + \snippet doc/src/snippets/declarative/propertychanges.qml reset + + + \section2 Immediate property changes in transitions + + When \l Transitions are used to animate state changes, they animate + properties from their values in the current state to those defined in the + new state (as defined by PropertyChanges objects). However, + it is sometimes desirable to set a property value \e immediately during a + \l Transition, without animation; in these cases, the PropertyAction + element can be used to force an immediate property change. + + See the PropertyAction documentation for more details. \sa {declarative/animation/states}{states example}, {qmlstate}{States}, QtDeclarative */ @@ -397,12 +374,12 @@ void QDeclarativePropertyChanges::setObject(QObject *o) /*! \qmlproperty bool PropertyChanges::restoreEntryValues - - Whether or not the previous values should be restored when - leaving the state. By default, restoreEntryValues is true. - By setting restoreEntryValues to false, you can create a temporary state - that has permanent effects on property values. + This property holds whether the previous values should be restored when + leaving the state. + + The default value is \c true. Setting this value to \c false creates a + temporary state that has permanent effects on property values. */ bool QDeclarativePropertyChanges::restoreEntryValues() const { diff --git a/src/s60installs/bwins/QtDeclarativeu.def b/src/s60installs/bwins/QtDeclarativeu.def index 480d9ff..bc6d0aa 100644 --- a/src/s60installs/bwins/QtDeclarativeu.def +++ b/src/s60installs/bwins/QtDeclarativeu.def @@ -1684,4 +1684,5 @@ EXPORTS ?rootContext@QDeclarativeView@@QBEPAVQDeclarativeContext@@XZ @ 1683 NONAME ; class QDeclarativeContext * QDeclarativeView::rootContext(void) const ?rootContext@QDeclarativeEngine@@QBEPAVQDeclarativeContext@@XZ @ 1684 NONAME ; class QDeclarativeContext * QDeclarativeEngine::rootContext(void) const ?qmlregister@QDeclarativePrivate@@YAHW4RegistrationType@1@PAX@Z @ 1685 NONAME ; int QDeclarativePrivate::qmlregister(enum QDeclarativePrivate::RegistrationType, void *) + ?hasValue@QDeclarativeOpenMetaObject@@QBE_NH@Z @ 1686 NONAME ; bool QDeclarativeOpenMetaObject::hasValue(int) const diff --git a/src/s60installs/bwins/QtGuiu.def b/src/s60installs/bwins/QtGuiu.def index 90c0878..21a2122 100644 --- a/src/s60installs/bwins/QtGuiu.def +++ b/src/s60installs/bwins/QtGuiu.def @@ -4148,7 +4148,7 @@ EXPORTS ?ensureSceneTransformRecursive@QGraphicsItemPrivate@@QAEXPAPAVQGraphicsItem@@@Z @ 4147 NONAME ; void QGraphicsItemPrivate::ensureSceneTransformRecursive(class QGraphicsItem * *) ?ensureSequentialSiblingIndex@QGraphicsItemPrivate@@QAEXXZ @ 4148 NONAME ; void QGraphicsItemPrivate::ensureSequentialSiblingIndex(void) ?ensureSortedChildren@QGraphicsItemPrivate@@QAEXXZ @ 4149 NONAME ; void QGraphicsItemPrivate::ensureSortedChildren(void) - ?ensureSpace@QTextEngine@@QBEXH@Z @ 4150 NONAME ; void QTextEngine::ensureSpace(int) const + ?ensureSpace@QTextEngine@@QBEXH@Z @ 4150 NONAME ABSENT ; void QTextEngine::ensureSpace(int) const ?ensureVisible@QGraphicsItem@@QAEXABVQRectF@@HH@Z @ 4151 NONAME ; void QGraphicsItem::ensureVisible(class QRectF const &, int, int) ?ensureVisible@QGraphicsItem@@QAEXMMMMHH@Z @ 4152 NONAME ; void QGraphicsItem::ensureVisible(float, float, float, float, int, int) ?ensureVisible@QGraphicsView@@QAEXABVQRectF@@HH@Z @ 4153 NONAME ; void QGraphicsView::ensureVisible(class QRectF const &, int, int) @@ -12886,4 +12886,6 @@ EXPORTS ?zScaleChanged@QGraphicsScale@@IAEXXZ @ 12885 NONAME ; void QGraphicsScale::zScaleChanged(void) ?xScaleChanged@QGraphicsScale@@IAEXXZ @ 12886 NONAME ; void QGraphicsScale::xScaleChanged(void) ?yScaleChanged@QGraphicsScale@@IAEXXZ @ 12887 NONAME ; void QGraphicsScale::yScaleChanged(void) + ?_q_aboutToQuit@QApplicationPrivate@@QAEXXZ @ 12888 NONAME ; void QApplicationPrivate::_q_aboutToQuit(void) + ?ensureSpace@QTextEngine@@QBE_NH@Z @ 12889 NONAME ; bool QTextEngine::ensureSpace(int) const diff --git a/src/s60installs/eabi/QtDeclarativeu.def b/src/s60installs/eabi/QtDeclarativeu.def index 9a3cefa..723f2ae 100644 --- a/src/s60installs/eabi/QtDeclarativeu.def +++ b/src/s60installs/eabi/QtDeclarativeu.def @@ -1714,4 +1714,5 @@ EXPORTS _ZNK16QDeclarativeView6engineEv @ 1713 NONAME _ZNK18QDeclarativeEngine11rootContextEv @ 1714 NONAME _ZN19QDeclarativePrivate11qmlregisterENS_16RegistrationTypeEPv @ 1715 NONAME + _ZNK26QDeclarativeOpenMetaObject8hasValueEi @ 1716 NONAME diff --git a/src/s60installs/eabi/QtGuiu.def b/src/s60installs/eabi/QtGuiu.def index d8e86bf..c4ad848 100644 --- a/src/s60installs/eabi/QtGuiu.def +++ b/src/s60installs/eabi/QtGuiu.def @@ -12091,4 +12091,5 @@ EXPORTS _ZN14QGraphicsScale13xScaleChangedEv @ 12090 NONAME _ZN14QGraphicsScale13yScaleChangedEv @ 12091 NONAME _ZN14QGraphicsScale13zScaleChangedEv @ 12092 NONAME + _ZN19QApplicationPrivate14_q_aboutToQuitEv @ 12093 NONAME diff --git a/tests/auto/declarative/qdeclarativeflickable/data/flickableqgraphicswidget.qml b/tests/auto/declarative/qdeclarativeflickable/data/flickableqgraphicswidget.qml new file mode 100644 index 0000000..8e95a94 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeflickable/data/flickableqgraphicswidget.qml @@ -0,0 +1,7 @@ +import Qt 4.7 + +Flickable { + width: 100; height: 100 + + QGraphicsWidget { objectName: "widget1"; width: 200; height: 300 } +} diff --git a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp index 678996b..e7ded8a 100644 --- a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp +++ b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp @@ -44,6 +44,7 @@ #include <QtDeclarative/qdeclarativecomponent.h> #include <private/qdeclarativeflickable_p.h> #include <private/qdeclarativevaluetype_p.h> +#include <QtGui/qgraphicswidget.h> #include <math.h> #ifdef Q_OS_SYMBIAN @@ -67,9 +68,13 @@ private slots: void flickDeceleration(); void pressDelay(); void flickableDirection(); + void qgraphicswidget(); private: QDeclarativeEngine engine; + + template<typename T> + T *findItem(QGraphicsObject *parent, const QString &objectName); }; tst_qdeclarativeflickable::tst_qdeclarativeflickable() @@ -261,6 +266,38 @@ void tst_qdeclarativeflickable::flickableDirection() QCOMPARE(spy.count(),3); } +void tst_qdeclarativeflickable::qgraphicswidget() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/flickableqgraphicswidget.qml")); + QDeclarativeFlickable *flickable = qobject_cast<QDeclarativeFlickable*>(c.create()); + + QVERIFY(flickable != 0); + QGraphicsWidget *widget = findItem<QGraphicsWidget>(flickable->contentItem(), "widget1"); + QVERIFY(widget); +} + +template<typename T> +T *tst_qdeclarativeflickable::findItem(QGraphicsObject *parent, const QString &objectName) +{ + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->childItems().count() << "children"; + for (int i = 0; i < parent->childItems().count(); ++i) { + QGraphicsObject *item = qobject_cast<QGraphicsObject*>(parent->childItems().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { + return static_cast<T*>(item); + } + item = findItem<T>(item, objectName); + if (item) + return static_cast<T*>(item); + } + + return 0; +} + QTEST_MAIN(tst_qdeclarativeflickable) #include "tst_qdeclarativeflickable.moc" diff --git a/tests/auto/declarative/qdeclarativepositioners/data/verticalqgraphicswidget.qml b/tests/auto/declarative/qdeclarativepositioners/data/verticalqgraphicswidget.qml new file mode 100644 index 0000000..c9c8607 --- /dev/null +++ b/tests/auto/declarative/qdeclarativepositioners/data/verticalqgraphicswidget.qml @@ -0,0 +1,24 @@ +import Qt 4.7 + +Item { + width: 640 + height: 480 + Column { + objectName: "column" + QGraphicsWidget { + objectName: "one" + width: 50 + height: 50 + } + QGraphicsWidget { + objectName: "two" + width: 20 + height: 10 + } + QGraphicsWidget { + objectName: "three" + width: 40 + height: 20 + } + } +} diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp index 0663991..887be50 100644 --- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp +++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp @@ -46,6 +46,7 @@ #include <private/qdeclarativepositioners_p.h> #include <private/qdeclarativetransition_p.h> #include <qdeclarativeexpression.h> +#include <QtGui/qgraphicswidget.h> #include "../../../shared/util.h" #ifdef Q_OS_SYMBIAN @@ -77,6 +78,7 @@ private slots: void test_flow_resize(); void test_flow_implicit_resize(); void test_conflictinganchors(); + void test_vertical_qgraphicswidget(); private: QDeclarativeView *createView(const QString &filename); }; @@ -771,6 +773,48 @@ void tst_QDeclarativePositioners::test_conflictinganchors() QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow")); } +void tst_QDeclarativePositioners::test_vertical_qgraphicswidget() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/verticalqgraphicswidget.qml"); + + QGraphicsWidget *one = canvas->rootObject()->findChild<QGraphicsWidget*>("one"); + QVERIFY(one != 0); + + QGraphicsWidget *two = canvas->rootObject()->findChild<QGraphicsWidget*>("two"); + QVERIFY(two != 0); + + QGraphicsWidget *three = canvas->rootObject()->findChild<QGraphicsWidget*>("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 60.0); + + QDeclarativeItem *column = canvas->rootObject()->findChild<QDeclarativeItem*>("column"); + QVERIFY(column); + QCOMPARE(column->height(), 80.0); + QCOMPARE(column->width(), 50.0); + + two->resize(QSizeF(two->size().width(), 20.0)); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 70.0); + + two->setOpacity(0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 50.0); + + one->setVisible(false); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 0.0); + + delete canvas; +} + QDeclarativeView *tst_QDeclarativePositioners::createView(const QString &filename) { QDeclarativeView *canvas = new QDeclarativeView(0); diff --git a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp index 623b3d7..360d90f 100644 --- a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp +++ b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp @@ -309,11 +309,14 @@ void tst_QDeclarativeRepeater::dataModel() QCOMPARE(container->childItems().count(), 4); + QSignalSpy repeaterSpy(repeater, SIGNAL(countChanged())); testModel.addItem("four", "4"); QCOMPARE(container->childItems().count(), 5); + QCOMPARE(repeaterSpy.count(),1); testModel.removeItem(2); QCOMPARE(container->childItems().count(), 4); + QCOMPARE(repeaterSpy.count(),2); // Check that model changes are propagated QDeclarativeText *text = findItem<QDeclarativeText>(canvas->rootObject(), "myName", 1); |