diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/fdegen/fdegen.pro | 8 | ||||
-rw-r--r-- | tools/fdegen/main.cpp | 362 | ||||
-rw-r--r-- | tools/qml/main.cpp | 27 | ||||
-rw-r--r-- | tools/qml/qml.pro | 2 | ||||
-rw-r--r-- | tools/qmleasing/mainwindow.cpp | 3 | ||||
-rw-r--r-- | tools/qmleasing/splineeditor.cpp | 21 | ||||
-rw-r--r-- | tools/qmlimportscanner/main.cpp | 104 | ||||
-rw-r--r-- | tools/qmljs/qmljs.cpp | 20 | ||||
-rw-r--r-- | tools/qmllint/main.cpp | 9 | ||||
-rw-r--r-- | tools/qmlmin/main.cpp | 2 | ||||
-rw-r--r-- | tools/qmlplugindump/main.cpp | 134 | ||||
-rw-r--r-- | tools/qmlplugindump/qmlplugindump.pro | 2 | ||||
-rw-r--r-- | tools/qmlplugindump/qmlstreamwriter.cpp | 2 | ||||
-rw-r--r-- | tools/qmlplugindump/qmltypereader.cpp | 2 | ||||
-rw-r--r-- | tools/qmlprofiler/commandlistener.h | 2 | ||||
-rw-r--r-- | tools/qmlprofiler/main.cpp | 6 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofilerapplication.cpp | 38 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofilerapplication.h | 11 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofilerdata.cpp | 18 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofilerdata.h | 11 | ||||
-rw-r--r-- | tools/qmlscene/main.cpp | 17 | ||||
-rw-r--r-- | tools/qmlscene/qmlscene.pro | 3 | ||||
-rw-r--r-- | tools/tools.pro | 2 |
23 files changed, 242 insertions, 564 deletions
diff --git a/tools/fdegen/fdegen.pro b/tools/fdegen/fdegen.pro deleted file mode 100644 index a52533280e..0000000000 --- a/tools/fdegen/fdegen.pro +++ /dev/null @@ -1,8 +0,0 @@ -TEMPLATE = app -TARGET = fdegen -INCLUDEPATH += . - -# Input -SOURCES += main.cpp - -LIBS += -ldwarf -lelf diff --git a/tools/fdegen/main.cpp b/tools/fdegen/main.cpp deleted file mode 100644 index 53ee9dec2a..0000000000 --- a/tools/fdegen/main.cpp +++ /dev/null @@ -1,362 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the V4VM module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** 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$ -** -****************************************************************************/ - -#include <libdwarf.h> -#include <dwarf.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> - -#define DEBUG - -#ifdef DEBUG -#include <libelf.h> -#endif - -#include <qglobal.h> - -enum DwarfRegs { -#if defined(Q_PROCESSOR_X86_64) - // X86-64 - RAX = 0, - RDX = 1, - RCX = 2, - RBX = 3, - RSI = 4, - RDI = 5, - RBP = 6, - RSP = 7, - R8 = 8, - R9 = 9, - R10 = 10, - R11 = 11, - R12 = 12, - R13 = 13, - R14 = 14, - R15 = 15, - RIP = 16, - - InstructionPointerRegister = RIP, - StackPointerRegister = RSP, - StackFrameRegister = RBP -#elif defined(Q_PROCESSOR_X86) - // x86 - EAX = 0, - EDX = 1, - ECX = 2, - EBX = 3, - ESP = 4, - EBP = 5, - ESI = 6, - EDI = 7, - EIP = 8, - - InstructionPointerRegister = EIP, - StackPointerRegister = ESP, - StackFrameRegister = EBP -#else -#error Not ported yet -#endif -}; - -static const DwarfRegs calleeSavedRegisters[] = { -#if defined(Q_PROCESSOR_X86_64) - R12, - R14 -#elif defined(Q_PROCESSOR_X86) - ESI, - EDI -#endif -}; -static const int calleeSavedRegisterCount = sizeof(calleeSavedRegisters) / sizeof(calleeSavedRegisters[0]); - -#if QT_POINTER_SIZE == 8 -#define Elf_Ehdr Elf64_Ehdr -#define elf_newehdr elf64_newehdr -#define Elf_Shdr Elf64_Shdr -#define elf_getshdr elf64_getshdr -#else -#define Elf_Ehdr Elf32_Ehdr -#define elf_newehdr elf32_newehdr -#define Elf_Shdr Elf32_Shdr -#define elf_getshdr elf32_getshdr -#endif - -static void die(const char *msg) -{ - fprintf(stderr, "error: %s\n", msg); - exit(1); -} - -static int createSectionCallback( - char *name, - int size, - Dwarf_Unsigned /*type*/, - Dwarf_Unsigned /*flags*/, - Dwarf_Unsigned /*link*/, - Dwarf_Unsigned /*info*/, - Dwarf_Unsigned* /*sect_name_index*/, - void * /*user_data*/, - int* /*error*/) -{ - if (strcmp(name, ".debug_frame")) - return 0; - fprintf(stderr, "createsection called with %s and size %d\n", name, size); - return 1; -} - -static unsigned char cie_init_instructions[] = { - DW_CFA_def_cfa, StackPointerRegister, /*offset in bytes */sizeof(void*), - DW_CFA_offset | InstructionPointerRegister, 1, -}; - -int main() -{ - Dwarf_Error error = 0; - Dwarf_P_Debug dw = dwarf_producer_init_c(DW_DLC_WRITE | DW_DLC_SIZE_64, - createSectionCallback, - /* error handler */0, - /* error arg */0, - /* user data */0, - &error); - if (error != 0) - die("dwarf_producer_init_c failed"); - - Dwarf_Unsigned cie = dwarf_add_frame_cie(dw, - "", - /* code alignment factor */sizeof(void*), - /* data alignment factor */-sizeof(void*), - /* return address reg*/InstructionPointerRegister, - cie_init_instructions, - sizeof(cie_init_instructions), - &error); - if (error != 0) - die("dwarf_add_frame_cie failed"); - - Dwarf_P_Fde fde = dwarf_new_fde(dw, &error); - if (error != 0) - die("dwarf_new_fde failed"); - - /* New entry in state machine for code offset 1 after push rbp instruction */ - dwarf_add_fde_inst(fde, - DW_CFA_advance_loc, - /*offset in code alignment units*/ 1, - /* unused*/ 0, - &error); - - /* After "push rbp" the offset to the CFA is now 2 instead of 1 */ - dwarf_add_fde_inst(fde, - DW_CFA_def_cfa_offset_sf, - /*offset in code alignment units*/ -2, - /* unused*/ 0, - &error); - - /* After "push rbp" the value of rbp is now stored at offset 1 from CFA */ - dwarf_add_fde_inst(fde, - DW_CFA_offset, - StackFrameRegister, - 2, - &error); - - /* New entry in state machine for code offset 3 for mov rbp, rsp instruction */ - dwarf_add_fde_inst(fde, - DW_CFA_advance_loc, - /*offset in code alignment units*/ 3, - /* unused */ 0, - &error); - - /* After "mov rbp, rsp" the cfa is reachable via rbp */ - dwarf_add_fde_inst(fde, - DW_CFA_def_cfa_register, - StackFrameRegister, - /* unused */0, - &error); - - /* Callee saved registers */ - for (int i = 0; i < calleeSavedRegisterCount; ++i) { - dwarf_add_fde_inst(fde, - DW_CFA_offset, - calleeSavedRegisters[i], - i + 3, - &error); - } - - dwarf_add_frame_fde(dw, fde, - /* die */0, - cie, - /*virt addr */0, - /* length of code */0, - /* symbol index */0, - &error); - if (error != 0) - die("dwarf_add_frame_fde failed"); - - dwarf_transform_to_disk_form(dw, &error); - if (error != 0) - die("dwarf_transform_to_disk_form failed"); - - Dwarf_Unsigned len = 0; - Dwarf_Signed elfIdx = 0; - unsigned char *bytes = (unsigned char *)dwarf_get_section_bytes(dw, /* section */1, - &elfIdx, &len, &error); - if (error != 0) - die("dwarf_get_section_bytes failed"); - - // libdwarf doesn't add a terminating FDE with zero length, so let's add one - // ourselves. - unsigned char *newBytes = (unsigned char *)alloca(len + 4); - memcpy(newBytes, bytes, len); - newBytes[len] = 0; - newBytes[len + 1] = 0; - newBytes[len + 2] = 0; - newBytes[len + 3] = 0; - newBytes[len + 4] = 0; - bytes = newBytes; - len += 4; - - // Reset CIE-ID back to 0 as expected for .eh_frames - bytes[4] = 0; - bytes[5] = 0; - bytes[6] = 0; - bytes[7] = 0; - - unsigned fde_offset = bytes[0] + 4; - - bytes[fde_offset + 4] = fde_offset + 4; - - printf("static const unsigned char cie_fde_data[] = {\n"); - int i = 0; - while (i < len) { - printf(" "); - for (int j = 0; i < len && j < 8; ++j, ++i) - printf("0x%x, ", bytes[i]); - printf("\n"); - } - printf("};\n"); - - printf("static const int fde_offset = %d;\n", fde_offset); - printf("static const int initial_location_offset = %d;\n", fde_offset + 8); - printf("static const int address_range_offset = %d;\n", fde_offset + 8 + sizeof(void*)); - -#ifdef DEBUG - { - if (elf_version(EV_CURRENT) == EV_NONE) - die("wrong elf version"); - int fd = open("debug.o", O_WRONLY | O_CREAT, 0777); - if (fd < 0) - die("cannot create debug.o"); - - Elf *e = elf_begin(fd, ELF_C_WRITE, 0); - if (!e) - die("elf_begin failed"); - - Elf_Ehdr *ehdr = elf_newehdr(e); - if (!ehdr) - die(elf_errmsg(-1)); - - ehdr->e_ident[EI_DATA] = ELFDATA2LSB; -#if defined(Q_PROCESSOR_X86_64) - ehdr->e_machine = EM_X86_64; -#elif defined(Q_PROCESSOR_X86) - ehdr->e_machine = EM_386; -#else -#error port me :) -#endif - ehdr->e_type = ET_EXEC; - ehdr->e_version = EV_CURRENT; - - Elf_Scn *section = elf_newscn(e); - if (!section) - die("elf_newscn failed"); - - Elf_Data *data = elf_newdata(section); - if (!data) - die(elf_errmsg(-1)); - data->d_align = 4; - data->d_off = 0; - data->d_buf = bytes; - data->d_size = len; - data->d_type = ELF_T_BYTE; - data->d_version = EV_CURRENT; - - Elf_Shdr *shdr = elf_getshdr(section); - if (!shdr) - die(elf_errmsg(-1)); - - shdr->sh_name = 1; - shdr->sh_type = SHT_PROGBITS; - shdr->sh_entsize = 0; - - char stringTable[] = { - 0, - '.', 'e', 'h', '_', 'f', 'r', 'a', 'm', 'e', 0, - '.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', 0 - }; - - section = elf_newscn(e); - if (!section) - die("elf_newscn failed"); - - data = elf_newdata(section); - if (!data) - die(elf_errmsg(-1)); - data->d_align = 1; - data->d_off = 0; - data->d_buf = stringTable; - data->d_size = sizeof(stringTable); - data->d_type = ELF_T_BYTE; - data->d_version = EV_CURRENT; - - shdr = elf_getshdr(section); - if (!shdr) - die(elf_errmsg(-1)); - - shdr->sh_name = 11; - shdr->sh_type = SHT_STRTAB; - shdr->sh_flags = SHF_STRINGS | SHF_ALLOC; - shdr->sh_entsize = 0; - - ehdr->e_shstrndx = elf_ndxscn(section); - - if (elf_update(e, ELF_C_WRITE) < 0) - die(elf_errmsg(-1)); - - elf_end(e); - close(fd); - } -#endif - - dwarf_producer_finish(dw, &error); - if (error != 0) - die("dwarf_producer_finish failed"); - return 0; -} diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index a795144984..fdfc66f3a6 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -160,18 +160,23 @@ public: LoadWatcher(QQmlApplicationEngine *e, int expected) : QObject(e) , earlyExit(false) + , returnCode(0) , expect(expected) , haveOne(false) { connect(e, SIGNAL(objectCreated(QObject*,QUrl)), this, SLOT(checkFinished(QObject*))); // QQmlApplicationEngine also connects quit() to QCoreApplication::quit - // but if called before exec() then QCoreApplication::quit does nothing + // and exit() to QCoreApplication::exit but if called before exec() + // then QCoreApplication::quit or QCoreApplication::exit does nothing connect(e, SIGNAL(quit()), this, SLOT(quit())); + connect(e, &QQmlEngine::exit, + this, &LoadWatcher::exit); } bool earlyExit; + int returnCode; private: void contain(QObject *o, const QUrl &containPath); @@ -187,7 +192,7 @@ public Q_SLOTS: checkForWindow(o); haveOne = true; if (conf && qae) - foreach (PartialScene *ps, conf->completers) + for (PartialScene *ps : qAsConst(conf->completers)) if (o->inherits(ps->itemType().toUtf8().constData())) contain(o, ps->container()); } @@ -196,14 +201,20 @@ public Q_SLOTS: if (! --expect) { printf("qml: Did not load any objects, exiting.\n"); - exit(2);//Different return code from qFatal + std::exit(2);//Different return code from qFatal } } void quit() { //Will be checked before calling exec() earlyExit = true; + returnCode = 0; } + void exit(int retCode) { + earlyExit = true; + returnCode = retCode; + } + #if defined(QT_GUI_LIB) && !defined(QT_NO_OPENGL) void onOpenGlContextCreated(QOpenGLContext *context); #endif @@ -402,8 +413,8 @@ static void loadDummyDataFiles(QQmlEngine &engine, const QString& directory) QObject *dummyData = comp.create(); if (comp.isError()) { - QList<QQmlError> errors = comp.errors(); - foreach (const QQmlError &error, errors) + const QList<QQmlError> errors = comp.errors(); + for (const QQmlError &error : errors) qWarning() << error; } @@ -452,7 +463,7 @@ int main(int argc, char *argv[]) QString dummyDir; //Handle main arguments - QStringList argList = app->arguments(); + const QStringList argList = app->arguments(); for (int i = 1; i < argList.count(); i++) { const QString &arg = argList[i]; if (arg == QLatin1String("-quiet")) @@ -555,7 +566,7 @@ int main(int argc, char *argv[]) if (!dummyDir.isEmpty() && QFileInfo (dummyDir).isDir()) loadDummyDataFiles(e, dummyDir); - foreach (const QString &path, files) { + for (const QString &path : qAsConst(files)) { //QUrl::fromUserInput doesn't treat no scheme as relative file paths #ifndef QT_NO_REGULAREXPRESSION QRegularExpression urlRe("[[:word:]]+://.*"); @@ -582,7 +593,7 @@ int main(int argc, char *argv[]) } if (lw->earlyExit) - return 0; + return lw->returnCode; return app->exec(); } diff --git a/tools/qml/qml.pro b/tools/qml/qml.pro index fe90916980..5f05054d04 100644 --- a/tools/qml/qml.pro +++ b/tools/qml/qml.pro @@ -12,6 +12,6 @@ mac { ICON = qml.icns } -DEFINES += QT_QML_DEBUG_NO_WARNING +!contains(QT_CONFIG, no-qml-debug): DEFINES += QT_QML_DEBUG_NO_WARNING load(qt_tool) diff --git a/tools/qmleasing/mainwindow.cpp b/tools/qmleasing/mainwindow.cpp index 5a5f651396..d36ab5fd75 100644 --- a/tools/qmleasing/mainwindow.cpp +++ b/tools/qmleasing/mainwindow.cpp @@ -73,7 +73,8 @@ MainWindow::MainWindow(QWidget *parent) : quickView.rootContext()->setContextProperty(QLatin1String("spinBox"), ui_properties.spinBox); - foreach (const QString &name, splineEditor->presetNames()) + const auto presetNames = splineEditor->presetNames(); + for (const QString &name : presetNames) ui_properties.comboBox->addItem(name); connect(ui_properties.comboBox, SIGNAL(currentIndexChanged(QString)), splineEditor, SLOT(setPreset(QString))); diff --git a/tools/qmleasing/splineeditor.cpp b/tools/qmleasing/splineeditor.cpp index 78ed9606db..d54a101b69 100644 --- a/tools/qmleasing/splineeditor.cpp +++ b/tools/qmleasing/splineeditor.cpp @@ -34,6 +34,7 @@ #include <QContextMenuEvent> #include <QDebug> #include <QApplication> +#include <QVector> const int canvasWidth = 640; const int canvasHeight = 320; @@ -287,7 +288,7 @@ QHash<QString, QEasingCurve> SplineEditor::presets() const QString SplineEditor::generateCode() { QString s = QLatin1String("["); - foreach (const QPointF &point, m_controlPoints) { + for (const QPointF &point : qAsConst(m_controlPoints)) { s += QString::number(point.x(), 'g', 2) + QLatin1Char(',') + QString::number(point.y(), 'g', 3) + QLatin1Char(','); } @@ -619,7 +620,7 @@ void SplineEditor::mouseMoveEvent(QMouseEvent *e) if (indexIsRealPoint(m_activeControlPoint)) { //move also the tangents QPointF targetPoint = p; - QPointF distance = targetPoint - m_controlPoints[m_activeControlPoint]; + QPointF distance = targetPoint - m_controlPoints.at(m_activeControlPoint); m_controlPoints[m_activeControlPoint] = targetPoint; m_controlPoints[m_activeControlPoint - 1] += distance; m_controlPoints[m_activeControlPoint + 1] += distance; @@ -628,7 +629,7 @@ void SplineEditor::mouseMoveEvent(QMouseEvent *e) m_controlPoints[m_activeControlPoint] = p; } else { QPointF targetPoint = p; - QPointF distance = targetPoint - m_controlPoints[m_activeControlPoint]; + QPointF distance = targetPoint - m_controlPoints.at(m_activeControlPoint); m_controlPoints[m_activeControlPoint] = p; if ((m_activeControlPoint > 1) && (m_activeControlPoint % 3) == 0) { //right control point @@ -672,25 +673,23 @@ void SplineEditor::setEasingCurve(const QString &code) if (m_block) return; if (code.startsWith(QLatin1Char('[')) && code.endsWith(QLatin1Char(']'))) { - QString cleanCode = code; - cleanCode.remove(0, 1); - cleanCode.chop(1); - const QStringList stringList = cleanCode.split(QLatin1Char(','), QString::SkipEmptyParts); + const QStringRef cleanCode(&code, 1, code.size() - 2); + const auto stringList = cleanCode.split(QLatin1Char(','), QString::SkipEmptyParts); if (stringList.count() >= 6 && (stringList.count() % 6 == 0)) { - QList<qreal> realList; + QVector<qreal> realList; realList.reserve(stringList.count()); - foreach (const QString &string, stringList) { + for (const QStringRef &string : stringList) { bool ok; realList.append(string.toDouble(&ok)); if (!ok) return; } - QList<QPointF> points; + QVector<QPointF> points; const int count = realList.count() / 2; points.reserve(count); for (int i = 0; i < count; ++i) points.append(QPointF(realList.at(i * 2), realList.at(i * 2 + 1))); - if (points.last() == QPointF(1.0, 1.0)) { + if (points.constLast() == QPointF(1.0, 1.0)) { QEasingCurve easingCurve(QEasingCurve::BezierSpline); for (int i = 0; i < points.count() / 3; ++i) { diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp index 2569d78c63..8f476649e9 100644 --- a/tools/qmlimportscanner/main.cpp +++ b/tools/qmlimportscanner/main.cpp @@ -55,6 +55,14 @@ QT_USE_NAMESPACE QStringList g_qmlImportPaths; +static inline QString typeLiteral() { return QStringLiteral("type"); } +static inline QString versionLiteral() { return QStringLiteral("version"); } +static inline QString nameLiteral() { return QStringLiteral("name"); } +static inline QString pluginsLiteral() { return QStringLiteral("plugins"); } +static inline QString pathLiteral() { return QStringLiteral("path"); } +static inline QString classnamesLiteral() { return QStringLiteral("classnames"); } +static inline QString dependenciesLiteral() { return QStringLiteral("dependencies"); } + static void printUsage(const QString &appNameIn) { const std::wstring appName = appNameIn.toStdWString(); @@ -84,14 +92,14 @@ QVariantList findImportsInAst(QQmlJS::AST::UiHeaderItemList *headerItemList, con // handle directory imports if (!importNode->fileName.isEmpty()) { QString name = importNode->fileName.toString(); - import[QStringLiteral("name")] = name; + import[nameLiteral()] = name; if (name.endsWith(QLatin1String(".js"))) { - import[QStringLiteral("type")] = QStringLiteral("javascript"); + import[typeLiteral()] = QStringLiteral("javascript"); } else { - import[QStringLiteral("type")] = QStringLiteral("directory"); + import[typeLiteral()] = QStringLiteral("directory"); } - import[QStringLiteral("path")] = QDir::cleanPath(path + QLatin1Char('/') + name); + import[pathLiteral()] = QDir::cleanPath(path + QLatin1Char('/') + name); } else { // Walk the id chain ("Foo" -> "Bar" -> etc) QString name; @@ -103,9 +111,9 @@ QVariantList findImportsInAst(QQmlJS::AST::UiHeaderItemList *headerItemList, con } name.chop(1); // remove trailing "." if (!name.isEmpty()) - import[QStringLiteral("name")] = name; - import[QStringLiteral("type")] = QStringLiteral("module"); - import[QStringLiteral("version")] = code.mid(importNode->versionToken.offset, importNode->versionToken.length); + import[nameLiteral()] = name; + import[typeLiteral()] = QStringLiteral("module"); + import[versionLiteral()] = code.mid(importNode->versionToken.offset, importNode->versionToken.length); } imports.append(import); @@ -117,7 +125,7 @@ QVariantList findImportsInAst(QQmlJS::AST::UiHeaderItemList *headerItemList, con // Read the qmldir file, extract a list of plugins by // parsing the "plugin" and "classname" lines. QVariantMap pluginsForModulePath(const QString &modulePath) { - QFile qmldirFile(modulePath + QStringLiteral("/qmldir")); + QFile qmldirFile(modulePath + QLatin1String("/qmldir")); if (!qmldirFile.exists()) return QVariantMap(); @@ -137,20 +145,20 @@ QVariantMap pluginsForModulePath(const QString &modulePath) { classnames += QString::fromUtf8(line.split(' ').at(1)); classnames += QLatin1Char(' '); } else if (line.startsWith("depends")) { - QList<QByteArray> dep = line.split(' '); + const QList<QByteArray> dep = line.split(' '); if (dep.length() != 3) std::cerr << "depends: expected 2 arguments: module identifier and version" << std::endl; else - dependencies << QString::fromUtf8(dep[1]) + QStringLiteral(" ") + QString::fromUtf8(dep[2]).simplified(); + dependencies << QString::fromUtf8(dep[1]) + QLatin1Char(' ') + QString::fromUtf8(dep[2]).simplified(); } } while (line.length() > 0); QVariantMap pluginInfo; - pluginInfo[QStringLiteral("plugins")] = plugins.simplified(); - pluginInfo[QStringLiteral("classnames")] = classnames.simplified(); + pluginInfo[pluginsLiteral()] = plugins.simplified(); + pluginInfo[classnamesLiteral()] = classnames.simplified(); if (dependencies.length()) - pluginInfo[QStringLiteral("dependencies")] = dependencies; + pluginInfo[dependenciesLiteral()] = dependencies; return pluginInfo; } @@ -163,7 +171,7 @@ QString resolveImportPath(const QString &uri, const QString &version) QString ver = version; while (true) { - foreach (const QString &qmlImportPath, g_qmlImportPaths) { + for (const QString &qmlImportPath : qAsConst(g_qmlImportPaths)) { // Search for the most specific version first, and search // also for the version in parent modules. For example: // - qml/QtQml/Models.2.0 @@ -209,26 +217,26 @@ QVariantList findPathsForModuleImports(const QVariantList &imports) QVariantList importsCopy(imports); for (int i = 0; i < importsCopy.length(); ++i) { - QVariantMap import = qvariant_cast<QVariantMap>(importsCopy[i]); - if (import[QStringLiteral("type")] == QLatin1String("module")) { - QString path = resolveImportPath(import.value(QStringLiteral("name")).toString(), import.value(QStringLiteral("version")).toString()); + QVariantMap import = qvariant_cast<QVariantMap>(importsCopy.at(i)); + if (import.value(typeLiteral()) == QLatin1String("module")) { + QString path = resolveImportPath(import.value(nameLiteral()).toString(), import.value(versionLiteral()).toString()); if (!path.isEmpty()) - import[QStringLiteral("path")] = path; - QVariantMap plugininfo = pluginsForModulePath(import.value(QStringLiteral("path")).toString()); - QString plugins = plugininfo.value(QStringLiteral("plugins")).toString(); - QString classnames = plugininfo.value(QStringLiteral("classnames")).toString(); + import[pathLiteral()] = path; + QVariantMap plugininfo = pluginsForModulePath(import.value(pathLiteral()).toString()); + QString plugins = plugininfo.value(pluginsLiteral()).toString(); + QString classnames = plugininfo.value(classnamesLiteral()).toString(); if (!plugins.isEmpty()) - import[QStringLiteral("plugin")] = plugins; + import.insert(QStringLiteral("plugin"), plugins); if (!classnames.isEmpty()) - import[QStringLiteral("classname")] = classnames; - if (plugininfo.contains(QStringLiteral("dependencies"))) { - QStringList dependencies = plugininfo.value(QStringLiteral("dependencies")).toStringList(); - foreach (const QString &line, dependencies) { - QList<QString> dep = line.split(QLatin1Char(' ')); + import.insert(QStringLiteral("classname"), classnames); + if (plugininfo.contains(dependenciesLiteral())) { + const QStringList dependencies = plugininfo.value(dependenciesLiteral()).toStringList(); + for (const QString &line : dependencies) { + const auto dep = line.splitRef(QLatin1Char(' ')); QVariantMap depImport; - depImport[QStringLiteral("type")] = QStringLiteral("module"); - depImport[QStringLiteral("name")] = dep[0]; - depImport[QStringLiteral("version")] = dep[1]; + depImport[typeLiteral()] = QStringLiteral("module"); + depImport[nameLiteral()] = dep[0].toString(); + depImport[versionLiteral()] = dep[1].toString(); importsCopy.append(depImport); } } @@ -248,7 +256,8 @@ static QVariantList findQmlImportsInQmlCode(const QString &filePath, const QStri if (!parser.parse() || !parser.diagnosticMessages().isEmpty()) { // Extract errors from the parser - foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) { + const auto diagnosticMessages = parser.diagnosticMessages(); + for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { std::cerr << QDir::toNativeSeparators(filePath).toStdString() << ':' << m.loc.startLine << ':' << m.message.toStdString() << std::endl; } @@ -277,8 +286,8 @@ struct ImportCollector : public QQmlJS::Directives virtual void importFile(const QString &jsfile, const QString &module, int line, int column) { QVariantMap entry; - entry[QLatin1String("type")] = QStringLiteral("javascript"); - entry[QLatin1String("path")] = jsfile; + entry[typeLiteral()] = QStringLiteral("javascript"); + entry[pathLiteral()] = jsfile; imports << entry; Q_UNUSED(module); @@ -290,12 +299,12 @@ struct ImportCollector : public QQmlJS::Directives { QVariantMap entry; if (uri.contains(QLatin1Char('/'))) { - entry[QLatin1String("type")] = QStringLiteral("directory"); - entry[QLatin1String("name")] = uri; + entry[typeLiteral()] = QStringLiteral("directory"); + entry[nameLiteral()] = uri; } else { - entry[QLatin1String("type")] = QStringLiteral("module"); - entry[QLatin1String("name")] = uri; - entry[QLatin1String("version")] = version; + entry[typeLiteral()] = QStringLiteral("module"); + entry[nameLiteral()] = uri; + entry[versionLiteral()] = version; } imports << entry; @@ -326,7 +335,8 @@ QVariantList findQmlImportsInJavascriptFile(const QString &filePath) QQmlJS::Parser parser(&ee); parser.parseProgram(); - foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) + const auto diagnosticMessages = parser.diagnosticMessages(); + for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) if (m.isError()) return QVariantList(); @@ -354,7 +364,7 @@ QVariantList findQmlImportsInFile(const QString &filePath) QVariantList mergeImports(const QVariantList &a, const QVariantList &b) { QVariantList merged = a; - foreach (const QVariant &variant, b) { + for (const QVariant &variant : b) { if (!merged.contains(variant)) merged.append(variant); } @@ -413,19 +423,19 @@ QVariantList findQmlImportsInDirectory(const QString &qmlDir) continue; } - foreach (const QFileInfo &x, entries) + for (const QFileInfo &x : entries) if (x.isFile()) ret = mergeImports(ret, findQmlImportsInFile(x.absoluteFilePath())); } return ret; } -QSet<QString> importModulePaths(QVariantList imports) { +QSet<QString> importModulePaths(const QVariantList &imports) { QSet<QString> ret; - foreach (const QVariant &importVariant, imports) { + for (const QVariant &importVariant : imports) { QVariantMap import = qvariant_cast<QVariantMap>(importVariant); - QString path = import.value(QStringLiteral("path")).toString(); - QString type = import.value(QStringLiteral("type")).toString(); + QString path = import.value(pathLiteral()).toString(); + QString type = import.value(typeLiteral()).toString(); if (type == QLatin1String("module") && !path.isEmpty()) ret.insert(QDir(path).canonicalPath()); } @@ -440,13 +450,13 @@ QVariantList findQmlImportsRecursively(const QStringList &qmlDirs, const QString QVariantList ret; // scan all app root qml directories for imports - foreach (const QString &qmlDir, qmlDirs) { + for (const QString &qmlDir : qmlDirs) { QVariantList imports = findQmlImportsInDirectory(qmlDir); ret = mergeImports(ret, imports); } // scan app qml files for imports - foreach (const QString &file, scanFiles) { + for (const QString &file : scanFiles) { QVariantList imports = findQmlImportsInFile(file); ret = mergeImports(ret, imports); } diff --git a/tools/qmljs/qmljs.cpp b/tools/qmljs/qmljs.cpp index 68aa52ce91..44ff37b925 100644 --- a/tools/qmljs/qmljs.cpp +++ b/tools/qmljs/qmljs.cpp @@ -68,7 +68,7 @@ struct Print: FunctionObject }; V4_OBJECT(FunctionObject) - static ReturnedValue call(const Managed *, CallData *callData) + static void call(const Managed *, Scope &scope, CallData *callData) { for (int i = 0; i < callData->argc; ++i) { QString s = callData->args[i].toQStringNoThrow(); @@ -77,7 +77,7 @@ struct Print: FunctionObject std::cout << qPrintable(s); } std::cout << std::endl; - return Encode::undefined(); + scope.result = Encode::undefined(); } }; @@ -94,10 +94,10 @@ struct GC: public FunctionObject }; V4_OBJECT(FunctionObject) - static ReturnedValue call(const Managed *m, CallData *) + static void call(const Managed *m, Scope &scope, CallData *) { static_cast<const GC *>(m)->engine()->memoryManager->runGC(); - return Encode::undefined(); + scope.result = Encode::undefined(); } }; @@ -118,7 +118,7 @@ static void showException(QV4::ExecutionContext *ctx, const QV4::Value &exceptio std::cerr << "Uncaught exception: " << qPrintable(message->toQStringNoThrow()) << std::endl; } - foreach (const QV4::StackFrame &frame, trace) { + for (const QV4::StackFrame &frame : trace) { std::cerr << " at " << qPrintable(frame.function) << " (" << qPrintable(frame.source); if (frame.line >= 0) std::cerr << ':' << frame.line; @@ -145,22 +145,22 @@ int main(int argc, char *argv[]) bool runAsQml = false; if (!args.isEmpty()) { - if (args.first() == QLatin1String("--jit")) { + if (args.constFirst() == QLatin1String("--jit")) { mode = use_masm; args.removeFirst(); } - if (args.first() == QLatin1String("--interpret")) { + if (args.constFirst() == QLatin1String("--interpret")) { mode = use_moth; args.removeFirst(); } - if (args.first() == QLatin1String("--qml")) { + if (args.constFirst() == QLatin1String("--qml")) { runAsQml = true; args.removeFirst(); } - if (args.first() == QLatin1String("--help")) { + if (args.constFirst() == QLatin1String("--help")) { std::cerr << "Usage: qmljs [|--jit|--interpret|--qml] file..." << std::endl; return EXIT_SUCCESS; } @@ -188,7 +188,7 @@ int main(int argc, char *argv[]) QV4::ScopedObject gc(scope, vm.memoryManager->allocObject<builtins::GC>(ctx)); vm.globalObject->put(QV4::ScopedString(scope, vm.newIdentifier(QStringLiteral("gc"))).getPointer(), gc); - foreach (const QString &fn, args) { + for (const QString &fn : qAsConst(args)) { QFile file(fn); if (file.open(QFile::ReadOnly)) { const QString code = QString::fromUtf8(file.readAll()); diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp index 211427cc64..99a53110a8 100644 --- a/tools/qmllint/main.cpp +++ b/tools/qmllint/main.cpp @@ -59,7 +59,8 @@ static bool lint_file(const QString &filename, bool silent) bool success = isJavaScript ? parser.parseProgram() : parser.parse(); if (!success && !silent) { - foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) { + const auto diagnosticMessages = parser.diagnosticMessages(); + for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { qWarning("%s:%d : %s", qPrintable(filename), m.loc.startLine, qPrintable(m.message)); } } @@ -82,15 +83,15 @@ int main(int argv, char *argc[]) parser.process(app); - if (parser.positionalArguments().isEmpty()) { + const auto positionalArguments = parser.positionalArguments(); + if (positionalArguments.isEmpty()) { parser.showHelp(-1); } bool silent = parser.isSet(silentOption); bool success = true; - foreach (const QString &filename, parser.positionalArguments()) { + for (const QString &filename : positionalArguments) success &= lint_file(filename, silent); - } return success ? 0 : -1; } diff --git a/tools/qmlmin/main.cpp b/tools/qmlmin/main.cpp index 2b18a8442b..d2bad9d0d5 100644 --- a/tools/qmlmin/main.cpp +++ b/tools/qmlmin/main.cpp @@ -120,7 +120,7 @@ protected: static QString quote(const QString &string) { QString quotedString; - foreach (const QChar &ch, string) { + for (const QChar &ch : string) { if (ch == QLatin1Char('"')) quotedString += QLatin1String("\\\""); else { diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index 395b3cd195..3294fa1e87 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -75,6 +75,12 @@ static const uint qtQmlMajorVersion = 2; static const uint qtQmlMinorVersion = 2; +static const uint qtQuickMajorVersion = 2; +static const uint qtQuickMinorVersion = 8; + +const QString qtQuickQualifiedName = QString::fromLatin1("QtQuick %1.%2") + .arg(qtQuickMajorVersion) + .arg(qtQuickMinorVersion); QString pluginImportPath; bool verbose = false; @@ -199,7 +205,8 @@ QByteArray convertToId(const QMetaObject *mo) // Collect all metaobjects for types registered with qmlRegisterType() without parameters void collectReachableMetaObjectsWithoutQmlName(QQmlEnginePrivate *engine, QSet<const QMetaObject *>& metas ) { - foreach (const QQmlType *ty, QQmlMetaType::qmlAllTypes()) { + const auto qmlAllTypes = QQmlMetaType::qmlAllTypes(); + for (const QQmlType *ty : qmlAllTypes) { if ( ! metas.contains(ty->metaObject()) ) { if (!ty->isComposite()) { collectReachableMetaObjects(engine, ty, &metas); @@ -219,7 +226,8 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, metas.insert(FriendlyQObject::qtMeta()); QHash<QByteArray, QSet<QByteArray> > extensions; - foreach (const QQmlType *ty, QQmlMetaType::qmlTypes()) { + const auto qmlTypes = QQmlMetaType::qmlTypes(); + for (const QQmlType *ty : qmlTypes) { if (!ty->isCreatable()) noncreatables.insert(ty->metaObject()); if (ty->isSingleton()) @@ -242,15 +250,15 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, QSet<const QQmlType *> baseExports = qmlTypesByCppName.value(it.key()); const QSet<QByteArray> extensionCppNames = it.value(); - foreach (const QByteArray &extensionCppName, extensionCppNames) { + for (const QByteArray &extensionCppName : extensionCppNames) { const QSet<const QQmlType *> extensionExports = qmlTypesByCppName.value(extensionCppName); // remove extension exports from base imports // unfortunately the QQmlType pointers don't match, so can't use QSet::subtract QSet<const QQmlType *> newBaseExports; - foreach (const QQmlType *baseExport, baseExports) { + for (const QQmlType *baseExport : qAsConst(baseExports)) { bool match = false; - foreach (const QQmlType *extensionExport, extensionExports) { + for (const QQmlType *extensionExport : extensionExports) { if (baseExport->qmlTypeName() == extensionExport->qmlTypeName() && baseExport->majorVersion() == extensionExport->majorVersion() && baseExport->minorVersion() == extensionExport->minorVersion()) { @@ -269,7 +277,7 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, if (creatable) { // find even more QMetaObjects by instantiating QML types and running // over the instances - foreach (QQmlType *ty, QQmlMetaType::qmlTypes()) { + for (QQmlType *ty : qmlTypes) { if (skip.contains(ty)) continue; if (ty->isExtendedType()) @@ -463,7 +471,7 @@ public: void dumpComposite(QQmlEngine *engine, const QSet<const QQmlType *> &compositeType, QSet<QByteArray> &defaultReachableNames) { - foreach (const QQmlType *type, compositeType) + for (const QQmlType *type : compositeType) dumpCompositeItem(engine, type, defaultReachableNames); } @@ -512,7 +520,7 @@ public: } } - foreach (const QMetaObject *meta, objectsToMerge) + for (const QMetaObject *meta : qAsConst(objectsToMerge)) writeMetaContent(meta, &knownAttributes); qml->writeEndObject(); @@ -536,11 +544,11 @@ public: if (meta->superClass()) qml->writeScriptBinding(QLatin1String("prototype"), enquote(convertToId(meta->superClass()))); - QSet<const QQmlType *> qmlTypes = qmlTypesByCppName.value(meta->className()); + const QSet<const QQmlType *> qmlTypes = qmlTypesByCppName.value(meta->className()); if (!qmlTypes.isEmpty()) { QHash<QString, const QQmlType *> exports; - foreach (const QQmlType *qmlTy, qmlTypes) { + for (const QQmlType *qmlTy : qmlTypes) { const QString exportString = getExportString(qmlTy->qmlTypeName(), qmlTy->majorVersion(), qmlTy->minorVersion()); exports.insert(exportString, qmlTy); } @@ -558,7 +566,7 @@ public: // write meta object revisions QStringList metaObjectRevisions; - foreach (const QString &exportString, exportStrings) { + for (const QString &exportString : qAsConst(exportStrings)) { int metaObjectRevision = exports[exportString]->metaObjectRevision(); metaObjectRevisions += QString::number(metaObjectRevision); } @@ -730,7 +738,7 @@ void sigSegvHandler(int) { void printUsage(const QString &appName) { std::cerr << qPrintable(QString( - "Usage: %1 [-v] [-noinstantiate] [-defaultplatform] [-[non]relocatable] [-dependencies <dependencies.json>] [-merge <file-to-merge.qmltypes>] module.uri version [module/import/path]\n" + "Usage: %1 [-v] [-noinstantiate] [-defaultplatform] [-[non]relocatable] [-dependencies <dependencies.json>] [-merge <file-to-merge.qmltypes>] [-noforceqtquick] module.uri version [module/import/path]\n" " %1 [-v] [-noinstantiate] -path path/to/qmldir/directory [version]\n" " %1 [-v] -builtins\n" "Example: %1 Qt.labs.folderlistmodel 2.0 /home/user/dev/qt-install/imports").arg( @@ -738,11 +746,12 @@ void printUsage(const QString &appName) } static bool readDependenciesData(QString dependenciesFile, const QByteArray &fileData, - QStringList *dependencies, const QStringList &urisToSkip) { + QStringList *dependencies, const QStringList &urisToSkip, + bool forceQtQuickDependency = true) { if (verbose) { std::cerr << "parsing " << qPrintable( dependenciesFile ) << " skipping"; - foreach (const QString &uriToSkip, urisToSkip) + for (const QString &uriToSkip : urisToSkip) std::cerr << ' ' << qPrintable(uriToSkip); std::cerr << std::endl; } @@ -756,13 +765,14 @@ static bool readDependenciesData(QString dependenciesFile, const QByteArray &fil return false; } if (doc.isArray()) { - QStringList requiredKeys = QStringList() << QStringLiteral("name") - << QStringLiteral("type") - << QStringLiteral("version"); - foreach (const QJsonValue &dep, doc.array()) { + const QStringList requiredKeys = QStringList() << QStringLiteral("name") + << QStringLiteral("type") + << QStringLiteral("version"); + const auto deps = doc.array(); + for (const QJsonValue &dep : deps) { if (dep.isObject()) { QJsonObject obj = dep.toObject(); - foreach (const QString &requiredKey, requiredKeys) + for (const QString &requiredKey : requiredKeys) if (!obj.contains(requiredKey) || obj.value(requiredKey).isString()) continue; if (obj.value(QStringLiteral("type")).toString() != QLatin1String("module")) @@ -793,8 +803,8 @@ static bool readDependenciesData(QString dependenciesFile, const QByteArray &fil // qmlplugindump used to import QtQuick, so all types defined in QtQuick used to be skipped when dumping. // Now that it imports only Qt, it is no longer the case: if no dependency is found all the types defined // in QtQuick will be dumped, causing conflicts. - if (dependencies->isEmpty()) - dependencies->push_back(QLatin1String("QtQuick 2.0")); + if (forceQtQuickDependency && dependencies->isEmpty()) + dependencies->push_back(qtQuickQualifiedName); return true; } @@ -812,11 +822,12 @@ static bool readDependenciesFile(const QString &dependenciesFile, QStringList *d return false; } QByteArray fileData = f.readAll(); - return readDependenciesData(dependenciesFile, fileData, dependencies, urisToSkip); + return readDependenciesData(dependenciesFile, fileData, dependencies, urisToSkip, false); } static bool getDependencies(const QQmlEngine &engine, const QString &pluginImportUri, - const QString &pluginImportVersion, QStringList *dependencies) + const QString &pluginImportVersion, QStringList *dependencies, + bool forceQtQuickDependency) { QFileInfo selfExe(QCoreApplication::applicationFilePath()); QString command = selfExe.absoluteDir().filePath(QLatin1String("qmlimportscanner") @@ -825,7 +836,8 @@ static bool getDependencies(const QQmlEngine &engine, const QString &pluginImpor QStringList commandArgs = QStringList() << QLatin1String("-qmlFiles") << QLatin1String("-"); - foreach (const QString &path, engine.importPathList()) + const auto importPathList = engine.importPathList(); + for (const QString &path : importPathList) commandArgs << QLatin1String("-importPath") << path; QProcess importScanner; @@ -842,20 +854,20 @@ static bool getDependencies(const QQmlEngine &engine, const QString &pluginImpor if (!importScanner.waitForFinished()) { std::cerr << "failure to start " << qPrintable(command); - foreach (const QString &arg, commandArgs) + for (const QString &arg : qAsConst(commandArgs)) std::cerr << ' ' << qPrintable(arg); std::cerr << std::endl; return false; } QByteArray depencenciesData = importScanner.readAllStandardOutput(); if (!readDependenciesData(QLatin1String("<outputOfQmlimportscanner>"), depencenciesData, - dependencies, QStringList(pluginImportUri))) { + dependencies, QStringList(pluginImportUri), forceQtQuickDependency)) { std::cerr << "failed to proecess output of qmlimportscanner" << std::endl; return false; } QStringList aux; - foreach (const QString &str, *dependencies) { + for (const QString &str : qAsConst(*dependencies)) { if (!str.startsWith("Qt.test.qtestroot")) aux += str; } @@ -869,20 +881,20 @@ bool compactDependencies(QStringList *dependencies) if (dependencies->isEmpty()) return false; dependencies->sort(); - QStringList oldDep = dependencies->first().split(QLatin1Char(' ')); + QStringList oldDep = dependencies->constFirst().split(QLatin1Char(' ')); Q_ASSERT(oldDep.size() == 2); int oldPos = 0; for (int idep = 1; idep < dependencies->size(); ++idep) { QString depStr = dependencies->at(idep); const QStringList newDep = depStr.split(QLatin1Char(' ')); Q_ASSERT(newDep.size() == 2); - if (newDep.first() != oldDep.first()) { + if (newDep.constFirst() != oldDep.constFirst()) { if (++oldPos != idep) dependencies->replace(oldPos, depStr); oldDep = newDep; } else { - QStringList v1 = oldDep.last().split(QLatin1Char('.')); - QStringList v2 = newDep.last().split(QLatin1Char('.')); + const QStringList v1 = oldDep.constLast().split(QLatin1Char('.')); + const QStringList v2 = newDep.constLast().split(QLatin1Char('.')); Q_ASSERT(v1.size() == 2); Q_ASSERT(v2.size() == 2); bool ok; @@ -891,9 +903,9 @@ bool compactDependencies(QStringList *dependencies) int major2 = v2.first().toInt(&ok); Q_ASSERT(ok); if (major1 != major2) { - std::cerr << "Found a dependency on " << qPrintable(oldDep.first()) - << " with two major versions:" << qPrintable(oldDep.last()) - << " and " << qPrintable(newDep.last()) + std::cerr << "Found a dependency on " << qPrintable(oldDep.constFirst()) + << " with two major versions:" << qPrintable(oldDep.constLast()) + << " and " << qPrintable(newDep.constLast()) << " which is unsupported, discarding smaller version" << std::endl; if (major1 < major2) dependencies->replace(oldPos, depStr); @@ -969,10 +981,11 @@ int main(int argc, char *argv[]) } } - if (!requireWindowManager) + if (!requireWindowManager && qEnvironmentVariableIsEmpty("QT_QPA_PLATFORM")) qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("minimal")); + else + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); - QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); QGuiApplication app(argc, argv); const QStringList args = app.arguments(); const QString appName = QFileInfo(app.applicationFilePath()).baseName(); @@ -986,6 +999,7 @@ int main(int argc, char *argv[]) bool relocatable = true; QString dependenciesFile; QString mergeFile; + bool forceQtQuickDependency = true; enum Action { Uri, Path, Builtins }; Action action = Uri; { @@ -1030,6 +1044,9 @@ int main(int argc, char *argv[]) action = Builtins; } else if (arg == QLatin1String("-v")) { verbose = true; + } else if (arg == QLatin1String("--noforceqtquick") + || arg == QLatin1String("-noforceqtquick")){ + forceQtQuickDependency = false; } else if (arg == QLatin1String("--defaultplatform") || arg == QLatin1String("-defaultplatform")) { continue; @@ -1044,18 +1061,18 @@ int main(int argc, char *argv[]) std::cerr << "Incorrect number of positional arguments" << std::endl; return EXIT_INVALIDARGUMENTS; } - pluginImportUri = positionalArgs[1]; + pluginImportUri = positionalArgs.at(1); pluginImportVersion = positionalArgs[2]; if (positionalArgs.size() >= 4) - pluginImportPath = positionalArgs[3]; + pluginImportPath = positionalArgs.at(3); } else if (action == Path) { if (positionalArgs.size() != 2 && positionalArgs.size() != 3) { std::cerr << "Incorrect number of positional arguments" << std::endl; return EXIT_INVALIDARGUMENTS; } - pluginImportPath = QDir::fromNativeSeparators(positionalArgs[1]); + pluginImportPath = QDir::fromNativeSeparators(positionalArgs.at(1)); if (positionalArgs.size() == 3) - pluginImportVersion = positionalArgs[2]; + pluginImportVersion = positionalArgs.at(2); } else if (action == Builtins) { if (positionalArgs.size() != 1) { std::cerr << "Incorrect number of positional arguments" << std::endl; @@ -1077,7 +1094,7 @@ int main(int argc, char *argv[]) QStringList mergeDependencies; QString mergeComponents; if (!mergeFile.isEmpty()) { - QStringList merge = readQmlTypes(mergeFile); + const QStringList merge = readQmlTypes(mergeFile); if (!merge.isEmpty()) { QRegularExpression re("(\\w+\\.*\\w*\\s*\\d+\\.\\d+)"); QRegularExpressionMatchIterator i = re.globalMatch(merge[1]); @@ -1098,9 +1115,12 @@ int main(int argc, char *argv[]) calculateDependencies = !readDependenciesFile(dependenciesFile, &dependencies, QStringList(pluginImportUri)) && calculateDependencies; if (calculateDependencies) - getDependencies(engine, pluginImportUri, pluginImportVersion, &dependencies); + getDependencies(engine, pluginImportUri, pluginImportVersion, &dependencies, + forceQtQuickDependency); + compactDependencies(&dependencies); + QString qtQmlImportString = QString::fromLatin1("import QtQml %1.%2") .arg(qtQmlMajorVersion) .arg(qtQmlMinorVersion); @@ -1108,7 +1128,7 @@ int main(int argc, char *argv[]) // load the QtQml builtins and the dependencies { QByteArray code(qtQmlImportString.toUtf8()); - foreach (const QString &moduleToImport, dependencies) { + for (const QString &moduleToImport : qAsConst(dependencies)) { code.append("\nimport "); code.append(moduleToImport.toUtf8()); } @@ -1116,8 +1136,9 @@ int main(int argc, char *argv[]) QQmlComponent c(&engine); c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/loaddependencies.qml")); c.create(); - if (!c.errors().isEmpty()) { - foreach (const QQmlError &error, c.errors()) + const auto errors = c.errors(); + if (!errors.isEmpty()) { + for (const QQmlError &error : errors) std::cerr << qPrintable( error.toString() ) << std::endl; return EXIT_IMPORTERROR; } @@ -1138,7 +1159,7 @@ int main(int argc, char *argv[]) QSet<const QMetaObject *> metas; if (action == Builtins) { - foreach (const QMetaObject *m, defaultReachable) { + for (const QMetaObject *m : qAsConst(defaultReachable)) { if (m->className() == QLatin1String("Qt")) { metas.insert(m); break; @@ -1146,7 +1167,7 @@ int main(int argc, char *argv[]) } } else if (pluginImportUri == QLatin1String("QtQml")) { bool ok = false; - const uint major = pluginImportVersion.split('.')[0].toUInt(&ok, 10); + const uint major = pluginImportVersion.splitRef('.').at(0).toUInt(&ok, 10); if (!ok) { std::cerr << "Malformed version string \""<< qPrintable(pluginImportVersion) << "\"." << std::endl; @@ -1159,7 +1180,7 @@ int main(int argc, char *argv[]) return EXIT_INVALIDARGUMENTS; } metas = defaultReachable; - foreach (const QMetaObject *m, defaultReachable) { + for (const QMetaObject *m : qAsConst(defaultReachable)) { if (m->className() == QLatin1String("Qt")) { metas.remove(m); break; @@ -1180,7 +1201,7 @@ int main(int argc, char *argv[]) QString::number(qtObjectType->minorVersion())).toUtf8(); } // avoid importing dependencies? - foreach (const QString &moduleToImport, dependencies) { + for (const QString &moduleToImport : qAsConst(dependencies)) { importCode.append("\nimport "); importCode.append(moduleToImport.toUtf8()); } @@ -1202,8 +1223,9 @@ int main(int argc, char *argv[]) c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typelist.qml")); c.create(); - if (!c.errors().isEmpty()) { - foreach (const QQmlError &error, c.errors()) + const auto errors = c.errors(); + if (!errors.isEmpty()) { + for (const QQmlError &error : errors) std::cerr << qPrintable( error.toString() ) << std::endl; return EXIT_IMPORTERROR; } @@ -1215,9 +1237,9 @@ int main(int argc, char *argv[]) // Also eliminate meta objects with the same classname. // This is required because extended objects seem not to share // a single meta object instance. - foreach (const QMetaObject *mo, defaultReachable) + for (const QMetaObject *mo : qAsConst(defaultReachable)) defaultReachableNames.insert(QByteArray(mo->className())); - foreach (const QMetaObject *mo, candidates) { + for (const QMetaObject *mo : qAsConst(candidates)) { if (!defaultReachableNames.contains(mo->className())) metas.insert(mo); } @@ -1249,19 +1271,19 @@ int main(int argc, char *argv[]) compactDependencies(&dependencies); QStringList quotedDependencies; - foreach (const QString &dep, dependencies) + for (const QString &dep : qAsConst(dependencies)) quotedDependencies << enquote(dep); qml.writeArrayBinding("dependencies", quotedDependencies); // put the metaobjects into a map so they are always dumped in the same order QMap<QString, const QMetaObject *> nameToMeta; - foreach (const QMetaObject *meta, metas) + for (const QMetaObject *meta : qAsConst(metas)) nameToMeta.insert(convertToId(meta), meta); Dumper dumper(&qml); if (relocatable) dumper.setRelocatableModuleUri(pluginImportUri); - foreach (const QMetaObject *meta, nameToMeta) { + for (const QMetaObject *meta : qAsConst(nameToMeta)) { dumper.dump(QQmlEnginePrivate::get(&engine), meta, uncreatableMetas.contains(meta), singletonMetas.contains(meta)); } diff --git a/tools/qmlplugindump/qmlplugindump.pro b/tools/qmlplugindump/qmlplugindump.pro index e45a7fad83..b38eea2554 100644 --- a/tools/qmlplugindump/qmlplugindump.pro +++ b/tools/qmlplugindump/qmlplugindump.pro @@ -17,7 +17,7 @@ macx { # Prevent qmlplugindump from popping up in the dock when launched. # We embed the Info.plist file, so the application doesn't need to # be a bundle. - QMAKE_LFLAGS += -sectcreate __TEXT __info_plist $$shell_quote($$PWD/Info.plist) + QMAKE_LFLAGS += -Wl,-sectcreate,__TEXT,__info_plist,$$shell_quote($$PWD/Info.plist) CONFIG -= app_bundle } diff --git a/tools/qmlplugindump/qmlstreamwriter.cpp b/tools/qmlplugindump/qmlstreamwriter.cpp index dd3c188fe4..3632cee60d 100644 --- a/tools/qmlplugindump/qmlstreamwriter.cpp +++ b/tools/qmlplugindump/qmlstreamwriter.cpp @@ -179,7 +179,7 @@ void QmlStreamWriter::flushPotentialLinesWithNewlines() { if (m_maybeOneline) m_stream->write("\n"); - foreach (const QByteArray &line, m_pendingLines) { + for (const QByteArray &line : qAsConst(m_pendingLines)) { writeIndent(); m_stream->write(line); m_stream->write("\n"); diff --git a/tools/qmlplugindump/qmltypereader.cpp b/tools/qmlplugindump/qmltypereader.cpp index 67ba415388..9dfb6fc1e0 100644 --- a/tools/qmlplugindump/qmltypereader.cpp +++ b/tools/qmlplugindump/qmltypereader.cpp @@ -40,7 +40,7 @@ #include <iostream> QStringList readQmlTypes(const QString &filename) { - QRegularExpression re("import QtQuick.tooling 1.2.*Module {\\s*dependencies:\\[([^\\]]*)\\](.*)}", + QRegularExpression re("import QtQuick\\.tooling 1\\.2.*Module {\\s*dependencies:\\s*\\[([^\\]]*)\\](.*)}", QRegularExpression::DotMatchesEverythingOption); if (!QFileInfo(filename).exists()) { std::cerr << "Non existing file: " << filename.toStdString() << std::endl; diff --git a/tools/qmlprofiler/commandlistener.h b/tools/qmlprofiler/commandlistener.h index c10b199daa..2a994bf449 100644 --- a/tools/qmlprofiler/commandlistener.h +++ b/tools/qmlprofiler/commandlistener.h @@ -33,7 +33,7 @@ class CommandListener : public QObject { Q_OBJECT -public slots: +public: void readCommand(); signals: diff --git a/tools/qmlprofiler/main.cpp b/tools/qmlprofiler/main.cpp index d3e2beb83f..c7cb979ff8 100644 --- a/tools/qmlprofiler/main.cpp +++ b/tools/qmlprofiler/main.cpp @@ -39,8 +39,10 @@ int main(int argc, char *argv[]) QThread listenerThread; CommandListener listener; listener.moveToThread(&listenerThread); - QObject::connect(&listener, SIGNAL(command(QString)), &app, SLOT(userCommand(QString))); - QObject::connect(&app, SIGNAL(readyForCommand()), &listener, SLOT(readCommand())); + QObject::connect(&listener, &CommandListener::command, + &app, &QmlProfilerApplication::userCommand); + QObject::connect(&app, &QmlProfilerApplication::readyForCommand, + &listener, &CommandListener::readCommand); listenerThread.start(); int exitValue = app.exec(); listenerThread.quit(); diff --git a/tools/qmlprofiler/qmlprofilerapplication.cpp b/tools/qmlprofiler/qmlprofilerapplication.cpp index b04ff7e558..033492b516 100644 --- a/tools/qmlprofiler/qmlprofilerapplication.cpp +++ b/tools/qmlprofiler/qmlprofilerapplication.cpp @@ -87,17 +87,21 @@ QmlProfilerApplication::QmlProfilerApplication(int &argc, char **argv) : m_connectionAttempts(0) { m_connectTimer.setInterval(1000); - connect(&m_connectTimer, SIGNAL(timeout()), this, SLOT(tryToConnect())); + connect(&m_connectTimer, &QTimer::timeout, this, &QmlProfilerApplication::tryToConnect); - connect(&m_connection, SIGNAL(connected()), this, SLOT(connected())); + connect(&m_connection, &QQmlDebugConnection::connected, + this, &QmlProfilerApplication::connected); - connect(&m_qmlProfilerClient, SIGNAL(enabledChanged(bool)), - this, SLOT(traceClientEnabledChanged(bool))); - connect(&m_qmlProfilerClient, SIGNAL(recordingStarted()), this, SLOT(notifyTraceStarted())); - connect(&m_qmlProfilerClient, SIGNAL(error(QString)), this, SLOT(logError(QString))); + connect(&m_qmlProfilerClient, &QmlProfilerClient::enabledChanged, + this, &QmlProfilerApplication::traceClientEnabledChanged); + connect(&m_qmlProfilerClient, &QmlProfilerClient::recordingStarted, + this, &QmlProfilerApplication::notifyTraceStarted); + connect(&m_qmlProfilerClient, &QmlProfilerClient::error, + this, &QmlProfilerApplication::logError); - connect(&m_profilerData, SIGNAL(error(QString)), this, SLOT(logError(QString))); - connect(&m_profilerData, SIGNAL(dataReady()), this, SLOT(traceFinished())); + connect(&m_profilerData, &QmlProfilerData::error, this, &QmlProfilerApplication::logError); + connect(&m_profilerData, &QmlProfilerData::dataReady, + this, &QmlProfilerApplication::traceFinished); } @@ -257,7 +261,7 @@ void QmlProfilerApplication::parseArguments() int QmlProfilerApplication::exec() { - QTimer::singleShot(0, this, SLOT(run())); + QTimer::singleShot(0, this, &QmlProfilerApplication::run); return QCoreApplication::exec(); } @@ -270,8 +274,8 @@ quint64 QmlProfilerApplication::parseFeatures(const QStringList &featureList, co bool exclude) { quint64 features = exclude ? std::numeric_limits<quint64>::max() : 0; - QStringList givenFeatures = values.split(QLatin1Char(',')); - foreach (const QString &f, givenFeatures) { + const QStringList givenFeatures = values.split(QLatin1Char(',')); + for (const QString &f : givenFeatures) { int index = featureList.indexOf(f); if (index < 0) { logError(tr("Unknown feature '%1'").arg(f)); @@ -343,7 +347,7 @@ bool QmlProfilerApplication::checkOutputFile(PendingRequest pending) void QmlProfilerApplication::userCommand(const QString &command) { - QStringList args = command.split(QChar::Space, QString::SkipEmptyParts); + auto args = command.splitRef(QChar::Space, QString::SkipEmptyParts); if (args.isEmpty()) { prompt(); return; @@ -397,7 +401,7 @@ void QmlProfilerApplication::userCommand(const QString &command) } else if (m_profilerData.isEmpty()) { prompt(tr("No data was recorded so far.")); } else { - m_interactiveOutputFile = args.length() > 0 ? args[0] : m_outputFile; + m_interactiveOutputFile = args.length() > 0 ? args.at(0).toString() : m_outputFile; if (checkOutputFile(REQUEST_OUTPUT_FILE)) output(); } @@ -414,7 +418,7 @@ void QmlProfilerApplication::userCommand(const QString &command) if (!m_recording && m_profilerData.isEmpty()) { prompt(tr("No data was recorded so far.")); } else { - m_interactiveOutputFile = args.length() > 0 ? args[0] : m_outputFile; + m_interactiveOutputFile = args.length() > 0 ? args.at(0).toString() : m_outputFile; if (checkOutputFile(REQUEST_FLUSH_FILE)) flush(); } @@ -460,9 +464,9 @@ void QmlProfilerApplication::run() arguments << m_programArguments; m_process->setProcessChannelMode(QProcess::MergedChannels); - connect(m_process, SIGNAL(readyRead()), this, SLOT(processHasOutput())); - connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), this, - SLOT(processFinished())); + connect(m_process, &QIODevice::readyRead, this, &QmlProfilerApplication::processHasOutput); + connect(m_process, static_cast<void(QProcess::*)(int)>(&QProcess::finished), + this, [this](int){ processFinished(); }); logStatus(QString("Starting '%1 %2' ...").arg(m_programPath, arguments.join(QLatin1Char(' ')))); m_process->start(m_programPath, arguments); diff --git a/tools/qmlprofiler/qmlprofilerapplication.h b/tools/qmlprofiler/qmlprofilerapplication.h index 04f9d43c87..13f0f041f0 100644 --- a/tools/qmlprofiler/qmlprofilerapplication.h +++ b/tools/qmlprofiler/qmlprofilerapplication.h @@ -58,16 +58,14 @@ public: void parseArguments(); int exec(); bool isInteractive() const; - -signals: - void readyForCommand(); - -public slots: void userCommand(const QString &command); void notifyTraceStarted(); void outputData(); -private slots: +signals: + void readyForCommand(); + +private: void run(); void tryToConnect(); void connected(); @@ -81,7 +79,6 @@ private slots: void logError(const QString &error); void logStatus(const QString &status); -private: quint64 parseFeatures(const QStringList &featureList, const QString &values, bool exclude); bool checkOutputFile(PendingRequest pending); void flush(); diff --git a/tools/qmlprofiler/qmlprofilerdata.cpp b/tools/qmlprofiler/qmlprofilerdata.cpp index 74fa44c1d6..668cb3ce2d 100644 --- a/tools/qmlprofiler/qmlprofilerdata.cpp +++ b/tools/qmlprofiler/qmlprofilerdata.cpp @@ -248,7 +248,7 @@ void QmlProfilerData::addQmlEvent(QQmlProfilerDefinitions::RangeType type, eventHashStr = getHashStringForQmlEvent(eventLocation, type); } else { const QString filePath = QUrl(eventLocation.filename).path(); - displayName = filePath.mid( + displayName = filePath.midRef( filePath.lastIndexOf(QLatin1Char('/')) + 1) + QLatin1Char(':') + QString::number(eventLocation.line); eventHashStr = getHashStringForQmlEvent(eventLocation, type); @@ -327,8 +327,8 @@ void QmlProfilerData::addPixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventTy QString filePath = QUrl(location).path(); - QString eventHashStr = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1) + - QStringLiteral(":") + QString::number(type); + const QString eventHashStr = filePath.midRef(filePath.lastIndexOf(QLatin1Char('/')) + 1) + + QLatin1Char(':') + QString::number(type); QmlRangeEventData *newEvent; if (d->eventDescriptions.contains(eventHashStr)) { newEvent = d->eventDescriptions[eventHashStr]; @@ -403,23 +403,23 @@ void QmlProfilerData::computeQmlTime() int level = minimumLevel; for (int i = 0; i < d->startInstanceList.count(); i++) { - qint64 st = d->startInstanceList[i].startTime; + qint64 st = d->startInstanceList.at(i).startTime; - if (d->startInstanceList[i].data->rangeType == QQmlProfilerDefinitions::Painting) { + if (d->startInstanceList.at(i).data->rangeType == QQmlProfilerDefinitions::Painting) { continue; } // general level - if (endtimesPerLevel[level] > st) { + if (endtimesPerLevel.value(level) > st) { level++; } else { while (level > minimumLevel && endtimesPerLevel[level-1] <= st) level--; } - endtimesPerLevel[level] = st + d->startInstanceList[i].duration; + endtimesPerLevel[level] = st + d->startInstanceList.at(i).duration; if (level == minimumLevel) { - d->qmlMeasuredTime += d->startInstanceList[i].duration; + d->qmlMeasuredTime += d->startInstanceList.at(i).duration; } } } @@ -572,7 +572,7 @@ bool QmlProfilerData::save(const QString &filename) stream.writeEndElement(); // eventData stream.writeStartElement(QStringLiteral("profilerDataModel")); - foreach (const QmlRangeEventStartInstance &event, d->startInstanceList) { + for (const QmlRangeEventStartInstance &event : qAsConst(d->startInstanceList)) { stream.writeStartElement(QStringLiteral("range")); stream.writeAttribute(QStringLiteral("startTime"), QString::number(event.startTime)); if (event.duration >= 0) diff --git a/tools/qmlprofiler/qmlprofilerdata.h b/tools/qmlprofiler/qmlprofilerdata.h index 2570513d93..00ef037071 100644 --- a/tools/qmlprofiler/qmlprofilerdata.h +++ b/tools/qmlprofiler/qmlprofilerdata.h @@ -58,12 +58,6 @@ public: bool isEmpty() const; -signals: - void error(QString); - void stateChanged(); - void dataReady(); - -public slots: void clear(); void setTraceEndTime(qint64 time); void setTraceStartTime(qint64 time); @@ -83,6 +77,11 @@ public slots: void complete(); bool save(const QString &filename); +signals: + void error(QString); + void stateChanged(); + void dataReady(); + private: void sortStartTimes(); void computeQmlTime(); diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp index 1185a8e7ae..9e1002166d 100644 --- a/tools/qmlscene/main.cpp +++ b/tools/qmlscene/main.cpp @@ -175,10 +175,10 @@ QFileInfoList findQmlFiles(const QString &dirName) QFileInfoList ret; if (dir.exists()) { - QFileInfoList fileInfos = dir.entryInfoList(QStringList() << "*.qml", - QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot); + const QFileInfoList fileInfos = dir.entryInfoList(QStringList() << "*.qml", + QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot); - foreach (QFileInfo fileInfo, fileInfos) { + for (const QFileInfo &fileInfo : fileInfos) { if (fileInfo.isDir()) ret += findQmlFiles(fileInfo.filePath()); else if (fileInfo.fileName().length() > 0 && fileInfo.fileName().at(0).isLower()) @@ -196,9 +196,9 @@ static int displayOptionsDialog(Options *options) QFormLayout *layout = new QFormLayout(&dialog); QComboBox *qmlFileComboBox = new QComboBox(&dialog); - QFileInfoList fileInfos = findQmlFiles(":/bundle") + findQmlFiles("./qmlscene-resources"); + const QFileInfoList fileInfos = findQmlFiles(":/bundle") + findQmlFiles("./qmlscene-resources"); - foreach (QFileInfo fileInfo, fileInfos) + for (const QFileInfo &fileInfo : fileInfos) qmlFileComboBox->addItem(fileInfo.dir().dirName() + QLatin1Char('/') + fileInfo.fileName(), QVariant::fromValue(fileInfo)); QCheckBox *originalCheckBox = new QCheckBox(&dialog); @@ -319,8 +319,8 @@ static void loadDummyDataFiles(QQmlEngine &engine, const QString& directory) QObject *dummyData = comp.create(); if(comp.isError()) { - QList<QQmlError> errors = comp.errors(); - foreach (const QQmlError &error, errors) + const QList<QQmlError> errors = comp.errors(); + for (const QQmlError &error : errors) fprintf(stderr, "%s\n", qPrintable(error.toString())); } @@ -457,7 +457,7 @@ int main(int argc, char ** argv) options.applicationAttributes.append(Qt::AA_DisableHighDpiScaling); } - foreach (Qt::ApplicationAttribute a, options.applicationAttributes) + for (Qt::ApplicationAttribute a : qAsConst(options.applicationAttributes)) QCoreApplication::setAttribute(a); #ifdef QT_WIDGETS_LIB QApplication app(argc, argv); @@ -564,6 +564,7 @@ int main(int argc, char ** argv) loadDummyDataFiles(engine, fi.path()); } QObject::connect(&engine, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit())); + QObject::connect(&engine, &QQmlEngine::exit, QCoreApplication::instance(), &QCoreApplication::exit); component->loadUrl(options.url); while (component->isLoading()) QCoreApplication::processEvents(); diff --git a/tools/qmlscene/qmlscene.pro b/tools/qmlscene/qmlscene.pro index 0411fd8e31..b1267612c5 100644 --- a/tools/qmlscene/qmlscene.pro +++ b/tools/qmlscene/qmlscene.pro @@ -4,6 +4,7 @@ CONFIG += no_import_scan SOURCES += main.cpp -DEFINES += QML_RUNTIME_TESTING QT_QML_DEBUG_NO_WARNING +DEFINES += QML_RUNTIME_TESTING +!contains(QT_CONFIG, no-qml-debug): DEFINES += QT_QML_DEBUG_NO_WARNING load(qt_tool) diff --git a/tools/tools.pro b/tools/tools.pro index 18bfe28a8a..5f72588a7e 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -23,7 +23,7 @@ qmlimportscanner.CONFIG = host_build qtHaveModule(widgets): SUBDIRS += qmleasing } qtHaveModule(qmltest): SUBDIRS += qmltestrunner - contains(QT_CONFIG, private_tests): SUBDIRS += qmljs + qtConfig(private_tests): SUBDIRS += qmljs } qml.depends = qmlimportscanner |