aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util/qquickpath.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-06-24 11:26:22 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2013-06-24 11:48:46 +0200
commit1a9759855639b9e2b3cdc0687d3381dcbf6c9815 (patch)
treeb2da51f6eddddb83c2d97cdcfac24d38d2e67a4e /src/quick/util/qquickpath.cpp
parent8217ec1b888f3ff93f004801b018c5f85362c484 (diff)
parente1fc2793aef53b84a3f1e19b6d6bdf1141340074 (diff)
Merge branch 'dev' of ssh://codereview.qt-project.org/qt/qtdeclarative into wip/v4
Conflicts: src/imports/qtquick2/plugins.qmltypes src/qml/debugger/qv8debugservice.cpp src/qml/qml/qml.pri src/qml/qml/qqmlcompiler.cpp src/qml/qml/qqmlcomponent.cpp src/qml/qml/qqmlcontext.cpp src/qml/qml/qqmldata_p.h src/qml/qml/qqmlengine_p.h src/qml/qml/qqmljavascriptexpression.cpp src/qml/qml/qqmlxmlhttprequest.cpp src/qml/qml/v4/qv4bindings.cpp src/qml/qml/v4/qv4irbuilder.cpp src/qml/qml/v4/qv4jsonobject_p.h src/qml/qml/v8/qqmlbuiltinfunctions.cpp src/qml/qml/v8/qv8bindings.cpp src/qml/qml/v8/qv8contextwrapper.cpp src/qml/qml/v8/qv8listwrapper.cpp src/qml/qml/v8/qv8qobjectwrapper.cpp src/qml/qml/v8/qv8qobjectwrapper_p.h src/qml/qml/v8/qv8sequencewrapper_p_p.h src/qml/qml/v8/qv8typewrapper.cpp src/qml/qml/v8/qv8valuetypewrapper.cpp src/qml/types/qqmldelegatemodel.cpp src/quick/items/context2d/qquickcanvasitem.cpp src/quick/items/context2d/qquickcontext2d.cpp sync.profile tests/auto/qml/qjsengine/tst_qjsengine.cpp tests/benchmarks/qml/animation/animation.pro tools/qmlprofiler/qmlprofiler.pro Change-Id: I18a76b8a81d87523247fa03a44ca334b1a2360c9
Diffstat (limited to 'src/quick/util/qquickpath.cpp')
-rw-r--r--src/quick/util/qquickpath.cpp109
1 files changed, 95 insertions, 14 deletions
diff --git a/src/quick/util/qquickpath.cpp b/src/quick/util/qquickpath.cpp
index 3aea724983..2278fd25ba 100644
--- a/src/quick/util/qquickpath.cpp
+++ b/src/quick/util/qquickpath.cpp
@@ -188,8 +188,67 @@ bool QQuickPath::hasEnd() const
QQmlListProperty<QQuickPathElement> QQuickPath::pathElements()
{
- Q_D(QQuickPath);
- return QQmlListProperty<QQuickPathElement>(this, d->_pathElements);
+ return QQmlListProperty<QQuickPathElement>(this,
+ 0,
+ pathElements_append,
+ pathElements_count,
+ pathElements_at,
+ pathElements_clear);
+}
+
+static QQuickPathPrivate *privatePath(QObject *object)
+{
+ QQuickPath *path = static_cast<QQuickPath*>(object);
+
+ return QQuickPathPrivate::get(path);
+}
+
+QQuickPathElement *QQuickPath::pathElements_at(QQmlListProperty<QQuickPathElement> *property, int index)
+{
+ QQuickPathPrivate *d = privatePath(property->object);
+
+ return d->_pathElements.at(index);
+}
+
+void QQuickPath::pathElements_append(QQmlListProperty<QQuickPathElement> *property, QQuickPathElement *pathElement)
+{
+ QQuickPathPrivate *d = privatePath(property->object);
+ QQuickPath *path = static_cast<QQuickPath*>(property->object);
+
+ d->_pathElements.append(pathElement);
+
+ if (d->componentComplete) {
+ QQuickCurve *curve = qobject_cast<QQuickCurve *>(pathElement);
+ if (curve)
+ d->_pathCurves.append(curve);
+ else {
+ QQuickPathAttribute *attribute = qobject_cast<QQuickPathAttribute *>(pathElement);
+ if (attribute && !d->_attributes.contains(attribute->name()))
+ d->_attributes.append(attribute->name());
+ }
+
+ path->processPath();
+
+ connect(pathElement, SIGNAL(changed()), path, SLOT(processPath()));
+ }
+}
+
+int QQuickPath::pathElements_count(QQmlListProperty<QQuickPathElement> *property)
+{
+ QQuickPathPrivate *d = privatePath(property->object);
+
+ return d->_pathElements.count();
+}
+
+void QQuickPath::pathElements_clear(QQmlListProperty<QQuickPathElement> *property)
+{
+ QQuickPathPrivate *d = privatePath(property->object);
+ QQuickPath *path = static_cast<QQuickPath*>(property->object);
+
+ path->disconnectPathElements();
+ d->_pathElements.clear();
+ d->_pathCurves.clear();
+ d->_pointCache.clear();
}
void QQuickPath::interpolate(int idx, const QString &name, qreal value)
@@ -373,27 +432,49 @@ void QQuickPath::classBegin()
d->componentComplete = false;
}
-void QQuickPath::componentComplete()
+void QQuickPath::disconnectPathElements()
+{
+ Q_D(QQuickPath);
+
+ foreach (QQuickPathElement *pathElement, d->_pathElements)
+ disconnect(pathElement, SIGNAL(changed()), this, SLOT(processPath()));
+}
+
+void QQuickPath::connectPathElements()
{
Q_D(QQuickPath);
- QSet<QString> attrs;
- d->componentComplete = true;
+
+ foreach (QQuickPathElement *pathElement, d->_pathElements)
+ connect(pathElement, SIGNAL(changed()), this, SLOT(processPath()));
+}
+
+void QQuickPath::gatherAttributes()
+{
+ Q_D(QQuickPath);
+
+ QSet<QString> attributes;
// First gather up all the attributes
foreach (QQuickPathElement *pathElement, d->_pathElements) {
- if (QQuickCurve *curve =
- qobject_cast<QQuickCurve *>(pathElement))
+ if (QQuickCurve *curve = qobject_cast<QQuickCurve *>(pathElement))
d->_pathCurves.append(curve);
- else if (QQuickPathAttribute *attribute =
- qobject_cast<QQuickPathAttribute *>(pathElement))
- attrs.insert(attribute->name());
+ else if (QQuickPathAttribute *attribute = qobject_cast<QQuickPathAttribute *>(pathElement))
+ attributes.insert(attribute->name());
}
- d->_attributes = attrs.toList();
+
+ d->_attributes = attributes.toList();
+}
+
+void QQuickPath::componentComplete()
+{
+ Q_D(QQuickPath);
+ d->componentComplete = true;
+
+ gatherAttributes();
processPath();
- foreach (QQuickPathElement *pathElement, d->_pathElements)
- connect(pathElement, SIGNAL(changed()), this, SLOT(processPath()));
+ connectPathElements();
}
QPainterPath QQuickPath::path() const
@@ -1465,7 +1546,7 @@ void QQuickPathCatmullRomCurve::addToPath(QPainterPath &path, const QQuickPathDa
nextData.curves = data.curves;
next = positionForCurve(nextData, point);
} else {
- if (point == QPointF(path.elementAt(0)) && qobject_cast<QQuickPathCatmullRomCurve*>(data.curves.at(0))) {
+ if (point == QPointF(path.elementAt(0)) && qobject_cast<QQuickPathCatmullRomCurve*>(data.curves.at(0)) && path.elementCount() >= 3) {
//this is a closed path starting and ending with catmull-rom segments.
//we try to smooth the join point
next = QPointF(path.elementAt(3)); //the first catmull-rom point