diff options
author | Martin Smith <martin.smith@nokia.com> | 2010-07-22 11:27:57 (GMT) |
---|---|---|
committer | Martin Smith <martin.smith@nokia.com> | 2010-07-22 11:27:57 (GMT) |
commit | cf1f76661613313615a77479687fa93a3c97efc9 (patch) | |
tree | 978b8d1117224773952d1d2782d7825920bfc6ed /src/declarative | |
parent | d8908922f339892fee4275a433e2bf6da87ae055 (diff) | |
parent | be227b0a01bb28f3ebebedc1aaa65cd8098edd81 (diff) | |
download | Qt-cf1f76661613313615a77479687fa93a3c97efc9.zip Qt-cf1f76661613313615a77479687fa93a3c97efc9.tar.gz Qt-cf1f76661613313615a77479687fa93a3c97efc9.tar.bz2 |
Merge branch '4.7' of git@scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7
Diffstat (limited to 'src/declarative')
29 files changed, 788 insertions, 500 deletions
diff --git a/src/declarative/debugger/qdeclarativedebugtrace.cpp b/src/declarative/debugger/qdeclarativedebugtrace.cpp index 5e6d5e7..b2b0c8a 100644 --- a/src/declarative/debugger/qdeclarativedebugtrace.cpp +++ b/src/declarative/debugger/qdeclarativedebugtrace.cpp @@ -78,6 +78,9 @@ void QDeclarativeDebugTrace::endRange(RangeType t) void QDeclarativeDebugTrace::addEventImpl(EventType event) { + if (!isEnabled()) + return; + QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); ds << m_timer.elapsed() << (int)Event << (int)event; @@ -86,6 +89,9 @@ void QDeclarativeDebugTrace::addEventImpl(EventType event) void QDeclarativeDebugTrace::startRangeImpl(RangeType range) { + if (!isEnabled()) + return; + QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); ds << m_timer.elapsed() << (int)RangeStart << (int)range; @@ -94,6 +100,9 @@ void QDeclarativeDebugTrace::startRangeImpl(RangeType range) void QDeclarativeDebugTrace::rangeDataImpl(RangeType range, const QUrl &u) { + if (!isEnabled()) + return; + QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); ds << m_timer.elapsed() << (int)RangeData << (int)range << (QString)u.toString(); @@ -102,6 +111,9 @@ void QDeclarativeDebugTrace::rangeDataImpl(RangeType range, const QUrl &u) void QDeclarativeDebugTrace::endRangeImpl(RangeType range) { + if (!isEnabled()) + return; + QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); ds << m_timer.elapsed() << (int)RangeEnd << (int)range; diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp index 44c206b..4881248 100644 --- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp @@ -149,6 +149,8 @@ QDeclarativeBorderImage::~QDeclarativeBorderImage() \endqml The URL may be absolute, or relative to the URL of the component. + + \sa QDeclarativeImageProvider */ void QDeclarativeBorderImage::setSource(const QUrl &url) { diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index dce6f0e..14a4f08 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -2438,8 +2438,11 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count) if (removedVisible && d->visibleItems.isEmpty()) { d->timeline.clear(); d->setPosition(0); - if (d->itemCount == 0) + if (d->itemCount == 0) { + d->updateHeader(); + d->updateFooter(); update(); + } } emit countChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 34d33f5..37736cc 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE \endqml \endtable - If the \l {Image::width}{width} and \l{Image::height}{height} properties are not specified, + If the \l {Item::width}{width} and \l{Item::height}{height} properties are not specified, the Image element is automatically sized to the loaded image. Image elements can be stretched and tiled using the \l fillMode property. @@ -324,17 +324,34 @@ qreal QDeclarativeImage::paintedHeight() const /*! \qmlproperty QSize Image::sourceSize - This property holds the size of the loaded image, in pixels. + This property holds the actual width and height of the loaded image. - This is used to control the storage used by a loaded image. Unlike - the width and height properties, which scale the painting of the image, this property - affects the number of pixels stored. + Unlike the \l {Item::}{width} and \l {Item::}{height} properties, which scale + the painting of the image, this property sets the actual number of pixels + stored for the loaded image so that large images do not use more + memory than necessary. For example, this ensures the image is memory is no + larger than 1024x1024 pixels, regardless of the Image's \l {Item::}{width} and + \l {Item::}{height} values: + + \code + Rectangle { + width: ... + height: ... + + Image { + anchors.fill: parent + source: "reallyBigImage.jpg" + sourceSize.width: 1024 + sourceSize.height: 1024 + } + } + \endcode If the image's actual size is larger than the sourceSize, the image is scaled down. If only one dimension of the size is set to greater than 0, the other dimension is set in proportion to preserve the source image's aspect ratio. (The \l fillMode is independent of this.) - + If the source is an instrinsically scalable image (eg. SVG), this property determines the size of the loaded image regardless of intrinsic size. Avoid changing this property dynamically; rendering an SVG is \e slow compared @@ -344,34 +361,8 @@ qreal QDeclarativeImage::paintedHeight() const be no greater than this property specifies. For some formats (currently only JPEG), the whole image will never actually be loaded into memory. - \note \e{Changing this property dynamically will lead to the image source being reloaded, - potentially even from the network if it is not in the disk cache.} - - Here is an example that ensures the size of the image in memory is - no larger than 1024x1024 pixels, regardless of the size of the Image element. - - \code - Image { - anchors.fill: parent - source: "images/reallyBigImage.jpg" - sourceSize.width: 1024 - sourceSize.height: 1024 - } - \endcode - - The example below ensures the memory used by the image is no more than necessary - to display the image at the size of the Image element. - Of course if the Image element is resized a costly reload will be required, so - use this technique \e only when the Image size is fixed. - - \code - Image { - anchors.fill: parent - source: "images/reallyBigImage.jpg" - sourceSize.width: width - sourceSize.height: height - } - \endcode + \note \e {Changing this property dynamically causes the image source to be reloaded, + potentially even from the network, if it is not in the disk cache.} */ void QDeclarativeImage::updatePaintedGeometry() @@ -415,6 +406,8 @@ void QDeclarativeImage::geometryChanged(const QRectF &newGeometry, const QRectF Image can handle any image format supported by Qt, loaded from any URL scheme supported by Qt. The URL may be absolute, or relative to the URL of the component. + + \sa QDeclarativeImageProvider */ /*! diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 0c1a7af..36081f7 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -2071,7 +2071,7 @@ QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const relationship with other items. Margins apply to top, bottom, left, right, and fill anchors. - The margins property can be used to set all of the various margins at once, to the same value. + The \c anchors.margins property can be used to set all of the various margins at once, to the same value. Offsets apply for horizontal center, vertical center, and baseline anchors. @@ -2106,10 +2106,12 @@ QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const \endqml \endtable - anchors.fill provides a convenient way for one item to have the + \c anchors.fill provides a convenient way for one item to have the same geometry as another item, and is equivalent to connecting all four directional anchors. + To clear an anchor value, set it to \c undefined. + \note You can only anchor an item to siblings or a parent. For more information see \l {anchor-layout}{Anchor Layouts}. @@ -2475,7 +2477,7 @@ QDeclarativeListProperty<QDeclarativeTransition> QDeclarativeItemPrivate::transi \qmlproperty bool Item::clip This property holds whether clipping is enabled. - if clipping is enabled, an item will clip its own painting, as well + If clipping is enabled, an item will clip its own painting, as well as the painting of its children, to its bounding rectangle. Non-rectangular clipping regions are not supported for performance reasons. @@ -2676,7 +2678,7 @@ bool QDeclarativeItem::sceneEvent(QEvent *event) } /*! - \reimp + \internal Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is \e not called during initial widget polishing. Items wishing to optimize start-up construction diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index cd26472..38bc6f5 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -577,7 +577,7 @@ FxListItem *QDeclarativeListViewPrivate::createItem(int modelIndex) listItem->attached->m_prevSection = sectionAt(modelIndex-1); if (FxListItem *item = visibleItem(modelIndex+1)) listItem->attached->m_nextSection = item->attached->section(); - else + else if (modelIndex < model->count()-1) listItem->attached->m_nextSection = sectionAt(modelIndex+1); } } @@ -1077,7 +1077,7 @@ void QDeclarativeListViewPrivate::updateFooter() } if (footer) { if (visibleItems.count()) { - qreal endPos = endPosition(); + qreal endPos = endPosition() + 1; if (lastVisibleIndex() == model->count()-1) { footer->setPosition(endPos); } else { @@ -1732,7 +1732,7 @@ void QDeclarativeListView::setHighlight(QDeclarativeComponent *highlight) highlight is not moved by the view, and any movement must be implemented by the highlight. - Here is a highlight with its motion defined by a \l {SpringAniamtion} item: + Here is a highlight with its motion defined by a \l {SpringAnimation} item: \snippet doc/src/snippets/declarative/listview/listview.qml highlightFollowsCurrentItem @@ -2893,8 +2893,11 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count) d->visiblePos = d->header ? d->header->size() : 0; d->timeline.clear(); d->setPosition(0); - if (d->itemCount == 0) + if (d->itemCount == 0) { + d->updateHeader(); + d->updateFooter(); update(); + } } emit countChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index 7b65ca7..b7b0c9e 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -767,10 +767,16 @@ QDeclarativeDrag *QDeclarativeMouseArea::drag() \i \c drag.minimum and \c drag.maximum limit how far the target can be dragged along the corresponding axes. \endlist - The following example displays an image that can be dragged along the X-axis. The opacity - of the image is reduced when it is dragged to the right. + The following example displays a \l Rectangle that can be dragged along the X-axis. The opacity + of the rectangle is reduced when it is dragged to the right. \snippet doc/src/snippets/declarative/mousearea.qml drag + + \note Items cannot be dragged if they are anchored for the requested + \c drag.axis. For example, if \c anchors.left or \c anchors.right was set + for \c rect in the above example, it cannot be dragged along the X-axis. + This can be avoided by settng the anchor value to \c undefined in + an \l onPressed handler. */ QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index a904869..80196a1 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -533,6 +533,13 @@ void QDeclarativeCurve::setY(qreal y) /*! \qmlproperty string PathAttribute::name the name of the attribute to change. + + This attribute will be available to the delegate as PathView.<name> + + Note that using an existing Item property name such as "opacity" as an + attribute is allowed. This is because path attributes add a new + \l{qdeclarativeintroduction.html#attached-properties} {Attached Property} + which in no way clashes with existing properties. */ /*! diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index f4ebd13..acf9827 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -284,8 +284,8 @@ void QDeclarativePathViewPrivate::updateItem(QDeclarativeItem *item, qreal perce att->setValue(attr.toUtf8(), path->attributeAt(attr, percent)); } QPointF pf = path->pointAt(percent); - item->setX(qRound(pf.x() - item->width()*item->scale()/2)); - item->setY(qRound(pf.y() - item->height()*item->scale()/2)); + item->setX(qRound(pf.x() - item->width()/2)); + item->setY(qRound(pf.y() - item->height()/2)); } void QDeclarativePathViewPrivate::regenerate() diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 9a281e5..ba4fa21 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -1127,6 +1127,15 @@ int QDeclarativeText::resourcesLoading() const return d->doc ? d->doc->resourcesLoading() : 0; } +/*! + \qmlproperty bool Text::clip + This property holds whether the text is clipped. + + Note that if the text does not fit in the bounding rectangle it will be abruptly chopped. + + If you want to display potentially long text in a limited space, you probably want to use \c elide instead. +*/ + void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QDeclarativeText); @@ -1146,13 +1155,10 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid bool needClip = clip() && (d->imgCache.width() > width() || d->imgCache.height() > height()); - if (needClip) { - p->save(); - p->setClipRect(boundingRect(), Qt::IntersectClip); - } - p->drawPixmap(br.x(), br.y(), d->imgCache); if (needClip) - p->restore(); + p->drawPixmap(0, 0, width(), height(), d->imgCache, -br.x(), -br.y(), width(), height()); + else + p->drawPixmap(br.x(), br.y(), d->imgCache); if (d->smooth) { p->setRenderHint(QPainter::Antialiasing, oldAA); @@ -1166,7 +1172,7 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid if (needClip) { p->save(); - p->setClipRect(boundingRect(), Qt::IntersectClip); + p->setClipRect(0, 0, width(), height(), Qt::IntersectClip); } if (d->richText) { QAbstractTextDocumentLayout::PaintContext context; diff --git a/src/declarative/graphicsitems/qdeclarativetranslate.cpp b/src/declarative/graphicsitems/qdeclarativetranslate.cpp index 17daac7..16a1127 100644 --- a/src/declarative/graphicsitems/qdeclarativetranslate.cpp +++ b/src/declarative/graphicsitems/qdeclarativetranslate.cpp @@ -117,7 +117,7 @@ void QDeclarativeTranslate::setY(qreal y) } /*! - \reimp + \internal */ void QDeclarativeTranslate::applyTo(QMatrix4x4 *matrix) const { diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 786d6f9..cfa1c6d 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -1089,6 +1089,11 @@ QString QDeclarativeVisualDataModel::stringValue(int index, const QString &name) if (d->m_visualItemModel) return d->m_visualItemModel->stringValue(index, name); + if ((!d->m_listModelInterface || !d->m_abstractItemModel) && d->m_listAccessor) { + if (QObject *object = d->m_listAccessor->at(index).value<QObject*>()) + return object->property(name.toUtf8()).toString(); + } + if ((!d->m_listModelInterface && !d->m_abstractItemModel) || !d->m_delegate) return QString(); diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index 882e981..e096305 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -54,27 +54,20 @@ QT_BEGIN_NAMESPACE -QDeclarativeBindingData::QDeclarativeBindingData() -: updating(false), enabled(false) +void QDeclarativeBindingPrivate::refresh() { + Q_Q(QDeclarativeBinding); + q->update(); } -QDeclarativeBindingData::~QDeclarativeBindingData() -{ - removeError(); -} - -void QDeclarativeBindingData::refresh() +QDeclarativeBindingPrivate::QDeclarativeBindingPrivate() +: updating(false), enabled(false), deleted(0) { - if (enabled && !updating && q) { - QDeclarativeBinding *b = static_cast<QDeclarativeBinding *>(QDeclarativeExpressionPrivate::get(q)); - b->update(); - } } -QDeclarativeBindingPrivate::QDeclarativeBindingPrivate() -: QDeclarativeExpressionPrivate(new QDeclarativeBindingData) +QDeclarativeBindingPrivate::~QDeclarativeBindingPrivate() { + if (deleted) *deleted = true; } QDeclarativeBinding::QDeclarativeBinding(void *data, QDeclarativeRefCount *rc, QObject *obj, @@ -109,7 +102,7 @@ QDeclarativeBinding::~QDeclarativeBinding() void QDeclarativeBinding::setTarget(const QDeclarativeProperty &prop) { Q_D(QDeclarativeBinding); - d->bindingData()->property = prop; + d->property = prop; update(); } @@ -117,50 +110,53 @@ void QDeclarativeBinding::setTarget(const QDeclarativeProperty &prop) QDeclarativeProperty QDeclarativeBinding::property() const { Q_D(const QDeclarativeBinding); - return d->bindingData()->property; + return d->property; } void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags) { Q_D(QDeclarativeBinding); - QDeclarativeBindingData *data = d->bindingData(); - - if (!data->enabled || !data->context() || !data->context()->isValid()) + if (!d->enabled || !d->context() || !d->context()->isValid()) return; - data->addref(); - - if (!data->updating) { - data->updating = true; + if (!d->updating) { + d->updating = true; + bool wasDeleted = false; + d->deleted = &wasDeleted; - if (data->property.propertyType() == qMetaTypeId<QDeclarativeBinding *>()) { + if (d->property.propertyType() == qMetaTypeId<QDeclarativeBinding *>()) { - int idx = data->property.index(); + int idx = d->property.index(); Q_ASSERT(idx != -1); - QDeclarativeBinding *t = this; int status = -1; void *a[] = { &t, 0, &status, &flags }; - QMetaObject::metacall(data->property.object(), + QMetaObject::metacall(d->property.object(), QMetaObject::WriteProperty, idx, a); + if (wasDeleted) + return; + } else { - QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(data->context()->engine); + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(d->context()->engine); bool isUndefined = false; QVariant value; QScriptValue scriptValue = d->scriptValue(0, &isUndefined); - if (data->property.propertyTypeCategory() == QDeclarativeProperty::List) { + if (wasDeleted) + return; + + if (d->property.propertyTypeCategory() == QDeclarativeProperty::List) { value = ep->scriptValueToVariant(scriptValue, qMetaTypeId<QList<QObject *> >()); } else if (scriptValue.isNull() && - data->property.propertyTypeCategory() == QDeclarativeProperty::Object) { + d->property.propertyTypeCategory() == QDeclarativeProperty::Object) { value = QVariant::fromValue((QObject *)0); } else { - value = ep->scriptValueToVariant(scriptValue, data->property.propertyType()); + value = ep->scriptValueToVariant(scriptValue, d->property.propertyType()); if (value.userType() == QMetaType::QObjectStar && !qvariant_cast<QObject*>(value)) { // If the object is null, we extract the predicted type. While this isn't // 100% reliable, in many cases it gives us better error messages if we @@ -172,73 +168,78 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags) } - if (data->error.isValid()) { + if (d->error.isValid()) { - } else if (isUndefined && data->property.isResettable()) { + } else if (isUndefined && d->property.isResettable()) { - data->property.reset(); + d->property.reset(); - } else if (isUndefined && data->property.propertyType() == qMetaTypeId<QVariant>()) { + } else if (isUndefined && d->property.propertyType() == qMetaTypeId<QVariant>()) { - QDeclarativePropertyPrivate::write(data->property, QVariant(), flags); + QDeclarativePropertyPrivate::write(d->property, QVariant(), flags); } else if (isUndefined) { - QUrl url = QUrl(data->url); - int line = data->line; + QUrl url = QUrl(d->url); + int line = d->line; if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>")); - data->error.setUrl(url); - data->error.setLine(line); - data->error.setColumn(-1); - data->error.setDescription(QLatin1String("Unable to assign [undefined] to ") - + QLatin1String(QMetaType::typeName(data->property.propertyType())) - + QLatin1String(" ") + data->property.name()); + d->error.setUrl(url); + d->error.setLine(line); + d->error.setColumn(-1); + d->error.setDescription(QLatin1String("Unable to assign [undefined] to ") + + QLatin1String(QMetaType::typeName(d->property.propertyType())) + + QLatin1String(" ") + d->property.name()); } else if (!scriptValue.isRegExp() && scriptValue.isFunction()) { - QUrl url = QUrl(data->url); - int line = data->line; + QUrl url = QUrl(d->url); + int line = d->line; if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>")); - data->error.setUrl(url); - data->error.setLine(line); - data->error.setColumn(-1); - data->error.setDescription(QLatin1String("Unable to assign a function to a property.")); + d->error.setUrl(url); + d->error.setLine(line); + d->error.setColumn(-1); + d->error.setDescription(QLatin1String("Unable to assign a function to a property.")); + + } else if (d->property.object() && + !QDeclarativePropertyPrivate::write(d->property, value, flags)) { - } else if (data->property.object() && - !QDeclarativePropertyPrivate::write(data->property, value, flags)) { + if (wasDeleted) + return; - QUrl url = QUrl(data->url); - int line = data->line; + QUrl url = QUrl(d->url); + int line = d->line; if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>")); const char *valueType = 0; if (value.userType() == QVariant::Invalid) valueType = "null"; else valueType = QMetaType::typeName(value.userType()); - data->error.setUrl(url); - data->error.setLine(line); - data->error.setColumn(-1); - data->error.setDescription(QLatin1String("Unable to assign ") + - QLatin1String(valueType) + - QLatin1String(" to ") + - QLatin1String(QMetaType::typeName(data->property.propertyType()))); + d->error.setUrl(url); + d->error.setLine(line); + d->error.setColumn(-1); + d->error.setDescription(QLatin1String("Unable to assign ") + + QLatin1String(valueType) + + QLatin1String(" to ") + + QLatin1String(QMetaType::typeName(d->property.propertyType()))); } - if (data->error.isValid()) { - if (!data->addError(ep)) ep->warning(this->error()); + if (wasDeleted) + return; + + if (d->error.isValid()) { + if (!d->addError(ep)) ep->warning(this->error()); } else { - data->removeError(); + d->removeError(); } } - data->updating = false; + d->updating = false; + d->deleted = 0; } else { - qmlInfo(data->property.object()) << tr("Binding loop detected for property \"%1\"").arg(data->property.name()); + qmlInfo(d->property.object()) << tr("Binding loop detected for property \"%1\"").arg(d->property.name()); } - - data->release(); } void QDeclarativeBindingPrivate::emitValueChanged() @@ -250,13 +251,13 @@ void QDeclarativeBindingPrivate::emitValueChanged() void QDeclarativeBinding::setEnabled(bool e, QDeclarativePropertyPrivate::WriteFlags flags) { Q_D(QDeclarativeBinding); - d->bindingData()->enabled = e; + d->enabled = e; setNotifyOnValueChanged(e); QDeclarativeAbstractBinding::setEnabled(e, flags); if (e) { - addToObject(d->bindingData()->property.object()); + addToObject(d->property.object()); update(flags); } else { removeFromObject(); @@ -266,14 +267,14 @@ void QDeclarativeBinding::setEnabled(bool e, QDeclarativePropertyPrivate::WriteF int QDeclarativeBinding::propertyIndex() { Q_D(QDeclarativeBinding); - return QDeclarativePropertyPrivate::bindingIndex(d->bindingData()->property); + return QDeclarativePropertyPrivate::bindingIndex(d->property); } bool QDeclarativeBinding::enabled() const { Q_D(const QDeclarativeBinding); - return d->bindingData()->enabled; + return d->enabled; } QString QDeclarativeBinding::expression() const diff --git a/src/declarative/qml/qdeclarativebinding_p_p.h b/src/declarative/qml/qdeclarativebinding_p_p.h index 617ec4b..6926158 100644 --- a/src/declarative/qml/qdeclarativebinding_p_p.h +++ b/src/declarative/qml/qdeclarativebinding_p_p.h @@ -60,30 +60,24 @@ QT_BEGIN_NAMESPACE -class QDeclarativeBindingData : public QDeclarativeExpressionData -{ -public: - QDeclarativeBindingData(); - virtual ~QDeclarativeBindingData(); - - bool updating:1; - bool enabled:1; - - QDeclarativeProperty property; - - virtual void refresh(); -}; - class QDeclarativeBindingPrivate : public QDeclarativeExpressionPrivate { Q_DECLARE_PUBLIC(QDeclarativeBinding) public: QDeclarativeBindingPrivate(); - - QDeclarativeBindingData *bindingData() { return static_cast<QDeclarativeBindingData *>(data); } - const QDeclarativeBindingData *bindingData() const { return static_cast<const QDeclarativeBindingData *>(data); } + ~QDeclarativeBindingPrivate(); virtual void emitValueChanged(); + +protected: + virtual void refresh(); + +private: + bool updating:1; + bool enabled:1; + QDeclarativeProperty property; + + bool *deleted; }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h index 1f5aaf1..c5a039a 100644 --- a/src/declarative/qml/qdeclarativecontext_p.h +++ b/src/declarative/qml/qdeclarativecontext_p.h @@ -198,6 +198,7 @@ public: // context QDeclarativeComponentAttached *componentAttached; + // Return the outermost id for obj, if any. QString findObjectId(const QObject *obj) const; static QDeclarativeContextData *get(QDeclarativeContext *context) { diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 905a62c..f2eb770 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -219,7 +219,7 @@ of their use. QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) -: captureProperties(false), rootContext(0), currentExpression(0), isDebugging(false), +: captureProperties(false), rootContext(0), isDebugging(false), outputWarningsToStdErr(true), contextClass(0), sharedContext(0), sharedScope(0), objectClass(0), valueTypeClass(0), globalClass(0), cleanup(0), erroredBindings(0), inProgressCreations(0), scriptEngine(this), workerScriptEngine(0), componentAttached(0), diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index f457b53..a5c8c38 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -162,7 +162,6 @@ public: QPODVector<CapturedProperty> capturedProperties; QDeclarativeContext *rootContext; - QDeclarativeExpression *currentExpression; bool isDebugging; bool outputWarningsToStdErr; diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 001da46..008d054 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -495,7 +495,7 @@ void QDeclarativeEngineDebugServer::setBinding(int objectId, QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); } else { QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context); - QDeclarativeProperty property(object, propertyName); + QDeclarativeProperty property(object, propertyName, context); binding->setTarget(property); binding->setNotifyOnValueChanged(true); QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index 96cdec1..9935e38 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -71,109 +71,95 @@ bool QDeclarativeDelayedError::addError(QDeclarativeEnginePrivate *e) return true; } -QDeclarativeExpressionData::QDeclarativeExpressionData() -: q(0), dataRef(0), expressionFunctionValid(false), expressionRewritten(false), me(0), - trackChange(false), isShared(false), line(-1), guardList(0), guardListLength(0) +QDeclarativeQtScriptExpression::QDeclarativeQtScriptExpression() +: dataRef(0), expressionFunctionMode(ExplicitContext), scopeObject(0), trackChange(false), + guardList(0), guardListLength(0), guardObject(0), guardObjectNotifyIndex(-1), deleted(0) { } -QDeclarativeExpressionData::~QDeclarativeExpressionData() +QDeclarativeQtScriptExpression::~QDeclarativeQtScriptExpression() { if (guardList) { delete [] guardList; guardList = 0; } if (dataRef) dataRef->release(); + if (deleted) *deleted = true; } QDeclarativeExpressionPrivate::QDeclarativeExpressionPrivate() -: data(new QDeclarativeExpressionData) +: expressionFunctionValid(true), line(-1) { - data->q = this; -} - -QDeclarativeExpressionPrivate::QDeclarativeExpressionPrivate(QDeclarativeExpressionData *d) -: data(d) -{ - data->q = this; } QDeclarativeExpressionPrivate::~QDeclarativeExpressionPrivate() { - if (data) { - delete [] data->guardList; - data->guardList = 0; - data->guardListLength = 0; - data->q = 0; - data->release(); - data = 0; - } } void QDeclarativeExpressionPrivate::init(QDeclarativeContextData *ctxt, const QString &expr, QObject *me) { - data->expression = expr; + expression = expr; - data->QDeclarativeAbstractExpression::setContext(ctxt); - data->me = me; + QDeclarativeAbstractExpression::setContext(ctxt); + scopeObject = me; + expressionFunctionValid = false; } -void QDeclarativeExpressionPrivate::init(QDeclarativeContextData *ctxt, void *expr, QDeclarativeRefCount *rc, - QObject *me, const QString &url, int lineNumber) +void QDeclarativeExpressionPrivate::init(QDeclarativeContextData *ctxt, void *expr, + QDeclarativeRefCount *rc, + QObject *me, const QString &srcUrl, int lineNumber) { - data->url = url; - data->line = lineNumber; + url = srcUrl; + line = lineNumber; - if (data->dataRef) data->dataRef->release(); - data->dataRef = rc; - if (data->dataRef) data->dataRef->addref(); + if (dataRef) dataRef->release(); + dataRef = rc; + if (dataRef) dataRef->addref(); quint32 *exprData = (quint32 *)expr; QDeclarativeCompiledData *dd = (QDeclarativeCompiledData *)rc; - data->expressionRewritten = true; - data->expression = QString::fromRawData((QChar *)(exprData + 2), exprData[1]); + expression = QString::fromRawData((QChar *)(exprData + 2), exprData[1]); int progIdx = *(exprData); - bool isShared = progIdx & 0x80000000; + bool isSharedProgram = progIdx & 0x80000000; progIdx &= 0x7FFFFFFF; QDeclarativeEngine *engine = ctxt->engine; QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); - if (isShared) { + if (isSharedProgram) { if (!dd->cachedClosures.at(progIdx)) { QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); scriptContext->pushScope(ep->contextClass->newSharedContext()); scriptContext->pushScope(ep->globalClass->staticGlobalObject()); - dd->cachedClosures[progIdx] = new QScriptValue(scriptEngine->evaluate(data->expression, data->url, data->line)); + dd->cachedClosures[progIdx] = new QScriptValue(scriptEngine->evaluate(expression, url, line)); scriptEngine->popContext(); } - data->expressionFunction = *dd->cachedClosures.at(progIdx); - data->isShared = true; - data->expressionFunctionValid = true; + expressionFunction = *dd->cachedClosures.at(progIdx); + expressionFunctionMode = SharedContext; + expressionFunctionValid = true; } else { #if !defined(Q_OS_SYMBIAN) //XXX Why doesn't this work? if (!dd->cachedPrograms.at(progIdx)) { - dd->cachedPrograms[progIdx] = - new QScriptProgram(data->expression, data->url, data->line); + dd->cachedPrograms[progIdx] = new QScriptProgram(expression, url, line); } - data->expressionFunction = evalInObjectScope(ctxt, me, *dd->cachedPrograms.at(progIdx), - &data->expressionContext); + expressionFunction = evalInObjectScope(ctxt, me, *dd->cachedPrograms.at(progIdx), + &expressionContext); #else - data->expressionFunction = evalInObjectScope(ctxt, me, data->expression, - &data->expressionContext); + expressionFunction = evalInObjectScope(ctxt, me, expression, &expressionContext); #endif - data->expressionFunctionValid = true; + expressionFunctionMode = ExplicitContext; + expressionFunctionValid = true; } - data->QDeclarativeAbstractExpression::setContext(ctxt); - data->me = me; + QDeclarativeAbstractExpression::setContext(ctxt); + scopeObject = me; } QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContextData *context, QObject *object, @@ -240,6 +226,8 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex \endcode */ +static int QDeclarativeExpression_notifyIdx = -1; + /*! Create an invalid QDeclarativeExpression. @@ -249,6 +237,11 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex QDeclarativeExpression::QDeclarativeExpression() : QObject(*new QDeclarativeExpressionPrivate, 0) { + Q_D(QDeclarativeExpression); + + if (QDeclarativeExpression_notifyIdx == -1) + QDeclarativeExpression_notifyIdx = QDeclarativeExpression::staticMetaObject.indexOfMethod("_q_notify()"); + d->setNotifyObject(this, QDeclarativeExpression_notifyIdx); } /*! \internal */ @@ -260,6 +253,10 @@ QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, vo { Q_D(QDeclarativeExpression); d->init(ctxt, expr, rc, me, url, lineNumber); + + if (QDeclarativeExpression_notifyIdx == -1) + QDeclarativeExpression_notifyIdx = QDeclarativeExpression::staticMetaObject.indexOfMethod("_q_notify()"); + d->setNotifyObject(this, QDeclarativeExpression_notifyIdx); } /*! @@ -277,6 +274,10 @@ QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContext *ctxt, { Q_D(QDeclarativeExpression); d->init(QDeclarativeContextData::get(ctxt), expression, scope); + + if (QDeclarativeExpression_notifyIdx == -1) + QDeclarativeExpression_notifyIdx = QDeclarativeExpression::staticMetaObject.indexOfMethod("_q_notify()"); + d->setNotifyObject(this, QDeclarativeExpression_notifyIdx); } /*! @@ -288,6 +289,10 @@ QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, QO { Q_D(QDeclarativeExpression); d->init(ctxt, expression, scope); + + if (QDeclarativeExpression_notifyIdx == -1) + QDeclarativeExpression_notifyIdx = QDeclarativeExpression::staticMetaObject.indexOfMethod("_q_notify()"); + d->setNotifyObject(this, QDeclarativeExpression_notifyIdx); } /*! \internal */ @@ -297,6 +302,10 @@ QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, QO { Q_D(QDeclarativeExpression); d->init(ctxt, expression, scope); + + if (QDeclarativeExpression_notifyIdx == -1) + QDeclarativeExpression_notifyIdx = QDeclarativeExpression::staticMetaObject.indexOfMethod("_q_notify()"); + d->setNotifyObject(this, QDeclarativeExpression_notifyIdx); } /*! @@ -313,7 +322,7 @@ QDeclarativeExpression::~QDeclarativeExpression() QDeclarativeEngine *QDeclarativeExpression::engine() const { Q_D(const QDeclarativeExpression); - return d->data->context()?d->data->context()->engine:0; + return d->context()?d->context()->engine:0; } /*! @@ -323,7 +332,7 @@ QDeclarativeEngine *QDeclarativeExpression::engine() const QDeclarativeContext *QDeclarativeExpression::context() const { Q_D(const QDeclarativeExpression); - QDeclarativeContextData *data = d->data->context(); + QDeclarativeContextData *data = d->context(); return data?data->asQDeclarativeContext():0; } @@ -333,7 +342,7 @@ QDeclarativeContext *QDeclarativeExpression::context() const QString QDeclarativeExpression::expression() const { Q_D(const QDeclarativeExpression); - return d->data->expression; + return d->expression; } /*! @@ -343,12 +352,10 @@ void QDeclarativeExpression::setExpression(const QString &expression) { Q_D(QDeclarativeExpression); - d->clearGuards(); - - d->data->expression = expression; - d->data->expressionFunctionValid = false; - d->data->expressionRewritten = false; - d->data->expressionFunction = QScriptValue(); + d->resetNotifyOnChange(); + d->expression = expression; + d->expressionFunctionValid = false; + d->expressionFunction = QScriptValue(); } void QDeclarativeExpressionPrivate::exceptionToError(QScriptEngine *scriptEngine, @@ -378,59 +385,108 @@ void QDeclarativeExpressionPrivate::exceptionToError(QScriptEngine *scriptEngine } } -QScriptValue QDeclarativeExpressionPrivate::eval(QObject *secondaryScope, bool *isUndefined) +bool QDeclarativeQtScriptExpression::notifyOnValueChange() const { - QDeclarativeExpressionData *data = this->data; - QDeclarativeEngine *engine = data->context()->engine; - QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); + return trackChange; +} - QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); +void QDeclarativeQtScriptExpression::setNotifyOnValueChange(bool notify) +{ + trackChange = notify; + if (!notify && guardList) + clearGuards(); +} - if (!data->expressionFunctionValid) { +void QDeclarativeQtScriptExpression::resetNotifyOnChange() +{ + clearGuards(); +} - QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); - data->expressionContext = ep->contextClass->newContext(data->context(), data->me); - scriptContext->pushScope(data->expressionContext); - scriptContext->pushScope(ep->globalClass->staticGlobalObject()); +void QDeclarativeQtScriptExpression::setNotifyObject(QObject *object, int notifyIndex) +{ + if (guardList) clearGuards(); + + if (!object || notifyIndex == -1) { + guardObject = 0; + notifyIndex = -1; + } else { + guardObject = object; + guardObjectNotifyIndex = notifyIndex; + + } +} + +QScriptValue QDeclarativeQtScriptExpression::scriptValue(QObject *secondaryScope, bool *isUndefined) +{ + Q_ASSERT(context() && context()->engine); + Q_ASSERT(!trackChange || (guardObject && guardObjectNotifyIndex != -1)); + + if (!expressionFunction.isValid()) { + if (isUndefined) *isUndefined = true; + return QScriptValue(); + } + + DeleteWatcher watcher(this); + + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context()->engine); + + bool lastCaptureProperties = ep->captureProperties; + QPODVector<QDeclarativeEnginePrivate::CapturedProperty> lastCapturedProperties; + ep->captureProperties = trackChange; + ep->capturedProperties.copyAndClear(lastCapturedProperties); + + QScriptValue value = eval(secondaryScope, isUndefined); + + if (!watcher.wasDeleted() && trackChange) { + if (ep->capturedProperties.count() == 0) { + + if (guardList) clearGuards(); - if (data->expressionRewritten) { - data->expressionFunction = scriptEngine->evaluate(data->expression, - data->url, data->line); } else { - QDeclarativeRewrite::RewriteBinding rewriteBinding; - bool ok = true; - const QString code = rewriteBinding(data->expression, &ok); - if (!ok) { - scriptEngine->popContext(); - return QScriptValue(); - } - data->expressionFunction = scriptEngine->evaluate(code, data->url, data->line); - } + updateGuards(ep->capturedProperties); - scriptEngine->popContext(); - data->expressionFunctionValid = true; + } } + lastCapturedProperties.copyAndClear(ep->capturedProperties); + ep->captureProperties = lastCaptureProperties; + + return value; +} + +QScriptValue QDeclarativeQtScriptExpression::eval(QObject *secondaryScope, bool *isUndefined) +{ + Q_ASSERT(context() && context()->engine); + + DeleteWatcher watcher(this); + + QDeclarativeEngine *engine = context()->engine; + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); + + QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); + QDeclarativeContextData *oldSharedContext = 0; QObject *oldSharedScope = 0; QObject *oldOverride = 0; - if (data->isShared) { + bool isShared = (expressionFunctionMode == SharedContext); + + if (isShared) { oldSharedContext = ep->sharedContext; oldSharedScope = ep->sharedScope; - ep->sharedContext = data->context(); - ep->sharedScope = data->me; + ep->sharedContext = context(); + ep->sharedScope = scopeObject; } else { - oldOverride = ep->contextClass->setOverrideObject(data->expressionContext, secondaryScope); + oldOverride = ep->contextClass->setOverrideObject(expressionContext, secondaryScope); } - QScriptValue svalue = data->expressionFunction.call(); + QScriptValue svalue = expressionFunction.call(); // This could cause this to be deleted - if (data->isShared) { + if (isShared) { ep->sharedContext = oldSharedContext; ep->sharedScope = oldSharedScope; - } else { - ep->contextClass->setOverrideObject(data->expressionContext, oldOverride); + } else if (!watcher.wasDeleted()) { + ep->contextClass->setOverrideObject(expressionContext, oldOverride); } if (isUndefined) @@ -438,63 +494,134 @@ QScriptValue QDeclarativeExpressionPrivate::eval(QObject *secondaryScope, bool * // Handle exception if (scriptEngine->hasUncaughtException()) { - exceptionToError(scriptEngine, data->error); + if (!watcher.wasDeleted()) + QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error); + scriptEngine->clearExceptions(); return QScriptValue(); } else { - data->error = QDeclarativeError(); + if (!watcher.wasDeleted()) + error = QDeclarativeError(); + return svalue; } } -QScriptValue QDeclarativeExpressionPrivate::scriptValue(QObject *secondaryScope, bool *isUndefined) +void QDeclarativeQtScriptExpression::updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties) { - Q_Q(QDeclarativeExpression); - Q_ASSERT(q->engine()); + Q_ASSERT(guardObject); + Q_ASSERT(guardObjectNotifyIndex != -1); - if (data->expression.isEmpty()) - return QScriptValue(); + if (properties.count() != guardListLength) { + QDeclarativeNotifierEndpoint *newGuardList = new QDeclarativeNotifierEndpoint[properties.count()]; - QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(q->engine()); + for (int ii = 0; ii < qMin(guardListLength, properties.count()); ++ii) + guardList[ii].copyAndClear(newGuardList[ii]); - QDeclarativeExpression *lastCurrentExpression = ep->currentExpression; - bool lastCaptureProperties = ep->captureProperties; - QPODVector<QDeclarativeEnginePrivate::CapturedProperty> lastCapturedProperties; - ep->capturedProperties.copyAndClear(lastCapturedProperties); + delete [] guardList; + guardList = newGuardList; + guardListLength = properties.count(); + } - ep->currentExpression = q; - ep->captureProperties = data->trackChange; + bool outputWarningHeader = false; + bool noChanges = true; + for (int ii = 0; ii < properties.count(); ++ii) { + QDeclarativeNotifierEndpoint &guard = guardList[ii]; + const QDeclarativeEnginePrivate::CapturedProperty &property = properties.at(ii); - // This object might be deleted during the eval - QDeclarativeExpressionData *localData = data; - localData->addref(); + guard.target = guardObject; + guard.targetMethod = guardObjectNotifyIndex; - QScriptValue value = eval(secondaryScope, isUndefined); + if (property.notifier != 0) { - ep->currentExpression = lastCurrentExpression; - ep->captureProperties = lastCaptureProperties; + if (!noChanges && guard.isConnected(property.notifier)) { + // Nothing to do - // Check if we were deleted - if (localData->q) { - if ((!data->trackChange || !ep->capturedProperties.count()) && data->guardList) { - clearGuards(); - } else if(data->trackChange) { - updateGuards(ep->capturedProperties); + } else { + noChanges = false; + + bool existing = false; + for (int jj = 0; !existing && jj < ii; ++jj) + if (guardList[jj].isConnected(property.notifier)) + existing = true; + + if (existing) { + // duplicate + guard.disconnect(); + } else { + guard.connect(property.notifier); + } + } + + + } else if (property.notifyIndex != -1) { + + if (!noChanges && guard.isConnected(property.object, property.notifyIndex)) { + // Nothing to do + + } else { + noChanges = false; + + bool existing = false; + for (int jj = 0; !existing && jj < ii; ++jj) + if (guardList[jj].isConnected(property.object, property.notifyIndex)) + existing = true; + + if (existing) { + // duplicate + guard.disconnect(); + } else { + guard.connect(property.object, property.notifyIndex); + } + } + + } else { + if (!outputWarningHeader) { + outputWarningHeader = true; + qWarning() << "QDeclarativeExpression: Expression" << expression + << "depends on non-NOTIFYable properties:"; + } + + const QMetaObject *metaObj = property.object->metaObject(); + QMetaProperty metaProp = metaObj->property(property.coreIndex); + + qWarning().nospace() << " " << metaObj->className() << "::" << metaProp.name(); } } +} - localData->release(); +QScriptValue QDeclarativeExpressionPrivate::scriptValue(QObject *secondaryScope, bool *isUndefined) +{ + if (!expressionFunctionValid) { + QDeclarativeEngine *engine = context()->engine; + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); - lastCapturedProperties.copyAndClear(ep->capturedProperties); + QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); - return value; + QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); + expressionContext = ep->contextClass->newContext(context(), scopeObject); + scriptContext->pushScope(expressionContext); + scriptContext->pushScope(ep->globalClass->staticGlobalObject()); + + QDeclarativeRewrite::RewriteBinding rewriteBinding; + bool ok = true; + const QString code = rewriteBinding(expression, &ok); + if (ok) + expressionFunction = scriptEngine->evaluate(code, url, line); + + scriptEngine->popContext(); + expressionFunctionMode = ExplicitContext; + expressionFunctionValid = true; + } + + return QDeclarativeQtScriptExpression::scriptValue(secondaryScope, isUndefined); } QVariant QDeclarativeExpressionPrivate::value(QObject *secondaryScope, bool *isUndefined) { Q_Q(QDeclarativeExpression); - if (!data || !data->context() || !data->context()->isValid()) { + if (!context() || !context()->isValid()) { qWarning("QDeclarativeExpression: Attempted to evaluate an expression in an invalid context"); return QVariant(); } @@ -526,7 +653,7 @@ value changes. bool QDeclarativeExpression::notifyOnValueChanged() const { Q_D(const QDeclarativeExpression); - return d->data->trackChange; + return d->notifyOnValueChange(); } /*! @@ -548,7 +675,7 @@ bool QDeclarativeExpression::notifyOnValueChanged() const void QDeclarativeExpression::setNotifyOnValueChanged(bool notifyOnChange) { Q_D(QDeclarativeExpression); - d->data->trackChange = notifyOnChange; + d->setNotifyOnValueChange(notifyOnChange); } /*! @@ -558,7 +685,7 @@ void QDeclarativeExpression::setNotifyOnValueChanged(bool notifyOnChange) QString QDeclarativeExpression::sourceFile() const { Q_D(const QDeclarativeExpression); - return d->data->url; + return d->url; } /*! @@ -568,7 +695,7 @@ QString QDeclarativeExpression::sourceFile() const int QDeclarativeExpression::lineNumber() const { Q_D(const QDeclarativeExpression); - return d->data->line; + return d->line; } /*! @@ -578,8 +705,8 @@ int QDeclarativeExpression::lineNumber() const void QDeclarativeExpression::setSourceLocation(const QString &url, int line) { Q_D(QDeclarativeExpression); - d->data->url = url; - d->data->line = line; + d->url = url; + d->line = line; } /*! @@ -591,7 +718,7 @@ void QDeclarativeExpression::setSourceLocation(const QString &url, int line) QObject *QDeclarativeExpression::scopeObject() const { Q_D(const QDeclarativeExpression); - return d->data->me; + return d->scopeObject; } /*! @@ -603,7 +730,7 @@ QObject *QDeclarativeExpression::scopeObject() const bool QDeclarativeExpression::hasError() const { Q_D(const QDeclarativeExpression); - return d->data->error.isValid(); + return d->error.isValid(); } /*! @@ -615,7 +742,7 @@ bool QDeclarativeExpression::hasError() const void QDeclarativeExpression::clearError() { Q_D(QDeclarativeExpression); - d->data->error = QDeclarativeError(); + d->error = QDeclarativeError(); } /*! @@ -628,7 +755,7 @@ void QDeclarativeExpression::clearError() QDeclarativeError QDeclarativeExpression::error() const { Q_D(const QDeclarativeExpression); - return d->data->error; + return d->error; } /*! \internal */ @@ -637,98 +764,11 @@ void QDeclarativeExpressionPrivate::_q_notify() emitValueChanged(); } -void QDeclarativeExpressionPrivate::clearGuards() -{ - delete [] data->guardList; - data->guardList = 0; - data->guardListLength = 0; -} - -void QDeclarativeExpressionPrivate::updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties) +void QDeclarativeQtScriptExpression::clearGuards() { - Q_Q(QDeclarativeExpression); - - static int notifyIdx = -1; - if (notifyIdx == -1) - notifyIdx = QDeclarativeExpression::staticMetaObject.indexOfMethod("_q_notify()"); - - if (properties.count() != data->guardListLength) { - QDeclarativeNotifierEndpoint *newGuardList = - new QDeclarativeNotifierEndpoint[properties.count()]; - - for (int ii = 0; ii < qMin(data->guardListLength, properties.count()); ++ii) - data->guardList[ii].copyAndClear(newGuardList[ii]); - - delete [] data->guardList; - data->guardList = newGuardList; - data->guardListLength = properties.count(); - } - - bool outputWarningHeader = false; - bool noChanges = true; - for (int ii = 0; ii < properties.count(); ++ii) { - QDeclarativeNotifierEndpoint &guard = data->guardList[ii]; - const QDeclarativeEnginePrivate::CapturedProperty &property = properties.at(ii); - - guard.target = q; - guard.targetMethod = notifyIdx; - - if (property.notifier != 0) { - - if (!noChanges && guard.isConnected(property.notifier)) { - // Nothing to do - - } else { - noChanges = false; - - bool existing = false; - for (int jj = 0; !existing && jj < ii; ++jj) - if (data->guardList[jj].isConnected(property.notifier)) - existing = true; - - if (existing) { - // duplicate - guard.disconnect(); - } else { - guard.connect(property.notifier); - } - } - - - } else if (property.notifyIndex != -1) { - - if (!noChanges && guard.isConnected(property.object, property.notifyIndex)) { - // Nothing to do - - } else { - noChanges = false; - - bool existing = false; - for (int jj = 0; !existing && jj < ii; ++jj) - if (data->guardList[jj].isConnected(property.object, property.notifyIndex)) - existing = true; - - if (existing) { - // duplicate - guard.disconnect(); - } else { - guard.connect(property.object, property.notifyIndex); - } - } - - } else { - if (!outputWarningHeader) { - outputWarningHeader = true; - qWarning() << "QDeclarativeExpression: Expression" << q->expression() - << "depends on non-NOTIFYable properties:"; - } - - const QMetaObject *metaObj = property.object->metaObject(); - QMetaProperty metaProp = metaObj->property(property.coreIndex); - - qWarning().nospace() << " " << metaObj->className() << "::" << metaProp.name(); - } - } + delete [] guardList; + guardList = 0; + guardListLength = 0; } /*! diff --git a/src/declarative/qml/qdeclarativeexpression_p.h b/src/declarative/qml/qdeclarativeexpression_p.h index 4ff3162..b629e20 100644 --- a/src/declarative/qml/qdeclarativeexpression_p.h +++ b/src/declarative/qml/qdeclarativeexpression_p.h @@ -107,56 +107,73 @@ private: QDeclarativeDelayedError **prevError; }; -class QDeclarativeExpressionData : public QDeclarativeAbstractExpression, public QDeclarativeDelayedError, public QDeclarativeRefCount +class QDeclarativeQtScriptExpression : public QDeclarativeAbstractExpression, + public QDeclarativeDelayedError { public: - QDeclarativeExpressionData(); - virtual ~QDeclarativeExpressionData(); + enum Mode { SharedContext, ExplicitContext }; - QDeclarativeExpressionPrivate *q; + QDeclarativeQtScriptExpression(); + virtual ~QDeclarativeQtScriptExpression(); QDeclarativeRefCount *dataRef; + QString expression; - bool expressionFunctionValid:1; - bool expressionRewritten:1; + + Mode expressionFunctionMode; QScriptValue expressionFunction; - QScriptValue expressionContext; - QObject *me; - bool trackChange; + QScriptValue expressionContext; // Only used in ExplicitContext + QObject *scopeObject; // Only used in SharedContext - bool isShared; + bool notifyOnValueChange() const; + void setNotifyOnValueChange(bool); + void resetNotifyOnChange(); + void setNotifyObject(QObject *, int ); - QString url; // This is a QString for a reason. QUrls are slooooooow... - int line; + QScriptValue scriptValue(QObject *secondaryScope, bool *isUndefined); + + class DeleteWatcher { + public: + inline DeleteWatcher(QDeclarativeQtScriptExpression *data); + inline ~DeleteWatcher(); + inline bool wasDeleted() const; + private: + bool *m_wasDeleted; + bool m_wasDeletedStorage; + QDeclarativeQtScriptExpression *m_d; + }; + +private: + void clearGuards(); + QScriptValue eval(QObject *secondaryScope, bool *isUndefined); + void updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties); + + bool trackChange; QDeclarativeNotifierEndpoint *guardList; int guardListLength; + + QObject *guardObject; + int guardObjectNotifyIndex; + bool *deleted; }; class QDeclarativeExpression; class QString; -class QDeclarativeExpressionPrivate : public QObjectPrivate +class QDeclarativeExpressionPrivate : public QObjectPrivate, public QDeclarativeQtScriptExpression { Q_DECLARE_PUBLIC(QDeclarativeExpression) public: QDeclarativeExpressionPrivate(); - QDeclarativeExpressionPrivate(QDeclarativeExpressionData *); ~QDeclarativeExpressionPrivate(); void init(QDeclarativeContextData *, const QString &, QObject *); void init(QDeclarativeContextData *, void *, QDeclarativeRefCount *, QObject *, const QString &, int); - QDeclarativeExpressionData *data; - QVariant value(QObject *secondaryScope = 0, bool *isUndefined = 0); QScriptValue scriptValue(QObject *secondaryScope = 0, bool *isUndefined = 0); - QScriptValue eval(QObject *secondaryScope, bool *isUndefined = 0); - - void updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties); - void clearGuards(); - static QDeclarativeExpressionPrivate *get(QDeclarativeExpression *expr) { return static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr)); } @@ -172,8 +189,32 @@ public: int, QScriptValue *); static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QScriptProgram &, QScriptValue *); + + bool expressionFunctionValid:1; + + QString url; // This is a QString for a reason. QUrls are slooooooow... + int line; }; +QDeclarativeQtScriptExpression::DeleteWatcher::DeleteWatcher(QDeclarativeQtScriptExpression *data) +: m_wasDeletedStorage(false), m_d(data) +{ + if (!m_d->deleted) + m_d->deleted = &m_wasDeletedStorage; + m_wasDeleted = m_d->deleted; +} + +QDeclarativeQtScriptExpression::DeleteWatcher::~DeleteWatcher() +{ + if (false == *m_wasDeleted && m_wasDeleted == m_d->deleted) + m_d->deleted = 0; +} + +bool QDeclarativeQtScriptExpression::DeleteWatcher::wasDeleted() const +{ + return *m_wasDeleted; +} + QT_END_NAMESPACE #endif // QDECLARATIVEEXPRESSION_P_H diff --git a/src/declarative/qml/qdeclarativeimageprovider.cpp b/src/declarative/qml/qdeclarativeimageprovider.cpp index f38da4e..a294c38 100644 --- a/src/declarative/qml/qdeclarativeimageprovider.cpp +++ b/src/declarative/qml/qdeclarativeimageprovider.cpp @@ -180,9 +180,13 @@ QDeclarativeImageProvider::ImageType QDeclarativeImageProvider::imageType() cons Implement this method to return the image with \a id. The default implementation returns an empty image. - If \a requestedSize is a valid size, the image returned should be of that size. + The \a requestedSize corresponds to the \l {Image::sourceSize} requested by + an Image element. If \a requestedSize is a valid size, the image + returned should be of that size. - In all cases, \a size must be set to the original size of the image. + In all cases, \a size must be set to the original size of the image. This + is used to set the \l {Item::}{width} and \l {Item::}{height} of image + elements that should be automatically sized to the loaded image. \note this method may be called by multiple threads, so ensure the implementation of this method is reentrant. @@ -201,9 +205,13 @@ QImage QDeclarativeImageProvider::requestImage(const QString &id, QSize *size, c Implement this method to return the pixmap with \a id. The default implementation returns an empty pixmap. - If \a requestedSize is a valid size, the image returned should be of that size. + The \a requestedSize corresponds to the \l {Image::sourceSize} requested by + an Image element. If \a requestedSize is a valid size, the image + returned should be of that size. - In all cases, \a size must be set to the original size of the image. + In all cases, \a size must be set to the original size of the image. This + is used to set the \l {Item::}{width} and \l {Item::}{height} of image + elements that should be automatically sized to the loaded image. \note this method may be called by multiple threads, so ensure the implementation of this method is reentrant. diff --git a/src/declarative/qml/qdeclarativelist.cpp b/src/declarative/qml/qdeclarativelist.cpp index 7c89672..9598d98 100644 --- a/src/declarative/qml/qdeclarativelist.cpp +++ b/src/declarative/qml/qdeclarativelist.cpp @@ -306,7 +306,7 @@ int QDeclarativeListReference::count() const /*! \class QDeclarativeListProperty \since 4.7 -\brief The QDeclarativeListProperty class allows applications to explose list-like +\brief The QDeclarativeListProperty class allows applications to expose list-like properties to QML. QML has many list properties, where more than one object value can be assigned. diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index bdb9510..88ec5ba 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -634,13 +634,23 @@ QAbstractAnimation *QDeclarativePauseAnimation::qtAnimation() \inherits PropertyAnimation \brief The ColorAnimation element allows you to animate color changes. - \code - ColorAnimation { from: "white"; to: "#c0c0c0"; duration: 100 } - \endcode + ColorAnimation defines an animation to be applied when a color value + changes. + + Here is a ColorAnimation applied to the \c color property of a \l Rectangle + as a property value source: + + \snippet doc/src/snippets/declarative/coloranimation.qml 0 + + Like any other animation element, a NumberAnimation can be applied in a + number of ways, including transitions, behaviors and property value + sources. The \l PropertyAnimation documentation shows a variety of methods + for creating animations. When used in a transition, ColorAnimation will by default animate - all properties of type color that are changing. If a property or properties - are explicitly set for the animation, then those will be used instead. + all properties of type color that have changed. If a \l{PropertyAnimation::}{property} + or \l{PropertyAnimation::}{properties} are explicitly set for the animation, + then those are used instead. \sa {QML Animation}, {declarative/animation/basics}{Animation basics example} */ @@ -665,6 +675,17 @@ QDeclarativeColorAnimation::~QDeclarativeColorAnimation() /*! \qmlproperty color ColorAnimation::from This property holds the starting color. + + For example, the following animation is not applied until a color value + has reached "#c0c0c0": + + Item { + states: [ ... ] + + transition: Transition { + NumberAnimation { from: "#c0c0c0"; duration: 2000 } + } + } */ QColor QDeclarativeColorAnimation::from() const { @@ -1098,11 +1119,22 @@ void QDeclarativePropertyAction::transition(QDeclarativeStateActions &actions, \inherits PropertyAnimation \brief The NumberAnimation element allows you to animate changes in properties of type qreal. - For example, to animate a set of properties over 200ms, from their values in the start state to - their values in the end state of the transition: - \code - NumberAnimation { properties: "x,y,scale"; duration: 200 } - \endcode + NumberAnimation defines an animation to be applied when a numerical value + changes. + + Here is a NumberAnimation applied to the \c x property of a \l Rectangle + as a property value source: + + \snippet doc/src/snippets/declarative/numberanimation.qml 0 + + Like any other animation element, a NumberAnimation can be applied in a + number of ways, including transitions, behaviors and property value + sources. The \l PropertyAnimation documentation shows a variety of methods + for creating animations. + + Note that NumberAnimation may not animate smoothly if there are irregular + changes in the number value that it is tracking. If this is the case, use + SmoothedAnimation instead. \sa {QML Animation}, {declarative/animation/basics}{Animation basics example} */ @@ -1137,9 +1169,23 @@ void QDeclarativeNumberAnimation::init() /*! \qmlproperty real NumberAnimation::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 number value. + + For example, the following animation is not applied until the \c x value + has reached 100: + + Item { + states: [ ... ] + + transition: Transition { + NumberAnimation { properties: "x"; from: 100; duration: 200 } + } + } + + If this value is not set, it defaults to the value defined in the start + state of the \l Transition. */ + qreal QDeclarativeNumberAnimation::from() const { Q_D(const QDeclarativePropertyAnimation); @@ -1153,8 +1199,10 @@ void QDeclarativeNumberAnimation::setFrom(qreal f) /*! \qmlproperty real NumberAnimation::to - This property holds the ending value. - If not set, then the value defined in the end state of the transition or Behavior. + This property holds the ending number value. + + If this value is not set, it defaults to the value defined in the end + state of the \l Transition or \l Behavior. */ qreal QDeclarativeNumberAnimation::to() const { @@ -1199,7 +1247,9 @@ QDeclarativeVector3dAnimation::~QDeclarativeVector3dAnimation() /*! \qmlproperty real Vector3dAnimation::from This property holds the starting value. - If not set, then the value defined in the start state of the transition. + + If this value is not set, it defaults to the value defined in the start + state of the \l Transition. */ QVector3D QDeclarativeVector3dAnimation::from() const { @@ -1215,7 +1265,9 @@ void QDeclarativeVector3dAnimation::setFrom(QVector3D f) /*! \qmlproperty real Vector3dAnimation::to This property holds the ending value. - If not set, then the value defined in the end state of the transition or Behavior. + + If this value is not set, it defaults to the value defined in the end + state of the \l Transition or \l Behavior. */ QVector3D QDeclarativeVector3dAnimation::to() const { @@ -1320,8 +1372,21 @@ QDeclarativeRotationAnimation::~QDeclarativeRotationAnimation() /*! \qmlproperty real RotationAnimation::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 number value. + + For example, the following animation is not applied until the \c angle value + has reached 100: + + Item { + states: [ ... ] + + transition: Transition { + RotationAnimation { properties: "angle"; from: 100; duration: 2000 } + } + } + + If this value is not set, it defaults to the value defined in the start + state of the \l Transition. */ qreal QDeclarativeRotationAnimation::from() const { @@ -1337,7 +1402,9 @@ void QDeclarativeRotationAnimation::setFrom(qreal f) /*! \qmlproperty real RotationAnimation::to This property holds the ending value. - If not set, then the value defined in the end state of the transition or Behavior. + + If this value is not set, it defaults to the value defined in the end + state of the \l Transition or \l Behavior. */ qreal QDeclarativeRotationAnimation::to() const { @@ -1620,57 +1687,58 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int \inherits Animation \brief The PropertyAnimation element allows you to animate property changes. - PropertyAnimation provides a way to animate changes to a property's value. It can - be used in many different situations: + PropertyAnimation provides a way to animate changes to a property's value. + + It can be used to define animations in a number of ways: + \list - \o In a Transition + \o In a \l Transition + + For example, to animate any objects that have changed their \c x or \c y properties + as a result of a state change, using an \c InOutQuad easing curve: + + \snippet doc/src/snippets/declarative/propertyanimation.qml transition + + + \o In a \l Behavior + + For example, to animate all changes to a rectangle's \c x property: + + \snippet doc/src/snippets/declarative/propertyanimation.qml behavior - Animate any objects that have changed their x or y properties in the target state using - an InOutQuad easing curve: - \qml - Transition { PropertyAnimation { properties: "x,y"; easing.type: Easing.InOutQuad } } - \endqml - \o In a Behavior - Animate all changes to a rectangle's x property. - \qml - Rectangle { - Behavior on x { PropertyAnimation {} } - } - \endqml \o As a property value source - Repeatedly animate the rectangle's x property. - \qml - Rectangle { - SequentialAnimation on x { - loops: Animation.Infinite - PropertyAnimation { to: 50 } - PropertyAnimation { to: 0 } - } - } - \endqml + For example, to repeatedly animate the rectangle's \c x property: + + \snippet doc/src/snippets/declarative/propertyanimation.qml propertyvaluesource + + \o In a signal handler - Fade out \c theObject when clicked: + For example, to fade out \c theObject when clicked: \qml MouseArea { anchors.fill: theObject onClicked: PropertyAnimation { target: theObject; property: "opacity"; to: 0 } } \endqml + \o Standalone - Animate \c theObject's size property over 200ms, from its current size to 20-by-20: - \qml - PropertyAnimation { target: theObject; property: "size"; to: "20x20"; duration: 200 } - \endqml + For example, to animate \c rect's \c width property over 500ms, from its current width to 30: + + \snippet doc/src/snippets/declarative/propertyanimation.qml standalone + \endlist Depending on how the animation is used, the set of properties normally used will be different. For more information see the individual property documentation, as well as the \l{QML Animation} introduction. + Note that PropertyAnimation inherits the abstract \l Animation element. + This includes additional properties and methods for controlling the animation. + \sa {QML Animation}, {declarative/animation/basics}{Animation basics example} */ diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp index 5d47c30..e0d1097 100644 --- a/src/declarative/util/qdeclarativesmoothedanimation.cpp +++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp @@ -272,33 +272,8 @@ void QSmoothedAnimation::init() with both a velocity of 200 and a duration of 8000 set. The follow example shows one rectangle tracking the position of another. -\code -import Qt 4.7 - -Rectangle { - width: 800; height: 600; color: "blue" - - Rectangle { - color: "green" - width: 60; height: 60; - x: rect1.x - 5; y: rect1.y - 5; - Behavior on x { SmoothedAnimation { velocity: 200 } } - Behavior on y { SmoothedAnimation { velocity: 200 } } - } - - Rectangle { - id: rect1 - color: "red" - width: 50; height: 50; - } - focus: true - Keys.onRightPressed: rect1.x = rect1.x + 100 - Keys.onLeftPressed: rect1.x = rect1.x - 100 - Keys.onUpPressed: rect1.y = rect1.y - 100 - Keys.onDownPressed: rect1.y = rect1.y + 100 -} -\endcode + \snippet doc/src/snippets/declarative/smoothedanimation.qml 0 The default velocity of SmoothedAnimation is 200 units/second. Note that if the range of the value being animated is small, then the velocity will need to be adjusted @@ -307,6 +282,11 @@ Rectangle { set to a value such as 0.5 units/second. Animating from 0 to 1.0 with a velocity of 0.5 will take 2000 ms to complete. + Like any other animation element, a SmoothedAnimation can be applied in a + number of ways, including transitions, behaviors and property value + sources. The \l PropertyAnimation documentation shows a variety of methods + for creating animations. + \sa {QML Animation}, {declarative/animation/basics}{Animation basics example} */ @@ -388,11 +368,13 @@ void QDeclarativeSmoothedAnimation::transition(QDeclarativeStateActions &actions Sets how the SmoothedAnimation behaves if an animation direction is reversed. - If reversing mode is \c SmoothedAnimation.Eased, the animation will smoothly decelerate, and - then reverse direction. If the reversing mode is \c SmoothedAnimation.Immediate, the - animation will immediately begin accelerating in the reverse direction, - begining with a velocity of 0. If the reversing mode is \c SmoothedAnimation.Sync, the - property is immediately set to the target value. + Possible values are: + + \list + \o SmoothedAnimation.Eased (default) - the animation will smoothly decelerate, and then reverse direction + \o SmoothedAnimation.Immediate - the animation will immediately begin accelerating in the reverse direction, begining with a velocity of 0 + \o SmoothedAnimation.Sync - the property is immediately set to the target value + \endlist */ QDeclarativeSmoothedAnimation::ReversingMode QDeclarativeSmoothedAnimation::reversingMode() const { diff --git a/src/declarative/util/qdeclarativespringanimation.cpp b/src/declarative/util/qdeclarativespringanimation.cpp index 4cf2fc0..be0af6d 100644 --- a/src/declarative/util/qdeclarativespringanimation.cpp +++ b/src/declarative/util/qdeclarativespringanimation.cpp @@ -207,14 +207,24 @@ void QDeclarativeSpringAnimationPrivate::updateMode() \qmlclass SpringAnimation QDeclarativeSpringAnimation \since 4.7 - \brief The SpringAnimation element allows a property to track a value in a spring-like motion + \brief The SpringAnimation element allows a property to track a value in a spring-like motion. SpringAnimation mimics the oscillatory behavior of a spring, with the appropriate \l spring constant to control the acceleration and the \l damping to control how quickly the effect dies away. You can also limit the maximum \l velocity of the animation. + The following \l Rectangle moves to the position of the mouse using a + SpringAnimation when the mouse is clicked: + \snippet doc/src/snippets/declarative/springanimation.qml 0 + + Like any other animation element, a SpringAnimation can be applied in a + number of ways, including transitions, behaviors and property value + sources. The \l PropertyAnimation documentation shows a variety of methods + for creating animations. + + \sa {QML Animation}, {declarative/animation/basics}{Animation basics example}, {declarative/toys/clocks}{Clocks example} */ QDeclarativeSpringAnimation::QDeclarativeSpringAnimation(QObject *parent) @@ -244,6 +254,11 @@ qreal QDeclarativeSpringAnimation::to() const /*! \qmlproperty real SpringAnimation::to + + This property holds the value at which the animation will end. + + If not set, the animation will continue until it reaches the + value that is being tracked. */ void QDeclarativeSpringAnimation::setTo(qreal value) @@ -266,6 +281,11 @@ qreal QDeclarativeSpringAnimation::from() const /*! \qmlproperty real SpringAnimation::from + + This property holds the value from which the animation will begin. + + If not set, the animation will start regardless of the + value being tracked. */ void QDeclarativeSpringAnimation::setFrom(qreal value) @@ -325,10 +345,12 @@ void QDeclarativeSpringAnimation::setSpring(qreal spring) /*! \qmlproperty real SpringAnimation::damping - This property holds the spring damping constant + This property holds the spring damping value. + + This value describes how quickly a sprung follower comes to rest. - The damping constant describes how quickly a sprung follower comes to rest. - Useful range is 0 - 1.0 + The useful range is 0 - 1.0. The lower the value, the faster the + follower comes to rest. */ qreal QDeclarativeSpringAnimation::damping() const { @@ -348,7 +370,7 @@ void QDeclarativeSpringAnimation::setDamping(qreal damping) /*! \qmlproperty real SpringAnimation::epsilon - This property holds the spring epsilon + This property holds the spring epsilon. The epsilon is the rate and amount of change in the value which is close enough to 0 to be considered equal to zero. This will depend on the usage of the value. diff --git a/src/declarative/util/qdeclarativestate.cpp b/src/declarative/util/qdeclarativestate.cpp index ae19a9c..9f4cc39 100644 --- a/src/declarative/util/qdeclarativestate.cpp +++ b/src/declarative/util/qdeclarativestate.cpp @@ -144,7 +144,7 @@ QDeclarativeStateOperation::QDeclarativeStateOperation(QObjectPrivate &dd, QObje can, for example, be used to apply different sets of property values or execute different scripts. - The following example displays a single Rectangle. In the default state, the rectangle + The following example displays a single \l Rectangle. In the default state, the rectangle is colored black. In the "clicked" state, a PropertyChanges element changes the rectangle's color to red. Clicking within the MouseArea toggles the rectangle's state between the default state and the "clicked" state, thus toggling the color of the @@ -157,7 +157,7 @@ QDeclarativeStateOperation::QDeclarativeStateOperation(QObjectPrivate &dd, QObje States are commonly used together with \l {state-transitions}{Transitions} to provide animations when state changes occur. - \note setting the state of an object from within another state of the same object is + \note Setting the state of an object from within another state of the same object is not allowed. \sa {declarative/animation/states}{states example}, {qmlstates}{States}, {state-transitions}{Transitions}, QtDeclarative @@ -194,7 +194,7 @@ QDeclarativeState::~QDeclarativeState() \qmlproperty string State::name This property holds the name of the state. - Each state should have a unique name. + Each state should have a unique name within its item. */ QString QDeclarativeState::name() const { @@ -226,7 +226,23 @@ bool QDeclarativeState::isWhenKnown() const This property holds when the state should be applied. This should be set to an expression that evaluates to \c true when you want the state to - be applied. + be applied. For example, the following \l Rectangle changes in and out of the "hidden" + state when the \l MouseArea is pressed: + + \qml + Rectangle { + id: myRect + width: 100; height: 100 + color: "red" + + MouseArea { id: mouseArea; anchors.fill: parent } + + states: State { + name: "hidden"; when: mouseArea.pressed + PropertyChanges { target: myRect; opacity: 0 } + } + } + \endqml If multiple states in a group have \c when clauses that evaluate to \c true at the same time, the first matching state will be applied. For example, in the following snippet diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 51e6f99..5590449 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -1039,7 +1039,7 @@ public: /*! \qmlproperty Item AnchorChanges::target - This property holds the Item whose anchors will change + This property holds the \l Item for which the anchor changes will be applied. */ QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent) diff --git a/src/declarative/util/qdeclarativetransition.cpp b/src/declarative/util/qdeclarativetransition.cpp index 38ed97e..6b7418e 100644 --- a/src/declarative/util/qdeclarativetransition.cpp +++ b/src/declarative/util/qdeclarativetransition.cpp @@ -56,6 +56,30 @@ QT_BEGIN_NAMESPACE \since 4.7 \brief The Transition element defines animated transitions that occur on state changes. + A Transition defines the animations to be applied when a \l State change occurs. + + For example, the following \l Rectangle has two states: the default state, and + an added "moved" state. In the "moved state, the rectangle's position changes + to (50, 50). The added \l Transition specifies that when the rectangle + changes between the default and the "moved" state, any changes + to the \c x and \c y properties should be animated, using an \c Easing.InOutQuad. + + \snippet doc/src/snippets/declarative/transition.qml 0 + + Items can have multiple transitions, if + + To specify multiple transitions, specify \l Item::transitions as a list: + + \qml + Item { + ... + transitions: [ + Transition { ... } + Transition { ... } + ] + } + \endqml + \sa {declarative/animation/states}{states example}, {qmlstates}{States}, {state-transitions}{Transitions}, {QtDeclarative} */ @@ -171,18 +195,31 @@ void QDeclarativeTransition::prepare(QDeclarativeStateOperation::ActionList &act /*! \qmlproperty string Transition::from \qmlproperty string Transition::to - These properties are selectors indicating which state changes should trigger the transition. - from is used in conjunction with to to determine when a transition should - be applied. By default from and to are both "*" (any state). In the following example, - the transition is applied when changing from state1 to state2. - \code - Transition { - from: "state1" - to: "state2" - ... + These properties indicate the state changes that trigger the transition. + + The default values for these properties is "*" (that is, any state). + + For example, the following transition has not set the \c to and \c from + properties, so the animation is always applied when changing between + the two states (i.e. when the mouse is pressed and released). + + \snippet doc/src/snippets/declarative/transition-from-to.qml 0 + + If the transition was changed to this: + + \qml + transitions: Transition { + to: "brighter" + ColorAnimation { duration: 1000 } + } } - \endcode + \endqml + + The animation would only be applied when changing from the default state to + the "brighter" state (i.e. when the mouse is pressed, but not on release). + + \sa reversible */ QString QDeclarativeTransition::fromState() const { @@ -205,6 +242,24 @@ void QDeclarativeTransition::setFromState(const QString &f) This property holds whether the transition should be automatically reversed when the conditions that triggered this transition are reversed. The default value is false. + + By default, transitions run in parallel and are applied to all state + changes if the \l from and \l to states have not been set. In this + situation, the transition is automatically applied when a state change + is reversed, and it is not necessary to set this property to reverse + the transition. + + However, if a SequentialAnimation is used, or if the \l from or \l to + properties have been set, this property will need to be set to reverse + a transition when a state change is reverted. For example, the following + transition applies a sequential animation when the mouse is pressed, + and reverses the sequence of the animation when the mouse is released: + + \snippet doc/src/snippets/declarative/transition-reversible.qml 0 + + If the transition did not set the \c to and \c reversible values, then + on the mouse release, the transition would play the PropertyAnimation + before the ColorAnimation instead of reversing the sequence. */ bool QDeclarativeTransition::reversible() const { @@ -241,12 +296,27 @@ void QDeclarativeTransition::setToState(const QString &t) /*! \qmlproperty list<Animation> Transition::animations \default + This property holds a list of the animations to be run for this transition. + \qml + Transition { + PropertyAnimation { ... } + NumberAnimation { ... } + } + \endqml + The top-level animations are run in parallel. To run them sequentially, - you can create a single SequentialAnimation which contains all the animations, - and assign that to animations the animations property. - \default + define them within a SequentialAnimation: + + \qml + Transition { + SequentialAnimation { + PropertyAnimation { ... } + NumberAnimation { ... } + } + } + \endqml */ QDeclarativeListProperty<QDeclarativeAbstractAnimation> QDeclarativeTransition::animations() { diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 05a8501..7c1e1fd 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -508,8 +508,8 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla \since 4.7 \brief The XmlListModel element is used to specify a model using XPath expressions. - XmlListModel is used to create a model from XML data. XmlListModel can be used as a data source - for the view classes (such as ListView, PathView, GridView) and other classes that interact with model + XmlListModel is used to create a model from XML data. It can be used as a data source + for view elements (such as ListView, PathView, GridView) and other elements that interact with model data (such as \l Repeater). For example, if there is a XML document at http://www.mysite.com/feed.xml like this: @@ -520,11 +520,11 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla ... <channel> <item> - <title>Item A</title> + <title>A blog post</title> <pubDate>Sat, 07 Sep 2010 10:00:01 GMT</pubDate> </item> <item> - <title>Item B</title> + <title>Another blog post</title> <pubDate>Sat, 07 Sep 2010 15:35:01 GMT</pubDate> </item> </channel> @@ -560,10 +560,17 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla ListView { width: 180; height: 300 model: xmlModel - delegate: Text { title + " (" + pubDate + ")" } + delegate: Text { text: title + " (" + pubDate + ")" } } \endqml + \image qml-xmllistmodel-example.png + + The XmlListModel data is loaded asynchronously, and \l status + is set to \c XmlListModel.Ready when loading is complete. + Note this means when XmlListModel is used for a view, the view is not + populated until the model is loaded. + \section2 Using key XML roles |