diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-09-02 22:28:43 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-09-03 17:33:32 +0200 |
commit | e81ff5732f7884c5c1d9efb1f63ac7ad0dabbcb5 (patch) | |
tree | d62afc29c40181e9818f760142bcf31fd6368431 /src/quick/util/qquickpath.cpp | |
parent | 45b1a3f97953fac65c6aef8e46abad865a0d0bc3 (diff) |
PathMultiline: handle directly-bound QVector<QPolygonF>
The autotest in 811b15bd161d12e5c85e093f9f492a0c4fa278d6 only tested
what happens if the vector of polygons is passed via a QVariant to the
PathMultiline paths property. But the intention (as documented) was to
literally support an object with Q_PROPERTY(QVector<QPolygonF> paths ...)
and binding that paths property to PathMultiline.paths. In that case
it appears in QQuickPathMultiline::setPaths() as a QVariant<QJSValue>,
canConvert<QVector<QPolygonF>>() returns false, then
canConvert<QVariantList>() returns true. Nevertheless each variant
in the QVariantList is a QPolygonF, as expected. So we need another
check to detect this case. Also added a test specifically for that.
Fixes: QTBUG-77929
Change-Id: I84d0a45326d5f007b8ba3cc9bb1fbccf0345d812
Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
Diffstat (limited to 'src/quick/util/qquickpath.cpp')
-rw-r--r-- | src/quick/util/qquickpath.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/quick/util/qquickpath.cpp b/src/quick/util/qquickpath.cpp index bebe9b2563..61319c388c 100644 --- a/src/quick/util/qquickpath.cpp +++ b/src/quick/util/qquickpath.cpp @@ -2566,14 +2566,20 @@ void QQuickPathMultiline::setPaths(const QVariant &paths) QVector<QVector<QPointF>> pathsList; QVariantList vll = paths.value<QVariantList>(); for (const QVariant &v : vll) { - QVariantList vl = v.value<QVariantList>(); - QVector<QPointF> l; - for (const QVariant &point : vl) { - if (point.canConvert<QPointF>()) - l.append(point.toPointF()); + // If we bind a QVector<QPolygonF> property directly, rather than via QVariant, + // it will come through as QJSValue that can be converted to QVariantList of QPolygonF. + if (v.canConvert<QPolygonF>()) { + pathsList.append(v.value<QPolygonF>()); + } else { + QVariantList vl = v.value<QVariantList>(); + QVector<QPointF> l; + for (const QVariant &point : vl) { + if (point.canConvert<QPointF>()) + l.append(point.toPointF()); + } + if (l.size() >= 2) + pathsList.append(l); } - if (l.size() >= 2) - pathsList.append(l); } setPaths(pathsList); } else { |