From d08fb44d8f1414bbf519875fd872d742c41300ec Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 29 Jul 2011 10:41:47 +1000 Subject: Correctly set ending path percent if none is provided. Task-number: QTBUG-19818 Change-Id: I5377551d041b593864d56e4449c133deb47d3b45 Reviewed-on: http://codereview.qt.nokia.com/2358 Reviewed-by: Qt Sanity Bot Reviewed-by: Martin Jones --- src/declarative/util/qdeclarativepath.cpp | 19 ++++++++++++++----- .../declarative/qsgpathview/data/missingPercent.qml | 9 +++++++++ .../auto/declarative/qsgpathview/tst_qsgpathview.cpp | 12 ++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tests/auto/declarative/qsgpathview/data/missingPercent.qml diff --git a/src/declarative/util/qdeclarativepath.cpp b/src/declarative/util/qdeclarativepath.cpp index 3437e82d30..7b5d966719 100644 --- a/src/declarative/util/qdeclarativepath.cpp +++ b/src/declarative/util/qdeclarativepath.cpp @@ -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(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(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 index 0000000000..97af8e8982 --- /dev/null +++ b/tests/auto/declarative/qsgpathview/data/missingPercent.qml @@ -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 } +} diff --git a/tests/auto/declarative/qsgpathview/tst_qsgpathview.cpp b/tests/auto/declarative/qsgpathview/tst_qsgpathview.cpp index bc0448d767..91f6491493 100644 --- a/tests/auto/declarative/qsgpathview/tst_qsgpathview.cpp +++ b/tests/auto/declarative/qsgpathview/tst_qsgpathview.cpp @@ -115,6 +115,7 @@ private slots: void mouseDrag(); void treeModel(); void changePreferredHighlight(); + void missingPercent(); private: QSGView *createView(); @@ -1072,6 +1073,17 @@ QList 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(c.create()); + QVERIFY(obj); + QCOMPARE(obj->attributeAt("_qfx_percent", 1.0), qreal(1.0)); + delete obj; +} + + QTEST_MAIN(tst_QSGPathView) #include "tst_qsgpathview.moc" -- cgit v1.2.3