aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFawzi Mohamed <fawzi.mohamed@qt.io>2020-01-28 14:21:10 +0100
committerFawzi Mohamed <fawzi.mohamed@qt.io>2020-01-31 14:33:12 +0100
commita87ad432a002614a5cca4d635ead5aedb97ba757 (patch)
tree5548b48b2be23909c761c2b4673bc72b999d3ea5 /tests
parent65fa7e795dd67250b8d95f13ebd9924069864866 (diff)
add annotations to QML
A QML Annotation is a Qml Object declaration prepended with @. The name of the annotation is restricted to a dot separated list of non keyword identifiers. Annotations can be put before an Object definition, or any object member declaration: bindings, property declarations, function declarations. This patch, aside parsing the annotations does absolutely nothing, the list of annotations is discarded and never touches the AST. [ChangeLog][QML] Add Qml Annotations Task-number: QTBUG-81714 Change-Id: I4d79559a0d1fb23acaf482d0ef8f7d106dbf099d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlparser/data/annotations/View1.qml76
-rw-r--r--tests/auto/qml/qqmlparser/data/noannotations/View1.qml76
-rw-r--r--tests/auto/qml/qqmlparser/tst_qqmlparser.cpp63
3 files changed, 215 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlparser/data/annotations/View1.qml b/tests/auto/qml/qqmlparser/data/annotations/View1.qml
new file mode 100644
index 0000000000..2d3d7d2cfd
--- /dev/null
+++ b/tests/auto/qml/qqmlparser/data/annotations/View1.qml
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//![2]
+import QtQuick 2.0
+//![2]
+import QtCharts 2.0
+
+@Pippo{ atg1:3 }
+@Annotation2{}
+Item {
+ @Annotate{}
+ anchors.fill: parent
+ @AnnotateMore{
+ property int x: 5
+ }
+ @AnnotateALot{}
+ property variant othersSlice: 0
+
+ //![1]
+ ChartView {
+ id: chart
+ title: "Top-5 car brand shares in Finland"
+ anchors.fill: parent
+ legend.alignment: Qt.AlignBottom
+ antialiasing: true
+
+@ExtraAnnotation{
+ signal pippo
+}
+ PieSeries {
+ id: pieSeries
+ PieSlice { label: "Volkswagen"; value: 13.5 }
+ PieSlice { label: "Toyota"; value: 10.9 }
+ PieSlice { label: "Ford"; value: 8.6 }
+ PieSlice { label: "Skoda"; value: 8.2 }
+ PieSlice { label: "Volvo"; value: 6.8 }
+ }
+ }
+
+@SuperComplete{
+binding: late
+}
+ Component.onCompleted: {
+ // You can also manipulate slices dynamically, like append a slice or set a slice exploded
+ othersSlice = pieSeries.append("Others", 52.0);
+ pieSeries.find("Volkswagen").exploded = true;
+ }
+ //![1]
+}
diff --git a/tests/auto/qml/qqmlparser/data/noannotations/View1.qml b/tests/auto/qml/qqmlparser/data/noannotations/View1.qml
new file mode 100644
index 0000000000..945bce3a44
--- /dev/null
+++ b/tests/auto/qml/qqmlparser/data/noannotations/View1.qml
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//![2]
+import QtQuick 2.0
+//![2]
+import QtCharts 2.0
+
+
+
+Item {
+
+ anchors.fill: parent
+
+
+
+
+ property variant othersSlice: 0
+
+ //![1]
+ ChartView {
+ id: chart
+ title: "Top-5 car brand shares in Finland"
+ anchors.fill: parent
+ legend.alignment: Qt.AlignBottom
+ antialiasing: true
+
+
+
+
+ PieSeries {
+ id: pieSeries
+ PieSlice { label: "Volkswagen"; value: 13.5 }
+ PieSlice { label: "Toyota"; value: 10.9 }
+ PieSlice { label: "Ford"; value: 8.6 }
+ PieSlice { label: "Skoda"; value: 8.2 }
+ PieSlice { label: "Volvo"; value: 6.8 }
+ }
+ }
+
+
+
+
+ Component.onCompleted: {
+ // You can also manipulate slices dynamically, like append a slice or set a slice exploded
+ othersSlice = pieSeries.append("Others", 52.0);
+ pieSeries.find("Volkswagen").exploded = true;
+ }
+ //![1]
+}
diff --git a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp
index 76b56bd303..0b88358d4a 100644
--- a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp
+++ b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp
@@ -65,6 +65,8 @@ private slots:
void semicolonPartOfExpressionStatement();
void typeAssertion_data();
void typeAssertion();
+ void annotations_data();
+ void annotations();
private:
QStringList excludedDirs;
@@ -521,6 +523,67 @@ void tst_qqmlparser::typeAssertion()
QVERIFY(parser.parse());
}
+void tst_qqmlparser::annotations_data()
+{
+ QTest::addColumn<QString>("file");
+ QTest::addColumn<QString>("refFile");
+
+ QString tests = dataDirectory() + "/annotations/";
+ QString compare = dataDirectory() + "/noannotations/";
+
+ QStringList files;
+ files << findFiles(QDir(tests));
+
+ QStringList refFiles;
+ refFiles << findFiles(QDir(compare));
+
+ for (const QString &file: qAsConst(files)) {
+ auto fileNameStart = file.lastIndexOf(QDir::separator());
+ QStringRef fileName(&file, fileNameStart, file.length()-fileNameStart);
+ auto ref=std::find_if(refFiles.constBegin(),refFiles.constEnd(), [fileName](const QString &s){ return s.endsWith(fileName); });
+ if (ref != refFiles.constEnd())
+ QTest::newRow(qPrintable(file)) << file << *ref;
+ else
+ QTest::newRow(qPrintable(file)) << file << QString();
+ }
+}
+
+void tst_qqmlparser::annotations()
+{
+ using namespace QQmlJS;
+
+ QFETCH(QString, file);
+ QFETCH(QString, refFile);
+
+ QString code;
+ QString refCode;
+
+ QFile f(file);
+ if (f.open(QFile::ReadOnly))
+ code = QString::fromUtf8(f.readAll());
+ QFile refF(refFile);
+ if (!refFile.isEmpty() && refF.open(QFile::ReadOnly))
+ refCode = QString::fromUtf8(refF.readAll());
+
+ const bool qmlMode = true;
+
+ Engine engine;
+ Lexer lexer(&engine);
+ lexer.setCode(code, 1, qmlMode);
+ Parser parser(&engine);
+ QVERIFY(parser.parse());
+
+ if (!refCode.isEmpty()) {
+ Engine engine2;
+ Lexer lexer2(&engine2);
+ lexer2.setCode(refCode, 1, qmlMode);
+ Parser parser2(&engine2);
+ QVERIFY(parser2.parse());
+
+ // to do: compare for equality skipping annotations
+ }
+}
+
QTEST_MAIN(tst_qqmlparser)
#include "tst_qqmlparser.moc"