From 51696d5e8dbd17fe2bfdfc669bbf22e0e50af6c6 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 31 May 2019 16:21:28 +0200 Subject: [PATCH 1/5] Parser: Accept templated readonly properties Change-Id: I37d313e3156a44eb4487b1be007aa93ace18d882 Fixes: QTBUG-76018 Reviewed-by: Simon Hausmann --- src/qml/parser/qqmljs.g | 45 ++++++++++++++++++++ tests/auto/qml/qqmlparser/tst_qqmlparser.cpp | 10 +++++ 2 files changed, 55 insertions(+) diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index 27f23a6fa7..e549c4620a 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -1110,6 +1110,23 @@ 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_AUTOMATIC_SEMICOLON; +UiObjectMember: T_READONLY T_PROPERTY T_IDENTIFIER T_LT UiPropertyType T_GT QmlIdentifier T_SEMICOLON; +/. + case $rule_number: { + AST::UiPublicMember *node = new (pool) AST::UiPublicMember(sym(5).UiQualifiedId->finish(), stringRef(7)); + node->isReadonlyMember = true; + node->readonlyToken = loc(1); + node->typeModifier = stringRef(3); + node->propertyToken = loc(2); + node->typeModifierToken = loc(3); + node->typeToken = loc(5); + node->identifierToken = loc(7); + node->semicolonToken = loc(8); + sym(1).Node = node; + } break; +./ + UiObjectMember: T_PROPERTY UiPropertyType QmlIdentifier T_AUTOMATIC_SEMICOLON; UiObjectMember: T_PROPERTY UiPropertyType QmlIdentifier T_SEMICOLON; /. @@ -1221,6 +1238,34 @@ 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; +/. + case $rule_number: { + AST::UiPublicMember *node = new (pool) AST::UiPublicMember(sym(5).UiQualifiedId->finish(), stringRef(7)); + node->isReadonlyMember = true; + node->readonlyToken = loc(1); + node->typeModifier = stringRef(3); + node->propertyToken = loc(2); + node->typeModifierToken = loc(3); + node->typeToken = loc(5); + node->identifierToken = loc(7); + node->semicolonToken = loc(8); // insert a fake ';' before ':' + + AST::UiQualifiedId *propertyName = new (pool) AST::UiQualifiedId(stringRef(7)); + propertyName->identifierToken = loc(7); + propertyName->next = 0; + + AST::UiArrayBinding *binding = new (pool) AST::UiArrayBinding(propertyName, sym(10).UiArrayMemberList->finish()); + binding->colonToken = loc(8); + binding->lbracketToken = loc(9); + binding->rbracketToken = loc(11); + + node->binding = binding; + + sym(1).Node = node; + } break; +./ + UiObjectMember: T_PROPERTY UiPropertyType QmlIdentifier T_COLON ExpressionStatementLookahead UiQualifiedId UiObjectInitializer; /. case $rule_number: { diff --git a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp index 71dd900073..89e1997096 100644 --- a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp +++ b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp @@ -54,6 +54,7 @@ private slots: void noSubstitutionTemplateLiteral(); void templateLiteral(); void leadingSemicolonInClass(); + void templatedReadonlyProperty(); private: QStringList excludedDirs; @@ -289,6 +290,15 @@ void tst_qqmlparser::leadingSemicolonInClass() QVERIFY(parser.parseProgram()); } +void tst_qqmlparser::templatedReadonlyProperty() +{ + QQmlJS::Engine engine; + QQmlJS::Lexer lexer(&engine); + lexer.setCode(QLatin1String("A { readonly property list listfoo: [ C{} ] }"), 1); + QQmlJS::Parser parser(&engine); + QVERIFY(parser.parse()); +} + QTEST_MAIN(tst_qqmlparser) #include "tst_qqmlparser.moc" From 56b0d420703e24523a6a06f75590f0480397f4d6 Mon Sep 17 00:00:00 2001 From: Tasuku Suzuki Date: Tue, 28 May 2019 23:29:41 +0900 Subject: [PATCH 2/5] Fix for loading translations automatically from resources When qml file is in resources, translations under i18n was not loaded Task-number: QTBUG-76085 Change-Id: I75315ceb6a1e6ab10309634a3c445a82476d525c Reviewed-by: Ulf Hermann --- src/qml/qml/qqmlapplicationengine.cpp | 9 ++++-- .../qqmlapplicationengine/data/i18n/qml.qm | Bin 0 -> 102 bytes .../qqmlapplicationengine/data/i18n/qml.ts | 11 +++++++ .../data/loadTranslation.qml | 5 ++++ .../tst_qqmlapplicationengine.cpp | 27 ++++++++++++++++++ .../tst_qqmlapplicationengine.pro | 3 ++ .../tst_qqmlapplicationengine.qrc | 6 ++++ 7 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tests/auto/qml/qqmlapplicationengine/data/i18n/qml.qm create mode 100644 tests/auto/qml/qqmlapplicationengine/data/i18n/qml.ts create mode 100644 tests/auto/qml/qqmlapplicationengine/data/loadTranslation.qml create mode 100644 tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.qrc diff --git a/src/qml/qml/qqmlapplicationengine.cpp b/src/qml/qml/qqmlapplicationengine.cpp index 1b7a433a84..facd79d211 100644 --- a/src/qml/qml/qqmlapplicationengine.cpp +++ b/src/qml/qml/qqmlapplicationengine.cpp @@ -76,7 +76,7 @@ void QQmlApplicationEnginePrivate::init() &QCoreApplication::exit, Qt::QueuedConnection); #if QT_CONFIG(translation) QTranslator* qtTranslator = new QTranslator; - if (qtTranslator->load(QLocale(), QLatin1String("qt"), QLatin1String("_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + if (qtTranslator->load(QLocale(), QLatin1String("qt"), QLatin1String("_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath), QLatin1String(".qm"))) QCoreApplication::installTranslator(qtTranslator); translators << qtTranslator; #endif @@ -90,10 +90,10 @@ void QQmlApplicationEnginePrivate::loadTranslations(const QUrl &rootFile) if (rootFile.scheme() != QLatin1String("file") && rootFile.scheme() != QLatin1String("qrc")) return; - QFileInfo fi(rootFile.toLocalFile()); + QFileInfo fi(QQmlFile::urlToLocalFileOrQrc(rootFile)); QTranslator *translator = new QTranslator; - if (translator->load(QLocale(), QLatin1String("qml"), QLatin1String("_"), fi.path() + QLatin1String("/i18n"))) { + if (translator->load(QLocale(), QLatin1String("qml"), QLatin1String("_"), fi.path() + QLatin1String("/i18n"), QLatin1String(".qm"))) { QCoreApplication::installTranslator(translator); translators << translator; } else { @@ -180,6 +180,9 @@ void QQmlApplicationEnginePrivate::finishLoad(QQmlComponent *c) \list \li Connecting Qt.quit() to QCoreApplication::quit() \li Automatically loads translation files from an i18n directory adjacent to the main QML file. + \list + \li Translation files must have "qml_" prefix e.g. qml_ja_JP.qm. + \endlist \li Automatically sets an incubation controller if the scene contains a QQuickWindow. \li Automatically sets a \c QQmlFileSelector as the url interceptor, applying file selectors to all QML files and assets. diff --git a/tests/auto/qml/qqmlapplicationengine/data/i18n/qml.qm b/tests/auto/qml/qqmlapplicationengine/data/i18n/qml.qm new file mode 100644 index 0000000000000000000000000000000000000000..8e3c4967c21110526368bb6967be6388573126e9 GIT binary patch literal 102 zcmcE7ks@*G{hX<16=n7(EZlq7iGhKEgVpHE5+Kcx3B)eUKthC}grSHbks*(vm>~y9 rmoTICqFSI1S*)BpT`IQv-KMJ literal 0 HcmV?d00001 diff --git a/tests/auto/qml/qqmlapplicationengine/data/i18n/qml.ts b/tests/auto/qml/qqmlapplicationengine/data/i18n/qml.ts new file mode 100644 index 0000000000..51a204be3e --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/data/i18n/qml.ts @@ -0,0 +1,11 @@ + + + + + loadTranslation + + translate it + translated + + + diff --git a/tests/auto/qml/qqmlapplicationengine/data/loadTranslation.qml b/tests/auto/qml/qqmlapplicationengine/data/loadTranslation.qml new file mode 100644 index 0000000000..bba4cab8d6 --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/data/loadTranslation.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +QtObject { + property string translation: qsTr('translate it') +} diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp index ce654dc45e..a9c28a0911 100644 --- a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp +++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp @@ -50,6 +50,9 @@ private slots: void application(); void applicationProperties(); void removeObjectsWhenDestroyed(); + void loadTranslation_data(); + void loadTranslation(); + private: QString buildDir; QString srcDir; @@ -241,6 +244,30 @@ void tst_qqmlapplicationengine::removeObjectsWhenDestroyed() QCOMPARE(test->rootObjects().size(), 0); } +void tst_qqmlapplicationengine::loadTranslation_data() +{ + QTest::addColumn("qmlUrl"); + QTest::addColumn("translation"); + + QTest::newRow("local file") << testFileUrl("loadTranslation.qml") + << QStringLiteral("translated"); + QTest::newRow("qrc") << QUrl(QLatin1String("qrc:///data/loadTranslation.qml")) + << QStringLiteral("translated"); +} + +void tst_qqmlapplicationengine::loadTranslation() +{ + QFETCH(QUrl, qmlUrl); + QFETCH(QString, translation); + + QQmlApplicationEngine test(qmlUrl); + QVERIFY(!test.rootObjects().isEmpty()); + + QObject *rootObject = test.rootObjects().first(); + QVERIFY(rootObject); + + QCOMPARE(rootObject->property("translation").toString(), translation); +} QTEST_MAIN(tst_qqmlapplicationengine) diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.pro b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.pro index 18c38a80b6..88d07f2b62 100644 --- a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.pro +++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.pro @@ -5,6 +5,9 @@ macx:CONFIG -= app_bundle SOURCES += tst_qqmlapplicationengine.cpp TESTDATA += data/* +RESOURCES += tst_qqmlapplicationengine.qrc include (../../shared/util.pri) QT += core-private gui-private qml-private network testlib + +TRANSLATIONS = data/i18n/qml_ja.ts diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.qrc b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.qrc new file mode 100644 index 0000000000..de79d665a3 --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.qrc @@ -0,0 +1,6 @@ + + + data/loadTranslation.qml + data/i18n/qml.qm + + From fca76305cb2bd36be5229be59d37af45238916a1 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Mon, 3 Jun 2019 10:01:26 +0200 Subject: [PATCH 3/5] Fix QQuickPathView autotest: update expected warning messages The wording of the warnings were changed in qtbase. Fixes: QTBUG-76152 Change-Id: Iae0dfbcbb699b8abff92b5923b0a5627591043c8 Reviewed-by: Liang Qi --- tests/auto/quick/qquickpathview/tst_qquickpathview.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index 7491df5087..355800359c 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -1490,11 +1490,11 @@ void tst_QQuickPathView::undefinedPath() // QPainterPath warnings are only received if QT_NO_DEBUG is not defined if (QLibraryInfo::isDebugBuild()) { - QString warning1("QPainterPath::moveTo: Adding point where x or y is NaN or Inf, ignoring call"); - QTest::ignoreMessage(QtWarningMsg,qPrintable(warning1)); + QRegularExpression warning1("^QPainterPath::moveTo:.*ignoring call$"); + QTest::ignoreMessage(QtWarningMsg, warning1); - QString warning2("QPainterPath::lineTo: Adding point where x or y is NaN or Inf, ignoring call"); - QTest::ignoreMessage(QtWarningMsg,qPrintable(warning2)); + QRegularExpression warning2("^QPainterPath::lineTo:.*ignoring call$"); + QTest::ignoreMessage(QtWarningMsg, warning2); } QQmlComponent c(&engine, testFileUrl("undefinedpath.qml")); From 03f99bc4ff8cdbf87054ee4cf92d167a19838cea Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 4 Jun 2019 10:35:40 +0200 Subject: [PATCH 4/5] QML Preview: Fix test to check absolute zoom factors The zoom factors passed to the preview service are interpreted as absolute values, not as relative to the base zoom factor. The test would fail if the base zoom factor was != 1. Change-Id: If66d8c79dea91e4013e1ab7f790fa308ac87c934 Reviewed-by: Simon Hausmann --- tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp b/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp index c7f8ec1118..f08f3c1da7 100644 --- a/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp +++ b/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp @@ -322,7 +322,7 @@ void tst_QQmlPreview::zoom() for (auto testZoomFactor : {2.0f, 1.5f, 0.5f}) { m_client->triggerZoom(testZoomFactor); - verifyZoomFactor(m_process, baseZoomFactor * testZoomFactor); + verifyZoomFactor(m_process, testZoomFactor); } m_client->triggerZoom(-1.0f); From b1e9bc580adc1e7b3b1398f392016880dc5201ba Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Tue, 4 Jun 2019 10:50:28 +0200 Subject: [PATCH 5/5] Doc: Remove superfluous double quotes in code snippets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTBUG-75957 Change-Id: I2c9c70461a828978d1413b8cbdb407663b4b7493 Reviewed-by: Topi Reiniƶ --- src/qml/doc/snippets/qml/componentCreation.js | 4 ++-- src/qml/qml/qqmlcomponent.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qml/doc/snippets/qml/componentCreation.js b/src/qml/doc/snippets/qml/componentCreation.js index 7364139d3d..ea45f18c37 100644 --- a/src/qml/doc/snippets/qml/componentCreation.js +++ b/src/qml/doc/snippets/qml/componentCreation.js @@ -17,7 +17,7 @@ function createSpriteObjects() { //![local] component = Qt.createComponent("Sprite.qml"); - sprite = component.createObject(appWindow, {"x": 100, "y": 100}); + sprite = component.createObject(appWindow, {x: 100, y: 100}); if (sprite == null) { // Error Handling @@ -32,7 +32,7 @@ function createSpriteObjects() { //![finishCreation] function finishCreation() { if (component.status == Component.Ready) { - sprite = component.createObject(appWindow, {"x": 100, "y": 100}); + sprite = component.createObject(appWindow, {x: 100, y: 100}); if (sprite == null) { // Error Handling console.log("Error creating object"); diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 57ea685a5d..a23a322df9 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -1207,7 +1207,7 @@ static void QQmlComponent_setQmlParent(QObject *me, QObject *parent) \js var component = Qt.createComponent("Button.qml"); if (component.status == Component.Ready) - component.createObject(parent, {"x": 100, "y": 100}); + component.createObject(parent, {x: 100, y: 100}); \endjs Dynamically created instances can be deleted with the \c destroy() method.