Refactor QQuickPath componentComplete
authorMarco Bubke <marco.bubke@digia.com>
Wed, 24 Apr 2013 11:26:51 +0000 (13:26 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 24 Apr 2013 19:36:01 +0000 (21:36 +0200)
It is a prequel for the refactoring of the pathElements property.

Change-Id: I56cc4b9b419fecf96e331a6cab58b33157742e70
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Reviewed-by: Aurindam Jana <aurindam.jana@digia.com>
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
src/quick/util/qquickpath.cpp
src/quick/util/qquickpath_p.h
src/quick/util/qquickpath_p_p.h

index 3aea724..49b9e4c 100644 (file)
@@ -373,27 +373,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);
+
+    foreach (QQuickPathElement *pathElement, d->_pathElements)
+        connect(pathElement, SIGNAL(changed()), this, SLOT(processPath()));
+}
+
+void QQuickPath::gatherAttributes()
 {
     Q_D(QQuickPath);
-    QSet<QString> attrs;
-    d->componentComplete = true;
+
+    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
index 7154585..cbb8566 100644 (file)
@@ -393,6 +393,9 @@ Q_SIGNALS:
 protected:
     virtual void componentComplete();
     virtual void classBegin();
+    void disconnectPathElements();
+    void connectPathElements();
+    void gatherAttributes();
 
 private Q_SLOTS:
     void processPath();
index b4227e6..e376925 100644 (file)
@@ -67,6 +67,9 @@ class QQuickPathPrivate : public QObjectPrivate
     Q_DECLARE_PUBLIC(QQuickPath)
 
 public:
+    static QQuickPathPrivate* get(QQuickPath *path) { return path->d_func(); }
+    static const QQuickPathPrivate* get(const QQuickPath *path) { return path->d_func(); }
+
     QQuickPathPrivate() : pathLength(0), closed(false), componentComplete(true) { }
 
     QPainterPath _path;