summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-03-16 02:09:27 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-03-16 02:09:27 (GMT)
commitdd703f7a7e676f26dcb3ad634d75e0c9f677db43 (patch)
treef29f903c584349fe7ef67d43613f9fddaeb85aba /src/declarative
parent081fafe395d52ae42b57c36d1279e6ac05ae2cde (diff)
parente56c5483fe8b292545bb9f004d796abd8ae00589 (diff)
downloadQt-dd703f7a7e676f26dcb3ad634d75e0c9f677db43.zip
Qt-dd703f7a7e676f26dcb3ad634d75e0c9f677db43.tar.gz
Qt-dd703f7a7e676f26dcb3ad634d75e0c9f677db43.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Conflicts: src/declarative/qml/qdeclarativeengine.cpp tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/QmlChanges.txt44
-rw-r--r--src/declarative/graphicsitems/graphicsitems.pri4
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanchors.cpp10
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanchors_p_p.h40
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp16
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h3
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage.cpp16
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp3
-rw-r--r--src/declarative/graphicsitems/qdeclarativefocuspanel.cpp5
-rw-r--r--src/declarative/graphicsitems/qdeclarativefocuspanel_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativefocusscope.cpp5
-rw-r--r--src/declarative/graphicsitems/qdeclarativefocusscope_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp8
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp538
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview_p.h36
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimage.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimage_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase.cpp11
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp89
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.h31
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem_p.h10
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp130
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp176
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview_p.h6
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader.cpp13
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp1
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea_p_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativepainteditem.cpp4
-rw-r--r--src/declarative/graphicsitems/qdeclarativeparticles.cpp1317
-rw-r--r--src/declarative/graphicsitems/qdeclarativeparticles_p.h258
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp96
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners.cpp7
-rw-r--r--src/declarative/graphicsitems/qdeclarativerepeater.cpp56
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit.cpp14
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit_p_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp10
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp6
-rw-r--r--src/declarative/qml/parser/qdeclarativejslexer.cpp6
-rw-r--r--src/declarative/qml/qdeclarative.h22
-rw-r--r--src/declarative/qml/qdeclarativebinding.cpp142
-rw-r--r--src/declarative/qml/qdeclarativebinding_p.h28
-rw-r--r--src/declarative/qml/qdeclarativecompiledbindings.cpp171
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp29
-rw-r--r--src/declarative/qml/qdeclarativecomponent.cpp20
-rw-r--r--src/declarative/qml/qdeclarativecompositetypemanager.cpp57
-rw-r--r--src/declarative/qml/qdeclarativecompositetypemanager_p.h3
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp93
-rw-r--r--src/declarative/qml/qdeclarativecontext.h7
-rw-r--r--src/declarative/qml/qdeclarativecontext_p.h45
-rw-r--r--src/declarative/qml/qdeclarativecontextscriptclass.cpp26
-rw-r--r--src/declarative/qml/qdeclarativecontextscriptclass_p.h1
-rw-r--r--src/declarative/qml/qdeclarativecustomparser_p.h3
-rw-r--r--src/declarative/qml/qdeclarativedeclarativedata_p.h17
-rw-r--r--src/declarative/qml/qdeclarativedirparser.cpp5
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp193
-rw-r--r--src/declarative/qml/qdeclarativeengine.h4
-rw-r--r--src/declarative/qml/qdeclarativeengine_p.h3
-rw-r--r--src/declarative/qml/qdeclarativeenginedebug.cpp24
-rw-r--r--src/declarative/qml/qdeclarativeexpression.cpp180
-rw-r--r--src/declarative/qml/qdeclarativeexpression_p.h19
-rw-r--r--src/declarative/qml/qdeclarativeextensionplugin.cpp2
-rw-r--r--src/declarative/qml/qdeclarativeimageprovider.cpp4
-rw-r--r--src/declarative/qml/qdeclarativeinstruction.cpp2
-rw-r--r--src/declarative/qml/qdeclarativemetatype.cpp12
-rw-r--r--src/declarative/qml/qdeclarativenotifier.cpp110
-rw-r--r--src/declarative/qml/qdeclarativenotifier_p.h272
-rw-r--r--src/declarative/qml/qdeclarativeobjectscriptclass.cpp156
-rw-r--r--src/declarative/qml/qdeclarativeobjectscriptclass_p.h3
-rw-r--r--src/declarative/qml/qdeclarativeparser.cpp5
-rw-r--r--src/declarative/qml/qdeclarativeparser_p.h2
-rw-r--r--src/declarative/qml/qdeclarativeprivate.h6
-rw-r--r--src/declarative/qml/qdeclarativeproperty.cpp155
-rw-r--r--src/declarative/qml/qdeclarativeproperty_p.h3
-rw-r--r--src/declarative/qml/qdeclarativepropertycache_p.h17
-rw-r--r--src/declarative/qml/qdeclarativevaluetype.cpp2
-rw-r--r--src/declarative/qml/qdeclarativevaluetypescriptclass.cpp7
-rw-r--r--src/declarative/qml/qdeclarativevme.cpp17
-rw-r--r--src/declarative/qml/qdeclarativevme_p.h2
-rw-r--r--src/declarative/qml/qdeclarativexmlhttprequest.cpp2
-rw-r--r--src/declarative/qml/qml.pri2
-rw-r--r--src/declarative/util/qdeclarativeanimation.cpp118
-rw-r--r--src/declarative/util/qdeclarativeanimation_p.h21
-rw-r--r--src/declarative/util/qdeclarativeanimation_p_p.h13
-rw-r--r--src/declarative/util/qdeclarativefontloader.cpp19
-rw-r--r--src/declarative/util/qdeclarativepixmapcache.cpp41
-rw-r--r--src/declarative/util/qdeclarativestate.cpp62
-rw-r--r--src/declarative/util/qdeclarativestate_p.h8
-rw-r--r--src/declarative/util/qdeclarativestateoperations.cpp250
-rw-r--r--src/declarative/util/qdeclarativestateoperations_p.h9
-rw-r--r--src/declarative/util/qdeclarativetransitionmanager.cpp26
-rw-r--r--src/declarative/util/qdeclarativeutilmodule.cpp76
-rw-r--r--src/declarative/util/qdeclarativeview.cpp23
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp55
99 files changed, 2802 insertions, 2783 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt
index 591fb3d..6d0f16f 100644
--- a/src/declarative/QmlChanges.txt
+++ b/src/declarative/QmlChanges.txt
@@ -1,4 +1,32 @@
=============================================================================
+The changes below are pre Qt 4.7.0 beta
+
+PathView: offset property now uses range 0-1.0 rather than 0-100
+ListView, GridView::positionViewAtIndex() gained a 'mode' parameter
+Removed Qt.playSound (replaced by SoundEffect element)
+Removed Qt.closestAngle (use RotationAnimation instead)
+Removed NumberFormatter
+Removed DateTimeFormatter (use Qt.formatDateTime() instead)
+Using WebView now requires "import org.webkit 1.0"
+Using Particles now requires "import Qt.labs.particles 1.0"
+AnchorAnimation must now be used to animate anchor changes (and not NumberAnimation)
+
+C++ API
+-------
+QDeclarativeContext::addDefaultObject() has been replaced with
+QDeclarativeContext::setContextObject()
+
+Behavior and Animation syntax
+-----------------------------
+Previously animations and behaviors could be "assigned" to properties like this:
+ Item { x: Behavior {}; y: NumberAnimation {} }
+To make it more obvious that these are not regular value assignments a new "on"
+syntax has been introduced:
+ Item { Behavior on x {}; NumberAnimation on y {} }
+Only the syntax has changed, the behavior is identical.
+
+
+=============================================================================
The changes below are pre Qt 4.7.0 alpha
Flickable: renamed viewportWidth -> contentWidth
@@ -6,16 +34,12 @@ Flickable: renamed viewportHeight -> contentHeight
Flickable: renamed viewportX -> contentX
Flickable: renamed viewportY -> contentY
Removed Flickable.reportedVelocitySmoothing
-Removed Qt.playSound (replaced by SoundEffect element)
-Removed NumberFormatter
-Removed DateTimeFormatter (use Qt.formatDateTime() instead)
Renamed MouseRegion -> MouseArea
Connection: syntax and rename:
Connection { sender: a; signal: foo(); script: xxx }
Connection { sender: a; signal: bar(); script: yyy }
becomes:
Connections { target: a; onFoo: xxx; onBar: yyy }
-Using WebView now requires "import org.webkit 1.0"
QmlView
-------
@@ -47,7 +71,7 @@ C++ API
QML_DEFINE_... definition macros, previously global macros, are replaced by
QML_REGISTER_... registration macros, which must be called explicitly. C++ API users
should also consider using the QmlExtensionPlugin (previously named QmlModulePlugin)
-as a cleaner mechanism for publishing libraries of QML types, or the upcoming
+as a cleaner mechanism for publishing libraries of QML types, or the upcoming
application plugin features of the qmlviewer / qmlruntime / qml.
PropertyAnimation
@@ -56,16 +80,6 @@ matchProperties and matchTargets have been renamed back to properties and target
The semantics are explained in the PropertyAnimation::properties documentation
and the animation overview documentation.
-Behavior and Animation syntax
------------------------------
-
-Previously animations and behaviors could be "assigned" to properties like this:
- Item { x: Behavior {}; y: NumberAnimation {} }
-To make it more obvious that these are not regular value assignments a new "on"
-syntax has been introduced:
- Item { Behavior on x {}; NumberAnimation on y {} }
-Only the syntax has changed, the behavior is identical.
-
=============================================================================
The changes below are pre-4.6.0 release.
diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri
index 3ff92b1..d30651b 100644
--- a/src/declarative/graphicsitems/graphicsitems.pri
+++ b/src/declarative/graphicsitems/graphicsitems.pri
@@ -48,7 +48,6 @@ HEADERS += \
$$PWD/qdeclarativevisualitemmodel_p.h \
$$PWD/qdeclarativelistview_p.h \
$$PWD/qdeclarativegraphicsobjectcontainer_p.h \
- $$PWD/qdeclarativeparticles_p.h \
$$PWD/qdeclarativelayoutitem_p.h \
$$PWD/qdeclarativeitemchangelistener_p.h \
$$PWD/qdeclarativeeffects.cpp
@@ -82,5 +81,4 @@ SOURCES += \
$$PWD/qdeclarativevisualitemmodel.cpp \
$$PWD/qdeclarativelistview.cpp \
$$PWD/qdeclarativegraphicsobjectcontainer.cpp \
- $$PWD/qdeclarativeparticles.cpp \
- $$PWD/qdeclarativelayoutitem.cpp \
+ $$PWD/qdeclarativelayoutitem.cpp
diff --git a/src/declarative/graphicsitems/qdeclarativeanchors.cpp b/src/declarative/graphicsitems/qdeclarativeanchors.cpp
index 274d778..dc1f09d 100644
--- a/src/declarative/graphicsitems/qdeclarativeanchors.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeanchors.cpp
@@ -168,8 +168,7 @@ void QDeclarativeAnchorsPrivate::fillChanged()
} else if (fill->parentItem() == item->parentItem()) { //siblings
setItemPos(QPointF(fill->x()+leftMargin, fill->y()+topMargin));
}
- setItemWidth(fill->width()-leftMargin-rightMargin);
- setItemHeight(fill->height()-topMargin-bottomMargin);
+ setItemSize(QSizeF(fill->width()-leftMargin-rightMargin, fill->height()-topMargin-bottomMargin));
--updatingFill;
} else {
@@ -314,6 +313,13 @@ void QDeclarativeAnchorsPrivate::setItemPos(const QPointF &v)
updatingMe = false;
}
+void QDeclarativeAnchorsPrivate::setItemSize(const QSizeF &v)
+{
+ updatingMe = true;
+ item->setSize(v);
+ updatingMe = false;
+}
+
void QDeclarativeAnchorsPrivate::updateMe()
{
if (updatingMe) {
diff --git a/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h b/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h
index d9d7ffa..5840868 100644
--- a/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h
@@ -59,12 +59,9 @@
QT_BEGIN_NAMESPACE
-class QDeclarativeAnchorLine
+struct QDeclarativeAnchorLine
{
-public:
- QDeclarativeAnchorLine() : item(0), anchorLine(Invalid)
- {
- }
+ QDeclarativeAnchorLine() : item(0), anchorLine(Invalid) {}
enum AnchorLine {
Invalid = 0x0,
@@ -81,27 +78,22 @@ public:
QDeclarativeItem *item;
AnchorLine anchorLine;
-
- bool operator==(const QDeclarativeAnchorLine& other) const
- {
- return item == other.item && anchorLine == other.anchorLine;
- }
};
+inline bool operator==(const QDeclarativeAnchorLine& a, const QDeclarativeAnchorLine& b)
+{
+ return a.item == b.item && a.anchorLine == b.anchorLine;
+}
+
class QDeclarativeAnchorsPrivate : public QObjectPrivate, public QDeclarativeItemChangeListener
{
Q_DECLARE_PUBLIC(QDeclarativeAnchors)
public:
QDeclarativeAnchorsPrivate(QDeclarativeItem *i)
- : updatingMe(false), updatingHorizontalAnchor(0),
+ : componentComplete(true), updatingMe(false), updatingHorizontalAnchor(0),
updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(i), usedAnchors(0), fill(0),
centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
- margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0),
- componentComplete(true)
- {
- }
-
- void init()
+ margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)
{
}
@@ -111,17 +103,19 @@ public:
void remDepend(QDeclarativeItem *);
bool isItemComplete() const;
- bool updatingMe;
- int updatingHorizontalAnchor;
- int updatingVerticalAnchor;
- int updatingFill;
- int updatingCenterIn;
+ bool componentComplete:1;
+ bool updatingMe:1;
+ uint updatingHorizontalAnchor:2;
+ uint updatingVerticalAnchor:2;
+ uint updatingFill:2;
+ uint updatingCenterIn:2;
void setItemHeight(qreal);
void setItemWidth(qreal);
void setItemX(qreal);
void setItemY(qreal);
void setItemPos(const QPointF &);
+ void setItemSize(const QSizeF &);
void updateOnComplete();
void updateMe();
@@ -163,8 +157,6 @@ public:
qreal vCenterOffset;
qreal hCenterOffset;
qreal baselineOffset;
-
- bool componentComplete;
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
index 20b1de3..2c2e034 100644
--- a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
@@ -247,9 +247,25 @@ void QDeclarativeAnimatedImage::setSource(const QUrl &url)
emit statusChanged(d->status);
}
+#define ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION 16
+
void QDeclarativeAnimatedImage::movieRequestFinished()
{
Q_D(QDeclarativeAnimatedImage);
+
+ d->redirectCount++;
+ if (d->redirectCount < ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION) {
+ QVariant redirect = d->reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirect.isValid()) {
+ QUrl url = d->reply->url().resolved(redirect.toUrl());
+ d->reply->deleteLater();
+ d->reply = 0;
+ setSource(url);
+ return;
+ }
+ }
+ d->redirectCount=0;
+
d->_movie = new QMovie(d->reply);
if (!d->_movie->isValid()){
qWarning() << "Error Reading Animated Image File " << d->url;
diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h
index 39bb3e5..273c1d6 100644
--- a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h
@@ -66,7 +66,7 @@ class QDeclarativeAnimatedImagePrivate : public QDeclarativeImagePrivate
public:
QDeclarativeAnimatedImagePrivate()
- : playing(true), paused(false), preset_currentframe(0), _movie(0), reply(0)
+ : playing(true), paused(false), preset_currentframe(0), _movie(0), reply(0), redirectCount(0)
{
}
@@ -75,6 +75,7 @@ public:
int preset_currentframe;
QMovie *_movie;
QNetworkReply *reply;
+ int redirectCount;
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
index de16668..a7534b8 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
@@ -191,7 +191,7 @@ void QDeclarativeBorderImage::load()
update();
} else {
d->status = Loading;
- if (d->url.path().endsWith(QLatin1String(".sci"))) {
+ if (d->url.path().endsWith(QLatin1String("sci"))) {
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
QString lf = toLocalFileOrQrc(d->url);
if (!lf.isEmpty()) {
@@ -400,9 +400,23 @@ void QDeclarativeBorderImage::requestFinished()
update();
}
+#define BORDERIMAGE_MAX_REDIRECT 16
+
void QDeclarativeBorderImage::sciRequestFinished()
{
Q_D(QDeclarativeBorderImage);
+
+ d->redirectCount++;
+ if (d->redirectCount < BORDERIMAGE_MAX_REDIRECT) {
+ QVariant redirect = d->sciReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirect.isValid()) {
+ QUrl url = d->sciReply->url().resolved(redirect.toUrl());
+ setSource(url);
+ return;
+ }
+ }
+ d->redirectCount=0;
+
if (d->sciReply->error() != QNetworkReply::NoError) {
d->status = Error;
d->sciReply->deleteLater();
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h b/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h
index b9cf73a..82b9ebf 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h
@@ -68,7 +68,8 @@ public:
: border(0), sciReply(0),
sciPendingPixmapCache(false),
horizontalTileMode(QDeclarativeBorderImage::Stretch),
- verticalTileMode(QDeclarativeBorderImage::Stretch)
+ verticalTileMode(QDeclarativeBorderImage::Stretch),
+ redirectCount(0)
{
}
@@ -90,6 +91,7 @@ public:
bool sciPendingPixmapCache;
QDeclarativeBorderImage::TileMode horizontalTileMode;
QDeclarativeBorderImage::TileMode verticalTileMode;
+ int redirectCount;
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index 67068a0..9ccb3b6 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -264,6 +264,7 @@ void QDeclarativeFlickablePrivate::fixupY()
void QDeclarativeFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent)
{
+ Q_Q(QDeclarativeFlickable);
if (data.move.value() > minExtent || maxExtent > minExtent) {
timeline.reset(data.move);
if (data.move.value() != minExtent) {
@@ -273,6 +274,7 @@ void QDeclarativeFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal
timeline.move(data.move, minExtent, QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4);
} else {
data.move.setValue(minExtent);
+ q->viewportMoved();
}
}
//emit flickingChanged();
@@ -284,6 +286,7 @@ void QDeclarativeFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal
timeline.move(data.move, maxExtent, QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4);
} else {
data.move.setValue(maxExtent);
+ q->viewportMoved();
}
//emit flickingChanged();
} else {
diff --git a/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp b/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp
index 0323a59..20524b6 100644
--- a/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp
+++ b/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp
@@ -41,6 +41,8 @@
#include "qdeclarativefocuspanel_p.h"
+#include "qdeclarativeitem_p.h"
+
#include <QtGui/qgraphicsscene.h>
#include <QEvent>
@@ -65,7 +67,8 @@ QT_BEGIN_NAMESPACE
QDeclarativeFocusPanel::QDeclarativeFocusPanel(QDeclarativeItem *parent) :
QDeclarativeItem(parent)
{
- setFlag(ItemIsPanel);
+ Q_D(QDeclarativeItem);
+ d->flags |= QGraphicsItem::ItemIsPanel;
}
QDeclarativeFocusPanel::~QDeclarativeFocusPanel()
diff --git a/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h b/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h
index 1ad8b6e..d9ca0b0 100644
--- a/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h
+++ b/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h
@@ -66,6 +66,7 @@ protected:
private:
Q_DISABLE_COPY(QDeclarativeFocusPanel)
+ Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem)
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativefocusscope.cpp b/src/declarative/graphicsitems/qdeclarativefocusscope.cpp
index 384a47b..484df13 100644
--- a/src/declarative/graphicsitems/qdeclarativefocusscope.cpp
+++ b/src/declarative/graphicsitems/qdeclarativefocusscope.cpp
@@ -41,6 +41,8 @@
#include "qdeclarativefocusscope_p.h"
+#include "qdeclarativeitem_p.h"
+
QT_BEGIN_NAMESPACE
/*!
@@ -62,7 +64,8 @@ QT_BEGIN_NAMESPACE
QDeclarativeFocusScope::QDeclarativeFocusScope(QDeclarativeItem *parent) :
QDeclarativeItem(parent)
{
- setFlag(QGraphicsItem::ItemIsFocusScope);
+ Q_D(QDeclarativeItem);
+ d->flags |= QGraphicsItem::ItemIsFocusScope;
}
QDeclarativeFocusScope::~QDeclarativeFocusScope()
diff --git a/src/declarative/graphicsitems/qdeclarativefocusscope_p.h b/src/declarative/graphicsitems/qdeclarativefocusscope_p.h
index cd480b4..c65a07c 100644
--- a/src/declarative/graphicsitems/qdeclarativefocusscope_p.h
+++ b/src/declarative/graphicsitems/qdeclarativefocusscope_p.h
@@ -54,6 +54,7 @@ QT_MODULE(Declarative)
class Q_DECLARATIVE_EXPORT QDeclarativeFocusScope : public QDeclarativeItem
{
Q_OBJECT
+ Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem)
public:
QDeclarativeFocusScope(QDeclarativeItem *parent=0);
virtual ~QDeclarativeFocusScope();
diff --git a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp
index 1977817..eb5b6ce 100644
--- a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp
@@ -65,12 +65,12 @@ public:
if (graphicsObject && graphicsObject->isWidget()) {
if (!on) {
graphicsObject->removeEventFilter(q);
- QObject::disconnect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize()));
- QObject::disconnect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize()));
+ QObject::disconnect(q, SIGNAL(widthChanged(qreal)), q, SLOT(_q_updateSize()));
+ QObject::disconnect(q, SIGNAL(heightChanged(qreal)), q, SLOT(_q_updateSize()));
} else {
graphicsObject->installEventFilter(q);
- QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize()));
- QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize()));
+ QObject::connect(q, SIGNAL(widthChanged(qreal)), q, SLOT(_q_updateSize()));
+ QObject::connect(q, SIGNAL(heightChanged(qreal)), q, SLOT(_q_updateSize()));
}
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 76ad9b7..b1391f9 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -50,6 +50,8 @@
#include <qlistmodelinterface_p.h>
#include <QKeyEvent>
+#include <math.h>
+
QT_BEGIN_NAMESPACE
@@ -95,14 +97,15 @@ class QDeclarativeGridViewPrivate : public QDeclarativeFlickablePrivate
public:
QDeclarativeGridViewPrivate()
: currentItem(0), flow(QDeclarativeGridView::LeftToRight)
- , visiblePos(0), visibleIndex(0) , currentIndex(-1)
+ , visibleIndex(0) , currentIndex(-1)
, cellWidth(100), cellHeight(100), columns(1), requestedIndex(-1)
+ , highlightRangeStart(0), highlightRangeEnd(0), highlightRange(QDeclarativeGridView::NoHighlightRange)
, highlightComponent(0), highlight(0), trackedItem(0)
, moveReason(Other), buffer(0), highlightXAnimator(0), highlightYAnimator(0)
- , bufferMode(NoBuffer)
+ , bufferMode(NoBuffer), snapMode(QDeclarativeGridView::NoSnap)
, ownModel(false), wrap(false), autoHighlight(true)
, fixCurrentVisibility(false), lazyRelease(false), layoutScheduled(false)
- , deferredRelease(false) {}
+ , deferredRelease(false), haveHighlightRange(false) {}
void init();
void clear();
@@ -119,6 +122,7 @@ public:
void createHighlight();
void updateHighlight();
void updateCurrent(int modelIndex);
+ void fixupPosition();
FxGridItem *visibleItem(int modelIndex) const {
if (modelIndex >= visibleIndex && modelIndex < visibleIndex + visibleItems.count()) {
@@ -236,7 +240,33 @@ public:
return -1; // Not in visibleList
}
- void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
+ qreal snapPosAt(qreal pos) {
+ qreal snapPos = 0;
+ if (!visibleItems.isEmpty()) {
+ pos += rowSize()/2;
+ snapPos = visibleItems.first()->rowPos() - visibleIndex / columns * rowSize();
+ snapPos = pos - fmodf(pos - snapPos, qreal(rowSize()));
+ }
+ return snapPos;
+ }
+
+ int snapIndex() {
+ int index = currentIndex;
+ for (int i = 0; i < visibleItems.count(); ++i) {
+ FxGridItem *item = visibleItems[i];
+ if (item->index == -1)
+ continue;
+ qreal itemTop = item->rowPos();
+ if (itemTop >= highlight->rowPos()-rowSize()/2 && itemTop < highlight->rowPos()+rowSize()/2) {
+ index = item->index;
+ if (item->colPos() >= highlight->colPos()-colSize()/2 && item->colPos() < highlight->colPos()+colSize()/2)
+ return item->index;
+ }
+ }
+ return index;
+ }
+
+ virtual void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
Q_Q(const QDeclarativeGridView);
QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry);
if (item == q) {
@@ -249,6 +279,11 @@ public:
}
}
}
+
+ virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
+ virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
+ QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity);
+
// for debugging only
void checkVisible() const {
int skip = 0;
@@ -270,13 +305,15 @@ public:
QHash<QDeclarativeItem*,int> unrequestedItems;
FxGridItem *currentItem;
QDeclarativeGridView::Flow flow;
- int visiblePos;
int visibleIndex;
int currentIndex;
int cellWidth;
int cellHeight;
int columns;
int requestedIndex;
+ qreal highlightRangeStart;
+ qreal highlightRangeEnd;
+ QDeclarativeGridView::HighlightRangeMode highlightRange;
QDeclarativeComponent *highlightComponent;
FxGridItem *highlight;
FxGridItem *trackedItem;
@@ -287,6 +324,7 @@ public:
QDeclarativeEaseFollow *highlightYAnimator;
enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
BufferMode bufferMode;
+ QDeclarativeGridView::SnapMode snapMode;
bool ownModel : 1;
bool wrap : 1;
@@ -295,6 +333,7 @@ public:
bool lazyRelease : 1;
bool layoutScheduled : 1;
bool deferredRelease : 1;
+ bool haveHighlightRange : 1;
};
void QDeclarativeGridViewPrivate::init()
@@ -310,7 +349,6 @@ void QDeclarativeGridViewPrivate::clear()
for (int i = 0; i < visibleItems.count(); ++i)
releaseItem(visibleItems.at(i));
visibleItems.clear();
- visiblePos = 0;
visibleIndex = 0;
releaseItem(currentItem);
currentItem = 0;
@@ -496,7 +534,7 @@ void QDeclarativeGridViewPrivate::scheduleLayout()
Q_Q(QDeclarativeGridView);
if (!layoutScheduled) {
layoutScheduled = true;
- QMetaObject::invokeMethod(q, "layout", Qt::QueuedConnection);
+ QCoreApplication::postEvent(q, new QEvent(QEvent::User), Qt::HighEventPriority);
}
}
@@ -683,6 +721,128 @@ void QDeclarativeGridViewPrivate::updateCurrent(int modelIndex)
releaseItem(oldCurrentItem);
}
+void QDeclarativeGridViewPrivate::fixupPosition()
+{
+ moveReason = Other;
+ if (flow == QDeclarativeGridView::LeftToRight)
+ fixupY();
+ else
+ fixupX();
+}
+
+void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent)
+{
+ Q_Q(QDeclarativeGridView);
+
+ if ((&data == &vData && !q->yflick())
+ || (&data == &hData && !q->xflick())
+ || data.move.timeLine())
+ return;
+
+ int oldDuration = fixupDuration;
+ fixupDuration = moveReason == Mouse ? fixupDuration : 0;
+
+ if (haveHighlightRange && highlightRange == QDeclarativeGridView::StrictlyEnforceRange) {
+ if (currentItem && currentItem->rowPos() - position() != highlightRangeStart) {
+ qreal pos = currentItem->rowPos() - highlightRangeStart;
+ timeline.reset(data.move);
+ if (fixupDuration) {
+ timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
+ } else {
+ data.move.setValue(-pos);
+ q->viewportMoved();
+ }
+ vTime = timeline.time();
+ }
+ } else if (snapMode != QDeclarativeGridView::NoSnap) {
+ qreal pos = -snapPosAt(-(data.move.value() - highlightRangeStart)) + highlightRangeStart;
+ pos = qMin(qMax(pos, maxExtent), minExtent);
+ qreal dist = qAbs(data.move.value() - pos);
+ if (dist > 0) {
+ timeline.reset(data.move);
+ if (fixupDuration) {
+ timeline.move(data.move, pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
+ } else {
+ data.move.setValue(pos);
+ q->viewportMoved();
+ }
+ vTime = timeline.time();
+ }
+ } else {
+ QDeclarativeFlickablePrivate::fixup(data, minExtent, maxExtent);
+ }
+ fixupDuration = oldDuration;
+}
+
+void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
+ QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity)
+{
+ Q_Q(QDeclarativeGridView);
+
+ moveReason = Mouse;
+ if ((!haveHighlightRange || highlightRange != QDeclarativeGridView::StrictlyEnforceRange) && snapMode == QDeclarativeGridView::NoSnap) {
+ QDeclarativeFlickablePrivate::flick(data, minExtent, maxExtent, vSize, fixupCallback, velocity);
+ return;
+ }
+ qreal maxDistance = -1;
+ // -ve velocity means list is moving up
+ if (velocity > 0) {
+ if (snapMode == QDeclarativeGridView::SnapOneRow) {
+ if (FxGridItem *item = firstVisibleItem())
+ maxDistance = qAbs(item->rowPos() + data.move.value());
+ } else if (data.move.value() < minExtent) {
+ maxDistance = qAbs(minExtent - data.move.value());
+ }
+ if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange)
+ data.flickTarget = minExtent;
+ } else {
+ if (snapMode == QDeclarativeGridView::SnapOneRow) {
+ qreal pos = snapPosAt(-data.move.value()) + rowSize();
+ maxDistance = qAbs(pos + data.move.value());
+ } else if (data.move.value() > maxExtent) {
+ maxDistance = qAbs(maxExtent - data.move.value());
+ }
+ if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange)
+ data.flickTarget = maxExtent;
+ }
+ if (maxDistance > 0 && (snapMode != QDeclarativeGridView::NoSnap || highlightRange == QDeclarativeGridView::StrictlyEnforceRange)) {
+ // This mode requires the grid to stop exactly on a row boundary.
+ qreal v = velocity;
+ if (maxVelocity != -1 && maxVelocity < qAbs(v)) {
+ if (v < 0)
+ v = -maxVelocity;
+ else
+ v = maxVelocity;
+ }
+ qreal accel = deceleration;
+ qreal v2 = v * v;
+ qreal maxAccel = v2 / (2.0f * maxDistance);
+ qreal overshootDist = 0.0;
+ if (maxAccel < accel) {
+ // + rowSize()/4 to encourage moving at least one item in the flick direction
+ qreal dist = v2 / (accel * 2.0) + rowSize()/4;
+ if (v > 0)
+ dist = -dist;
+ data.flickTarget = -snapPosAt(-(data.move.value() - highlightRangeStart) + dist) + highlightRangeStart;
+ dist = -data.flickTarget + data.move.value();
+ accel = v2 / (2.0f * qAbs(dist));
+ } else {
+ data.flickTarget = velocity > 0 ? minExtent : maxExtent;
+ overshootDist = overShoot ? overShootDistance(v, vSize) : 0;
+ }
+ timeline.reset(data.move);
+ timeline.accel(data.move, v, accel, maxDistance + overshootDist);
+ timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this));
+ flicked = true;
+ emit q->flickingChanged();
+ emit q->flickStarted();
+ } else {
+ timeline.reset(data.move);
+ fixup(data, minExtent, maxExtent);
+ }
+}
+
+
//----------------------------------------------------------------------------
/*!
@@ -1031,6 +1191,87 @@ void QDeclarativeGridView::setHighlightFollowsCurrentItem(bool autoHighlight)
}
/*!
+ \qmlproperty real GridView::preferredHighlightBegin
+ \qmlproperty real GridView::preferredHighlightEnd
+ \qmlproperty enumeration GridView::highlightRangeMode
+
+ These properties set the preferred range of the highlight (current item)
+ within the view.
+
+ Note that this is the correct way to influence where the
+ current item ends up when the view scrolls. For example, if you want the
+ currently selected item to be in the middle of the list, then set the
+ highlight range to be where the middle item would go. Then, when the view scrolls,
+ the currently selected item will be the item at that spot. This also applies to
+ when the currently selected item changes - it will scroll to within the preferred
+ highlight range. Furthermore, the behaviour of the current item index will occur
+ whether or not a highlight exists.
+
+ If highlightRangeMode is set to \e ApplyRange the view will
+ attempt to maintain the highlight within the range, however
+ the highlight can move outside of the range at the ends of the list
+ or due to a mouse interaction.
+
+ If highlightRangeMode is set to \e StrictlyEnforceRange the highlight will never
+ move outside of the range. This means that the current item will change
+ if a keyboard or mouse action would cause the highlight to move
+ outside of the range.
+
+ The default value is \e NoHighlightRange.
+
+ Note that a valid range requires preferredHighlightEnd to be greater
+ than or equal to preferredHighlightBegin.
+*/
+qreal QDeclarativeGridView::preferredHighlightBegin() const
+{
+ Q_D(const QDeclarativeGridView);
+ return d->highlightRangeStart;
+}
+
+void QDeclarativeGridView::setPreferredHighlightBegin(qreal start)
+{
+ Q_D(QDeclarativeGridView);
+ if (d->highlightRangeStart == start)
+ return;
+ d->highlightRangeStart = start;
+ d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd;
+ emit preferredHighlightBeginChanged();
+}
+
+qreal QDeclarativeGridView::preferredHighlightEnd() const
+{
+ Q_D(const QDeclarativeGridView);
+ return d->highlightRangeEnd;
+}
+
+void QDeclarativeGridView::setPreferredHighlightEnd(qreal end)
+{
+ Q_D(QDeclarativeGridView);
+ if (d->highlightRangeEnd == end)
+ return;
+ d->highlightRangeEnd = end;
+ d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd;
+ emit preferredHighlightEndChanged();
+}
+
+QDeclarativeGridView::HighlightRangeMode QDeclarativeGridView::highlightRangeMode() const
+{
+ Q_D(const QDeclarativeGridView);
+ return d->highlightRange;
+}
+
+void QDeclarativeGridView::setHighlightRangeMode(HighlightRangeMode mode)
+{
+ Q_D(QDeclarativeGridView);
+ if (d->highlightRange == mode)
+ return;
+ d->highlightRange = mode;
+ d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd;
+ emit highlightRangeModeChanged();
+}
+
+
+/*!
\qmlproperty enumeration GridView::flow
This property holds the flow of the grid.
@@ -1153,6 +1394,47 @@ void QDeclarativeGridView::setCellHeight(int cellHeight)
d->layout();
}
}
+/*!
+ \qmlproperty enumeration GridView::snapMode
+
+ This property determines where the view will settle following a drag or flick.
+ The allowed values are:
+
+ \list
+ \o NoSnap (default) - the view will stop anywhere within the visible area.
+ \o SnapToRow - the view will settle with a row (or column for TopToBottom flow)
+ aligned with the start of the view.
+ \o SnapOneRow - the view will settle no more than one row (or column for TopToBottom flow)
+ away from the first visible row at the time the mouse button is released.
+ This mode is particularly useful for moving one page at a time.
+ \endlist
+
+*/
+QDeclarativeGridView::SnapMode QDeclarativeGridView::snapMode() const
+{
+ Q_D(const QDeclarativeGridView);
+ return d->snapMode;
+}
+
+void QDeclarativeGridView::setSnapMode(SnapMode mode)
+{
+ Q_D(QDeclarativeGridView);
+ if (d->snapMode != mode) {
+ d->snapMode = mode;
+ emit snapModeChanged();
+ }
+}
+
+bool QDeclarativeGridView::event(QEvent *event)
+{
+ Q_D(QDeclarativeGridView);
+ if (event->type() == QEvent::User) {
+ d->layout();
+ return true;
+ }
+
+ return QDeclarativeFlickable::event(event);
+}
void QDeclarativeGridView::viewportMoved()
{
@@ -1175,6 +1457,32 @@ void QDeclarativeGridView::viewportMoved()
}
}
refill();
+ if (isFlicking() || d->moving)
+ d->moveReason = QDeclarativeGridViewPrivate::Mouse;
+ if (d->moveReason != QDeclarativeGridViewPrivate::SetIndex) {
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) {
+ // reposition highlight
+ qreal pos = d->highlight->rowPos();
+ qreal viewPos = qRound(d->position());
+ if (pos > viewPos + d->highlightRangeEnd - 1 - d->rowSize())
+ pos = viewPos + d->highlightRangeEnd - 1 - d->rowSize();
+ if (pos < viewPos + d->highlightRangeStart)
+ pos = viewPos + d->highlightRangeStart;
+ d->highlight->setPosition(d->highlight->colPos(), pos);
+
+ // update current index
+ int idx = d->snapIndex();
+ if (idx >= 0 && idx != d->currentIndex) {
+ d->updateCurrent(idx);
+ if (d->currentItem && d->currentItem->colPos() != d->highlight->colPos() && d->autoHighlight) {
+ if (d->flow == LeftToRight)
+ d->highlightXAnimator->setSourceValue(d->currentItem->item->x());
+ else
+ d->highlightYAnimator->setSourceValue(d->currentItem->item->y());
+ }
+ }
+ }
+ }
}
qreal QDeclarativeGridView::minYExtent() const
@@ -1182,7 +1490,10 @@ qreal QDeclarativeGridView::minYExtent() const
Q_D(const QDeclarativeGridView);
if (d->flow == QDeclarativeGridView::TopToBottom)
return QDeclarativeFlickable::minYExtent();
- return -d->startPosition();
+ qreal extent = -d->startPosition();
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ extent += d->highlightRangeStart;
+ return extent;
}
qreal QDeclarativeGridView::maxYExtent() const
@@ -1190,7 +1501,11 @@ qreal QDeclarativeGridView::maxYExtent() const
Q_D(const QDeclarativeGridView);
if (d->flow == QDeclarativeGridView::TopToBottom)
return QDeclarativeFlickable::maxYExtent();
- qreal extent = -(d->endPosition() - height());
+ qreal extent;
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ extent = -(d->rowPosAt(count()-1) - d->highlightRangeEnd);
+ else
+ extent = -(d->endPosition() - height());
const qreal minY = minYExtent();
if (extent > minY)
extent = minY;
@@ -1202,7 +1517,10 @@ qreal QDeclarativeGridView::minXExtent() const
Q_D(const QDeclarativeGridView);
if (d->flow == QDeclarativeGridView::LeftToRight)
return QDeclarativeFlickable::minXExtent();
- return -d->startPosition();
+ qreal extent = -d->startPosition();
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ extent += d->highlightRangeStart;
+ return extent;
}
qreal QDeclarativeGridView::maxXExtent() const
@@ -1210,7 +1528,11 @@ qreal QDeclarativeGridView::maxXExtent() const
Q_D(const QDeclarativeGridView);
if (d->flow == QDeclarativeGridView::LeftToRight)
return QDeclarativeFlickable::maxXExtent();
- qreal extent = -(d->endPosition() - width());
+ qreal extent;
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ extent = -(d->rowPosAt(count()-1) - d->highlightRangeEnd);
+ else
+ extent = -(d->endPosition() - height());
const qreal minX = minXExtent();
if (extent > minX)
extent = minX;
@@ -1344,46 +1666,84 @@ void QDeclarativeGridView::moveCurrentIndexRight()
}
/*!
- \qmlmethod GridView::positionViewAtIndex(int index)
+ \qmlmethod GridView::positionViewAtIndex(int index, PositionMode mode)
+
+ Positions the view such that the \a index is at the position specified by
+ \a mode:
+
+ \list
+ \o Beginning - position item at the top (or left for TopToBottom flow) of the view.
+ \o Center- position item in the center of the view.
+ \o End - position item at bottom (or right for horizontal orientation) of the view.
+ \o Visible - if any part of the item is visible then take no action, otherwise
+ bring the item into view.
+ \o Contain - ensure the entire item is visible. If the item is larger than
+ the view the item is positioned at the top (or left for TopToBottom flow) of the view.
+ \endlist
- Positions the view such that the \a index is at the top (or left for horizontal orientation) of the view.
If positioning the view at the index would cause empty space to be displayed at
- the end of the view, the view will be positioned at the end.
+ the beginning or end of the view, the view will be positioned at the boundary.
It is not recommended to use contentX or contentY to position the view
at a particular index. This is unreliable since removing items from the start
- of the list does not cause all other items to be repositioned.
+ of the view does not cause all other items to be repositioned.
The correct way to bring an item into view is with positionViewAtIndex.
*/
-void QDeclarativeGridView::positionViewAtIndex(int index)
+void QDeclarativeGridView::positionViewAtIndex(int index, int mode)
{
Q_D(QDeclarativeGridView);
if (!d->isValid() || index < 0 || index >= d->model->count())
return;
+ if (mode < Beginning || mode > Contain)
+ return;
- qreal maxExtent = d->flow == QDeclarativeGridView::LeftToRight ? -maxYExtent() : -maxXExtent();
+ qreal pos = d->position();
FxGridItem *item = d->visibleItem(index);
- if (item) {
- // Already created - just move to top of view
- int pos = qMin(item->rowPos(), maxExtent);
- d->setPosition(pos);
- } else {
- int pos = d->rowPosAt(index);
+ if (!item) {
+ int itemPos = d->rowPosAt(index);
// save the currently visible items in case any of them end up visible again
QList<FxGridItem*> oldVisible = d->visibleItems;
d->visibleItems.clear();
d->visibleIndex = index - index % d->columns;
- d->setPosition(pos);
- // setPosition() will cause refill. Adjust if we have moved beyond range
- if (d->position() > maxExtent)
- d->setPosition(maxExtent);
+ d->setPosition(itemPos);
// now release the reference to all the old visible items.
for (int i = 0; i < oldVisible.count(); ++i)
d->releaseItem(oldVisible.at(i));
+ item = d->visibleItem(index);
}
+ if (item) {
+ qreal itemPos = item->rowPos();
+ switch (mode) {
+ case Beginning:
+ pos = itemPos;
+ break;
+ case Center:
+ pos = itemPos - (d->size() - d->rowSize())/2;
+ break;
+ case End:
+ pos = itemPos - d->size() + d->rowSize();
+ break;
+ case Visible:
+ if (itemPos > pos + d->size())
+ pos = itemPos - d->size() + d->rowSize();
+ else if (item->endRowPos() < pos)
+ pos = itemPos;
+ break;
+ case Contain:
+ if (item->endRowPos() > pos + d->size())
+ pos = itemPos - d->size() + d->rowSize();
+ if (itemPos < pos)
+ pos = itemPos;
+ }
+ qreal maxExtent = d->flow == QDeclarativeGridView::LeftToRight ? -maxYExtent() : -maxXExtent();
+ pos = qMin(pos, maxExtent);
+ qreal minExtent = d->flow == QDeclarativeGridView::LeftToRight ? -minYExtent() : -minXExtent();
+ pos = qMax(pos, minExtent);
+ d->setPosition(pos);
+ }
+ d->fixupPosition();
}
-
void QDeclarativeGridView::componentComplete()
{
Q_D(QDeclarativeGridView);
@@ -1394,6 +1754,7 @@ void QDeclarativeGridView::componentComplete()
d->updateCurrent(0);
else
d->updateCurrent(d->currentIndex);
+ d->fixupPosition();
}
void QDeclarativeGridView::trackedPositionChanged()
@@ -1402,22 +1763,50 @@ void QDeclarativeGridView::trackedPositionChanged()
if (!d->trackedItem || !d->currentItem)
return;
if (!isFlicking() && !d->moving && d->moveReason == QDeclarativeGridViewPrivate::SetIndex) {
+ const qreal trackedPos = d->trackedItem->rowPos();
const qreal viewPos = d->position();
- if (d->trackedItem->rowPos() < viewPos && d->currentItem->rowPos() < viewPos) {
- d->setPosition(d->currentItem->rowPos() < d->trackedItem->rowPos() ? d->trackedItem->rowPos() : d->currentItem->rowPos());
- } else if (d->trackedItem->endRowPos() > viewPos + d->size()
- && d->currentItem->endRowPos() > viewPos + d->size()) {
- qreal pos;
- if (d->trackedItem->endRowPos() < d->currentItem->endRowPos()) {
- pos = d->trackedItem->endRowPos() - d->size();
- if (d->rowSize() > d->size())
- pos = d->trackedItem->rowPos();
+ if (d->haveHighlightRange) {
+ if (d->highlightRange == StrictlyEnforceRange) {
+ qreal pos = viewPos;
+ if (trackedPos > pos + d->highlightRangeEnd - d->rowSize())
+ pos = trackedPos - d->highlightRangeEnd + d->rowSize();
+ if (trackedPos < pos + d->highlightRangeStart)
+ pos = trackedPos - d->highlightRangeStart;
+ d->setPosition(pos);
} else {
- pos = d->currentItem->endRowPos() - d->size();
- if (d->rowSize() > d->size())
- pos = d->currentItem->rowPos();
+ qreal pos = viewPos;
+ if (trackedPos < d->startPosition() + d->highlightRangeStart) {
+ pos = d->startPosition();
+ } else if (d->trackedItem->endRowPos() > d->endPosition() - d->size() + d->highlightRangeEnd) {
+ pos = d->endPosition() - d->size();
+ if (pos < d->startPosition())
+ pos = d->startPosition();
+ } else {
+ if (trackedPos < viewPos + d->highlightRangeStart) {
+ pos = trackedPos - d->highlightRangeStart;
+ } else if (trackedPos > viewPos + d->highlightRangeEnd - d->rowSize()) {
+ pos = trackedPos - d->highlightRangeEnd + d->rowSize();
+ }
+ }
+ d->setPosition(pos);
+ }
+ } else {
+ if (trackedPos < viewPos && d->currentItem->rowPos() < viewPos) {
+ d->setPosition(d->currentItem->rowPos() < trackedPos ? trackedPos : d->currentItem->rowPos());
+ } else if (d->trackedItem->endRowPos() > viewPos + d->size()
+ && d->currentItem->endRowPos() > viewPos + d->size()) {
+ qreal pos;
+ if (d->trackedItem->endRowPos() < d->currentItem->endRowPos()) {
+ pos = d->trackedItem->endRowPos() - d->size();
+ if (d->rowSize() > d->size())
+ pos = trackedPos;
+ } else {
+ pos = d->currentItem->endRowPos() - d->size();
+ if (d->rowSize() > d->size())
+ pos = d->currentItem->rowPos();
+ }
+ d->setPosition(pos);
}
- d->setPosition(pos);
}
}
}
@@ -1426,7 +1815,7 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
{
Q_D(QDeclarativeGridView);
if (!d->visibleItems.count() || d->model->count() <= 1) {
- refill();
+ d->scheduleLayout();
d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1)));
emit countChanged();
return;
@@ -1455,8 +1844,9 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
d->currentIndex += count;
if (d->currentItem)
d->currentItem->index = d->currentIndex;
+ emit currentIndexChanged();
}
- d->layout();
+ d->scheduleLayout();
emit countChanged();
return;
}
@@ -1486,9 +1876,21 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
}
}
+ // Update the indexes of the following visible items.
+ for (int i = 0; i < d->visibleItems.count(); ++i) {
+ FxGridItem *listItem = d->visibleItems.at(i);
+ if (listItem->index != -1 && listItem->index >= modelIndex)
+ listItem->index += count;
+ }
+
+ bool addedVisible = false;
QList<FxGridItem*> added;
int i = 0;
while (i < insertCount && rowPos <= to + d->rowSize()*(d->columns - (colPos/d->colSize()))/qreal(d->columns)) {
+ if (!addedVisible) {
+ d->scheduleLayout();
+ addedVisible = true;
+ }
FxGridItem *item = d->createItem(modelIndex + i);
d->visibleItems.insert(index, item);
item->setPosition(colPos, rowPos);
@@ -1509,6 +1911,15 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
}
}
+ // update visibleIndex
+ d->visibleIndex = 0;
+ for (QList<FxGridItem*>::Iterator it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) {
+ if ((*it)->index != -1) {
+ d->visibleIndex = (*it)->index;
+ break;
+ }
+ }
+
if (d->currentIndex >= modelIndex) {
// adjust current item index
d->currentIndex += count;
@@ -1516,18 +1927,13 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
d->currentItem->index = d->currentIndex;
d->currentItem->setPosition(d->colPosAt(d->currentIndex), d->rowPosAt(d->currentIndex));
}
- }
- // Update the indexes of the following visible items.
- for (; index < d->visibleItems.count(); ++index) {
- FxGridItem *listItem = d->visibleItems.at(index);
- if (listItem->index != -1)
- listItem->index += count;
+ emit currentIndexChanged();
}
// everything is in order now - emit add() signal
for (int j = 0; j < added.count(); ++j)
added.at(j)->attached->emitAdd();
- d->layout();
+
emit countChanged();
}
@@ -1543,8 +1949,10 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count)
FxGridItem *item = *it;
if (item->index == -1 || item->index < modelIndex) {
// already removed, or before removed items
- if (item->index < modelIndex)
+ if (item->index < modelIndex && !removedVisible) {
+ d->scheduleLayout();
removedVisible = true;
+ }
++it;
} else if (item->index >= modelIndex + count) {
// after removed items
@@ -1552,7 +1960,10 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count)
++it;
} else {
// removed item
- removedVisible = true;
+ if (!removedVisible) {
+ d->scheduleLayout();
+ removedVisible = true;
+ }
item->attached->emitRemove();
if (item->attached->delayRemove()) {
item->index = -1;
@@ -1570,6 +1981,7 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count)
d->currentIndex -= count;
if (d->currentItem)
d->currentItem->index -= count;
+ emit currentIndexChanged();
} else if (currentRemoved) {
// current item has been removed.
d->releaseItem(d->currentItem);
@@ -1579,6 +1991,7 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count)
}
// update visibleIndex
+ d->visibleIndex = 0;
for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) {
if ((*it)->index != -1) {
d->visibleIndex = (*it)->index;
@@ -1586,27 +1999,16 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count)
}
}
- if (removedVisible) {
- if (d->visibleItems.isEmpty()) {
- d->visibleIndex = 0;
- d->setPosition(0);
- refill();
- } else {
- // Correct the positioning of the items
- d->scheduleLayout();
- }
+ if (removedVisible && d->visibleItems.isEmpty()) {
+ d->timeline.clear();
+ d->setPosition(0);
+ if (d->model->count() == 0)
+ update();
}
emit countChanged();
}
-void QDeclarativeGridView::layout()
-{
- Q_D(QDeclarativeGridView);
- if (d->layoutScheduled)
- d->layout();
-}
-
void QDeclarativeGridView::destroyRemoved()
{
Q_D(QDeclarativeGridView);
diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h
index 7255d3d..f14ec14 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h
@@ -67,11 +67,20 @@ class Q_DECLARATIVE_EXPORT QDeclarativeGridView : public QDeclarativeFlickable
Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem)
+ Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged)
+ Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged)
+ Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
+
Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged)
Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged)
+
+ Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
+
+ Q_ENUMS(HighlightRangeMode)
+ Q_ENUMS(SnapMode)
Q_CLASSINFO("DefaultProperty", "data")
public:
@@ -97,6 +106,16 @@ public:
bool highlightFollowsCurrentItem() const;
void setHighlightFollowsCurrentItem(bool);
+ enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
+ HighlightRangeMode highlightRangeMode() const;
+ void setHighlightRangeMode(HighlightRangeMode mode);
+
+ qreal preferredHighlightBegin() const;
+ void setPreferredHighlightBegin(qreal);
+
+ qreal preferredHighlightEnd() const;
+ void setPreferredHighlightEnd(qreal);
+
Q_ENUMS(Flow)
enum Flow { LeftToRight, TopToBottom };
Flow flow() const;
@@ -114,6 +133,13 @@ public:
int cellHeight() const;
void setCellHeight(int);
+ enum SnapMode { NoSnap, SnapToRow, SnapOneRow };
+ SnapMode snapMode() const;
+ void setSnapMode(SnapMode mode);
+
+ enum PositionMode { Beginning, Center, End, Visible, Contain };
+ Q_ENUMS(PositionMode)
+
static QDeclarativeGridViewAttached *qmlAttachedProperties(QObject *);
public Q_SLOTS:
@@ -121,7 +147,7 @@ public Q_SLOTS:
void moveCurrentIndexDown();
void moveCurrentIndexLeft();
void moveCurrentIndexRight();
- void positionViewAtIndex(int index);
+ void positionViewAtIndex(int index, int mode);
Q_SIGNALS:
void countChanged();
@@ -130,13 +156,18 @@ Q_SIGNALS:
void cellHeightChanged();
void highlightChanged();
void highlightItemChanged();
+ void preferredHighlightBeginChanged();
+ void preferredHighlightEndChanged();
+ void highlightRangeModeChanged();
void modelChanged();
void delegateChanged();
void flowChanged();
void keyNavigationWrapsChanged();
void cacheBufferChanged();
+ void snapModeChanged();
protected:
+ virtual bool event(QEvent *event);
virtual void viewportMoved();
virtual qreal minYExtent() const;
virtual qreal maxYExtent() const;
@@ -154,7 +185,6 @@ private Q_SLOTS:
void destroyRemoved();
void createdItem(int index, QDeclarativeItem *item);
void destroyingItem(QDeclarativeItem *item);
- void layout();
private:
void refill();
@@ -165,7 +195,7 @@ class QDeclarativeGridViewAttached : public QObject
Q_OBJECT
public:
QDeclarativeGridViewAttached(QObject *parent)
- : QObject(parent), m_isCurrent(false), m_delayRemove(false) {}
+ : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {}
~QDeclarativeGridViewAttached() {}
Q_PROPERTY(QDeclarativeGridView *view READ view CONSTANT)
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp
index a20d6bc..425976f 100644
--- a/src/declarative/graphicsitems/qdeclarativeimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp
@@ -386,7 +386,7 @@ void QDeclarativeImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWi
void QDeclarativeImage::pixmapChange()
{
updatePaintedGeometry();
- QDeclarativeImageBase::pixmapChange();
+ emit pixmapChanged();
}
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativeimage_p.h b/src/declarative/graphicsitems/qdeclarativeimage_p.h
index 7394774..da6cbd5 100644
--- a/src/declarative/graphicsitems/qdeclarativeimage_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeimage_p.h
@@ -79,6 +79,7 @@ public:
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
Q_SIGNALS:
+ void pixmapChanged();
void fillModeChanged();
void paintedGeometryChanged();
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
index 0e9638d..e65c9d1 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
@@ -144,19 +144,19 @@ void QDeclarativeImageBase::load()
static int thisRequestProgress = -1;
static int thisRequestFinished = -1;
if (replyDownloadProgress == -1) {
- replyDownloadProgress =
+ replyDownloadProgress =
QDeclarativePixmapReply::staticMetaObject.indexOfSignal("downloadProgress(qint64,qint64)");
- replyFinished =
+ replyFinished =
QDeclarativePixmapReply::staticMetaObject.indexOfSignal("finished()");
- thisRequestProgress =
+ thisRequestProgress =
QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)");
thisRequestFinished =
QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestFinished()");
}
- QMetaObject::connect(reply, replyFinished, this,
+ QMetaObject::connect(reply, replyFinished, this,
thisRequestFinished, Qt::DirectConnection);
- QMetaObject::connect(reply, replyDownloadProgress, this,
+ QMetaObject::connect(reply, replyDownloadProgress, this,
thisRequestProgress, Qt::DirectConnection);
} else {
//### should be unified with requestFinished
@@ -219,7 +219,6 @@ void QDeclarativeImageBase::componentComplete()
void QDeclarativeImageBase::pixmapChange()
{
- emit pixmapChanged();
}
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
index cfebdca..b215193 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
@@ -75,7 +75,6 @@ Q_SIGNALS:
void sourceChanged(const QUrl &);
void statusChanged(Status);
void progressChanged(qreal progress);
- void pixmapChanged();
void asynchronousChanged();
protected:
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 59dd43d..4ba80ad 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -273,7 +273,7 @@ void QDeclarativeContents::calcHeight()
m_height = qMax(bottom - top, qreal(0.0));
if (m_height != oldheight || m_y != oldy)
- emit rectChanged();
+ emit rectChanged(rectF());
}
//TODO: optimization: only check sender(), if there is one
@@ -301,7 +301,7 @@ void QDeclarativeContents::calcWidth()
m_width = qMax(right - left, qreal(0.0));
if (m_width != oldwidth || m_x != oldx)
- emit rectChanged();
+ emit rectChanged(rectF());
}
void QDeclarativeContents::setItem(QDeclarativeItem *item)
@@ -313,11 +313,11 @@ void QDeclarativeContents::setItem(QDeclarativeItem *item)
QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
continue;
- connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight()));
+ connect(child, SIGNAL(heightChanged(qreal)), this, SLOT(calcHeight()));
connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight()));
- connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth()));
+ connect(child, SIGNAL(widthChanged(qreal)), this, SLOT(calcWidth()));
connect(child, SIGNAL(xChanged()), this, SLOT(calcWidth()));
- connect(this, SIGNAL(rectChanged()), m_item, SIGNAL(childrenRectChanged()));
+ connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF)));
}
calcHeight();
@@ -1293,6 +1293,16 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec
\internal
*/
+/*!
+ \fn void QDeclarativeItem::smoothChanged()
+ \internal
+*/
+
+/*!
+ \fn void QDeclarativeItem::clipChanged()
+ \internal
+*/
+
/*! \fn void QDeclarativeItem::transformOriginChanged(TransformOrigin)
\internal
*/
@@ -1652,7 +1662,7 @@ void QDeclarativeItem::setClip(bool c)
if (clip() == c)
return;
setFlag(ItemClipsChildrenToShape, c);
- emit clipChanged();
+ emit clipChanged(c);
}
/*!
@@ -1792,11 +1802,11 @@ void QDeclarativeItem::geometryChanged(const QRectF &newGeometry,
if (newGeometry.x() != oldGeometry.x())
emit xChanged();
if (newGeometry.width() != oldGeometry.width())
- emit widthChanged();
+ emit widthChanged(newGeometry.width());
if (newGeometry.y() != oldGeometry.y())
emit yChanged();
if (newGeometry.height() != oldGeometry.height())
- emit heightChanged();
+ emit heightChanged(newGeometry.height());
for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
@@ -2058,7 +2068,6 @@ void QDeclarativeItem::setBaselineOffset(qreal offset)
return;
d->_baselineOffset = offset;
- emit baselineOffsetChanged();
for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
@@ -2068,6 +2077,7 @@ void QDeclarativeItem::setBaselineOffset(qreal offset)
anchor->updateVerticalAnchors();
}
}
+ emit baselineOffsetChanged(offset);
}
/*!
@@ -2214,7 +2224,7 @@ void QDeclarativeItem::setKeepMouseGrab(bool keep)
}
/*!
- \qmlmethod object Item::mapFromItem(Item item, int x, int y)
+ \qmlmethod object Item::mapFromItem(Item item, real x, real y)
Maps the point (\a x, \a y), which is in \a item's coordinate system, to
this item's coordinate system, and returns an object with \c x and \c y
@@ -2223,7 +2233,7 @@ void QDeclarativeItem::setKeepMouseGrab(bool keep)
If \a item is a \c null value, this maps the point from the coordinate
system of the root QML view.
*/
-QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, int x, int y) const
+QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, qreal x, qreal y) const
{
QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject();
QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject());
@@ -2234,13 +2244,13 @@ QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, int x, int
// If QGraphicsItem::mapFromItem() is called with 0, behaves the same as mapFromScene()
QPointF p = qobject_cast<QGraphicsItem*>(this)->mapFromItem(itemObj, x, y);
- sv.setProperty("x", p.x());
- sv.setProperty("y", p.y());
+ sv.setProperty(QLatin1String("x"), p.x());
+ sv.setProperty(QLatin1String("y"), p.y());
return sv;
}
/*!
- \qmlmethod object Item::mapToItem(Item item, int x, int y)
+ \qmlmethod object Item::mapToItem(Item item, real x, real y)
Maps the point (\a x, \a y), which is in this item's coordinate system, to
\a item's coordinate system, and returns an object with \c x and \c y
@@ -2249,7 +2259,7 @@ QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, int x, int
If \a item is a \c null value, this maps \a x and \a y to the coordinate
system of the root QML view.
*/
-QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, int x, int y) const
+QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, qreal x, qreal y) const
{
QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject();
QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject());
@@ -2260,23 +2270,15 @@ QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, int x, int y)
// If QGraphicsItem::mapToItem() is called with 0, behaves the same as mapToScene()
QPointF p = qobject_cast<QGraphicsItem*>(this)->mapToItem(itemObj, x, y);
- sv.setProperty("x", p.x());
- sv.setProperty("y", p.y());
+ sv.setProperty(QLatin1String("x"), p.x());
+ sv.setProperty(QLatin1String("y"), p.y());
return sv;
}
-/*!
- \internal
-
- This function emits the \e focusChanged signal.
-
- Subclasses overriding this function should call up
- to their base class.
-*/
-void QDeclarativeItem::focusChanged(bool flag)
+void QDeclarativeItemPrivate::focusChanged(bool flag)
{
- Q_UNUSED(flag);
- emit focusChanged();
+ Q_Q(QDeclarativeItem);
+ emit q->focusChanged(flag);
}
/*! \internal */
@@ -2569,14 +2571,16 @@ QPointF QDeclarativeItemPrivate::computeTransformOrigin() const
/*! \internal */
bool QDeclarativeItem::sceneEvent(QEvent *event)
{
+ Q_D(QDeclarativeItem);
if (event->type() == QEvent::KeyPress) {
QKeyEvent *k = static_cast<QKeyEvent *>(event);
-
if ((k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) &&
!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
keyPressEvent(static_cast<QKeyEvent *>(event));
if (!event->isAccepted())
return QGraphicsItem::sceneEvent(event);
+ else
+ return true;
} else {
return QGraphicsItem::sceneEvent(event);
}
@@ -2585,7 +2589,7 @@ bool QDeclarativeItem::sceneEvent(QEvent *event)
if (event->type() == QEvent::FocusIn ||
event->type() == QEvent::FocusOut) {
- focusChanged(hasFocus());
+ d->focusChanged(hasFocus());
}
return rv;
}
@@ -2598,7 +2602,7 @@ QVariant QDeclarativeItem::itemChange(GraphicsItemChange change,
Q_D(const QDeclarativeItem);
switch (change) {
case ItemParentHasChanged:
- emit parentChanged();
+ emit parentChanged(parentItem());
break;
case ItemChildAddedChange:
case ItemChildRemovedChange:
@@ -2711,7 +2715,7 @@ void QDeclarativeItem::setSmooth(bool smooth)
if (d->smooth == smooth)
return;
d->smooth = smooth;
- emit smoothChanged();
+ emit smoothChanged(smooth);
update();
}
@@ -2855,6 +2859,27 @@ bool QDeclarativeItem::heightValid() const
return d->heightValid;
}
+/*! \internal */
+void QDeclarativeItem::setSize(const QSizeF &size)
+{
+ Q_D(QDeclarativeItem);
+ d->heightValid = true;
+ d->widthValid = true;
+
+ if (d->height == size.height() && d->width == size.width())
+ return;
+
+ qreal oldHeight = d->height;
+ qreal oldWidth = d->width;
+
+ prepareGeometryChange();
+ d->height = size.height();
+ d->width = size.width();
+
+ geometryChanged(QRectF(x(), y(), width(), height()),
+ QRectF(x(), y(), oldWidth, oldHeight));
+}
+
/*!
\qmlproperty bool Item::wantsFocus
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h
index f6fedc7..9b85ba3 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem.h
@@ -42,8 +42,8 @@
#ifndef QDECLARATIVEITEM_H
#define QDECLARATIVEITEM_H
-#include <qdeclarative.h>
-#include <qdeclarativecomponent.h>
+#include <QtDeclarative/qdeclarative.h>
+#include <QtDeclarative/qdeclarativecomponent.h>
#include <QtCore/QObject>
#include <QtCore/QList>
@@ -143,6 +143,8 @@ public:
void resetHeight();
qreal implicitHeight() const;
+ void setSize(const QSizeF &size);
+
TransformOrigin transformOrigin() const;
void setTransformOrigin(TransformOrigin);
@@ -159,8 +161,8 @@ public:
bool keepMouseGrab() const;
void setKeepMouseGrab(bool);
- Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, int x, int y) const;
- Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, int x, int y) const;
+ Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const;
+ Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const;
QDeclarativeAnchorLine left() const;
QDeclarativeAnchorLine right() const;
@@ -171,18 +173,18 @@ public:
QDeclarativeAnchorLine baseline() const;
Q_SIGNALS:
- void widthChanged();
- void heightChanged();
+ void widthChanged(qreal);
+ void heightChanged(qreal);
void childrenChanged();
- void childrenRectChanged();
- void baselineOffsetChanged();
+ void childrenRectChanged(const QRectF &);
+ void baselineOffsetChanged(qreal);
void stateChanged(const QString &);
- void focusChanged();
- void wantsFocusChanged();
- void parentChanged();
+ void focusChanged(bool);
+ void wantsFocusChanged(bool);
+ void parentChanged(QDeclarativeItem *);
void transformOriginChanged(TransformOrigin);
- void smoothChanged();
- void clipChanged();
+ void smoothChanged(bool);
+ void clipChanged(bool);
protected:
bool isComponentComplete() const;
@@ -197,7 +199,6 @@ protected:
virtual void classBegin();
virtual void componentComplete();
- virtual void focusChanged(bool);
virtual void keyPressEvent(QKeyEvent *event);
virtual void keyReleaseEvent(QKeyEvent *event);
virtual void inputMethodEvent(QInputMethodEvent *);
@@ -209,8 +210,6 @@ protected:
QDeclarativeItem(QDeclarativeItemPrivate &dd, QDeclarativeItem *parent = 0);
private:
- friend class QDeclarativeStatePrivate;
- friend class QDeclarativeAnchors;
Q_DISABLE_COPY(QDeclarativeItem)
Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem)
};
diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h
index e424970..55df063 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h
@@ -91,7 +91,7 @@ public Q_SLOTS:
void calcWidth();
Q_SIGNALS:
- void rectChanged();
+ void rectChanged(QRectF);
private:
QDeclarativeItem *m_item;
@@ -101,7 +101,7 @@ private:
qreal m_height;
};
-class QDeclarativeItemPrivate : public QGraphicsItemPrivate
+class Q_DECLARATIVE_EXPORT QDeclarativeItemPrivate : public QGraphicsItemPrivate
{
Q_DECLARE_PUBLIC(QDeclarativeItem)
@@ -240,7 +240,7 @@ public:
// Reimplemented from QGraphicsItemPrivate
virtual void subFocusItemChange()
{
- emit q_func()->wantsFocusChanged();
+ emit q_func()->wantsFocusChanged(subFocusItem != 0);
}
// Reimplemented from QGraphicsItemPrivate
@@ -255,9 +255,11 @@ public:
}
}
+ virtual void focusChanged(bool);
+
static int consistentTime;
static QTime currentTime();
- static void Q_DECLARATIVE_EXPORT setConsistentTime(int t);
+ static void setConsistentTime(int t);
static void start(QTime &);
static int elapsed(QTime &);
static int restart(QTime &);
diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
index 25660f8..2ac55a4 100644
--- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
@@ -65,7 +65,6 @@
#include "qdeclarativelistview_p.h"
#include "qdeclarativeloader_p.h"
#include "qdeclarativemousearea_p.h"
-#include "qdeclarativeparticles_p.h"
#include "qdeclarativepath_p.h"
#include "qdeclarativepathview_p.h"
#include "qdeclarativerectangle_p.h"
@@ -82,76 +81,71 @@
void QDeclarativeItemModule::defineModule()
{
- QML_REGISTER_TYPE(Qt,4,6,AnimatedImage,QDeclarativeAnimatedImage);
- QML_REGISTER_TYPE(Qt,4,6,Blur,QGraphicsBlurEffect);
- QML_REGISTER_TYPE(Qt,4,6,BorderImage,QDeclarativeBorderImage);
- QML_REGISTER_TYPE(Qt,4,6,Colorize,QGraphicsColorizeEffect);
- QML_REGISTER_TYPE(Qt,4,6,Column,QDeclarativeColumn);
- QML_REGISTER_TYPE(Qt,4,6,Drag,QDeclarativeDrag);
- QML_REGISTER_TYPE(Qt,4,6,DropShadow,QGraphicsDropShadowEffect);
- QML_REGISTER_TYPE(Qt,4,6,Flickable,QDeclarativeFlickable);
- QML_REGISTER_TYPE(Qt,4,6,Flipable,QDeclarativeFlipable);
- QML_REGISTER_TYPE(Qt,4,6,Flow,QDeclarativeFlow);
- QML_REGISTER_TYPE(Qt,4,6,FocusPanel,QDeclarativeFocusPanel);
- QML_REGISTER_TYPE(Qt,4,6,FocusScope,QDeclarativeFocusScope);
- QML_REGISTER_TYPE(Qt,4,6,Gradient,QDeclarativeGradient);
- QML_REGISTER_TYPE(Qt,4,6,GradientStop,QDeclarativeGradientStop);
- QML_REGISTER_TYPE(Qt,4,6,GraphicsObjectContainer,QDeclarativeGraphicsObjectContainer);
- QML_REGISTER_TYPE(Qt,4,6,Grid,QDeclarativeGrid);
- QML_REGISTER_TYPE(Qt,4,6,GridView,QDeclarativeGridView);
- QML_REGISTER_TYPE(Qt,4,6,Image,QDeclarativeImage);
- QML_REGISTER_TYPE(Qt,4,6,Item,QDeclarativeItem);
- QML_REGISTER_TYPE(Qt,4,6,KeyNavigation,QDeclarativeKeyNavigationAttached);
- QML_REGISTER_TYPE(Qt,4,6,Keys,QDeclarativeKeysAttached);
- QML_REGISTER_TYPE(Qt,4,6,LayoutItem,QDeclarativeLayoutItem);
- QML_REGISTER_TYPE(Qt,4,6,ListView,QDeclarativeListView);
- QML_REGISTER_TYPE(Qt,4,6,Loader,QDeclarativeLoader);
- QML_REGISTER_TYPE(Qt,4,6,MouseArea,QDeclarativeMouseArea);
- QML_REGISTER_TYPE(Qt,4,6,Opacity,QGraphicsOpacityEffect);
- QML_REGISTER_TYPE(Qt,4,6,ParticleMotion,QDeclarativeParticleMotion);
- QML_REGISTER_TYPE(Qt,4,6,ParticleMotionGravity,QDeclarativeParticleMotionGravity);
- QML_REGISTER_TYPE(Qt,4,6,ParticleMotionLinear,QDeclarativeParticleMotionLinear);
- QML_REGISTER_TYPE(Qt,4,6,ParticleMotionWander,QDeclarativeParticleMotionWander);
- QML_REGISTER_TYPE(Qt,4,6,Particles,QDeclarativeParticles);
- QML_REGISTER_TYPE(Qt,4,6,Path,QDeclarativePath);
- QML_REGISTER_TYPE(Qt,4,6,PathAttribute,QDeclarativePathAttribute);
- QML_REGISTER_TYPE(Qt,4,6,PathCubic,QDeclarativePathCubic);
- QML_REGISTER_TYPE(Qt,4,6,PathLine,QDeclarativePathLine);
- QML_REGISTER_TYPE(Qt,4,6,PathPercent,QDeclarativePathPercent);
- QML_REGISTER_TYPE(Qt,4,6,PathQuad,QDeclarativePathQuad);
- QML_REGISTER_TYPE(Qt,4,6,PathView,QDeclarativePathView);
- QML_REGISTER_TYPE(Qt,4,6,Pen,QDeclarativePen);
- QML_REGISTER_TYPE(Qt,4,6,QIntValidator,QIntValidator);
+ qmlRegisterType<QDeclarativeAnimatedImage>("Qt",4,6,"AnimatedImage");
+ qmlRegisterType<QGraphicsBlurEffect>("Qt",4,6,"Blur");
+ qmlRegisterType<QDeclarativeBorderImage>("Qt",4,6,"BorderImage");
+ qmlRegisterType<QGraphicsColorizeEffect>("Qt",4,6,"Colorize");
+ qmlRegisterType<QDeclarativeColumn>("Qt",4,6,"Column");
+ qmlRegisterType<QDeclarativeDrag>("Qt",4,6,"Drag");
+ qmlRegisterType<QGraphicsDropShadowEffect>("Qt",4,6,"DropShadow");
+ qmlRegisterType<QDeclarativeFlickable>("Qt",4,6,"Flickable");
+ qmlRegisterType<QDeclarativeFlipable>("Qt",4,6,"Flipable");
+ qmlRegisterType<QDeclarativeFlow>("Qt",4,6,"Flow");
+ qmlRegisterType<QDeclarativeFocusPanel>("Qt",4,6,"FocusPanel");
+ qmlRegisterType<QDeclarativeFocusScope>("Qt",4,6,"FocusScope");
+ qmlRegisterType<QDeclarativeGradient>("Qt",4,6,"Gradient");
+ qmlRegisterType<QDeclarativeGradientStop>("Qt",4,6,"GradientStop");
+ qmlRegisterType<QDeclarativeGraphicsObjectContainer>("Qt",4,6,"GraphicsObjectContainer");
+ qmlRegisterType<QDeclarativeGrid>("Qt",4,6,"Grid");
+ qmlRegisterType<QDeclarativeGridView>("Qt",4,6,"GridView");
+ qmlRegisterType<QDeclarativeImage>("Qt",4,6,"Image");
+ qmlRegisterType<QDeclarativeItem>("Qt",4,6,"Item");
+ qmlRegisterType<QDeclarativeKeyNavigationAttached>("Qt",4,6,"KeyNavigation");
+ qmlRegisterType<QDeclarativeKeysAttached>("Qt",4,6,"Keys");
+ qmlRegisterType<QDeclarativeLayoutItem>("Qt",4,6,"LayoutItem");
+ qmlRegisterType<QDeclarativeListView>("Qt",4,6,"ListView");
+ qmlRegisterType<QDeclarativeLoader>("Qt",4,6,"Loader");
+ qmlRegisterType<QDeclarativeMouseArea>("Qt",4,6,"MouseArea");
+ qmlRegisterType<QGraphicsOpacityEffect>("Qt",4,6,"Opacity");
+ qmlRegisterType<QDeclarativePath>("Qt",4,6,"Path");
+ qmlRegisterType<QDeclarativePathAttribute>("Qt",4,6,"PathAttribute");
+ qmlRegisterType<QDeclarativePathCubic>("Qt",4,6,"PathCubic");
+ qmlRegisterType<QDeclarativePathLine>("Qt",4,6,"PathLine");
+ qmlRegisterType<QDeclarativePathPercent>("Qt",4,6,"PathPercent");
+ qmlRegisterType<QDeclarativePathQuad>("Qt",4,6,"PathQuad");
+ qmlRegisterType<QDeclarativePathView>("Qt",4,6,"PathView");
+ qmlRegisterType<QDeclarativePen>("Qt",4,6,"Pen");
+ qmlRegisterType<QIntValidator>("Qt",4,6,"QIntValidator");
#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0))
- QML_REGISTER_TYPE(Qt,4,7,QDoubleValidator,QDoubleValidator);
- QML_REGISTER_TYPE(Qt,4,7,QRegExpValidator,QRegExpValidator);
+ qmlRegisterType<QDoubleValidator>("Qt",4,7,"QDoubleValidator");
+ qmlRegisterType<QRegExpValidator>("Qt",4,7,"QRegExpValidator");
#endif
- QML_REGISTER_TYPE(Qt,4,6,Rectangle,QDeclarativeRectangle);
- QML_REGISTER_TYPE(Qt,4,6,Repeater,QDeclarativeRepeater);
- QML_REGISTER_TYPE(Qt,4,6,Rotation,QGraphicsRotation);
- QML_REGISTER_TYPE(Qt,4,6,Row,QDeclarativeRow);
- QML_REGISTER_TYPE(Qt,4,6,Scale,QGraphicsScale);
- QML_REGISTER_TYPE(Qt,4,6,Text,QDeclarativeText);
- QML_REGISTER_TYPE(Qt,4,6,TextEdit,QDeclarativeTextEdit);
- QML_REGISTER_TYPE(Qt,4,6,TextInput,QDeclarativeTextInput);
- QML_REGISTER_TYPE(Qt,4,6,ViewSection,QDeclarativeViewSection);
- QML_REGISTER_TYPE(Qt,4,6,VisibleArea,QDeclarativeFlickableVisibleArea);
- QML_REGISTER_TYPE(Qt,4,6,VisualDataModel,QDeclarativeVisualDataModel);
- QML_REGISTER_TYPE(Qt,4,6,VisualItemModel,QDeclarativeVisualItemModel);
+ qmlRegisterType<QDeclarativeRectangle>("Qt",4,6,"Rectangle");
+ qmlRegisterType<QDeclarativeRepeater>("Qt",4,6,"Repeater");
+ qmlRegisterType<QGraphicsRotation>("Qt",4,6,"Rotation");
+ qmlRegisterType<QDeclarativeRow>("Qt",4,6,"Row");
+ qmlRegisterType<QGraphicsScale>("Qt",4,6,"Scale");
+ qmlRegisterType<QDeclarativeText>("Qt",4,6,"Text");
+ qmlRegisterType<QDeclarativeTextEdit>("Qt",4,6,"TextEdit");
+ qmlRegisterType<QDeclarativeTextInput>("Qt",4,6,"TextInput");
+ qmlRegisterType<QDeclarativeViewSection>("Qt",4,6,"ViewSection");
+ qmlRegisterType<QDeclarativeFlickableVisibleArea>("Qt",4,6,"VisibleArea");
+ qmlRegisterType<QDeclarativeVisualDataModel>("Qt",4,6,"VisualDataModel");
+ qmlRegisterType<QDeclarativeVisualItemModel>("Qt",4,6,"VisualItemModel");
- QML_REGISTER_NOCREATE_TYPE(QDeclarativeAnchors);
- QML_REGISTER_NOCREATE_TYPE(QGraphicsEffect);
- QML_REGISTER_NOCREATE_TYPE(QDeclarativeKeyEvent);
- QML_REGISTER_NOCREATE_TYPE(QDeclarativeMouseEvent);
- QML_REGISTER_NOCREATE_TYPE(QGraphicsObject);
- QML_REGISTER_NOCREATE_TYPE(QGraphicsTransform);
- QML_REGISTER_NOCREATE_TYPE(QDeclarativePathElement);
- QML_REGISTER_NOCREATE_TYPE(QDeclarativeCurve);
- QML_REGISTER_NOCREATE_TYPE(QDeclarativeScaleGrid);
- QML_REGISTER_NOCREATE_TYPE(QValidator);
- QML_REGISTER_NOCREATE_TYPE(QDeclarativeVisualModel);
- QML_REGISTER_NOCREATE_TYPE(QAction);
+ qmlRegisterType<QDeclarativeAnchors>();
+ qmlRegisterType<QGraphicsEffect>();
+ qmlRegisterType<QDeclarativeKeyEvent>();
+ qmlRegisterType<QDeclarativeMouseEvent>();
+ qmlRegisterType<QGraphicsObject>();
+ qmlRegisterType<QGraphicsTransform>();
+ qmlRegisterType<QDeclarativePathElement>();
+ qmlRegisterType<QDeclarativeCurve>();
+ qmlRegisterType<QDeclarativeScaleGrid>();
+ qmlRegisterType<QValidator>();
+ qmlRegisterType<QDeclarativeVisualModel>();
+ qmlRegisterType<QAction>();
#ifdef QT_WEBKIT_LIB
- QML_REGISTER_NOCREATE_TYPE(QDeclarativeWebSettings);
+ qmlRegisterType<QDeclarativeWebSettings>();
#endif
}
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index d54bb70..e5013a9 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -158,7 +158,7 @@ public:
, bufferMode(NoBuffer)
, ownModel(false), wrap(false), autoHighlight(true), haveHighlightRange(false)
, correctFlick(true), inFlickCorrection(false), lazyRelease(false)
- , deferredRelease(false), minExtentDirty(true), maxExtentDirty(true)
+ , deferredRelease(false), layoutScheduled(false), minExtentDirty(true), maxExtentDirty(true)
{}
void init();
@@ -414,6 +414,7 @@ public:
}
void refill(qreal from, qreal to, bool doBuffer = false);
+ void scheduleLayout();
void layout();
void updateUnrequestedIndexes();
void updateUnrequestedPositions();
@@ -480,6 +481,7 @@ public:
bool inFlickCorrection : 1;
bool lazyRelease : 1;
bool deferredRelease : 1;
+ bool layoutScheduled : 1;
mutable bool minExtentDirty : 1;
mutable bool maxExtentDirty : 1;
};
@@ -557,7 +559,7 @@ void QDeclarativeListViewPrivate::releaseItem(FxListItem *item)
return;
if (trackedItem == item) {
const char *notifier1 = orient == QDeclarativeListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged());
- const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged());
+ const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged(qreal)) : SIGNAL(widthChanged(qreal));
QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged()));
QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged()));
trackedItem = 0;
@@ -680,9 +682,19 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer)
lazyRelease = false;
}
+void QDeclarativeListViewPrivate::scheduleLayout()
+{
+ Q_Q(QDeclarativeListView);
+ if (!layoutScheduled) {
+ layoutScheduled = true;
+ QCoreApplication::postEvent(q, new QEvent(QEvent::User), Qt::HighEventPriority);
+ }
+}
+
void QDeclarativeListViewPrivate::layout()
{
Q_Q(QDeclarativeListView);
+ layoutScheduled = false;
updateSections();
if (!visibleItems.isEmpty()) {
int oldEnd = visibleItems.last()->endPosition();
@@ -748,7 +760,7 @@ void QDeclarativeListViewPrivate::updateTrackedItem()
FxListItem *oldTracked = trackedItem;
const char *notifier1 = orient == QDeclarativeListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged());
- const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged());
+ const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged(qreal)) : SIGNAL(widthChanged(qreal));
if (trackedItem && item != trackedItem) {
QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged()));
@@ -1082,10 +1094,12 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
if (currentItem && currentItem->position() - position() != highlightRangeStart) {
qreal pos = currentItem->position() - highlightRangeStart;
timeline.reset(data.move);
- if (fixupDuration)
+ if (fixupDuration) {
timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
- else
+ } else {
data.move.setValue(-pos);
+ q->viewportMoved();
+ }
vTime = timeline.time();
}
} else if (snapMode != QDeclarativeListView::NoSnap) {
@@ -1094,10 +1108,12 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
qreal dist = qAbs(data.move + pos);
if (dist > 0) {
timeline.reset(data.move);
- if (fixupDuration)
+ if (fixupDuration) {
timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
- else
+ } else {
data.move.setValue(-pos);
+ q->viewportMoved();
+ }
vTime = timeline.time();
}
}
@@ -1124,7 +1140,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
if (FxListItem *item = firstVisibleItem())
maxDistance = qAbs(item->position() + data.move.value());
} else if (data.move.value() < minExtent) {
- maxDistance = qAbs(minExtent - data.move.value() + (overShoot?overShootDistance(velocity, vSize):0));
+ maxDistance = qAbs(minExtent - data.move.value());
}
if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange)
data.flickTarget = minExtent;
@@ -1133,7 +1149,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
if (FxListItem *item = nextVisibleItem())
maxDistance = qAbs(item->position() + data.move.value());
} else if (data.move.value() > maxExtent) {
- maxDistance = qAbs(maxExtent - data.move.value()) + (overShoot?overShootDistance(velocity, vSize):0);
+ maxDistance = qAbs(maxExtent - data.move.value());
}
if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange)
data.flickTarget = maxExtent;
@@ -1156,7 +1172,8 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
qreal v2 = v * v;
qreal maxAccel = v2 / (2.0f * maxDistance);
if (maxAccel < accel) {
- qreal dist = v2 / (accel * 2.0);
+ // + averageSize/4 to encourage moving at least one item in the flick direction
+ qreal dist = v2 / (accel * 2.0) + averageSize/4;
if (v > 0)
dist = -dist;
data.flickTarget = -snapPosAt(-(data.move.value() - highlightRangeStart) + dist) + highlightRangeStart;
@@ -1944,6 +1961,17 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header)
}
}
+bool QDeclarativeListView::event(QEvent *event)
+{
+ Q_D(QDeclarativeListView);
+ if (event->type() == QEvent::User) {
+ d->layout();
+ return true;
+ }
+
+ return QDeclarativeFlickable::event(event);
+}
+
void QDeclarativeListView::viewportMoved()
{
Q_D(QDeclarativeListView);
@@ -1956,10 +1984,11 @@ void QDeclarativeListView::viewportMoved()
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) {
// reposition highlight
qreal pos = d->highlight->position();
- if (pos > d->position() + d->highlightRangeEnd - 1 - d->highlight->size())
- pos = d->position() + d->highlightRangeEnd - 1 - d->highlight->size();
- if (pos < d->position() + d->highlightRangeStart)
- pos = d->position() + d->highlightRangeStart;
+ qreal viewPos = qRound(d->position());
+ if (pos > viewPos + d->highlightRangeEnd - 1 - d->highlight->size())
+ pos = viewPos + d->highlightRangeEnd - 1 - d->highlight->size();
+ if (pos < viewPos + d->highlightRangeStart)
+ pos = viewPos + d->highlightRangeStart;
d->highlight->setPosition(pos);
// update current index
@@ -2032,7 +2061,7 @@ qreal QDeclarativeListView::maxYExtent() const
return height();
if (d->maxExtentDirty) {
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
- d->maxExtent = -(d->positionAt(count()-1) - d->highlightRangeEnd);
+ d->maxExtent = -(d->endPosition() - d->highlightRangeEnd);
else
d->maxExtent = -(d->endPosition() - height() + 1);
if (d->footer)
@@ -2069,7 +2098,7 @@ qreal QDeclarativeListView::maxXExtent() const
return width();
if (d->maxExtentDirty) {
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
- d->maxExtent = -(d->positionAt(count()-1) - d->highlightRangeEnd);
+ d->maxExtent = -(d->endPosition() - d->highlightRangeEnd);
else
d->maxExtent = -(d->endPosition() - width() + 1);
if (d->footer)
@@ -2151,11 +2180,23 @@ void QDeclarativeListView::decrementCurrentIndex()
}
/*!
- \qmlmethod ListView::positionViewAtIndex(int index)
+ \qmlmethod ListView::positionViewAtIndex(int index, PositionMode mode)
+
+ Positions the view such that the \a index is at the position specified by
+ \a mode:
+
+ \list
+ \o Beginning - position item at the top (or left for horizontal orientation) of the view.
+ \o Center- position item in the center of the view.
+ \o End - position item at bottom (or right for horizontal orientation) of the view.
+ \o Visible - if any part of the item is visible then take no action, otherwise
+ bring the item into view.
+ \o Contain - ensure the entire item is visible. If the item is larger than
+ the view the item is positioned at the top (or left for horizontal orientation) of the view.
+ \endlist
- Positions the view such that the \a index is at the top (or left for horizontal orientation) of the view.
If positioning the view at the index would cause empty space to be displayed at
- the end of the view, the view will be positioned at the end.
+ the beginning or end of the view, the view will be positioned at the boundary.
It is not recommended to use contentX or contentY to position the view
at a particular index. This is unreliable since removing items from the start
@@ -2163,32 +2204,58 @@ void QDeclarativeListView::decrementCurrentIndex()
the actual start of the view can vary based on the size of the delegates.
The correct way to bring an item into view is with positionViewAtIndex.
*/
-void QDeclarativeListView::positionViewAtIndex(int index)
+void QDeclarativeListView::positionViewAtIndex(int index, int mode)
{
Q_D(QDeclarativeListView);
if (!d->isValid() || index < 0 || index >= d->model->count())
return;
+ if (mode < Beginning || mode > Contain)
+ return;
- qreal maxExtent = d->orient == QDeclarativeListView::Vertical ? -maxYExtent() : -maxXExtent();
+ qreal pos = d->position();
FxListItem *item = d->visibleItem(index);
- if (item) {
- // Already created - just move to top of view
- int pos = qMin(item->position(), maxExtent);
- d->setPosition(pos);
- } else {
- int pos = d->positionAt(index);
+ if (!item) {
+ int itemPos = d->positionAt(index);
// save the currently visible items in case any of them end up visible again
QList<FxListItem*> oldVisible = d->visibleItems;
d->visibleItems.clear();
- d->visiblePos = pos;
+ d->visiblePos = itemPos;
d->visibleIndex = index;
- d->setPosition(pos);
- // setPosition() will cause refill. Adjust if we have moved beyond range.
- if (d->position() > maxExtent)
- d->setPosition(maxExtent);
+ d->setPosition(itemPos);
// now release the reference to all the old visible items.
for (int i = 0; i < oldVisible.count(); ++i)
d->releaseItem(oldVisible.at(i));
+ item = d->visibleItem(index);
+ }
+ if (item) {
+ const qreal itemPos = item->position();
+ switch (mode) {
+ case Beginning:
+ pos = itemPos;
+ break;
+ case Center:
+ pos = itemPos - (d->size() - item->size())/2;
+ break;
+ case End:
+ pos = itemPos - d->size() + item->size();
+ break;
+ case Visible:
+ if (itemPos > pos + d->size())
+ pos = itemPos - d->size() + item->size();
+ else if (item->endPosition() < pos)
+ pos = itemPos;
+ break;
+ case Contain:
+ if (item->endPosition() > pos + d->size())
+ pos = itemPos - d->size() + item->size();
+ if (itemPos < pos)
+ pos = itemPos;
+ }
+ qreal maxExtent = d->orient == QDeclarativeListView::Vertical ? -maxYExtent() : -maxXExtent();
+ pos = qMin(pos, maxExtent);
+ qreal minExtent = d->orient == QDeclarativeListView::Vertical ? -minYExtent() : -minXExtent();
+ pos = qMax(pos, minExtent);
+ d->setPosition(pos);
}
d->fixupPosition();
}
@@ -2273,7 +2340,7 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
d->updateUnrequestedIndexes();
d->moveReason = QDeclarativeListViewPrivate::Other;
if (!d->visibleItems.count() || d->model->count() <= 1) {
- d->layout();
+ d->scheduleLayout();
d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1)));
emit countChanged();
return;
@@ -2303,8 +2370,9 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
d->currentIndex += count;
if (d->currentItem)
d->currentItem->index = d->currentIndex;
+ emit currentIndexChanged();
}
- d->layout();
+ d->scheduleLayout();
emit countChanged();
return;
}
@@ -2327,7 +2395,10 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
int i = 0;
int from = d->position() - d->buffer;
for (i = count-1; i >= 0 && pos > from; --i) {
- addedVisible = true;
+ if (!addedVisible) {
+ d->scheduleLayout();
+ addedVisible = true;
+ }
FxListItem *item = d->createItem(modelIndex + i);
d->visibleItems.insert(insertionIdx, item);
pos -= item->size() + d->spacing;
@@ -2354,7 +2425,10 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
int i = 0;
int to = d->buffer+d->position()+d->size()-1;
for (i = 0; i < count && pos <= to; ++i) {
- addedVisible = true;
+ if (!addedVisible) {
+ d->scheduleLayout();
+ addedVisible = true;
+ }
FxListItem *item = d->createItem(modelIndex + i);
d->visibleItems.insert(index, item);
item->setPosition(pos);
@@ -2377,6 +2451,7 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
d->currentItem->index = d->currentIndex;
d->currentItem->setPosition(d->currentItem->position() + diff);
}
+ emit currentIndexChanged();
}
// Update the indexes of the following visible items.
for (; index < d->visibleItems.count(); ++index) {
@@ -2390,8 +2465,6 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
for (int j = 0; j < added.count(); ++j)
added.at(j)->attached->emitAdd();
- if (addedVisible)
- d->layout();
emit countChanged();
}
@@ -2417,7 +2490,10 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count)
++it;
} else {
// removed item
- removedVisible = true;
+ if (!removedVisible) {
+ d->scheduleLayout();
+ removedVisible = true;
+ }
item->attached->emitRemove();
if (item->attached->delayRemove()) {
item->index = -1;
@@ -2442,6 +2518,7 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count)
d->currentIndex -= count;
if (d->currentItem)
d->currentItem->index -= count;
+ emit currentIndexChanged();
} else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) {
// current item has been removed.
d->currentItem->attached->setIsCurrentItem(false);
@@ -2459,20 +2536,13 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count)
}
}
- if (removedVisible) {
- if (d->visibleItems.isEmpty()) {
- d->visibleIndex = 0;
- d->visiblePos = d->header ? d->header->size() : 0;
- d->timeline.clear();
- d->setPosition(0);
- if (d->model->count() == 0)
- update();
- else
- refill();
- } else {
- // Correct the positioning of the items
- d->layout();
- }
+ if (removedVisible && d->visibleItems.isEmpty()) {
+ d->visibleIndex = 0;
+ d->visiblePos = d->header ? d->header->size() : 0;
+ d->timeline.clear();
+ d->setPosition(0);
+ if (d->model->count() == 0)
+ update();
}
emit countChanged();
diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h
index d66ac2b..0c2677c 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h
@@ -191,10 +191,13 @@ public:
static QDeclarativeListViewAttached *qmlAttachedProperties(QObject *);
+ enum PositionMode { Beginning, Center, End, Visible, Contain };
+ Q_ENUMS(PositionMode)
+
public Q_SLOTS:
void incrementCurrentIndex();
void decrementCurrentIndex();
- void positionViewAtIndex(int index);
+ void positionViewAtIndex(int index, int mode);
Q_SIGNALS:
void countChanged();
@@ -219,6 +222,7 @@ Q_SIGNALS:
void footerChanged();
protected:
+ virtual bool event(QEvent *event);
virtual void viewportMoved();
virtual qreal minYExtent() const;
virtual qreal maxYExtent() const;
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp
index b0499d7..6dbcd16 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp
@@ -155,6 +155,8 @@ void QDeclarativeLoaderPrivate::initResize()
QDeclarativeLoader::QDeclarativeLoader(QDeclarativeItem *parent)
: QDeclarativeItem(*(new QDeclarativeLoaderPrivate), parent)
{
+ Q_D(QDeclarativeItem);
+ d->flags |= QGraphicsItem::ItemIsFocusScope;
}
/*!
@@ -273,7 +275,7 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded()
if (component) {
QDeclarativeContext *ctxt = new QDeclarativeContext(qmlContext(q));
- ctxt->addDefaultObject(q);
+ ctxt->setContextObject(q);
if (!component->errors().isEmpty()) {
qWarning() << component->errors();
@@ -346,12 +348,13 @@ QDeclarativeLoader::Status QDeclarativeLoader::status() const
}
/*!
- \qmlproperty real Loader::progress
+\qmlproperty real Loader::progress
- This property holds the progress of QML data loading, from 0.0 (nothing loaded)
- to 1.0 (finished).
+This property holds the progress of loading QML data from the network, from
+0.0 (nothing loaded) to 1.0 (finished). Most QML files are quite small, so
+this value will rapidly change from 0 to 1.
- \sa status
+\sa status
*/
qreal QDeclarativeLoader::progress() const
{
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
index ec7aa62..13195af 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp
+++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
@@ -383,7 +383,6 @@ void QDeclarativeMouseArea::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
d->dragged = false;
setHovered(true);
- d->start = event->pos();
d->startScene = event->scenePos();
// we should only start timer if pressAndHold is connected to.
if (d->isConnected("pressAndHold(QDeclarativeMouseEvent*)"))
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
index d4871f2..88206cd 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
@@ -101,7 +101,6 @@ public:
bool dragY : 1;
bool dragged : 1;
QDeclarativeDrag *drag;
- QPointF start;
QPointF startScene;
qreal startX;
qreal startY;
diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
index ab6007a..28a93d2 100644
--- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
@@ -211,8 +211,8 @@ QDeclarativePaintedItem::~QDeclarativePaintedItem()
*/
void QDeclarativePaintedItem::init()
{
- connect(this,SIGNAL(widthChanged()),this,SLOT(clearCache()));
- connect(this,SIGNAL(heightChanged()),this,SLOT(clearCache()));
+ connect(this,SIGNAL(widthChanged(qreal)),this,SLOT(clearCache()));
+ connect(this,SIGNAL(heightChanged(qreal)),this,SLOT(clearCache()));
connect(this,SIGNAL(visibleChanged()),this,SLOT(clearCache()));
}
diff --git a/src/declarative/graphicsitems/qdeclarativeparticles.cpp b/src/declarative/graphicsitems/qdeclarativeparticles.cpp
deleted file mode 100644
index ec0bf6c..0000000
--- a/src/declarative/graphicsitems/qdeclarativeparticles.cpp
+++ /dev/null
@@ -1,1317 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include "qdeclarativeparticles_p.h"
-
-#include "qdeclarativeitem_p.h"
-
-#include <qdeclarativepixmapcache_p.h>
-#include <qfxperf_p_p.h>
-#include <qdeclarativeanimation_p_p.h>
-
-#include <QNetworkReply>
-#include <QPainter>
-#include <QtGui/qdrawutil.h>
-#include <QVarLengthArray>
-
-#include <stdlib.h>
-#include <math.h>
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#define M_PI_2 (M_PI / 2.)
-#endif
-#ifndef INT_MAX
-#define INT_MAX 2147483647
-#endif
-
-QT_BEGIN_NAMESPACE
-#define PI_SQR 9.8696044
-// parabolic approximation
-inline qreal fastSin(qreal theta)
-{
- const qreal b = 4 / M_PI;
- const qreal c = -4 / PI_SQR;
-
- qreal y = b * theta + c * theta * qAbs(theta);
- return y;
-}
-
-inline qreal fastCos(qreal theta)
-{
- theta += M_PI_2;
- if (theta > M_PI)
- theta -= 2 * M_PI;
-
- return fastSin(theta);
-}
-
-class QDeclarativeParticle
-{
-public:
- QDeclarativeParticle(int time) : lifeSpan(1000), fadeOutAge(800)
- , opacity(0), birthTime(time), x_velocity(0), y_velocity(0)
- , state(FadeIn), data(0)
- {
- }
-
- int lifeSpan;
- int fadeOutAge;
- qreal x;
- qreal y;
- qreal opacity;
- int birthTime;
- qreal x_velocity;
- qreal y_velocity;
- enum State { FadeIn, Solid, FadeOut };
- State state;
- void *data;
-};
-
-//---------------------------------------------------------------------------
-
-/*!
- \class QDeclarativeParticleMotion
- \ingroup group_effects
- \brief The QDeclarativeParticleMotion class is the base class for particle motion.
- \internal
-
- This class causes the particles to remain static.
-*/
-
-/*!
- Constructs a QDeclarativeParticleMotion with parent object \a parent.
-*/
-QDeclarativeParticleMotion::QDeclarativeParticleMotion(QObject *parent) :
- QObject(parent)
-{
-}
-
-/*!
- Move the \a particle to its new position. \a interval is the number of
- milliseconds elapsed since it was last moved.
-*/
-void QDeclarativeParticleMotion::advance(QDeclarativeParticle &particle, int interval)
-{
- Q_UNUSED(particle);
- Q_UNUSED(interval);
-}
-
-/*!
- The \a particle has just been created. Some motion strategies require
- additional state information. This can be allocated by this function.
-*/
-void QDeclarativeParticleMotion::created(QDeclarativeParticle &particle)
-{
- Q_UNUSED(particle);
-}
-
-/*!
- The \a particle is about to be destroyed. Any additional memory
- that has been allocated for the particle should be freed.
-*/
-void QDeclarativeParticleMotion::destroy(QDeclarativeParticle &particle)
-{
- Q_UNUSED(particle);
-}
-
-/*!
- \qmlclass ParticleMotionLinear
- \since 4.7
- \brief The ParticleMotionLinear object moves particles linearly.
-
- \sa Particles
-*/
-
-/*!
- \internal
- \class QDeclarativeParticleMotionLinear
- \ingroup group_effects
- \brief The QDeclarativeParticleMotionLinear class moves the particles linearly.
-*/
-
-void QDeclarativeParticleMotionLinear::advance(QDeclarativeParticle &p, int interval)
-{
- p.x += interval * p.x_velocity;
- p.y += interval * p.y_velocity;
-}
-
-/*!
- \qmlclass ParticleMotionGravity
- \since 4.7
- \brief The ParticleMotionGravity object moves particles towards a point.
-
- \sa Particles
-*/
-
-/*!
- \internal
- \class QDeclarativeParticleMotionGravity
- \ingroup group_effects
- \brief The QDeclarativeParticleMotionGravity class moves the particles towards a point.
-*/
-
-/*!
- \qmlproperty qreal ParticleMotionGravity::xattractor
- \qmlproperty qreal ParticleMotionGravity::yattractor
- These properties hold the x and y coordinates of the point attracting the particles.
-*/
-
-/*!
- \qmlproperty qreal ParticleMotionGravity::acceleration
- This property holds the acceleration to apply to the particles.
-*/
-
-/*!
- \property QDeclarativeParticleMotionGravity::xattractor
- \brief the x coordinate of the point attracting the particles.
-*/
-
-/*!
- \property QDeclarativeParticleMotionGravity::yattractor
- \brief the y coordinate of the point attracting the particles.
-*/
-
-/*!
- \property QDeclarativeParticleMotionGravity::acceleration
- \brief the acceleration to apply to the particles.
-*/
-
-void QDeclarativeParticleMotionGravity::setXAttractor(qreal x)
-{
- if (qFuzzyCompare(x, _xAttr))
- return;
- _xAttr = x;
- emit xattractorChanged();
-}
-
-void QDeclarativeParticleMotionGravity::setYAttractor(qreal y)
-{
- if (qFuzzyCompare(y, _yAttr))
- return;
- _yAttr = y;
- emit yattractorChanged();
-}
-
-void QDeclarativeParticleMotionGravity::setAcceleration(qreal accel)
-{
- qreal scaledAccel = accel/1000000.0;
- if (qFuzzyCompare(scaledAccel, _accel))
- return;
- _accel = scaledAccel;
- emit accelerationChanged();
-}
-
-void QDeclarativeParticleMotionGravity::advance(QDeclarativeParticle &p, int interval)
-{
- qreal xdiff = p.x - _xAttr;
- qreal ydiff = p.y - _yAttr;
-
- qreal xcomp = xdiff / (xdiff + ydiff);
- qreal ycomp = ydiff / (xdiff + ydiff);
-
- p.x_velocity += xcomp * _accel * interval;
- p.y_velocity += ycomp * _accel * interval;
-
- p.x += interval * p.x_velocity;
- p.y += interval * p.y_velocity;
-}
-
-/*!
- \qmlclass ParticleMotionWander
- \since 4.7
- \brief The ParticleMotionWander object moves particles in a somewhat random fashion.
-
- The particles will continue roughly in the original direction, however will randomly
- drift to each side.
-
- The code below produces an effect similar to falling snow.
-
- \qml
-Rectangle {
- width: 240
- height: 320
- color: "black"
-
- Particles {
- y: 0
- width: parent.width
- height: 30
- source: "star.png"
- lifeSpan: 5000
- count: 50
- angle: 70
- angleDeviation: 36
- velocity: 30
- velocityDeviation: 10
- ParticleMotionWander {
- xvariance: 30
- pace: 100
- }
- }
-}
- \endqml
-
- \sa Particles
-*/
-
-/*!
- \internal
- \class QDeclarativeParticleMotionWander
- \ingroup group_effects
- \brief The QDeclarativeParticleMotionWander class moves particles in a somewhat random fashion.
-
- The particles will continue roughly in the original direction, however will randomly
- drift to each side.
-*/
-
-/*!
- \qmlproperty qreal QDeclarativeParticleMotionWander::xvariance
- \qmlproperty qreal QDeclarativeParticleMotionWander::yvariance
-
- These properties set the amount to wander in the x and y directions.
-*/
-
-/*!
- \qmlproperty qreal QDeclarativeParticleMotionWander::pace
- This property holds how quickly the paricles will move from side to side.
-*/
-
-void QDeclarativeParticleMotionWander::advance(QDeclarativeParticle &p, int interval)
-{
- if (!particles)
- particles = qobject_cast<QDeclarativeParticles*>(parent());
- if (particles) {
- Data *d = (Data*)p.data;
- if (_xvariance != 0.) {
- qreal xdiff = p.x_velocity - d->x_targetV;
- if ((xdiff > d->x_peak && d->x_var > 0.0) || (xdiff < -d->x_peak && d->x_var < 0.0)) {
- d->x_var = -d->x_var;
- d->x_peak = _xvariance + _xvariance * qreal(qrand()) / RAND_MAX;
- }
- p.x_velocity += d->x_var * interval;
- }
- p.x += interval * p.x_velocity;
-
- if (_yvariance != 0.) {
- qreal ydiff = p.y_velocity - d->y_targetV;
- if ((ydiff > d->y_peak && d->y_var > 0.0) || (ydiff < -d->y_peak && d->y_var < 0.0)) {
- d->y_var = -d->y_var;
- d->y_peak = _yvariance + _yvariance * qreal(qrand()) / RAND_MAX;
- }
- p.y_velocity += d->y_var * interval;
- }
- p.y += interval * p.y_velocity;
- }
-}
-
-void QDeclarativeParticleMotionWander::created(QDeclarativeParticle &p)
-{
- if (!p.data) {
- Data *d = new Data;
- p.data = (void*)d;
- d->x_targetV = p.x_velocity;
- d->y_targetV = p.y_velocity;
- d->x_peak = _xvariance;
- d->y_peak = _yvariance;
- d->x_var = _pace * qreal(qrand()) / RAND_MAX / 1000.0;
- d->y_var = _pace * qreal(qrand()) / RAND_MAX / 1000.0;
- }
-}
-
-void QDeclarativeParticleMotionWander::destroy(QDeclarativeParticle &p)
-{
- if (p.data)
- delete (Data*)p.data;
-}
-
-void QDeclarativeParticleMotionWander::setXVariance(qreal var)
-{
- qreal scaledVar = var / 1000.0;
- if (qFuzzyCompare(scaledVar, _xvariance))
- return;
- _xvariance = scaledVar;
- emit xvarianceChanged();
-}
-
-void QDeclarativeParticleMotionWander::setYVariance(qreal var)
-{
- qreal scaledVar = var / 1000.0;
- if (qFuzzyCompare(scaledVar, _yvariance))
- return;
- _yvariance = scaledVar;
- emit yvarianceChanged();
-}
-
-void QDeclarativeParticleMotionWander::setPace(qreal pace)
-{
- qreal scaledPace = pace / 1000.0;
- if (qFuzzyCompare(scaledPace, _pace))
- return;
- _pace = scaledPace;
- emit paceChanged();
-}
-
-//---------------------------------------------------------------------------
-class QDeclarativeParticlesPainter : public QDeclarativeItem
-{
-public:
- QDeclarativeParticlesPainter(QDeclarativeParticlesPrivate *p, QDeclarativeItem* parent)
- : QDeclarativeItem(parent), d(p)
- {
- setFlag(QGraphicsItem::ItemHasNoContents, false);
- maxX = minX = maxY = minY = 0;
- }
-
- void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
-
- void updateSize();
-
- qreal maxX;
- qreal minX;
- qreal maxY;
- qreal minY;
- QDeclarativeParticlesPrivate* d;
-};
-
-//---------------------------------------------------------------------------
-class QDeclarativeParticlesPrivate : public QDeclarativeItemPrivate
-{
- Q_DECLARE_PUBLIC(QDeclarativeParticles)
-public:
- QDeclarativeParticlesPrivate()
- : count(1), emissionRate(-1), emissionVariance(0.5), lifeSpan(1000)
- , lifeSpanDev(1000), fadeInDur(200), fadeOutDur(300)
- , angle(0), angleDev(0), velocity(0), velocityDev(0), emissionCarry(0.)
- , addParticleTime(0), addParticleCount(0), lastAdvTime(0)
- , motion(0), pendingPixmapCache(false), clock(this)
- {
- }
-
- ~QDeclarativeParticlesPrivate()
- {
- }
-
- void init()
- {
- Q_Q(QDeclarativeParticles);
- paintItem = new QDeclarativeParticlesPainter(this, q);
- }
-
- void tick(int time);
- void createParticle(int time);
- void updateOpacity(QDeclarativeParticle &p, int age);
-
- QUrl url;
- QPixmap image;
- int count;
- int emissionRate;
- qreal emissionVariance;
- int lifeSpan;
- int lifeSpanDev;
- int fadeInDur;
- int fadeOutDur;
- qreal angle;
- qreal angleDev;
- qreal velocity;
- qreal velocityDev;
- qreal emissionCarry;
- int addParticleTime;
- int addParticleCount;
- int lastAdvTime;
- QDeclarativeParticleMotion *motion;
- QDeclarativeParticlesPainter *paintItem;
-
- bool pendingPixmapCache;
-
- QList<QPair<int, int> > bursts;//countLeft, emissionRate pairs
- QList<QDeclarativeParticle> particles;
- QTickAnimationProxy<QDeclarativeParticlesPrivate, &QDeclarativeParticlesPrivate::tick> clock;
-
-};
-
-void QDeclarativeParticlesPrivate::tick(int time)
-{
- Q_Q(QDeclarativeParticles);
- if (!motion)
- motion = new QDeclarativeParticleMotionLinear(q);
-
- int oldCount = particles.count();
- int removed = 0;
- int interval = time - lastAdvTime;
- for (int i = 0; i < particles.count(); ) {
- QDeclarativeParticle &particle = particles[i];
- int age = time - particle.birthTime;
- if (age >= particle.lifeSpan) {
- QDeclarativeParticle part = particles.takeAt(i);
- motion->destroy(part);
- ++removed;
- } else {
- updateOpacity(particle, age);
- motion->advance(particle, interval);
- ++i;
- }
- }
-
- if(emissionRate == -1)//Otherwise leave emission to the emission rate
- while(removed-- && ((count == -1) || particles.count() < count))
- createParticle(time);
-
- if (!addParticleTime)
- addParticleTime = time;
-
- //Possibly emit new particles
- if (((count == -1) || particles.count() < count) && emissionRate
- && !(count==-1 && emissionRate==-1)) {
- int emissionCount = -1;
- if (emissionRate != -1){
- qreal variance = 1.;
- if (emissionVariance > 0.){
- variance += (qreal(qrand())/RAND_MAX) * emissionVariance * (qrand()%2?-1.:1.);
- }
- qreal emission = emissionRate * (qreal(interval)/1000.);
- emission = emission * variance + emissionCarry;
- double tmpDbl;
- emissionCarry = modf(emission, &tmpDbl);
- emissionCount = (int)tmpDbl;
- emissionCount = qMax(0,emissionCount);
- }
- while(((count == -1) || particles.count() < count) &&
- (emissionRate==-1 || emissionCount--))
- createParticle(time);
- }
-
- //Deal with emissions from requested bursts
- for(int i=0; i<bursts.size(); i++){
- int emission = 0;
- if(bursts[i].second == -1){
- emission = bursts[i].first;
- }else{
- qreal variance = 1.;
- if (emissionVariance > 0.){
- variance += (qreal(qrand())/RAND_MAX) * emissionVariance * (qrand()%2?-1.:1.);
- }
- qreal workingEmission = bursts[i].second * (qreal(interval)/1000.);
- workingEmission *= variance;
- emission = (int)workingEmission;
- emission = qMax(emission, 0);
- }
- emission = qMin(emission, bursts[i].first);
- bursts[i].first -= emission;
- while(emission--)
- createParticle(time);
- }
- for(int i=bursts.size()-1; i>=0; i--)
- if(bursts[i].first <= 0)
- bursts.removeAt(i);
-
- lastAdvTime = time;
- paintItem->updateSize();
- paintItem->update();
- if (!(oldCount || particles.count()) && (!count || !emissionRate) && bursts.isEmpty()) {
- lastAdvTime = 0;
- clock.stop();
- }
-}
-
-void QDeclarativeParticlesPrivate::createParticle(int time)
-{
-#ifdef Q_ENABLE_PERFORMANCE_LOG
- QDeclarativePerfTimer<QDeclarativePerf::CreateParticle> x;
-#endif
- Q_Q(QDeclarativeParticles);
- QDeclarativeParticle p(time);
- p.x = q->x() + q->width() * qreal(qrand()) / RAND_MAX - image.width()/2.0;
- p.y = q->y() + q->height() * qreal(qrand()) / RAND_MAX - image.height()/2.0;
- p.lifeSpan = lifeSpan;
- if (lifeSpanDev)
- p.lifeSpan += int(lifeSpanDev/2 - lifeSpanDev * qreal(qrand()) / RAND_MAX);
- p.fadeOutAge = p.lifeSpan - fadeOutDur;
- if (fadeInDur == 0.) {
- p.state= QDeclarativeParticle::Solid;
- p.opacity = 1.0;
- }
- qreal a = angle;
- if (angleDev)
- a += angleDev/2 - angleDev * qreal(qrand()) / RAND_MAX;
- if (a > M_PI)
- a = a - 2 * M_PI;
- qreal v = velocity;
- if (velocityDev)
- v += velocityDev/2 - velocityDev * qreal(qrand()) / RAND_MAX;
- p.x_velocity = v * fastCos(a);
- p.y_velocity = v * fastSin(a);
- particles.append(p);
- motion->created(particles.last());
-}
-
-void QDeclarativeParticlesPrivate::updateOpacity(QDeclarativeParticle &p, int age)
-{
- switch (p.state) {
- case QDeclarativeParticle::FadeIn:
- if (age <= fadeInDur) {
- p.opacity = qreal(age) / fadeInDur;
- break;
- } else {
- p.opacity = 1.0;
- p.state = QDeclarativeParticle::Solid;
- // Fall through
- }
- case QDeclarativeParticle::Solid:
- if (age <= p.fadeOutAge) {
- break;
- } else {
- p.state = QDeclarativeParticle::FadeOut;
- // Fall through
- }
- case QDeclarativeParticle::FadeOut:
- p.opacity = qreal(p.lifeSpan - age) / fadeOutDur;
- break;
- }
-}
-
-/*!
- \qmlclass Particles
- \since 4.7
- \brief The Particles object generates and moves particles.
- \inherits Item
-
- This element provides preliminary support for particles in QML,
- and may be heavily changed or removed in later versions.
-
- The particles created by this object cannot be dealt with
- directly, they can only be controlled through the parameters of
- the Particles object. The particles are all the same pixmap,
- specified by the user.
-
- The particles are painted relative to the parent of the Particles
- object. Moving the Particles object will not move the particles
- already emitted.
-
- The below example creates two differently behaving particle
- sources. The top one has particles falling from the top like
- snow, the lower one has particles expelled up like a fountain.
-
- \qml
-Rectangle {
- width: 240
- height: 320
- color: "black"
- Particles {
- y: 0
- width: parent.width
- height: 30
- source: "star.png"
- lifeSpan: 5000
- count: 50
- angle: 70
- angleDeviation: 36
- velocity: 30
- velocityDeviation: 10
- ParticleMotionWander {
- xvariance: 30
- pace: 100
- }
- }
- Particles {
- y: 300
- x: 120
- width: 1
- height: 1
- source: "star.png"
- lifeSpan: 5000
- count: 200
- angle: 270
- angleDeviation: 45
- velocity: 50
- velocityDeviation: 30
- ParticleMotionGravity {
- yattractor: 1000
- xattractor: 0
- acceleration: 25
- }
- }
-}
- \endqml
- \image particles.gif
-*/
-
-/*!
- \internal
- \class QDeclarativeParticles
- \ingroup group_effects
- \brief The QDeclarativeParticles class generates and moves particles.
-*/
-
-QDeclarativeParticles::QDeclarativeParticles(QDeclarativeItem *parent)
- : QDeclarativeItem(*(new QDeclarativeParticlesPrivate), parent)
-{
- Q_D(QDeclarativeParticles);
- d->init();
-}
-
-QDeclarativeParticles::~QDeclarativeParticles()
-{
- Q_D(QDeclarativeParticles);
- if (d->pendingPixmapCache)
- QDeclarativePixmapCache::cancel(d->url, this);
-}
-
-/*!
- \qmlproperty string Particles::source
- This property holds the URL of the particle image.
-*/
-
-/*!
- \property QDeclarativeParticles::source
- \brief the URL of the particle image.
-*/
-QUrl QDeclarativeParticles::source() const
-{
- Q_D(const QDeclarativeParticles);
- return d->url;
-}
-
-void QDeclarativeParticles::imageLoaded()
-{
- Q_D(QDeclarativeParticles);
- d->pendingPixmapCache = false;
- QDeclarativePixmapCache::get(d->url, &d->image);
- d->paintItem->updateSize();
- d->paintItem->update();
-}
-
-void QDeclarativeParticles::setSource(const QUrl &name)
-{
- Q_D(QDeclarativeParticles);
-
- if ((d->url.isEmpty() == name.isEmpty()) && name == d->url)
- return;
-
- if (d->pendingPixmapCache) {
- QDeclarativePixmapCache::cancel(d->url, this);
- d->pendingPixmapCache = false;
- }
- if (name.isEmpty()) {
- d->url = name;
- d->image = QPixmap();
- d->paintItem->updateSize();
- d->paintItem->update();
- } else {
- d->url = name;
- Q_ASSERT(!name.isRelative());
- QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->image);
- if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) {
- QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(this), d->url);
- connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded()));
- d->pendingPixmapCache = true;
- } else {
- //### unify with imageLoaded
- d->paintItem->updateSize();
- d->paintItem->update();
- }
- }
- emit sourceChanged();
-}
-
-/*!
- \qmlproperty int Particles::count
- This property holds the maximum number of particles
-
- The particles element emits particles until it has count active
- particles. When this number is reached, new particles are not emitted until
- some of the current particles reach the end of their lifespan.
-
- If count is -1 then there is no maximum number of active particles, and
- particles will be constantly emitted at the rate specified by emissionRate.
-
- The default value for count is 1.
-
- If both count and emissionRate are set to -1, nothing will be emitted.
-
-*/
-
-/*!
- \property QDeclarativeParticles::count
- \brief the maximum number of particles
-*/
-int QDeclarativeParticles::count() const
-{
- Q_D(const QDeclarativeParticles);
- return d->count;
-}
-
-void QDeclarativeParticles::setCount(int cnt)
-{
- Q_D(QDeclarativeParticles);
- if (cnt == d->count)
- return;
-
- int oldCount = d->count;
- d->count = cnt;
- d->addParticleTime = 0;
- d->addParticleCount = d->particles.count();
- if (!oldCount && d->clock.state() != QAbstractAnimation::Running && d->count && d->emissionRate) {
- d->clock.start();
- }
- d->paintItem->updateSize();
- d->paintItem->update();
- emit countChanged();
-}
-
-
-/*!
- \qmlproperty int Particles::emissionRate
- This property holds the target number of particles to emit every second.
-
- The particles element will emit up to emissionRate particles every
- second. Fewer particles may be emitted per second if the maximum number of
- particles has been reached.
-
- If emissionRate is set to -1 there is no limit to the number of
- particles emitted per second, and particles will be instantly emitted to
- reach the maximum number of particles specified by count.
-
- The default value for emissionRate is -1.
-
- If both count and emissionRate are set to -1, nothing will be emitted.
-*/
-
-/*!
- \property QDeclarativeParticles::emissionRate
- \brief the emission rate of particles
-*/
-int QDeclarativeParticles::emissionRate() const
-{
- Q_D(const QDeclarativeParticles);
- return d->emissionRate;
-}
-void QDeclarativeParticles::setEmissionRate(int er)
-{
- Q_D(QDeclarativeParticles);
- if(er == d->emissionRate)
- return;
- d->emissionRate = er;
- if (d->clock.state() != QAbstractAnimation::Running && d->count && d->emissionRate) {
- d->clock.start();
- }
- emit emissionRateChanged();
-}
-
-/*!
- \qmlproperty qreal Particles::emissionVariance
- This property holds how inconsistent the rate of particle emissions are.
- It is a number between 0 (no variance) and 1 (some variance).
-
- The expected number of particles emitted per second is emissionRate. If
- emissionVariance is 0 then particles will be emitted consistently throughout
- each second to reach that number. If emissionVariance is greater than 0 the
- rate of particle emission will vary randomly throughout the second, with the
- consequence that the actual number of particles emitted in one second will
- vary randomly as well.
-
- emissionVariance is the maximum deviation from emitting
- emissionRate particles per second. An emissionVariance of 0 means you should
- get exactly emissionRate particles emitted per second,
- and an emissionVariance of 1 means you will get between zero and two times
- emissionRate particles per second, but you should get emissionRate particles
- per second on average.
-
- Note that even with an emissionVariance of 0 there may be some variance due
- to performance and hardware constraints.
-
- The default value of emissionVariance is 0.5
-*/
-
-/*!
- \property QDeclarativeParticles::emissionVariance
- \brief how much the particle emission amounts vary per tick
-*/
-
-qreal QDeclarativeParticles::emissionVariance() const
-{
- Q_D(const QDeclarativeParticles);
- return d->emissionVariance;
-}
-
-void QDeclarativeParticles::setEmissionVariance(qreal ev)
-{
- Q_D(QDeclarativeParticles);
- if(d->emissionVariance == ev)
- return;
- d->emissionVariance = ev;
- emit emissionVarianceChanged();
-}
-
-/*!
- \qmlproperty int Particles::lifeSpan
- \qmlproperty int Particles::lifeSpanDeviation
-
- These properties describe the life span of each particle.
-
- The default lifespan for a particle is 1000ms.
-
- lifeSpanDeviation randomly varies the lifeSpan up to the specified variation. For
- example, the following creates particles whose lifeSpan will vary
- from 150ms to 250ms:
-
- \qml
-Particles {
- source: "star.png"
- lifeSpan: 200
- lifeSpanDeviation: 100
-}
- \endqml
-*/
-
-/*!
- \property QDeclarativeParticles::lifeSpan
- \brief the life span of each particle.
-
- Default value is 1000ms.
-
- \sa QDeclarativeParticles::lifeSpanDeviation
-*/
-int QDeclarativeParticles::lifeSpan() const
-{
- Q_D(const QDeclarativeParticles);
- return d->lifeSpan;
-}
-
-void QDeclarativeParticles::setLifeSpan(int ls)
-{
- Q_D(QDeclarativeParticles);
- if(d->lifeSpan == ls)
- return;
- d->lifeSpan = ls;
- emit lifeSpanChanged();
-}
-
-/*!
- \property QDeclarativeParticles::lifeSpanDeviation
- \brief the maximum possible deviation from the set lifeSpan.
-
- Randomly varies the lifeSpan up to the specified variation. For
- example, the following creates particles whose lifeSpan will vary
- from 150ms to 250ms:
-
-\qml
-Particles {
- source: "star.png"
- lifeSpan: 200
- lifeSpanDeviation: 100
-}
-\endqml
-
- \sa QDeclarativeParticles::lifeSpan
-*/
-int QDeclarativeParticles::lifeSpanDeviation() const
-{
- Q_D(const QDeclarativeParticles);
- return d->lifeSpanDev;
-}
-
-void QDeclarativeParticles::setLifeSpanDeviation(int dev)
-{
- Q_D(QDeclarativeParticles);
- if(d->lifeSpanDev == dev)
- return;
- d->lifeSpanDev = dev;
- emit lifeSpanDeviationChanged();
-}
-
-/*!
- \qmlproperty int Particles::fadeInDuration
- \qmlproperty int Particles::fadeOutDuration
- These properties hold the time taken to fade the particles in and out.
-
- By default fade in is 200ms and fade out is 300ms.
-*/
-
-/*!
- \property QDeclarativeParticles::fadeInDuration
- \brief the time taken to fade in the particles.
-
- Default value is 200ms.
-*/
-int QDeclarativeParticles::fadeInDuration() const
-{
- Q_D(const QDeclarativeParticles);
- return d->fadeInDur;
-}
-
-void QDeclarativeParticles::setFadeInDuration(int dur)
-{
- Q_D(QDeclarativeParticles);
- if (dur < 0.0 || dur == d->fadeInDur)
- return;
- d->fadeInDur = dur;
- emit fadeInDurationChanged();
-}
-
-/*!
- \property QDeclarativeParticles::fadeOutDuration
- \brief the time taken to fade out the particles.
-
- Default value is 300ms.
-*/
-int QDeclarativeParticles::fadeOutDuration() const
-{
- Q_D(const QDeclarativeParticles);
- return d->fadeOutDur;
-}
-
-void QDeclarativeParticles::setFadeOutDuration(int dur)
-{
- Q_D(QDeclarativeParticles);
- if (dur < 0.0 || d->fadeOutDur == dur)
- return;
- d->fadeOutDur = dur;
- emit fadeOutDurationChanged();
-}
-
-/*!
- \qmlproperty real Particles::angle
- \qmlproperty real Particles::angleDeviation
-
- These properties control particle direction.
-
- angleDeviation randomly varies the direction up to the specified variation. For
- example, the following creates particles whose initial direction will
- vary from 15 degrees to 105 degrees:
-
- \qml
-Particles {
- source: "star.png"
- angle: 60
- angleDeviation: 90
-}
- \endqml
-*/
-
-/*!
- \property QDeclarativeParticles::angle
- \brief the initial angle of direction.
-
- \sa QDeclarativeParticles::angleDeviation
-*/
-qreal QDeclarativeParticles::angle() const
-{
- Q_D(const QDeclarativeParticles);
- return d->angle * 180.0 / M_PI;
-}
-
-void QDeclarativeParticles::setAngle(qreal angle)
-{
- Q_D(QDeclarativeParticles);
- qreal radAngle = angle * M_PI / 180.0;
- if(radAngle == d->angle)
- return;
- d->angle = radAngle;
- emit angleChanged();
-}
-
-/*!
- \property QDeclarativeParticles::angleDeviation
- \brief the maximum possible deviation from the set angle.
-
- Randomly varies the direction up to the specified variation. For
- example, the following creates particles whose initial direction will
- vary from 15 degrees to 105 degrees:
-
-\qml
-Particles {
- source: "star.png"
- angle: 60
- angleDeviation: 90
-}
-\endqml
-
- \sa QDeclarativeParticles::angle
-*/
-qreal QDeclarativeParticles::angleDeviation() const
-{
- Q_D(const QDeclarativeParticles);
- return d->angleDev * 180.0 / M_PI;
-}
-
-void QDeclarativeParticles::setAngleDeviation(qreal dev)
-{
- Q_D(QDeclarativeParticles);
- qreal radDev = dev * M_PI / 180.0;
- if(radDev == d->angleDev)
- return;
- d->angleDev = radDev;
- emit angleDeviationChanged();
-}
-
-/*!
- \qmlproperty real Particles::velocity
- \qmlproperty real Particles::velocityDeviation
-
- These properties control the velocity of the particles.
-
- velocityDeviation randomly varies the velocity up to the specified variation. For
- example, the following creates particles whose initial velocity will
- vary from 40 to 60.
-
- \qml
-Particles {
- source: "star.png"
- velocity: 50
- velocityDeviation: 20
-}
- \endqml
-*/
-
-/*!
- \property QDeclarativeParticles::velocity
- \brief the initial velocity of the particles.
-
- \sa QDeclarativeParticles::velocityDeviation
-*/
-qreal QDeclarativeParticles::velocity() const
-{
- Q_D(const QDeclarativeParticles);
- return d->velocity * 1000.0;
-}
-
-void QDeclarativeParticles::setVelocity(qreal velocity)
-{
- Q_D(QDeclarativeParticles);
- qreal realVel = velocity / 1000.0;
- if(realVel == d->velocity)
- return;
- d->velocity = realVel;
- emit velocityChanged();
-}
-
-/*!
- \property QDeclarativeParticles::velocityDeviation
- \brief the maximum possible deviation from the set velocity.
-
- Randomly varies the velocity up to the specified variation. For
- example, the following creates particles whose initial velocity will
- vary from 40 to 60.
-
-\qml
-Particles {
- source: "star.png"
- velocity: 50
- velocityDeviation: 20
-}
-\endqml
-
- \sa QDeclarativeParticles::velocity
-*/
-qreal QDeclarativeParticles::velocityDeviation() const
-{
- Q_D(const QDeclarativeParticles);
- return d->velocityDev * 1000.0;
-}
-
-void QDeclarativeParticles::setVelocityDeviation(qreal velocity)
-{
- Q_D(QDeclarativeParticles);
- qreal realDev = velocity / 1000.0;
- if(realDev == d->velocityDev)
- return;
- d->velocityDev = realDev;
- emit velocityDeviationChanged();
-}
-
-/*!
- \qmlproperty ParticleMotion Particles::motion
- This property sets the type of motion to apply to the particles.
-
- When a particle is created it will have an initial direction and velocity.
- The motion of the particle during its lifeSpan is then influenced by the
- motion property.
-
- Default motion is ParticleMotionLinear.
-*/
-
-/*!
- \property QDeclarativeParticles::motion
- \brief sets the type of motion to apply to the particles.
-
- When a particle is created it will have an initial direction and velocity.
- The motion of the particle during its lifeSpan is then influenced by the
- motion property.
-
- Default motion is QDeclarativeParticleMotionLinear.
-*/
-QDeclarativeParticleMotion *QDeclarativeParticles::motion() const
-{
- Q_D(const QDeclarativeParticles);
- return d->motion;
-}
-
-void QDeclarativeParticles::setMotion(QDeclarativeParticleMotion *motion)
-{
- Q_D(QDeclarativeParticles);
- if (motion == d->motion)
- return;
- d->motion = motion;
- emit motionChanged();
-}
-
-/*!
- \qmlmethod Particles::burst(int count, int emissionRate)
-
- Initiates a burst of particles.
-
- This method takes two arguments. The first argument is the number
- of particles to emit and the second argument is the emissionRate for the
- burst. If the second argument is omitted, it is treated as -1. The burst
- of particles has a separate emissionRate and count to the normal emission of
- particles. The burst uses the same values as normal emission for all other
- properties, including emissionVariance.
-
- The normal emission of particles will continue during the burst, however
- the particles created by the burst count towards the maximum number used by
- normal emission. To avoid this behavior, use two Particles elements.
-
-*/
-void QDeclarativeParticles::burst(int count, int emissionRate)
-{
- Q_D(QDeclarativeParticles);
- d->bursts << qMakePair(count, emissionRate);
- if (d->clock.state() != QAbstractAnimation::Running)
- d->clock.start();
-}
-
-void QDeclarativeParticlesPainter::updateSize()
-{
- if (!d->_componentComplete)
- return;
-
- const int parentX = parentItem()->x();
- const int parentY = parentItem()->y();
- for (int i = 0; i < d->particles.count(); ++i) {
- const QDeclarativeParticle &particle = d->particles.at(i);
- if(particle.x > maxX)
- maxX = particle.x;
- if(particle.x < minX)
- minX = particle.x;
- if(particle.y > maxY)
- maxY = particle.y;
- if(particle.y < minY)
- minY = particle.y;
- }
-
- int myWidth = (int)(maxX-minX+0.5)+d->image.width();
- int myX = (int)(minX - parentX);
- int myHeight = (int)(maxY-minY+0.5)+d->image.height();
- int myY = (int)(minY - parentY);
- setWidth(myWidth);
- setHeight(myHeight);
- setX(myX);
- setY(myY);
-}
-
-void QDeclarativeParticles::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
-{
- Q_UNUSED(p);
- //painting is done by the ParticlesPainter, so it can have the right size
-}
-
-void QDeclarativeParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
-{
- if (d->image.isNull() || d->particles.isEmpty())
- return;
-
- const int myX = x() + parentItem()->x();
- const int myY = y() + parentItem()->y();
-
-#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0))
- QVarLengthArray<QPainter::Fragment, 256> pixmapData;
-#else
- QVarLengthArray<QDrawPixmaps::Data, 256> pixmapData;
-#endif
- pixmapData.resize(d->particles.count());
-
- const QRectF sourceRect = d->image.rect();
- qreal halfPWidth = sourceRect.width()/2.;
- qreal halfPHeight = sourceRect.height()/2.;
- for (int i = 0; i < d->particles.count(); ++i) {
- const QDeclarativeParticle &particle = d->particles.at(i);
-#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0))
- pixmapData[i].x = particle.x - myX + halfPWidth;
- pixmapData[i].y = particle.y - myY + halfPHeight;
-#else
- pixmapData[i].point = QPointF(particle.x - myX + halfPWidth, particle.y - myY + halfPHeight);
-#endif
- pixmapData[i].opacity = particle.opacity;
-
- //these never change
- pixmapData[i].rotation = 0;
- pixmapData[i].scaleX = 1;
- pixmapData[i].scaleY = 1;
-#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0))
- pixmapData[i].sourceLeft = sourceRect.left();
- pixmapData[i].sourceTop = sourceRect.top();
- pixmapData[i].width = sourceRect.width();
- pixmapData[i].height = sourceRect.height();
-#else
- pixmapData[i].source = sourceRect;
-#endif
- }
-#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0))
- p->drawPixmapFragments(pixmapData.data(), d->particles.count(), d->image);
-#else
- qDrawPixmaps(p, pixmapData.data(), d->particles.count(), d->image);
-#endif
-}
-
-void QDeclarativeParticles::componentComplete()
-{
- Q_D(QDeclarativeParticles);
- QDeclarativeItem::componentComplete();
- if (d->count && d->emissionRate) {
- d->paintItem->updateSize();
- d->clock.start();
- }
- if (d->lifeSpanDev > d->lifeSpan)
- d->lifeSpanDev = d->lifeSpan;
-}
-
-QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativeparticles_p.h b/src/declarative/graphicsitems/qdeclarativeparticles_p.h
deleted file mode 100644
index 06acbb9..0000000
--- a/src/declarative/graphicsitems/qdeclarativeparticles_p.h
+++ /dev/null
@@ -1,258 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEPARTICLES_H
-#define QDECLARATIVEPARTICLES_H
-
-#include "qdeclarativeitem.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class QDeclarativeParticle;
-class QDeclarativeParticles;
-class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotion : public QObject
-{
- Q_OBJECT
-public:
- QDeclarativeParticleMotion(QObject *parent=0);
-
- virtual void advance(QDeclarativeParticle &, int interval);
- virtual void created(QDeclarativeParticle &);
- virtual void destroy(QDeclarativeParticle &);
-};
-
-class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotionLinear : public QDeclarativeParticleMotion
-{
- Q_OBJECT
-public:
- QDeclarativeParticleMotionLinear(QObject *parent=0)
- : QDeclarativeParticleMotion(parent) {}
-
- virtual void advance(QDeclarativeParticle &, int interval);
-};
-
-class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotionGravity : public QDeclarativeParticleMotion
-{
- Q_OBJECT
-
- Q_PROPERTY(qreal xattractor READ xAttractor WRITE setXAttractor NOTIFY xattractorChanged)
- Q_PROPERTY(qreal yattractor READ yAttractor WRITE setYAttractor NOTIFY yattractorChanged)
- Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
-public:
- QDeclarativeParticleMotionGravity(QObject *parent=0)
- : QDeclarativeParticleMotion(parent), _xAttr(0.0), _yAttr(0.0), _accel(0.00005) {}
-
- qreal xAttractor() const { return _xAttr; }
- void setXAttractor(qreal x);
-
- qreal yAttractor() const { return _yAttr; }
- void setYAttractor(qreal y);
-
- qreal acceleration() const { return _accel * 1000000; }
- void setAcceleration(qreal accel);
-
- virtual void advance(QDeclarativeParticle &, int interval);
-
-Q_SIGNALS:
- void xattractorChanged();
- void yattractorChanged();
- void accelerationChanged();
-
-private:
- qreal _xAttr;
- qreal _yAttr;
- qreal _accel;
-};
-
-class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotionWander : public QDeclarativeParticleMotion
-{
- Q_OBJECT
-public:
- QDeclarativeParticleMotionWander()
- : QDeclarativeParticleMotion(), particles(0), _xvariance(0), _yvariance(0) {}
-
- virtual void advance(QDeclarativeParticle &, int interval);
- virtual void created(QDeclarativeParticle &);
- virtual void destroy(QDeclarativeParticle &);
-
- struct Data {
- qreal x_targetV;
- qreal y_targetV;
- qreal x_peak;
- qreal y_peak;
- qreal x_var;
- qreal y_var;
- };
-
- Q_PROPERTY(qreal xvariance READ xVariance WRITE setXVariance NOTIFY xvarianceChanged)
- qreal xVariance() const { return _xvariance * 1000.0; }
- void setXVariance(qreal var);
-
- Q_PROPERTY(qreal yvariance READ yVariance WRITE setYVariance NOTIFY yvarianceChanged)
- qreal yVariance() const { return _yvariance * 1000.0; }
- void setYVariance(qreal var);
-
- Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged)
- qreal pace() const { return _pace * 1000.0; }
- void setPace(qreal pace);
-
-Q_SIGNALS:
- void xvarianceChanged();
- void yvarianceChanged();
- void paceChanged();
-
-private:
- QDeclarativeParticles *particles;
- qreal _xvariance;
- qreal _yvariance;
- qreal _pace;
-};
-
-class QDeclarativeParticlesPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeParticles : public QDeclarativeItem
-{
- Q_OBJECT
-
- Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
- Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
- Q_PROPERTY(int emissionRate READ emissionRate WRITE setEmissionRate NOTIFY emissionRateChanged)
- Q_PROPERTY(qreal emissionVariance READ emissionVariance WRITE setEmissionVariance NOTIFY emissionVarianceChanged)
- Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan NOTIFY lifeSpanChanged)
- Q_PROPERTY(int lifeSpanDeviation READ lifeSpanDeviation WRITE setLifeSpanDeviation NOTIFY lifeSpanDeviationChanged)
- Q_PROPERTY(int fadeInDuration READ fadeInDuration WRITE setFadeInDuration NOTIFY fadeInDurationChanged)
- Q_PROPERTY(int fadeOutDuration READ fadeOutDuration WRITE setFadeOutDuration NOTIFY fadeOutDurationChanged)
- Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
- Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation NOTIFY angleDeviationChanged)
- Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity NOTIFY velocityChanged)
- Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation NOTIFY velocityDeviationChanged)
- Q_PROPERTY(QDeclarativeParticleMotion *motion READ motion WRITE setMotion NOTIFY motionChanged)
- Q_CLASSINFO("DefaultProperty", "motion")
-
-public:
- QDeclarativeParticles(QDeclarativeItem *parent=0);
- ~QDeclarativeParticles();
-
- QUrl source() const;
- void setSource(const QUrl &);
-
- int count() const;
- void setCount(int cnt);
-
- int emissionRate() const;
- void setEmissionRate(int);
-
- qreal emissionVariance() const;
- void setEmissionVariance(qreal);
-
- int lifeSpan() const;
- void setLifeSpan(int);
-
- int lifeSpanDeviation() const;
- void setLifeSpanDeviation(int);
-
- int fadeInDuration() const;
- void setFadeInDuration(int);
-
- int fadeOutDuration() const;
- void setFadeOutDuration(int);
-
- qreal angle() const;
- void setAngle(qreal);
-
- qreal angleDeviation() const;
- void setAngleDeviation(qreal);
-
- qreal velocity() const;
- void setVelocity(qreal);
-
- qreal velocityDeviation() const;
- void setVelocityDeviation(qreal);
-
- QDeclarativeParticleMotion *motion() const;
- void setMotion(QDeclarativeParticleMotion *);
-
- void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
-
-public Q_SLOTS:
- void burst(int count, int emissionRate=-1);
-
-protected:
- virtual void componentComplete();
-
-Q_SIGNALS:
- void sourceChanged();
- void countChanged();
- void emissionRateChanged();
- void emissionVarianceChanged();
- void lifeSpanChanged();
- void lifeSpanDeviationChanged();
- void fadeInDurationChanged();
- void fadeOutDurationChanged();
- void angleChanged();
- void angleDeviationChanged();
- void velocityChanged();
- void velocityDeviationChanged();
- void emittingChanged();
- void motionChanged();
-
-private Q_SLOTS:
- void imageLoaded();
-
-private:
- Q_DISABLE_COPY(QDeclarativeParticles)
- Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeParticles)
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QDeclarativeParticleMotion)
-QML_DECLARE_TYPE(QDeclarativeParticleMotionLinear)
-QML_DECLARE_TYPE(QDeclarativeParticleMotionGravity)
-QML_DECLARE_TYPE(QDeclarativeParticleMotionWander)
-QML_DECLARE_TYPE(QDeclarativeParticles)
-
-QT_END_HEADER
-
-#endif
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index cc17157..b9c8971 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -354,7 +354,7 @@ void QDeclarativePathView::setCurrentIndex(int idx)
/*!
\qmlproperty real PathView::offset
- The offset specifies how far along the path the items are from their initial positions.
+ The offset specifies how far along the path (0.0-1.0) the items are from their initial positions.
*/
qreal QDeclarativePathView::offset() const
{
@@ -373,9 +373,9 @@ void QDeclarativePathViewPrivate::setOffset(qreal o)
{
Q_Q(QDeclarativePathView);
if (_offset != o) {
- _offset = qmlMod(o, qreal(100.0));
+ _offset = qmlMod(o, qreal(1.0));
if (_offset < 0)
- _offset = 100.0 + _offset;
+ _offset = 1.0 + _offset;
q->refill();
}
}
@@ -503,7 +503,7 @@ QPointF QDeclarativePathViewPrivate::pointNear(const QPointF &point, qreal *near
}
if (nearPercent)
- *nearPercent = nearPc / 10.0;
+ *nearPercent = nearPc / 1000.0;
return nearPoint;
}
@@ -559,10 +559,10 @@ void QDeclarativePathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (diff) {
setOffset(d->_offset + diff);
- if (diff > 50)
- diff -= 100;
- else if (diff < -50)
- diff += 100;
+ if (diff > 0.5)
+ diff -= 1.0;
+ else if (diff < -0.5)
+ diff += 1.0;
d->lastElapsed = QDeclarativeItemPrivate::restart(d->lastPosTime);
d->lastDist = diff;
@@ -579,15 +579,15 @@ void QDeclarativePathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
qreal elapsed = qreal(d->lastElapsed + QDeclarativeItemPrivate::elapsed(d->lastPosTime)) / 1000.;
qreal velocity = elapsed > 0. ? d->lastDist / elapsed : 0;
- if (d->model && d->model->count() && qAbs(velocity) > 5) {
- if (velocity > 100)
- velocity = 100;
- else if (velocity < -100)
- velocity = -100;
- qreal inc = qmlMod(d->_offset - d->snapPos, qreal(100.0 / d->model->count()));
- qreal dist = qAbs(velocity/2 - qmlMod(velocity/2, qreal(100.0 / d->model->count()) - inc));
+ if (d->model && d->model->count() && qAbs(velocity) > 0.05) {
+ if (velocity > 1.5)
+ velocity = 1.5;
+ else if (velocity < -1.5)
+ velocity = -1.5;
+ qreal inc = qmlMod(d->_offset - d->snapPos, qreal(1.0 / d->model->count()));
+ qreal dist = qAbs(velocity/2 - qmlMod(velocity/2, qreal(1.0 / d->model->count()) - inc));
d->moveOffset.setValue(d->_offset);
- d->tl.accel(d->moveOffset, velocity, 10, dist);
+ d->tl.accel(d->moveOffset, velocity, 0.1, dist);
d->tl.callback(QDeclarativeTimeLineCallback(&d->moveOffset, d->fixOffsetCallback, d));
} else {
d->fixOffset();
@@ -676,10 +676,10 @@ void QDeclarativePathView::componentComplete()
itemIndex += d->pathOffset;
itemIndex %= d->items.count();
- qreal targetOffset = qmlMod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), qreal(100.0));
+ qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0));
if (targetOffset < 0)
- targetOffset = 100.0 + targetOffset;
+ targetOffset = 1.0 + targetOffset;
if (targetOffset != d->_offset) {
d->moveOffset.setValue(targetOffset);
}
@@ -712,8 +712,8 @@ void QDeclarativePathViewPrivate::regenerate()
}
items.append(item);
item->setZValue(i);
- qreal percent = i * (100. / numItems) + _offset;
- percent = qAbs(qmlMod(percent, qreal(100.0))/100.0);
+ qreal percent = qreal(i) / numItems + _offset;
+ percent = qAbs(qmlMod(percent, qreal(1.0)));
updateItem(item, percent);
model->completeItem();
if (currentIndex == index) {
@@ -745,10 +745,10 @@ void QDeclarativePathView::refill()
QList<qreal> positions;
for (int i=0; i<d->items.count(); i++){
- qreal percent = i * (100. / d->items.count());
+ qreal percent = qreal(i) / d->items.count();
percent = percent + d->_offset;
- percent = qmlMod(percent, qreal(100.0));
- positions << qAbs(percent/100.0);
+ percent = qmlMod(percent, qreal(1.0));
+ positions << qAbs(percent);
}
if (d->pathItems==-1) {
@@ -843,10 +843,10 @@ void QDeclarativePathView::itemsInserted(int modelIndex, int count)
int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count();
itemIndex += d->pathOffset;
itemIndex %= d->items.count();
- qreal targetOffset = qmlMod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), qreal(100.0));
+ qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0));
if (targetOffset < 0)
- targetOffset = 100.0 + targetOffset;
+ targetOffset = 1.0 + targetOffset;
if (targetOffset != d->_offset)
d->moveOffset.setValue(targetOffset);
}
@@ -880,10 +880,10 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count)
int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count();
itemIndex += d->pathOffset;
itemIndex %= d->items.count();
- qreal targetOffset = qmlMod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), qreal(100.0));
+ qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0));
if (targetOffset < 0)
- targetOffset = 100.0 + targetOffset;
+ targetOffset = 1.0 + targetOffset;
if (targetOffset != d->_offset)
d->moveOffset.setValue(targetOffset);
}
@@ -919,15 +919,15 @@ int QDeclarativePathViewPrivate::calcCurrentIndex()
{
int current = -1;
if (model && items.count()) {
- _offset = qmlMod(_offset, qreal(100.0));
+ _offset = qmlMod(_offset, qreal(1.0));
if (_offset < 0)
- _offset += 100.0;
+ _offset += 1.0;
if (pathItems == -1) {
- qreal delta = qmlMod(_offset - snapPos, qreal(100.0));
+ qreal delta = qmlMod(_offset - snapPos, qreal(1.0));
if (delta < 0)
- delta = 100.0 + delta;
- int ii = model->count() - qRound(delta * model->count() / 100);
+ delta = 1.0 + delta;
+ int ii = model->count() - qRound(delta * model->count());
if (ii < 0)
ii = 0;
current = ii;
@@ -935,10 +935,10 @@ int QDeclarativePathViewPrivate::calcCurrentIndex()
qreal bestDiff=1e9;
int bestI=-1;
for (int i=0; i<items.count(); i++){
- qreal percent = i * (100. / items.count());
+ qreal percent = qreal(i) / items.count();
percent = percent + _offset;
- percent = qmlMod(percent, qreal(100.0));
- qreal diff = qAbs(snapPos - (percent/100.0));
+ percent = qmlMod(percent, qreal(1.0));
+ qreal diff = qAbs(snapPos - percent);
if (diff < bestDiff){
bestDiff = diff;
bestI = i;
@@ -1017,10 +1017,10 @@ void QDeclarativePathViewPrivate::snapToCurrent()
itemIndex = itemIndex - model->count() + items.count();
}
itemIndex %= items.count();
- qreal targetOffset = qmlMod(100 + (snapPos*100) - 100.0 * itemIndex / items.count(), qreal(100.0));
+ qreal targetOffset = qmlMod(1.0 + snapPos - qreal(itemIndex) / items.count(), qreal(1.0));
if (targetOffset < 0)
- targetOffset = 100.0 + targetOffset;
+ targetOffset = 1.0 + targetOffset;
if (targetOffset == _offset && rounds == 0)
return;
@@ -1031,24 +1031,24 @@ void QDeclarativePathViewPrivate::snapToCurrent()
if (rounds!=0){
//Compensate if the targetOffset would bring the target in from off the screen
qreal distance = targetOffset - _offset;
- if (distance <= -50)
+ if (distance <= -0.5)
rounds--;
- if (distance > 50)
+ if (distance > 0.5)
rounds++;
- tl.move(moveOffset, targetOffset + 100.0*(-rounds), QEasingCurve(QEasingCurve::InOutQuad),
- int(100*items.count()*qMax((qreal)(2.0/items.count()),(qreal)qAbs(rounds))));
+ tl.move(moveOffset, targetOffset -rounds, QEasingCurve(QEasingCurve::InOutQuad),
+ int(items.count()*qMax((qreal)(2.0/items.count()),(qreal)qAbs(rounds))));
tl.callback(QDeclarativeTimeLineCallback(&moveOffset, fixOffsetCallback, this));
return;
}
- if (targetOffset - _offset > 50.0) {
- qreal distance = 100 - targetOffset + _offset;
+ if (targetOffset - _offset > 0.5) {
+ qreal distance = 1 - targetOffset + _offset;
tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * _offset / distance));
- tl.set(moveOffset, 100.0);
- tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * (100-targetOffset) / distance));
- } else if (targetOffset - _offset <= -50.0) {
- qreal distance = 100 - _offset + targetOffset;
- tl.move(moveOffset, 100.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * (100-_offset) / distance));
+ tl.set(moveOffset, 1.0);
+ tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * (1.0-targetOffset) / distance));
+ } else if (targetOffset - _offset <= -0.5) {
+ qreal distance = 1 - _offset + targetOffset;
+ tl.move(moveOffset, 1.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * (1.0-_offset) / distance));
tl.set(moveOffset, 0.0);
tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * targetOffset / distance));
} else {
diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
index 4083ab5..62f7d95 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
@@ -66,11 +66,6 @@
QT_BEGIN_NAMESPACE
-typedef struct PathViewItem{
- int index;
- QDeclarativeItem* item;
-}PathViewItem;
-
class QDeclarativeOpenMetaObjectType;
class QDeclarativePathViewAttached;
class QDeclarativePathViewPrivate : public QDeclarativeItemPrivate
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
index 1212e89..0f59a70 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
@@ -212,19 +212,22 @@ void QDeclarativeBasePositioner::prePositioning()
QList<QGraphicsItem *> children = d->QGraphicsItemPrivate::children;
qSort(children.begin(), children.end(), d->insertionOrder);
+ QPODVector<PositionedItem,8> oldItems;
+ positionedItems.copyAndClear(oldItems);
for (int ii = 0; ii < children.count(); ++ii) {
QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(ii));
if (!child)
continue;
PositionedItem *item = 0;
PositionedItem posItem(child);
- int wIdx = positionedItems.find(posItem);
+ int wIdx = oldItems.find(posItem);
if (wIdx < 0) {
d->watchChanges(child);
positionedItems.append(posItem);
item = &positionedItems[positionedItems.count()-1];
} else {
- item = &positionedItems[wIdx];
+ item = &oldItems[wIdx];
+ positionedItems.append(*item);
}
if (child->opacity() <= 0.0 || !child->isVisible()) {
item->isVisible = false;
diff --git a/src/declarative/graphicsitems/qdeclarativerepeater.cpp b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
index e4cd499..b9696c8 100644
--- a/src/declarative/graphicsitems/qdeclarativerepeater.cpp
+++ b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
@@ -296,6 +296,8 @@ void QDeclarativeRepeater::clear()
void QDeclarativeRepeater::regenerate()
{
Q_D(QDeclarativeRepeater);
+ if (!isComponentComplete())
+ return;
clear();
@@ -312,23 +314,65 @@ void QDeclarativeRepeater::regenerate()
}
}
-void QDeclarativeRepeater::itemsInserted(int, int)
+void QDeclarativeRepeater::itemsInserted(int index, int count)
{
- regenerate();
+ Q_D(QDeclarativeRepeater);
+ if (!isComponentComplete())
+ return;
+ for (int i = 0; i < count; ++i) {
+ int modelIndex = index + i;
+ QDeclarativeItem *item = d->model->item(modelIndex);
+ if (item) {
+ item->setParent(parentItem());
+ if (modelIndex < d->deletables.count())
+ item->stackBefore(d->deletables.at(modelIndex));
+ else
+ item->stackBefore(this);
+ d->deletables.insert(modelIndex, item);
+ }
+ }
}
-void QDeclarativeRepeater::itemsRemoved(int, int)
+void QDeclarativeRepeater::itemsRemoved(int index, int count)
{
- regenerate();
+ Q_D(QDeclarativeRepeater);
+ if (!isComponentComplete())
+ return;
+ while (count--) {
+ QDeclarativeItem *item = d->deletables.takeAt(index);
+ if (item) {
+ item->setParentItem(this);
+ d->model->release(item);
+ }
+ }
}
-void QDeclarativeRepeater::itemsMoved(int,int,int)
+void QDeclarativeRepeater::itemsMoved(int from, int to, int count)
{
- regenerate();
+ Q_D(QDeclarativeRepeater);
+ if (!isComponentComplete())
+ return;
+ QList<QDeclarativeItem*> removed;
+ int removedCount = count;
+ while (removedCount--)
+ removed << d->deletables.takeAt(from);
+ for (int i = 0; i < count; ++i)
+ d->deletables.insert(to + i, removed.at(i));
+ for (int i = 0; i < d->model->count(); ++i) {
+ if (i < from && i < to)
+ continue;
+ QDeclarativeItem *item = d->deletables.at(i);
+ if (i < d->deletables.count()-1)
+ item->stackBefore(d->deletables.at(i+1));
+ else
+ item->stackBefore(this);
+ }
}
void QDeclarativeRepeater::modelReset()
{
+ if (!isComponentComplete())
+ return;
regenerate();
}
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
index be73b39..dbae47d 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
@@ -760,17 +760,11 @@ void QDeclarativeTextEdit::keyReleaseEvent(QKeyEvent *event)
QDeclarativePaintedItem::keyReleaseEvent(event);
}
-/*!
- \overload
- Handles changing of the focus property. Focus is applied to the control
- even if the edit does not have active focus. This is because things
- like KeyProxy can give the behavior of focus even when hasFocus() isn't
- true.
-*/
-void QDeclarativeTextEdit::focusChanged(bool hasFocus)
+void QDeclarativeTextEditPrivate::focusChanged(bool hasFocus)
{
- setCursorVisible(hasFocus);
- QDeclarativeItem::focusChanged(hasFocus);
+ Q_Q(QDeclarativeTextEdit);
+ q->setCursorVisible(hasFocus);
+ QDeclarativeItemPrivate::focusChanged(hasFocus);
}
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
index 6183b1d..b1682c4 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
@@ -215,8 +215,6 @@ protected:
void keyPressEvent(QKeyEvent *);
void keyReleaseEvent(QKeyEvent *);
- void focusChanged(bool);
-
// mouse filter?
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
index 002fac4..dd2a29d 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
@@ -80,6 +80,7 @@ public:
void updateDefaultTextOption();
void relayoutDocument();
void updateSelection();
+ void focusChanged(bool);
QString text;
QFont font;
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 3382628..6df3533 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -636,12 +636,12 @@ int QDeclarativeTextInput::xToPos(int x)
return d->control->xToPos(x - d->hscroll);
}
-void QDeclarativeTextInput::focusChanged(bool hasFocus)
+void QDeclarativeTextInputPrivate::focusChanged(bool hasFocus)
{
- Q_D(QDeclarativeTextInput);
- d->focused = hasFocus;
- setCursorVisible(hasFocus);
- QDeclarativeItem::focusChanged(hasFocus);
+ Q_Q(QDeclarativeTextInput);
+ focused = hasFocus;
+ q->setCursorVisible(hasFocus);
+ QDeclarativeItemPrivate::focusChanged(hasFocus);
}
void QDeclarativeTextInput::keyPressEvent(QKeyEvent* ev)
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
index f690ae2..6a61c2d 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -199,8 +199,6 @@ protected:
void keyPressEvent(QKeyEvent* ev);
bool event(QEvent *e);
- void focusChanged(bool hasFocus);
-
public Q_SLOTS:
void selectAll();
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
index 3d28f40..5d17a55 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
@@ -83,6 +83,7 @@ public:
void init();
void startCreatingCursor();
+ void focusChanged(bool hasFocus);
QLineControl* control;
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
index 6bad4da..6341764 100644
--- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
+++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
@@ -196,7 +196,7 @@ QVariant QDeclarativeVisualItemModel::evaluate(int index, const QString &express
return QVariant();
QDeclarativeContext *ccontext = qmlContext(this);
QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext);
- ctxt->addDefaultObject(d->children.at(index));
+ ctxt->setContextObject(d->children.at(index));
QDeclarativeExpression e(ctxt, expression, objectContext);
QVariant value = e.value();
delete ctxt;
@@ -991,7 +991,7 @@ QDeclarativeItem *QDeclarativeVisualDataModel::item(int index, const QByteArray
QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext);
QDeclarativeVisualDataModelData *data = new QDeclarativeVisualDataModelData(index, this);
ctxt->setContextProperty(QLatin1String("model"), data);
- ctxt->addDefaultObject(data);
+ ctxt->setContextObject(data);
nobj = d->m_delegate->beginCreate(ctxt);
if (complete)
d->m_delegate->completeCreate();
@@ -1104,7 +1104,7 @@ QVariant QDeclarativeVisualDataModel::evaluate(int index, const QString &express
if (!ccontext) ccontext = qmlContext(this);
QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext);
QDeclarativeVisualDataModelData *data = new QDeclarativeVisualDataModelData(index, this);
- ctxt->addDefaultObject(data);
+ ctxt->setContextObject(data);
QDeclarativeExpression e(ctxt, expression, objectContext);
value = e.value();
delete data;
diff --git a/src/declarative/qml/parser/qdeclarativejslexer.cpp b/src/declarative/qml/parser/qdeclarativejslexer.cpp
index 34163a4..6404be3 100644
--- a/src/declarative/qml/parser/qdeclarativejslexer.cpp
+++ b/src/declarative/qml/parser/qdeclarativejslexer.cpp
@@ -56,9 +56,11 @@
#include <stdio.h>
#include <string.h>
-QT_QML_BEGIN_NAMESPACE
-
+QT_BEGIN_NAMESPACE
extern double qstrtod(const char *s00, char const **se, bool *ok);
+QT_END_NAMESPACE
+
+QT_QML_BEGIN_NAMESPACE
#define shiftWindowsLineBreak() \
do { \
diff --git a/src/declarative/qml/qdeclarative.h b/src/declarative/qml/qdeclarative.h
index 77b7484..dfdef11 100644
--- a/src/declarative/qml/qdeclarative.h
+++ b/src/declarative/qml/qdeclarative.h
@@ -99,7 +99,7 @@ int qmlRegisterType()
qRegisterMetaType<T *>(pointerName.constData()),
qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
- 0,
+ 0, 0,
0, 0, 0, 0, &T::staticMetaObject,
@@ -131,7 +131,7 @@ int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const c
qRegisterMetaType<T *>(pointerName.constData()),
qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
- QDeclarativePrivate::create<T>,
+ sizeof(T), QDeclarativePrivate::createInto<T>,
uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
@@ -163,7 +163,7 @@ int qmlRegisterExtendedType()
qRegisterMetaType<T *>(pointerName.constData()),
qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
- 0,
+ 0, 0,
0, 0, 0, 0, &T::staticMetaObject,
@@ -203,7 +203,7 @@ int qmlRegisterExtendedType(const char *uri, int versionMajor, int versionMinor,
qRegisterMetaType<T *>(pointerName.constData()),
qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
- QDeclarativePrivate::create<T>,
+ sizeof(T), QDeclarativePrivate::createInto<T>,
uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
@@ -256,7 +256,7 @@ int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor,
qRegisterMetaType<T *>(pointerName.constData()),
qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
- QDeclarativePrivate::create<T>,
+ sizeof(T), QDeclarativePrivate::createInto<T>,
uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
@@ -275,18 +275,6 @@ int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor,
return QDeclarativePrivate::registerType(type);
}
-#define QML_REGISTER_INTERFACE(INTERFACE) \
- qmlRegisterInterface<INTERFACE>(#INTERFACE)
-
-#define QML_REGISTER_EXTENDED_TYPE(URI, VERSION_MAJ, VERSION_MIN, NAME, CLASS, EXTENSION) \
- qmlRegisterExtendedType<CLASS,EXTENSION>(#URI, VERSION_MAJ, VERSION_MIN, #NAME)
-
-#define QML_REGISTER_TYPE(URI,VMAJ,VMIN,NAME,CLASS) \
- qmlRegisterType<CLASS>(#URI, VMAJ, VMIN, #NAME)
-
-#define QML_REGISTER_NOCREATE_TYPE(CLASS) \
- qmlRegisterType<CLASS>()
-
class QDeclarativeContext;
class QDeclarativeEngine;
Q_DECLARATIVE_EXPORT void qmlExecuteDeferred(QObject *);
diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp
index 88ca5cd..bc78b5b 100644
--- a/src/declarative/qml/qdeclarativebinding.cpp
+++ b/src/declarative/qml/qdeclarativebinding.cpp
@@ -223,7 +223,7 @@ void QDeclarativeBinding::setEnabled(bool e, QDeclarativePropertyPrivate::WriteF
int QDeclarativeBinding::propertyIndex()
{
Q_D(QDeclarativeBinding);
- return d->bindingData()->property.index();
+ return QDeclarativePropertyPrivate::bindingIndex(d->bindingData()->property);
}
bool QDeclarativeBinding::enabled() const
@@ -259,23 +259,57 @@ void QDeclarativeAbstractBinding::addToObject(QObject *object)
{
Q_ASSERT(object);
+ if (m_object == object)
+ return;
+
+ int index = propertyIndex();
+
removeFromObject();
Q_ASSERT(!m_prevBinding);
- QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, true);
- m_nextBinding = data->bindings;
- if (m_nextBinding) m_nextBinding->m_prevBinding = &m_nextBinding;
- m_prevBinding = &data->bindings;
- data->bindings = this;
m_object = object;
+ QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, true);
+
+ if (index & 0xFF000000) {
+ // Value type
- data->setBindingBit(m_object, propertyIndex());
+ int coreIndex = index & 0xFFFFFF;
+
+ // Find the value type proxy (if there is one)
+ QDeclarativeValueTypeProxyBinding *proxy = 0;
+ if (data->hasBindingBit(coreIndex)) {
+ QDeclarativeAbstractBinding *b = data->bindings;
+ while (b && b->propertyIndex() != coreIndex)
+ b = b->m_nextBinding;
+ Q_ASSERT(b && b->bindingType() == QDeclarativeAbstractBinding::ValueTypeProxy);
+ proxy = static_cast<QDeclarativeValueTypeProxyBinding *>(b);
+ }
+
+ if (!proxy)
+ proxy = new QDeclarativeValueTypeProxyBinding(object, coreIndex);
+ proxy->addToObject(object);
+
+ m_nextBinding = proxy->m_bindings;
+ if (m_nextBinding) m_nextBinding->m_prevBinding = &m_nextBinding;
+ m_prevBinding = &proxy->m_bindings;
+ proxy->m_bindings = this;
+
+ } else {
+ m_nextBinding = data->bindings;
+ if (m_nextBinding) m_nextBinding->m_prevBinding = &m_nextBinding;
+ m_prevBinding = &data->bindings;
+ data->bindings = this;
+
+ data->setBindingBit(m_object, index);
+ }
}
void QDeclarativeAbstractBinding::removeFromObject()
{
if (m_prevBinding) {
+ int index = propertyIndex();
+
Q_ASSERT(m_object);
*m_prevBinding = m_nextBinding;
@@ -283,8 +317,14 @@ void QDeclarativeAbstractBinding::removeFromObject()
m_prevBinding = 0;
m_nextBinding = 0;
- QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(m_object, false);
- if (data) data->clearBindingBit(propertyIndex());
+ if (index & 0xFF000000) {
+ // Value type - we don't remove the proxy from the object. It will sit their happily
+ // doing nothing for ever more.
+ } else {
+ QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(m_object, false);
+ if (data) data->clearBindingBit(index);
+ }
+
m_object = 0;
}
}
@@ -305,4 +345,88 @@ void QDeclarativeAbstractBinding::setEnabled(bool e, QDeclarativePropertyPrivate
if (e) m_mePtr = 0;
}
+QDeclarativeValueTypeProxyBinding::QDeclarativeValueTypeProxyBinding(QObject *o, int index)
+: m_object(o), m_index(index), m_bindings(0)
+{
+}
+
+QDeclarativeValueTypeProxyBinding::~QDeclarativeValueTypeProxyBinding()
+{
+ while (m_bindings) {
+ QDeclarativeAbstractBinding *binding = m_bindings;
+ binding->setEnabled(false, 0);
+ binding->destroy();
+ }
+}
+
+void QDeclarativeValueTypeProxyBinding::setEnabled(bool e, QDeclarativePropertyPrivate::WriteFlags flags)
+{
+ if (e) {
+ addToObject(m_object);
+
+ QDeclarativeAbstractBinding *bindings = m_bindings;
+ m_bindings = 0;
+ recursiveEnable(bindings, flags);
+ } else {
+ removeFromObject();
+
+ QDeclarativeAbstractBinding *bindings = m_bindings;
+ m_bindings = 0;
+ recursiveDisable(bindings);
+ }
+}
+
+void QDeclarativeValueTypeProxyBinding::recursiveEnable(QDeclarativeAbstractBinding *b, QDeclarativePropertyPrivate::WriteFlags flags)
+{
+ if (!b)
+ return;
+
+ QDeclarativeAbstractBinding *next = b->m_nextBinding;
+ b->m_prevBinding = 0;
+ b->m_nextBinding = 0;
+ Q_ASSERT(b->m_mePtr == 0);
+ b->m_mePtr = &b;
+
+ recursiveEnable(next, flags);
+
+ if (b)
+ b->setEnabled(true, flags);
+}
+
+void QDeclarativeValueTypeProxyBinding::recursiveDisable(QDeclarativeAbstractBinding *b)
+{
+ if (!b)
+ return;
+
+ recursiveDisable(b->m_nextBinding);
+
+ b->setEnabled(false, 0);
+
+ Q_ASSERT(b->m_prevBinding == 0);
+ Q_ASSERT(b->m_nextBinding == 0);
+ b->m_nextBinding = m_bindings;
+ if (b->m_nextBinding) b->m_nextBinding->m_prevBinding = &b->m_nextBinding;
+ b->m_prevBinding = &m_bindings;
+ m_bindings = b;
+}
+
+int QDeclarativeValueTypeProxyBinding::propertyIndex()
+{
+ return m_index;
+}
+
+void QDeclarativeValueTypeProxyBinding::update(QDeclarativePropertyPrivate::WriteFlags)
+{
+}
+
+QDeclarativeAbstractBinding *QDeclarativeValueTypeProxyBinding::binding(int propertyIndex)
+{
+ QDeclarativeAbstractBinding *binding = m_bindings;
+
+ while (binding && binding->propertyIndex() != propertyIndex)
+ binding = binding->m_nextBinding;
+
+ return binding;
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativebinding_p.h b/src/declarative/qml/qdeclarativebinding_p.h
index 1a714f0..21e3248 100644
--- a/src/declarative/qml/qdeclarativebinding_p.h
+++ b/src/declarative/qml/qdeclarativebinding_p.h
@@ -74,6 +74,9 @@ public:
virtual QString expression() const;
+ enum Type { PropertyBinding, ValueTypeProxy };
+ virtual Type bindingType() const { return PropertyBinding; }
+
void setEnabled(bool e) { setEnabled(e, QDeclarativePropertyPrivate::DontRemoveBinding); }
virtual void setEnabled(bool, QDeclarativePropertyPrivate::WriteFlags) = 0;
virtual int propertyIndex() = 0;
@@ -92,6 +95,7 @@ private:
friend class QDeclarativeProperty;
friend class QDeclarativePropertyPrivate;
friend class QDeclarativeVME;
+ friend class QDeclarativeValueTypeProxyBinding;
QObject *m_object;
QDeclarativeAbstractBinding **m_mePtr;
@@ -99,6 +103,30 @@ private:
QDeclarativeAbstractBinding *m_nextBinding;
};
+class QDeclarativeValueTypeProxyBinding : public QDeclarativeAbstractBinding
+{
+public:
+ QDeclarativeValueTypeProxyBinding(QObject *o, int coreIndex);
+ virtual ~QDeclarativeValueTypeProxyBinding();
+
+ virtual Type bindingType() const { return ValueTypeProxy; }
+
+ virtual void setEnabled(bool, QDeclarativePropertyPrivate::WriteFlags);
+ virtual int propertyIndex();
+ virtual void update(QDeclarativePropertyPrivate::WriteFlags);
+
+ QDeclarativeAbstractBinding *binding(int propertyIndex);
+
+private:
+ void recursiveEnable(QDeclarativeAbstractBinding *, QDeclarativePropertyPrivate::WriteFlags);
+ void recursiveDisable(QDeclarativeAbstractBinding *);
+
+ friend class QDeclarativeAbstractBinding;
+ QObject *m_object;
+ int m_index;
+ QDeclarativeAbstractBinding *m_bindings;
+};
+
class QDeclarativeContext;
class QDeclarativeBindingPrivate;
class Q_DECLARATIVE_EXPORT QDeclarativeBinding : public QDeclarativeExpression, public QDeclarativeAbstractBinding
diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp
index 17937fd..aa549a9 100644
--- a/src/declarative/qml/qdeclarativecompiledbindings.cpp
+++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp
@@ -48,12 +48,17 @@
#include <private/qdeclarativejsast_p.h>
#include <private/qdeclarativejsengine_p.h>
#include <private/qdeclarativeexpression_p.h>
+#include <QtCore/qcoreapplication.h>
#include <QtCore/qdebug.h>
#include <QtCore/qnumeric.h>
#include <private/qdeclarativeanchors_p_p.h>
+#include <private/qdeclarativeglobal_p.h>
QT_BEGIN_NAMESPACE
+DEFINE_BOOL_CONFIG_OPTION(qmlExperimental, QML_EXPERIMENTAL);
+DEFINE_BOOL_CONFIG_OPTION(qmlDisableOptimizer, QML_DISABLE_OPTIMIZER);
+
using namespace QDeclarativeJS;
namespace {
@@ -124,24 +129,7 @@ public:
QDeclarativeCompiledBindingsPrivate *parent;
};
- struct Subscription {
- struct Signal {
- QDeclarativeGuard<QObject> source;
- int notifyIndex;
- };
-
- enum { InvalidType, SignalType, IdType } type;
- inline Subscription();
- inline ~Subscription();
- bool isSignal() const { return type == SignalType; }
- bool isId() const { return type == IdType; }
- inline Signal *signal();
- inline QDeclarativeContextPrivate::IdNotifier *id();
- union {
- char signalData[sizeof(Signal)];
- char idData[sizeof(QDeclarativeContextPrivate::IdNotifier)];
- };
- };
+ typedef QDeclarativeNotifierEndpoint Subscription;
Subscription *subscriptions;
QScriptDeclarativeClass::PersistentIdentifier *identifiers;
@@ -190,18 +178,6 @@ QDeclarativeCompiledBindingsPrivate::~QDeclarativeCompiledBindingsPrivate()
delete [] identifiers; identifiers = 0;
}
-QDeclarativeCompiledBindingsPrivate::Subscription::Subscription()
-: type(InvalidType)
-{
-}
-
-QDeclarativeCompiledBindingsPrivate::Subscription::~Subscription()
-{
- if (type == SignalType) ((Signal *)signalData)->~Signal();
- else if (type == IdType) ((QDeclarativeContextPrivate::IdNotifier *)idData)->~IdNotifier();
-}
-
-
int QDeclarativeCompiledBindingsPrivate::methodCount = -1;
QDeclarativeCompiledBindings::QDeclarativeCompiledBindings(const char *program, QDeclarativeContext *context)
@@ -248,7 +224,6 @@ void QDeclarativeCompiledBindingsPrivate::Binding::setEnabled(bool e, QDeclarati
{
if (e) {
addToObject(target);
- update(flags);
} else {
removeFromObject();
}
@@ -303,8 +278,6 @@ void QDeclarativeCompiledBindingsPrivate::run(Binding *binding)
if (!binding->enabled)
return;
- if (binding->updating)
- qWarning("ERROR: Circular binding");
QDeclarativeContext *context = q->QDeclarativeAbstractExpression::context();
if (!context) {
@@ -313,6 +286,25 @@ void QDeclarativeCompiledBindingsPrivate::run(Binding *binding)
}
QDeclarativeContextPrivate *cp = QDeclarativeContextPrivate::get(context);
+ if (binding->updating) {
+ QString name;
+ if (binding->property & 0xFFFF0000) {
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(cp->engine);
+
+ QDeclarativeValueType *vt = ep->valueTypes[(binding->property >> 16) & 0xFF];
+ Q_ASSERT(vt);
+
+ name = QLatin1String(binding->target->metaObject()->property(binding->property & 0xFFFF).name());
+ name.append(QLatin1String("."));
+ name.append(QLatin1String(vt->metaObject()->property(binding->property >> 24).name()));
+ } else {
+ name = binding->target->metaObject()->property(binding->property).name();
+ }
+ qmlInfo(binding->target) << QCoreApplication::translate("QDeclarativeCompiledBindings", "Binding loop detected for property \"%1\"").arg(name);
+ return;
+ }
+
+ binding->updating = true;
if (binding->property & 0xFFFF0000) {
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(cp->engine);
@@ -328,22 +320,7 @@ void QDeclarativeCompiledBindingsPrivate::run(Binding *binding)
} else {
run(binding->index, cp, binding, binding->scope, binding->target);
}
-}
-
-QDeclarativeCompiledBindingsPrivate::Subscription::Signal *QDeclarativeCompiledBindingsPrivate::Subscription::signal()
-{
- if (type == IdType) ((QDeclarativeContextPrivate::IdNotifier *)idData)->~IdNotifier();
- if (type != SignalType) new (signalData) Signal;
- type = SignalType;
- return (Signal *)signalData;
-}
-
-QDeclarativeContextPrivate::IdNotifier *QDeclarativeCompiledBindingsPrivate::Subscription::id()
-{
- if (type == SignalType) ((Signal *)signalData)->~Signal();
- if (type != IdType) new (idData) QDeclarativeContextPrivate::IdNotifier;
- type = IdType;
- return (QDeclarativeContextPrivate::IdNotifier *)idData;
+ binding->updating = false;
}
namespace {
@@ -656,20 +633,7 @@ void QDeclarativeCompiledBindingsPrivate::unsubscribe(int subIndex)
Q_Q(QDeclarativeCompiledBindings);
QDeclarativeCompiledBindingsPrivate::Subscription *sub = (subscriptions + subIndex);
- if (sub->isSignal()) {
- QDeclarativeCompiledBindingsPrivate::Subscription::Signal *s = sub->signal();
- if (s->source)
-#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 2))
- QMetaObject::disconnectOne(s->source, s->notifyIndex,
- q, methodCount + subIndex);
-#else
- // QTBUG-6781
- QMetaObject::disconnect(s->source, s->notifyIndex,
- q, methodCount + subIndex);
-#endif
- } else if (sub->isId()) {
- sub->id()->clear();
- }
+ sub->disconnect();
}
void QDeclarativeCompiledBindingsPrivate::subscribeId(QDeclarativeContextPrivate *p, int idIndex, int subIndex)
@@ -680,15 +644,9 @@ void QDeclarativeCompiledBindingsPrivate::subscribeId(QDeclarativeContextPrivate
if (p->idValues[idIndex]) {
QDeclarativeCompiledBindingsPrivate::Subscription *sub = (subscriptions + subIndex);
- QDeclarativeContextPrivate::IdNotifier *i = sub->id();
-
- i->next = p->idValues[idIndex].bindings;
- i->prev = &p->idValues[idIndex].bindings;
- p->idValues[idIndex].bindings = i;
- if (i->next) i->next->prev = &i->next;
-
- i->target = q;
- i->methodIndex = methodCount + subIndex;
+ sub->target = q;
+ sub->targetMethod = methodCount + subIndex;
+ sub->connect(&p->idValues[idIndex].bindings);
}
}
@@ -697,27 +655,12 @@ void QDeclarativeCompiledBindingsPrivate::subscribe(QObject *o, int notifyIndex,
Q_Q(QDeclarativeCompiledBindings);
QDeclarativeCompiledBindingsPrivate::Subscription *sub = (subscriptions + subIndex);
-
- if (sub->isId())
- unsubscribe(subIndex);
-
- QDeclarativeCompiledBindingsPrivate::Subscription::Signal *s = sub->signal();
- if (o != s->source || notifyIndex != s->notifyIndex) {
- if (s->source)
-#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 2))
- QMetaObject::disconnectOne(s->source, s->notifyIndex,
- q, methodCount + subIndex);
-#else
- // QTBUG-6781
- QMetaObject::disconnect(s->source, s->notifyIndex,
- q, methodCount + subIndex);
-#endif
- s->source = o;
- s->notifyIndex = notifyIndex;
- if (s->source && s->notifyIndex != -1)
- QMetaObject::connect(s->source, s->notifyIndex, q,
- methodCount + subIndex, Qt::DirectConnection);
- }
+ sub->target = q;
+ sub->targetMethod = methodCount + subIndex;
+ if (o)
+ sub->connect(o, notifyIndex);
+ else
+ sub->disconnect();
}
// Conversion functions - these MUST match the QtScript expression path
@@ -811,9 +754,9 @@ static QObject *variantToQObject(const QVariant &value, bool *ok)
}
bool QDeclarativeCompiledBindingsPrivate::findproperty(QObject *obj, Register *output,
- QDeclarativeEnginePrivate *enginePriv,
- int subIdx, const QScriptDeclarativeClass::Identifier &name,
- bool isTerminal)
+ QDeclarativeEnginePrivate *enginePriv,
+ int subIdx, const QScriptDeclarativeClass::Identifier &name,
+ bool isTerminal)
{
if (!obj) {
output->setUndefined();
@@ -884,10 +827,10 @@ bool QDeclarativeCompiledBindingsPrivate::findproperty(QObject *obj, Register *o
}
void QDeclarativeCompiledBindingsPrivate::findgeneric(Register *output,
- int subIdx,
- QDeclarativeContextPrivate *context,
- const QScriptDeclarativeClass::Identifier &name,
- bool isTerminal)
+ int subIdx,
+ QDeclarativeContextPrivate *context,
+ const QScriptDeclarativeClass::Identifier &name,
+ bool isTerminal)
{
QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(context->engine);
@@ -928,7 +871,7 @@ void QDeclarativeCompiledBindingsPrivate::findgeneric(Register *output,
}
}
- if (QObject *root = context->defaultObjects.isEmpty()?0:context->defaultObjects.first()) {
+ if (QObject *root = context->contextObject) {
if (findproperty(root, output, enginePriv, subIdx, name, isTerminal))
return;
@@ -1169,7 +1112,7 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex,
break;
case Instr::LoadRoot:
- registers[instr->load.reg].setQObject(context->defaultObjects.at(0));
+ registers[instr->load.reg].setQObject(context->contextObject);
break;
case Instr::LoadAttached:
@@ -1612,6 +1555,9 @@ bool QDeclarativeBindingCompilerPrivate::compile(QDeclarativeJS::AST::Node *node
return false;
if (type.unknownType) {
+ if (!qmlExperimental())
+ return false;
+
if (destination->type != QMetaType::QReal &&
destination->type != QVariant::String &&
destination->type != QMetaType::Bool &&
@@ -1895,7 +1841,7 @@ bool QDeclarativeBindingCompilerPrivate::parseName(AST::Node *node, Result &type
if (!fetch(type, component->metaObject(), reg, d1Idx, subscribeName, nameNodes.at(ii)))
return false;
- } else {
+ } else if (qmlExperimental()) {
Instr find;
if (nameParts.count() == 1)
find.common.type = Instr::FindGenericTerminal;
@@ -2051,7 +1997,11 @@ bool QDeclarativeBindingCompilerPrivate::numberArith(Result &type, const Result
int lhsTmp = -1;
int rhsTmp = -1;
+
if (lhs.unknownType) {
+ if (!qmlExperimental())
+ return false;
+
lhsTmp = acquireReg();
Instr conv;
@@ -2062,6 +2012,9 @@ bool QDeclarativeBindingCompilerPrivate::numberArith(Result &type, const Result
}
if (rhs.unknownType) {
+ if (!qmlExperimental())
+ return false;
+
rhsTmp = acquireReg();
Instr conv;
@@ -2107,6 +2060,9 @@ bool QDeclarativeBindingCompilerPrivate::stringArith(Result &type, const Result
int rhsTmp = -1;
if (lhs.unknownType) {
+ if (!qmlExperimental())
+ return false;
+
lhsTmp = acquireReg(Instr::CleanupString);
Instr convert;
@@ -2117,6 +2073,9 @@ bool QDeclarativeBindingCompilerPrivate::stringArith(Result &type, const Result
}
if (rhs.unknownType) {
+ if (!qmlExperimental())
+ return false;
+
rhsTmp = acquireReg(Instr::CleanupString);
Instr convert;
@@ -2637,6 +2596,12 @@ int QDeclarativeBindingCompiler::compile(const Expression &expression, QDeclarat
{
if (!expression.expression.asAST()) return false;
+ if (!qmlExperimental() && expression.property->isValueTypeSubProperty)
+ return -1;
+
+ if (qmlDisableOptimizer())
+ return -1;
+
d->context = expression.context;
d->component = expression.component;
d->destination = expression.property;
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index ef1032b..06ff47c 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -82,7 +82,7 @@ QT_BEGIN_NAMESPACE
DEFINE_BOOL_CONFIG_OPTION(compilerDump, QML_COMPILER_DUMP);
DEFINE_BOOL_CONFIG_OPTION(compilerStatDump, QML_COMPILER_STATISTICS_DUMP);
-DEFINE_BOOL_CONFIG_OPTION(qmlExperimental, QML_EXPERIMENTAL);
+DEFINE_BOOL_CONFIG_OPTION(bindingsDump, QML_BINDINGS_DUMP);
using namespace QDeclarativeParser;
@@ -1850,6 +1850,7 @@ bool QDeclarativeCompiler::buildValueTypeProperty(QObject *type,
QMetaProperty p = type->metaObject()->property(idx);
prop->index = idx;
prop->type = p.userType();
+ prop->isValueTypeSubProperty = true;
if (prop->value)
COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Property assignment expected"));
@@ -2712,7 +2713,9 @@ bool QDeclarativeCompiler::completeComponentBuild()
QDeclarativeBindingCompiler bindingCompiler;
- for (QHash<QDeclarativeParser::Value*,BindingReference>::Iterator iter = compileState.bindings.begin(); iter != compileState.bindings.end(); ++iter) {
+ for (QHash<QDeclarativeParser::Value*,BindingReference>::Iterator iter = compileState.bindings.begin();
+ iter != compileState.bindings.end(); ++iter) {
+
BindingReference &binding = *iter;
expr.context = binding.bindingContext.object;
@@ -2720,18 +2723,13 @@ bool QDeclarativeCompiler::completeComponentBuild()
expr.expression = binding.expression;
expr.imports = unit->imports;
- if (qmlExperimental()) {
- int index = bindingCompiler.compile(expr, QDeclarativeEnginePrivate::get(engine));
- if (index != -1) {
- qWarning() << "Accepted for optimization:" << qPrintable(expr.expression.asScript());
- binding.dataType = BindingReference::Experimental;
- binding.compiledIndex = index;
- componentStat.optimizedBindings++;
- continue;
- } else {
- qWarning() << "Rejected for optimization:" << qPrintable(expr.expression.asScript());
- }
- }
+ int index = bindingCompiler.compile(expr, QDeclarativeEnginePrivate::get(engine));
+ if (index != -1) {
+ binding.dataType = BindingReference::Experimental;
+ binding.compiledIndex = index;
+ componentStat.optimizedBindings++;
+ continue;
+ }
binding.dataType = BindingReference::QtScript;
@@ -2768,7 +2766,8 @@ bool QDeclarativeCompiler::completeComponentBuild()
if (bindingCompiler.isValid()) {
compileState.compiledBindingData = bindingCompiler.program();
- QDeclarativeBindingCompiler::dump(compileState.compiledBindingData);
+ if (bindingsDump())
+ QDeclarativeBindingCompiler::dump(compileState.compiledBindingData);
}
saveComponentState();
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp
index d6bb216..d3608c4 100644
--- a/src/declarative/qml/qdeclarativecomponent.cpp
+++ b/src/declarative/qml/qdeclarativecomponent.cpp
@@ -512,7 +512,6 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q
{
}
-
/*!
\internal
A version of create which returns a scriptObject, for use in script
@@ -526,7 +525,9 @@ QScriptValue QDeclarativeComponent::createObject()
return QScriptValue();
}
QObject* ret = create(ctxt);
- return QDeclarativeEnginePrivate::qmlScriptObject(ret, d->engine);
+ QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(d->engine);
+ QDeclarativeDeclarativeData::get(ret, true)->setImplicitDestructible();
+ return priv->objectClass->newQObject(ret, QMetaType::QObjectStar);
}
/*!
@@ -541,7 +542,12 @@ QObject *QDeclarativeComponent::create(QDeclarativeContext *context)
{
Q_D(QDeclarativeComponent);
- return d->create(context, QBitField());
+ if (!context)
+ context = d->engine->rootContext();
+
+ QObject *rv = beginCreate(context);
+ completeCreate();
+ return rv;
}
QObject *QDeclarativeComponentPrivate::create(QDeclarativeContext *context,
@@ -586,7 +592,13 @@ QObject *QDeclarativeComponentPrivate::create(QDeclarativeContext *context,
QObject *QDeclarativeComponent::beginCreate(QDeclarativeContext *context)
{
Q_D(QDeclarativeComponent);
- return d->beginCreate(context, QBitField());
+ QObject *rv = d->beginCreate(context, QBitField());
+ if (rv) {
+ QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(rv);
+ Q_ASSERT(ddata);
+ ddata->indestructible = true;
+ }
+ return rv;
}
QObject *
diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
index b90a598..e2a6e0c 100644
--- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp
+++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
@@ -154,7 +154,7 @@ QDeclarativeCompositeTypeData::TypeReference::TypeReference()
}
QDeclarativeCompositeTypeManager::QDeclarativeCompositeTypeManager(QDeclarativeEngine *e)
-: engine(e)
+: engine(e), redirectCount(0)
{
}
@@ -172,6 +172,10 @@ QDeclarativeCompositeTypeManager::~QDeclarativeCompositeTypeManager()
QDeclarativeCompositeTypeData *QDeclarativeCompositeTypeManager::get(const QUrl &url)
{
+ Redirects::Iterator redir = redirects.find(url);
+ if (redir != redirects.end())
+ return get(*redir);
+
QDeclarativeCompositeTypeData *unit = components.value(url);
if (!unit) {
@@ -219,6 +223,8 @@ void QDeclarativeCompositeTypeManager::clearCache()
}
}
+#define TYPEMANAGER_MAXIMUM_REDIRECT_RECURSION 16
+
void QDeclarativeCompositeTypeManager::replyFinished()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
@@ -226,6 +232,26 @@ void QDeclarativeCompositeTypeManager::replyFinished()
QDeclarativeCompositeTypeData *unit = components.value(reply->url());
Q_ASSERT(unit);
+ redirectCount++;
+ if (redirectCount < TYPEMANAGER_MAXIMUM_REDIRECT_RECURSION) {
+ QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirect.isValid()) {
+ QUrl url = reply->url().resolved(redirect.toUrl());
+ redirects.insert(reply->url(),url);
+ unit->imports.setBaseUrl(url);
+ components.remove(reply->url());
+ components.insert(url, unit);
+ reply->deleteLater();
+ reply = engine->networkAccessManager()->get(QNetworkRequest(url));
+ QObject::connect(reply, SIGNAL(finished()),
+ this, SLOT(replyFinished()));
+ QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
+ this, SLOT(requestProgress(qint64,qint64)));
+ return;
+ }
+ }
+ redirectCount = 0;
+
if (reply->error() != QNetworkReply::NoError) {
QString errorDescription;
// ### - Fill in error
@@ -256,6 +282,24 @@ void QDeclarativeCompositeTypeManager::resourceReplyFinished()
QDeclarativeCompositeTypeResource *resource = resources.value(reply->url());
Q_ASSERT(resource);
+ redirectCount++;
+ if (redirectCount < TYPEMANAGER_MAXIMUM_REDIRECT_RECURSION) {
+ QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirect.isValid()) {
+ QUrl url = reply->url().resolved(redirect.toUrl());
+ redirects.insert(reply->url(),url);
+ resource->url = url.toString();
+ resources.remove(reply->url());
+ resources.insert(url, resource);
+ reply->deleteLater();
+ reply = engine->networkAccessManager()->get(QNetworkRequest(url));
+ QObject::connect(reply, SIGNAL(finished()),
+ this, SLOT(resourceReplyFinished()));
+ return;
+ }
+ }
+ redirectCount = 0;
+
if (reply->error() != QNetworkReply::NoError) {
resource->status = QDeclarativeCompositeTypeResource::Error;
@@ -462,17 +506,18 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData
int waiting = 0;
foreach (QDeclarativeScriptParser::Import imp, unit->data.imports()) {
- QString qmldir;
+ QString qmldircontentnetwork;
if (imp.type == QDeclarativeScriptParser::Import::File && imp.qualifier.isEmpty()) {
QString importUrl = unit->imports.baseUrl().resolved(QUrl(imp.uri + QLatin1String("/qmldir"))).toString();
for (int ii = 0; ii < unit->resources.count(); ++ii) {
if (unit->resources.at(ii)->url == importUrl) {
- qmldir = QString::fromUtf8(unit->resources.at(ii)->data);
+ qmldircontentnetwork = QString::fromUtf8(unit->resources.at(ii)->data);
break;
}
}
}
+
int vmaj = -1;
int vmin = -1;
if (!imp.version.isEmpty()) {
@@ -487,7 +532,7 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData
}
if (!QDeclarativeEnginePrivate::get(engine)->
- addToImport(&unit->imports, qmldir, imp.uri, imp.qualifier, vmaj, vmin, imp.type))
+ addToImport(&unit->imports, qmldircontentnetwork, imp.uri, imp.qualifier, vmaj, vmin, imp.type))
{
QDeclarativeError error;
error.setUrl(unit->imports.baseUrl());
@@ -546,6 +591,10 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData
continue;
}
+ Redirects::Iterator redir = redirects.find(url);
+ if (redir != redirects.end())
+ url = *redir;
+
QDeclarativeCompositeTypeData *urlUnit = components.value(url);
if (!urlUnit) {
diff --git a/src/declarative/qml/qdeclarativecompositetypemanager_p.h b/src/declarative/qml/qdeclarativecompositetypemanager_p.h
index 03d16b8..a572e0c 100644
--- a/src/declarative/qml/qdeclarativecompositetypemanager_p.h
+++ b/src/declarative/qml/qdeclarativecompositetypemanager_p.h
@@ -109,6 +109,9 @@ private:
Components components;
typedef QHash<QUrl, QDeclarativeCompositeTypeResource *> Resources;
Resources resources;
+ typedef QHash<QUrl, QUrl> Redirects;
+ Redirects redirects;
+ int redirectCount;
};
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index f70e143..237cb7e 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -59,12 +59,14 @@ QT_BEGIN_NAMESPACE
QDeclarativeContextPrivate::QDeclarativeContextPrivate()
: parent(0), engine(0), isInternal(false), propertyNames(0),
- notifyIndex(-1), highPriorityCount(0), imports(0), expressions(0), contextObjects(0),
+ notifyIndex(-1), contextObject(0), imports(0), childContexts(0),
+ nextChild(0), prevChild(0), expressions(0), contextObjects(0),
idValues(0), idValueCount(0), optimizedBindings(0)
{
}
-void QDeclarativeContextPrivate::addScript(const QDeclarativeParser::Object::ScriptBlock &script, QObject *scopeObject)
+void QDeclarativeContextPrivate::addScript(const QDeclarativeParser::Object::ScriptBlock &script,
+ QObject *scopeObject)
{
Q_Q(QDeclarativeContext);
@@ -109,12 +111,7 @@ void QDeclarativeContextPrivate::destroyed(ContextGuard *guard)
if (parent && QObjectPrivate::get(parent)->wasDeleted)
return;
- while(guard->bindings) {
- QObject *o = guard->bindings->target;
- int mi = guard->bindings->methodIndex;
- guard->bindings->clear();
- if (o) o->qt_metacall(QMetaObject::InvokeMetaMethod, mi, 0);
- }
+ guard->bindings.notify();
for (int ii = 0; ii < idValueCount; ++ii) {
if (&idValues[ii] == guard) {
@@ -128,8 +125,13 @@ void QDeclarativeContextPrivate::init()
{
Q_Q(QDeclarativeContext);
- if (parent)
- parent->d_func()->childContexts.insert(q);
+ if (parent) {
+ QDeclarativeContextPrivate *ppriv = parent->d_func();
+ nextChild = ppriv->childContexts;
+ if (nextChild) nextChild->d_func()->prevChild = &nextChild;
+ prevChild = &ppriv->childContexts;
+ ppriv->childContexts = q;
+ }
}
/*!
@@ -177,7 +179,7 @@ void QDeclarativeContextPrivate::init()
MyDataSet myDataSet;
QDeclarativeEngine engine;
QDeclarativeContext context(engine.rootContext());
- context.addDefaultObject(&myDataSet);
+ context.setContextObject(&myDataSet);
QDeclarativeComponent component(&engine, "ListView { model=myModel }");
component.create(&context);
@@ -275,15 +277,24 @@ QDeclarativeContext::QDeclarativeContext(QDeclarativeContext *parentContext, QOb
QDeclarativeContext::~QDeclarativeContext()
{
Q_D(QDeclarativeContext);
- if (d->parent)
- d->parent->d_func()->childContexts.remove(this);
-
- for (QSet<QDeclarativeContext *>::ConstIterator iter = d->childContexts.begin();
- iter != d->childContexts.end();
- ++iter) {
- (*iter)->d_func()->invalidateEngines();
- (*iter)->d_func()->parent = 0;
+
+ if (d->prevChild) {
+ *d->prevChild = d->nextChild;
+ if (d->nextChild) d->nextChild->d_func()->prevChild = d->prevChild;
+ d->nextChild = 0;
+ d->prevChild = 0;
}
+
+ QDeclarativeContext *child = d->childContexts;
+ while (child) {
+ QDeclarativeContextPrivate *childpriv = child->d_func();
+ childpriv->invalidateEngines();
+ childpriv->parent = 0;
+ child = childpriv->nextChild;
+ childpriv->nextChild = 0;
+ childpriv->prevChild = 0;
+ }
+ d->childContexts = 0;
QDeclarativeAbstractExpression *expression = d->expressions;
while (expression) {
@@ -322,10 +333,12 @@ void QDeclarativeContextPrivate::invalidateEngines()
if (!engine)
return;
engine = 0;
- for (QSet<QDeclarativeContext *>::ConstIterator iter = childContexts.begin();
- iter != childContexts.end();
- ++iter) {
- (*iter)->d_func()->invalidateEngines();
+
+ QDeclarativeContext *child = childContexts;
+ while (child) {
+ QDeclarativeContextPrivate *childpriv = child->d_func();
+ childpriv->invalidateEngines();
+ child = childpriv->nextChild;
}
}
@@ -336,10 +349,11 @@ time the context tree *structure* (not values) changes.
*/
void QDeclarativeContextPrivate::refreshExpressions()
{
- for (QSet<QDeclarativeContext *>::ConstIterator iter = childContexts.begin();
- iter != childContexts.end();
- ++iter) {
- (*iter)->d_func()->refreshExpressions();
+ QDeclarativeContext *child = childContexts;
+ while (child) {
+ QDeclarativeContextPrivate *childpriv = child->d_func();
+ childpriv->refreshExpressions();
+ child = childpriv->nextChild;
}
QDeclarativeAbstractExpression *expression = expressions;
@@ -370,13 +384,21 @@ QDeclarativeContext *QDeclarativeContext::parentContext() const
}
/*!
- Add \a defaultObject to this context. The object will be added after
- any existing default objects.
+ Return the context object, or 0 if there is no context object.
*/
-void QDeclarativeContext::addDefaultObject(QObject *defaultObject)
+QObject *QDeclarativeContext::contextObject() const
+{
+ Q_D(const QDeclarativeContext);
+ return d->contextObject;
+}
+
+/*!
+ Set the context \a object.
+*/
+void QDeclarativeContext::setContextObject(QObject *object)
{
Q_D(QDeclarativeContext);
- d->defaultObjects.prepend(defaultObject);
+ d->contextObject = object;
}
/*!
@@ -471,15 +493,12 @@ QVariant QDeclarativeContext::contextProperty(const QString &name) const
if (idx == -1) {
QByteArray utf8Name = name.toUtf8();
- for (int ii = d->defaultObjects.count() - 1; ii >= 0; --ii) {
- QObject *obj = d->defaultObjects.at(ii);
+ if (d->contextObject) {
+ QObject *obj = d->contextObject;
QDeclarativePropertyCache::Data local;
QDeclarativePropertyCache::Data *property = QDeclarativePropertyCache::property(d->engine, obj, name, local);
- if (property) {
- value = obj->metaObject()->property(property->coreIndex).read(obj);
- break;
- }
+ if (property) value = obj->metaObject()->property(property->coreIndex).read(obj);
}
if (!value.isValid() && parentContext())
value = parentContext()->contextProperty(name);
diff --git a/src/declarative/qml/qdeclarativecontext.h b/src/declarative/qml/qdeclarativecontext.h
index 0fb9bee..3ad9863 100644
--- a/src/declarative/qml/qdeclarativecontext.h
+++ b/src/declarative/qml/qdeclarativecontext.h
@@ -72,11 +72,12 @@ public:
QDeclarativeEngine *engine() const;
QDeclarativeContext *parentContext() const;
- void addDefaultObject(QObject *);
- void setContextProperty(const QString &, QObject *);
- void setContextProperty(const QString &, const QVariant &);
+ QObject *contextObject() const;
+ void setContextObject(QObject *);
QVariant contextProperty(const QString &) const;
+ void setContextProperty(const QString &, QObject *);
+ void setContextProperty(const QString &, const QVariant &);
QUrl resolvedUrl(const QUrl &);
diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h
index 8297280..a1056b1 100644
--- a/src/declarative/qml/qdeclarativecontext_p.h
+++ b/src/declarative/qml/qdeclarativecontext_p.h
@@ -59,6 +59,7 @@
#include "qdeclarativeengine_p.h"
#include "qdeclarativeintegercache_p.h"
#include "qdeclarativetypenamecache_p.h"
+#include "qdeclarativenotifier_p.h"
#include <QtCore/qhash.h>
#include <QtScript/qscriptvalue.h>
@@ -93,8 +94,7 @@ public:
QList<QVariant> propertyValues;
int notifyIndex;
- QObjectList defaultObjects;
- int highPriorityCount;
+ QObject *contextObject;
QList<QScriptValue> scripts;
void addScript(const QDeclarativeParser::Object::ScriptBlock &, QObject *);
@@ -107,25 +107,16 @@ public:
void invalidateEngines();
void refreshExpressions();
- QSet<QDeclarativeContext *> childContexts;
+
+ QDeclarativeContext *childContexts;
+
+ QDeclarativeContext *nextChild;
+ QDeclarativeContext **prevChild;
QDeclarativeAbstractExpression *expressions;
QDeclarativeDeclarativeData *contextObjects;
- struct IdNotifier
- {
- inline IdNotifier();
- inline ~IdNotifier();
-
- inline void clear();
-
- IdNotifier *next;
- IdNotifier**prev;
- QObject *target;
- int methodIndex;
- };
-
struct ContextGuard : public QDeclarativeGuard<QObject>
{
inline ContextGuard();
@@ -133,7 +124,7 @@ public:
inline virtual void objectDestroyed(QObject *);
QDeclarativeContextPrivate *priv;
- IdNotifier *bindings;
+ QDeclarativeNotifier bindings;
};
ContextGuard *idValues;
int idValueCount;
@@ -157,26 +148,8 @@ public:
static QObject *context_at(QDeclarativeListProperty<QObject> *, int);
};
-QDeclarativeContextPrivate::IdNotifier::IdNotifier()
-: next(0), prev(0), target(0), methodIndex(-1)
-{
-}
-
-QDeclarativeContextPrivate::IdNotifier::~IdNotifier()
-{
- clear();
-}
-
-void QDeclarativeContextPrivate::IdNotifier::clear()
-{
- if (next) next->prev = prev;
- if (prev) *prev = next;
- next = 0; prev = 0; target = 0;
- methodIndex = -1;
-}
-
QDeclarativeContextPrivate::ContextGuard::ContextGuard()
-: priv(0), bindings(0)
+: priv(0)
{
}
diff --git a/src/declarative/qml/qdeclarativecontextscriptclass.cpp b/src/declarative/qml/qdeclarativecontextscriptclass.cpp
index 5fcf4e2..874eeac 100644
--- a/src/declarative/qml/qdeclarativecontextscriptclass.cpp
+++ b/src/declarative/qml/qdeclarativecontextscriptclass.cpp
@@ -80,7 +80,7 @@ struct ContextData : public QScriptDeclarativeClass::Object {
*/
QDeclarativeContextScriptClass::QDeclarativeContextScriptClass(QDeclarativeEngine *bindEngine)
: QDeclarativeScriptClass(QDeclarativeEnginePrivate::getScriptEngine(bindEngine)), engine(bindEngine),
- lastScopeObject(0), lastContext(0), lastData(0), lastPropertyIndex(-1), lastDefaultObject(-1)
+ lastScopeObject(0), lastContext(0), lastData(0), lastPropertyIndex(-1)
{
}
@@ -132,7 +132,6 @@ QDeclarativeContextScriptClass::queryProperty(Object *object, const Identifier &
lastContext = 0;
lastData = 0;
lastPropertyIndex = -1;
- lastDefaultObject = -1;
QDeclarativeContext *bindContext = ((ContextData *)object)->getContext(engine);
QObject *scopeObject = ((ContextData *)object)->getScope(engine);
@@ -210,13 +209,13 @@ QDeclarativeContextScriptClass::queryProperty(QDeclarativeContext *bindContext,
}
}
- for (int ii = cp->defaultObjects.count() - 1; ii >= 0; --ii) {
+ if (cp->contextObject) {
QScriptClass::QueryFlags rv =
- ep->objectClass->queryProperty(cp->defaultObjects.at(ii), name, flags, bindContext,
+ ep->objectClass->queryProperty(cp->contextObject, name, flags, bindContext,
QDeclarativeObjectScriptClass::ImplicitObject | QDeclarativeObjectScriptClass::SkipAttachedProperties);
if (rv) {
- lastDefaultObject = ii;
+ lastScopeObject = cp->contextObject;
lastContext = bindContext;
return rv;
}
@@ -244,9 +243,9 @@ QDeclarativeContextScriptClass::property(Object *object, const Identifier &name)
} else if (lastData) {
if (lastData->type)
- return Value(scriptEngine, ep->typeNameClass->newObject(cp->defaultObjects.at(0), lastData->type));
+ return Value(scriptEngine, ep->typeNameClass->newObject(cp->contextObject, lastData->type));
else
- return Value(scriptEngine, ep->typeNameClass->newObject(cp->defaultObjects.at(0), lastData->typeNamespace));
+ return Value(scriptEngine, ep->typeNameClass->newObject(cp->contextObject, lastData->typeNamespace));
} else if (lastPropertyIndex != -1) {
@@ -267,10 +266,6 @@ QDeclarativeContextScriptClass::property(Object *object, const Identifier &name)
return Value(scriptEngine, rv);
- } else if(lastDefaultObject != -1) {
-
- // Default object property
- return ep->objectClass->property(cp->defaultObjects.at(lastDefaultObject), name);
} else {
@@ -283,7 +278,7 @@ void QDeclarativeContextScriptClass::setProperty(Object *object, const Identifie
const QScriptValue &value)
{
Q_UNUSED(object);
- Q_ASSERT(lastScopeObject || lastDefaultObject != -1);
+ Q_ASSERT(lastScopeObject);
QDeclarativeContext *bindContext = lastContext;
Q_ASSERT(bindContext);
@@ -291,12 +286,7 @@ void QDeclarativeContextScriptClass::setProperty(Object *object, const Identifie
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
QDeclarativeContextPrivate *cp = QDeclarativeContextPrivate::get(bindContext);
- if (lastScopeObject) {
- ep->objectClass->setProperty(lastScopeObject, name, value, bindContext);
- } else {
- ep->objectClass->setProperty(cp->defaultObjects.at(lastDefaultObject), name, value,
- bindContext);
- }
+ ep->objectClass->setProperty(lastScopeObject, name, value, bindContext);
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativecontextscriptclass_p.h b/src/declarative/qml/qdeclarativecontextscriptclass_p.h
index 4b0dca0..32c117c 100644
--- a/src/declarative/qml/qdeclarativecontextscriptclass_p.h
+++ b/src/declarative/qml/qdeclarativecontextscriptclass_p.h
@@ -90,7 +90,6 @@ private:
QDeclarativeContext *lastContext;
QDeclarativeTypeNameCache::Data *lastData;
int lastPropertyIndex;
- int lastDefaultObject;
QScriptValue lastFunction;
uint m_id;
diff --git a/src/declarative/qml/qdeclarativecustomparser_p.h b/src/declarative/qml/qdeclarativecustomparser_p.h
index 99587a8..39bd43c 100644
--- a/src/declarative/qml/qdeclarativecustomparser_p.h
+++ b/src/declarative/qml/qdeclarativecustomparser_p.h
@@ -128,9 +128,10 @@ private:
QList<QDeclarativeError> exceptions;
};
+#if 0
#define QML_REGISTER_CUSTOM_TYPE(URI, VERSION_MAJ, VERSION_MIN, NAME, TYPE, CUSTOMTYPE) \
qmlRegisterCustomType<TYPE>(#URI, VERSION_MAJ, VERSION_MIN, #NAME, #TYPE, new CUSTOMTYPE)
-
+#endif
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativedeclarativedata_p.h b/src/declarative/qml/qdeclarativedeclarativedata_p.h
index ae40130..ffce9c9 100644
--- a/src/declarative/qml/qdeclarativedeclarativedata_p.h
+++ b/src/declarative/qml/qdeclarativedeclarativedata_p.h
@@ -67,12 +67,21 @@ class Q_AUTOTEST_EXPORT QDeclarativeDeclarativeData : public QDeclarativeData
{
public:
QDeclarativeDeclarativeData(QDeclarativeContext *ctxt = 0)
- : context(ctxt), bindings(0), nextContextObject(0), prevContextObject(0),
- bindingBitsSize(0), bindingBits(0), outerContext(0), lineNumber(0),
- columnNumber(0), deferredComponent(0), deferredIdx(0), attachedProperties(0),
- propertyCache(0), guards(0) {}
+ : indestructible(true), explicitIndestructibleSet(false), context(ctxt),
+ bindings(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0), bindingBits(0),
+ outerContext(0), lineNumber(0), columnNumber(0), deferredComponent(0), deferredIdx(0),
+ attachedProperties(0), propertyCache(0), guards(0) {}
virtual void destroyed(QObject *);
+ virtual void parentChanged(QObject *, QObject *);
+
+ void setImplicitDestructible() {
+ if (!explicitIndestructibleSet) indestructible = false;
+ }
+
+ quint32 indestructible:1;
+ quint32 explicitIndestructibleSet:1;
+ quint32 dummy:29;
QDeclarativeContext *context;
QDeclarativeAbstractBinding *bindings;
diff --git a/src/declarative/qml/qdeclarativedirparser.cpp b/src/declarative/qml/qdeclarativedirparser.cpp
index e730b92..b6d2115 100644
--- a/src/declarative/qml/qdeclarativedirparser.cpp
+++ b/src/declarative/qml/qdeclarativedirparser.cpp
@@ -151,13 +151,16 @@ bool QDeclarativeDirParser::parse()
_plugins.append(entry);
+ } else if (sectionCount == 2) {
+ // No version specified (should only be used for relative qmldir files)
+ const Component entry(sections[0], sections[1], -1, -1);
+ _components.append(entry);
} else if (sectionCount == 3) {
const QString &version = sections[1];
const int dotIndex = version.indexOf(QLatin1Char('.'));
if (dotIndex == -1) {
qWarning() << "expected '.'"; // ### use reportError
-
} else if (version.indexOf(QLatin1Char('.'), dotIndex + 1) != -1) {
qWarning() << "unexpected '.'"; // ### use reportError
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 3b8d603..e84e267 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -146,11 +146,11 @@ static bool qt_QmlQtModule_registered = false;
void QDeclarativeEnginePrivate::defineModule()
{
- QML_REGISTER_TYPE(Qt,4,6,Component,QDeclarativeComponent);
- QML_REGISTER_TYPE(Qt,4,6,QtObject,QObject);
- QML_REGISTER_TYPE(Qt,4,6,WorkerScript,QDeclarativeWorkerScript);
+ qmlRegisterType<QDeclarativeComponent>("Qt",4,6,"Component");
+ qmlRegisterType<QObject>("Qt",4,6,"QtObject");
+ qmlRegisterType<QDeclarativeWorkerScript>("Qt",4,6,"WorkerScript");
- QML_REGISTER_NOCREATE_TYPE(QDeclarativeBinding);
+ qmlRegisterType<QDeclarativeBinding>();
}
QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e)
@@ -242,7 +242,6 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr
qtObject.setProperty(QLatin1String("formatDateTime"),newFunction(QDeclarativeEnginePrivate::formatDateTime, 2));
//misc methods
- qtObject.setProperty(QLatin1String("closestAngle"), newFunction(QDeclarativeEnginePrivate::closestAngle, 2));
qtObject.setProperty(QLatin1String("openUrlExternally"),newFunction(QDeclarativeEnginePrivate::desktopOpenUrl, 1));
qtObject.setProperty(QLatin1String("md5"),newFunction(QDeclarativeEnginePrivate::md5, 1));
qtObject.setProperty(QLatin1String("btoa"),newFunction(QDeclarativeEnginePrivate::btoa, 1));
@@ -541,9 +540,9 @@ QNetworkAccessManager *QDeclarativeEngine::networkAccessManager() const
This example creates a provider with id \e colors:
- \snippet examples/declarative/imageprovider/main.cpp 0
+ \snippet examples/declarative/imageprovider/imageprovider.cpp 0
- \snippet examples/declarative/imageprovider/view.qml 0
+ \snippet examples/declarative/imageprovider/imageprovider.qml 0
\sa removeImageProvider()
*/
@@ -667,6 +666,61 @@ void QDeclarativeEngine::setContextForObject(QObject *object, QDeclarativeContex
context->d_func()->contextObjects = data;
}
+/*!
+\enum QDeclarativeEngine::ObjectOwnership
+
+Ownership controls whether or not QML automatically destroys the QObject when the object
+is garbage collected by the JavaScript engine. The two ownership options are:
+
+\list
+\o CppOwnership - The object is owned by C++ code, and will never be deleted by QML. The
+JavaScript destroy() method cannot be used on objects with CppOwnership. This option
+is similar to QScriptEngine::QtOwnership.
+
+\o JavaScriptOwnership - The object is owned by JavaScript. When the object is returned to QML
+as the return value of a method call or property access, QML will delete the object if there
+are no remaining JavaScript references to it and it has no QObject::parent(). This option
+is similar to QScriptEngine::ScriptOwnership.
+\endlist
+
+Generally an application doesn't need to set an object's ownership explicitly. QML uses
+a heuristic to set the default object ownership. By default, an object that is created by
+QML has JavaScriptOwnership. The exception to this are the root objects created by calling
+QDeclarativeCompnent::create() or QDeclarativeComponent::beginCreate() which have
+CppOwnership by default. The ownership of these root-level objects is considered to have
+been transfered to the C++ caller.
+
+Objects not-created by QML have CppOwnership by default. The exception to this is objects
+returned from a C++ method call. The ownership of these objects is passed to JavaScript.
+
+Calling setObjectOwnership() overrides the default ownership heuristic used by QML.
+*/
+
+/*!
+Sets the \a ownership of \a object.
+*/
+void QDeclarativeEngine::setObjectOwnership(QObject *object, ObjectOwnership ownership)
+{
+ QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(object, true);
+ if (!ddata)
+ return;
+
+ ddata->indestructible = (ownership == CppOwnership)?true:false;
+ ddata->explicitIndestructibleSet = true;
+}
+
+/*!
+Returns the ownership of \a object.
+*/
+QDeclarativeEngine::ObjectOwnership QDeclarativeEngine::objectOwnership(QObject *object)
+{
+ QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(object, false);
+ if (!ddata)
+ return CppOwnership;
+ else
+ return ddata->indestructible?CppOwnership:JavaScriptOwnership;
+}
+
void qmlExecuteDeferred(QObject *object)
{
QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object);
@@ -777,6 +831,11 @@ void QDeclarativeDeclarativeData::destroyed(QObject *object)
delete this;
}
+void QDeclarativeDeclarativeData::parentChanged(QObject *, QObject *parent)
+{
+ if (!parent && scriptValue.isValid()) scriptValue = QScriptValue();
+}
+
bool QDeclarativeDeclarativeData::hasBindingBit(int bit) const
{
if (bindingBitsSize > bit)
@@ -857,6 +916,7 @@ QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt,
QUrl url = QUrl(context->resolvedUrl(QUrl(arg)));
QDeclarativeComponent *c = new QDeclarativeComponent(activeEngine, url, activeEngine);
c->setCreationContext(context);
+ QDeclarativeDeclarativeData::get(c, true)->setImplicitDestructible();
return activeEnginePriv->objectClass->newQObject(c, qMetaTypeId<QDeclarativeComponent*>());
}
}
@@ -927,7 +987,8 @@ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QS
if(gobj && gparent)
gobj->setParentItem(gparent);
- return qmlScriptObject(obj, activeEngine);
+ QDeclarativeDeclarativeData::get(obj, true)->setImplicitDestructible();
+ return activeEnginePriv->objectClass->newQObject(obj, QMetaType::QObjectStar);
}
QScriptValue QDeclarativeEnginePrivate::vector(QScriptContext *ctxt, QScriptEngine *engine)
@@ -1176,25 +1237,6 @@ QScriptValue QDeclarativeEnginePrivate::quit(QScriptContext * /*ctxt*/, QScriptE
return QScriptValue();
}
-QScriptValue QDeclarativeEnginePrivate::closestAngle(QScriptContext *ctxt, QScriptEngine *e)
-{
- if(ctxt->argumentCount() < 2)
- return e->newVariant(QVariant(0.0));
- qreal a = ctxt->argument(0).toNumber();
- qreal b = ctxt->argument(1).toNumber();
- qreal ret = b;
- qreal diff = b-a;
- while(diff > 180.0){
- ret -= 360.0;
- diff -= 360.0;
- }
- while(diff < -180.0){
- ret += 360.0;
- diff += 360.0;
- }
- return e->newVariant(QVariant(ret));
-}
-
QScriptValue QDeclarativeEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine)
{
if(ctxt->argumentCount() != 2)
@@ -1300,10 +1342,13 @@ QVariant QDeclarativeScriptClass::toVariant(QDeclarativeEngine *engine, const QS
// XXX this beyonds in QUrl::toLocalFile()
static QString toLocalFileOrQrc(const QUrl& url)
{
- QString r = url.toLocalFile();
- if (r.isEmpty() && url.scheme() == QLatin1String("qrc"))
- r = QLatin1Char(':') + url.path();
- return r;
+ if (url.scheme() == QLatin1String("qrc")) {
+ if (url.authority().isEmpty())
+ return QLatin1Char(':') + url.path();
+ qWarning() << "Invalid url:" << url.toString() << "authority" << url.authority() << "not known.";
+ return QString();
+ }
+ return url.toLocalFile();
}
/////////////////////////////////////////////////////////////
@@ -1315,7 +1360,7 @@ struct QDeclarativeEnginePrivate::ImportedNamespace {
QList<bool> isLibrary;
QList<QString> qmlDirContent;
- bool find(const QByteArray& type, int *vmajor, int *vminor, QDeclarativeType** type_return, QUrl* url_return) const
+ bool find(const QByteArray& type, int *vmajor, int *vminor, QDeclarativeType** type_return, QUrl* url_return)
{
for (int i=0; i<urls.count(); ++i) {
int vmaj = majversions.at(i);
@@ -1325,14 +1370,10 @@ struct QDeclarativeEnginePrivate::ImportedNamespace {
qt += '/';
qt += type;
- if (qmlImportTrace())
- qDebug() << "Look in" << qt;
QDeclarativeType *t = QDeclarativeMetaType::qmlType(qt,vmaj,vmin);
if (t) {
if (vmajor) *vmajor = vmaj;
if (vminor) *vminor = vmin;
- if (qmlImportTrace())
- qDebug() << "Found" << qt;
if (type_return)
*type_return = t;
return true;
@@ -1340,14 +1381,8 @@ struct QDeclarativeEnginePrivate::ImportedNamespace {
QUrl url = QUrl(urls.at(i) + QLatin1Char('/') + QString::fromUtf8(type) + QLatin1String(".qml"));
QString qmldircontent = qmlDirContent.at(i);
- if (vmaj>=0 || !qmldircontent.isEmpty()) {
- // Check version file - XXX cache these in QDeclarativeEngine!
- if (qmldircontent.isEmpty()) {
- QFile qmldir(toLocalFileOrQrc(QUrl(urls.at(i)+QLatin1String("/qmldir"))));
- if (qmldir.open(QIODevice::ReadOnly)) {
- qmldircontent = QString::fromUtf8(qmldir.readAll());
- }
- }
+
+ if (!qmldircontent.isEmpty()) {
const QString typeName = QString::fromUtf8(type);
@@ -1361,7 +1396,6 @@ struct QDeclarativeEnginePrivate::ImportedNamespace {
if (c.typeName == typeName) {
if (url_return)
*url_return = url.resolved(QUrl(c.fileName));
-
return true;
}
}
@@ -1395,8 +1429,9 @@ public:
QSet<QString> qmlDirFilesForWhichPluginsHaveBeenLoaded;
- bool add(const QUrl& base, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, const QStringList& importPath, QDeclarativeEngine *engine)
+ bool add(const QUrl& base, const QString &qmldircontentnetwork, const QString& uri, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, const QStringList& importPath, QDeclarativeEngine *engine)
{
+ QString qmldircontent = qmldircontentnetwork;
QDeclarativeEnginePrivate::ImportedNamespace *s;
if (prefix.isEmpty()) {
s = &unqualifiedset;
@@ -1409,15 +1444,21 @@ public:
if (importType == QDeclarativeScriptParser::Import::Library) {
url.replace(QLatin1Char('.'), QLatin1Char('/'));
bool found = false;
- QString content;
QString dir;
// user import paths
QStringList paths;
// base..
- paths += QFileInfo(base.toLocalFile()).path();
+ QString localFileOrQrc = toLocalFileOrQrc(base);
+ QString localFileOrQrcPath = QFileInfo(localFileOrQrc).path();
+ paths += localFileOrQrcPath;
paths += importPath;
+
+ QString applicationDirPath = QCoreApplication::applicationDirPath();
+ if (!applicationDirPath.isEmpty())
+ paths += applicationDirPath;
+
paths += QDeclarativeEnginePrivate::get(engine)->environmentImportPath;
#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0))
QString builtinPath = QLibraryInfo::location(QLibraryInfo::ImportsPath);
@@ -1429,6 +1470,7 @@ public:
foreach (const QString &p, paths) {
dir = p+QLatin1Char('/')+url;
+
QFileInfo fi(dir+QLatin1String("/qmldir"));
const QString absoluteFilePath = fi.absoluteFilePath();
@@ -1438,22 +1480,31 @@ public:
url = QUrl::fromLocalFile(fi.absolutePath()).toString();
QFile file(absoluteFilePath);
- if (file.open(QFile::ReadOnly))
- content = QString::fromUtf8(file.readAll());
+ if (file.open(QFile::ReadOnly)) {
+ qmldircontent = QString::fromUtf8(file.readAll());
+ if (qmlImportTrace())
+ qDebug() << "QDeclarativeEngine::add: loaded" << absoluteFilePath;
+ }
if (! qmlDirFilesForWhichPluginsHaveBeenLoaded.contains(absoluteFilePath)) {
qmlDirFilesForWhichPluginsHaveBeenLoaded.insert(absoluteFilePath);
QDeclarativeDirParser qmldirParser;
- qmldirParser.setSource(content);
+ qmldirParser.setSource(qmldircontent);
qmldirParser.parse();
foreach (const QDeclarativeDirParser::Plugin &plugin, qmldirParser.plugins()) {
- QString resolvedFilePath = QDeclarativeEnginePrivate::get(engine)->resolvePlugin(QDir(dir + QDir::separator() + plugin.path),
- plugin.name);
-
- if (!resolvedFilePath.isEmpty())
+ QDir pluginDir(dir + QDir::separator() + plugin.path);
+ if (p.startsWith(QLatin1Char(':')))
+ pluginDir = QDir(QCoreApplication::applicationDirPath());
+ QString resolvedFilePath =
+ QDeclarativeEnginePrivate::get(engine)
+ ->resolvePlugin(pluginDir,
+ plugin.name);
+
+ if (!resolvedFilePath.isEmpty()) {
engine->importExtension(resolvedFilePath, uri);
+ }
}
}
@@ -1641,9 +1692,10 @@ QUrl QDeclarativeEnginePrivate::Imports::baseUrl() const
type version mapping and possibly declarative extensions plugins.
The engine searches in the base directory of the qml file, then
- the paths added via addImportPath(), then the paths specified in the
- \c QML_IMPORT_PATH environment variable, then the builtin \c ImportsPath from
- QLibraryInfo.
+ the paths added via addImportPath(), then in the directory containing the
+ application executable (QCoreApplication::applicationDirPath()),
+ then the paths specified in the \c QML_IMPORT_PATH environment variable, then the
+ builtin \c ImportsPath from QLibraryInfo.
*/
void QDeclarativeEngine::addImportPath(const QString& path)
@@ -1655,13 +1707,13 @@ void QDeclarativeEngine::addImportPath(const QString& path)
}
/*!
- Imports the given \a extension into this QDeclarativeEngine. Returns
- true if the extension was successfully imported.
-
- \sa QDeclarativeExtensionInterface
+ Imports the extension named \a fileName from the \a uri provided.
+ Returns true if the extension was successfully imported.
*/
bool QDeclarativeEngine::importExtension(const QString &fileName, const QString &uri)
{
+ if (qmlImportTrace())
+ qDebug() << "QDeclarativeEngine::importExtension" << uri << "from" << fileName;
QFileInfo fileInfo(fileName);
const QString absoluteFilePath = fileInfo.absoluteFilePath();
QPluginLoader loader(absoluteFilePath);
@@ -1785,6 +1837,9 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString
return resolvePlugin(dir, baseName,
QStringList()
+# ifdef QT_DEBUG
+ << QLatin1String("_debug.dylib") // try a qmake-style debug build first
+# endif
<< QLatin1String(".dylib")
<< QLatin1String(".so")
<< QLatin1String(".bundle"),
@@ -1831,12 +1886,12 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString
The base URL must already have been set with Import::setBaseUrl().
*/
-bool QDeclarativeEnginePrivate::addToImport(Imports* imports, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType) const
+bool QDeclarativeEnginePrivate::addToImport(Imports* imports, const QString &qmldircontentnetwork, const QString& uri, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType) const
{
QDeclarativeEngine *engine = QDeclarativeEnginePrivate::get(const_cast<QDeclarativeEnginePrivate *>(this));
- bool ok = imports->d->add(imports->d->base,qmldircontent,uri,prefix,vmaj,vmin,importType,fileImportPath, engine);
if (qmlImportTrace())
- qDebug() << "QDeclarativeEngine::addToImport(" << imports << uri << prefix << vmaj << '.' << vmin << (importType==QDeclarativeScriptParser::Import::Library? "Library" : "File") << ": " << ok;
+ qDebug() << "QDeclarativeEngine::addToImport(" << imports << uri << prefix << vmaj << '.' << vmin << (importType==QDeclarativeScriptParser::Import::Library? "Library" : "File");
+ bool ok = imports->d->add(imports->d->base,qmldircontentnetwork, uri,prefix,vmaj,vmin,importType,fileImportPath, engine);
return ok;
}
@@ -1856,8 +1911,6 @@ bool QDeclarativeEnginePrivate::resolveType(const Imports& imports, const QByteA
{
ImportedNamespace* ns = imports.d->findNamespace(QString::fromUtf8(type));
if (ns) {
- if (qmlImportTrace())
- qDebug() << "QDeclarativeEngine::resolveType" << type << "is namespace for" << ns->urls;
if (ns_return)
*ns_return = ns;
return true;
@@ -1865,15 +1918,15 @@ bool QDeclarativeEnginePrivate::resolveType(const Imports& imports, const QByteA
if (type_return || url_return) {
if (imports.d->find(type,vmaj,vmin,type_return,url_return)) {
if (qmlImportTrace()) {
+ if (type_return && *type_return && url_return && !url_return->isEmpty())
+ qDebug() << "QDeclarativeEngine::resolveType" << type << '=' << (*type_return)->typeName() << *url_return;
if (type_return && *type_return)
qDebug() << "QDeclarativeEngine::resolveType" << type << '=' << (*type_return)->typeName();
- if (url_return)
+ if (url_return && !url_return->isEmpty())
qDebug() << "QDeclarativeEngine::resolveType" << type << '=' << *url_return;
}
return true;
}
- if (qmlImportTrace())
- qDebug() << "QDeclarativeEngine::resolveType" << type << "not found";
}
return false;
}
diff --git a/src/declarative/qml/qdeclarativeengine.h b/src/declarative/qml/qdeclarativeengine.h
index fd66358..19e81b6 100644
--- a/src/declarative/qml/qdeclarativeengine.h
+++ b/src/declarative/qml/qdeclarativeengine.h
@@ -98,6 +98,10 @@ public:
static QDeclarativeContext *contextForObject(const QObject *);
static void setContextForObject(QObject *, QDeclarativeContext *);
+ enum ObjectOwnership { CppOwnership, JavaScriptOwnership };
+ static void setObjectOwnership(QObject *, ObjectOwnership);
+ static ObjectOwnership objectOwnership(QObject *);
+
Q_SIGNALS:
void quit ();
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index 459a325..c73a758 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -276,7 +276,7 @@ public:
QString resolvePlugin(const QDir &dir, const QString &baseName);
- bool addToImport(Imports*, const QString& qmlDirContent,const QString& uri, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType) const;
+ bool addToImport(Imports*, const QString& uri, const QString &qmldircontentnetwork, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType) const;
bool resolveType(const Imports&, const QByteArray& type,
QDeclarativeType** type_return, QUrl* url_return,
int *version_major, int *version_minor,
@@ -318,7 +318,6 @@ public:
static QScriptValue darker(QScriptContext*, QScriptEngine*);
static QScriptValue tint(QScriptContext*, QScriptEngine*);
- static QScriptValue closestAngle(QScriptContext*, QScriptEngine*);
static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*);
static QScriptValue md5(QScriptContext*, QScriptEngine*);
static QScriptValue btoa(QScriptContext*, QScriptEngine*);
diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp
index 3e4acbe..933683c 100644
--- a/src/declarative/qml/qdeclarativeenginedebug.cpp
+++ b/src/declarative/qml/qdeclarativeenginedebug.cpp
@@ -230,22 +230,22 @@ void QDeclarativeEngineDebugServer::buildObjectList(QDataStream &message,
int count = 0;
- for (QSet<QDeclarativeContext *>::ConstIterator iter = p->childContexts.begin();
- iter != p->childContexts.end(); ++iter) {
- QDeclarativeContextPrivate *p = (QDeclarativeContextPrivate *)QObjectPrivate::get(*iter);
- if (p->isInternal)
- continue;
- ++count;
+ QDeclarativeContext *child = p->childContexts;
+ while (child) {
+ QDeclarativeContextPrivate *p = QDeclarativeContextPrivate::get(child);
+ if (!p->isInternal)
+ ++count;
+ child = p->nextChild;
}
message << count;
- for (QSet<QDeclarativeContext *>::ConstIterator iter = p->childContexts.begin();
- iter != p->childContexts.end(); ++iter) {
- QDeclarativeContextPrivate *p = (QDeclarativeContextPrivate *)QObjectPrivate::get(*iter);
- if (p->isInternal)
- continue;
- buildObjectList(message, *iter);
+ child = p->childContexts;
+ while (child) {
+ QDeclarativeContextPrivate *p = QDeclarativeContextPrivate::get(child);
+ if (!p->isInternal)
+ buildObjectList(message, child);
+ child = p->nextChild;
}
// Clean deleted objects
diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp
index e528e9e..5ff22f7 100644
--- a/src/declarative/qml/qdeclarativeexpression.cpp
+++ b/src/declarative/qml/qdeclarativeexpression.cpp
@@ -512,19 +512,20 @@ bool QDeclarativeExpression::notifyOnValueChanged() const
}
/*!
-Sets whether the valueChanged() signal is emitted when the expression's evaluated
-value changes.
-
-If true, the QDeclarativeExpression will monitor properties involved in the expression's
-evaluation, and emit QDeclarativeExpression::valueChanged() if they have changed. This allows
-an application to ensure that any value associated with the result of the expression
-remains up to date.
-
-If false, the QDeclarativeExpression will not montitor properties involved in the expression's
-evaluation, and QDeclarativeExpression::valueChanged() will never be emitted. This is more efficient
-if an application wants a "one off" evaluation of the expression.
-
-By default, notifyOnChange is false.
+ Sets whether the valueChanged() signal is emitted when the
+ expression's evaluated value changes.
+
+ If \a notifyOnChange is true, the QDeclarativeExpression will
+ monitor properties involved in the expression's evaluation, and emit
+ QDeclarativeExpression::valueChanged() if they have changed. This
+ allows an application to ensure that any value associated with the
+ result of the expression remains up to date.
+
+ If \a notifyOnChange is false (default), the QDeclarativeExpression
+ will not montitor properties involved in the expression's
+ evaluation, and QDeclarativeExpression::valueChanged() will never be
+ emitted. This is more efficient if an application wants a "one off"
+ evaluation of the expression.
*/
void QDeclarativeExpression::setNotifyOnValueChanged(bool notifyOnChange)
{
@@ -621,137 +622,74 @@ void QDeclarativeExpression::__q_notify()
void QDeclarativeExpressionPrivate::clearGuards()
{
- Q_Q(QDeclarativeExpression);
-
- static int notifyIdx = -1;
- if (notifyIdx == -1)
- notifyIdx =
- QDeclarativeExpression::staticMetaObject.indexOfMethod("__q_notify()");
-
- for (int ii = 0; ii < data->guardListLength; ++ii) {
- if (data->guardList[ii].data()) {
-#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 2))
- QMetaObject::disconnectOne(data->guardList[ii].data(),
- data->guardList[ii].notifyIndex,
- q, notifyIdx);
-#else
- // QTBUG-6781
- QMetaObject::disconnect(data->guardList[ii].data(),
- data->guardList[ii].notifyIndex,
- q, notifyIdx);
-#endif
- }
- }
-
- delete [] data->guardList; data->guardList = 0;
+ delete [] data->guardList;
+ data->guardList = 0;
data->guardListLength = 0;
}
void QDeclarativeExpressionPrivate::updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties)
{
- //clearGuards();
Q_Q(QDeclarativeExpression);
static int notifyIdx = -1;
if (notifyIdx == -1)
- notifyIdx =
- QDeclarativeExpression::staticMetaObject.indexOfMethod("__q_notify()");
+ notifyIdx = QDeclarativeExpression::staticMetaObject.indexOfMethod("__q_notify()");
- QDeclarativeExpressionData::SignalGuard *newGuardList = 0;
-
- if (properties.count() != data->guardListLength)
- newGuardList = new QDeclarativeExpressionData::SignalGuard[properties.count()];
+ 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;
- int hit = 0;
+ bool noChanges = true;
for (int ii = 0; ii < properties.count(); ++ii) {
+ QDeclarativeNotifierEndpoint &guard = data->guardList[ii];
const QDeclarativeEnginePrivate::CapturedProperty &property = properties.at(ii);
- bool needGuard = true;
- if (ii >= data->guardListLength) {
- // New guard
- } else if(data->guardList[ii].data() == property.object &&
- data->guardList[ii].notifyIndex == property.notifyIndex) {
- // Cache hit
- if (!data->guardList[ii].isDuplicate ||
- (data->guardList[ii].isDuplicate && hit == ii)) {
- needGuard = false;
- ++hit;
- }
- } else if(data->guardList[ii].data() && !data->guardList[ii].isDuplicate) {
- // Cache miss
-#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 2))
- QMetaObject::disconnectOne(data->guardList[ii].data(),
- data->guardList[ii].notifyIndex,
- q, notifyIdx);
-#else
- // QTBUG-6781
- QMetaObject::disconnect(data->guardList[ii].data(),
- data->guardList[ii].notifyIndex,
- q, notifyIdx);
-#endif
- }
- /* else {
- // Cache miss, but nothing to do
- } */
-
- if (needGuard) {
- if (!newGuardList) {
- newGuardList = new QDeclarativeExpressionData::SignalGuard[properties.count()];
- for (int jj = 0; jj < ii; ++jj)
- newGuardList[jj] = data->guardList[jj];
- }
+ guard.target = q;
+ guard.targetMethod = notifyIdx;
+
+ if (property.notifyIndex != -1) {
+
+ if (!noChanges && guard.isConnected(property.object, property.notifyIndex)) {
+ // Nothing to do
+
+ } else {
+ noChanges = false;
- if (property.notifyIndex != -1) {
bool existing = false;
for (int jj = 0; !existing && jj < ii; ++jj)
- existing = newGuardList[jj].data() == property.object &&
- newGuardList[jj].notifyIndex == property.notifyIndex;
-
- newGuardList[ii] = property.object;
- newGuardList[ii].notifyIndex = property.notifyIndex;
- if (existing)
- newGuardList[ii].isDuplicate = true;
- else
- QMetaObject::connect(property.object, property.notifyIndex,
- q, notifyIdx);
- } else {
- if (!outputWarningHeader) {
- outputWarningHeader = true;
- qWarning() << "QDeclarativeExpression: Expression" << q->expression()
- << "depends on non-NOTIFYable properties:";
+ if (data->guardList[jj].isConnected(property.object, property.notifyIndex))
+ existing = true;
+
+ if (existing) {
+ // duplicate
+ guard.disconnect();
+ } else {
+ guard.connect(property.object, property.notifyIndex);
}
+ }
- const QMetaObject *metaObj = property.object->metaObject();
- QMetaProperty metaProp = metaObj->property(property.coreIndex);
-
- qWarning().nospace() << " " << metaObj->className()
- << "::" << metaProp.name();
+ } else {
+ if (!outputWarningHeader) {
+ outputWarningHeader = true;
+ qWarning() << "QDeclarativeExpression: Expression" << q->expression()
+ << "depends on non-NOTIFYable properties:";
}
- } else if (newGuardList) {
- newGuardList[ii] = data->guardList[ii];
- }
- }
- for (int ii = properties.count(); ii < data->guardListLength; ++ii) {
- if (data->guardList[ii].data() && !data->guardList[ii].isDuplicate) {
-#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 2))
- QMetaObject::disconnectOne(data->guardList[ii].data(),
- data->guardList[ii].notifyIndex,
- q, notifyIdx);
-#else
- // QTBUG-6781
- QMetaObject::disconnect(data->guardList[ii].data(),
- data->guardList[ii].notifyIndex,
- q, notifyIdx);
-#endif
- }
- }
+ const QMetaObject *metaObj = property.object->metaObject();
+ QMetaProperty metaProp = metaObj->property(property.coreIndex);
- if (newGuardList) {
- if (data->guardList) delete [] data->guardList;
- data->guardList = newGuardList;
- data->guardListLength = properties.count();
+ qWarning().nospace() << " " << metaObj->className()
+ << "::" << metaProp.name();
+ }
}
}
diff --git a/src/declarative/qml/qdeclarativeexpression_p.h b/src/declarative/qml/qdeclarativeexpression_p.h
index cd1729d..d170559 100644
--- a/src/declarative/qml/qdeclarativeexpression_p.h
+++ b/src/declarative/qml/qdeclarativeexpression_p.h
@@ -129,24 +129,7 @@ public:
QString url; // This is a QString for a reason. QUrls are slooooooow...
int line;
- struct SignalGuard : public QDeclarativeGuard<QObject> {
- SignalGuard() : isDuplicate(false), notifyIndex(-1) {}
-
- SignalGuard &operator=(QObject *obj) {
- QDeclarativeGuard<QObject>::operator=(obj);
- return *this;
- }
- SignalGuard &operator=(const SignalGuard &o) {
- QDeclarativeGuard<QObject>::operator=(o);
- isDuplicate = o.isDuplicate;
- notifyIndex = o.notifyIndex;
- return *this;
- }
-
- bool isDuplicate:1;
- int notifyIndex:31;
- };
- SignalGuard *guardList;
+ QDeclarativeNotifierEndpoint *guardList;
int guardListLength;
};
diff --git a/src/declarative/qml/qdeclarativeextensionplugin.cpp b/src/declarative/qml/qdeclarativeextensionplugin.cpp
index 3d44d63..7617977 100644
--- a/src/declarative/qml/qdeclarativeextensionplugin.cpp
+++ b/src/declarative/qml/qdeclarativeextensionplugin.cpp
@@ -87,7 +87,7 @@ QDeclarativeExtensionPlugin::~QDeclarativeExtensionPlugin()
/*!
\fn void QDeclarativeExtensionPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri)
- Initializes the extension specified in the given \a engine.
+ Initializes the extension from the \a uri using the \a engine.
*/
void QDeclarativeExtensionPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri)
diff --git a/src/declarative/qml/qdeclarativeimageprovider.cpp b/src/declarative/qml/qdeclarativeimageprovider.cpp
index daa2e87..9ef8545 100644
--- a/src/declarative/qml/qdeclarativeimageprovider.cpp
+++ b/src/declarative/qml/qdeclarativeimageprovider.cpp
@@ -52,6 +52,10 @@ QT_BEGIN_NAMESPACE
\sa QDeclarativeEngine::addImageProvider()
*/
+
+/*!
+ The destructor is virtual.
+ */
QDeclarativeImageProvider::~QDeclarativeImageProvider()
{
}
diff --git a/src/declarative/qml/qdeclarativeinstruction.cpp b/src/declarative/qml/qdeclarativeinstruction.cpp
index cf485fe..a23ff75 100644
--- a/src/declarative/qml/qdeclarativeinstruction.cpp
+++ b/src/declarative/qml/qdeclarativeinstruction.cpp
@@ -90,7 +90,7 @@ void QDeclarativeCompiledData::dump(QDeclarativeInstruction *instr, int idx)
qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_STRING\t\t" << instr->storeString.propertyIndex << "\t" << instr->storeString.value << "\t\t" << primitives.at(instr->storeString.value);
break;
case QDeclarativeInstruction::StoreUrl:
- qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_URL\t\t" << instr->storeUrl.propertyIndex << "\t" << instr->storeUrl.value << "\t\t" << primitives.at(instr->storeUrl.value);
+ qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_URL\t\t" << instr->storeUrl.propertyIndex << "\t" << instr->storeUrl.value << "\t\t" << urls.at(instr->storeUrl.value);
break;
case QDeclarativeInstruction::StoreColor:
qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_COLOR\t\t" << instr->storeColor.propertyIndex << "\t\t\t" << QString::number(instr->storeColor.value, 16);
diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp
index 50ab56b..55c7413 100644
--- a/src/declarative/qml/qdeclarativemetatype.cpp
+++ b/src/declarative/qml/qdeclarativemetatype.cpp
@@ -124,7 +124,10 @@ public:
int m_version_maj;
int m_version_min;
int m_typeId; int m_listId;
- QObject *(*m_newFunc)();
+
+ int m_allocationSize;
+ void (*m_newFunc)(void *);
+
const QMetaObject *m_baseMetaObject;
QDeclarativeAttachedPropertiesFunc m_attachedPropertiesFunc;
const QMetaObject *m_attachedPropertiesType;
@@ -141,7 +144,7 @@ public:
QDeclarativeTypePrivate::QDeclarativeTypePrivate()
: m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0),
- m_newFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0),
+ m_allocationSize(0), m_newFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0),
m_parserStatusCast(-1), m_propertyValueSourceCast(-1), m_propertyValueInterceptorCast(-1),
m_extFunc(0), m_extMetaObject(0), m_index(-1), m_customParser(0), m_isSetup(false)
{
@@ -174,6 +177,7 @@ QDeclarativeType::QDeclarativeType(int index, const QDeclarativePrivate::Registe
d->m_version_min = type.versionMinor;
d->m_typeId = type.typeId;
d->m_listId = type.listId;
+ d->m_allocationSize = type.objectSize;
d->m_newFunc = type.create;
d->m_baseMetaObject = type.metaObject;
d->m_attachedPropertiesFunc = type.attachedPropertiesFunction;
@@ -274,7 +278,9 @@ QObject *QDeclarativeType::create() const
{
d->init();
- QObject *rv = d->m_newFunc();
+ QObject *rv = (QObject *)operator new(d->m_allocationSize);
+ d->m_newFunc(rv);
+
if (rv && !d->m_metaObjects.isEmpty())
(void *)new QDeclarativeProxyMetaObject(rv, &d->m_metaObjects);
diff --git a/src/declarative/qml/qdeclarativenotifier.cpp b/src/declarative/qml/qdeclarativenotifier.cpp
new file mode 100644
index 0000000..8e5904c
--- /dev/null
+++ b/src/declarative/qml/qdeclarativenotifier.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#include "qdeclarativenotifier_p.h"
+
+QT_BEGIN_NAMESPACE
+
+void QDeclarativeNotifier::emitNotify(QDeclarativeNotifierEndpoint *endpoint)
+{
+ QDeclarativeNotifierEndpoint::Notifier *n = endpoint->asNotifier();
+
+ QDeclarativeNotifierEndpoint::Notifier **oldDisconnected = n->disconnected;
+ n->disconnected = &n;
+
+ if (n->next)
+ emitNotify(n->next);
+
+ if (n) {
+ void *args[] = { 0 };
+
+ QMetaObject::metacall(endpoint->target, QMetaObject::InvokeMetaMethod,
+ endpoint->targetMethod, args);
+
+ if (n)
+ n->disconnected = oldDisconnected;
+ }
+
+ if (oldDisconnected) *oldDisconnected = n;
+}
+
+void QDeclarativeNotifierEndpoint::copyAndClear(QDeclarativeNotifierEndpoint &other)
+{
+ other.disconnect();
+
+ other.target = target;
+ other.targetMethod = targetMethod;
+
+ if (!isConnected())
+ return;
+
+ if (SignalType == type) {
+ Signal *other_s = other.toSignal();
+ Signal *s = asSignal();
+
+ other_s->source = s->source;
+ other_s->sourceSignal = s->sourceSignal;
+ s->source = 0;
+ } else if(NotifierType == type) {
+ Notifier *other_n = other.toNotifier();
+ Notifier *n = asNotifier();
+
+ other_n->notifier = n->notifier;
+ other_n->disconnected = n->disconnected;
+ if (other_n->disconnected) *other_n->disconnected = other_n;
+
+ if (n->next) {
+ other_n->next = n->next;
+ n->next->asNotifier()->prev = &other_n->next;
+ }
+ other_n->prev = n->prev;
+ *other_n->prev = &other;
+
+ n->prev = 0;
+ n->next = 0;
+ n->disconnected = 0;
+ n->notifier = 0;
+ }
+}
+
+
+QT_END_NAMESPACE
+
diff --git a/src/declarative/qml/qdeclarativenotifier_p.h b/src/declarative/qml/qdeclarativenotifier_p.h
new file mode 100644
index 0000000..a0e6b43
--- /dev/null
+++ b/src/declarative/qml/qdeclarativenotifier_p.h
@@ -0,0 +1,272 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVENOTIFIER_P_H
+#define QDECLARATIVENOTIFIER_P_H
+
+#include "qdeclarativeguard_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QDeclarativeNotifierEndpoint;
+class QDeclarativeNotifier
+{
+public:
+ inline QDeclarativeNotifier();
+ inline ~QDeclarativeNotifier();
+ inline void notify();
+
+private:
+ friend class QDeclarativeNotifierEndpoint;
+
+ static void emitNotify(QDeclarativeNotifierEndpoint *);
+ QDeclarativeNotifierEndpoint *endpoints;
+};
+
+class QDeclarativeNotifierEndpoint
+{
+public:
+ inline QDeclarativeNotifierEndpoint();
+ inline QDeclarativeNotifierEndpoint(QObject *t, int m);
+ inline ~QDeclarativeNotifierEndpoint();
+
+ QObject *target;
+ int targetMethod;
+
+ inline bool isConnected();
+ inline bool isConnected(QObject *source, int sourceSignal);
+ inline bool isConnected(QDeclarativeNotifier *);
+
+ inline void connect(QObject *source, int sourceSignal);
+ inline void connect(QDeclarativeNotifier *);
+ inline void disconnect();
+
+ void copyAndClear(QDeclarativeNotifierEndpoint &other);
+
+private:
+ friend class QDeclarativeNotifier;
+
+ struct Signal {
+ QDeclarativeGuard<QObject> source;
+ int sourceSignal;
+ };
+
+ struct Notifier {
+ QDeclarativeNotifier *notifier;
+ Notifier **disconnected;
+
+ QDeclarativeNotifierEndpoint *next;
+ QDeclarativeNotifierEndpoint **prev;
+ };
+
+ enum { InvalidType, SignalType, NotifierType } type;
+ union {
+ char signalData[sizeof(Signal)];
+ char notifierData[sizeof(Notifier)];
+ };
+
+ inline Notifier *toNotifier();
+ inline Notifier *asNotifier();
+ inline Signal *toSignal();
+ inline Signal *asSignal();
+};
+
+QDeclarativeNotifier::QDeclarativeNotifier()
+: endpoints(0)
+{
+ QDeclarativeNotifierEndpoint *endpoint = endpoints;
+ while (endpoint) {
+ QDeclarativeNotifierEndpoint *next = endpoint->asNotifier()->next;
+ endpoint->asNotifier()->next = 0;
+ endpoint->asNotifier()->prev = 0;
+ endpoint->asNotifier()->notifier = 0;
+ endpoint = next;
+ }
+}
+
+QDeclarativeNotifier::~QDeclarativeNotifier()
+{
+}
+
+void QDeclarativeNotifier::notify()
+{
+ if (endpoints) emitNotify(endpoints);
+}
+
+QDeclarativeNotifierEndpoint::QDeclarativeNotifierEndpoint()
+: target(0), targetMethod(0), type(InvalidType)
+{
+}
+
+QDeclarativeNotifierEndpoint::QDeclarativeNotifierEndpoint(QObject *t, int m)
+: target(t), targetMethod(m), type(InvalidType)
+{
+}
+
+QDeclarativeNotifierEndpoint::~QDeclarativeNotifierEndpoint()
+{
+ disconnect();
+ if (SignalType == type) {
+ Signal *s = asSignal();
+ s->~Signal();
+ }
+}
+
+bool QDeclarativeNotifierEndpoint::isConnected()
+{
+ if (SignalType == type) {
+ return asSignal()->source;
+ } else if (NotifierType == type) {
+ return asNotifier()->notifier;
+ } else {
+ return false;
+ }
+}
+
+bool QDeclarativeNotifierEndpoint::isConnected(QObject *source, int sourceSignal)
+{
+ return SignalType == type && asSignal()->source == source && asSignal()->sourceSignal == sourceSignal;
+}
+
+bool QDeclarativeNotifierEndpoint::isConnected(QDeclarativeNotifier *notifier)
+{
+ return NotifierType == type && asNotifier()->notifier == notifier;
+}
+
+void QDeclarativeNotifierEndpoint::connect(QObject *source, int sourceSignal)
+{
+ Signal *s = toSignal();
+
+ if (s->source == source && s->sourceSignal == sourceSignal)
+ return;
+
+ disconnect();
+
+ QMetaObject::connect(source, sourceSignal, target, targetMethod);
+
+ s->source = source;
+ s->sourceSignal = sourceSignal;
+}
+
+void QDeclarativeNotifierEndpoint::connect(QDeclarativeNotifier *notifier)
+{
+ Notifier *n = toNotifier();
+
+ if (n->notifier == notifier)
+ return;
+
+ disconnect();
+
+ n->next = notifier->endpoints;
+ if (n->next) { n->next->asNotifier()->prev = &n->next; }
+ notifier->endpoints = this;
+ n->prev = &notifier->endpoints;
+ n->notifier = notifier;
+}
+
+void QDeclarativeNotifierEndpoint::disconnect()
+{
+ if (type == SignalType) {
+ Signal *s = (Signal *)&signalData;
+ if (s->source) {
+ QMetaObject::disconnectOne(s->source, s->sourceSignal, target, targetMethod);
+ s->source = 0;
+ }
+ } else if (type == NotifierType) {
+ Notifier *n = asNotifier();
+
+ if (n->next) n->next->asNotifier()->prev = n->prev;
+ if (n->prev) *n->prev = n->next;
+ if (n->disconnected) *n->disconnected = 0;
+ n->next = 0;
+ n->prev = 0;
+ n->disconnected = 0;
+ n->notifier = 0;
+ }
+}
+
+QDeclarativeNotifierEndpoint::Notifier *QDeclarativeNotifierEndpoint::toNotifier()
+{
+ if (NotifierType == type)
+ return asNotifier();
+
+ if (SignalType == type) {
+ disconnect();
+ Signal *s = asSignal();
+ s->~Signal();
+ }
+
+ Notifier *n = asNotifier();
+ n->next = 0;
+ n->prev = 0;
+ n->disconnected = 0;
+ n->notifier = 0;
+ type = NotifierType;
+ return n;
+}
+
+QDeclarativeNotifierEndpoint::Notifier *QDeclarativeNotifierEndpoint::asNotifier()
+{
+ return (Notifier *)(&notifierData);
+}
+
+QDeclarativeNotifierEndpoint::Signal *QDeclarativeNotifierEndpoint::toSignal()
+{
+ if (SignalType == type)
+ return asSignal();
+
+ disconnect();
+ Signal *s = asSignal();
+ new (s) Signal;
+ type = SignalType;
+
+ return s;
+}
+
+QDeclarativeNotifierEndpoint::Signal *QDeclarativeNotifierEndpoint::asSignal()
+{
+ return (Signal *)(&signalData);
+}
+
+QT_END_NAMESPACE
+
+#endif // QDECLARATIVENOTIFIER_P_H
+
diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
index e6f6e5f..32a28fe 100644
--- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
+++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
@@ -59,6 +59,15 @@ QT_BEGIN_NAMESPACE
struct ObjectData : public QScriptDeclarativeClass::Object {
ObjectData(QObject *o, int t) : object(o), type(t) {}
+
+ virtual ~ObjectData() {
+ if (object && !object->parent()) {
+ QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(object, false);
+ if (ddata && !ddata->indestructible)
+ object->deleteLater();
+ }
+ }
+
QDeclarativeGuard<QObject> object;
int type;
};
@@ -87,7 +96,7 @@ QDeclarativeObjectScriptClass::~QDeclarativeObjectScriptClass()
{
}
-QScriptValue QDeclarativeObjectScriptClass::newQObject(QObject *object, int type)
+QScriptValue QDeclarativeObjectScriptClass::newQObject(QObject *object, int type)
{
QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
@@ -96,7 +105,11 @@ QScriptValue QDeclarativeObjectScriptClass::newQObject(QObject *object, int type
QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(object, true);
- if (!ddata->scriptValue.isValid()) {
+ if (!ddata) {
+ return scriptEngine->undefinedValue();
+ } else if (!ddata->indestructible && !object->parent()) {
+ return newObject(scriptEngine, this, new ObjectData(object, type));
+ } else if (!ddata->scriptValue.isValid()) {
ddata->scriptValue = newObject(scriptEngine, this, new ObjectData(object, type));
return ddata->scriptValue;
} else if (ddata->scriptValue.engine() == QDeclarativeEnginePrivate::getScriptEngine(engine)) {
@@ -338,7 +351,8 @@ void QDeclarativeObjectScriptClass::setProperty(QObject *obj,
}
}
- QDeclarativeAbstractBinding *delBinding = QDeclarativePropertyPrivate::setBinding(obj, *lastData, 0);
+ QDeclarativeAbstractBinding *delBinding =
+ QDeclarativePropertyPrivate::setBinding(obj, lastData->coreIndex, -1, 0);
if (delBinding)
delBinding->destroy();
@@ -392,17 +406,30 @@ QScriptValue QDeclarativeObjectScriptClass::tostring(QScriptContext *context, QS
QScriptValue QDeclarativeObjectScriptClass::destroy(QScriptContext *context, QScriptEngine *engine)
{
- QObject* obj = context->thisObject().toQObject();
- if(obj){
- int delay = 0;
- if(context->argumentCount() > 0)
- delay = context->argument(0).toInt32();
- if (delay > 0)
- QTimer::singleShot(delay, obj, SLOT(deleteLater()));
- else
- obj->deleteLater();
- }
- return engine->nullValue();
+ QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine);
+ QScriptValue that = context->thisObject();
+
+ if (scriptClass(that) != p->objectClass)
+ return engine->undefinedValue();
+
+ ObjectData *data = (ObjectData *)p->objectClass->object(that);
+ if (!data->object)
+ return engine->undefinedValue();
+
+ QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(data->object, false);
+ if (!ddata || ddata->indestructible)
+ return engine->currentContext()->throwError(QLatin1String("Invalid attempt to destroy() an indestructible object"));
+
+ QObject *obj = data->object;
+ int delay = 0;
+ if (context->argumentCount() > 0)
+ delay = context->argument(0).toInt32();
+ if (delay > 0)
+ QTimer::singleShot(delay, obj, SLOT(deleteLater()));
+ else
+ obj->deleteLater();
+
+ return engine->undefinedValue();
}
QStringList QDeclarativeObjectScriptClass::propertyNames(Object *object)
@@ -428,6 +455,14 @@ QStringList QDeclarativeObjectScriptClass::propertyNames(Object *object)
return cache->propertyNames();
}
+bool QDeclarativeObjectScriptClass::compare(Object *o1, Object *o2)
+{
+ ObjectData *d1 = (ObjectData *)o1;
+ ObjectData *d2 = (ObjectData *)o2;
+
+ return d1 == d2 || d1->object == d2->object;
+}
+
#if (QT_VERSION > QT_VERSION_CHECK(4, 6, 2)) || defined(QT_HAVE_QSCRIPTDECLARATIVECLASS_VALUE)
struct MethodData : public QScriptDeclarativeClass::Object {
@@ -441,6 +476,8 @@ QDeclarativeObjectMethodScriptClass::QDeclarativeObjectMethodScriptClass(QDeclar
: QScriptDeclarativeClass(QDeclarativeEnginePrivate::getScriptEngine(bindEngine)),
engine(bindEngine)
{
+ qRegisterMetaType<QList<QObject *> >("QList<QObject *>");
+
setSupportsCall(true);
QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
@@ -551,7 +588,7 @@ private:
inline void cleanup();
- char *data[16];
+ void *data[4];
int type;
};
}
@@ -569,11 +606,13 @@ MetaCallArgument::~MetaCallArgument()
void MetaCallArgument::cleanup()
{
if (type == QMetaType::QString) {
- ((QString *)data)->~QString();
+ ((QString *)&data)->~QString();
} else if (type == -1 || type == qMetaTypeId<QVariant>()) {
- ((QVariant *)data)->~QVariant();
+ ((QVariant *)&data)->~QVariant();
} else if (type == qMetaTypeId<QScriptValue>()) {
- ((QScriptValue *)data)->~QScriptValue();
+ ((QScriptValue *)&data)->~QScriptValue();
+ } else if (type == qMetaTypeId<QList<QObject *> >()) {
+ ((QList<QObject *> *)&data)->~QList<QObject *>();
}
}
@@ -582,7 +621,7 @@ void *MetaCallArgument::dataPtr()
if (type == -1)
return ((QVariant *)data)->data();
else
- return (void *)data;
+ return (void *)&data;
}
void MetaCallArgument::initAsType(int callType, QDeclarativeEngine *e)
@@ -593,7 +632,7 @@ void MetaCallArgument::initAsType(int callType, QDeclarativeEngine *e)
QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(e);
if (callType == qMetaTypeId<QScriptValue>()) {
- new (data) QScriptValue(engine->undefinedValue());
+ new (&data) QScriptValue(engine->undefinedValue());
type = callType;
} else if (callType == QMetaType::Int ||
callType == QMetaType::UInt ||
@@ -602,17 +641,20 @@ void MetaCallArgument::initAsType(int callType, QDeclarativeEngine *e)
callType == QMetaType::Float) {
type = callType;
} else if (callType == QMetaType::QObjectStar) {
- *((QObject **)data) = 0;
+ *((QObject **)&data) = 0;
type = callType;
} else if (callType == QMetaType::QString) {
- new (data) QString();
+ new (&data) QString();
type = callType;
} else if (callType == qMetaTypeId<QVariant>()) {
- type = qMetaTypeId<QVariant>();
- new (data) QVariant();
+ type = callType;
+ new (&data) QVariant();
+ } else if (callType == qMetaTypeId<QList<QObject *> >()) {
+ type = callType;
+ new (&data) QList<QObject *>();
} else {
type = -1;
- new (data) QVariant(callType, (void *)0);
+ new (&data) QVariant(callType, (void *)0);
}
}
@@ -621,47 +663,50 @@ void MetaCallArgument::fromScriptValue(int callType, QDeclarativeEngine *engine,
if (type != 0) { cleanup(); type = 0; }
if (callType == qMetaTypeId<QScriptValue>()) {
- new (data) QScriptValue(value);
+ new (&data) QScriptValue(value);
type = qMetaTypeId<QScriptValue>();
} else if (callType == QMetaType::Int) {
- *((int *)data) = int(value.toInt32());
+ *((int *)&data) = int(value.toInt32());
type = callType;
} else if (callType == QMetaType::UInt) {
- *((uint *)data) = uint(value.toUInt32());
+ *((uint *)&data) = uint(value.toUInt32());
type = callType;
} else if (callType == QMetaType::Bool) {
- *((bool *)data) = value.toBool();
+ *((bool *)&data) = value.toBool();
type = callType;
} else if (callType == QMetaType::Double) {
- *((double *)data) = double(value.toNumber());
+ *((double *)&data) = double(value.toNumber());
type = callType;
} else if (callType == QMetaType::Float) {
- *((float *)data) = float(value.toNumber());
+ *((float *)&data) = float(value.toNumber());
type = callType;
} else if (callType == QMetaType::QString) {
if (value.isNull() || value.isUndefined())
- new (data) QString();
+ new (&data) QString();
else
- new (data) QString(value.toString());
+ new (&data) QString(value.toString());
type = callType;
} else if (callType == QMetaType::QObjectStar) {
- *((QObject **)data) = value.toQObject();
+ *((QObject **)&data) = value.toQObject();
type = callType;
} else if (callType == qMetaTypeId<QVariant>()) {
- new (data) QVariant(QDeclarativeScriptClass::toVariant(engine, value));
+ new (&data) QVariant(QDeclarativeScriptClass::toVariant(engine, value));
+ type = callType;
+ } else if (callType == qMetaTypeId<QList<QObject*> >()) {
+ new (&data) QList<QObject *>(); // We don't support passing in QList<QObject*>
type = callType;
} else {
- new (data) QVariant();
+ new (&data) QVariant();
type = -1;
QVariant v = QDeclarativeScriptClass::toVariant(engine, value);
if (v.userType() == callType) {
- *((QVariant *)data) = v;
+ *((QVariant *)&data) = v;
} else if (v.canConvert((QVariant::Type)callType)) {
- *((QVariant *)data) = v;
- ((QVariant *)data)->convert((QVariant::Type)callType);
+ *((QVariant *)&data) = v;
+ ((QVariant *)&data)->convert((QVariant::Type)callType);
} else {
- *((QVariant *)data) = QVariant(callType, (void *)0);
+ *((QVariant *)&data) = QVariant(callType, (void *)0);
}
}
}
@@ -671,23 +716,36 @@ QScriptDeclarativeClass::Value MetaCallArgument::toValue(QDeclarativeEngine *e)
QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(e);
if (type == qMetaTypeId<QScriptValue>()) {
- return QScriptDeclarativeClass::Value(engine, *((QScriptValue *)data));
+ return QScriptDeclarativeClass::Value(engine, *((QScriptValue *)&data));
} else if (type == QMetaType::Int) {
- return QScriptDeclarativeClass::Value(engine, *((int *)data));
+ return QScriptDeclarativeClass::Value(engine, *((int *)&data));
} else if (type == QMetaType::UInt) {
- return QScriptDeclarativeClass::Value(engine, *((uint *)data));
+ return QScriptDeclarativeClass::Value(engine, *((uint *)&data));
} else if (type == QMetaType::Bool) {
- return QScriptDeclarativeClass::Value(engine, *((bool *)data));
+ return QScriptDeclarativeClass::Value(engine, *((bool *)&data));
} else if (type == QMetaType::Double) {
- return QScriptDeclarativeClass::Value(engine, *((double *)data));
+ return QScriptDeclarativeClass::Value(engine, *((double *)&data));
} else if (type == QMetaType::Float) {
- return QScriptDeclarativeClass::Value(engine, *((float *)data));
+ return QScriptDeclarativeClass::Value(engine, *((float *)&data));
} else if (type == QMetaType::QString) {
- return QScriptDeclarativeClass::Value(engine, *((QString *)data));
+ return QScriptDeclarativeClass::Value(engine, *((QString *)&data));
} else if (type == QMetaType::QObjectStar) {
- return QScriptDeclarativeClass::Value(engine, QDeclarativeEnginePrivate::get(e)->objectClass->newQObject(*((QObject **)data)));
+ QObject *object = *((QObject **)&data);
+ QDeclarativeDeclarativeData::get(object, true)->setImplicitDestructible();
+ QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(e);
+ return QScriptDeclarativeClass::Value(engine, priv->objectClass->newQObject(object));
+ } else if (type == qMetaTypeId<QList<QObject *> >()) {
+ QList<QObject *> &list = *(QList<QObject *>*)&data;
+ QScriptValue rv = engine->newArray(list.count());
+ QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(e);
+ for (int ii = 0; ii < list.count(); ++ii) {
+ QObject *object = list.at(ii);
+ QDeclarativeDeclarativeData::get(object, true)->setImplicitDestructible();
+ rv.setProperty(ii, priv->objectClass->newQObject(object));
+ }
+ return QScriptDeclarativeClass::Value(engine, rv);
} else if (type == -1 || type == qMetaTypeId<QVariant>()) {
- return QScriptDeclarativeClass::Value(engine, QDeclarativeEnginePrivate::get(e)->scriptValueFromVariant(*((QVariant *)data)));
+ return QScriptDeclarativeClass::Value(engine, QDeclarativeEnginePrivate::get(e)->scriptValueFromVariant(*((QVariant *)&data)));
} else {
return QScriptDeclarativeClass::Value();
}
diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h
index 04e760f..1f7d1c9 100644
--- a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h
+++ b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h
@@ -57,6 +57,7 @@
#include "qdeclarativetypenamecache_p.h"
#include <private/qdeclarativescriptclass_p.h>
+#include <QtScript/qscriptengine.h>
QT_BEGIN_NAMESPACE
@@ -99,6 +100,7 @@ public:
~QDeclarativeObjectScriptClass();
QScriptValue newQObject(QObject *, int type = QMetaType::QObjectStar);
+
QObject *toQObject(const QScriptValue &) const;
int objectType(const QScriptValue &) const;
@@ -118,6 +120,7 @@ public:
void setProperty(QObject *, const Identifier &name, const QScriptValue &,
QDeclarativeContext *evalContext = 0);
virtual QStringList propertyNames(Object *);
+ virtual bool compare(Object *, Object *);
protected:
virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &,
diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp
index b0599ad..51f1660 100644
--- a/src/declarative/qml/qdeclarativeparser.cpp
+++ b/src/declarative/qml/qdeclarativeparser.cpp
@@ -207,13 +207,14 @@ QDeclarativeParser::Object::DynamicSlot::DynamicSlot(const DynamicSlot &o)
}
QDeclarativeParser::Property::Property()
-: parent(0), type(0), index(-1), value(0), isDefault(true), isDeferred(false)
+: parent(0), type(0), index(-1), value(0), isDefault(true), isDeferred(false),
+ isValueTypeSubProperty(false)
{
}
QDeclarativeParser::Property::Property(const QByteArray &n)
: parent(0), type(0), index(-1), value(0), name(n), isDefault(false),
- isDeferred(false)
+ isDeferred(false), isValueTypeSubProperty(false)
{
}
diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h
index 5bf4b68..9dfb86b 100644
--- a/src/declarative/qml/qdeclarativeparser_p.h
+++ b/src/declarative/qml/qdeclarativeparser_p.h
@@ -351,6 +351,8 @@ namespace QDeclarativeParser
// True if the setting of this property will be deferred. Set by the
// QDeclarativeCompiler
bool isDeferred;
+ // True if this property is a value-type psuedo-property
+ bool isValueTypeSubProperty;
LocationSpan location;
LocationRange listValueRange;
diff --git a/src/declarative/qml/qdeclarativeprivate.h b/src/declarative/qml/qdeclarativeprivate.h
index 01369d4..bebe82c 100644
--- a/src/declarative/qml/qdeclarativeprivate.h
+++ b/src/declarative/qml/qdeclarativeprivate.h
@@ -73,6 +73,9 @@ namespace QDeclarativePrivate
QObject *create() { return new T; }
template<typename T>
+ void createInto(void *memory) { new (memory) T; }
+
+ template<typename T>
QObject *createParent(QObject *p) { return new T(p); }
template<class From, class To, int N>
@@ -172,7 +175,8 @@ namespace QDeclarativePrivate
int typeId;
int listId;
- QObject *(*create)();
+ int objectSize;
+ void (*create)(void *);
const char *uri;
int versionMajor;
diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp
index 4f73b89..c55c22f 100644
--- a/src/declarative/qml/qdeclarativeproperty.cpp
+++ b/src/declarative/qml/qdeclarativeproperty.cpp
@@ -115,8 +115,10 @@ QDeclarativeProperty::QDeclarativeProperty(QObject *obj)
}
/*!
- Creates a QDeclarativeProperty for the default property of \a obj. If there is no
- default property, an invalid QDeclarativeProperty will be created.
+ Creates a QDeclarativeProperty for the default property of \a obj
+ using the \l{QDeclarativeContext} {context} \a ctxt. If there is
+ no default property, an invalid QDeclarativeProperty will be
+ created.
*/
QDeclarativeProperty::QDeclarativeProperty(QObject *obj, QDeclarativeContext *ctxt)
: d(new QDeclarativePropertyPrivate)
@@ -128,11 +130,13 @@ QDeclarativeProperty::QDeclarativeProperty(QObject *obj, QDeclarativeContext *ct
}
/*!
- Creates a QDeclarativeProperty for the default property of \a obj. If there is no
- default property, an invalid QDeclarativeProperty will be created.
+ Creates a QDeclarativeProperty for the default property of \a obj
+ using the environment for instantiating QML components that is
+ provided by \a engine. If there is no default property, an
+ invalid QDeclarativeProperty will be created.
*/
QDeclarativeProperty::QDeclarativeProperty(QObject *obj, QDeclarativeEngine *engine)
-: d(new QDeclarativePropertyPrivate)
+ : d(new QDeclarativePropertyPrivate)
{
d->q = this;
d->context = 0;
@@ -166,8 +170,9 @@ QDeclarativeProperty::QDeclarativeProperty(QObject *obj, const QString &name)
}
/*!
- Creates a QDeclarativeProperty for the property \a name of \a obj.
- */
+ Creates a QDeclarativeProperty for the property \a name of \a obj
+ using the \l{QDeclarativeContext} {context} \a ctxt.
+*/
QDeclarativeProperty::QDeclarativeProperty(QObject *obj, const QString &name, QDeclarativeContext *ctxt)
: d(new QDeclarativePropertyPrivate)
{
@@ -179,7 +184,9 @@ QDeclarativeProperty::QDeclarativeProperty(QObject *obj, const QString &name, QD
}
/*!
- Creates a QDeclarativeProperty for the property \a name of \a obj.
+ Creates a QDeclarativeProperty for the property \a name of \a obj
+ using the environment for instantiating QML components that is
+ provided by \a engine.
*/
QDeclarativeProperty::QDeclarativeProperty(QObject *obj, const QString &name, QDeclarativeEngine *engine)
: d(new QDeclarativePropertyPrivate)
@@ -487,15 +494,13 @@ QDeclarativeProperty &QDeclarativeProperty::operator=(const QDeclarativeProperty
*/
bool QDeclarativeProperty::isWritable() const
{
- QDeclarativeProperty::PropertyTypeCategory category = propertyTypeCategory();
-
if (!d->object)
return false;
- if (category == List)
+ if (d->core.flags & QDeclarativePropertyCache::Data::IsQList) //list
return true;
- else if (type() & SignalProperty)
+ else if (d->core.flags & QDeclarativePropertyCache::Data::IsFunction) //signal handler
return false;
- else if (d->core.isValid() && d->object)
+ else if (d->core.isValid()) //normal property
return d->core.flags & QDeclarativePropertyCache::Data::IsWritable;
else
return false;
@@ -591,7 +596,6 @@ QMetaMethod QDeclarativeProperty::method() const
return QMetaMethod();
}
-
/*!
Returns the binding associated with this property, or 0 if no binding
exists.
@@ -610,13 +614,18 @@ QDeclarativePropertyPrivate::binding(const QDeclarativeProperty &that)
return 0;
QDeclarativeAbstractBinding *binding = data->bindings;
- while (binding) {
- // ### This wont work for value types
- if (binding->propertyIndex() == that.d->core.coreIndex)
- return binding;
+ while (binding && binding->propertyIndex() != that.d->core.coreIndex)
binding = binding->m_nextBinding;
+
+ if (binding && that.d->valueType.valueTypeCoreIdx != -1) {
+ if (binding->bindingType() == QDeclarativeAbstractBinding::ValueTypeProxy) {
+ QDeclarativeValueTypeProxyBinding *proxy = static_cast<QDeclarativeValueTypeProxyBinding *>(binding);
+
+ binding = proxy->binding(bindingIndex(that));
+ }
}
- return 0;
+
+ return binding;
}
/*!
@@ -643,36 +652,36 @@ QDeclarativePropertyPrivate::setBinding(const QDeclarativeProperty &that,
return 0;
}
- return that.d->setBinding(that.d->object, that.d->core, newBinding, flags);
+ return that.d->setBinding(that.d->object, that.d->core.coreIndex,
+ that.d->valueType.valueTypeCoreIdx, newBinding, flags);
}
QDeclarativeAbstractBinding *
-QDeclarativePropertyPrivate::setBinding(QObject *object, const QDeclarativePropertyCache::Data &core,
- QDeclarativeAbstractBinding *newBinding, WriteFlags flags)
+QDeclarativePropertyPrivate::setBinding(QObject *object, int coreIndex, int valueTypeIndex,
+ QDeclarativeAbstractBinding *newBinding, WriteFlags flags)
{
QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, 0 != newBinding);
+ QDeclarativeAbstractBinding *binding = 0;
- if (data && data->hasBindingBit(core.coreIndex)) {
- QDeclarativeAbstractBinding *binding = data->bindings;
- while (binding) {
- // ### This wont work for value types
- if (binding->propertyIndex() == core.coreIndex) {
- binding->setEnabled(false);
+ if (data && data->hasBindingBit(coreIndex)) {
+ binding = data->bindings;
- if (newBinding)
- newBinding->setEnabled(true, flags);
+ while (binding && binding->propertyIndex() != coreIndex)
+ binding = binding->m_nextBinding;
+ }
- return binding; // ### QDeclarativeAbstractBinding;
- }
+ if (binding && valueTypeIndex != -1 && binding->bindingType() == QDeclarativeAbstractBinding::ValueTypeProxy) {
+ int index = coreIndex | (valueTypeIndex << 24);
+ binding = static_cast<QDeclarativeValueTypeProxyBinding *>(binding)->binding(index);
+ }
- binding = binding->m_nextBinding;
- }
- }
+ if (binding)
+ binding->setEnabled(false);
- if (newBinding)
+ if (newBinding)
newBinding->setEnabled(true, flags);
- return 0;
+ return binding;
}
/*!
@@ -766,11 +775,14 @@ QVariant QDeclarativeProperty::read(QObject *object, const QString &name)
}
/*!
-Return the \a name property value of \a object. This method is equivalent to:
-\code
+ Return the \a name property value of \a object using the
+ \l{QDeclarativeContext} {context} \a ctxt. This method is
+ equivalent to:
+
+ \code
QDeclarativeProperty p(object, name, context);
p.read();
-\endcode
+ \endcode
*/
QVariant QDeclarativeProperty::read(QObject *object, const QString &name, QDeclarativeContext *ctxt)
{
@@ -779,11 +791,15 @@ QVariant QDeclarativeProperty::read(QObject *object, const QString &name, QDecla
}
/*!
-Return the \a name property value of \a object. This method is equivalent to:
-\code
+
+ Return the \a name property value of \a object using the environment
+ for instantiating QML components that is provided by \a engine. .
+ This method is equivalent to:
+
+ \code
QDeclarativeProperty p(object, name, engine);
p.read();
-\endcode
+ \endcode
*/
QVariant QDeclarativeProperty::read(QObject *object, const QString &name, QDeclarativeEngine *engine)
{
@@ -1073,19 +1089,23 @@ const QMetaObject *QDeclarativePropertyPrivate::rawMetaObjectForType(QDeclarativ
}
/*!
- Set the property value to \a value.
-*/
+ Sets the property value to \a value and returns true.
+ Returns false if the property can't be set because the
+ \a value is the wrong type, for example.
+ */
bool QDeclarativeProperty::write(const QVariant &value) const
{
return QDeclarativePropertyPrivate::write(*this, value, 0);
}
/*!
-Writes \a value to the \a name property of \a object. This method is equivalent to:
-\code
+ Writes \a value to the \a name property of \a object. This method
+ is equivalent to:
+
+ \code
QDeclarativeProperty p(object, name);
p.write(value);
-\endcode
+ \endcode
*/
bool QDeclarativeProperty::write(QObject *object, const QString &name, const QVariant &value)
{
@@ -1094,13 +1114,18 @@ bool QDeclarativeProperty::write(QObject *object, const QString &name, const QVa
}
/*!
-Writes \a value to the \a name property of \a object. This method is equivalent to:
-\code
+ Writes \a value to the \a name property of \a object using the
+ \l{QDeclarativeContext} {context} \a ctxt. This method is
+ equivalent to:
+
+ \code
QDeclarativeProperty p(object, name, ctxt);
p.write(value);
-\endcode
+ \endcode
*/
-bool QDeclarativeProperty::write(QObject *object, const QString &name, const QVariant &value,
+bool QDeclarativeProperty::write(QObject *object,
+ const QString &name,
+ const QVariant &value,
QDeclarativeContext *ctxt)
{
QDeclarativeProperty p(object, name, ctxt);
@@ -1108,11 +1133,15 @@ bool QDeclarativeProperty::write(QObject *object, const QString &name, const QVa
}
/*!
-Writes \a value to the \a name property of \a object. This method is equivalent to:
-\code
+
+ Writes \a value to the \a name property of \a object using the
+ environment for instantiating QML components that is provided by
+ \a engine. This method is equivalent to:
+
+ \code
QDeclarativeProperty p(object, name, engine);
p.write(value);
-\endcode
+ \endcode
*/
bool QDeclarativeProperty::write(QObject *object, const QString &name, const QVariant &value,
QDeclarativeEngine *engine)
@@ -1122,7 +1151,9 @@ bool QDeclarativeProperty::write(QObject *object, const QString &name, const QVa
}
/*!
- Resets the property value.
+ Resets the property and returns true if the property is
+ resettable. If the property is not resettable, nothing happens
+ and false is returned.
*/
bool QDeclarativeProperty::reset() const
{
@@ -1224,6 +1255,18 @@ int QDeclarativePropertyPrivate::valueTypeCoreIndex(const QDeclarativeProperty &
return that.d->valueType.valueTypeCoreIdx;
}
+/*!
+ Returns the "property index" for use in bindings. The top 8 bits are the value type
+ offset, and 0 otherwise. The bottom 24-bits are the regular property index.
+*/
+int QDeclarativePropertyPrivate::bindingIndex(const QDeclarativeProperty &that)
+{
+ int rv = that.d->core.coreIndex;
+ if (rv != -1 && that.d->valueType.valueTypeCoreIdx != -1)
+ rv = rv | (that.d->valueType.valueTypeCoreIdx << 24);
+ return rv;
+}
+
struct SerializedData {
bool isValueType;
QDeclarativePropertyCache::Data core;
diff --git a/src/declarative/qml/qdeclarativeproperty_p.h b/src/declarative/qml/qdeclarativeproperty_p.h
index c31e2d3..26b85b8 100644
--- a/src/declarative/qml/qdeclarativeproperty_p.h
+++ b/src/declarative/qml/qdeclarativeproperty_p.h
@@ -110,7 +110,7 @@ public:
const QVariant &value, int flags);
static bool write(QObject *, const QDeclarativePropertyCache::Data &, const QVariant &,
QDeclarativeContext *, WriteFlags flags = 0);
- static QDeclarativeAbstractBinding *setBinding(QObject *, const QDeclarativePropertyCache::Data &,
+ static QDeclarativeAbstractBinding *setBinding(QObject *, int coreIndex, int valueTypeIndex /* -1 */,
QDeclarativeAbstractBinding *,
WriteFlags flags = DontRemoveBinding);
@@ -133,6 +133,7 @@ public:
QDeclarativeExpression *) ;
static bool write(const QDeclarativeProperty &that, const QVariant &, WriteFlags);
static int valueTypeCoreIndex(const QDeclarativeProperty &that);
+ static int bindingIndex(const QDeclarativeProperty &that);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyPrivate::WriteFlags)
diff --git a/src/declarative/qml/qdeclarativepropertycache_p.h b/src/declarative/qml/qdeclarativepropertycache_p.h
index 68e6e6b..bfbeff4 100644
--- a/src/declarative/qml/qdeclarativepropertycache_p.h
+++ b/src/declarative/qml/qdeclarativepropertycache_p.h
@@ -55,15 +55,16 @@
#include "qdeclarativerefcount_p.h"
#include "qdeclarativecleanup_p.h"
+#include "qdeclarativenotifier_p.h"
#include <QtCore/qvector.h>
#include <QtScript/private/qscriptdeclarativeclass_p.h>
-
QT_BEGIN_NAMESPACE
class QDeclarativeEngine;
class QMetaProperty;
+
class QDeclarativePropertyCache : public QDeclarativeRefCount, public QDeclarativeCleanup
{
public:
@@ -83,9 +84,9 @@ public:
IsResettable = 0x00000004,
// These are mutualy exclusive
- IsFunction = 0x00000008,
- IsQObjectDerived = 0x00000010,
- IsEnumType = 0x00000020,
+ IsFunction = 0x00000010,
+ IsQObjectDerived = 0x00000020,
+ IsEnumType = 0x00000040,
IsQList = 0x00000080,
IsQmlBinding = 0x00000100,
IsQScriptValue = 0x00000200,
@@ -96,7 +97,7 @@ public:
};
Q_DECLARE_FLAGS(Flags, Flag)
-
+
bool isValid() const { return coreIndex != -1; }
Flags flags;
@@ -114,9 +115,9 @@ public:
struct ValueTypeData {
inline ValueTypeData();
inline bool operator==(const ValueTypeData &);
- Data::Flags flags; // flags on the value type wrapper
- int valueTypeCoreIdx; // The prop index of the access property on the value type wrapper
- int valueTypePropType; // The QVariant::Type of access property on the value type wrapper
+ Data::Flags flags; // flags of the access property on the value type proxy object
+ int valueTypeCoreIdx; // The prop index of the access property on the value type proxy object
+ int valueTypePropType; // The QVariant::Type of access property on the value type proxy object
};
void update(QDeclarativeEngine *, const QMetaObject *);
diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp
index c070123..00e6704 100644
--- a/src/declarative/qml/qdeclarativevaluetype.cpp
+++ b/src/declarative/qml/qdeclarativevaluetype.cpp
@@ -61,7 +61,7 @@ int qmlRegisterValueTypeEnums(const char *qmlName)
QDeclarativePrivate::RegisterType type = {
0,
- qRegisterMetaType<T *>(pointerName.constData()), 0, 0,
+ qRegisterMetaType<T *>(pointerName.constData()), 0, 0, 0,
"Qt", 4, 6, qmlName, &T::staticMetaObject,
diff --git a/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp b/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp
index 9cb65f8..a567c38 100644
--- a/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp
+++ b/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp
@@ -41,6 +41,8 @@
#include "qdeclarativevaluetypescriptclass_p.h"
+#include "qdeclarativebinding_p.h"
+#include "qdeclarativeproperty_p.h"
#include "qdeclarativeengine_p.h"
#include "qdeclarativeguard_p.h"
@@ -115,6 +117,11 @@ void QDeclarativeValueTypeScriptClass::setProperty(Object *obj, const Identifier
{
QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj);
+ QDeclarativeAbstractBinding *delBinding =
+ QDeclarativePropertyPrivate::setBinding(ref->object, ref->property, m_lastIndex, 0);
+ if (delBinding)
+ delBinding->destroy();
+
QVariant v = QDeclarativeScriptClass::toVariant(engine, value);
ref->type->read(ref->object, ref->property);
diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp
index 6a08674..05553fd 100644
--- a/src/declarative/qml/qdeclarativevme.cpp
+++ b/src/declarative/qml/qdeclarativevme.cpp
@@ -130,9 +130,9 @@ void QDeclarativeVME::runDeferred(QObject *object)
}
QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, QDeclarativeContext *ctxt,
- QDeclarativeCompiledData *comp,
- int start, int count,
- const QBitField &bindingSkipList)
+ QDeclarativeCompiledData *comp,
+ int start, int count,
+ const QBitField &bindingSkipList)
{
Q_ASSERT(comp);
Q_ASSERT(ctxt);
@@ -197,6 +197,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, QDeclarati
QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(o);
Q_ASSERT(ddata);
+ ddata->setImplicitDestructible();
ddata->outerContext = ctxt;
ddata->lineNumber = instr.line;
ddata->columnNumber = instr.create.column;
@@ -236,7 +237,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, QDeclarati
case QDeclarativeInstruction::SetDefault:
{
QObject *target = stack.top();
- ctxt->addDefaultObject(target);
+ ctxt->setContextObject(target);
}
break;
@@ -247,6 +248,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, QDeclarati
QDeclarativeEngine::setContextForObject(qcomp, ctxt);
QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(qcomp);
Q_ASSERT(ddata);
+ ddata->setImplicitDestructible();
ddata->outerContext = ctxt;
ddata->lineNumber = instr.line;
ddata->columnNumber = instr.create.column;
@@ -832,11 +834,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, QDeclarati
if (parserStatus.count)
ep->parserStatus << parserStatus;
- if (stack.isEmpty())
- return 0;
- else
- return stack.top();
- return 0;
+ Q_ASSERT(stack.count() == 1);
+ return stack.top();
}
bool QDeclarativeVME::isError() const
diff --git a/src/declarative/qml/qdeclarativevme_p.h b/src/declarative/qml/qdeclarativevme_p.h
index 951f6a7..bcd3ac9 100644
--- a/src/declarative/qml/qdeclarativevme_p.h
+++ b/src/declarative/qml/qdeclarativevme_p.h
@@ -71,7 +71,7 @@ template<typename T, int N = 128>
class QDeclarativeVMEStack {
public:
QDeclarativeVMEStack() : index(-1), maxSize(N), data(fixedData) {}
- ~QDeclarativeVMEStack() { if (data != fixedData) qFree(fixedData); }
+ ~QDeclarativeVMEStack() { if (data != fixedData) qFree(data); }
bool isEmpty() const { return index == -1; }
const T &top() const { return data[index]; }
diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
index 87cab85..58e67fa 100644
--- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp
+++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
@@ -1245,7 +1245,7 @@ void QDeclarativeXMLHttpRequest::finished()
if (m_redirectCount < XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION) {
QVariant redirect = m_network->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (redirect.isValid()) {
- QUrl url = redirect.toUrl();
+ QUrl url = m_network->url().resolved(redirect.toUrl());
destroyNetwork();
requestFromUrl(url);
return;
diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri
index aa1a34b..49888c3 100644
--- a/src/declarative/qml/qml.pri
+++ b/src/declarative/qml/qml.pri
@@ -38,6 +38,7 @@ SOURCES += \
$$PWD/qdeclarativescript.cpp \
$$PWD/qdeclarativecleanup.cpp \
$$PWD/qdeclarativepropertycache.cpp \
+ $$PWD/qdeclarativenotifier.cpp \
$$PWD/qdeclarativeintegercache.cpp \
$$PWD/qdeclarativetypenamecache.cpp \
$$PWD/qdeclarativescriptstring.cpp \
@@ -108,6 +109,7 @@ HEADERS += \
$$PWD/qdeclarativewatcher_p.h \
$$PWD/qdeclarativecleanup_p.h \
$$PWD/qdeclarativepropertycache_p.h \
+ $$PWD/qdeclarativenotifier_p.h \
$$PWD/qdeclarativeintegercache_p.h \
$$PWD/qdeclarativetypenamecache_p.h \
$$PWD/qdeclarativescriptstring.h \
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp
index 8c8dd95..009e07f 100644
--- a/src/declarative/util/qdeclarativeanimation.cpp
+++ b/src/declarative/util/qdeclarativeanimation.cpp
@@ -838,10 +838,10 @@ void QDeclarativePropertyAction::setProperty(const QString &n)
}
/*!
+ \qmlproperty list<Object> PropertyAction::targets
\qmlproperty string PropertyAction::property
\qmlproperty string PropertyAction::properties
\qmlproperty Object PropertyAction::target
- \qmlproperty list<Object> PropertyAction::targets
These properties are used as a set to determine which properties should be
affected by this action.
@@ -876,6 +876,7 @@ QDeclarativeListProperty<QObject> QDeclarativePropertyAction::targets()
/*!
\qmlproperty list<Object> PropertyAction::exclude
This property holds the objects not to be affected by this animation.
+
\sa targets
*/
QDeclarativeListProperty<QObject> QDeclarativePropertyAction::exclude()
@@ -1876,13 +1877,17 @@ void QDeclarativePropertyAnimation::setTo(const QVariant &t)
}
/*!
- \qmlproperty QEasingCurve PropertyAnimation::easing
- \brief the easing curve used for the transition.
+ \qmlproperty enum PropertyAnimation::easing.type
+ \qmlproperty real PropertyAnimation::easing.amplitude
+ \qmlproperty real PropertyAnimation::easing.overshoot
+ \qmlproperty real PropertyAnimation::easing.period
+ \brief the easing curve used for the animation.
- For the easing you can specify the following parameters: type, amplitude, period and overshoot.
+ To specify an easing curve you need to specify at least the type. For some curves you can also specify
+ amplitude, period and/or overshoot (more details provided after the table).
\qml
- PropertyAnimation { properties: "y"; easing.type: "InOutElastc"; easing.amplitude: 2.0; easing.period: 1.5 }
+ PropertyAnimation { properties: "y"; easing.type: "InOutElastic"; easing.amplitude: 2.0; easing.period: 1.5 }
\endqml
Available types are:
@@ -2220,7 +2225,7 @@ QDeclarativeListProperty<QObject> QDeclarativePropertyAnimation::targets()
/*!
\qmlproperty list<Object> PropertyAnimation::exclude
This property holds the items not to be affected by this animation.
- \sa targets
+ \sa PropertyAnimation::targets
*/
QDeclarativeListProperty<QObject> QDeclarativePropertyAnimation::exclude()
{
@@ -2428,11 +2433,12 @@ void QDeclarativePropertyAnimation::transition(QDeclarativeStateActions &actions
be run in parallel (like those in a ParallelAnimation group).
In some cases, such as reparenting between items with clipping, it's useful
- to animate the parent change \i via another item with no clipping.
+ to animate the parent change via another item with no clipping.
When used in a transition, ParentAnimation will by default animate
all ParentChanges.
*/
+
/*!
\internal
\class QDeclarativeParentAnimation
@@ -2445,12 +2451,15 @@ QDeclarativeParentAnimation::QDeclarativeParentAnimation(QObject *parent)
QDeclarative_setParent_noEvent(d->topLevelGroup, this);
d->startAction = new QActionAnimation;
+ QDeclarative_setParent_noEvent(d->startAction, d->topLevelGroup);
d->topLevelGroup->addAnimation(d->startAction);
d->ag = new QParallelAnimationGroup;
+ QDeclarative_setParent_noEvent(d->ag, d->topLevelGroup);
d->topLevelGroup->addAnimation(d->ag);
d->endAction = new QActionAnimation;
+ QDeclarative_setParent_noEvent(d->endAction, d->topLevelGroup);
d->topLevelGroup->addAnimation(d->endAction);
}
@@ -2741,4 +2750,99 @@ QAbstractAnimation *QDeclarativeParentAnimation::qtAnimation()
return d->topLevelGroup;
}
+/*!
+ \qmlclass AnchorAnimation QDeclarativeAnchorAnimation
+ \since 4.7
+ \inherits Animation
+ \brief The AnchorAnimation element allows you to animate anchor changes.
+
+ AnchorAnimation will animated any changes specified by a state's AnchorChanges.
+ In the following snippet we animate the addition of a right anchor to our item.
+ \qml
+ Item {
+ id: myItem
+ width: 100
+ }
+ ...
+ State {
+ AnchorChanges {
+ target: myItem
+ anchors.right: container.right
+ }
+ }
+ ...
+ Transition {
+ //smoothly reanchor myItem and move into new position
+ AnchorAnimation {}
+ }
+ \endqml
+
+ \sa AnchorChanges
+*/
+
+QDeclarativeAnchorAnimation::QDeclarativeAnchorAnimation(QObject *parent)
+: QDeclarativeAbstractAnimation(*(new QDeclarativeAnchorAnimationPrivate), parent)
+{
+ Q_D(QDeclarativeAnchorAnimation);
+ d->va = new QDeclarativeBulkValueAnimator;
+ QDeclarative_setParent_noEvent(d->va, this);
+}
+
+QDeclarativeAnchorAnimation::~QDeclarativeAnchorAnimation()
+{
+}
+
+QAbstractAnimation *QDeclarativeAnchorAnimation::qtAnimation()
+{
+ Q_D(QDeclarativeAnchorAnimation);
+ return d->va;
+}
+
+/*!
+ \qmlproperty list<Item> AnchorAnimation::targets
+ The items to reanchor.
+
+ If no targets are specified all AnchorChanges will be
+ animated by the AnchorAnimation.
+*/
+QDeclarativeListProperty<QDeclarativeItem> QDeclarativeAnchorAnimation::targets()
+{
+ Q_D(QDeclarativeAnchorAnimation);
+ return QDeclarativeListProperty<QDeclarativeItem>(this, d->targets);
+}
+
+void QDeclarativeAnchorAnimation::transition(QDeclarativeStateActions &actions,
+ QDeclarativeProperties &modified,
+ TransitionDirection direction)
+{
+ Q_D(QDeclarativeAnchorAnimation);
+ PropertyUpdater *data = new PropertyUpdater;
+ data->interpolatorType = QMetaType::QReal;
+ data->interpolator = d->interpolator;
+
+ data->reverse = direction == Backward ? true : false;
+ data->fromSourced = false;
+ data->fromDefined = false;
+
+ for (int ii = 0; ii < actions.count(); ++ii) {
+ QDeclarativeAction &action = actions[ii];
+ if (action.event && action.event->typeName() == QLatin1String("AnchorChanges")
+ && (d->targets.isEmpty() || d->targets.contains(static_cast<QDeclarativeAnchorChanges*>(action.event)->object()))) {
+ data->actions << static_cast<QDeclarativeAnchorChanges*>(action.event)->additionalActions();
+ }
+ }
+
+ if (data->actions.count()) {
+ if (!d->rangeIsSet) {
+ d->va->setStartValue(qreal(0));
+ d->va->setEndValue(qreal(1));
+ d->rangeIsSet = true;
+ }
+ d->va->setAnimValue(data, QAbstractAnimation::DeleteWhenStopped);
+ d->va->setFromSourcedValue(&data->fromSourced);
+ } else {
+ delete data;
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h
index af48309..eb339f6 100644
--- a/src/declarative/util/qdeclarativeanimation_p.h
+++ b/src/declarative/util/qdeclarativeanimation_p.h
@@ -480,6 +480,26 @@ protected:
virtual QAbstractAnimation *qtAnimation();
};
+class QDeclarativeAnchorAnimationPrivate;
+class QDeclarativeAnchorAnimation : public QDeclarativeAbstractAnimation
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QDeclarativeAnchorAnimation)
+ Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> targets READ targets)
+
+public:
+ QDeclarativeAnchorAnimation(QObject *parent=0);
+ virtual ~QDeclarativeAnchorAnimation();
+
+ QDeclarativeListProperty<QDeclarativeItem> targets();
+
+protected:
+ virtual void transition(QDeclarativeStateActions &actions,
+ QDeclarativeProperties &modified,
+ TransitionDirection direction);
+ virtual QAbstractAnimation *qtAnimation();
+};
+
QT_END_NAMESPACE
QML_DECLARE_TYPE(QDeclarativeAbstractAnimation)
@@ -495,6 +515,7 @@ QML_DECLARE_TYPE(QDeclarativeParallelAnimation)
QML_DECLARE_TYPE(QDeclarativeVector3dAnimation)
QML_DECLARE_TYPE(QDeclarativeRotationAnimation)
QML_DECLARE_TYPE(QDeclarativeParentAnimation)
+QML_DECLARE_TYPE(QDeclarativeAnchorAnimation)
QT_END_HEADER
diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h
index ae82a90..0460312 100644
--- a/src/declarative/util/qdeclarativeanimation_p_p.h
+++ b/src/declarative/util/qdeclarativeanimation_p_p.h
@@ -393,6 +393,19 @@ public:
QPointF computeTransformOrigin(QDeclarativeItem::TransformOrigin origin, qreal width, qreal height) const;
};
+class QDeclarativeAnchorAnimationPrivate : public QDeclarativeAbstractAnimationPrivate
+{
+ Q_DECLARE_PUBLIC(QDeclarativeAnchorAnimation)
+public:
+ QDeclarativeAnchorAnimationPrivate() : rangeIsSet(false), va(0),
+ interpolator(QVariantAnimationPrivate::getInterpolator(QMetaType::QReal)) {}
+
+ bool rangeIsSet;
+ QDeclarativeBulkValueAnimator *va;
+ QVariantAnimation::Interpolator interpolator;
+ QList<QDeclarativeItem*> targets;
+};
+
QT_END_NAMESPACE
#endif // QDECLARATIVEANIMATION_P_H
diff --git a/src/declarative/util/qdeclarativefontloader.cpp b/src/declarative/util/qdeclarativefontloader.cpp
index 8f5f537..bf98d40 100644
--- a/src/declarative/util/qdeclarativefontloader.cpp
+++ b/src/declarative/util/qdeclarativefontloader.cpp
@@ -61,7 +61,7 @@ class QDeclarativeFontLoaderPrivate : public QObjectPrivate
Q_DECLARE_PUBLIC(QDeclarativeFontLoader)
public:
- QDeclarativeFontLoaderPrivate() : reply(0), status(QDeclarativeFontLoader::Null) {}
+ QDeclarativeFontLoaderPrivate() : reply(0), status(QDeclarativeFontLoader::Null), redirectCount(0) {}
void addFontToDatabase(const QByteArray &);
@@ -69,6 +69,7 @@ public:
QString name;
QNetworkReply *reply;
QDeclarativeFontLoader::Status status;
+ int redirectCount;
};
@@ -206,15 +207,31 @@ QDeclarativeFontLoader::Status QDeclarativeFontLoader::status() const
return d->status;
}
+#define FONTLOADER_MAXIMUM_REDIRECT_RECURSION 16
+
void QDeclarativeFontLoader::replyFinished()
{
Q_D(QDeclarativeFontLoader);
if (d->reply) {
+ d->redirectCount++;
+ if (d->redirectCount < FONTLOADER_MAXIMUM_REDIRECT_RECURSION) {
+ QVariant redirect = d->reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirect.isValid()) {
+ QUrl url = d->reply->url().resolved(redirect.toUrl());
+ d->reply->deleteLater();
+ d->reply = 0;
+ setSource(url);
+ return;
+ }
+ }
+ d->redirectCount=0;
+
if (!d->reply->error()) {
QByteArray ba = d->reply->readAll();
d->addFontToDatabase(ba);
} else {
d->status = Error;
+ qWarning() << "Cannot load font:" << d->reply->url();
emit statusChanged();
}
d->reply->deleteLater();
diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp
index cfb25dd..942d5f6 100644
--- a/src/declarative/util/qdeclarativepixmapcache.cpp
+++ b/src/declarative/util/qdeclarativepixmapcache.cpp
@@ -137,7 +137,7 @@ class QDeclarativeImageRequestHandler : public QObject
Q_OBJECT
public:
QDeclarativeImageRequestHandler(QDeclarativeImageReader *read, QDeclarativeEngine *eng)
- : QObject(), accessManager(0), engine(eng), reader(read)
+ : QObject(), accessManager(0), engine(eng), reader(read), redirectCount(0)
{
QCoreApplication::postEvent(this, new QEvent(QEvent::User));
}
@@ -162,18 +162,24 @@ private:
QNetworkAccessManager *accessManager;
QDeclarativeEngine *engine;
QDeclarativeImageReader *reader;
+ int redirectCount;
+
+ static int replyDownloadProgress;
+ static int replyFinished;
+ static int downloadProgress;
+ static int thisNetworkRequestDone;
};
//===========================================================================
+int QDeclarativeImageRequestHandler::replyDownloadProgress = -1;
+int QDeclarativeImageRequestHandler::replyFinished = -1;
+int QDeclarativeImageRequestHandler::downloadProgress = -1;
+int QDeclarativeImageRequestHandler::thisNetworkRequestDone = -1;
+
bool QDeclarativeImageRequestHandler::event(QEvent *event)
{
if (event->type() == QEvent::User) {
- static int replyDownloadProgress = -1;
- static int replyFinished = -1;
- static int downloadProgress = -1;
- static int thisNetworkRequestDone = -1;
-
if (replyDownloadProgress == -1) {
replyDownloadProgress = QNetworkReply::staticMetaObject.indexOfSignal("downloadProgress(qint64,qint64)");
replyFinished = QNetworkReply::staticMetaObject.indexOfSignal("finished()");
@@ -264,10 +270,33 @@ bool QDeclarativeImageRequestHandler::event(QEvent *event)
return QObject::event(event);
}
+#define IMAGEREQUESTHANDLER_MAX_REDIRECT_RECURSION 16
+
void QDeclarativeImageRequestHandler::networkRequestDone()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
QDeclarativePixmapReply *job = replies.take(reply);
+
+ redirectCount++;
+ if (redirectCount < IMAGEREQUESTHANDLER_MAX_REDIRECT_RECURSION) {
+ QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirect.isValid()) {
+ QUrl url = reply->url().resolved(redirect.toUrl());
+ QNetworkRequest req(url);
+ req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
+
+ reply->deleteLater();
+ reply = networkAccessManager()->get(req);
+
+ QMetaObject::connect(reply, replyDownloadProgress, job, downloadProgress);
+ QMetaObject::connect(reply, replyFinished, this, thisNetworkRequestDone);
+
+ replies.insert(reply, job);
+ return;
+ }
+ }
+ redirectCount=0;
+
if (job) {
QImage image;
QDeclarativeImageReaderEvent::ReadError error;
diff --git a/src/declarative/util/qdeclarativestate.cpp b/src/declarative/util/qdeclarativestate.cpp
index 1d70d33..802ff1c 100644
--- a/src/declarative/util/qdeclarativestate.cpp
+++ b/src/declarative/util/qdeclarativestate.cpp
@@ -96,21 +96,12 @@ void QDeclarativeActionEvent::reverse()
{
}
-QList<QDeclarativeAction> QDeclarativeActionEvent::extraActions()
-{
- return QList<QDeclarativeAction>();
-}
-
bool QDeclarativeActionEvent::changesBindings()
{
return false;
}
-void QDeclarativeActionEvent::clearForwardBindings()
-{
-}
-
-void QDeclarativeActionEvent::clearReverseBindings()
+void QDeclarativeActionEvent::clearBindings()
{
}
@@ -368,47 +359,60 @@ void QDeclarativeState::apply(QDeclarativeStateGroup *group, QDeclarativeTransit
for (int ii = 0; ii < applyList.count(); ++ii) {
QDeclarativeAction &action = applyList[ii];
- bool found = false;
-
- int jj;
if (action.event) {
if (!action.event->isReversable())
continue;
- for (jj = 0; jj < d->revertList.count(); ++jj) {
+ bool found = false;
+ for (int jj = 0; jj < d->revertList.count(); ++jj) {
QDeclarativeActionEvent *event = d->revertList.at(jj).event;
if (event && event->typeName() == action.event->typeName()) {
if (action.event->override(event)) {
found = true;
+
+ if (action.event != d->revertList.at(jj).event) {
+ action.event->copyOriginals(d->revertList.at(jj).event);
+
+ QDeclarativeSimpleAction r(action);
+ additionalReverts << r;
+ d->revertList.removeAt(jj);
+ } else if (action.event->isRewindable()) //###why needed?
+ action.event->saveCurrentValues();
+
break;
}
}
}
- if (!found || action.event != d->revertList.at(jj).event)
+ if (!found) {
action.event->saveOriginals();
- else if (action.event->isRewindable())
- action.event->saveCurrentValues();
+ // Only need to revert the applyList action if the previous
+ // state doesn't have a higher priority revert already
+ QDeclarativeSimpleAction r(action);
+ additionalReverts << r;
+ }
} else {
+ bool found = false;
action.fromBinding = QDeclarativePropertyPrivate::binding(action.property);
- for (jj = 0; jj < d->revertList.count(); ++jj) {
+ for (int jj = 0; jj < d->revertList.count(); ++jj) {
if (d->revertList.at(jj).property == action.property) {
found = true;
+ if (d->revertList.at(jj).binding != action.fromBinding) {
+ action.deleteFromBinding();
+ }
break;
}
}
- }
- if (!found) {
- if (!action.restore) {
- action.deleteFromBinding();
- } else {
- // Only need to revert the applyList action if the previous
- // state doesn't have a higher priority revert already
- QDeclarativeSimpleAction r(action);
- additionalReverts << r;
+ if (!found) {
+ if (!action.restore) {
+ action.deleteFromBinding();
+ } else {
+ // Only need to revert the applyList action if the previous
+ // state doesn't have a higher priority revert already
+ QDeclarativeSimpleAction r(action);
+ additionalReverts << r;
+ }
}
- } else if (d->revertList.at(jj).binding != action.fromBinding) {
- action.deleteFromBinding();
}
}
diff --git a/src/declarative/util/qdeclarativestate_p.h b/src/declarative/util/qdeclarativestate_p.h
index 0c6e7a3..ee2b7e8 100644
--- a/src/declarative/util/qdeclarativestate_p.h
+++ b/src/declarative/util/qdeclarativestate_p.h
@@ -92,17 +92,15 @@ public:
virtual bool isReversable();
virtual void reverse();
virtual void saveOriginals() {}
+ virtual void copyOriginals(QDeclarativeActionEvent *) {}
virtual bool isRewindable() { return isReversable(); }
virtual void rewind() {}
virtual void saveCurrentValues() {}
-
- //virtual bool hasExtraActions();
- virtual QList<QDeclarativeAction> extraActions();
+ virtual void saveTargetValues() {}
virtual bool changesBindings();
- virtual void clearForwardBindings();
- virtual void clearReverseBindings();
+ virtual void clearBindings();
virtual bool override(QDeclarativeActionEvent*other);
};
diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp
index cd06380..6f5bb66 100644
--- a/src/declarative/util/qdeclarativestateoperations.cpp
+++ b/src/declarative/util/qdeclarativestateoperations.cpp
@@ -403,6 +403,17 @@ void QDeclarativeParentChange::saveOriginals()
d->origStackBefore = d->rewindStackBefore;
}
+void QDeclarativeParentChange::copyOriginals(QDeclarativeActionEvent *other)
+{
+ Q_D(QDeclarativeParentChange);
+ QDeclarativeParentChange *pc = static_cast<QDeclarativeParentChange*>(other);
+
+ d->origParent = pc->d_func()->rewindParent;
+ d->origStackBefore = pc->d_func()->rewindStackBefore;
+
+ saveCurrentValues();
+}
+
void QDeclarativeParentChange::execute()
{
Q_D(QDeclarativeParentChange);
@@ -562,13 +573,16 @@ QString QDeclarativeStateChangeScript::typeName() const
\brief The AnchorChanges element allows you to change the anchors of an item in a state.
In the following example we change the top and bottom anchors of an item:
- \snippet examples/declarative/anchors/anchor-changes.qml 0
+ \qml
+ AnchorChanges {
+ target: content; top: window.top; bottom: window.bottom
+ }
+ \endqml
- AnchorChanges will 'inject' \c x, \c y, \c width, and \c height changes into the transition,
- so you can animate them as you would normally changes to these properties:
+ AnchorChanges can be animated using AnchorAnimation.
\qml
//animate our anchor changes
- NumberAnimation { targets: content; properties: "x,y,width,height" }
+ AnchorAnimation {}
\endqml
For more information on anchors see \l {anchor-layout}{Anchor Layouts}.
@@ -581,10 +595,10 @@ class QDeclarativeAnchorChangesPrivate : public QObjectPrivate
public:
QDeclarativeAnchorChangesPrivate() : target(0) {}
- QString name;
QDeclarativeItem *target;
QString resetString;
QStringList resetList;
+
QDeclarativeAnchorLine left;
QDeclarativeAnchorLine right;
QDeclarativeAnchorLine horizontalCenter;
@@ -613,6 +627,24 @@ public:
qreal fromY;
qreal fromWidth;
qreal fromHeight;
+
+ qreal toX;
+ qreal toY;
+ qreal toWidth;
+ qreal toHeight;
+
+ qreal rewindX;
+ qreal rewindY;
+ qreal rewindWidth;
+ qreal rewindHeight;
+
+ bool applyOrigLeft;
+ bool applyOrigRight;
+ bool applyOrigHCenter;
+ bool applyOrigTop;
+ bool applyOrigBottom;
+ bool applyOrigVCenter;
+ bool applyOrigBaseline;
};
/*!
@@ -765,6 +797,38 @@ void QDeclarativeAnchorChanges::execute()
if (!d->target)
return;
+ //incorporate any needed "reverts"
+ if (d->applyOrigLeft)
+ d->target->anchors()->setLeft(d->origLeft);
+ if (d->applyOrigRight)
+ d->target->anchors()->setRight(d->origRight);
+ if (d->applyOrigHCenter)
+ d->target->anchors()->setHorizontalCenter(d->origHCenter);
+ if (d->applyOrigTop)
+ d->target->anchors()->setTop(d->origTop);
+ if (d->applyOrigBottom)
+ d->target->anchors()->setBottom(d->origBottom);
+ if (d->applyOrigVCenter)
+ d->target->anchors()->setVerticalCenter(d->origVCenter);
+ if (d->applyOrigBaseline)
+ d->target->anchors()->setBaseline(d->origBaseline);
+
+ //reset any anchors that have been specified
+ if (d->resetList.contains(QLatin1String("left")))
+ d->target->anchors()->resetLeft();
+ if (d->resetList.contains(QLatin1String("right")))
+ d->target->anchors()->resetRight();
+ if (d->resetList.contains(QLatin1String("horizontalCenter")))
+ d->target->anchors()->resetHorizontalCenter();
+ if (d->resetList.contains(QLatin1String("top")))
+ d->target->anchors()->resetTop();
+ if (d->resetList.contains(QLatin1String("bottom")))
+ d->target->anchors()->resetBottom();
+ if (d->resetList.contains(QLatin1String("verticalCenter")))
+ d->target->anchors()->resetVerticalCenter();
+ if (d->resetList.contains(QLatin1String("baseline")))
+ d->target->anchors()->resetBaseline();
+
//set any anchors that have been specified
if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->setLeft(d->left);
@@ -793,6 +857,22 @@ void QDeclarativeAnchorChanges::reverse()
if (!d->target)
return;
+ //reset any anchors set by the state
+ if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->resetLeft();
+ if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->resetRight();
+ if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->resetHorizontalCenter();
+ if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->resetTop();
+ if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->resetBottom();
+ if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->resetVerticalCenter();
+ if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->resetBaseline();
+
//restore previous anchors
if (d->origLeft.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->setLeft(d->origLeft);
@@ -815,31 +895,33 @@ QString QDeclarativeAnchorChanges::typeName() const
return QLatin1String("AnchorChanges");
}
-QList<QDeclarativeAction> QDeclarativeAnchorChanges::extraActions()
+QList<QDeclarativeAction> QDeclarativeAnchorChanges::additionalActions()
{
Q_D(QDeclarativeAnchorChanges);
QList<QDeclarativeAction> extra;
- //### try to be smarter about which ones we add.
- // or short-circuit later on if they haven't actually changed.
- // we shouldn't set explicit width if there wasn't one before.
if (d->target) {
QDeclarativeAction a;
- a.fromValue = d->fromX;
- a.property = QDeclarativeProperty(d->target, QLatin1String("x"));
- extra << a;
-
- a.fromValue = d->fromY;
- a.property = QDeclarativeProperty(d->target, QLatin1String("y"));
- extra << a;
-
- a.fromValue = d->fromWidth;
- a.property = QDeclarativeProperty(d->target, QLatin1String("width"));
- extra << a;
-
- a.fromValue = d->fromHeight;
- a.property = QDeclarativeProperty(d->target, QLatin1String("height"));
- extra << a;
+ if (d->fromX != d->toX) {
+ a.property = QDeclarativeProperty(d->target, QLatin1String("x"));
+ a.toValue = d->toX;
+ extra << a;
+ }
+ if (d->fromY != d->toY) {
+ a.property = QDeclarativeProperty(d->target, QLatin1String("y"));
+ a.toValue = d->toY;
+ extra << a;
+ }
+ if (d->fromWidth != d->toWidth) {
+ a.property = QDeclarativeProperty(d->target, QLatin1String("width"));
+ a.toValue = d->toWidth;
+ extra << a;
+ }
+ if (d->fromHeight != d->toHeight) {
+ a.property = QDeclarativeProperty(d->target, QLatin1String("height"));
+ a.toValue = d->toHeight;
+ extra << a;
+ }
}
return extra;
@@ -861,10 +943,52 @@ void QDeclarativeAnchorChanges::saveOriginals()
d->origVCenter = d->target->anchors()->verticalCenter();
d->origBaseline = d->target->anchors()->baseline();
+ d->applyOrigLeft = d->applyOrigRight = d->applyOrigHCenter = d->applyOrigTop
+ = d->applyOrigBottom = d->applyOrigHCenter = d->applyOrigBaseline = false;
+
+ saveCurrentValues();
+}
+
+void QDeclarativeAnchorChanges::copyOriginals(QDeclarativeActionEvent *other)
+{
+ Q_D(QDeclarativeAnchorChanges);
+ QDeclarativeAnchorChanges *ac = static_cast<QDeclarativeAnchorChanges*>(other);
+ QDeclarativeAnchorChangesPrivate *acp = ac->d_func();
+
+ //probably also need to revert some things
+ d->applyOrigLeft = (acp->left.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->resetList.contains(QLatin1String("left")));
+
+ d->applyOrigRight = (acp->right.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->resetList.contains(QLatin1String("right")));
+
+ d->applyOrigHCenter = (acp->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->resetList.contains(QLatin1String("horizontalCenter")));
+
+ d->applyOrigTop = (acp->top.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->resetList.contains(QLatin1String("top")));
+
+ d->applyOrigBottom = (acp->bottom.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->resetList.contains(QLatin1String("bottom")));
+
+ d->applyOrigVCenter = (acp->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->resetList.contains(QLatin1String("verticalCenter")));
+
+ d->applyOrigBaseline = (acp->baseline.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->resetList.contains(QLatin1String("baseline")));
+
+ d->origLeft = ac->d_func()->origLeft;
+ d->origRight = ac->d_func()->origRight;
+ d->origHCenter = ac->d_func()->origHCenter;
+ d->origTop = ac->d_func()->origTop;
+ d->origBottom = ac->d_func()->origBottom;
+ d->origVCenter = ac->d_func()->origVCenter;
+ d->origBaseline = ac->d_func()->origBaseline;
+
saveCurrentValues();
}
-void QDeclarativeAnchorChanges::clearForwardBindings()
+void QDeclarativeAnchorChanges::clearBindings()
{
Q_D(QDeclarativeAnchorChanges);
d->fromX = d->target->x();
@@ -872,6 +996,22 @@ void QDeclarativeAnchorChanges::clearForwardBindings()
d->fromWidth = d->target->width();
d->fromHeight = d->target->height();
+ //reset any anchors with corresponding reverts
+ if (d->applyOrigLeft)
+ d->target->anchors()->resetLeft();
+ if (d->applyOrigRight)
+ d->target->anchors()->resetRight();
+ if (d->applyOrigHCenter)
+ d->target->anchors()->resetHorizontalCenter();
+ if (d->applyOrigTop)
+ d->target->anchors()->resetTop();
+ if (d->applyOrigBottom)
+ d->target->anchors()->resetBottom();
+ if (d->applyOrigVCenter)
+ d->target->anchors()->resetVerticalCenter();
+ if (d->applyOrigBaseline)
+ d->target->anchors()->resetBaseline();
+
//reset any anchors that have been specified
if (d->resetList.contains(QLatin1String("left")))
d->target->anchors()->resetLeft();
@@ -905,47 +1045,6 @@ void QDeclarativeAnchorChanges::clearForwardBindings()
d->target->anchors()->resetBaseline();
}
-void QDeclarativeAnchorChanges::clearReverseBindings()
-{
- Q_D(QDeclarativeAnchorChanges);
- d->fromX = d->target->x();
- d->fromY = d->target->y();
- d->fromWidth = d->target->width();
- d->fromHeight = d->target->height();
-
- //reset any anchors that were set in the state
- if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetLeft();
- if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetRight();
- if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetHorizontalCenter();
- if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetTop();
- if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetBottom();
- if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetVerticalCenter();
- if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetBaseline();
-
- //reset any anchors that were set in the original state
- if (d->origLeft.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetLeft();
- if (d->origRight.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetRight();
- if (d->origHCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetHorizontalCenter();
- if (d->origTop.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetTop();
- if (d->origBottom.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetBottom();
- if (d->origVCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetVerticalCenter();
- if (d->origBaseline.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->resetBaseline();
-}
-
bool QDeclarativeAnchorChanges::override(QDeclarativeActionEvent*other)
{
if (other->typeName() != QLatin1String("AnchorChanges"))
@@ -978,6 +1077,11 @@ void QDeclarativeAnchorChanges::rewind()
d->target->anchors()->setVerticalCenter(d->rewindVCenter);
if (d->rewindBaseline.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->setBaseline(d->rewindBaseline);
+
+ d->target->setX(d->rewindX);
+ d->target->setY(d->rewindY);
+ d->target->setWidth(d->rewindWidth);
+ d->target->setHeight(d->rewindHeight);
}
void QDeclarativeAnchorChanges::saveCurrentValues()
@@ -990,6 +1094,20 @@ void QDeclarativeAnchorChanges::saveCurrentValues()
d->rewindBottom = d->target->anchors()->bottom();
d->rewindVCenter = d->target->anchors()->verticalCenter();
d->rewindBaseline = d->target->anchors()->baseline();
+
+ d->rewindX = d->target->x();
+ d->rewindY = d->target->y();
+ d->rewindWidth = d->target->width();
+ d->rewindHeight = d->target->height();
+}
+
+void QDeclarativeAnchorChanges::saveTargetValues()
+{
+ Q_D(QDeclarativeAnchorChanges);
+ d->toX = d->target->x();
+ d->toY = d->target->y();
+ d->toWidth = d->target->width();
+ d->toHeight = d->target->height();
}
#include <qdeclarativestateoperations.moc>
diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h
index dd4248023..66a8717 100644
--- a/src/declarative/util/qdeclarativestateoperations_p.h
+++ b/src/declarative/util/qdeclarativestateoperations_p.h
@@ -107,6 +107,7 @@ public:
virtual ActionList actions();
virtual void saveOriginals();
+ virtual void copyOriginals(QDeclarativeActionEvent*);
virtual void execute();
virtual bool isReversable();
virtual void reverse();
@@ -196,13 +197,15 @@ public:
virtual void reverse();
virtual QString typeName() const;
virtual bool override(QDeclarativeActionEvent*other);
- virtual QList<QDeclarativeAction> extraActions();
virtual bool changesBindings();
virtual void saveOriginals();
- virtual void clearForwardBindings();
- virtual void clearReverseBindings();
+ virtual void copyOriginals(QDeclarativeActionEvent*);
+ virtual void clearBindings();
virtual void rewind();
virtual void saveCurrentValues();
+
+ QList<QDeclarativeAction> additionalActions();
+ virtual void saveTargetValues();
};
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativetransitionmanager.cpp b/src/declarative/util/qdeclarativetransitionmanager.cpp
index e1143fa..f07fb23 100644
--- a/src/declarative/util/qdeclarativetransitionmanager.cpp
+++ b/src/declarative/util/qdeclarativetransitionmanager.cpp
@@ -126,10 +126,7 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> &
QDeclarativePropertyPrivate::setBinding(action.property, 0); // Disable current binding
if (action.event && action.event->changesBindings()) { //### assume isReversable()?
d->bindingsList << action;
- if (action.reverseEvent)
- action.event->clearReverseBindings();
- else
- action.event->clearForwardBindings();
+ action.event->clearBindings();
}
}
@@ -144,8 +141,6 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> &
if (!d->bindingsList.isEmpty()) {
- //### do extra actions here?
-
// Apply all the property and binding changes
for (int ii = 0; ii < applyList.size(); ++ii) {
const QDeclarativeAction &action = applyList.at(ii);
@@ -158,17 +153,18 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> &
action.event->reverse();
else
action.event->execute();
- applyList << action.event->extraActions();
}
}
// Read all the end values for binding changes
for (int ii = 0; ii < applyList.size(); ++ii) {
QDeclarativeAction *action = &applyList[ii];
- if (action->event)
+ if (action->event) {
+ action->event->saveTargetValues();
continue;
+ }
const QDeclarativeProperty &prop = action->property;
- if (action->toBinding || !action->toValue.isValid()) { //### is this always right (used for exta actions)
+ if (action->toBinding || !action->toValue.isValid()) {
action->toValue = prop.read();
}
}
@@ -177,15 +173,9 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> &
foreach(const QDeclarativeAction &action, applyList) {
if (action.event) {
if (action.event->isReversable()) {
- if (action.reverseEvent) { //reverse the reverse
- action.event->clearForwardBindings();
- action.event->rewind();
- action.event->clearReverseBindings();
- } else {
- action.event->clearReverseBindings();
- action.event->rewind();
- action.event->clearForwardBindings();
- }
+ action.event->clearBindings();
+ action.event->rewind();
+ action.event->clearBindings();
}
continue;
}
diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp
index 65bfdc1..4d4678a 100644
--- a/src/declarative/util/qdeclarativeutilmodule.cpp
+++ b/src/declarative/util/qdeclarativeutilmodule.cpp
@@ -75,44 +75,48 @@
void QDeclarativeUtilModule::defineModule()
{
- QML_REGISTER_TYPE(Qt,4,6,AnchorChanges,QDeclarativeAnchorChanges);
- QML_REGISTER_TYPE(Qt,4,6,Behavior,QDeclarativeBehavior);
- QML_REGISTER_TYPE(Qt,4,6,Binding,QDeclarativeBind);
- QML_REGISTER_TYPE(Qt,4,6,ColorAnimation,QDeclarativeColorAnimation);
- QML_REGISTER_TYPE(Qt,4,6,Connections,QDeclarativeConnections);
- QML_REGISTER_TYPE(Qt,4,6,EaseFollow,QDeclarativeEaseFollow);;
- QML_REGISTER_TYPE(Qt,4,6,FontLoader,QDeclarativeFontLoader);
- QML_REGISTER_TYPE(Qt,4,6,ListElement,QDeclarativeListElement);
- QML_REGISTER_TYPE(Qt,4,6,NumberAnimation,QDeclarativeNumberAnimation);
- QML_REGISTER_TYPE(Qt,4,6,Package,QDeclarativePackage);
- QML_REGISTER_TYPE(Qt,4,6,ParallelAnimation,QDeclarativeParallelAnimation);
- QML_REGISTER_TYPE(Qt,4,6,ParentAction,QDeclarativeParentAction);
- QML_REGISTER_TYPE(Qt,4,6,ParentAnimation,QDeclarativeParentAnimation);
- QML_REGISTER_TYPE(Qt,4,6,ParentChange,QDeclarativeParentChange);
- QML_REGISTER_TYPE(Qt,4,6,PauseAnimation,QDeclarativePauseAnimation);
- QML_REGISTER_TYPE(Qt,4,6,PropertyAction,QDeclarativePropertyAction);
- QML_REGISTER_TYPE(Qt,4,6,PropertyAnimation,QDeclarativePropertyAnimation);
- QML_REGISTER_TYPE(Qt,4,6,RotationAnimation,QDeclarativeRotationAnimation);
- QML_REGISTER_TYPE(Qt,4,6,ScriptAction,QDeclarativeScriptAction);
- QML_REGISTER_TYPE(Qt,4,6,SequentialAnimation,QDeclarativeSequentialAnimation);
- QML_REGISTER_TYPE(Qt,4,6,SpringFollow,QDeclarativeSpringFollow);
- QML_REGISTER_TYPE(Qt,4,6,StateChangeScript,QDeclarativeStateChangeScript);
- QML_REGISTER_TYPE(Qt,4,6,StateGroup,QDeclarativeStateGroup);
- QML_REGISTER_TYPE(Qt,4,6,State,QDeclarativeState);
- QML_REGISTER_TYPE(Qt,4,6,SystemPalette,QDeclarativeSystemPalette);
- QML_REGISTER_TYPE(Qt,4,6,Timer,QDeclarativeTimer);
- QML_REGISTER_TYPE(Qt,4,6,Transition,QDeclarativeTransition);
- QML_REGISTER_TYPE(Qt,4,6,Vector3dAnimation,QDeclarativeVector3dAnimation);
+ qmlRegisterType<QDeclarativeAnchorAnimation>("Qt",4,6,"AnchorAnimation");
+ qmlRegisterType<QDeclarativeAnchorChanges>("Qt",4,6,"AnchorChanges");
+ qmlRegisterType<QDeclarativeBehavior>("Qt",4,6,"Behavior");
+ qmlRegisterType<QDeclarativeBind>("Qt",4,6,"Binding");
+ qmlRegisterType<QDeclarativeColorAnimation>("Qt",4,6,"ColorAnimation");
+ qmlRegisterType<QDeclarativeConnections>("Qt",4,6,"Connections");
+ qmlRegisterType<QDeclarativeEaseFollow>("Qt",4,6,"EaseFollow");
+ qmlRegisterType<QDeclarativeFontLoader>("Qt",4,6,"FontLoader");
+ qmlRegisterType<QDeclarativeListElement>("Qt",4,6,"ListElement");
+ qmlRegisterType<QDeclarativeNumberAnimation>("Qt",4,6,"NumberAnimation");
+ qmlRegisterType<QDeclarativePackage>("Qt",4,6,"Package");
+ qmlRegisterType<QDeclarativeParallelAnimation>("Qt",4,6,"ParallelAnimation");
+ qmlRegisterType<QDeclarativeParentAction>("Qt",4,6,"ParentAction");
+ qmlRegisterType<QDeclarativeParentAnimation>("Qt",4,6,"ParentAnimation");
+ qmlRegisterType<QDeclarativeParentChange>("Qt",4,6,"ParentChange");
+ qmlRegisterType<QDeclarativePauseAnimation>("Qt",4,6,"PauseAnimation");
+ qmlRegisterType<QDeclarativePropertyAction>("Qt",4,6,"PropertyAction");
+ qmlRegisterType<QDeclarativePropertyAnimation>("Qt",4,6,"PropertyAnimation");
+ qmlRegisterType<QDeclarativeRotationAnimation>("Qt",4,6,"RotationAnimation");
+ qmlRegisterType<QDeclarativeScriptAction>("Qt",4,6,"ScriptAction");
+ qmlRegisterType<QDeclarativeSequentialAnimation>("Qt",4,6,"SequentialAnimation");
+ qmlRegisterType<QDeclarativeSpringFollow>("Qt",4,6,"SpringFollow");
+ qmlRegisterType<QDeclarativeStateChangeScript>("Qt",4,6,"StateChangeScript");
+ qmlRegisterType<QDeclarativeStateGroup>("Qt",4,6,"StateGroup");
+ qmlRegisterType<QDeclarativeState>("Qt",4,6,"State");
+ qmlRegisterType<QDeclarativeSystemPalette>("Qt",4,6,"SystemPalette");
+ qmlRegisterType<QDeclarativeTimer>("Qt",4,6,"Timer");
+ qmlRegisterType<QDeclarativeTransition>("Qt",4,6,"Transition");
+ qmlRegisterType<QDeclarativeVector3dAnimation>("Qt",4,6,"Vector3dAnimation");
#ifndef QT_NO_XMLPATTERNS
- QML_REGISTER_TYPE(Qt,4,6,XmlListModel,QDeclarativeXmlListModel);
- QML_REGISTER_TYPE(Qt,4,6,XmlRole,QDeclarativeXmlListModelRole);
+ qmlRegisterType<QDeclarativeXmlListModel>("Qt",4,6,"XmlListModel");
+ qmlRegisterType<QDeclarativeXmlListModelRole>("Qt",4,6,"XmlRole");
#endif
- QML_REGISTER_NOCREATE_TYPE(QDeclarativeAnchors);
- QML_REGISTER_NOCREATE_TYPE(QDeclarativeAbstractAnimation);
- QML_REGISTER_NOCREATE_TYPE(QDeclarativeStateOperation);
+ qmlRegisterType<QDeclarativeAnchors>();
+ qmlRegisterType<QDeclarativeAbstractAnimation>();
+ qmlRegisterType<QDeclarativeStateOperation>();
- QML_REGISTER_CUSTOM_TYPE(Qt, 4,6, ListModel, QDeclarativeListModel, QDeclarativeListModelParser);
- QML_REGISTER_CUSTOM_TYPE(Qt, 4,6, PropertyChanges, QDeclarativePropertyChanges, QDeclarativePropertyChangesParser);
- QML_REGISTER_CUSTOM_TYPE(Qt, 4,6, Connections, QDeclarativeConnections, QDeclarativeConnectionsParser);
+ qmlRegisterCustomType<QDeclarativeListModel>("Qt", 4,6, "ListModel", "QDeclarativeListModel",
+ new QDeclarativeListModelParser);
+ qmlRegisterCustomType<QDeclarativePropertyChanges>("Qt", 4, 6, "PropertyChanges", "QDeclarativePropertyChanges",
+ new QDeclarativePropertyChangesParser);
+ qmlRegisterCustomType<QDeclarativeConnections>("Qt", 4, 6, "Connections", "QDeclarativeConnections",
+ new QDeclarativeConnectionsParser);
}
diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp
index cd67aeb..486553a 100644
--- a/src/declarative/util/qdeclarativeview.cpp
+++ b/src/declarative/util/qdeclarativeview.cpp
@@ -221,7 +221,7 @@ void QDeclarativeViewPrivate::execute()
*/
/*! \fn void QDeclarativeView::statusChanged(QDeclarativeView::Status status)
- This signal is emitted when the component's current \l{QDeclarativeView::Status} {status} changes.
+ This signal is emitted when the component's current \a status changes.
*/
/*!
@@ -283,6 +283,12 @@ QDeclarativeView::~QDeclarativeView()
delete d->root;
}
+/*! \property QDeclarativeView::source
+ \brief The URL of the source of the QML component.
+
+ Changing this property causes the QML component to be reloaded.
+ */
+
/*!
Sets the source to the \a url, loads the QML component and instantiates it.
@@ -326,7 +332,6 @@ QDeclarativeContext* QDeclarativeView::rootContext()
return d->engine.rootContext();
}
-
/*!
\enum QDeclarativeView::Status
@@ -338,6 +343,14 @@ QDeclarativeContext* QDeclarativeView::rootContext()
\value Error An error has occured. Calling errorDescription() to retrieve a description.
*/
+/*! \enum QDeclarativeView::ResizeMode
+
+ This enum specifies how to resize the view.
+
+ \value SizeViewToRootObject
+ \value SizeRootObjectToView
+*/
+
/*!
\property QDeclarativeView::status
The component's current \l{QDeclarativeView::Status} {status}.
@@ -376,8 +389,6 @@ QList<QDeclarativeError> QDeclarativeView::errors() const
Regardless of this property, the sizeHint of the view
is the initial size of the root item. Note though that
since QML may load dynamically, that size may change.
-
- \sa initialSize()
*/
void QDeclarativeView::setResizeMode(ResizeMode mode)
@@ -447,8 +458,8 @@ void QDeclarativeView::setRootObject(QObject *obj)
QPerformanceLog::clear();
d->root = item;
d->qmlRoot = item;
- connect(item, SIGNAL(widthChanged()), this, SLOT(sizeChanged()));
- connect(item, SIGNAL(heightChanged()), this, SLOT(sizeChanged()));
+ connect(item, SIGNAL(widthChanged(qreal)), this, SLOT(sizeChanged()));
+ connect(item, SIGNAL(heightChanged(qreal)), this, SLOT(sizeChanged()));
if (d->initialSize.height() <= 0 && d->qmlRoot->width() > 0)
d->initialSize.setWidth(d->qmlRoot->width());
if (d->initialSize.height() <= 0 && d->qmlRoot->height() > 0)
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index 49dbb27..01ae2ed 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -61,6 +61,9 @@
QT_BEGIN_NAMESPACE
+
+
+
typedef QPair<int, int> QDeclarativeXmlListRange;
/*!
@@ -111,6 +114,9 @@ class QDeclarativeXmlQuery : public QThread
{
Q_OBJECT
public:
+ QDeclarativeXmlQuery(QObject *parent=0)
+ : QThread(parent), m_quit(false), m_restart(false), m_abort(false), m_queryId(0) {
+ }
~QDeclarativeXmlQuery() {
m_mutex.lock();
m_quit = true;
@@ -120,11 +126,6 @@ public:
wait();
}
- static QDeclarativeXmlQuery *instance() {
- static QDeclarativeXmlQuery *query = new QDeclarativeXmlQuery;
- return query;
- }
-
void abort() {
QMutexLocker locker(&m_mutex);
m_abort = true;
@@ -163,11 +164,6 @@ public:
return m_removedItemRanges;
}
-private:
- QDeclarativeXmlQuery(QObject *parent=0)
- : QThread(parent), m_quit(false), m_restart(false), m_abort(false), m_queryId(0) {
- }
-
Q_SIGNALS:
void queryCompleted(int queryId, int size);
@@ -217,8 +213,6 @@ private:
QList<QDeclarativeXmlListRange> m_removedItemRanges;
};
-//Q_GLOBAL_STATIC(QDeclarativeXmlQuery, QDeclarativeXmlQuery::instance());
-
void QDeclarativeXmlQuery::doQueryJob()
{
QString r;
@@ -396,7 +390,7 @@ public:
QDeclarativeXmlListModelPrivate()
: isComponentComplete(true), size(-1), highestRole(Qt::UserRole)
, reply(0), status(QDeclarativeXmlListModel::Null), progress(0.0)
- , queryId(-1), roleObjects() {}
+ , queryId(-1), roleObjects(), redirectCount(0) {}
bool isComponentComplete;
QUrl src;
@@ -410,6 +404,7 @@ public:
QNetworkReply *reply;
QDeclarativeXmlListModel::Status status;
qreal progress;
+ QDeclarativeXmlQuery qmlXmlQuery;
int queryId;
QList<QDeclarativeXmlListModelRole *> roleObjects;
static void append_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list, QDeclarativeXmlListModelRole *role);
@@ -417,6 +412,7 @@ public:
static void removeAt_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list, int i);
static void insert_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list, int i, QDeclarativeXmlListModelRole *role);
QList<QList<QVariant> > data;
+ int redirectCount;
};
@@ -493,7 +489,8 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla
QDeclarativeXmlListModel::QDeclarativeXmlListModel(QObject *parent)
: QListModelInterface(*(new QDeclarativeXmlListModelPrivate), parent)
{
- connect(QDeclarativeXmlQuery::instance(), SIGNAL(queryCompleted(int,int)),
+ Q_D(QDeclarativeXmlListModel);
+ connect(&d->qmlXmlQuery, SIGNAL(queryCompleted(int,int)),
this, SLOT(queryCompleted(int,int)));
}
@@ -575,8 +572,8 @@ void QDeclarativeXmlListModel::setSource(const QUrl &src)
{
Q_D(QDeclarativeXmlListModel);
if (d->src != src) {
- reload();
d->src = src;
+ reload();
emit sourceChanged();
}
}
@@ -726,7 +723,7 @@ void QDeclarativeXmlListModel::reload()
if (!d->isComponentComplete)
return;
- QDeclarativeXmlQuery::instance()->abort();
+ d->qmlXmlQuery.abort();
d->queryId = -1;
int count = d->size;
@@ -758,7 +755,7 @@ void QDeclarativeXmlListModel::reload()
}
if (!d->xml.isEmpty()) {
- d->queryId = QDeclarativeXmlQuery::instance()->doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects);
+ d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects);
d->progress = 1.0;
d->status = Ready;
emit progressChanged(d->progress);
@@ -778,9 +775,25 @@ void QDeclarativeXmlListModel::reload()
this, SLOT(requestProgress(qint64,qint64)));
}
+#define XMLLISTMODEL_MAX_REDIRECT 16
+
void QDeclarativeXmlListModel::requestFinished()
{
Q_D(QDeclarativeXmlListModel);
+
+ d->redirectCount++;
+ if (d->redirectCount < XMLLISTMODEL_MAX_REDIRECT) {
+ QVariant redirect = d->reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirect.isValid()) {
+ QUrl url = d->reply->url().resolved(redirect.toUrl());
+ d->reply->deleteLater();
+ d->reply = 0;
+ setSource(url);
+ return;
+ }
+ }
+ d->redirectCount = 0;
+
if (d->reply->error() != QNetworkReply::NoError) {
disconnect(d->reply, 0, this, 0);
d->reply->deleteLater();
@@ -789,7 +802,7 @@ void QDeclarativeXmlListModel::requestFinished()
} else {
d->status = Ready;
QByteArray data = d->reply->readAll();
- d->queryId = QDeclarativeXmlQuery::instance()->doQuery(d->query, d->namespaces, data, &d->roleObjects);
+ d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, data, &d->roleObjects);
disconnect(d->reply, 0, this, 0);
d->reply->deleteLater();
d->reply = 0;
@@ -815,10 +828,10 @@ void QDeclarativeXmlListModel::queryCompleted(int id, int size)
return;
bool sizeChanged = size != d->size;
d->size = size;
- d->data = QDeclarativeXmlQuery::instance()->modelData();
+ d->data = d->qmlXmlQuery.modelData();
- QList<QDeclarativeXmlListRange> removed = QDeclarativeXmlQuery::instance()->removedItemRanges();
- QList<QDeclarativeXmlListRange> inserted = QDeclarativeXmlQuery::instance()->insertedItemRanges();
+ QList<QDeclarativeXmlListRange> removed = d->qmlXmlQuery.removedItemRanges();
+ QList<QDeclarativeXmlListRange> inserted = d->qmlXmlQuery.insertedItemRanges();
for (int i=0; i<removed.count(); i++)
emit itemsRemoved(removed[i].first, removed[i].second);