QmlDesigner: Show error message when using imports without version with Qt 5

If the document contains a 6.0 import or an import without version, but the
kit is a Qt 5 kit we show an error message.
Also show an error message if there is no Qt kit at all.

Task-number: QTCREATORBUG-25983
Change-Id: Id87ef47f0d8fbc31d1a8dbe8a471986d7288a4d3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Thomas Hartmann
2021-07-22 14:47:32 +02:00
parent a0da3ce69f
commit 493f8b8adc
2 changed files with 58 additions and 4 deletions

View File

@@ -43,6 +43,16 @@
#include <enumeration.h> #include <enumeration.h>
#ifndef QMLDESIGNER_TEST
#include <projectexplorer/kit.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
#endif
#include <qmljs/qmljsevaluate.h> #include <qmljs/qmljsevaluate.h>
#include <qmljs/qmljslink.h> #include <qmljs/qmljslink.h>
#include <qmljs/parser/qmljsast_p.h> #include <qmljs/parser/qmljsast_p.h>
@@ -793,6 +803,8 @@ void TextToModelMerger::setupImports(const Document::Ptr &doc,
{ {
QList<Import> existingImports = m_rewriterView->model()->imports(); QList<Import> existingImports = m_rewriterView->model()->imports();
m_hasVersionlessImport = false;
for (AST::UiHeaderItemList *iter = doc->qmlProgram()->headers; iter; iter = iter->next) { for (AST::UiHeaderItemList *iter = doc->qmlProgram()->headers; iter; iter = iter->next) {
auto import = AST::cast<AST::UiImport *>(iter->headerItem); auto import = AST::cast<AST::UiImport *>(iter->headerItem);
if (!import) if (!import)
@@ -812,8 +824,10 @@ void TextToModelMerger::setupImports(const Document::Ptr &doc,
differenceHandler.modelMissesImport(newImport); differenceHandler.modelMissesImport(newImport);
} else { } else {
QString importUri = toString(import->importUri); QString importUri = toString(import->importUri);
if (version.isEmpty()) if (version.isEmpty()) {
version = getHighestPossibleImport(importUri); version = getHighestPossibleImport(importUri);
m_hasVersionlessImport = true;
}
const Import newImport = Import::createLibraryImport(importUri, const Import newImport = Import::createLibraryImport(importUri,
version, version,
as, as,
@@ -2099,10 +2113,49 @@ void TextToModelMerger::collectImportErrors(QList<DocumentMessage> *errors)
if (supportedQtQuickVersion(import.version())) { if (supportedQtQuickVersion(import.version())) {
hasQtQuick = true; hasQtQuick = true;
#ifndef QMLDESIGNER_TEST
auto target = ProjectExplorer::SessionManager::startupTarget();
if (target) {
QtSupport::BaseQtVersion *currentQtVersion = QtSupport::QtKitAspect::qtVersion(
target->kit());
if (currentQtVersion && currentQtVersion->isValid()) {
const bool qt6import = import.version().startsWith("6");
if (currentQtVersion->qtVersion().majorVersion == 5
&& (m_hasVersionlessImport || qt6import)) {
const QmlJS::DiagnosticMessage diagnosticMessage(
QmlJS::Severity::Error,
SourceLocation(0, 0, 0, 0),
QCoreApplication::translate(
"QmlDesigner::TextToModelMerger",
"QtQuick 6 is not supported with a Qt 5 kit."));
errors->prepend(
DocumentMessage(diagnosticMessage,
QUrl::fromLocalFile(m_document->fileName())));
}
} else { } else {
const QmlJS::DiagnosticMessage diagnosticMessage(QmlJS::Severity::Error, SourceLocation(0, 0, 0, 0), const QmlJS::DiagnosticMessage
QCoreApplication::translate("QmlDesigner::TextToModelMerger", "Unsupported QtQuick version")); diagnosticMessage(QmlJS::Severity::Error,
errors->append(DocumentMessage(diagnosticMessage, QUrl::fromLocalFile(m_document->fileName()))); SourceLocation(0, 0, 0, 0),
QCoreApplication::translate(
"QmlDesigner::TextToModelMerger",
"The Design Mode requires a valid Qt kit."));
errors->prepend(
DocumentMessage(diagnosticMessage,
QUrl::fromLocalFile(m_document->fileName())));
}
}
#endif
} else {
const QmlJS::DiagnosticMessage
diagnosticMessage(QmlJS::Severity::Error,
SourceLocation(0, 0, 0, 0),
QCoreApplication::translate("QmlDesigner::TextToModelMerger",
"Unsupported QtQuick version"));
errors->append(DocumentMessage(diagnosticMessage,
QUrl::fromLocalFile(m_document->fileName())));
} }
} }
} }

View File

@@ -166,6 +166,7 @@ private:
QmlJS::ViewerContext m_vContext; QmlJS::ViewerContext m_vContext;
QSet<QPair<QString, QString> > m_qrcMapping; QSet<QPair<QString, QString> > m_qrcMapping;
QSet<QmlJS::ImportKey> m_possibleImportKeys; QSet<QmlJS::ImportKey> m_possibleImportKeys;
bool m_hasVersionlessImport = false;
}; };
class DifferenceHandler class DifferenceHandler