From 5935536b71ba5fa23a1063674d225e50bd03daee Mon Sep 17 00:00:00 2001 From: Sami Shalayel Date: Tue, 13 Dec 2022 11:16:58 +0100 Subject: qml code model: load builtins import LinkPrivate::linkImports() would either load the or the module, but only process the module in LinkPrivate::populateImportedTypes(). Note: The module (from the package '') is the QtCreator magic replacement for the actual modules (from the package 'QML'). This means that if the were loaded, then QtObject would be recognized as an object from QtQuick. On the other hand, if the were found, then neither nor would have been imported and QtObject would not have been found in the imports (because neither nor would have been imported). The "-found" situation happens right after a "reset code model" while the "-found" appears when the qml code finally found the package, usually after running cmake or when a project was freshly opened in Qt Creator. Instead, always try to load both and module. Also, fix the builtins.qmltypes (that contains the qt creators magic types) to reflect that Component and QtObject are both available from the QML package (the module), as else one cannot import QtObject from QtQml after a code mode reset. Fixes: QTCREATORBUG-28287 Fixes: QTCREATORBUG-28375 Change-Id: I67084a169dc5ca8ec2474b721dbef83cd47037c7 Reviewed-by: Thomas Hartmann Reviewed-by: Fabian Kosmale --- src/libs/qmljs/qmljslink.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/libs/qmljs/qmljslink.cpp') diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index 6c04966ced..b7a1350ad6 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -83,6 +83,7 @@ public: const Utils::FilePath &libraryPath); void loadImplicitDirectoryImports(Imports *imports, const Document::Ptr &doc); void loadImplicitDefaultImports(Imports *imports); + void loadImplicitBuiltinsImports(Imports *imports); void error(const Document::Ptr &doc, const SourceLocation &loc, const QString &message); void warning(const Document::Ptr &doc, const SourceLocation &loc, const QString &message); @@ -91,6 +92,8 @@ public: private: friend class Link; + void loadImplicitImports(Imports *imports, const QString &packageName, const QString &moduleName); + Snapshot m_snapshot; ValueOwner *m_valueOwner = nullptr; QList m_importPaths; @@ -254,8 +257,11 @@ void LinkPrivate::populateImportedTypes(Imports *imports, const Document::Ptr &d { importableModuleApis.clear(); - // implicit imports: the package is always available + // implicit imports: the package is always available (except when the QML package was loaded). + // In the latter case, still try to load the 's module . loadImplicitDefaultImports(imports); + // Load the import, if the QML package was loaded. + loadImplicitBuiltinsImports(imports); // implicit imports: // qml files in the same directory are available without explicit imports @@ -683,20 +689,19 @@ void LinkPrivate::loadImplicitDirectoryImports(Imports *imports, const Document: } } -void LinkPrivate::loadImplicitDefaultImports(Imports *imports) +void LinkPrivate::loadImplicitImports(Imports *imports, const QString &packageName, const QString &moduleName) { - const QString defaultPackage = CppQmlTypes::defaultPackage; - if (m_valueOwner->cppQmlTypes().hasModule(defaultPackage)) { + if (m_valueOwner->cppQmlTypes().hasModule(packageName)) { const ComponentVersion maxVersion(ComponentVersion::MaxVersion, ComponentVersion::MaxVersion); - const ImportInfo info = ImportInfo::moduleImport(defaultPackage, maxVersion, QString()); + const ImportInfo info = ImportInfo::moduleImport(packageName, maxVersion, QString()); Import import = importCache.value(ImportCacheKey(info)); if (!import.object) { import.valid = true; import.info = info; - import.object = new ObjectValue(m_valueOwner, QLatin1String("")); + import.object = new ObjectValue(m_valueOwner, moduleName); - const auto objects = m_valueOwner->cppQmlTypes().createObjectsForImport(defaultPackage, + const auto objects = m_valueOwner->cppQmlTypes().createObjectsForImport(packageName, maxVersion); for (const CppComponentValue *object : objects) import.object->setMember(object->className(), object); @@ -707,4 +712,14 @@ void LinkPrivate::loadImplicitDefaultImports(Imports *imports) } } +void LinkPrivate::loadImplicitDefaultImports(Imports *imports) +{ + loadImplicitImports(imports, CppQmlTypes::defaultPackage, QLatin1String("")); +} + +void LinkPrivate::loadImplicitBuiltinsImports(Imports *imports) +{ + loadImplicitImports(imports, QLatin1String("QML"), QLatin1String("")); +} + } // namespace QmlJS -- cgit v1.2.1 From 56baf8c058792187b574cf988fcf4b313f527156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20K=C3=B6hne?= Date: Wed, 21 Dec 2022 10:12:09 +0100 Subject: Remove GPL-3.0+ from license identifiers Since we also license under GPL-3.0 WITH Qt-GPL-exception-1.0, this applies only to a hypothetical newer version of GPL, that doesn't exist yet. If such a version emerges, we can still decide to relicense... While at it, replace (deprecated) GPL-3.0 with more explicit GPL-3.0-only Change was done by running find . -type f -exec perl -pi -e "s/LicenseRef-Qt-Commercial OR GPL-3.0\+ OR GPL-3.0 WITH Qt-GPL-exception-1.0/LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0/g" {} \; Change-Id: I5097e6ce8d10233993ee30d7e25120e2659eb10b Reviewed-by: Eike Ziller --- src/libs/qmljs/qmljslink.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libs/qmljs/qmljslink.cpp') diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index bd759b2f64..4a690b6e66 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "qmljslink.h" -- cgit v1.2.1 From 17b28909a99cce2dc908ad2ffbb43a85539fa526 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 24 Jan 2023 14:39:05 +0100 Subject: QmlJS: Tr::Tr Excluding the Qml parser, which needs to remain in sync with it's copy in Qt. Change-Id: I22f475f265dd74687e3239c4d6916c777798a447 Reviewed-by: hjk --- src/libs/qmljs/qmljslink.cpp | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'src/libs/qmljs/qmljslink.cpp') diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index 4a690b6e66..5054ce5703 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -4,11 +4,13 @@ #include "qmljslink.h" #include "parser/qmljsast_p.h" -#include "qmljsdocument.h" + #include "qmljsbind.h" -#include "qmljsutils.h" -#include "qmljsmodelmanagerinterface.h" #include "qmljsconstants.h" +#include "qmljsdocument.h" +#include "qmljsmodelmanagerinterface.h" +#include "qmljstr.h" +#include "qmljsutils.h" #include #include @@ -293,7 +295,7 @@ void LinkPrivate::populateImportedTypes(Imports *imports, const Document::Ptr &d imports->setImportFailed(); if (info.ast()) { error(doc, info.ast()->fileNameToken, - Link::tr("File or directory not found.")); + Tr::tr("File or directory not found.")); } break; default: @@ -455,7 +457,7 @@ Import LinkPrivate::importNonFile(const Document::Ptr &doc, const ImportInfo &im error(doc, locationFromRange(importInfo.ast()->firstSourceLocation(), importInfo.ast()->lastSourceLocation()), - Link::tr( + Tr::tr( "QML module not found (%1).\n\n" "Import paths:\n" "%2\n\n" @@ -525,19 +527,19 @@ bool LinkPrivate::importLibrary(const Document::Ptr &doc, if (!(optional || (toImport.flags & QmlDirParser::Import::Optional))) { error(doc, errorLoc, - Link::tr("Implicit import '%1' of QML module '%2' not found.\n\n" - "Import paths:\n" - "%3\n\n" - "For qmake projects, use the QML_IMPORT_PATH variable to add import " - "paths.\n" - "For Qbs projects, declare and set a qmlImportPaths property in " - "your product " - "to add import paths.\n" - "For qmlproject projects, use the importPaths property to add " - "import paths.\n" - "For CMake projects, make sure QML_IMPORT_PATH variable is in " - "CMakeCache.txt.\n") - .arg(importName, + Tr::tr("Implicit import '%1' of QML module '%2' not found.\n\n" + "Import paths:\n" + "%3\n\n" + "For qmake projects, use the QML_IMPORT_PATH variable to add import " + "paths.\n" + "For Qbs projects, declare and set a qmlImportPaths property in " + "your product " + "to add import paths.\n" + "For qmlproject projects, use the importPaths property to add " + "import paths.\n" + "For CMake projects, make sure QML_IMPORT_PATH variable is in " + "CMakeCache.txt.\n") + .arg(importName, importInfo.name(), Utils::transform(m_importPaths, [](const Utils::FilePath &p) { return p.toString(); @@ -569,8 +571,9 @@ bool LinkPrivate::importLibrary(const Document::Ptr &doc, if (!optional && errorLoc.isValid()) { appendDiagnostic(doc, DiagnosticMessage( Severity::ReadingTypeInfoWarning, errorLoc, - Link::tr("QML module contains C++ plugins, " - "currently reading type information... %1").arg(import->info.name()))); + Tr::tr("QML module contains C++ plugins, " + "currently reading type information... %1") + .arg(import->info.name()))); import->valid = false; } } else if (libraryInfo.pluginTypeInfoStatus() == LibraryInfo::DumpError -- cgit v1.2.1