diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-01-06 06:57:06 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2011-01-06 06:57:06 (GMT) |
commit | 05b9137fe1974aa123ce6d9c16b733e1f77d8269 (patch) | |
tree | 6965ebdba00a655ee879bc969986cd24753c6823 | |
parent | 1ba3e41f09ea719249286fede5d3fe96621ccb61 (diff) | |
download | Qt-05b9137fe1974aa123ce6d9c16b733e1f77d8269.zip Qt-05b9137fe1974aa123ce6d9c16b733e1f77d8269.tar.gz Qt-05b9137fe1974aa123ce6d9c16b733e1f77d8269.tar.bz2 |
PathView crashed when the path is provided with undefined values.
Task-number: QTBUG-16356
Reviewed-by: Bea Lam
3 files changed, 38 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index 966c51b..e63a2c3 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -46,6 +46,8 @@ #include <QTime> #include <private/qbezier_p.h> +#include <QtCore/qmath.h> +#include <QtCore/qnumeric.h> QT_BEGIN_NAMESPACE @@ -367,9 +369,11 @@ void QDeclarativePath::createPointCache() const { Q_D(const QDeclarativePath); qreal pathLength = d->_path.length(); + if (pathLength <= 0 || qIsNaN(pathLength)) + return; // more points means less jitter between items as they move along the // path, but takes longer to generate - const int points = int(pathLength*5); + const int points = qCeil(pathLength*5); const int lastElement = d->_path.elementCount() - 1; d->_pointCache.resize(points+1); @@ -418,6 +422,8 @@ QPointF QDeclarativePath::pointAt(qreal p) const Q_D(const QDeclarativePath); if (d->_pointCache.isEmpty()) { createPointCache(); + if (d->_pointCache.isEmpty()) + return QPointF(); } int idx = qRound(p*d->_pointCache.size()); if (idx >= d->_pointCache.size()) diff --git a/tests/auto/declarative/qdeclarativepathview/data/undefinedpath.qml b/tests/auto/declarative/qdeclarativepathview/data/undefinedpath.qml new file mode 100644 index 0000000..5a647cb --- /dev/null +++ b/tests/auto/declarative/qdeclarativepathview/data/undefinedpath.qml @@ -0,0 +1,17 @@ +import QtQuick 1.0 + +PathView { + id: pathView + width: 240; height: 200 + path: Path { + startX: pathView.undef/2.0; startY: 0 + PathLine { x: pathView.undef/2.0; y: 0 } + } + + delegate: Text { text: value } + model: ListModel { + ListElement { value: "one" } + ListElement { value: "two" } + ListElement { value: "three" } + } +} diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index 90b1056..bd8baab 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -88,6 +88,7 @@ private slots: void closed(); void pathUpdate(); void visualDataModel(); + void undefinedPath(); private: QDeclarativeView *createView(); @@ -853,6 +854,19 @@ void tst_QDeclarativePathView::visualDataModel() delete obj; } +void tst_QDeclarativePathView::undefinedPath() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/undefinedpath.qml")); + + QDeclarativePathView *obj = qobject_cast<QDeclarativePathView*>(c.create()); + QVERIFY(obj != 0); + + QCOMPARE(obj->count(), 3); + + delete obj; +} + QDeclarativeView *tst_QDeclarativePathView::createView() { QDeclarativeView *canvas = new QDeclarativeView(0); |