diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-09-04 01:00:31 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-09-04 01:00:31 +0200 |
commit | 42d1e82030151a0b1ab16746d82f261178477ccc (patch) | |
tree | b1d90a981588f1fd3ebacaa503b40213c4a3b338 /src | |
parent | 3c1b9cc4c86a4813994eab2111f5d7f91633f032 (diff) | |
parent | e81ff5732f7884c5c1d9efb1f63ac7ad0dabbcb5 (diff) |
Merge remote-tracking branch 'origin/5.14' into dev
Change-Id: Idade92fa5db03faee91c770a52131f35ab938ad7
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/parser/qqmljs.g | 19 | ||||
-rw-r--r-- | src/qml/parser/qqmljsast.cpp | 73 | ||||
-rw-r--r-- | src/quick/util/qquickpath.cpp | 118 | ||||
-rw-r--r-- | src/quick/util/qquickpath_p.h | 12 |
4 files changed, 126 insertions, 96 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index 6c9760e472..8ac7633ae0 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -1246,8 +1246,13 @@ UiObjectMember: T_DEFAULT T_PROPERTY T_IDENTIFIER T_LT UiPropertyType T_GT QmlId sym(1).Node = node; } break; ./ +OptionalSemicolon: | Semicolon; +/. +/* we need OptionalSemicolon because UiScriptStatement might already parse the last semicolon + and then we would miss a semicolon (see tests/auto/quick/qquickvisualdatamodel/data/objectlist.qml)*/ + ./ -UiObjectMember: T_PROPERTY UiPropertyType QmlIdentifier T_COLON UiScriptStatement; +UiObjectMember: T_PROPERTY UiPropertyType QmlIdentifier T_COLON UiScriptStatement OptionalSemicolon; /. case $rule_number: { AST::UiPublicMember *node = new (pool) AST::UiPublicMember(sym(2).UiQualifiedId->finish(), stringRef(3), sym(5).Statement); @@ -1259,7 +1264,7 @@ UiObjectMember: T_PROPERTY UiPropertyType QmlIdentifier T_COLON UiScriptStatemen } break; ./ -UiObjectMember: T_READONLY T_PROPERTY UiPropertyType QmlIdentifier T_COLON UiScriptStatement; +UiObjectMember: T_READONLY T_PROPERTY UiPropertyType QmlIdentifier T_COLON UiScriptStatement OptionalSemicolon; /. case $rule_number: { AST::UiPublicMember *node = new (pool) AST::UiPublicMember(sym(3).UiQualifiedId->finish(), stringRef(4), sym(6).Statement); @@ -1273,7 +1278,7 @@ UiObjectMember: T_READONLY T_PROPERTY UiPropertyType QmlIdentifier T_COLON UiScr } break; ./ -UiObjectMember: T_DEFAULT T_PROPERTY UiPropertyType QmlIdentifier T_COLON UiScriptStatement; +UiObjectMember: T_DEFAULT T_PROPERTY UiPropertyType QmlIdentifier T_COLON UiScriptStatement OptionalSemicolon; /. case $rule_number: { AST::UiPublicMember *node = new (pool) AST::UiPublicMember(sym(3).UiQualifiedId->finish(), stringRef(4), sym(6).Statement); @@ -1287,7 +1292,7 @@ UiObjectMember: T_DEFAULT T_PROPERTY UiPropertyType QmlIdentifier T_COLON UiScri } break; ./ -UiObjectMember: T_PROPERTY T_IDENTIFIER T_LT UiPropertyType T_GT QmlIdentifier T_COLON T_LBRACKET UiArrayMemberList T_RBRACKET; +UiObjectMember: T_PROPERTY T_IDENTIFIER T_LT UiPropertyType T_GT QmlIdentifier T_COLON T_LBRACKET UiArrayMemberList T_RBRACKET Semicolon; /. case $rule_number: { AST::UiPublicMember *node = new (pool) AST::UiPublicMember(sym(4).UiQualifiedId->finish(), stringRef(6)); @@ -1313,7 +1318,7 @@ UiObjectMember: T_PROPERTY T_IDENTIFIER T_LT UiPropertyType T_GT QmlIdentifier T } break; ./ -UiObjectMember: T_READONLY T_PROPERTY T_IDENTIFIER T_LT UiPropertyType T_GT QmlIdentifier T_COLON T_LBRACKET UiArrayMemberList T_RBRACKET; +UiObjectMember: T_READONLY T_PROPERTY T_IDENTIFIER T_LT UiPropertyType T_GT QmlIdentifier T_COLON T_LBRACKET UiArrayMemberList T_RBRACKET Semicolon; /. case $rule_number: { AST::UiPublicMember *node = new (pool) AST::UiPublicMember(sym(5).UiQualifiedId->finish(), stringRef(7)); @@ -1341,7 +1346,7 @@ UiObjectMember: T_READONLY T_PROPERTY T_IDENTIFIER T_LT UiPropertyType T_GT QmlI } break; ./ -UiObjectMember: T_PROPERTY UiPropertyType QmlIdentifier T_COLON ExpressionStatementLookahead UiQualifiedId UiObjectInitializer; +UiObjectMember: T_PROPERTY UiPropertyType QmlIdentifier T_COLON ExpressionStatementLookahead UiQualifiedId UiObjectInitializer Semicolon; /. case $rule_number: { AST::UiPublicMember *node = new (pool) AST::UiPublicMember(sym(2).UiQualifiedId->finish(), stringRef(3)); @@ -1364,7 +1369,7 @@ UiObjectMember: T_PROPERTY UiPropertyType QmlIdentifier T_COLON ExpressionStatem } break; ./ -UiObjectMember: T_READONLY T_PROPERTY UiPropertyType QmlIdentifier T_COLON ExpressionStatementLookahead UiQualifiedId UiObjectInitializer; +UiObjectMember: T_READONLY T_PROPERTY UiPropertyType QmlIdentifier T_COLON ExpressionStatementLookahead UiQualifiedId UiObjectInitializer Semicolon; /. case $rule_number: { AST::UiPublicMember *node = new (pool) AST::UiPublicMember(sym(3).UiQualifiedId->finish(), stringRef(4)); diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp index 700c191499..b63b2191b9 100644 --- a/src/qml/parser/qqmljsast.cpp +++ b/src/qml/parser/qqmljsast.cpp @@ -238,12 +238,11 @@ void StringLiteral::accept0(Visitor *visitor) void TemplateLiteral::accept0(Visitor *visitor) { - if (visitor->visit(this)) { - if (next) - accept(next, visitor); + bool accepted = true; + for (TemplateLiteral *it = this; it && accepted; it = it->next) { + accepted = visitor->visit(it); + visitor->endVisit(it); } - - visitor->endVisit(this); } void NumericLiteral::accept0(Visitor *visitor) @@ -1015,13 +1014,13 @@ BoundNames FormalParameterList::boundNames() const void FormalParameterList::accept0(Visitor *visitor) { - if (visitor->visit(this)) { - accept(element, visitor); - if (next) - accept(next, visitor); + bool accepted = true; + for (FormalParameterList *it = this; it && accepted; it = it->next) { + accepted = visitor->visit(it); + if (accepted) + accept(it->element, visitor); + visitor->endVisit(it); } - - visitor->endVisit(this); } FormalParameterList *FormalParameterList::finish(QQmlJS::MemoryPool *pool) @@ -1321,12 +1320,14 @@ void UiPragma::accept0(Visitor *visitor) void UiHeaderItemList::accept0(Visitor *visitor) { - if (visitor->visit(this)) { - accept(headerItem, visitor); - accept(next, visitor); - } + bool accepted = true; + for (UiHeaderItemList *it = this; it && accepted; it = it->next) { + accepted = visitor->visit(it); + if (accepted) + accept(it->headerItem, visitor); - visitor->endVisit(this); + visitor->endVisit(it); + } } @@ -1391,14 +1392,15 @@ void PatternElement::boundNames(BoundNames *names) void PatternElementList::accept0(Visitor *visitor) { - if (visitor->visit(this)) { - accept(elision, visitor); - accept(element, visitor); - if (next) - accept(next, visitor); + bool accepted = true; + for (PatternElementList *it = this; it && accepted; it = it->next) { + accepted = visitor->visit(it); + if (accepted) { + accept(it->elision, visitor); + accept(it->element, visitor); + } + visitor->endVisit(it); } - - visitor->endVisit(this); } void PatternElementList::boundNames(BoundNames *names) @@ -1428,13 +1430,13 @@ void PatternProperty::boundNames(BoundNames *names) void PatternPropertyList::accept0(Visitor *visitor) { - if (visitor->visit(this)) { - accept(property, visitor); - if (next) - accept(next, visitor); + bool accepted = true; + for (PatternPropertyList *it = this; it && accepted; it = it->next) { + accepted = visitor->visit(it); + if (accepted) + accept(it->property, visitor); + visitor->endVisit(it); } - - visitor->endVisit(this); } void PatternPropertyList::boundNames(BoundNames *names) @@ -1479,13 +1481,14 @@ void ClassDeclaration::accept0(Visitor *visitor) void ClassElementList::accept0(Visitor *visitor) { - if (visitor->visit(this)) { - accept(property, visitor); - if (next) - accept(next, visitor); - } + bool accepted = true; + for (ClassElementList *it = this; it && accepted; it = it->next) { + accepted = visitor->visit(it); + if (accepted) + accept(it->property, visitor); - visitor->endVisit(this); + visitor->endVisit(it); + } } ClassElementList *ClassElementList::finish() diff --git a/src/quick/util/qquickpath.cpp b/src/quick/util/qquickpath.cpp index d246ee7910..61319c388c 100644 --- a/src/quick/util/qquickpath.cpp +++ b/src/quick/util/qquickpath.cpp @@ -2397,32 +2397,42 @@ void QQuickPathPercent::setValue(qreal value) \qmlproperty list<point> QtQuick::PathPolyline::path This property defines the vertices of the polyline. + + It can be a JS array of points constructed with \c Qt.point(), + a QList or QVector of QPointF, or QPolygonF. + If you are binding this to a custom property in some C++ object, + QPolygonF is the most appropriate type to use. */ QQuickPathPolyline::QQuickPathPolyline(QObject *parent) : QQuickCurve(parent) { } -QVariantList QQuickPathPolyline::path() const +QVariant QQuickPathPolyline::path() const { - QVariantList res; - for (int i = 0; i < m_path.length(); ++i) { - const QPointF &c = m_path.at(i); - res.append(QVariant::fromValue(c)); - } - - return res; + return QVariant::fromValue(m_path); } -void QQuickPathPolyline::setPath(const QVariantList &path) +void QQuickPathPolyline::setPath(const QVariant &path) { - QVector<QPointF> pathList; - for (int i = 0; i < path.length(); ++i) { - const QPointF c = path.at(i).toPointF(); - pathList.append(c); + if (path.type() == QVariant::PolygonF) { + setPath(path.value<QPolygonF>()); + } else if (path.canConvert<QVector<QPointF>>()) { + setPath(path.value<QVector<QPointF>>()); + } else if (path.canConvert<QVariantList>()) { + // This handles cases other than QPolygonF or QVector<QPointF>, such as + // QList<QPointF>, QVector<QPoint>, QVariantList of QPointF, QVariantList of QPoint. + QVector<QPointF> pathList; + QVariantList vl = path.value<QVariantList>(); + // If path is a QJSValue, e.g. coming from a JS array of Qt.point() in QML, + // then path.value<QVariantList>() is inefficient. + // TODO We should be able to iterate over path.value<QSequentialIterable>() eventually + for (const QVariant &v : vl) + pathList.append(v.toPointF()); + setPath(pathList); + } else { + qWarning() << "PathPolyline: path of type" << path.type() << "not supported"; } - - setPath(pathList); } void QQuickPathPolyline::setPath(const QVector<QPointF> &path) @@ -2522,48 +2532,60 @@ void QQuickPathPolyline::addToPath(QPainterPath &path, const QQuickPathData &/*d \qmlproperty list<list<point>> QtQuick::PathMultiline::paths This property defines the vertices of the polylines. + + It can be a JS array of JS arrays of points constructed with \c Qt.point(), + a QList or QVector of QPolygonF, or QVector<QVector<QPointF>>. + If you are binding this to a custom property in some C++ object, + QVector<QPolygonF> or QVector<QVector<QPointF>> is the most + appropriate type to use. */ QQuickPathMultiline::QQuickPathMultiline(QObject *parent) : QQuickCurve(parent) { } -QVariantList QQuickPathMultiline::paths() const -{ - QVariantList res; - for (int j = 0; j < m_paths.length(); ++j) { - const QVector<QPointF> &path = m_paths.at(j); - QVariantList p; - for (int i = 0; i < path.length(); ++i) { - const QPointF &c = path.at(i); - p.append(QVariant::fromValue(c)); - } - res.append(p); - } - return res; -} - -void QQuickPathMultiline::setPaths(const QVariantList &paths) -{ - QVector<QVector<QPointF>> pathsList; - for (int j = 0; j < paths.length(); ++j) { - if (paths.at(j).type() != QVariant::List) - qWarning() << "QQuickPathMultiLine::setPaths: elements in argument not of type List"; - QVariantList path = paths.at(j).toList(); - QVector<QPointF> l; - for (int i = 0; i < path.length(); ++i) { - const QVariant &element = path.at(i); - const QVariant::Type elementType = element.type(); - if (elementType == QVariant::PointF || elementType == QVariant::Point) { - const QPointF c = element.toPointF(); - l.append(c); +QVariant QQuickPathMultiline::paths() const +{ + return QVariant::fromValue(m_paths); +} + +void QQuickPathMultiline::setPaths(const QVariant &paths) +{ + if (paths.canConvert<QVector<QPolygonF>>()) { + const QVector<QPolygonF> pathPolygons = paths.value<QVector<QPolygonF>>(); + QVector<QVector<QPointF>> pathVectors; + for (const QPolygonF &p : pathPolygons) + pathVectors << p; + setPaths(pathVectors); + } else if (paths.canConvert<QVector<QVector<QPointF>>>()) { + setPaths(paths.value<QVector<QVector<QPointF>>>()); + } else if (paths.canConvert<QVariantList>()) { + // This handles cases other than QVector<QPolygonF> or QVector<QVector<QPointF>>, such as + // QList<QVector<QPointF>>, QList<QList<QPointF>>, QVariantList of QVector<QPointF>, + // QVariantList of QVariantList of QPointF, QVector<QList<QPoint>> etc. + QVector<QVector<QPointF>> pathsList; + QVariantList vll = paths.value<QVariantList>(); + for (const QVariant &v : vll) { + // 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 { + qWarning() << "PathMultiline: paths of type" << paths.type() << "not supported"; + setPaths(QVector<QVector<QPointF>>()); } - - setPaths(pathsList); } void QQuickPathMultiline::setPaths(const QVector<QVector<QPointF>> &paths) diff --git a/src/quick/util/qquickpath_p.h b/src/quick/util/qquickpath_p.h index 92607a6c1e..5987ae8f35 100644 --- a/src/quick/util/qquickpath_p.h +++ b/src/quick/util/qquickpath_p.h @@ -428,12 +428,12 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPathPolyline : public QQuickCurve { Q_OBJECT Q_PROPERTY(QPointF start READ start NOTIFY startChanged) - Q_PROPERTY(QVariantList path READ path WRITE setPath NOTIFY pathChanged) + Q_PROPERTY(QVariant path READ path WRITE setPath NOTIFY pathChanged) public: QQuickPathPolyline(QObject *parent=nullptr); - QVariantList path() const; - void setPath(const QVariantList &path); + QVariant path() const; + void setPath(const QVariant &path); void setPath(const QVector<QPointF> &path); QPointF start() const; void addToPath(QPainterPath &path, const QQuickPathData &data) override; @@ -450,12 +450,12 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPathMultiline : public QQuickCurve { Q_OBJECT Q_PROPERTY(QPointF start READ start NOTIFY startChanged) - Q_PROPERTY(QVariantList paths READ paths WRITE setPaths NOTIFY pathsChanged) + Q_PROPERTY(QVariant paths READ paths WRITE setPaths NOTIFY pathsChanged) public: QQuickPathMultiline(QObject *parent=nullptr); - QVariantList paths() const; - void setPaths(const QVariantList &paths); + QVariant paths() const; + void setPaths(const QVariant &paths); void setPaths(const QVector<QVector<QPointF>> &paths); QPointF start() const; void addToPath(QPainterPath &path, const QQuickPathData &) override; |