summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/QmlChanges.txt4
-rw-r--r--src/declarative/debugger/qdeclarativedebug.cpp14
-rw-r--r--src/declarative/debugger/qdeclarativedebug_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp4
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflipable.cpp23
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflipable_p.h12
-rw-r--r--src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp10
-rw-r--r--src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp62
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp188
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.h8
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem_p.h31
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp66
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader.cpp13
-rw-r--r--src/declarative/graphicsitems/qdeclarativepainteditem.cpp4
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp641
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p.h25
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p_p.h25
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativerectangle.cpp2
-rw-r--r--src/declarative/qml/qdeclarativecompiledbindings.cpp88
-rw-r--r--src/declarative/qml/qdeclarativecompiledbindings_p.h2
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp3
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp31
-rw-r--r--src/declarative/qml/qdeclarativecontext.h2
-rw-r--r--src/declarative/qml/qdeclarativecontext_p.h12
-rw-r--r--src/declarative/qml/qdeclarativedom.cpp6
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp1
-rw-r--r--src/declarative/qml/qdeclarativeenginedebug.cpp15
-rw-r--r--src/declarative/qml/qdeclarativeenginedebug_p.h1
-rw-r--r--src/declarative/qml/qdeclarativeintegercache.cpp10
-rw-r--r--src/declarative/qml/qdeclarativeintegercache_p.h1
-rw-r--r--src/declarative/qml/qdeclarativelist.h4
-rw-r--r--src/declarative/qml/qdeclarativemetatype_p.h2
-rw-r--r--src/declarative/qml/qml.pri2
-rw-r--r--src/declarative/util/qdeclarativeanimation.cpp103
-rw-r--r--src/declarative/util/qdeclarativeanimation_p.h14
-rw-r--r--src/declarative/util/qdeclarativeanimation_p_p.h11
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp18
-rw-r--r--src/declarative/util/qdeclarativespringfollow.cpp6
-rw-r--r--src/declarative/util/qdeclarativestateoperations.cpp500
-rw-r--r--src/declarative/util/qdeclarativestateoperations_p.h123
-rw-r--r--src/declarative/util/qdeclarativeutilmodule.cpp36
-rw-r--r--src/declarative/util/qdeclarativeview.cpp7
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp191
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel_p.h15
49 files changed, 1471 insertions, 878 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt
index 1d96688..9a55bde 100644
--- a/src/declarative/QmlChanges.txt
+++ b/src/declarative/QmlChanges.txt
@@ -11,6 +11,10 @@ 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)
Removed ParentAction (use ParentAnimation instead)
+ScriptAction: renamed stateChangeScriptName -> scriptName
+Animation: replace repeat with loops (loops: Animation.Infinite gives the old repeat behavior)
+AnchorChanges: use natural form to specify anchors (anchors.left instead of left)
+AnchorChanges: removed reset property. (reset: "left" should now be anchors.left: undefined)
C++ API
-------
diff --git a/src/declarative/debugger/qdeclarativedebug.cpp b/src/declarative/debugger/qdeclarativedebug.cpp
index e4b7d4d..677d05f 100644
--- a/src/declarative/debugger/qdeclarativedebug.cpp
+++ b/src/declarative/debugger/qdeclarativedebug.cpp
@@ -151,6 +151,7 @@ void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugOb
ds >> data;
o.m_debugId = data.objectId;
o.m_class = data.objectType;
+ o.m_idString = data.idString;
o.m_name = data.objectName;
o.m_source.m_url = data.url;
o.m_source.m_lineNumber = data.lineNumber;
@@ -750,8 +751,8 @@ QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(int debugId)
}
QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(const QDeclarativeDebugObjectReference &o)
-: m_debugId(o.m_debugId), m_class(o.m_class), m_name(o.m_name),
- m_source(o.m_source), m_contextDebugId(o.m_contextDebugId),
+: m_debugId(o.m_debugId), m_class(o.m_class), m_idString(o.m_idString),
+ m_name(o.m_name), m_source(o.m_source), m_contextDebugId(o.m_contextDebugId),
m_properties(o.m_properties), m_children(o.m_children)
{
}
@@ -759,8 +760,8 @@ QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(const QDeclar
QDeclarativeDebugObjectReference &
QDeclarativeDebugObjectReference::operator=(const QDeclarativeDebugObjectReference &o)
{
- m_debugId = o.m_debugId; m_class = o.m_class; m_name = o.m_name;
- m_source = o.m_source; m_contextDebugId = o.m_contextDebugId;
+ m_debugId = o.m_debugId; m_class = o.m_class; m_idString = o.m_idString;
+ m_name = o.m_name; m_source = o.m_source; m_contextDebugId = o.m_contextDebugId;
m_properties = o.m_properties; m_children = o.m_children;
return *this;
}
@@ -775,6 +776,11 @@ QString QDeclarativeDebugObjectReference::className() const
return m_class;
}
+QString QDeclarativeDebugObjectReference::idString() const
+{
+ return m_idString;
+}
+
QString QDeclarativeDebugObjectReference::name() const
{
return m_name;
diff --git a/src/declarative/debugger/qdeclarativedebug_p.h b/src/declarative/debugger/qdeclarativedebug_p.h
index f0c7a77..4ead232 100644
--- a/src/declarative/debugger/qdeclarativedebug_p.h
+++ b/src/declarative/debugger/qdeclarativedebug_p.h
@@ -230,6 +230,7 @@ public:
int debugId() const;
QString className() const;
+ QString idString() const;
QString name() const;
QDeclarativeDebugFileReference source() const;
@@ -242,6 +243,7 @@ private:
friend class QDeclarativeEngineDebugPrivate;
int m_debugId;
QString m_class;
+ QString m_idString;
QString m_name;
QDeclarativeDebugFileReference m_source;
int m_contextDebugId;
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
index a7534b8..f92c207 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
@@ -444,7 +444,7 @@ void QDeclarativeBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem
const QDeclarativeScaleGrid *border = d->getScaleGrid();
QMargins margins(border->left(), border->top(), border->right(), border->bottom());
QTileRules rules((Qt::TileRule)d->horizontalTileMode, (Qt::TileRule)d->verticalTileMode);
- qDrawBorderPixmap(p, QRect(0, 0, (int)d->width, (int)d->height), margins, d->pix, d->pix.rect(), margins, rules);
+ qDrawBorderPixmap(p, QRect(0, 0, (int)d->width(), (int)d->height()), margins, d->pix, d->pix.rect(), margins, rules);
if (d->smooth) {
p->setRenderHint(QPainter::Antialiasing, oldAA);
p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth);
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index 9ccb3b6..98502fd 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -990,10 +990,10 @@ QDeclarativeListProperty<QObject> QDeclarativeFlickable::flickableData()
return QDeclarativeListProperty<QObject>(this, (void *)d, QDeclarativeFlickablePrivate::data_append);
}
-QDeclarativeListProperty<QDeclarativeItem> QDeclarativeFlickable::flickableChildren()
+QDeclarativeListProperty<QGraphicsObject> QDeclarativeFlickable::flickableChildren()
{
Q_D(QDeclarativeFlickable);
- return d->viewport->fxChildren();
+ return QGraphicsItemPrivate::get(d->viewport)->childrenList();
}
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h
index 7dcab98..1fa2c74 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h
@@ -82,7 +82,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem
Q_PROPERTY(QDeclarativeFlickableVisibleArea *visibleArea READ visibleArea CONSTANT)
Q_PROPERTY(QDeclarativeListProperty<QObject> flickableData READ flickableData)
- Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> flickableChildren READ flickableChildren)
+ Q_PROPERTY(QDeclarativeListProperty<QGraphicsObject> flickableChildren READ flickableChildren)
Q_CLASSINFO("DefaultProperty", "flickableData")
Q_ENUMS(FlickDirection)
@@ -92,7 +92,7 @@ public:
~QDeclarativeFlickable();
QDeclarativeListProperty<QObject> flickableData();
- QDeclarativeListProperty<QDeclarativeItem> flickableChildren();
+ QDeclarativeListProperty<QGraphicsObject> flickableChildren();
bool overShoot() const;
void setOverShoot(bool);
diff --git a/src/declarative/graphicsitems/qdeclarativeflipable.cpp b/src/declarative/graphicsitems/qdeclarativeflipable.cpp
index 8b46039..cb4044f 100644
--- a/src/declarative/graphicsitems/qdeclarativeflipable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflipable.cpp
@@ -59,8 +59,8 @@ public:
void updateSceneTransformFromParent();
QDeclarativeFlipable::Side current;
- QDeclarativeGuard<QDeclarativeItem> front;
- QDeclarativeGuard<QDeclarativeItem> back;
+ QDeclarativeGuard<QGraphicsObject> front;
+ QDeclarativeGuard<QGraphicsObject> back;
};
/*!
@@ -112,13 +112,13 @@ QDeclarativeFlipable::~QDeclarativeFlipable()
The front and back sides of the flipable.
*/
-QDeclarativeItem *QDeclarativeFlipable::front()
+QGraphicsObject *QDeclarativeFlipable::front()
{
Q_D(const QDeclarativeFlipable);
return d->front;
}
-void QDeclarativeFlipable::setFront(QDeclarativeItem *front)
+void QDeclarativeFlipable::setFront(QGraphicsObject *front)
{
Q_D(QDeclarativeFlipable);
if (d->front) {
@@ -131,13 +131,13 @@ void QDeclarativeFlipable::setFront(QDeclarativeItem *front)
d->front->setOpacity(0.);
}
-QDeclarativeItem *QDeclarativeFlipable::back()
+QGraphicsObject *QDeclarativeFlipable::back()
{
Q_D(const QDeclarativeFlipable);
return d->back;
}
-void QDeclarativeFlipable::setBack(QDeclarativeItem *back)
+void QDeclarativeFlipable::setBack(QGraphicsObject *back)
{
Q_D(QDeclarativeFlipable);
if (d->back) {
@@ -160,7 +160,7 @@ QDeclarativeFlipable::Side QDeclarativeFlipable::side() const
{
Q_D(const QDeclarativeFlipable);
if (d->dirtySceneTransform)
- const_cast<QDeclarativeFlipablePrivate *>(d)->updateSceneTransformFromParent();
+ const_cast<QDeclarativeFlipablePrivate *>(d)->ensureSceneTransform();
return d->current;
}
@@ -195,12 +195,13 @@ void QDeclarativeFlipablePrivate::updateSceneTransformFromParent()
current = newSide;
if (current == QDeclarativeFlipable::Back && back) {
QTransform mat;
- mat.translate(back->width()/2,back->height()/2);
- if (back->width() && p1.x() >= p2.x())
+ QGraphicsItemPrivate *dBack = QGraphicsItemPrivate::get(back);
+ mat.translate(dBack->width()/2,dBack->height()/2);
+ if (dBack->width() && p1.x() >= p2.x())
mat.rotate(180, Qt::YAxis);
- if (back->height() && p2.y() >= p3.y())
+ if (dBack->height() && p2.y() >= p3.y())
mat.rotate(180, Qt::XAxis);
- mat.translate(-back->width()/2,-back->height()/2);
+ mat.translate(-dBack->width()/2,-dBack->height()/2);
back->setTransform(mat);
}
if (front)
diff --git a/src/declarative/graphicsitems/qdeclarativeflipable_p.h b/src/declarative/graphicsitems/qdeclarativeflipable_p.h
index 8b9c24c..302f083 100644
--- a/src/declarative/graphicsitems/qdeclarativeflipable_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeflipable_p.h
@@ -60,8 +60,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlipable : public QDeclarativeItem
Q_OBJECT
Q_ENUMS(Side)
- Q_PROPERTY(QDeclarativeItem *front READ front WRITE setFront)
- Q_PROPERTY(QDeclarativeItem *back READ back WRITE setBack)
+ Q_PROPERTY(QGraphicsObject *front READ front WRITE setFront)
+ Q_PROPERTY(QGraphicsObject *back READ back WRITE setBack)
Q_PROPERTY(Side side READ side NOTIFY sideChanged)
//### flipAxis
//### flipRotation
@@ -69,11 +69,11 @@ public:
QDeclarativeFlipable(QDeclarativeItem *parent=0);
~QDeclarativeFlipable();
- QDeclarativeItem *front();
- void setFront(QDeclarativeItem *);
+ QGraphicsObject *front();
+ void setFront(QGraphicsObject *);
- QDeclarativeItem *back();
- void setBack(QDeclarativeItem *);
+ QGraphicsObject *back();
+ void setBack(QGraphicsObject *);
enum Side { Front, Back };
Side side() const;
diff --git a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp
index eb5b6ce..ff85bbd 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(qreal)), q, SLOT(_q_updateSize()));
- QObject::disconnect(q, SIGNAL(heightChanged(qreal)), q, SLOT(_q_updateSize()));
+ QObject::disconnect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize()));
+ QObject::disconnect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize()));
} else {
graphicsObject->installEventFilter(q);
- QObject::connect(q, SIGNAL(widthChanged(qreal)), q, SLOT(_q_updateSize()));
- QObject::connect(q, SIGNAL(heightChanged(qreal)), q, SLOT(_q_updateSize()));
+ QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize()));
+ QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize()));
}
}
}
@@ -251,7 +251,7 @@ void QDeclarativeGraphicsObjectContainerPrivate::_q_updateSize()
return;
QGraphicsWidget *gw = static_cast<QGraphicsWidget*>(graphicsObject);
- const QSizeF newSize(width, height);
+ const QSizeF newSize(width(), height());
gw->resize(newSize);
//### will respecting the widgets min/max ever get us in trouble? (all other items always
diff --git a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h
index 95d7a4b..20c5bcf 100644
--- a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h
+++ b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h
@@ -82,7 +82,6 @@ private:
QT_END_NAMESPACE
-QML_DECLARE_TYPE(QGraphicsObject)
QML_DECLARE_TYPE(QDeclarativeGraphicsObjectContainer)
QT_END_HEADER
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 93f8d06..de0cb04 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -786,28 +786,32 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
QDeclarativeFlickablePrivate::flick(data, minExtent, maxExtent, vSize, fixupCallback, velocity);
return;
}
- qreal maxDistance = -1;
+ qreal maxDistance = 0;
// -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 (data.move.value() < minExtent) {
+ if (snapMode == QDeclarativeGridView::SnapOneRow) {
+ if (FxGridItem *item = firstVisibleItem())
+ maxDistance = qAbs(item->rowPos() + data.move.value());
+ } else {
+ 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 (data.move.value() > maxExtent) {
+ if (snapMode == QDeclarativeGridView::SnapOneRow) {
+ qreal pos = snapPosAt(-data.move.value()) + rowSize();
+ maxDistance = qAbs(pos + data.move.value());
+ } else {
+ 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)) {
+ if ((maxDistance > 0 || overShoot) && (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)) {
@@ -818,9 +822,8 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
}
qreal accel = deceleration;
qreal v2 = v * v;
- qreal maxAccel = v2 / (2.0f * maxDistance);
qreal overshootDist = 0.0;
- if (maxAccel < accel) {
+ if (maxDistance > 0.0 && v2 / (2.0f * maxDistance) < 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)
@@ -924,7 +927,7 @@ QDeclarativeGridView::~QDeclarativeGridView()
id: wrapper
SequentialAnimation on GridView.onRemove {
PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: true }
- NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" }
+ NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: "InOutQuad" }
PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: false }
}
}
@@ -1080,8 +1083,9 @@ void QDeclarativeGridView::setCurrentIndex(int index)
d->moveReason = QDeclarativeGridViewPrivate::SetIndex;
cancelFlick();
d->updateCurrent(index);
- } else {
+ } else if (index != d->currentIndex) {
d->currentIndex = index;
+ emit currentIndexChanged();
}
}
@@ -1504,10 +1508,12 @@ qreal QDeclarativeGridView::maxYExtent() const
if (d->flow == QDeclarativeGridView::TopToBottom)
return QDeclarativeFlickable::maxYExtent();
qreal extent;
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
extent = -(d->endPosition() - d->highlightRangeEnd);
- else
+ extent = qMax(extent, -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart));
+ } else {
extent = -(d->endPosition() - height());
+ }
const qreal minY = minYExtent();
if (extent > minY)
extent = minY;
@@ -1531,10 +1537,12 @@ qreal QDeclarativeGridView::maxXExtent() const
if (d->flow == QDeclarativeGridView::LeftToRight)
return QDeclarativeFlickable::maxXExtent();
qreal extent;
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
extent = -(d->endPosition() - d->highlightRangeEnd);
- else
+ extent = qMax(extent, -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart));
+ } else {
extent = -(d->endPosition() - height());
+ }
const qreal minX = minXExtent();
if (extent > minX)
extent = minX;
@@ -1838,9 +1846,17 @@ void QDeclarativeGridView::trackedPositionChanged()
void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
{
Q_D(QDeclarativeGridView);
+ if (!isComponentComplete())
+ return;
if (!d->visibleItems.count() || d->model->count() <= 1) {
d->scheduleLayout();
- d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1)));
+ if (d->currentIndex >= modelIndex) {
+ // adjust current item index
+ d->currentIndex += count;
+ if (d->currentItem)
+ d->currentItem->index = d->currentIndex;
+ emit currentIndexChanged();
+ }
emit countChanged();
return;
}
@@ -1964,6 +1980,8 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
void QDeclarativeGridView::itemsRemoved(int modelIndex, int count)
{
Q_D(QDeclarativeGridView);
+ if (!isComponentComplete())
+ return;
bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count;
bool removedVisible = false;
@@ -2054,6 +2072,8 @@ void QDeclarativeGridView::destroyRemoved()
void QDeclarativeGridView::itemsMoved(int from, int to, int count)
{
Q_D(QDeclarativeGridView);
+ if (!isComponentComplete())
+ return;
QHash<int,FxGridItem*> moved;
bool removedBeforeVisible = false;
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 9b1bdba..ee0682a 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -312,9 +312,9 @@ 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(qreal)), this, SLOT(calcHeight()));
+ connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight()));
connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight()));
- connect(child, SIGNAL(widthChanged(qreal)), this, SLOT(calcWidth()));
+ connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth()));
connect(child, SIGNAL(xChanged()), this, SLOT(calcWidth()));
connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF)));
}
@@ -1273,16 +1273,6 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec
*/
/*!
- \fn void QDeclarativeItem::widthChanged()
- \internal
-*/
-
-/*!
- \fn void QDeclarativeItem::heightChanged()
- \internal
-*/
-
-/*!
\fn void QDeclarativeItem::stateChanged(const QString &state)
\internal
*/
@@ -1462,11 +1452,6 @@ QDeclarativeItem *QDeclarativeItem::parentItem() const
*/
/*!
- \property QDeclarativeItem::children
- \internal
-*/
-
-/*!
\property QDeclarativeItem::resources
\internal
*/
@@ -1500,11 +1485,12 @@ QDeclarativeAnchors *QDeclarativeItem::anchors()
void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty<QObject> *prop, QObject *o)
{
- QDeclarativeItem *i = qobject_cast<QDeclarativeItem *>(o);
- if (i)
+ QGraphicsObject *i = qobject_cast<QGraphicsObject *>(o);
+ if (i) {
i->setParentItem(static_cast<QDeclarativeItem *>(prop->object));
- else
+ } else {
o->setParent(static_cast<QDeclarativeItem *>(prop->object));
+ }
}
QObject *QDeclarativeItemPrivate::resources_at(QDeclarativeListProperty<QObject> *prop, int index)
@@ -1526,27 +1512,6 @@ int QDeclarativeItemPrivate::resources_count(QDeclarativeListProperty<QObject> *
return prop->object->children().count();
}
-QDeclarativeItem *QDeclarativeItemPrivate::children_at(QDeclarativeListProperty<QDeclarativeItem> *prop, int index)
-{
- QList<QGraphicsItem *> children = static_cast<QDeclarativeItem*>(prop->object)->childItems();
-
- if (index < children.count())
- return qobject_cast<QDeclarativeItem *>(children.at(index));
- else
- return 0;
-}
-
-void QDeclarativeItemPrivate::children_append(QDeclarativeListProperty<QDeclarativeItem> *prop, QDeclarativeItem *i)
-{
- if (i)
- i->setParentItem(static_cast<QDeclarativeItem*>(prop->object));
-}
-
-int QDeclarativeItemPrivate::children_count(QDeclarativeListProperty<QDeclarativeItem> *prop)
-{
- return static_cast<QDeclarativeItem*>(prop->object)->childItems().count();
-}
-
int QDeclarativeItemPrivate::transform_count(QDeclarativeListProperty<QGraphicsTransform> *list)
{
QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
@@ -1589,6 +1554,14 @@ void QDeclarativeItemPrivate::transform_clear(QDeclarativeListProperty<QGraphics
}
}
+void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e)
+{
+ QDeclarativeItem *item = static_cast<QDeclarativeItem*>(o);
+ if (e)
+ e->connect(&item->d_func()->parentNotifier);
+ *((QDeclarativeItem **)rv) = item->parentItem();
+}
+
/*!
\qmlproperty list<Object> Item::data
\default
@@ -1678,18 +1651,6 @@ void QDeclarativeItem::setClip(bool c)
*/
/*!
- \property QDeclarativeItem::width
-
- Defines the item's width relative to its parent.
- */
-
-/*!
- \property QDeclarativeItem::height
-
- Defines the item's height relative to its parent.
- */
-
-/*!
\qmlproperty real Item::z
Sets the stacking order of the item. By default the stacking order is 0.
@@ -1801,11 +1762,11 @@ void QDeclarativeItem::geometryChanged(const QRectF &newGeometry,
if (newGeometry.x() != oldGeometry.x())
emit xChanged();
if (newGeometry.width() != oldGeometry.width())
- emit widthChanged(newGeometry.width());
+ emit widthChanged();
if (newGeometry.y() != oldGeometry.y())
emit yChanged();
if (newGeometry.height() != oldGeometry.height())
- emit heightChanged(newGeometry.height());
+ emit heightChanged();
for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
@@ -2281,14 +2242,6 @@ void QDeclarativeItemPrivate::focusChanged(bool flag)
}
/*! \internal */
-QDeclarativeListProperty<QDeclarativeItem> QDeclarativeItem::fxChildren()
-{
- return QDeclarativeListProperty<QDeclarativeItem>(this, 0, QDeclarativeItemPrivate::children_append,
- QDeclarativeItemPrivate::children_count,
- QDeclarativeItemPrivate::children_at);
-}
-
-/*! \internal */
QDeclarativeListProperty<QObject> QDeclarativeItem::resources()
{
return QDeclarativeListProperty<QObject>(this, 0, QDeclarativeItemPrivate::resources_append,
@@ -2594,10 +2547,11 @@ bool QDeclarativeItem::sceneEvent(QEvent *event)
QVariant QDeclarativeItem::itemChange(GraphicsItemChange change,
const QVariant &value)
{
- Q_D(const QDeclarativeItem);
+ Q_D(QDeclarativeItem);
switch (change) {
case ItemParentHasChanged:
emit parentChanged(parentItem());
+ d->parentNotifier.notify();
break;
case ItemChildAddedChange:
case ItemChildRemovedChange:
@@ -2632,7 +2586,7 @@ QVariant QDeclarativeItem::itemChange(GraphicsItemChange change,
QRectF QDeclarativeItem::boundingRect() const
{
Q_D(const QDeclarativeItem);
- return QRectF(0, 0, d->width, d->height);
+ return QRectF(0, 0, d->mWidth, d->mHeight);
}
/*!
@@ -2717,33 +2671,50 @@ void QDeclarativeItem::setSmooth(bool smooth)
qreal QDeclarativeItem::width() const
{
Q_D(const QDeclarativeItem);
- return d->width;
+ return d->width();
}
void QDeclarativeItem::setWidth(qreal w)
{
Q_D(QDeclarativeItem);
+ d->setWidth(w);
+}
+
+void QDeclarativeItem::resetWidth()
+{
+ Q_D(QDeclarativeItem);
+ d->resetWidth();
+}
+
+qreal QDeclarativeItemPrivate::width() const
+{
+ return mWidth;
+}
+
+void QDeclarativeItemPrivate::setWidth(qreal w)
+{
+ Q_Q(QDeclarativeItem);
if (qIsNaN(w))
return;
- d->widthValid = true;
- if (d->width == w)
+ widthValid = true;
+ if (mWidth == w)
return;
- qreal oldWidth = d->width;
+ qreal oldWidth = mWidth;
- prepareGeometryChange();
- d->width = w;
+ q->prepareGeometryChange();
+ mWidth = w;
- geometryChanged(QRectF(x(), y(), width(), height()),
- QRectF(x(), y(), oldWidth, height()));
+ q->geometryChanged(QRectF(q->x(), q->y(), width(), height()),
+ QRectF(q->x(), q->y(), oldWidth, height()));
}
-void QDeclarativeItem::resetWidth()
+void QDeclarativeItemPrivate ::resetWidth()
{
- Q_D(QDeclarativeItem);
- d->widthValid = false;
- setImplicitWidth(implicitWidth());
+ Q_Q(QDeclarativeItem);
+ widthValid = false;
+ q->setImplicitWidth(q->implicitWidth());
}
/*!
@@ -2763,13 +2734,13 @@ void QDeclarativeItem::setImplicitWidth(qreal w)
{
Q_D(QDeclarativeItem);
d->implicitWidth = w;
- if (d->width == w || widthValid())
+ if (d->mWidth == w || widthValid())
return;
- qreal oldWidth = d->width;
+ qreal oldWidth = d->mWidth;
prepareGeometryChange();
- d->width = w;
+ d->mWidth = w;
geometryChanged(QRectF(x(), y(), width(), height()),
QRectF(x(), y(), oldWidth, height()));
@@ -2787,33 +2758,50 @@ bool QDeclarativeItem::widthValid() const
qreal QDeclarativeItem::height() const
{
Q_D(const QDeclarativeItem);
- return d->height;
+ return d->height();
}
void QDeclarativeItem::setHeight(qreal h)
{
Q_D(QDeclarativeItem);
+ d->setHeight(h);
+}
+
+void QDeclarativeItem::resetHeight()
+{
+ Q_D(QDeclarativeItem);
+ d->resetHeight();
+}
+
+qreal QDeclarativeItemPrivate::height() const
+{
+ return mHeight;
+}
+
+void QDeclarativeItemPrivate::setHeight(qreal h)
+{
+ Q_Q(QDeclarativeItem);
if (qIsNaN(h))
return;
- d->heightValid = true;
- if (d->height == h)
+ heightValid = true;
+ if (mHeight == h)
return;
- qreal oldHeight = d->height;
+ qreal oldHeight = mHeight;
- prepareGeometryChange();
- d->height = h;
+ q->prepareGeometryChange();
+ mHeight = h;
- geometryChanged(QRectF(x(), y(), width(), height()),
- QRectF(x(), y(), width(), oldHeight));
+ q->geometryChanged(QRectF(q->x(), q->y(), width(), height()),
+ QRectF(q->x(), q->y(), width(), oldHeight));
}
-void QDeclarativeItem::resetHeight()
+void QDeclarativeItemPrivate::resetHeight()
{
- Q_D(QDeclarativeItem);
- d->heightValid = false;
- setImplicitHeight(implicitHeight());
+ Q_Q(QDeclarativeItem);
+ heightValid = false;
+ q->setImplicitHeight(q->implicitHeight());
}
/*!
@@ -2833,13 +2821,13 @@ void QDeclarativeItem::setImplicitHeight(qreal h)
{
Q_D(QDeclarativeItem);
d->implicitHeight = h;
- if (d->height == h || heightValid())
+ if (d->mHeight == h || heightValid())
return;
- qreal oldHeight = d->height;
+ qreal oldHeight = d->mHeight;
prepareGeometryChange();
- d->height = h;
+ d->mHeight = h;
geometryChanged(QRectF(x(), y(), width(), height()),
QRectF(x(), y(), width(), oldHeight));
@@ -2861,15 +2849,15 @@ void QDeclarativeItem::setSize(const QSizeF &size)
d->heightValid = true;
d->widthValid = true;
- if (d->height == size.height() && d->width == size.width())
+ if (d->height() == size.height() && d->width() == size.width())
return;
- qreal oldHeight = d->height;
- qreal oldWidth = d->width;
+ qreal oldHeight = d->height();
+ qreal oldWidth = d->width();
prepareGeometryChange();
- d->height = size.height();
- d->width = size.width();
+ d->setHeight(size.height());
+ d->setWidth(size.width());
geometryChanged(QRectF(x(), y(), width(), height()),
QRectF(x(), y(), oldWidth, oldHeight));
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h
index c88b1db..712e854 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem.h
@@ -71,13 +71,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeItem : public QGraphicsObject, public QDe
Q_PROPERTY(QDeclarativeItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
Q_PROPERTY(QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
- Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> children READ fxChildren DESIGNABLE false NOTIFY childrenChanged)
Q_PROPERTY(QDeclarativeListProperty<QObject> resources READ resources DESIGNABLE false)
Q_PROPERTY(QDeclarativeListProperty<QDeclarativeState> states READ states DESIGNABLE false)
Q_PROPERTY(QDeclarativeListProperty<QDeclarativeTransition> transitions READ transitions DESIGNABLE false)
Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
- Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL)
- Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL)
Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL)
Q_PROPERTY(QDeclarativeAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
Q_PROPERTY(QDeclarativeAnchorLine left READ left CONSTANT FINAL)
@@ -113,7 +110,6 @@ public:
void setParent(QDeclarativeItem *parent) { setParentItem(parent); }
QDeclarativeListProperty<QObject> data();
- QDeclarativeListProperty<QDeclarativeItem> fxChildren();
QDeclarativeListProperty<QObject> resources();
QDeclarativeAnchors *anchors();
@@ -173,8 +169,6 @@ public:
QDeclarativeAnchorLine baseline() const;
Q_SIGNALS:
- void widthChanged(qreal);
- void heightChanged(qreal);
void childrenChanged();
void childrenRectChanged(const QRectF &);
void baselineOffsetChanged(qreal);
@@ -235,9 +229,11 @@ QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QDeclarativeItem *item);
QT_END_NAMESPACE
QML_DECLARE_TYPE(QDeclarativeItem)
+QML_DECLARE_TYPE(QGraphicsObject)
QML_DECLARE_TYPE(QGraphicsTransform)
QML_DECLARE_TYPE(QGraphicsScale)
QML_DECLARE_TYPE(QGraphicsRotation)
+QML_DECLARE_TYPE(QGraphicsWidget)
QML_DECLARE_TYPE(QAction)
QT_END_HEADER
diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h
index 55df063..4828f4e 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h
@@ -62,6 +62,8 @@
#include <private/qdeclarativestate_p.h>
#include <private/qdeclarativenullablevalue_p_p.h>
+#include <private/qdeclarativenotifier_p.h>
+
#include <qdeclarative.h>
#include <qdeclarativecontext.h>
@@ -114,7 +116,7 @@ public:
widthValid(false), heightValid(false),
_componentComplete(true), _keepMouse(false),
smooth(false), keyHandler(0),
- width(0), height(0), implicitWidth(0), implicitHeight(0)
+ mWidth(0), mHeight(0), implicitWidth(0), implicitHeight(0)
{
QGraphicsItemPrivate::acceptedMouseButtons = 0;
QGraphicsItemPrivate::flags = QGraphicsItem::GraphicsItemFlags(
@@ -136,6 +138,16 @@ public:
QString _id;
+ // Private Properties
+ qreal width() const;
+ void setWidth(qreal);
+ void resetWidth();
+
+ qreal height() const;
+ void setHeight(qreal);
+ void resetHeight();
+
+
// data property
static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
@@ -144,17 +156,16 @@ public:
static void resources_append(QDeclarativeListProperty<QObject> *, QObject *);
static int resources_count(QDeclarativeListProperty<QObject> *);
- // children property
- static QDeclarativeItem *children_at(QDeclarativeListProperty<QDeclarativeItem> *, int);
- static void children_append(QDeclarativeListProperty<QDeclarativeItem> *, QDeclarativeItem *);
- static int children_count(QDeclarativeListProperty<QDeclarativeItem> *);
-
// transform property
static int transform_count(QDeclarativeListProperty<QGraphicsTransform> *list);
static void transform_append(QDeclarativeListProperty<QGraphicsTransform> *list, QGraphicsTransform *);
static QGraphicsTransform *transform_at(QDeclarativeListProperty<QGraphicsTransform> *list, int);
static void transform_clear(QDeclarativeListProperty<QGraphicsTransform> *list);
+ // Accelerated property accessors
+ QDeclarativeNotifier parentNotifier;
+ static void parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e);
+
QDeclarativeAnchors *anchors() {
if (!_anchors) {
Q_Q(QDeclarativeItem);
@@ -222,8 +233,8 @@ public:
QDeclarativeItemKeyFilter *keyHandler;
- qreal width;
- qreal height;
+ qreal mWidth;
+ qreal mHeight;
qreal implicitWidth;
qreal implicitHeight;
@@ -232,9 +243,9 @@ public:
virtual void setPosHelper(const QPointF &pos)
{
Q_Q(QDeclarativeItem);
- QRectF oldGeometry(this->pos.x(), this->pos.y(), width, height);
+ QRectF oldGeometry(this->pos.x(), this->pos.y(), mWidth, mHeight);
QGraphicsItemPrivate::setPosHelper(pos);
- q->geometryChanged(QRectF(this->pos.x(), this->pos.y(), width, height), oldGeometry);
+ q->geometryChanged(QRectF(this->pos.x(), this->pos.y(), mWidth, mHeight), oldGeometry);
}
// Reimplemented from QGraphicsItemPrivate
diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
index 1a48cbd..07d7f4d 100644
--- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
@@ -114,7 +114,6 @@ void QDeclarativeItemModule::defineModule()
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))
qmlRegisterType<QDoubleValidator>("Qt",4,7,"QDoubleValidator");
@@ -146,6 +145,7 @@ void QDeclarativeItemModule::defineModule()
qmlRegisterType<QValidator>();
qmlRegisterType<QDeclarativeVisualModel>();
qmlRegisterType<QAction>();
+ qmlRegisterType<QDeclarativePen>();
#ifdef QT_WEBKIT_LIB
qmlRegisterType<QDeclarativeWebSettings>();
#endif
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index 84281c8..8a70c07 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -562,7 +562,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(qreal)) : SIGNAL(widthChanged(qreal));
+ const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged());
QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged()));
QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged()));
trackedItem = 0;
@@ -763,7 +763,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(qreal)) : SIGNAL(widthChanged(qreal));
+ const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged());
if (trackedItem && item != trackedItem) {
QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged()));
@@ -1136,28 +1136,32 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
QDeclarativeFlickablePrivate::flick(data, minExtent, maxExtent, vSize, fixupCallback, velocity);
return;
}
- qreal maxDistance = -1;
- // -ve velocity means list is moving up
+ qreal maxDistance = 0;
+ // -ve velocity means list is moving up/left
if (velocity > 0) {
- if (snapMode == QDeclarativeListView::SnapOneItem) {
- if (FxListItem *item = firstVisibleItem())
- maxDistance = qAbs(item->position() + data.move.value());
- } else if (data.move.value() < minExtent) {
- maxDistance = qAbs(minExtent - data.move.value());
+ if (data.move.value() < minExtent) {
+ if (snapMode == QDeclarativeListView::SnapOneItem) {
+ if (FxListItem *item = firstVisibleItem())
+ maxDistance = qAbs(item->position() + data.move.value());
+ } else {
+ maxDistance = qAbs(minExtent - data.move.value());
+ }
}
if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange)
data.flickTarget = minExtent;
} else {
- if (snapMode == QDeclarativeListView::SnapOneItem) {
- if (FxListItem *item = nextVisibleItem())
- maxDistance = qAbs(item->position() + data.move.value());
- } else if (data.move.value() > maxExtent) {
- maxDistance = qAbs(maxExtent - data.move.value());
+ if (data.move.value() > maxExtent) {
+ if (snapMode == QDeclarativeListView::SnapOneItem) {
+ if (FxListItem *item = nextVisibleItem())
+ maxDistance = qAbs(item->position() + data.move.value());
+ } else {
+ maxDistance = qAbs(maxExtent - data.move.value());
+ }
}
if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange)
data.flickTarget = maxExtent;
}
- if (maxDistance > 0 && (snapMode != QDeclarativeListView::NoSnap || highlightRange == QDeclarativeListView::StrictlyEnforceRange)) {
+ if ((maxDistance > 0 || overShoot) && (snapMode != QDeclarativeListView::NoSnap || highlightRange == QDeclarativeListView::StrictlyEnforceRange)) {
// These modes require the list to stop exactly on an item boundary.
// The initial flick will estimate the boundary to stop on.
// Since list items can have variable sizes, the boundary will be
@@ -1173,8 +1177,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
// the initial flick - estimate boundary
qreal accel = deceleration;
qreal v2 = v * v;
- qreal maxAccel = v2 / (2.0f * maxDistance);
- if (maxAccel < accel) {
+ if (maxDistance > 0.0 && v2 / (2.0f * maxDistance) < accel) {
// + averageSize/4 to encourage moving at least one item in the flick direction
qreal dist = v2 / (accel * 2.0) + averageSize/4;
if (v > 0)
@@ -1328,7 +1331,7 @@ QDeclarativeListView::~QDeclarativeListView()
id: wrapper
SequentialAnimation on ListView.onRemove {
PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: true }
- NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" }
+ NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: "InOutQuad" }
PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: false }
}
}
@@ -1488,8 +1491,9 @@ void QDeclarativeListView::setCurrentIndex(int index)
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
cancelFlick();
d->updateCurrent(index);
- } else {
+ } else if (index != d->currentIndex) {
d->currentIndex = index;
+ emit currentIndexChanged();
}
}
@@ -2063,9 +2067,10 @@ qreal QDeclarativeListView::maxYExtent() const
if (d->orient == QDeclarativeListView::Horizontal)
return height();
if (d->maxExtentDirty) {
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
d->maxExtent = -(d->endPosition() - d->highlightRangeEnd);
- else
+ d->maxExtent = qMax(d->maxExtent, -(d->positionAt(d->model->count()-1) - d->highlightRangeStart));
+ } else
d->maxExtent = -(d->endPosition() - height() + 1);
if (d->footer)
d->maxExtent -= d->footer->size();
@@ -2100,9 +2105,10 @@ qreal QDeclarativeListView::maxXExtent() const
if (d->orient == QDeclarativeListView::Vertical)
return width();
if (d->maxExtentDirty) {
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
d->maxExtent = -(d->endPosition() - d->highlightRangeEnd);
- else
+ d->maxExtent = qMax(d->maxExtent, -(d->positionAt(d->model->count()-1) - d->highlightRangeStart));
+ } else
d->maxExtent = -(d->endPosition() - width() + 1);
if (d->footer)
d->maxExtent -= d->footer->size();
@@ -2361,11 +2367,19 @@ void QDeclarativeListView::trackedPositionChanged()
void QDeclarativeListView::itemsInserted(int modelIndex, int count)
{
Q_D(QDeclarativeListView);
+ if (!isComponentComplete())
+ return;
d->updateUnrequestedIndexes();
d->moveReason = QDeclarativeListViewPrivate::Other;
if (!d->visibleItems.count() || d->model->count() <= 1) {
d->scheduleLayout();
- d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1)));
+ if (d->currentIndex >= modelIndex) {
+ // adjust current item index
+ d->currentIndex += count;
+ if (d->currentItem)
+ d->currentItem->index = d->currentIndex;
+ emit currentIndexChanged();
+ }
emit countChanged();
return;
}
@@ -2495,6 +2509,8 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
void QDeclarativeListView::itemsRemoved(int modelIndex, int count)
{
Q_D(QDeclarativeListView);
+ if (!isComponentComplete())
+ return;
d->moveReason = QDeclarativeListViewPrivate::Other;
d->updateUnrequestedIndexes();
@@ -2593,6 +2609,8 @@ void QDeclarativeListView::destroyRemoved()
void QDeclarativeListView::itemsMoved(int from, int to, int count)
{
Q_D(QDeclarativeListView);
+ if (!isComponentComplete())
+ return;
d->updateUnrequestedIndexes();
if (d->visibleItems.isEmpty()) {
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp
index 3cbafd6..0d62afa 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp
@@ -41,7 +41,9 @@
#include "qdeclarativeloader_p_p.h"
+#include <qdeclarativeinfo.h>
#include <qdeclarativeengine_p.h>
+#include <qdeclarativeglobal_p.h>
QT_BEGIN_NAMESPACE
@@ -185,9 +187,6 @@ void QDeclarativeLoader::setSource(const QUrl &url)
if (d->source == url)
return;
- if (!qmlContext(this)->isSafeOrigin(url))
- return;
-
d->clear();
d->source = url;
@@ -299,9 +298,9 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded()
return;
}
if (obj) {
- ctxt->setParent(obj);
item = qobject_cast<QGraphicsObject *>(obj);
if (item) {
+ QDeclarative_setParent_noEvent(ctxt, obj);
if (QDeclarativeItem* qmlItem = qobject_cast<QDeclarativeItem *>(item)) {
qmlItem->setParentItem(q);
} else {
@@ -310,8 +309,14 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded()
}
// item->setFocus(true);
initResize();
+ } else {
+ qmlInfo(q) << QDeclarativeLoader::tr("Loader does not support loading non-visual elements.");
+ delete obj;
+ delete ctxt;
}
} else {
+ if (!component->errors().isEmpty())
+ qWarning() << component->errors();
delete obj;
delete ctxt;
source = QUrl();
diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
index 28a93d2..ab6007a 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(qreal)),this,SLOT(clearCache()));
- connect(this,SIGNAL(heightChanged(qreal)),this,SLOT(clearCache()));
+ connect(this,SIGNAL(widthChanged()),this,SLOT(clearCache()));
+ connect(this,SIGNAL(heightChanged()),this,SLOT(clearCache()));
connect(this,SIGNAL(visibleChanged()),this,SLOT(clearCache()));
}
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index b9c8971..f3d6137 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -138,6 +138,103 @@ void QDeclarativePathViewPrivate::clear()
items.clear();
}
+void QDeclarativePathViewPrivate::updateMappedRange()
+{
+ if (model && pathItems != -1 && pathItems < model->count())
+ mappedRange = qreal(pathItems)/model->count();
+ else
+ mappedRange = 1.0;
+}
+
+qreal QDeclarativePathViewPrivate::positionOfIndex(int index) const
+{
+ qreal pos = -1.0;
+
+ if (model && index >= 0 && index < model->count()) {
+ qreal globalPos = qreal(index) + offset;
+ globalPos = qmlMod(globalPos, qreal(model->count())) / model->count();
+ if (pathItems != -1 && pathItems < model->count()) {
+ globalPos += snapPos * mappedRange;
+ globalPos = qmlMod(globalPos, 1.0);
+ if (globalPos < mappedRange)
+ pos = globalPos / mappedRange;
+ } else {
+ pos = qmlMod(globalPos + snapPos, 1.0);
+ }
+ }
+
+ return pos;
+}
+
+void QDeclarativePathViewPrivate::createHighlight()
+{
+ Q_Q(QDeclarativePathView);
+ bool changed = false;
+ if (highlightItem) {
+ delete highlightItem;
+ highlightItem = 0;
+ changed = true;
+ }
+
+ QDeclarativeItem *item = 0;
+ if (highlightComponent) {
+ QDeclarativeContext *highlightContext = new QDeclarativeContext(qmlContext(q));
+ QObject *nobj = highlightComponent->create(highlightContext);
+ if (nobj) {
+ highlightContext->setParent(nobj);
+ item = qobject_cast<QDeclarativeItem *>(nobj);
+ if (!item)
+ delete nobj;
+ } else {
+ delete highlightContext;
+ }
+ } else {
+ item = new QDeclarativeItem;
+ }
+ if (item) {
+ item->setParent(q);
+ highlightItem = item;
+ changed = true;
+ }
+ if (changed)
+ emit q->highlightItemChanged();
+}
+
+void QDeclarativePathViewPrivate::updateHighlight()
+{
+ Q_Q(QDeclarativePathView);
+ if (!q->isComponentComplete())
+ return;
+ if (highlightItem)
+ updateItem(highlightItem, snapPos);
+}
+
+void QDeclarativePathViewPrivate::updateItem(QDeclarativeItem *item, qreal percent)
+{
+ if (QDeclarativePathViewAttached *att = attached(item)) {
+ foreach(const QString &attr, path->attributes())
+ att->setValue(attr.toUtf8(), path->attributeAt(attr, percent));
+ }
+ QPointF pf = path->pointAt(percent);
+ item->setX(pf.x() - item->width()*item->scale()/2);
+ item->setY(pf.y() - item->height()*item->scale()/2);
+}
+
+void QDeclarativePathViewPrivate::regenerate()
+{
+ Q_Q(QDeclarativePathView);
+ if (!q->isComponentComplete())
+ return;
+
+ clear();
+
+ if (!isValid())
+ return;
+
+ firstIndex = -1;
+ updateMappedRange();
+ q->refill();
+}
/*!
\qmlclass PathView QDeclarativePathView
@@ -232,6 +329,7 @@ void QDeclarativePathView::setModel(const QVariant &model)
if (d->model) {
disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int)));
disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int)));
+ disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int)));
disconnect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset()));
disconnect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*)));
for (int i=0; i<d->items.count(); i++){
@@ -261,13 +359,16 @@ void QDeclarativePathView::setModel(const QVariant &model)
if (d->model) {
connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int)));
connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int)));
+ connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int)));
connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset()));
connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*)));
}
- d->firstIndex = 0;
- d->pathOffset = 0;
+ d->offset = qmlMod(d->offset, qreal(d->model->count()));
+ if (d->offset < 0)
+ d->offset = d->model->count() + d->offset;
d->regenerate();
d->fixOffset();
+ emit countChanged();
emit modelChanged();
}
@@ -330,7 +431,7 @@ void QDeclarativePathView::setCurrentIndex(int idx)
if (d->model->count()) {
int itemIndex = (d->currentIndex - d->firstIndex + d->model->count()) % d->model->count();
if (itemIndex < d->items.count()) {
- if (QDeclarativeItem *item = d->items.at(d->currentIndex)) {
+ if (QDeclarativeItem *item = d->items.at(itemIndex)) {
if (QDeclarativePathViewAttached *att = d->attached(item))
att->setIsCurrentItem(false);
}
@@ -354,12 +455,13 @@ void QDeclarativePathView::setCurrentIndex(int idx)
/*!
\qmlproperty real PathView::offset
- The offset specifies how far along the path (0.0-1.0) the items are from their initial positions.
+ The offset specifies how far along the path the items are from their initial positions.
+ This is a real number that ranges from 0.0 to the count of items in the model.
*/
qreal QDeclarativePathView::offset() const
{
Q_D(const QDeclarativePathView);
- return d->_offset;
+ return d->offset;
}
void QDeclarativePathView::setOffset(qreal offset)
@@ -372,18 +474,25 @@ void QDeclarativePathView::setOffset(qreal offset)
void QDeclarativePathViewPrivate::setOffset(qreal o)
{
Q_Q(QDeclarativePathView);
- if (_offset != o) {
- _offset = qmlMod(o, qreal(1.0));
- if (_offset < 0)
- _offset = 1.0 + _offset;
- q->refill();
+ if (offset != o) {
+ if (isValid() && q->isComponentComplete()) {
+ offset = qmlMod(o, qreal(model->count()));
+ if (offset < 0)
+ offset = model->count() + offset;
+ q->refill();
+ } else {
+ offset = o;
+ }
+ emit q->offsetChanged();
}
}
/*!
\qmlproperty real PathView::snapPosition
- This property determines the position (0.0-1.0) the nearest item will snap to.
+ This property determines the position on the path (0.0-1.0) the nearest item will snap to.
+ The item nearest this position will set currentIndex, for example when offset is 0.0 the
+ first item will be placed at this position and currentIndex will be 0.
*/
qreal QDeclarativePathView::snapPosition() const
{
@@ -398,10 +507,34 @@ void QDeclarativePathView::setSnapPosition(qreal pos)
if (qFuzzyCompare(normalizedPos, d->snapPos))
return;
d->snapPos = normalizedPos;
+ d->updateHighlight();
d->fixOffset();
emit snapPositionChanged();
}
+QDeclarativeComponent *QDeclarativePathView::highlight() const
+{
+ Q_D(const QDeclarativePathView);
+ return d->highlightComponent;
+}
+
+void QDeclarativePathView::setHighlight(QDeclarativeComponent *highlight)
+{
+ Q_D(QDeclarativePathView);
+ if (highlight != d->highlightComponent) {
+ d->highlightComponent = highlight;
+ d->createHighlight();
+ d->updateHighlight();
+ emit highlightChanged();
+ }
+}
+
+QDeclarativeItem *QDeclarativePathView::highlightItem()
+{
+ Q_D(const QDeclarativePathView);
+ return d->highlightItem;
+}
+
/*!
\qmlproperty real PathView::dragMargin
This property holds the maximum distance from the path that initiate mouse dragging.
@@ -426,6 +559,52 @@ void QDeclarativePathView::setDragMargin(qreal dragMargin)
}
/*!
+ \qmlproperty real PathView::flickDeceleration
+ This property holds the rate at which a flick will decelerate.
+
+ The default is 100.
+*/
+qreal QDeclarativePathView::flickDeceleration() const
+{
+ Q_D(const QDeclarativePathView);
+ return d->deceleration;
+}
+
+void QDeclarativePathView::setFlickDeceleration(qreal dec)
+{
+ Q_D(QDeclarativePathView);
+ if (d->deceleration == dec)
+ return;
+ d->deceleration = dec;
+ emit flickDecelerationChanged();
+}
+
+/*!
+ \qmlproperty bool PathView::interactive
+
+ A user cannot drag or flick a PathView that is not interactive.
+
+ This property is useful for temporarily disabling flicking. This allows
+ special interaction with PathView's children.
+*/
+bool QDeclarativePathView::isInteractive() const
+{
+ Q_D(const QDeclarativePathView);
+ return d->interactive;
+}
+
+void QDeclarativePathView::setInteractive(bool interactive)
+{
+ Q_D(QDeclarativePathView);
+ if (interactive != d->interactive) {
+ d->interactive = interactive;
+ if (!interactive)
+ d->tl.clear();
+ emit interactiveChanged();
+ }
+}
+
+/*!
\qmlproperty component PathView::delegate
The delegate provides a template defining each item instantiated by the view.
@@ -467,7 +646,7 @@ void QDeclarativePathView::setDelegate(QDeclarativeComponent *delegate)
/*!
\qmlproperty int PathView::pathItemCount
- This property holds the number of items visible on the path at any one time
+ This property holds the number of items visible on the path at any one time.
*/
int QDeclarativePathView::pathItemCount() const
{
@@ -480,9 +659,13 @@ void QDeclarativePathView::setPathItemCount(int i)
Q_D(QDeclarativePathView);
if (i == d->pathItems)
return;
+ if (i < 1)
+ i = 1;
d->pathItems = i;
- d->regenerate();
- pathItemCountChanged();
+ if (d->isValid() && isComponentComplete()) {
+ d->regenerate();
+ }
+ emit pathItemCountChanged();
}
QPointF QDeclarativePathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const
@@ -512,7 +695,7 @@ QPointF QDeclarativePathViewPrivate::pointNear(const QPointF &point, qreal *near
void QDeclarativePathView::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativePathView);
- if (!d->items.count())
+ if (!d->interactive || !d->items.count())
return;
QPointF scenePoint = mapToScene(event->pos());
int idx = 0;
@@ -542,7 +725,7 @@ void QDeclarativePathView::mousePressEvent(QGraphicsSceneMouseEvent *event)
void QDeclarativePathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativePathView);
- if (d->lastPosTime.isNull())
+ if (!d->interactive || d->lastPosTime.isNull())
return;
if (!d->stealMouse) {
@@ -555,14 +738,14 @@ void QDeclarativePathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
d->moveReason = QDeclarativePathViewPrivate::Mouse;
qreal newPc;
d->pointNear(event->pos(), &newPc);
- qreal diff = newPc - d->startPc;
+ qreal diff = (newPc - d->startPc)*d->model->count()*d->mappedRange;
if (diff) {
- setOffset(d->_offset + diff);
+ setOffset(d->offset + diff);
- if (diff > 0.5)
- diff -= 1.0;
- else if (diff < -0.5)
- diff += 1.0;
+ if (diff > d->model->count()/2)
+ diff -= d->model->count();
+ else if (diff < -d->model->count()/2)
+ diff += d->model->count();
d->lastElapsed = QDeclarativeItemPrivate::restart(d->lastPosTime);
d->lastDist = diff;
@@ -574,27 +757,37 @@ void QDeclarativePathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void QDeclarativePathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
{
Q_D(QDeclarativePathView);
- if (d->lastPosTime.isNull())
+ d->stealMouse = false;
+ setKeepMouseGrab(false);
+ if (!d->interactive || d->lastPosTime.isNull())
return;
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) > 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, 0.1, dist);
+ if (d->model && d->model->count() && qAbs(velocity) > 1.) {
+ qreal count = d->pathItems == -1 ? d->model->count() : d->pathItems;
+ if (qAbs(velocity) > count * 2) // limit velocity
+ velocity = (velocity > 0 ? count : -count) * 2;
+ // Calculate the distance to be travelled
+ qreal v2 = velocity*velocity;
+ qreal accel = d->deceleration;
+ // + 0.25 to encourage moving at least one item in the flick direction
+ qreal dist = qMin(qreal(d->model->count()-1), d->model->count() * v2 / (accel * 2.0) + 0.25);
+ // round to nearest item.
+ if (velocity > 0.)
+ dist = qRound(dist + d->offset) - d->offset;
+ else
+ dist = qRound(dist - d->offset) + d->offset;
+ // Calculate accel required to stop on item boundary
+ accel = v2 / (2.0f * qAbs(dist));
+ d->moveOffset.setValue(d->offset);
+ d->tl.accel(d->moveOffset, velocity, accel, dist);
d->tl.callback(QDeclarativeTimeLineCallback(&d->moveOffset, d->fixOffsetCallback, d));
} else {
d->fixOffset();
}
d->lastPosTime = QTime();
- d->stealMouse = false;
ungrabMouse();
}
@@ -644,7 +837,8 @@ bool QDeclarativePathView::sendMouseEvent(QGraphicsSceneMouseEvent *event)
bool QDeclarativePathView::sceneEventFilter(QGraphicsItem *i, QEvent *e)
{
- if (!isVisible())
+ Q_D(QDeclarativePathView);
+ if (!isVisible() || !d->interactive)
return QDeclarativeItem::sceneEventFilter(i, e);
switch (e->type()) {
@@ -669,72 +863,7 @@ void QDeclarativePathView::componentComplete()
Q_D(QDeclarativePathView);
QDeclarativeItem::componentComplete();
d->regenerate();
-
- // move to correct offset
- if (d->items.count()) {
- int itemIndex = (d->currentIndex - d->firstIndex + d->model->count()) % d->model->count();
-
- itemIndex += d->pathOffset;
- itemIndex %= d->items.count();
- qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0));
-
- if (targetOffset < 0)
- targetOffset = 1.0 + targetOffset;
- if (targetOffset != d->_offset) {
- d->moveOffset.setValue(targetOffset);
- }
- }
-}
-
-void QDeclarativePathViewPrivate::regenerate()
-{
- Q_Q(QDeclarativePathView);
- if (!q->isComponentComplete())
- return;
-
- clear();
-
- if (!isValid())
- return;
-
- if (firstIndex >= model->count())
- firstIndex = model->count()-1;
- if (pathOffset >= model->count())
- pathOffset = model->count()-1;
-
- int numItems = pathItems >= 0 ? pathItems : model->count();
- for (int i=0; i < numItems && i < model->count(); ++i){
- int index = (i + firstIndex) % model->count();
- QDeclarativeItem *item = getItem(index);
- if (!item) {
- qWarning() << "PathView: Cannot create item, index" << (i + firstIndex) % model->count();
- return;
- }
- items.append(item);
- item->setZValue(i);
- qreal percent = qreal(i) / numItems + _offset;
- percent = qAbs(qmlMod(percent, qreal(1.0)));
- updateItem(item, percent);
- model->completeItem();
- if (currentIndex == index) {
- item->setFocus(true);
- if (QDeclarativePathViewAttached *att = attached(item))
- att->setIsCurrentItem(true);
- }
- }
- if (pathItems != -1)
- q->refill();
-}
-
-void QDeclarativePathViewPrivate::updateItem(QDeclarativeItem *item, qreal percent)
-{
- if (QDeclarativePathViewAttached *att = attached(item)) {
- foreach(const QString &attr, path->attributes())
- att->setValue(attr.toUtf8(), path->attributeAt(attr, percent));
- }
- QPointF pf = path->pointAt(percent);
- item->setX(pf.x() - item->width()*item->scale()/2);
- item->setY(pf.y() - item->height()*item->scale()/2);
+ d->updateHighlight();
}
void QDeclarativePathView::refill()
@@ -743,81 +872,85 @@ void QDeclarativePathView::refill()
if (!d->isValid() || !isComponentComplete())
return;
- QList<qreal> positions;
- for (int i=0; i<d->items.count(); i++){
- qreal percent = qreal(i) / d->items.count();
- percent = percent + d->_offset;
- percent = qmlMod(percent, qreal(1.0));
- positions << qAbs(percent);
- }
-
- if (d->pathItems==-1) {
- for (int i=0; i<positions.count(); i++)
- d->updateItem(d->items.at(i), positions[i]);
- return;
+// qDebug() << "offset" << d->_offset;
+
+ // first move existing items and remove items off path
+ int idx = d->firstIndex;
+ QList<QDeclarativeItem*>::iterator it = d->items.begin();
+ while (it != d->items.end()) {
+ qreal pos = d->positionOfIndex(idx);
+ QDeclarativeItem *item = *it;
+ if (pos >= 0.0) {
+ d->updateItem(item, pos);
+ ++it;
+ } else {
+// qDebug() << "release";
+ d->updateItem(item, 1.0);
+ d->releaseItem(item);
+ if (it == d->items.begin()) {
+ if (++d->firstIndex >= d->model->count())
+ d->firstIndex = 0;
+ }
+ it = d->items.erase(it);
+ }
+ ++idx;
+ if (idx >= d->model->count())
+ idx = 0;
}
- QList<qreal> rotatedPositions;
- for (int i=0; i<d->items.count(); i++)
- rotatedPositions << positions[(i + d->pathOffset + d->items.count()) % d->items.count()];
-
- int wrapIndex= -1;
- for (int i=0; i<d->items.count()-1; i++) {
- if (rotatedPositions[i] > rotatedPositions[i+1]){
- wrapIndex = i;
- break;
+ // add items to beginning and end
+ int count = d->pathItems == -1 ? d->model->count() : qMin(d->pathItems, d->model->count());
+ if (d->items.count() < count) {
+ int idx = qRound(d->model->count() - d->offset) % d->model->count();
+ qreal startPos = d->snapPos;
+ if (d->firstIndex >= 0) {
+ startPos = d->positionOfIndex(d->firstIndex);
+ idx = (d->firstIndex + d->items.count()) % d->model->count();
}
- }
- if (wrapIndex != -1 ){
- //A wraparound has occured
- if (wrapIndex < d->items.count()/2){
- while(wrapIndex-- >= 0){
- QDeclarativeItem* p = d->items.takeFirst();
- d->updateItem(p, 0.0);
- d->releaseItem(p);
- d->firstIndex++;
- d->firstIndex %= d->model->count();
- int index = (d->firstIndex + d->items.count())%d->model->count();
- QDeclarativeItem *item = d->getItem(index);
- item->setZValue(wrapIndex);
- d->model->completeItem();
- if (d->currentIndex == index) {
- item->setFocus(true);
- if (QDeclarativePathViewAttached *att = d->attached(item))
- att->setIsCurrentItem(true);
- }
- d->items << item;
- d->pathOffset++;
- d->pathOffset=d->pathOffset % d->items.count();
+ qreal pos = d->positionOfIndex(idx);
+ while ((pos > startPos || !d->items.count()) && d->items.count() < count) {
+// qDebug() << "append" << idx;
+ QDeclarativeItem *item = d->getItem(idx);
+ item->setZValue(idx+1);
+ d->model->completeItem();
+ if (d->currentIndex == idx) {
+ item->setFocus(true);
+ if (QDeclarativePathViewAttached *att = d->attached(item))
+ att->setIsCurrentItem(true);
}
- } else {
- while(wrapIndex++ < d->items.count()-1){
- QDeclarativeItem* p = d->items.takeLast();
- d->updateItem(p, 1.0);
- d->releaseItem(p);
- d->firstIndex--;
- if (d->firstIndex < 0)
- d->firstIndex = d->model->count() - 1;
- QDeclarativeItem *item = d->getItem(d->firstIndex);
- item->setZValue(d->firstIndex);
- d->model->completeItem();
- if (d->currentIndex == d->firstIndex) {
- item->setFocus(true);
- if (QDeclarativePathViewAttached *att = d->attached(item))
- att->setIsCurrentItem(true);
- }
- d->items.prepend(item);
- d->pathOffset--;
- if (d->pathOffset < 0)
- d->pathOffset = d->items.count() - 1;
+ if (d->items.count() == 0)
+ d->firstIndex = idx;
+ d->items.append(item);
+ d->updateItem(item, pos);
+ ++idx;
+ if (idx >= d->model->count())
+ idx = 0;
+ pos = d->positionOfIndex(idx);
+ }
+
+ idx = d->firstIndex - 1;
+ if (idx < 0)
+ idx = d->model->count() - 1;
+ pos = d->positionOfIndex(idx);
+ while (pos >= 0.0 && pos < startPos) {
+// qDebug() << "prepend" << idx;
+ QDeclarativeItem *item = d->getItem(idx);
+ item->setZValue(idx+1);
+ d->model->completeItem();
+ if (d->currentIndex == idx) {
+ item->setFocus(true);
+ if (QDeclarativePathViewAttached *att = d->attached(item))
+ att->setIsCurrentItem(true);
}
+ d->items.prepend(item);
+ d->updateItem(item, pos);
+ d->firstIndex = idx;
+ idx = d->firstIndex - 1;
+ if (idx < 0)
+ idx = d->model->count() - 1;
+ pos = d->positionOfIndex(idx);
}
- for (int i=0; i<d->items.count(); i++)
- rotatedPositions[i] = positions[(i + d->pathOffset + d->items.count())
- % d->items.count()];
}
- for (int i=0; i<d->items.count(); i++)
- d->updateItem(d->items.at(i), rotatedPositions[i]);
}
void QDeclarativePathView::itemsInserted(int modelIndex, int count)
@@ -826,29 +959,14 @@ void QDeclarativePathView::itemsInserted(int modelIndex, int count)
Q_D(QDeclarativePathView);
if (!d->isValid() || !isComponentComplete())
return;
- if (d->pathItems == -1) {
- for (int i = 0; i < count; ++i) {
- QDeclarativeItem *item = d->getItem(modelIndex + i);
- item->setZValue(modelIndex + i);
- d->model->completeItem();
- d->items.insert(modelIndex + i, item);
- }
- refill();
- } else {
- //XXX This is pretty heavy handed until we reference count items.
- d->regenerate();
- }
- // make sure the current item is still at the snap position
- int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count();
- itemIndex += d->pathOffset;
- itemIndex %= d->items.count();
- qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0));
-
- if (targetOffset < 0)
- targetOffset = 1.0 + targetOffset;
- if (targetOffset != d->_offset)
- d->moveOffset.setValue(targetOffset);
+ QList<QDeclarativeItem *> removedItems = d->items;
+ d->items.clear();
+ d->regenerate();
+ while (removedItems.count())
+ d->releaseItem(removedItems.takeLast());
+ d->updateCurrent();
+ emit countChanged();
}
void QDeclarativePathView::itemsRemoved(int modelIndex, int count)
@@ -857,41 +975,37 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count)
Q_D(QDeclarativePathView);
if (!d->isValid() || !isComponentComplete())
return;
- if (d->pathItems == -1) {
- for (int i = 0; i < count && d->items.count() > modelIndex; ++i) {
- QDeclarativeItem* p = d->items.takeAt(modelIndex);
- d->model->release(p);
- }
- d->snapToCurrent();
- refill();
- } else {
- d->regenerate();
- }
- if (d->model->count() == 0) {
- d->currentIndex = -1;
- d->moveOffset.setValue(0);
+ QList<QDeclarativeItem *> removedItems = d->items;
+ d->items.clear();
+ if (d->offset >= d->model->count())
+ d->offset = d->model->count() - 1;
+ d->regenerate();
+ while (removedItems.count())
+ d->releaseItem(removedItems.takeLast());
+ d->updateCurrent();
+ emit countChanged();
+}
+
+void QDeclarativePathView::itemsMoved(int from, int to, int count)
+{
+ Q_D(QDeclarativePathView);
+ if (!d->isValid() || !isComponentComplete())
return;
- }
- // make sure the current item is still at the snap position
- if (d->currentIndex >= d->model->count())
- d->currentIndex = d->model->count() - 1;
- int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count();
- itemIndex += d->pathOffset;
- itemIndex %= d->items.count();
- qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0));
-
- if (targetOffset < 0)
- targetOffset = 1.0 + targetOffset;
- if (targetOffset != d->_offset)
- d->moveOffset.setValue(targetOffset);
+ QList<QDeclarativeItem *> removedItems = d->items;
+ d->items.clear();
+ d->regenerate();
+ while (removedItems.count())
+ d->releaseItem(removedItems.takeLast());
+ d->updateCurrent();
}
void QDeclarativePathView::modelReset()
{
Q_D(QDeclarativePathView);
d->regenerate();
+ emit countChanged();
}
void QDeclarativePathView::createdItem(int index, QDeclarativeItem *item)
@@ -919,36 +1033,10 @@ int QDeclarativePathViewPrivate::calcCurrentIndex()
{
int current = -1;
if (model && items.count()) {
- _offset = qmlMod(_offset, qreal(1.0));
- if (_offset < 0)
- _offset += 1.0;
-
- if (pathItems == -1) {
- qreal delta = qmlMod(_offset - snapPos, qreal(1.0));
- if (delta < 0)
- delta = 1.0 + delta;
- int ii = model->count() - qRound(delta * model->count());
- if (ii < 0)
- ii = 0;
- current = ii;
- } else {
- qreal bestDiff=1e9;
- int bestI=-1;
- for (int i=0; i<items.count(); i++){
- qreal percent = qreal(i) / items.count();
- percent = percent + _offset;
- percent = qmlMod(percent, qreal(1.0));
- qreal diff = qAbs(snapPos - percent);
- if (diff < bestDiff){
- bestDiff = diff;
- bestI = i;
- }
- }
- int modelIndex = (bestI - pathOffset + items.count())%items.count();
- modelIndex += firstIndex;
- current = modelIndex;
- }
- current = qAbs(current % model->count());
+ offset = qmlMod(offset, model->count());
+ if (offset < 0)
+ offset += model->count();
+ current = qRound(qAbs(qmlMod(model->count() - offset, model->count())));
}
return current;
@@ -1002,57 +1090,26 @@ void QDeclarativePathViewPrivate::snapToCurrent()
if (!model || model->count() <= 0)
return;
- int itemIndex = (currentIndex - firstIndex + model->count()) % model->count();
-
- //Rounds is the number of times round to make the current item visible
- int rounds = itemIndex / items.count();
- int otherWayRounds = (model->count() - (itemIndex)) / items.count();
- if (otherWayRounds < rounds)
- rounds = -otherWayRounds;
-
- itemIndex += pathOffset;
- if(model->count() % items.count() && itemIndex - model->count() + items.count() > 0){
- //When model.count() is not a multiple of pathItemCount we need to manually
- //fix the index so that going backwards one step works correctly.
- itemIndex = itemIndex - model->count() + items.count();
- }
- itemIndex %= items.count();
- qreal targetOffset = qmlMod(1.0 + snapPos - qreal(itemIndex) / items.count(), qreal(1.0));
-
- if (targetOffset < 0)
- targetOffset = 1.0 + targetOffset;
- if (targetOffset == _offset && rounds == 0)
- return;
+ qreal targetOffset = model->count() - currentIndex;
moveReason = Other;
tl.clear();
- moveOffset.setValue(_offset);
-
- if (rounds!=0){
- //Compensate if the targetOffset would bring the target in from off the screen
- qreal distance = targetOffset - _offset;
- if (distance <= -0.5)
- rounds--;
- if (distance > 0.5)
- 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 > 0.5) {
- qreal distance = 1 - targetOffset + _offset;
- tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * _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));
+ moveOffset.setValue(offset);
+
+ const int duration = 300;
+
+ if (targetOffset - offset > model->count()/2) {
+ qreal distance = model->count() - targetOffset + offset;
+ tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * offset / distance));
+ tl.set(moveOffset, model->count());
+ tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * (model->count()-targetOffset) / distance));
+ } else if (targetOffset - offset <= -model->count()/2) {
+ qreal distance = model->count() - offset + targetOffset;
+ tl.move(moveOffset, model->count(), QEasingCurve(QEasingCurve::InQuad), int(duration * (model->count()-offset) / distance));
tl.set(moveOffset, 0.0);
- tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * targetOffset / distance));
+ tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * targetOffset / distance));
} else {
- tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), 200);
+ tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration);
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h
index 6dbd044..07b8f6f 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h
@@ -62,8 +62,15 @@ class Q_DECLARATIVE_EXPORT QDeclarativePathView : public QDeclarativeItem
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged)
Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition NOTIFY snapPositionChanged)
+
+ Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
+ Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
+
Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin NOTIFY dragMarginChanged)
- Q_PROPERTY(int count READ count)
+ Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged)
+ Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged)
+
+ Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount NOTIFY pathItemCountChanged)
@@ -86,9 +93,19 @@ public:
qreal snapPosition() const;
void setSnapPosition(qreal pos);
+ QDeclarativeComponent *highlight() const;
+ void setHighlight(QDeclarativeComponent *highlight);
+ QDeclarativeItem *highlightItem();
+
qreal dragMargin() const;
void setDragMargin(qreal margin);
+ qreal flickDeceleration() const;
+ void setFlickDeceleration(qreal dec);
+
+ bool isInteractive() const;
+ void setInteractive(bool);
+
int count() const;
QDeclarativeComponent *delegate() const;
@@ -103,11 +120,16 @@ Q_SIGNALS:
void currentIndexChanged();
void offsetChanged();
void modelChanged();
+ void countChanged();
void pathChanged();
void dragMarginChanged();
void snapPositionChanged();
void delegateChanged();
void pathItemCountChanged();
+ void flickDecelerationChanged();
+ void interactiveChanged();
+ void highlightChanged();
+ void highlightItemChanged();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
@@ -122,6 +144,7 @@ private Q_SLOTS:
void ticked();
void itemsInserted(int index, int count);
void itemsRemoved(int index, int count);
+ void itemsMoved(int,int,int);
void modelReset();
void createdItem(int index, QDeclarativeItem *item);
void destroyingItem(QDeclarativeItem *item);
diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
index 62f7d95..1780869 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
@@ -75,17 +75,18 @@ class QDeclarativePathViewPrivate : public QDeclarativeItemPrivate
public:
QDeclarativePathViewPrivate()
: path(0), currentIndex(0), startPc(0), lastDist(0)
- , lastElapsed(0), stealMouse(false), ownModel(false), activeItem(0)
- , snapPos(0), dragMargin(0), moveOffset(this, &QDeclarativePathViewPrivate::setOffset)
- , firstIndex(0), pathItems(-1), pathOffset(0), requestedIndex(-1)
- , moveReason(Other), attType(0)
+ , lastElapsed(0), mappedRange(1.0), stealMouse(false), ownModel(false), interactive(true)
+ , snapPos(0), dragMargin(0), deceleration(100)
+ , moveOffset(this, &QDeclarativePathViewPrivate::setOffset)
+ , firstIndex(-1), pathItems(-1), requestedIndex(-1)
+ , moveReason(Other), attType(0), highlightComponent(0), highlightItem(0)
{
}
void init()
{
Q_Q(QDeclarativePathView);
- _offset = 0;
+ offset = 0;
q->setAcceptedMouseButtons(Qt::LeftButton);
q->setFlag(QGraphicsItem::ItemIsFocusScope);
q->setFiltersChildEvents(true);
@@ -96,7 +97,10 @@ public:
void releaseItem(QDeclarativeItem *item);
QDeclarativePathViewAttached *attached(QDeclarativeItem *item);
void clear();
-
+ void updateMappedRange();
+ qreal positionOfIndex(int index) const;
+ void createHighlight();
+ void updateHighlight();
bool isValid() const {
return model && model->count() > 0 && model->isValid() && path;
}
@@ -117,19 +121,20 @@ public:
QPointF startPoint;
qreal lastDist;
int lastElapsed;
- qreal _offset;
+ qreal offset;
+ qreal mappedRange;
bool stealMouse : 1;
bool ownModel : 1;
+ bool interactive : 1;
QTime lastPosTime;
QPointF lastPos;
- QDeclarativeItem *activeItem;
qreal snapPos;
qreal dragMargin;
+ qreal deceleration;
QDeclarativeTimeLine tl;
QDeclarativeTimeLineValueProxy<QDeclarativePathViewPrivate> moveOffset;
int firstIndex;
int pathItems;
- int pathOffset;
int requestedIndex;
QList<QDeclarativeItem *> items;
QDeclarativeGuard<QDeclarativeVisualModel> model;
@@ -137,6 +142,8 @@ public:
enum MovementReason { Other, Key, Mouse };
MovementReason moveReason;
QDeclarativeOpenMetaObjectType *attType;
+ QDeclarativeComponent *highlightComponent;
+ QDeclarativeItem *highlightItem;
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
index ded58f5..7a0d33a 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
@@ -385,7 +385,7 @@ Column {
move: Transition {
NumberAnimation {
properties: "y"
- easing: "easeOutBounce"
+ easing.type: "OutBounce"
}
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp
index 207d05e..b82fb53 100644
--- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp
+++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp
@@ -470,7 +470,7 @@ void QDeclarativeRectangle::drawRect(QPainter &p)
QRectF QDeclarativeRectangle::boundingRect() const
{
Q_D(const QDeclarativeRectangle);
- return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2);
+ return QRectF(-d->paintmargin, -d->paintmargin, d->width()+d->paintmargin*2, d->height()+d->paintmargin*2);
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp
index 1acca2f..67750a4 100644
--- a/src/declarative/qml/qdeclarativecompiledbindings.cpp
+++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp
@@ -53,11 +53,15 @@
#include <QtCore/qnumeric.h>
#include <private/qdeclarativeanchors_p_p.h>
#include <private/qdeclarativeglobal_p.h>
+#include <private/qdeclarativefastproperties_p.h>
QT_BEGIN_NAMESPACE
DEFINE_BOOL_CONFIG_OPTION(qmlExperimental, QML_EXPERIMENTAL);
DEFINE_BOOL_CONFIG_OPTION(qmlDisableOptimizer, QML_DISABLE_OPTIMIZER);
+DEFINE_BOOL_CONFIG_OPTION(qmlDisableFastProperties, QML_DISABLE_FAST_PROPERTIES);
+
+Q_GLOBAL_STATIC(QDeclarativeFastProperties, fastProperties);
using namespace QDeclarativeJS;
@@ -334,6 +338,8 @@ struct Instr {
Subscribe, // subscribe
SubscribeId, // subscribe
+ FetchAndSubscribe, // fetchAndSubscribe
+
LoadId, // load
LoadScope, // load
LoadRoot, // load
@@ -433,6 +439,14 @@ struct Instr {
qint8 output;
qint8 objectReg;
quint8 exceptionId;
+ quint16 subscription;
+ quint16 function;
+ } fetchAndSubscribe;
+ struct {
+ quint8 type;
+ qint8 output;
+ qint8 objectReg;
+ quint8 exceptionId;
quint32 index;
} fetch;
struct {
@@ -937,6 +951,9 @@ static void dumpInstruction(const Instr *instr)
case Instr::SubscribeId:
qWarning().nospace() << "SubscribeId" << "\t\t" << instr->subscribe.offset << "\t" << instr->subscribe.reg << "\t" << instr->subscribe.index;
break;
+ case Instr::FetchAndSubscribe:
+ qWarning().nospace() << "FetchAndSubscribe" << "\t" << instr->fetchAndSubscribe.output << "\t" << instr->fetchAndSubscribe.objectReg << "\t" << instr->fetchAndSubscribe.subscription;
+ break;
case Instr::LoadId:
qWarning().nospace() << "LoadId" << "\t\t\t" << instr->load.index << "\t" << instr->load.reg;
break;
@@ -1070,6 +1087,8 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex,
QDeclarativeContextData *context, QDeclarativeDelayedError *error,
QObject *scope, QObject *output)
{
+ Q_Q(QDeclarativeCompiledBindings);
+
error->removeError();
Register registers[32];
@@ -1081,6 +1100,7 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex,
instr += instrIndex;
const char *data = program->data();
+ // return;
#ifdef COMPILEDBINDINGS_DEBUG
qWarning().nospace() << "Begin binding run";
#endif
@@ -1107,6 +1127,32 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex,
}
break;
+ case Instr::FetchAndSubscribe:
+ {
+ const Register &input = registers[instr->fetchAndSubscribe.objectReg];
+ Register &output = registers[instr->fetchAndSubscribe.output];
+
+ if (input.isUndefined()) {
+ throwException(instr->fetchAndSubscribe.exceptionId, error, program, context);
+ return;
+ }
+
+ QObject *object = input.getQObject();
+ if (!object) {
+ output.setUndefined();
+ } else {
+ int subIdx = instr->fetchAndSubscribe.subscription;
+ QDeclarativeCompiledBindingsPrivate::Subscription *sub = 0;
+ if (subIdx != -1) {
+ sub = (subscriptions + subIdx);
+ sub->target = q;
+ sub->targetMethod = methodCount + subIdx;
+ }
+ fastProperties()->accessor(instr->fetchAndSubscribe.function)(object, output.typeDataPtr(), sub);
+ }
+ }
+ break;
+
case Instr::LoadId:
registers[instr->load.reg].setQObject(context->idValues[instr->load.index].data());
break;
@@ -2376,29 +2422,41 @@ bool QDeclarativeBindingCompilerPrivate::buildName(QStringList &name,
return true;
}
-
bool QDeclarativeBindingCompilerPrivate::fetch(Result &rv, const QMetaObject *mo, int reg,
- int idx, const QStringList &subName, QDeclarativeJS::AST::ExpressionNode *node)
+ int idx, const QStringList &subName,
+ QDeclarativeJS::AST::ExpressionNode *node)
{
QMetaProperty prop = mo->property(idx);
rv.metaObject = 0;
rv.type = 0;
- if (subscription(subName, &rv) && prop.hasNotifySignal() && prop.notifySignalIndex() != -1) {
- Instr sub;
- sub.common.type = Instr::Subscribe;
- sub.subscribe.offset = subscriptionIndex(subName);
- sub.subscribe.reg = reg;
- sub.subscribe.index = prop.notifySignalIndex();
- bytecode << sub;
- }
+ int fastFetchIndex = fastProperties()->accessorIndexForProperty(mo, idx);
Instr fetch;
- fetch.common.type = Instr::Fetch;
- fetch.fetch.objectReg = reg;
- fetch.fetch.index = idx;
- fetch.fetch.output = reg;
- fetch.fetch.exceptionId = exceptionId(node);
+
+ if (!qmlDisableFastProperties() && fastFetchIndex != -1) {
+ fetch.common.type = Instr::FetchAndSubscribe;
+ fetch.fetchAndSubscribe.objectReg = reg;
+ fetch.fetchAndSubscribe.output = reg;
+ fetch.fetchAndSubscribe.function = fastFetchIndex;
+ fetch.fetchAndSubscribe.subscription = subscriptionIndex(subName);
+ fetch.fetchAndSubscribe.exceptionId = exceptionId(node);
+ } else {
+ if (subscription(subName, &rv) && prop.hasNotifySignal() && prop.notifySignalIndex() != -1) {
+ Instr sub;
+ sub.common.type = Instr::Subscribe;
+ sub.subscribe.offset = subscriptionIndex(subName);
+ sub.subscribe.reg = reg;
+ sub.subscribe.index = prop.notifySignalIndex();
+ bytecode << sub;
+ }
+
+ fetch.common.type = Instr::Fetch;
+ fetch.fetch.objectReg = reg;
+ fetch.fetch.index = idx;
+ fetch.fetch.output = reg;
+ fetch.fetch.exceptionId = exceptionId(node);
+ }
rv.type = prop.userType();
rv.metaObject = engine->metaObjectForType(rv.type);
diff --git a/src/declarative/qml/qdeclarativecompiledbindings_p.h b/src/declarative/qml/qdeclarativecompiledbindings_p.h
index 84a5df9..8776c08 100644
--- a/src/declarative/qml/qdeclarativecompiledbindings_p.h
+++ b/src/declarative/qml/qdeclarativecompiledbindings_p.h
@@ -60,7 +60,7 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-class QDeclarativeBindingCompilerPrivate;
+struct QDeclarativeBindingCompilerPrivate;
class QDeclarativeBindingCompiler
{
public:
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index e668553..c1f2fe6 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -1368,7 +1368,6 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl
const BindingContext &ctxt)
{
Q_ASSERT(obj->metaObject());
- Q_ASSERT(!prop->isEmpty());
QByteArray name = prop->name;
Q_ASSERT(name.startsWith("on"));
@@ -1387,7 +1386,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl
} else {
if (prop->value || prop->values.count() != 1)
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Incorrectly specified signal"));
+ COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Incorrectly specified signal assignment"));
prop->index = sigIdx;
obj->addSignalProperty(prop);
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index ab3849a..2b8cf70 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -361,22 +361,6 @@ QVariant QDeclarativeContext::contextProperty(const QString &name) const
return value;
}
-bool QDeclarativeContext::isSafeOrigin(const QUrl &src) const
-{
- if (src.isRelative())
- return true;
- if (src.scheme()==QLatin1String("https"))
- return true;
-
- QUrl base = baseUrl();
- if (src.host() == base.host() && src.port() == base.port()) // including files (with no host)
- return true;
-
- qWarning() << src << "is not a safe origin from" << base;
-
- return false;
-}
-
/*!
Resolves the URL \a src relative to the URL of the
containing component.
@@ -740,6 +724,21 @@ void QDeclarativeContextData::setIdPropertyData(QDeclarativeIntegerCache *data)
idValues = new ContextGuard[idValueCount];
}
+QString QDeclarativeContextData::findObjectId(const QObject *obj) const
+{
+ if (!idValues || !propertyNames)
+ return QString();
+
+ for (int i=0; i<idValueCount; i++) {
+ if (idValues[i] == obj)
+ return propertyNames->findId(i);
+ }
+
+ if (linkedContext)
+ return linkedContext->findObjectId(obj);
+ return QString();
+}
+
QDeclarativeContext *QDeclarativeContextData::asQDeclarativeContext()
{
if (!publicContext)
diff --git a/src/declarative/qml/qdeclarativecontext.h b/src/declarative/qml/qdeclarativecontext.h
index 959af8b..a349628 100644
--- a/src/declarative/qml/qdeclarativecontext.h
+++ b/src/declarative/qml/qdeclarativecontext.h
@@ -85,8 +85,6 @@ public:
void setBaseUrl(const QUrl &);
QUrl baseUrl() const;
- bool isSafeOrigin(const QUrl &src) const;
-
private:
friend class QDeclarativeVME;
friend class QDeclarativeEngine;
diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h
index f07045e..397f37a 100644
--- a/src/declarative/qml/qdeclarativecontext_p.h
+++ b/src/declarative/qml/qdeclarativecontext_p.h
@@ -190,6 +190,8 @@ public:
// Linked contexts. this owns linkedContext.
QDeclarativeContextData *linkedContext;
+ QString findObjectId(const QObject *obj) const;
+
static QDeclarativeContextData *get(QDeclarativeContext *context) {
return QDeclarativeContextPrivate::get(context)->data;
}
@@ -211,8 +213,11 @@ public:
inline operator QDeclarativeContextData*() const { return m_contextData; }
inline QDeclarativeContextData* operator->() const { return m_contextData; }
+ inline QDeclarativeGuardedContextData &operator=(QDeclarativeContextData *d);
private:
+ QDeclarativeGuardedContextData &operator=(const QDeclarativeGuardedContextData &);
+ QDeclarativeGuardedContextData(const QDeclarativeGuardedContextData &);
friend class QDeclarativeContextData;
inline void clear();
@@ -267,6 +272,13 @@ void QDeclarativeGuardedContextData::clear()
}
}
+QDeclarativeGuardedContextData &
+QDeclarativeGuardedContextData::operator=(QDeclarativeContextData *d)
+{
+ setContextData(d);
+ return *this;
+}
+
QT_END_NAMESPACE
#endif // QDECLARATIVECONTEXT_P_H
diff --git a/src/declarative/qml/qdeclarativedom.cpp b/src/declarative/qml/qdeclarativedom.cpp
index cb56ead..366750e 100644
--- a/src/declarative/qml/qdeclarativedom.cpp
+++ b/src/declarative/qml/qdeclarativedom.cpp
@@ -1107,8 +1107,7 @@ Rectangle {
x: NumberAnimation {
from: 0
to: 100
- repeat: true
- running: true
+ loops: Animation.Infinite
}
}
\endqml
@@ -1156,8 +1155,7 @@ Rectangle {
x: NumberAnimation {
from: 0
to: 100
- repeat: true
- running: true
+ loops: Animation.Infinite
}
}
\endqml
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 164fab7..0980b62 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -218,7 +218,6 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr
// XXX When the above a done some better way, that way should also be
// XXX used to add Qt.Sound class.
-
//types
qtObject.setProperty(QLatin1String("rgba"), newFunction(QDeclarativeEnginePrivate::rgba, 4));
qtObject.setProperty(QLatin1String("hsla"), newFunction(QDeclarativeEnginePrivate::hsla, 4));
diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp
index a377b35..d30aa8e 100644
--- a/src/declarative/qml/qdeclarativeenginedebug.cpp
+++ b/src/declarative/qml/qdeclarativeenginedebug.cpp
@@ -68,16 +68,16 @@ QDeclarativeEngineDebugServer::QDeclarativeEngineDebugServer(QObject *parent)
QDataStream &operator<<(QDataStream &ds,
const QDeclarativeEngineDebugServer::QDeclarativeObjectData &data)
{
- ds << data.url << data.lineNumber << data.columnNumber << data.objectName
- << data.objectType << data.objectId << data.contextId;
+ ds << data.url << data.lineNumber << data.columnNumber << data.idString
+ << data.objectName << data.objectType << data.objectId << data.contextId;
return ds;
}
QDataStream &operator>>(QDataStream &ds,
QDeclarativeEngineDebugServer::QDeclarativeObjectData &data)
{
- ds >> data.url >> data.lineNumber >> data.columnNumber >> data.objectName
- >> data.objectType >> data.objectId >> data.contextId;
+ ds >> data.url >> data.lineNumber >> data.columnNumber >> data.idString
+ >> data.objectName >> data.objectType >> data.objectId >> data.contextId;
return ds;
}
@@ -275,6 +275,13 @@ QDeclarativeEngineDebugServer::objectData(QObject *object)
rv.columnNumber = -1;
}
+ QDeclarativeContext *context = qmlContext(object);
+ if (context) {
+ QDeclarativeContextData *cdata = QDeclarativeContextData::get(context);
+ if (cdata)
+ rv.idString = cdata->findObjectId(object);
+ }
+
rv.objectName = object->objectName();
rv.objectId = QDeclarativeDebugService::idForObject(object);
rv.contextId = QDeclarativeDebugService::idForObject(qmlContext(object));
diff --git a/src/declarative/qml/qdeclarativeenginedebug_p.h b/src/declarative/qml/qdeclarativeenginedebug_p.h
index a95449b..9491411 100644
--- a/src/declarative/qml/qdeclarativeenginedebug_p.h
+++ b/src/declarative/qml/qdeclarativeenginedebug_p.h
@@ -75,6 +75,7 @@ public:
QUrl url;
int lineNumber;
int columnNumber;
+ QString idString;
QString objectName;
QString objectType;
int objectId;
diff --git a/src/declarative/qml/qdeclarativeintegercache.cpp b/src/declarative/qml/qdeclarativeintegercache.cpp
index 8fa210f..be36471 100644
--- a/src/declarative/qml/qdeclarativeintegercache.cpp
+++ b/src/declarative/qml/qdeclarativeintegercache.cpp
@@ -64,6 +64,16 @@ void QDeclarativeIntegerCache::clear()
engine = 0;
}
+QString QDeclarativeIntegerCache::findId(int value) const
+{
+ for (StringCache::ConstIterator iter = stringCache.begin();
+ iter != stringCache.end(); ++iter) {
+ if (iter.value() && iter.value()->value == value)
+ return iter.key();
+ }
+ return QString();
+}
+
void QDeclarativeIntegerCache::add(const QString &id, int value)
{
Q_ASSERT(!stringCache.contains(id));
diff --git a/src/declarative/qml/qdeclarativeintegercache_p.h b/src/declarative/qml/qdeclarativeintegercache_p.h
index b57565e..5fb5a76 100644
--- a/src/declarative/qml/qdeclarativeintegercache_p.h
+++ b/src/declarative/qml/qdeclarativeintegercache_p.h
@@ -73,6 +73,7 @@ public:
inline int count() const;
void add(const QString &, int);
int value(const QString &);
+ QString findId(int value) const;
inline int value(const QScriptDeclarativeClass::Identifier &id) const;
protected:
diff --git a/src/declarative/qml/qdeclarativelist.h b/src/declarative/qml/qdeclarativelist.h
index ed402a8..bd87990 100644
--- a/src/declarative/qml/qdeclarativelist.h
+++ b/src/declarative/qml/qdeclarativelist.h
@@ -54,6 +54,9 @@ QT_MODULE(Declarative)
class QObject;
struct QMetaObject;
+
+#ifndef QDECLARATIVELISTPROPERTY
+#define QDECLARATIVELISTPROPERTY
template<typename T>
struct QDeclarativeListProperty {
typedef void (*AppendFunction)(QDeclarativeListProperty<T> *, T*);
@@ -106,6 +109,7 @@ private:
return ((QList<T *> *)p->data)->clear();
}
};
+#endif
class QDeclarativeEngine;
class QDeclarativeListReferencePrivate;
diff --git a/src/declarative/qml/qdeclarativemetatype_p.h b/src/declarative/qml/qdeclarativemetatype_p.h
index e70b4bf..b3ec5e3 100644
--- a/src/declarative/qml/qdeclarativemetatype_p.h
+++ b/src/declarative/qml/qdeclarativemetatype_p.h
@@ -138,7 +138,7 @@ public:
int index() const;
private:
friend class QDeclarativeTypePrivate;
- friend class QDeclarativeMetaTypeData;
+ friend struct QDeclarativeMetaTypeData;
friend int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterInterface &);
friend int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &);
QDeclarativeType(int, const QDeclarativePrivate::RegisterInterface &);
diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri
index 49888c3..fc8ba50 100644
--- a/src/declarative/qml/qml.pri
+++ b/src/declarative/qml/qml.pri
@@ -31,6 +31,7 @@ SOURCES += \
$$PWD/qdeclarativerewrite.cpp \
$$PWD/qdeclarativevaluetype.cpp \
$$PWD/qdeclarativecompiledbindings.cpp \
+ $$PWD/qdeclarativefastproperties.cpp \
$$PWD/qdeclarativexmlhttprequest.cpp \
$$PWD/qdeclarativesqldatabase.cpp \
$$PWD/qmetaobjectbuilder.cpp \
@@ -103,6 +104,7 @@ HEADERS += \
$$PWD/qbitfield_p.h \
$$PWD/qdeclarativevaluetype_p.h \
$$PWD/qdeclarativecompiledbindings_p.h \
+ $$PWD/qdeclarativefastproperties_p.h \
$$PWD/qdeclarativexmlhttprequest_p.h \
$$PWD/qdeclarativesqldatabase_p.h \
$$PWD/qmetaobjectbuilder_p.h \
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp
index 1fb3d99..bad142c 100644
--- a/src/declarative/util/qdeclarativeanimation.cpp
+++ b/src/declarative/util/qdeclarativeanimation.cpp
@@ -190,9 +190,13 @@ void QDeclarativeAbstractAnimation::setRunning(bool r)
d->running = r;
if (d->running) {
- if (d->alwaysRunToEnd && d->repeat
+ if (d->alwaysRunToEnd && d->loopCount != 1
&& qtAnimation()->state() == QAbstractAnimation::Running) {
- qtAnimation()->setLoopCount(-1);
+ //we've restarted before the final loop finished; restore proper loop count
+ if (d->loopCount == -1)
+ qtAnimation()->setLoopCount(d->loopCount);
+ else
+ qtAnimation()->setLoopCount(qtAnimation()->currentLoop() + d->loopCount);
}
if (!d->connectedTimeLine) {
@@ -204,8 +208,8 @@ void QDeclarativeAbstractAnimation::setRunning(bool r)
emit started();
} else {
if (d->alwaysRunToEnd) {
- if (d->repeat)
- qtAnimation()->setLoopCount(qtAnimation()->currentLoop()+1);
+ if (d->loopCount != 1)
+ qtAnimation()->setLoopCount(qtAnimation()->currentLoop()+1); //finish the current loop
} else
qtAnimation()->stop();
@@ -300,10 +304,12 @@ void QDeclarativeAbstractAnimation::setAlwaysRunToEnd(bool f)
}
/*!
- \qmlproperty bool Animation::repeat
- This property holds whether the animation should repeat.
+ \qmlproperty int Animation::loops
+ This property holds the number of times the animation should play.
+
+ By default, \c loops is 1: the animation will play through once and then stop.
- If set, the animation will continuously repeat until it is explicitly
+ If set to Animation.Infinite, the animation will continuously repeat until it is explicitly
stopped - either by setting the \c running property to false, or by calling
the \c stop() method.
@@ -311,28 +317,36 @@ void QDeclarativeAbstractAnimation::setAlwaysRunToEnd(bool f)
\code
Rectangle {
- NumberAnimation on rotation { running: true; repeat: true; from: 0 to: 360 }
+ width: 100; height: 100; color: "green"
+ RotationAnimation on rotation {
+ loops: Animation.Infinite
+ from: 0
+ to: 360
+ }
}
\endcode
*/
-bool QDeclarativeAbstractAnimation::repeat() const
+int QDeclarativeAbstractAnimation::loops() const
{
Q_D(const QDeclarativeAbstractAnimation);
- return d->repeat;
+ return d->loopCount;
}
-void QDeclarativeAbstractAnimation::setRepeat(bool r)
+void QDeclarativeAbstractAnimation::setLoops(int loops)
{
Q_D(QDeclarativeAbstractAnimation);
- if (r == d->repeat)
+ if (loops < 0)
+ loops = -1;
+
+ if (loops == d->loopCount)
return;
- d->repeat = r;
- int lc = r ? -1 : 1;
- qtAnimation()->setLoopCount(lc);
- emit repeatChanged(r);
+ d->loopCount = loops;
+ qtAnimation()->setLoopCount(loops);
+ emit loopCountChanged(loops);
}
+
int QDeclarativeAbstractAnimation::currentTime()
{
return qtAnimation()->currentLoopTime();
@@ -509,8 +523,9 @@ void QDeclarativeAbstractAnimation::timelineComplete()
{
Q_D(QDeclarativeAbstractAnimation);
setRunning(false);
- if (d->alwaysRunToEnd && d->repeat) {
- qtAnimation()->setLoopCount(-1);
+ if (d->alwaysRunToEnd && d->loopCount != 1) {
+ //restore the proper loopCount for the next run
+ qtAnimation()->setLoopCount(d->loopCount);
}
}
@@ -658,6 +673,37 @@ void QDeclarativeColorAnimation::setTo(const QColor &t)
\inherits Animation
\brief The ScriptAction element allows scripts to be run during an animation.
+ ScriptAction can be used to run script at a specific point in an animation.
+
+ \qml
+ SequentialAnimation {
+ NumberAnimation { ... }
+ ScriptAction { script: doSomething(); }
+ NumberAnimation { ... }
+ }
+ \endqml
+
+ When used as part of a Transition, you can also target a specific
+ StateChangeScript to run using the \c scriptName property.
+
+ \qml
+ State {
+ StateChangeScript {
+ name: "myScript"
+ script: doStateStuff();
+ }
+ }
+ ...
+ Transition {
+ SequentialAnimation {
+ NumberAnimation { ... }
+ ScriptAction { scriptName: "myScript" }
+ NumberAnimation { ... }
+ }
+ }
+ \endqml
+
+ \sa StateChangeScript
*/
/*!
\internal
@@ -698,11 +744,14 @@ void QDeclarativeScriptAction::setScript(const QDeclarativeScriptString &script)
}
/*!
- \qmlproperty QString ScriptAction::stateChangeScriptName
+ \qmlproperty QString ScriptAction::scriptName
This property holds the the name of the StateChangeScript to run.
This property is only valid when ScriptAction is used as part of a transition.
- If both script and stateChangeScriptName are set, stateChangeScriptName will be used.
+ If both script and scriptName are set, scriptName will be used.
+
+ \note When using scriptName in a reversible transition, the script will only
+ be run when the transition is being run forwards.
*/
QString QDeclarativeScriptAction::stateChangeScriptName() const
{
@@ -718,6 +767,9 @@ void QDeclarativeScriptAction::setStateChangeScriptName(const QString &name)
void QDeclarativeScriptActionPrivate::execute()
{
+ if (hasRunScriptScript && reversing)
+ return;
+
QDeclarativeScriptString scriptStr = hasRunScriptScript ? runScriptScript : script;
const QString &str = scriptStr.script();
@@ -733,19 +785,18 @@ void QDeclarativeScriptAction::transition(QDeclarativeStateActions &actions,
{
Q_D(QDeclarativeScriptAction);
Q_UNUSED(modified);
- Q_UNUSED(direction);
d->hasRunScriptScript = false;
+ d->reversing = (direction == Backward);
for (int ii = 0; ii < actions.count(); ++ii) {
QDeclarativeAction &action = actions[ii];
if (action.event && action.event->typeName() == QLatin1String("StateChangeScript")
&& static_cast<QDeclarativeStateChangeScript*>(action.event)->name() == d->name) {
- //### how should we handle reverse direction?
d->runScriptScript = static_cast<QDeclarativeStateChangeScript*>(action.event)->script();
d->hasRunScriptScript = true;
action.actionDone = true;
- break; //assumes names are unique
+ break; //only match one (names should be unique)
}
}
}
@@ -1318,8 +1369,8 @@ void QDeclarativeAnimationGroupPrivate::append_animation(QDeclarativeListPropert
{
QDeclarativeAnimationGroup *q = qobject_cast<QDeclarativeAnimationGroup *>(list->object);
if (q) {
- q->d_func()->animations.append(a);
a->setGroup(q);
+ QDeclarative_setParent_noEvent(a->qtAnimation(), q->d_func()->ag);
q->d_func()->ag->addAnimation(a->qtAnimation());
}
}
@@ -1550,7 +1601,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int
\qml
Rectangle {
SequentialAnimation on x {
- repeat: true
+ loops: Animation.Infinite
PropertyAnimation { to: 50 }
PropertyAnimation { to: 0 }
}
@@ -1959,7 +2010,7 @@ void QDeclarativePropertyAnimation::setProperties(const QString &prop)
id: theRect
width: 100; height: 100
color: Qt.rgba(0,0,1)
- NumberAnimation on x { to: 500; repeat: true } //animate theRect's x property
+ NumberAnimation on x { to: 500; loops: Animation.Infinite } //animate theRect's x property
Behavior on y { NumberAnimation {} } //animate theRect's y property
}
\endqml
diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h
index 356b015..816520e 100644
--- a/src/declarative/util/qdeclarativeanimation_p.h
+++ b/src/declarative/util/qdeclarativeanimation_p.h
@@ -70,24 +70,28 @@ class Q_AUTOTEST_EXPORT QDeclarativeAbstractAnimation : public QObject, public Q
Q_INTERFACES(QDeclarativeParserStatus)
Q_INTERFACES(QDeclarativePropertyValueSource)
+ Q_ENUMS(Loops)
Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
Q_PROPERTY(bool alwaysRunToEnd READ alwaysRunToEnd WRITE setAlwaysRunToEnd NOTIFY alwaysRunToEndChanged)
- Q_PROPERTY(bool repeat READ repeat WRITE setRepeat NOTIFY repeatChanged)
+ Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged)
Q_CLASSINFO("DefaultMethod", "start()")
public:
QDeclarativeAbstractAnimation(QObject *parent=0);
virtual ~QDeclarativeAbstractAnimation();
+ enum Loops { Infinite = -2 };
+
bool isRunning() const;
void setRunning(bool);
bool isPaused() const;
void setPaused(bool);
bool alwaysRunToEnd() const;
void setAlwaysRunToEnd(bool);
- bool repeat() const;
- void setRepeat(bool);
+
+ int loops() const;
+ void setLoops(int);
int currentTime();
void setCurrentTime(int);
@@ -106,8 +110,8 @@ Q_SIGNALS:
void completed();
void runningChanged(bool);
void pausedChanged(bool);
- void repeatChanged(bool);
void alwaysRunToEndChanged(bool);
+ void loopCountChanged(int);
public Q_SLOTS:
void restart();
@@ -163,7 +167,7 @@ class QDeclarativeScriptAction : public QDeclarativeAbstractAnimation
Q_DECLARE_PRIVATE(QDeclarativeScriptAction)
Q_PROPERTY(QDeclarativeScriptString script READ script WRITE setScript)
- Q_PROPERTY(QString stateChangeScriptName READ stateChangeScriptName WRITE setStateChangeScriptName)
+ Q_PROPERTY(QString scriptName READ stateChangeScriptName WRITE setStateChangeScriptName)
public:
QDeclarativeScriptAction(QObject *parent=0);
diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h
index 55aacfa..3908e50 100644
--- a/src/declarative/util/qdeclarativeanimation_p_p.h
+++ b/src/declarative/util/qdeclarativeanimation_p_p.h
@@ -225,19 +225,21 @@ class QDeclarativeAbstractAnimationPrivate : public QObjectPrivate
Q_DECLARE_PUBLIC(QDeclarativeAbstractAnimation)
public:
QDeclarativeAbstractAnimationPrivate()
- : running(false), paused(false), alwaysRunToEnd(false), repeat(false),
+ : running(false), paused(false), alwaysRunToEnd(false),
connectedTimeLine(false), componentComplete(true),
- avoidPropertyValueSourceStart(false), disableUserControl(false), group(0) {}
+ avoidPropertyValueSourceStart(false), disableUserControl(false),
+ loopCount(1), group(0) {}
bool running:1;
bool paused:1;
bool alwaysRunToEnd:1;
- bool repeat:1;
bool connectedTimeLine:1;
bool componentComplete:1;
bool avoidPropertyValueSourceStart:1;
bool disableUserControl:1;
+ int loopCount;
+
void commence();
QDeclarativeProperty defaultProperty;
@@ -264,7 +266,7 @@ class QDeclarativeScriptActionPrivate : public QDeclarativeAbstractAnimationPriv
Q_DECLARE_PUBLIC(QDeclarativeScriptAction)
public:
QDeclarativeScriptActionPrivate()
- : QDeclarativeAbstractAnimationPrivate(), hasRunScriptScript(false), proxy(this), rsa(0) {}
+ : QDeclarativeAbstractAnimationPrivate(), hasRunScriptScript(false), reversing(false), proxy(this), rsa(0) {}
void init();
@@ -272,6 +274,7 @@ public:
QString name;
QDeclarativeScriptString runScriptScript;
bool hasRunScriptScript;
+ bool reversing;
void execute();
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 340e9ac..3e25234 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -401,7 +401,7 @@ void QDeclarativeListModel::remove(int index)
values in \a dict.
\code
- FruitModel.insert(2, {"cost": 5.95, "name":"Pizza"})
+ fruitModel.insert(2, {"cost": 5.95, "name":"Pizza"})
\endcode
The \a index must be to an existing item in the list, or one past
@@ -437,7 +437,7 @@ void QDeclarativeListModel::insert(int index, const QScriptValue& valuemap)
to the end of the list:
\code
- FruitModel.move(0,FruitModel.count-3,3)
+ fruitModel.move(0,fruitModel.count-3,3)
\endcode
\sa append()
@@ -479,7 +479,7 @@ void QDeclarativeListModel::move(int from, int to, int n)
values in \a dict.
\code
- FruitModel.append({"cost": 5.95, "name":"Pizza"})
+ fruitModel.append({"cost": 5.95, "name":"Pizza"})
\endcode
\sa set() remove()
@@ -500,8 +500,8 @@ void QDeclarativeListModel::append(const QScriptValue& valuemap)
Returns the item at \a index in the list model.
\code
- FruitModel.append({"cost": 5.95, "name":"Jackfruit"})
- FruitModel.get(0).cost
+ fruitModel.append({"cost": 5.95, "name":"Jackfruit"})
+ fruitModel.get(0).cost
\endcode
The \a index must be an element in the list.
@@ -510,10 +510,10 @@ void QDeclarativeListModel::append(const QScriptValue& valuemap)
will also be models, and this get() method is used to access elements:
\code
- FruitModel.append(..., "attributes":
+ fruitModel.append(..., "attributes":
[{"name":"spikes","value":"7mm"},
{"name":"color","value":"green"}]);
- FruitModel.get(0).attributes.get(1).value; // == "green"
+ fruitModel.get(0).attributes.get(1).value; // == "green"
\endcode
\sa append()
@@ -536,7 +536,7 @@ QScriptValue QDeclarativeListModel::get(int index) const
are left unchanged.
\code
- FruitModel.set(3, {"cost": 5.95, "name":"Pizza"})
+ fruitModel.set(3, {"cost": 5.95, "name":"Pizza"})
\endcode
The \a index must be an element in the list.
@@ -574,7 +574,7 @@ void QDeclarativeListModel::set(int index, const QScriptValue& valuemap)
Changes the \a property of the item at \a index in the list model to \a value.
\code
- FruitModel.set(3, "cost", 5.95)
+ fruitModel.set(3, "cost", 5.95)
\endcode
The \a index must be an element in the list.
diff --git a/src/declarative/util/qdeclarativespringfollow.cpp b/src/declarative/util/qdeclarativespringfollow.cpp
index 1d69dd3..76d7c98 100644
--- a/src/declarative/util/qdeclarativespringfollow.cpp
+++ b/src/declarative/util/qdeclarativespringfollow.cpp
@@ -224,11 +224,11 @@ void QDeclarativeSpringFollowPrivate::stop()
color: "#00ff00"
y: 200 // initial value
SequentialAnimation on y {
- running: true
- repeat: true
+ loops: Animation.Infinite
NumberAnimation {
to: 200
- easing: "easeOutBounce(amplitude:100)"
+ easing.type: "OutBounce"
+ easing.amplitude: 100
duration: 2000
}
PauseAnimation { duration: 1000 }
diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp
index 163d220..3469136 100644
--- a/src/declarative/util/qdeclarativestateoperations.cpp
+++ b/src/declarative/util/qdeclarativestateoperations.cpp
@@ -494,9 +494,31 @@ public:
\qmlclass StateChangeScript QDeclarativeStateChangeScript
\brief The StateChangeScript element allows you to run a script in a state.
- The script specified will be run immediately when the state is made current.
- Alternatively you can use a ScriptAction to specify at which point in the transition
+ StateChangeScripts are run when entering the state. You can use
+ ScriptAction to specify at which point in the transition
you want the StateChangeScript to be run.
+
+ \qml
+ State {
+ name "state1"
+ StateChangeScript {
+ name: "myScript"
+ script: doStateStuff();
+ }
+ ...
+ }
+ ...
+ Transition {
+ to: "state1"
+ SequentialAnimation {
+ NumberAnimation { ... }
+ ScriptAction { scriptName: "myScript" }
+ NumberAnimation { ... }
+ }
+ }
+ \endqml
+
+ \sa ScriptAction
*/
QDeclarativeStateChangeScript::QDeclarativeStateChangeScript(QObject *parent)
@@ -587,209 +609,343 @@ QString QDeclarativeStateChangeScript::typeName() const
For more information on anchors see \l {anchor-layout}{Anchor Layouts}.
*/
-
-
-class QDeclarativeAnchorChangesPrivate : public QObjectPrivate
+class QDeclarativeAnchorSetPrivate : public QObjectPrivate
{
+ Q_DECLARE_PUBLIC(QDeclarativeAnchorSet)
public:
- QDeclarativeAnchorChangesPrivate() : target(0) {}
+ QDeclarativeAnchorSetPrivate()
+ : usedAnchors(0), fill(0),
+ centerIn(0)/*, leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
+ margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)*/
+ {
+ }
- QDeclarativeItem *target;
- QString resetString;
+ QDeclarativeAnchors::UsedAnchors usedAnchors;
+ //### change to QDeclarativeAnchors::UsedAnchors resetAnchors
QStringList resetList;
+ QDeclarativeItem *fill;
+ QDeclarativeItem *centerIn;
+
QDeclarativeAnchorLine left;
QDeclarativeAnchorLine right;
- QDeclarativeAnchorLine horizontalCenter;
QDeclarativeAnchorLine top;
QDeclarativeAnchorLine bottom;
- QDeclarativeAnchorLine verticalCenter;
+ QDeclarativeAnchorLine vCenter;
+ QDeclarativeAnchorLine hCenter;
QDeclarativeAnchorLine baseline;
- QDeclarativeAnchorLine origLeft;
- QDeclarativeAnchorLine origRight;
- QDeclarativeAnchorLine origHCenter;
- QDeclarativeAnchorLine origTop;
- QDeclarativeAnchorLine origBottom;
- QDeclarativeAnchorLine origVCenter;
- QDeclarativeAnchorLine origBaseline;
-
- QDeclarativeAnchorLine rewindLeft;
- QDeclarativeAnchorLine rewindRight;
- QDeclarativeAnchorLine rewindHCenter;
- QDeclarativeAnchorLine rewindTop;
- QDeclarativeAnchorLine rewindBottom;
- QDeclarativeAnchorLine rewindVCenter;
- QDeclarativeAnchorLine rewindBaseline;
+ /*qreal leftMargin;
+ qreal rightMargin;
+ qreal topMargin;
+ qreal bottomMargin;
+ qreal margins;
+ qreal vCenterOffset;
+ qreal hCenterOffset;
+ qreal baselineOffset;*/
+};
- qreal fromX;
- qreal fromY;
- qreal fromWidth;
- qreal fromHeight;
+QDeclarativeAnchorSet::QDeclarativeAnchorSet(QObject *parent)
+ : QObject(*new QDeclarativeAnchorSetPrivate, parent)
+{
+}
- qreal toX;
- qreal toY;
- qreal toWidth;
- qreal toHeight;
+QDeclarativeAnchorSet::~QDeclarativeAnchorSet()
+{
+}
- qreal rewindX;
- qreal rewindY;
- qreal rewindWidth;
- qreal rewindHeight;
+QDeclarativeAnchorLine QDeclarativeAnchorSet::top() const
+{
+ Q_D(const QDeclarativeAnchorSet);
+ return d->top;
+}
- bool applyOrigLeft;
- bool applyOrigRight;
- bool applyOrigHCenter;
- bool applyOrigTop;
- bool applyOrigBottom;
- bool applyOrigVCenter;
- bool applyOrigBaseline;
-};
+void QDeclarativeAnchorSet::setTop(const QDeclarativeAnchorLine &edge)
+{
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasTopAnchor;
+ d->top = edge;
+}
-/*!
- \qmlproperty Item AnchorChanges::target
- This property holds the Item whose anchors will change
-*/
+void QDeclarativeAnchorSet::resetTop()
+{
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasTopAnchor;
+ d->top = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("top");
+}
-QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent)
- : QDeclarativeStateOperation(*(new QDeclarativeAnchorChangesPrivate), parent)
+QDeclarativeAnchorLine QDeclarativeAnchorSet::bottom() const
{
+ Q_D(const QDeclarativeAnchorSet);
+ return d->bottom;
}
-QDeclarativeAnchorChanges::~QDeclarativeAnchorChanges()
+void QDeclarativeAnchorSet::setBottom(const QDeclarativeAnchorLine &edge)
{
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasBottomAnchor;
+ d->bottom = edge;
}
-QDeclarativeAnchorChanges::ActionList QDeclarativeAnchorChanges::actions()
+void QDeclarativeAnchorSet::resetBottom()
{
- QDeclarativeAction a;
- a.event = this;
- return ActionList() << a;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasBottomAnchor;
+ d->bottom = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("bottom");
}
-QDeclarativeItem *QDeclarativeAnchorChanges::object() const
+QDeclarativeAnchorLine QDeclarativeAnchorSet::verticalCenter() const
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->target;
+ Q_D(const QDeclarativeAnchorSet);
+ return d->vCenter;
}
-void QDeclarativeAnchorChanges::setObject(QDeclarativeItem *target)
+void QDeclarativeAnchorSet::setVerticalCenter(const QDeclarativeAnchorLine &edge)
{
- Q_D(QDeclarativeAnchorChanges);
- d->target = target;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasVCenterAnchor;
+ d->vCenter = edge;
}
-QString QDeclarativeAnchorChanges::reset() const
+void QDeclarativeAnchorSet::resetVerticalCenter()
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->resetString;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasVCenterAnchor;
+ d->vCenter = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("verticalCenter");
}
-void QDeclarativeAnchorChanges::setReset(const QString &reset)
+QDeclarativeAnchorLine QDeclarativeAnchorSet::baseline() const
{
- Q_D(QDeclarativeAnchorChanges);
- d->resetString = reset;
- d->resetList = d->resetString.split(QLatin1Char(','));
- for (int i = 0; i < d->resetList.count(); ++i)
- d->resetList[i] = d->resetList.at(i).trimmed();
+ Q_D(const QDeclarativeAnchorSet);
+ return d->baseline;
}
-/*!
- \qmlproperty AnchorLine AnchorChanges::left
- \qmlproperty AnchorLine AnchorChanges::right
- \qmlproperty AnchorLine AnchorChanges::horizontalCenter
- \qmlproperty AnchorLine AnchorChanges::top
- \qmlproperty AnchorLine AnchorChanges::bottom
- \qmlproperty AnchorLine AnchorChanges::verticalCenter
- \qmlproperty AnchorLine AnchorChanges::baseline
+void QDeclarativeAnchorSet::setBaseline(const QDeclarativeAnchorLine &edge)
+{
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasBaselineAnchor;
+ d->baseline = edge;
+}
- These properties change the respective anchors of the item.
-*/
+void QDeclarativeAnchorSet::resetBaseline()
+{
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasBaselineAnchor;
+ d->baseline = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("baseline");
+}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::left() const
+QDeclarativeAnchorLine QDeclarativeAnchorSet::left() const
{
- Q_D(const QDeclarativeAnchorChanges);
+ Q_D(const QDeclarativeAnchorSet);
return d->left;
}
-void QDeclarativeAnchorChanges::setLeft(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorSet::setLeft(const QDeclarativeAnchorLine &edge)
{
- Q_D(QDeclarativeAnchorChanges);
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasLeftAnchor;
d->left = edge;
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::right() const
+void QDeclarativeAnchorSet::resetLeft()
{
- Q_D(const QDeclarativeAnchorChanges);
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasLeftAnchor;
+ d->left = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("left");
+}
+
+QDeclarativeAnchorLine QDeclarativeAnchorSet::right() const
+{
+ Q_D(const QDeclarativeAnchorSet);
return d->right;
}
-void QDeclarativeAnchorChanges::setRight(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorSet::setRight(const QDeclarativeAnchorLine &edge)
{
- Q_D(QDeclarativeAnchorChanges);
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasRightAnchor;
d->right = edge;
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::horizontalCenter() const
+void QDeclarativeAnchorSet::resetRight()
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->horizontalCenter;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasRightAnchor;
+ d->right = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("right");
}
-void QDeclarativeAnchorChanges::setHorizontalCenter(const QDeclarativeAnchorLine &edge)
+QDeclarativeAnchorLine QDeclarativeAnchorSet::horizontalCenter() const
{
- Q_D(QDeclarativeAnchorChanges);
- d->horizontalCenter = edge;
+ Q_D(const QDeclarativeAnchorSet);
+ return d->hCenter;
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::top() const
+void QDeclarativeAnchorSet::setHorizontalCenter(const QDeclarativeAnchorLine &edge)
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->top;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasHCenterAnchor;
+ d->hCenter = edge;
}
-void QDeclarativeAnchorChanges::setTop(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorSet::resetHorizontalCenter()
{
- Q_D(QDeclarativeAnchorChanges);
- d->top = edge;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasHCenterAnchor;
+ d->hCenter = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("horizontalCenter");
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::bottom() const
+QDeclarativeItem *QDeclarativeAnchorSet::fill() const
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->bottom;
+ Q_D(const QDeclarativeAnchorSet);
+ return d->fill;
}
-void QDeclarativeAnchorChanges::setBottom(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorSet::setFill(QDeclarativeItem *f)
{
- Q_D(QDeclarativeAnchorChanges);
- d->bottom = edge;
+ Q_D(QDeclarativeAnchorSet);
+ d->fill = f;
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::verticalCenter() const
+void QDeclarativeAnchorSet::resetFill()
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->verticalCenter;
+ setFill(0);
+}
+
+QDeclarativeItem *QDeclarativeAnchorSet::centerIn() const
+{
+ Q_D(const QDeclarativeAnchorSet);
+ return d->centerIn;
+}
+
+void QDeclarativeAnchorSet::setCenterIn(QDeclarativeItem* c)
+{
+ Q_D(QDeclarativeAnchorSet);
+ d->centerIn = c;
}
-void QDeclarativeAnchorChanges::setVerticalCenter(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorSet::resetCenterIn()
+{
+ setCenterIn(0);
+}
+
+
+class QDeclarativeAnchorChangesPrivate : public QObjectPrivate
+{
+public:
+ QDeclarativeAnchorChangesPrivate()
+ : target(0), anchorSet(new QDeclarativeAnchorSet) {}
+ ~QDeclarativeAnchorChangesPrivate() { delete anchorSet; }
+
+ QDeclarativeItem *target;
+ QDeclarativeAnchorSet *anchorSet;
+
+ QDeclarativeAnchorLine origLeft;
+ QDeclarativeAnchorLine origRight;
+ QDeclarativeAnchorLine origHCenter;
+ QDeclarativeAnchorLine origTop;
+ QDeclarativeAnchorLine origBottom;
+ QDeclarativeAnchorLine origVCenter;
+ QDeclarativeAnchorLine origBaseline;
+
+ QDeclarativeAnchorLine rewindLeft;
+ QDeclarativeAnchorLine rewindRight;
+ QDeclarativeAnchorLine rewindHCenter;
+ QDeclarativeAnchorLine rewindTop;
+ QDeclarativeAnchorLine rewindBottom;
+ QDeclarativeAnchorLine rewindVCenter;
+ QDeclarativeAnchorLine rewindBaseline;
+
+ qreal fromX;
+ 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;
+};
+
+/*!
+ \qmlproperty Item AnchorChanges::target
+ This property holds the Item whose anchors will change
+*/
+
+QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent)
+ : QDeclarativeStateOperation(*(new QDeclarativeAnchorChangesPrivate), parent)
+{
+}
+
+QDeclarativeAnchorChanges::~QDeclarativeAnchorChanges()
+{
+}
+
+QDeclarativeAnchorChanges::ActionList QDeclarativeAnchorChanges::actions()
+{
+ QDeclarativeAction a;
+ a.event = this;
+ return ActionList() << a;
+}
+
+QDeclarativeAnchorSet *QDeclarativeAnchorChanges::anchors()
{
Q_D(QDeclarativeAnchorChanges);
- d->verticalCenter = edge;
+ return d->anchorSet;
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::baseline() const
+QDeclarativeItem *QDeclarativeAnchorChanges::object() const
{
Q_D(const QDeclarativeAnchorChanges);
- return d->baseline;
+ return d->target;
}
-void QDeclarativeAnchorChanges::setBaseline(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorChanges::setObject(QDeclarativeItem *target)
{
Q_D(QDeclarativeAnchorChanges);
- d->baseline = edge;
+ d->target = target;
}
+/*!
+ \qmlproperty AnchorLine AnchorChanges::anchors.left
+ \qmlproperty AnchorLine AnchorChanges::anchors.right
+ \qmlproperty AnchorLine AnchorChanges::anchors.horizontalCenter
+ \qmlproperty AnchorLine AnchorChanges::anchors.top
+ \qmlproperty AnchorLine AnchorChanges::anchors.bottom
+ \qmlproperty AnchorLine AnchorChanges::anchors.verticalCenter
+ \qmlproperty AnchorLine AnchorChanges::anchors.baseline
+
+ These properties change the respective anchors of the item.
+
+ To reset an anchor you can assign \c undefined:
+ \qml
+ AnchorChanges {
+ target: myItem
+ left: undefined //remove myItem's left anchor
+ right: otherItem.right
+ }
+ \endqml
+*/
+
void QDeclarativeAnchorChanges::execute()
{
Q_D(QDeclarativeAnchorChanges);
@@ -813,36 +969,36 @@ void QDeclarativeAnchorChanges::execute()
d->target->anchors()->setBaseline(d->origBaseline);
//reset any anchors that have been specified
- if (d->resetList.contains(QLatin1String("left")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("left")))
d->target->anchors()->resetLeft();
- if (d->resetList.contains(QLatin1String("right")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("right")))
d->target->anchors()->resetRight();
- if (d->resetList.contains(QLatin1String("horizontalCenter")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("horizontalCenter")))
d->target->anchors()->resetHorizontalCenter();
- if (d->resetList.contains(QLatin1String("top")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("top")))
d->target->anchors()->resetTop();
- if (d->resetList.contains(QLatin1String("bottom")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("bottom")))
d->target->anchors()->resetBottom();
- if (d->resetList.contains(QLatin1String("verticalCenter")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("verticalCenter")))
d->target->anchors()->resetVerticalCenter();
- if (d->resetList.contains(QLatin1String("baseline")))
+ if (d->anchorSet->d_func()->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);
- if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setRight(d->right);
- if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setHorizontalCenter(d->horizontalCenter);
- if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setTop(d->top);
- if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setBottom(d->bottom);
- if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setVerticalCenter(d->verticalCenter);
- if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setBaseline(d->baseline);
+ if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setLeft(d->anchorSet->d_func()->left);
+ if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setRight(d->anchorSet->d_func()->right);
+ if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setHorizontalCenter(d->anchorSet->d_func()->hCenter);
+ if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setTop(d->anchorSet->d_func()->top);
+ if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setBottom(d->anchorSet->d_func()->bottom);
+ if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setVerticalCenter(d->anchorSet->d_func()->vCenter);
+ if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setBaseline(d->anchorSet->d_func()->baseline);
}
bool QDeclarativeAnchorChanges::isReversable()
@@ -857,19 +1013,19 @@ void QDeclarativeAnchorChanges::reverse()
return;
//reset any anchors set by the state
- if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetLeft();
- if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetRight();
- if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetHorizontalCenter();
- if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetTop();
- if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetBottom();
- if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetVerticalCenter();
- if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetBaseline();
//restore previous anchors
@@ -955,26 +1111,26 @@ void QDeclarativeAnchorChanges::copyOriginals(QDeclarativeActionEvent *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->applyOrigLeft = (acp->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("left")));
- d->applyOrigRight = (acp->right.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("right")));
+ d->applyOrigRight = (acp->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("right")));
- d->applyOrigHCenter = (acp->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("horizontalCenter")));
+ d->applyOrigHCenter = (acp->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("horizontalCenter")));
- d->applyOrigTop = (acp->top.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("top")));
+ d->applyOrigTop = (acp->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("top")));
- d->applyOrigBottom = (acp->bottom.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("bottom")));
+ d->applyOrigBottom = (acp->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("bottom")));
- d->applyOrigVCenter = (acp->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("verticalCenter")));
+ d->applyOrigVCenter = (acp->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("verticalCenter")));
- d->applyOrigBaseline = (acp->baseline.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("baseline")));
+ d->applyOrigBaseline = (acp->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("baseline")));
d->origLeft = ac->d_func()->origLeft;
d->origRight = ac->d_func()->origRight;
@@ -1012,35 +1168,35 @@ void QDeclarativeAnchorChanges::clearBindings()
d->target->anchors()->resetBaseline();
//reset any anchors that have been specified
- if (d->resetList.contains(QLatin1String("left")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("left")))
d->target->anchors()->resetLeft();
- if (d->resetList.contains(QLatin1String("right")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("right")))
d->target->anchors()->resetRight();
- if (d->resetList.contains(QLatin1String("horizontalCenter")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("horizontalCenter")))
d->target->anchors()->resetHorizontalCenter();
- if (d->resetList.contains(QLatin1String("top")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("top")))
d->target->anchors()->resetTop();
- if (d->resetList.contains(QLatin1String("bottom")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("bottom")))
d->target->anchors()->resetBottom();
- if (d->resetList.contains(QLatin1String("verticalCenter")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("verticalCenter")))
d->target->anchors()->resetVerticalCenter();
- if (d->resetList.contains(QLatin1String("baseline")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("baseline")))
d->target->anchors()->resetBaseline();
//reset any anchors that we'll be setting in the state
- if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetLeft();
- if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetRight();
- if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetHorizontalCenter();
- if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetTop();
- if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetBottom();
- if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetVerticalCenter();
- if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetBaseline();
}
diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h
index 66a8717..c97b2da 100644
--- a/src/declarative/util/qdeclarativestateoperations_p.h
+++ b/src/declarative/util/qdeclarativestateoperations_p.h
@@ -143,54 +143,132 @@ public:
virtual void execute();
};
-class QDeclarativeAnchorChangesPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent
+class QDeclarativeAnchorChanges;
+class QDeclarativeAnchorSetPrivate;
+class Q_AUTOTEST_EXPORT QDeclarativeAnchorSet : public QObject
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QDeclarativeAnchorChanges)
- Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject)
- Q_PROPERTY(QString reset READ reset WRITE setReset)
- Q_PROPERTY(QDeclarativeAnchorLine left READ left WRITE setLeft)
- Q_PROPERTY(QDeclarativeAnchorLine right READ right WRITE setRight)
- Q_PROPERTY(QDeclarativeAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter)
- Q_PROPERTY(QDeclarativeAnchorLine top READ top WRITE setTop)
- Q_PROPERTY(QDeclarativeAnchorLine bottom READ bottom WRITE setBottom)
- Q_PROPERTY(QDeclarativeAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter)
- Q_PROPERTY(QDeclarativeAnchorLine baseline READ baseline WRITE setBaseline)
+ Q_PROPERTY(QDeclarativeAnchorLine left READ left WRITE setLeft RESET resetLeft)
+ Q_PROPERTY(QDeclarativeAnchorLine right READ right WRITE setRight RESET resetRight)
+ Q_PROPERTY(QDeclarativeAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter)
+ Q_PROPERTY(QDeclarativeAnchorLine top READ top WRITE setTop RESET resetTop)
+ Q_PROPERTY(QDeclarativeAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom)
+ Q_PROPERTY(QDeclarativeAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter)
+ Q_PROPERTY(QDeclarativeAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline)
+ //Q_PROPERTY(QDeclarativeItem *fill READ fill WRITE setFill RESET resetFill)
+ //Q_PROPERTY(QDeclarativeItem *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn)
+
+ /*Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged)
+ Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged)
+ Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged)
+ Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged())
+ Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged)
+ Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
+ Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged())
+ Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged())*/
public:
- QDeclarativeAnchorChanges(QObject *parent=0);
- ~QDeclarativeAnchorChanges();
-
- virtual ActionList actions();
-
- QDeclarativeItem *object() const;
- void setObject(QDeclarativeItem *);
-
- QString reset() const;
- void setReset(const QString &);
+ QDeclarativeAnchorSet(QObject *parent=0);
+ virtual ~QDeclarativeAnchorSet();
QDeclarativeAnchorLine left() const;
void setLeft(const QDeclarativeAnchorLine &edge);
+ void resetLeft();
QDeclarativeAnchorLine right() const;
void setRight(const QDeclarativeAnchorLine &edge);
+ void resetRight();
QDeclarativeAnchorLine horizontalCenter() const;
void setHorizontalCenter(const QDeclarativeAnchorLine &edge);
+ void resetHorizontalCenter();
QDeclarativeAnchorLine top() const;
void setTop(const QDeclarativeAnchorLine &edge);
+ void resetTop();
QDeclarativeAnchorLine bottom() const;
void setBottom(const QDeclarativeAnchorLine &edge);
+ void resetBottom();
QDeclarativeAnchorLine verticalCenter() const;
void setVerticalCenter(const QDeclarativeAnchorLine &edge);
+ void resetVerticalCenter();
QDeclarativeAnchorLine baseline() const;
void setBaseline(const QDeclarativeAnchorLine &edge);
+ void resetBaseline();
+
+ QDeclarativeItem *fill() const;
+ void setFill(QDeclarativeItem *);
+ void resetFill();
+
+ QDeclarativeItem *centerIn() const;
+ void setCenterIn(QDeclarativeItem *);
+ void resetCenterIn();
+
+ /*qreal leftMargin() const;
+ void setLeftMargin(qreal);
+
+ qreal rightMargin() const;
+ void setRightMargin(qreal);
+
+ qreal horizontalCenterOffset() const;
+ void setHorizontalCenterOffset(qreal);
+
+ qreal topMargin() const;
+ void setTopMargin(qreal);
+
+ qreal bottomMargin() const;
+ void setBottomMargin(qreal);
+
+ qreal margins() const;
+ void setMargins(qreal);
+
+ qreal verticalCenterOffset() const;
+ void setVerticalCenterOffset(qreal);
+
+ qreal baselineOffset() const;
+ void setBaselineOffset(qreal);*/
+
+ QDeclarativeAnchors::UsedAnchors usedAnchors() const;
+
+/*Q_SIGNALS:
+ void leftMarginChanged();
+ void rightMarginChanged();
+ void topMarginChanged();
+ void bottomMarginChanged();
+ void marginsChanged();
+ void verticalCenterOffsetChanged();
+ void horizontalCenterOffsetChanged();
+ void baselineOffsetChanged();*/
+
+private:
+ friend class QDeclarativeAnchorChanges;
+ Q_DISABLE_COPY(QDeclarativeAnchorSet)
+ Q_DECLARE_PRIVATE(QDeclarativeAnchorSet)
+};
+
+class QDeclarativeAnchorChangesPrivate;
+class Q_DECLARATIVE_EXPORT QDeclarativeAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QDeclarativeAnchorChanges)
+
+ Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject)
+ Q_PROPERTY(QDeclarativeAnchorSet *anchors READ anchors CONSTANT)
+
+public:
+ QDeclarativeAnchorChanges(QObject *parent=0);
+ ~QDeclarativeAnchorChanges();
+
+ virtual ActionList actions();
+
+ QDeclarativeAnchorSet *anchors();
+
+ QDeclarativeItem *object() const;
+ void setObject(QDeclarativeItem *);
virtual void execute();
virtual bool isReversable();
@@ -212,6 +290,7 @@ QT_END_NAMESPACE
QML_DECLARE_TYPE(QDeclarativeParentChange)
QML_DECLARE_TYPE(QDeclarativeStateChangeScript)
+QML_DECLARE_TYPE(QDeclarativeAnchorSet)
QML_DECLARE_TYPE(QDeclarativeAnchorChanges)
QT_END_HEADER
diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp
index 46c9b73..2a02ffe 100644
--- a/src/declarative/util/qdeclarativeutilmodule.cpp
+++ b/src/declarative/util/qdeclarativeutilmodule.cpp
@@ -71,6 +71,38 @@
#include "qdeclarativexmllistmodel_p.h"
#endif
+template<typename T>
+int qmlRegisterTypeEnums(const char *qmlName)
+{
+ QByteArray name(T::staticMetaObject.className());
+
+ QByteArray pointerName(name + '*');
+ QByteArray listName("QDeclarativeListProperty<" + name + ">");
+
+ QDeclarativePrivate::RegisterType type = {
+ 0,
+
+ qRegisterMetaType<T *>(pointerName.constData()),
+ qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
+ 0, 0,
+
+ "Qt", 4, 6, qmlName, &T::staticMetaObject,
+
+ QDeclarativePrivate::attachedPropertiesFunc<T>(),
+ QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
+
+ QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(),
+ QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(),
+ QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(),
+
+ 0, 0,
+
+ 0
+ };
+
+ return QDeclarativePrivate::registerType(type);
+}
+
void QDeclarativeUtilModule::defineModule()
{
qmlRegisterType<QDeclarativeAnchorAnimation>("Qt",4,6,"AnchorAnimation");
@@ -107,8 +139,10 @@ void QDeclarativeUtilModule::defineModule()
#endif
qmlRegisterType<QDeclarativeAnchors>();
- qmlRegisterType<QDeclarativeAbstractAnimation>();
qmlRegisterType<QDeclarativeStateOperation>();
+ qmlRegisterType<QDeclarativeAnchorSet>();
+
+ qmlRegisterTypeEnums<QDeclarativeAbstractAnimation>("Animation");
qmlRegisterCustomType<QDeclarativeListModel>("Qt", 4,6, "ListModel", "QDeclarativeListModel",
new QDeclarativeListModelParser);
diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp
index c2dbf92..8e65151 100644
--- a/src/declarative/util/qdeclarativeview.cpp
+++ b/src/declarative/util/qdeclarativeview.cpp
@@ -129,6 +129,7 @@ class QDeclarativeViewPrivate
public:
QDeclarativeViewPrivate(QDeclarativeView *view)
: q(view), root(0), component(0), resizeMode(QDeclarativeView::SizeViewToRootObject) {}
+ ~QDeclarativeViewPrivate() { delete root; }
void execute();
@@ -270,7 +271,7 @@ void QDeclarativeViewPrivate::init()
*/
QDeclarativeView::~QDeclarativeView()
{
- delete d->root;
+ delete d;
}
/*! \property QDeclarativeView::source
@@ -447,8 +448,8 @@ void QDeclarativeView::setRootObject(QObject *obj)
d->root = item;
d->qmlRoot = item;
- connect(item, SIGNAL(widthChanged(qreal)), this, SLOT(sizeChanged()));
- connect(item, SIGNAL(heightChanged(qreal)), this, SLOT(sizeChanged()));
+ connect(item, SIGNAL(widthChanged()), this, SLOT(sizeChanged()));
+ connect(item, SIGNAL(heightChanged()), 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 01ae2ed..f7beeaa 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -46,6 +46,7 @@
#include <QDebug>
#include <QStringList>
+#include <QQueue>
#include <QApplication>
#include <QThread>
#include <QMutex>
@@ -59,9 +60,9 @@
#include <private/qobject_p.h>
-QT_BEGIN_NAMESPACE
-
+Q_DECLARE_METATYPE(QDeclarativeXmlQueryResult)
+QT_BEGIN_NAMESPACE
typedef QPair<int, int> QDeclarativeXmlListRange;
@@ -109,13 +110,25 @@ typedef QPair<int, int> QDeclarativeXmlListRange;
\sa XmlListModel
*/
+struct XmlQueryJob
+{
+ int queryId;
+ QByteArray data;
+ QString query;
+ QString namespaces;
+ QStringList roleQueries;
+ QStringList keyRoleQueries;
+ QStringList keyRoleResultsCache;
+};
+
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) {
+ : QThread(parent), m_quit(false), m_abortQueryId(-1), m_queryIds(0) {
+ qRegisterMetaType<QDeclarativeXmlQueryResult>("QDeclarativeXmlQueryResult");
}
~QDeclarativeXmlQuery() {
m_mutex.lock();
@@ -126,27 +139,38 @@ public:
wait();
}
- void abort() {
+ void abort(int id) {
QMutexLocker locker(&m_mutex);
- m_abort = true;
+ m_abortQueryId = id;
}
- int doQuery(QString query, QString namespaces, QByteArray data, QList<QDeclarativeXmlListModelRole *> *roleObjects) {
+ int doQuery(QString query, QString namespaces, QByteArray data, QList<QDeclarativeXmlListModelRole *> *roleObjects, QStringList keyRoleResultsCache) {
QMutexLocker locker(&m_mutex);
- m_size = 0;
- m_data = data;
- m_query = QLatin1String("doc($src)") + query;
- m_namespaces = namespaces;
- m_roleObjects = roleObjects;
- if (!isRunning()) {
- m_abort = false;
+
+ XmlQueryJob job;
+ job.queryId = m_queryIds;
+ job.data = data;
+ job.query = QLatin1String("doc($src)") + query;
+ job.namespaces = namespaces;
+ job.keyRoleResultsCache = keyRoleResultsCache;
+
+ for (int i=0; i<roleObjects->count(); i++) {
+ if (!roleObjects->at(i)->isValid()) {
+ job.roleQueries << "";
+ continue;
+ }
+ job.roleQueries << roleObjects->at(i)->query();
+ if (roleObjects->at(i)->isKey())
+ job.keyRoleQueries << job.roleQueries.last();
+ }
+ m_jobs.enqueue(job);
+ m_queryIds++;
+
+ if (!isRunning())
start();
- } else {
- m_restart = true;
+ else
m_condition.wakeOne();
- }
- m_queryId++;
- return m_queryId;
+ return job.queryId;
}
QList<QList<QVariant> > modelData() {
@@ -164,26 +188,33 @@ public:
return m_removedItemRanges;
}
+
Q_SIGNALS:
- void queryCompleted(int queryId, int size);
+ void queryCompleted(const QDeclarativeXmlQueryResult &);
protected:
void run() {
while (!m_quit) {
m_mutex.lock();
- int queryId = m_queryId;
doQueryJob();
doSubQueryJob();
- m_data.clear(); // no longer needed
m_mutex.unlock();
m_mutex.lock();
- if (!m_abort)
- emit queryCompleted(queryId, m_size);
- if (!m_restart)
+ const XmlQueryJob &job = m_jobs.dequeue();
+ if (m_abortQueryId != job.queryId) {
+ QDeclarativeXmlQueryResult r;
+ r.queryId = job.queryId;
+ r.size = m_size;
+ r.data = m_modelData;
+ r.inserted = m_insertedItemRanges;
+ r.removed = m_removedItemRanges;
+ r.keyRoleResultsCache = job.keyRoleResultsCache;
+ emit queryCompleted(r);
+ }
+ if (m_jobs.isEmpty())
m_condition.wait(&m_mutex);
- m_abort = false;
- m_restart = false;
+ m_abortQueryId = -1;
m_mutex.unlock();
}
}
@@ -197,30 +228,30 @@ private:
private:
QMutex m_mutex;
QWaitCondition m_condition;
+ QQueue<XmlQueryJob> m_jobs;
bool m_quit;
- bool m_restart;
- bool m_abort;
- QByteArray m_data;
- QString m_query;
- QString m_namespaces;
+ int m_abortQueryId;
QString m_prefix;
int m_size;
- int m_queryId;
- const QList<QDeclarativeXmlListModelRole *> *m_roleObjects;
+ int m_queryIds;
QList<QList<QVariant> > m_modelData;
- QStringList m_keysValues;
QList<QDeclarativeXmlListRange> m_insertedItemRanges;
QList<QDeclarativeXmlListRange> m_removedItemRanges;
};
+Q_GLOBAL_STATIC(QDeclarativeXmlQuery, globalXmlQuery)
+
void QDeclarativeXmlQuery::doQueryJob()
{
+ Q_ASSERT(!m_jobs.isEmpty());
+ XmlQueryJob &job = m_jobs.head();
+
QString r;
QXmlQuery query;
- QBuffer buffer(&m_data);
+ QBuffer buffer(&job.data);
buffer.open(QIODevice::ReadOnly);
query.bindVariable(QLatin1String("src"), &buffer);
- query.setQuery(m_namespaces + m_query);
+ query.setQuery(job.namespaces + job.query);
query.evaluateTo(&r);
//qDebug() << r;
@@ -231,9 +262,9 @@ void QDeclarativeXmlQuery::doQueryJob()
b.open(QIODevice::ReadOnly);
//qDebug() << xml;
- QString namespaces = QLatin1String("declare namespace dummy=\"http://qtsotware.com/dummy\";\n") + m_namespaces;
+ QString namespaces = QLatin1String("declare namespace dummy=\"http://qtsotware.com/dummy\";\n") + job.namespaces;
QString prefix = QLatin1String("doc($inputDocument)/dummy:items") +
- m_query.mid(m_query.lastIndexOf(QLatin1Char('/')));
+ job.query.mid(job.query.lastIndexOf(QLatin1Char('/')));
//figure out how many items we are dealing with
int count = -1;
@@ -249,19 +280,18 @@ void QDeclarativeXmlQuery::doQueryJob()
}
//qDebug() << count;
+ job.data = xml;
m_prefix = namespaces + prefix + QLatin1Char('/');
- m_data = xml;
+ m_size = 0;
if (count > 0)
m_size = count;
}
void QDeclarativeXmlQuery::getValuesOfKeyRoles(QStringList *values, QXmlQuery *query) const
{
- QStringList keysQueries;
- for (int i=0; i<m_roleObjects->count(); i++) {
- if (m_roleObjects->at(i)->isKey())
- keysQueries << m_roleObjects->at(i)->query();
- }
+ Q_ASSERT(!m_jobs.isEmpty());
+
+ const QStringList &keysQueries = m_jobs.head().keyRoleQueries;
QString keysQuery;
if (keysQueries.count() == 1)
keysQuery = m_prefix + keysQueries[0];
@@ -291,54 +321,58 @@ void QDeclarativeXmlQuery::addIndexToRangeList(QList<QDeclarativeXmlListRange> *
void QDeclarativeXmlQuery::doSubQueryJob()
{
+ Q_ASSERT(!m_jobs.isEmpty());
+ XmlQueryJob &job = m_jobs.head();
m_modelData.clear();
- QBuffer b(&m_data);
+ QBuffer b(&job.data);
b.open(QIODevice::ReadOnly);
QXmlQuery subquery;
subquery.bindVariable(QLatin1String("inputDocument"), &b);
- QStringList keysValues;
- getValuesOfKeyRoles(&keysValues, &subquery);
+ QStringList keyRoleResults;
+ getValuesOfKeyRoles(&keyRoleResults, &subquery);
// See if any values of key roles have been inserted or removed.
+
m_insertedItemRanges.clear();
m_removedItemRanges.clear();
- if (m_keysValues.isEmpty()) {
+ if (job.keyRoleResultsCache.isEmpty()) {
m_insertedItemRanges << qMakePair(0, m_size);
} else {
- if (keysValues != m_keysValues) {
+ if (keyRoleResults != job.keyRoleResultsCache) {
QStringList temp;
- for (int i=0; i<m_keysValues.count(); i++) {
- if (!keysValues.contains(m_keysValues[i]))
+ for (int i=0; i<job.keyRoleResultsCache.count(); i++) {
+ if (!keyRoleResults.contains(job.keyRoleResultsCache[i]))
addIndexToRangeList(&m_removedItemRanges, i);
else
- temp << m_keysValues[i];
+ temp << job.keyRoleResultsCache[i];
}
- for (int i=0; i<keysValues.count(); i++) {
- if (temp.count() == i || keysValues[i] != temp[i]) {
- temp.insert(i, keysValues[i]);
+ for (int i=0; i<keyRoleResults.count(); i++) {
+ if (temp.count() == i || keyRoleResults[i] != temp[i]) {
+ temp.insert(i, keyRoleResults[i]);
addIndexToRangeList(&m_insertedItemRanges, i);
}
}
}
}
- m_keysValues = keysValues;
+ job.keyRoleResultsCache = keyRoleResults;
+
// Get the new values for each role.
//### we might be able to condense even further (query for everything in one go)
- for (int i = 0; i < m_roleObjects->size(); ++i) {
- QDeclarativeXmlListModelRole *role = m_roleObjects->at(i);
- if (!role->isValid()) {
+ const QStringList &queries = job.roleQueries;
+ for (int i = 0; i < queries.size(); ++i) {
+ if (queries[i].isEmpty()) {
QList<QVariant> resultList;
for (int j = 0; j < m_size; ++j)
resultList << QVariant();
m_modelData << resultList;
continue;
}
- subquery.setQuery(m_prefix + QLatin1String("(let $v := ") + role->query() + QLatin1String(" return if ($v) then ") + role->query() + QLatin1String(" else \"\")"));
+ subquery.setQuery(m_prefix + QLatin1String("(let $v := ") + queries[i] + QLatin1String(" return if ($v) then ") + queries[i] + QLatin1String(" else \"\")"));
QXmlResultItems resultItems;
subquery.evaluateTo(&resultItems);
QXmlItem item(resultItems.next());
@@ -404,8 +438,8 @@ public:
QNetworkReply *reply;
QDeclarativeXmlListModel::Status status;
qreal progress;
- QDeclarativeXmlQuery qmlXmlQuery;
int queryId;
+ QStringList keyRoleResultsCache;
QList<QDeclarativeXmlListModelRole *> roleObjects;
static void append_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list, QDeclarativeXmlListModelRole *role);
static void clear_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list);
@@ -489,9 +523,8 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla
QDeclarativeXmlListModel::QDeclarativeXmlListModel(QObject *parent)
: QListModelInterface(*(new QDeclarativeXmlListModelPrivate), parent)
{
- Q_D(QDeclarativeXmlListModel);
- connect(&d->qmlXmlQuery, SIGNAL(queryCompleted(int,int)),
- this, SLOT(queryCompleted(int,int)));
+ connect(globalXmlQuery(), SIGNAL(queryCompleted(QDeclarativeXmlQueryResult)),
+ this, SLOT(queryCompleted(QDeclarativeXmlQueryResult)));
}
QDeclarativeXmlListModel::~QDeclarativeXmlListModel()
@@ -723,7 +756,7 @@ void QDeclarativeXmlListModel::reload()
if (!d->isComponentComplete)
return;
- d->qmlXmlQuery.abort();
+ globalXmlQuery()->abort(d->queryId);
d->queryId = -1;
int count = d->size;
@@ -755,7 +788,7 @@ void QDeclarativeXmlListModel::reload()
}
if (!d->xml.isEmpty()) {
- d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects);
+ d->queryId = globalXmlQuery()->doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects, d->keyRoleResultsCache);
d->progress = 1.0;
d->status = Ready;
emit progressChanged(d->progress);
@@ -802,7 +835,7 @@ void QDeclarativeXmlListModel::requestFinished()
} else {
d->status = Ready;
QByteArray data = d->reply->readAll();
- d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, data, &d->roleObjects);
+ d->queryId = globalXmlQuery()->doQuery(d->query, d->namespaces, data, &d->roleObjects, d->keyRoleResultsCache);
disconnect(d->reply, 0, this, 0);
d->reply->deleteLater();
d->reply = 0;
@@ -821,22 +854,20 @@ void QDeclarativeXmlListModel::requestProgress(qint64 received, qint64 total)
}
}
-void QDeclarativeXmlListModel::queryCompleted(int id, int size)
+void QDeclarativeXmlListModel::queryCompleted(const QDeclarativeXmlQueryResult &result)
{
Q_D(QDeclarativeXmlListModel);
- if (id != d->queryId)
+ if (result.queryId != d->queryId)
return;
- bool sizeChanged = size != d->size;
- d->size = size;
- d->data = d->qmlXmlQuery.modelData();
-
- 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);
- for (int i=0; i<inserted.count(); i++)
- emit itemsInserted(inserted[i].first, inserted[i].second);
+ bool sizeChanged = result.size != d->size;
+ d->size = result.size;
+ d->data = result.data;
+ d->keyRoleResultsCache = result.keyRoleResultsCache;
+
+ for (int i=0; i<result.removed.count(); i++)
+ emit itemsRemoved(result.removed[i].first, result.removed[i].second);
+ for (int i=0; i<result.inserted.count(); i++)
+ emit itemsInserted(result.inserted[i].first, result.inserted[i].second);
if (sizeChanged)
emit countChanged();
diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h
index 23ff7ce..7bb0f0e 100644
--- a/src/declarative/util/qdeclarativexmllistmodel_p.h
+++ b/src/declarative/util/qdeclarativexmllistmodel_p.h
@@ -46,6 +46,7 @@
#include <qdeclarativeinfo.h>
#include <QtCore/qurl.h>
+#include <QtCore/qstringlist.h>
#include <private/qlistmodelinterface_p.h>
@@ -56,10 +57,18 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeContext;
-
class QDeclarativeXmlListModelRole;
-
class QDeclarativeXmlListModelPrivate;
+
+struct QDeclarativeXmlQueryResult {
+ int queryId;
+ int size;
+ QList<QList<QVariant> > data;
+ QList<QPair<int, int> > inserted;
+ QList<QPair<int, int> > removed;
+ QStringList keyRoleResultsCache;
+};
+
class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModel : public QListModelInterface, public QDeclarativeParserStatus
{
Q_OBJECT
@@ -126,7 +135,7 @@ public Q_SLOTS:
private Q_SLOTS:
void requestFinished();
void requestProgress(qint64,qint64);
- void queryCompleted(int,int);
+ void queryCompleted(const QDeclarativeXmlQueryResult &);
private:
Q_DECLARE_PRIVATE(QDeclarativeXmlListModel)