Correctly set ending path percent if none is provided.
authorMichael Brasser <michael.brasser@nokia.com>
Fri, 29 Jul 2011 00:41:47 +0000 (10:41 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 29 Jul 2011 02:08:13 +0000 (04:08 +0200)
Task-number: QTBUG-19818
Change-Id: I5377551d041b593864d56e4449c133deb47d3b45
Reviewed-on: http://codereview.qt.nokia.com/2358
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/declarative/util/qdeclarativepath.cpp
tests/auto/declarative/qsgpathview/data/missingPercent.qml [new file with mode: 0644]
tests/auto/declarative/qsgpathview/tst_qsgpathview.cpp

index 3437e82..7b5d966 100644 (file)
@@ -208,6 +208,8 @@ void QDeclarativePath::endpoint(const QString &name)
     }
 }
 
+static QString percentString(QStringLiteral("_qfx_percent"));
+
 void QDeclarativePath::processPath()
 {
     Q_D(QDeclarativePath);
@@ -227,6 +229,7 @@ void QDeclarativePath::processPath()
     d->_path.moveTo(d->startX, d->startY);
 
     QDeclarativeCurve *lastCurve = 0;
+    bool usesPercent = false;
     foreach (QDeclarativePathElement *pathElement, d->_pathElements) {
         if (QDeclarativeCurve *curve = qobject_cast<QDeclarativeCurve *>(pathElement)) {
             curve->addToPath(d->_path);
@@ -240,8 +243,9 @@ void QDeclarativePath::processPath()
             interpolate(d->_attributePoints.count() - 1, attribute->name(), attribute->value());
         } else if (QDeclarativePathPercent *percent = qobject_cast<QDeclarativePathPercent *>(pathElement)) {
             AttributePoint &point = d->_attributePoints.last();
-            point.values[QLatin1String("_qfx_percent")] = percent->value();
-            interpolate(d->_attributePoints.count() - 1, QLatin1String("_qfx_percent"), percent->value());
+            point.values[percentString] = percent->value();
+            interpolate(d->_attributePoints.count() - 1, percentString, percent->value());
+            usesPercent = true;
         }
     }
 
@@ -251,6 +255,11 @@ void QDeclarativePath::processPath()
         if (!last.values.contains(d->_attributes.at(ii)))
             endpoint(d->_attributes.at(ii));
     }
+    if (usesPercent && !last.values.contains(percentString)) {
+        d->_attributePoints.last().values[percentString] = 1;
+        interpolate(d->_attributePoints.count() - 1, percentString, 1);
+    }
+
 
     // Adjust percent
     qreal length = d->_path.length();
@@ -258,14 +267,14 @@ void QDeclarativePath::processPath()
     qreal prevorigpercent = 0;
     for (int ii = 0; ii < d->_attributePoints.count(); ++ii) {
         const AttributePoint &point = d->_attributePoints.at(ii);
-        if (point.values.contains(QLatin1String("_qfx_percent"))) { //special string for QDeclarativePathPercent
+        if (point.values.contains(percentString)) { //special string for QDeclarativePathPercent
             if ( ii > 0) {
                 qreal scale = (d->_attributePoints[ii].origpercent/length - prevorigpercent) /
-                            (point.values.value(QLatin1String("_qfx_percent"))-prevpercent);
+                            (point.values.value(percentString)-prevpercent);
                 d->_attributePoints[ii].scale = scale;
             }
             d->_attributePoints[ii].origpercent /= length;
-            d->_attributePoints[ii].percent = point.values.value(QLatin1String("_qfx_percent"));
+            d->_attributePoints[ii].percent = point.values.value(percentString);
             prevorigpercent = d->_attributePoints[ii].origpercent;
             prevpercent = d->_attributePoints[ii].percent;
         } else {
diff --git a/tests/auto/declarative/qsgpathview/data/missingPercent.qml b/tests/auto/declarative/qsgpathview/data/missingPercent.qml
new file mode 100644 (file)
index 0000000..97af8e8
--- /dev/null
@@ -0,0 +1,9 @@
+import QtQuick 2.0
+
+Path {
+    startY: 0
+    startX: 0
+    PathLine { x: 0; y: 50 }
+    PathPercent { value: .5 }
+    PathLine { x: 50; y: 50 }
+}
index bc0448d..91f6491 100644 (file)
@@ -115,6 +115,7 @@ private slots:
     void mouseDrag();
     void treeModel();
     void changePreferredHighlight();
+    void missingPercent();
 
 private:
     QSGView *createView();
@@ -1072,6 +1073,17 @@ QList<T*> tst_QSGPathView::findItems(QSGItem *parent, const QString &objectName)
     return items;
 }
 
+void tst_QSGPathView::missingPercent()
+{
+    QDeclarativeEngine engine;
+    QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/missingPercent.qml"));
+    QDeclarativePath *obj = qobject_cast<QDeclarativePath*>(c.create());
+    QVERIFY(obj);
+    QCOMPARE(obj->attributeAt("_qfx_percent", 1.0), qreal(1.0));
+    delete obj;
+}
+
+
 QTEST_MAIN(tst_QSGPathView)
 
 #include "tst_qsgpathview.moc"