diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-01-29 16:41:59 +0100 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-01-29 16:52:58 +0100 |
commit | b684ba219493fb7b0108ae367d6d033aaa28053b (patch) | |
tree | f1fec8922da198e231416b50ef8f441ef6db065b /tools | |
parent | 97a5cf86345fd72cdff83c03664c19a8f5cdf79a (diff) | |
parent | 8354851b628ebae567a9125cbd0ba69268470c1b (diff) |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Conflicts:
dependencies.yaml
Change-Id: Ie3e9dc62031a85e5e81cbdf04694b95159d49fca
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qml/conf.h | 2 | ||||
-rw-r--r-- | tools/qml/main.cpp | 51 | ||||
-rw-r--r-- | tools/qmlformat/dumpastvisitor.cpp | 98 | ||||
-rw-r--r-- | tools/qmlformat/dumpastvisitor.h | 3 | ||||
-rw-r--r-- | tools/qmlformat/main.cpp | 17 | ||||
-rw-r--r-- | tools/qmlimportscanner/Qt5QmlImportScannerConfig.cmake.in | 10 | ||||
-rw-r--r-- | tools/qmlimportscanner/main.cpp | 2 | ||||
-rw-r--r-- | tools/qmlscene/main.cpp | 2 |
8 files changed, 142 insertions, 43 deletions
diff --git a/tools/qml/conf.h b/tools/qml/conf.h index e83d63cba5..4ad45428ed 100644 --- a/tools/qml/conf.h +++ b/tools/qml/conf.h @@ -81,7 +81,7 @@ public: QQmlListProperty<PartialScene> sceneCompleters() { - return QQmlListProperty<PartialScene>(this, completers); + return QQmlListProperty<PartialScene>(this, &completers); } QList<PartialScene*> completers; diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 7235c65aff..618dab6690 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -332,26 +332,35 @@ void quietMessageHandler(QtMsgType type, const QMessageLogContext &ctxt, const Q } } -// Called before application initialization, removes arguments it uses -void getAppFlags(int &argc, char **argv) +// Called before application initialization +static void getAppFlags(int argc, char **argv) { #ifdef QT_GUI_LIB for (int i=0; i<argc; i++) { if (!strcmp(argv[i], "--apptype") || !strcmp(argv[i], "-a") || !strcmp(argv[i], "-apptype")) { applicationType = QmlApplicationTypeUnknown; if (i+1 < argc) { - if (!strcmp(argv[i+1], "core")) + ++i; + if (!strcmp(argv[i], "core")) applicationType = QmlApplicationTypeCore; - else if (!strcmp(argv[i+1], "gui")) + else if (!strcmp(argv[i], "gui")) applicationType = QmlApplicationTypeGui; -#ifdef QT_WIDGETS_LIB - else if (!strcmp(argv[i+1], "widget")) +# ifdef QT_WIDGETS_LIB + else if (!strcmp(argv[i], "widget")) applicationType = QmlApplicationTypeWidget; -#endif // QT_WIDGETS_LIB +# endif // QT_WIDGETS_LIB + } - for (int j=i; j<argc-2; j++) - argv[j] = argv[j+2]; - argc -= 2; + } else if (!strcmp(argv[i], "-desktop") || !strcmp(argv[i], "--desktop")) { + QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); + } else if (!strcmp(argv[i], "-gles") || !strcmp(argv[i], "--gles")) { + QCoreApplication::setAttribute(Qt::AA_UseOpenGLES); + } else if (!strcmp(argv[i], "-software") || !strcmp(argv[i], "--software")) { + QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL); + } else if (!strcmp(argv[i], "-scaling") || !strcmp(argv[i], "--scaling")) { + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + } else if (!strcmp(argv[i], "-no-scaling") || !strcmp(argv[i], "--no-scaling")) { + QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); } } #else @@ -466,22 +475,24 @@ int main(int argc, char *argv[]) QCommandLineOption dummyDataOption(QStringLiteral("dummy-data"), QCoreApplication::translate("main", "Load QML files from the given directory as context properties."), QStringLiteral("file")); parser.addOption(dummyDataOption); +#ifdef QT_GUI_LIB // OpenGL options QCommandLineOption glDesktopOption(QStringLiteral("desktop"), QCoreApplication::translate("main", "Force use of desktop OpenGL (AA_UseDesktopOpenGL).")); - parser.addOption(glDesktopOption); + parser.addOption(glDesktopOption); // Just for the help text... we've already handled this argument above QCommandLineOption glEsOption(QStringLiteral("gles"), QCoreApplication::translate("main", "Force use of GLES (AA_UseOpenGLES).")); - parser.addOption(glEsOption); + parser.addOption(glEsOption); // Just for the help text... we've already handled this argument above QCommandLineOption glSoftwareOption(QStringLiteral("software"), QCoreApplication::translate("main", "Force use of software rendering (AA_UseSoftwareOpenGL).")); - parser.addOption(glSoftwareOption); + parser.addOption(glSoftwareOption); // Just for the help text... we've already handled this argument above QCommandLineOption scalingOption(QStringLiteral("scaling"), QCoreApplication::translate("main", "Enable High DPI scaling (AA_EnableHighDpiScaling).")); - parser.addOption(scalingOption); + parser.addOption(scalingOption); // Just for the help text... we've already handled this argument above QCommandLineOption noScalingOption(QStringLiteral("no-scaling"), QCoreApplication::translate("main", "Disable High DPI scaling (AA_DisableHighDpiScaling).")); - parser.addOption(noScalingOption); + parser.addOption(noScalingOption); // Just for the help text... we've already handled this argument above +#endif // QT_GUI_LIB // Debugging and verbosity options QCommandLineOption quietOption(QStringLiteral("quiet"), QCoreApplication::translate("main", "Suppress all output.")); @@ -537,16 +548,6 @@ int main(int argc, char *argv[]) if (parser.isSet(fixedAnimationsOption)) QUnifiedTimer::instance()->setConsistentTiming(true); #endif - if (parser.isSet(glEsOption)) - QCoreApplication::setAttribute(Qt::AA_UseOpenGLES); - if (parser.isSet(glSoftwareOption)) - QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL); - if (parser.isSet(glDesktopOption)) - QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); - if (parser.isSet(scalingOption)) - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - if (parser.isSet(noScalingOption)) - QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); for (const QString &importPath : parser.values(importOption)) e.addImportPath(importPath); files << parser.values(qmlFileOption); diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp index 716be0a9a7..20ebef8927 100644 --- a/tools/qmlformat/dumpastvisitor.cpp +++ b/tools/qmlformat/dumpastvisitor.cpp @@ -28,6 +28,8 @@ #include "dumpastvisitor.h" +#include <QtQml/private/qqmljslexer_p.h> + DumpAstVisitor::DumpAstVisitor(Node *rootNode, CommentAstVisitor *comment): m_comment(comment) { // Add all completely orphaned comments @@ -257,6 +259,22 @@ QString DumpAstVisitor::parseFormalParameterList(FormalParameterList *list) return result; } +QString DumpAstVisitor::parsePatternProperty(PatternProperty *property) +{ + return escapeString(property->name->asString())+": "+parsePatternElement(property, false); +} + +QString DumpAstVisitor::parsePatternPropertyList(PatternPropertyList *list) +{ + QString result = ""; + + for (auto *item = list; item != nullptr; item = item->next) { + result += formatLine(parsePatternProperty(item->property) + (item->next != nullptr ? "," : "")); + } + + return result; +} + QString DumpAstVisitor::parseExpression(ExpressionNode *expression) { if (expression == nullptr) @@ -288,13 +306,23 @@ QString DumpAstVisitor::parseExpression(ExpressionNode *expression) auto *functExpr = cast<FunctionExpression *>(expression); m_indentLevel++; - QString result = "function"; + QString result; + + if (!functExpr->isArrowFunction) { + result += "function"; - if (!functExpr->name.isEmpty()) - result += " " + functExpr->name; + if (functExpr->isGenerator) + result += "*"; - result += "("+parseFormalParameterList(functExpr->formals)+") {\n" - + parseStatementList(functExpr->body); + if (!functExpr->name.isEmpty()) + result += " " + functExpr->name; + + result += "("+parseFormalParameterList(functExpr->formals)+") {\n" + + parseStatementList(functExpr->body); + } else { + result += "("+parseFormalParameterList(functExpr->formals)+") => {\n"; + result += parseStatementList(functExpr->body); + } m_indentLevel--; @@ -304,6 +332,8 @@ QString DumpAstVisitor::parseExpression(ExpressionNode *expression) } case Node::Kind_NullExpression: return "null"; + case Node::Kind_ThisExpression: + return "this"; case Node::Kind_PostIncrementExpression: return parseExpression(cast<PostIncrementExpression *>(expression)->base)+"++"; case Node::Kind_PreIncrementExpression: @@ -371,6 +401,44 @@ QString DumpAstVisitor::parseExpression(ExpressionNode *expression) return result; } + case Node::Kind_ObjectPattern: { + auto *objectPattern = cast<ObjectPattern*>(expression); + QString result = "{\n"; + + m_indentLevel++; + result += parsePatternPropertyList(objectPattern->properties); + m_indentLevel--; + + result += formatLine("}", false); + + return result; + } + case Node::Kind_Expression: { + auto* expr = cast<Expression*>(expression); + return parseExpression(expr->left)+", "+parseExpression(expr->right); + } + case Node::Kind_Type: { + auto* type = reinterpret_cast<Type*>(expression); + + return parseUiQualifiedId(type->typeId); + } + case Node::Kind_RegExpLiteral: { + auto* regexpLiteral = cast<RegExpLiteral*>(expression); + QString result = "/"+regexpLiteral->pattern+"/"; + + if (regexpLiteral->flags & QQmlJS::Lexer::RegExp_Unicode) + result += "u"; + if (regexpLiteral->flags & QQmlJS::Lexer::RegExp_Global) + result += "g"; + if (regexpLiteral->flags & QQmlJS::Lexer::RegExp_Multiline) + result += "m"; + if (regexpLiteral->flags & QQmlJS::Lexer::RegExp_Sticky) + result += "y"; + if (regexpLiteral->flags & QQmlJS::Lexer::RegExp_IgnoreCase) + result += "i"; + + return result; + } default: m_error = true; return "unknown_expression_"+QString::number(expression->kind); @@ -383,7 +451,7 @@ QString DumpAstVisitor::parseVariableDeclarationList(VariableDeclarationList *li for (auto *item = list; item != nullptr; item = item->next) { result += parsePatternElement(item->declaration, (item == list)) - + (item->next != nullptr ? ", " : ""); + + (item->next != nullptr ? ", " : ""); } return result; @@ -469,7 +537,7 @@ QString DumpAstVisitor::parseStatement(Statement *statement, bool blockHasNext, case Node::Kind_VariableStatement: return parseVariableDeclarationList(cast<VariableStatement *>(statement)->declarations); case Node::Kind_ReturnStatement: - return "return "+parseExpression(cast<ReturnStatement *>(statement)->expression); + return "return "+parseExpression(cast<ReturnStatement *>(statement)->expression); case Node::Kind_ContinueStatement: return "continue"; case Node::Kind_BreakStatement: @@ -705,7 +773,7 @@ bool DumpAstVisitor::visit(UiPublicMember *node) { addLine("signal "+node->name.toString()+"("+parseUiParameterList(node->parameters) + ")" + commentBackInline); - break; + break; case UiPublicMember::Property: { if (m_firstProperty) { if (m_firstOfAll) @@ -912,7 +980,15 @@ bool DumpAstVisitor::visit(FunctionDeclaration *node) { addNewLine(); addLine(getComment(node, Comment::Location::Front)); - addLine("function "+node->name+"("+parseFormalParameterList(node->formals)+") {"); + + QString head = "function"; + + if (node->isGenerator) + head += "*"; + + head += " "+node->name+"("+parseFormalParameterList(node->formals)+") {"; + + addLine(head); m_indentLevel++; m_result += parseStatementList(node->body); m_indentLevel--; @@ -970,8 +1046,8 @@ bool DumpAstVisitor::visit(UiImport *node) { result += parseUiQualifiedId(node->importUri); if (node->version) { - result += " " + QString::number(node->version->majorVersion) + "." - + QString::number(node->version->minorVersion); + result += " " + QString::number(node->version->majorVersion) + "." + + QString::number(node->version->minorVersion); } if (node->asToken.isValid()) { diff --git a/tools/qmlformat/dumpastvisitor.h b/tools/qmlformat/dumpastvisitor.h index e73a7b628f..2001f4366e 100644 --- a/tools/qmlformat/dumpastvisitor.h +++ b/tools/qmlformat/dumpastvisitor.h @@ -89,6 +89,9 @@ private: QString parsePatternElement(PatternElement *element, bool scope = true); QString parsePatternElementList(PatternElementList *element); + QString parsePatternProperty(PatternProperty *property); + QString parsePatternPropertyList(PatternPropertyList *list); + QString parseArgumentList(ArgumentList *list); QString parseUiParameterList(UiParameterList *list); diff --git a/tools/qmlformat/main.cpp b/tools/qmlformat/main.cpp index bca788d316..036fbe9748 100644 --- a/tools/qmlformat/main.cpp +++ b/tools/qmlformat/main.cpp @@ -43,7 +43,7 @@ #include "dumpastvisitor.h" #include "restructureastvisitor.h" -bool parseFile(const QString& filename, bool inplace, bool verbose, bool sortImports) +bool parseFile(const QString& filename, bool inplace, bool verbose, bool sortImports, bool force) { QFile file(filename); @@ -101,8 +101,14 @@ bool parseFile(const QString& filename, bool inplace, bool verbose, bool sortImp DumpAstVisitor dump(parser.rootNode(), &comment); - if (dump.error()) - qWarning().noquote() << "An error has occurred. The output may not be reliable."; + if (dump.error()) { + if (force) { + qWarning().noquote() << "An error has occurred. The output may not be reliable."; + } else { + qWarning().noquote() << "Am error has occurred. Aborting."; + return false; + } + } if (inplace) { if (verbose) @@ -145,6 +151,9 @@ int main(int argc, char *argv[]) parser.addOption(QCommandLineOption({"i", "inplace"}, QStringLiteral("Edit file in-place instead of outputting to stdout."))); + parser.addOption(QCommandLineOption({"f", "force"}, + QStringLiteral("Continue even if an error has occurred."))); + parser.addPositionalArgument("filenames", "files to be processed by qmlformat"); parser.process(app); @@ -155,7 +164,7 @@ int main(int argc, char *argv[]) parser.showHelp(-1); for (const QString& file: parser.positionalArguments()) { - if (!parseFile(file, parser.isSet("inplace"), parser.isSet("verbose"), !parser.isSet("no-sort"))) + if (!parseFile(file, parser.isSet("inplace"), parser.isSet("verbose"), !parser.isSet("no-sort"), parser.isSet("force"))) success = false; } #endif diff --git a/tools/qmlimportscanner/Qt5QmlImportScannerConfig.cmake.in b/tools/qmlimportscanner/Qt5QmlImportScannerConfig.cmake.in index 6cdfaf8f6f..f92b8d295d 100644 --- a/tools/qmlimportscanner/Qt5QmlImportScannerConfig.cmake.in +++ b/tools/qmlimportscanner/Qt5QmlImportScannerConfig.cmake.in @@ -182,3 +182,13 @@ but this file does not exist. Possible reasons include: endif() !!ENDIF // !isEmpty(CMAKE_STATIC_TYPE) endfunction() + +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_import_qml_plugins) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_import_qml_plugins(${ARGV}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_import_qml_plugins(${ARGV}) + endif() + endfunction() +endif() diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp index c37910bdaf..b563d7df95 100644 --- a/tools/qmlimportscanner/main.cpp +++ b/tools/qmlimportscanner/main.cpp @@ -509,7 +509,7 @@ QString generateCmakeIncludeFileContent(const QVariantList &importList) { QTextStream s(&content); int importsCount = 0; for (const QVariant &importVariant: importList) { - if (static_cast<QMetaType::Type>(importVariant.type()) == QMetaType::QVariantMap) { + if (static_cast<QMetaType::Type>(importVariant.userType()) == QMetaType::QVariantMap) { s << QStringLiteral("set(qml_import_scanner_import_") << importsCount << QStringLiteral(" \""); diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp index 260c5bb7d1..28370cb522 100644 --- a/tools/qmlscene/main.cpp +++ b/tools/qmlscene/main.cpp @@ -36,7 +36,7 @@ #include <QtCore/qregularexpression.h> #include <QtGui/QGuiApplication> -#include <QtGui/QOpenGLFunctions> +#include <QOpenGLFunctions> #include <QtQml/qqml.h> #include <QtQml/qqmlengine.h> |