diff options
Diffstat (limited to 'tools/qmlscene/main.cpp')
-rw-r--r-- | tools/qmlscene/main.cpp | 86 |
1 files changed, 58 insertions, 28 deletions
diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp index 1e8d91a95b..6ce676456c 100644 --- a/tools/qmlscene/main.cpp +++ b/tools/qmlscene/main.cpp @@ -33,6 +33,7 @@ #include <QtCore/qpointer.h> #include <QtCore/qscopedpointer.h> #include <QtCore/qtextstream.h> +#include <QtCore/qregularexpression.h> #include <QtGui/QGuiApplication> #include <QtGui/QOpenGLFunctions> @@ -132,6 +133,17 @@ void RenderStatistics::printTotalStats() struct Options { + enum QmlApplicationType + { + QmlApplicationTypeGui, + QmlApplicationTypeWidget, +#ifdef QT_WIDGETS_LIB + DefaultQmlApplicationType = QmlApplicationTypeWidget +#else + DefaultQmlApplicationType = QmlApplicationTypeGui +#endif + }; + Options() : originalQml(false) , originalQmlRaster(false) @@ -145,6 +157,7 @@ struct Options , resizeViewToRootItem(false) , multisample(false) , verbose(false) + , applicationType(DefaultQmlApplicationType) { // QtWebEngine needs a shared context in order for the GPU thread to // upload textures. @@ -166,6 +179,7 @@ struct Options bool verbose; QVector<Qt::ApplicationAttribute> applicationAttributes; QString translationFile; + QmlApplicationType applicationType; }; #if defined(QMLSCENE_BUNDLE) @@ -258,8 +272,8 @@ static bool checkVersion(const QUrl &url) return false; } - QRegExp quick1("^\\s*import +QtQuick +1\\.\\w*"); - QRegExp qt47("^\\s*import +Qt +4\\.7"); + QRegularExpression quick1("^\\s*import +QtQuick +1\\.\\w*"); + QRegularExpression qt47("^\\s*import +Qt +4\\.7"); QTextStream stream(&f); bool codeFound= false; @@ -269,10 +283,11 @@ static bool checkVersion(const QUrl &url) codeFound = true; } else { QString import; - if (quick1.indexIn(line) >= 0) - import = quick1.cap(0).trimmed(); - else if (qt47.indexIn(line) >= 0) - import = qt47.cap(0).trimmed(); + QRegularExpressionMatch match = quick1.match(line); + if (match.hasMatch()) + import = match.captured(0).trimmed(); + else if ((match = qt47.match(line)).hasMatch()) + import = match.captured(0).trimmed(); if (!import.isNull()) { fprintf(stderr, "qmlscene: '%s' is no longer supported.\n" @@ -290,15 +305,17 @@ static bool checkVersion(const QUrl &url) static void displayFileDialog(Options *options) { #if defined(QT_WIDGETS_LIB) && QT_CONFIG(filedialog) - QString fileName = QFileDialog::getOpenFileName(0, "Open QML file", QString(), "QML Files (*.qml)"); - if (!fileName.isEmpty()) { - QFileInfo fi(fileName); - options->url = QUrl::fromLocalFile(fi.canonicalFilePath()); + if (options->applicationType == Options::QmlApplicationTypeWidget) { + QString fileName = QFileDialog::getOpenFileName(0, "Open QML file", QString(), "QML Files (*.qml)"); + if (!fileName.isEmpty()) { + QFileInfo fi(fileName); + options->url = QUrl::fromLocalFile(fi.canonicalFilePath()); + } + return; } -#else +#endif // QT_WIDGETS_LIB && QT_CONFIG(filedialog) Q_UNUSED(options); puts("No filename specified..."); -#endif } #if QT_CONFIG(translation) @@ -354,6 +371,9 @@ static void usage() puts(" --scaling..........................Enable High DPI scaling (AA_EnableHighDpiScaling)"); puts(" --no-scaling.......................Disable High DPI scaling (AA_DisableHighDpiScaling)"); puts(" --verbose..........................Print version and graphical diagnostics for the run-time"); +#ifdef QT_WIDGETS_LIB + puts(" --apptype [gui|widgets] ...........Select which application class to use. Default is widgets."); +#endif puts(" -I <path> ........................ Add <path> to the list of import paths"); puts(" -P <path> ........................ Add <path> to the list of plugin paths"); puts(" -translation <translationfile> ... Set the language to run in"); @@ -443,30 +463,38 @@ int main(int argc, char ** argv) // Parse arguments for application attributes to be applied before Q[Gui]Application creation. for (int i = 1; i < argc; ++i) { const char *arg = argv[i]; - if (!qstrcmp(arg, "--disable-context-sharing")) + if (!qstrcmp(arg, "--disable-context-sharing")) { options.applicationAttributes.removeAll(Qt::AA_ShareOpenGLContexts); - else if (!qstrcmp(arg, "--gles")) + } else if (!qstrcmp(arg, "--gles")) { options.applicationAttributes.append(Qt::AA_UseOpenGLES); - else if (!qstrcmp(arg, "--software")) + } else if (!qstrcmp(arg, "--software")) { options.applicationAttributes.append(Qt::AA_UseSoftwareOpenGL); - else if (!qstrcmp(arg, "--desktop")) + } else if (!qstrcmp(arg, "--desktop")) { options.applicationAttributes.append(Qt::AA_UseDesktopOpenGL); - else if (!qstrcmp(arg, "--scaling")) + } else if (!qstrcmp(arg, "--scaling")) { options.applicationAttributes.append(Qt::AA_EnableHighDpiScaling); - else if (!qstrcmp(arg, "--no-scaling")) + } else if (!qstrcmp(arg, "--no-scaling")) { options.applicationAttributes.append(Qt::AA_DisableHighDpiScaling); + } else if (!qstrcmp(arg, "--apptype")) { + if (++i >= argc) + usage(); + if (!qstrcmp(argv[i], "gui")) + options.applicationType = Options::QmlApplicationTypeGui; + } } for (Qt::ApplicationAttribute a : qAsConst(options.applicationAttributes)) QCoreApplication::setAttribute(a); + QScopedPointer<QGuiApplication> app; #ifdef QT_WIDGETS_LIB - QApplication app(argc, argv); -#else - QGuiApplication app(argc, argv); + if (options.applicationType == Options::QmlApplicationTypeWidget) + app.reset(new QApplication(argc, argv)); #endif - app.setApplicationName("QtQmlViewer"); - app.setOrganizationName("QtProject"); - app.setOrganizationDomain("qt-project.org"); + if (app.isNull()) + app.reset(new QGuiApplication(argc, argv)); + QCoreApplication::setApplicationName(QStringLiteral("QtQmlViewer")); + QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); + QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org")); QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); const QStringList arguments = QCoreApplication::arguments(); @@ -501,6 +529,8 @@ int main(int argc, char ** argv) imports.append(arguments.at(++i)); else if (lowerArgument == QLatin1String("-p") && i + 1 < size) pluginPaths.append(arguments.at(++i)); + else if (lowerArgument == QLatin1String("--apptype")) + ++i; // Consume previously parsed argument else if (lowerArgument == QLatin1String("--help") || lowerArgument == QLatin1String("-help") || lowerArgument == QLatin1String("--h") @@ -514,14 +544,14 @@ int main(int argc, char ** argv) QTranslator qtTranslator; QString sysLocale = QLocale::system().name(); if (qtTranslator.load(QLatin1String("qt_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) - app.installTranslator(&qtTranslator); + app->installTranslator(&qtTranslator); if (translator.load(QLatin1String("qmlscene_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) - app.installTranslator(&translator); + app->installTranslator(&translator); QTranslator qmlTranslator; if (!options.translationFile.isEmpty()) { if (qmlTranslator.load(options.translationFile)) { - app.installTranslator(&qmlTranslator); + app->installTranslator(&qmlTranslator); } else { fprintf(stderr, "Could not load the translation file \"%s\"\n", qPrintable(options.translationFile)); @@ -629,7 +659,7 @@ int main(int argc, char ** argv) // Now would be a good time to inform the debug service to start listening. - exitCode = app.exec(); + exitCode = app->exec(); #ifdef QML_RUNTIME_TESTING RenderStatistics::printTotalStats(); |