aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qml/main.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-04-24 21:05:32 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-04-25 08:40:45 +0000
commit8d9a7e47aaa03efe2d3eddfc9ac37d02a99affc7 (patch)
tree721e4823dcbee6d07bdc8d0ce7b3e80e51353086 /tools/qml/main.cpp
parent6a03d300be399a09de6cc02a6e3731b51ed5c6da (diff)
qml runtime tool: support alternate conf; add resizeToItem conf
The qmlscene --resize-to-root feature has always been missing from the qml runtime tool; however it was already possible to add it by writing a custom configuration file. Now we support loading different configurations from resources as well as from the filesystem, and the first new configuration being added here is resizeToItem.qml which provides behavior equivalent to qmlscene --resize-to-root. When the argument given to --config ends with .qml, by convention it's to be loaded from the filesystem; whereas configurations from resources are specified without the .qml extension (to make the command line shorter). [ChangeLog][QtQml][qml] The QML Runtime tool now has default behavior matching qmlscene when the root QML object is an Item: it will be wrapped in a Window which will resize the Item when the Window is resized. But you can alternatively use the --config resizeToItem option, resulting in the same behavior as qmlscene --resizeToRoot: resizing the root Item programmatically causes the wrapping Window to be resized. Behavior can still be customized in other ways using the --config option with an external QML configuration file. Task-number: QTBUG-53557 Change-Id: Icdcbbd12258105c33b64634049d735e022dfbd06 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools/qml/main.cpp')
-rw-r--r--tools/qml/main.cpp50
1 files changed, 37 insertions, 13 deletions
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp
index 1d520b8fde..1e367d91bf 100644
--- a/tools/qml/main.cpp
+++ b/tools/qml/main.cpp
@@ -95,12 +95,13 @@ static QQmlApplicationEngine *qae = nullptr;
static int exitTimerId = -1;
#endif
static const QString iconResourcePath(QStringLiteral(":/qt-project.org/QmlRuntime/resources/qml-64.png"));
+static const QString confResourcePath(QStringLiteral(":/qt-project.org/QmlRuntime/conf/"));
static bool verboseMode = false;
static bool quietMode = false;
static void loadConf(const QString &override, bool quiet) // Terminates app on failure
{
- const QString defaultFileName = QLatin1String("configuration.qml");
+ const QString defaultFileName = QLatin1String("default.qml");
QUrl settingsUrl;
bool builtIn = false; //just for keeping track of the warning
if (override.isEmpty()) {
@@ -110,29 +111,38 @@ static void loadConf(const QString &override, bool quiet) // Terminates app on f
settingsUrl = QUrl::fromLocalFile(fi.absoluteFilePath());
} else {
// ### If different built-in configs are needed per-platform, just apply QFileSelector to the qrc conf.qml path
- settingsUrl = QUrl(QLatin1String("qrc:///qt-project.org/QmlRuntime/conf/") + defaultFileName);
+ fi.setFile(confResourcePath + defaultFileName);
+ settingsUrl = QUrl::fromLocalFile(fi.absoluteFilePath());
builtIn = true;
}
} else {
QFileInfo fi;
- fi.setFile(override);
- if (!fi.exists()) {
- printf("qml: Couldn't find required configuration file: %s\n",
- qPrintable(QDir::toNativeSeparators(fi.absoluteFilePath())));
- exit(1);
+ fi.setFile(confResourcePath + override + QLatin1String(".qml"));
+ if (fi.exists()) {
+ settingsUrl = QUrl::fromLocalFile(fi.absoluteFilePath());
+ builtIn = true;
+ } else {
+ fi.setFile(override);
+ if (!fi.exists()) {
+ printf("qml: Couldn't find required configuration file: %s\n",
+ qPrintable(QDir::toNativeSeparators(fi.absoluteFilePath())));
+ exit(1);
+ }
+ settingsUrl = QUrl::fromLocalFile(fi.absoluteFilePath());
}
- settingsUrl = QUrl::fromLocalFile(fi.absoluteFilePath());
}
if (!quiet) {
printf("qml: %s\n", QLibraryInfo::build());
- if (builtIn)
- printf("qml: Using built-in configuration.\n");
- else
- printf("qml: Using configuration file: %s\n",
+ if (builtIn) {
+ printf("qml: Using built-in configuration: %s\n",
+ qPrintable(override.isEmpty() ? defaultFileName : override));
+ } else {
+ printf("qml: Using configuration: %s\n",
qPrintable(settingsUrl.isLocalFile()
? QDir::toNativeSeparators(settingsUrl.toLocalFile())
: settingsUrl.toString()));
+ }
}
// TODO: When we have better engine control, ban QtQuick* imports on this engine
@@ -153,6 +163,15 @@ void noFilesGiven()
exit(1);
}
+static void listConfFiles()
+{
+ QDir confResourceDir(confResourcePath);
+ printf("%s\n", qPrintable(QCoreApplication::translate("main", "Built-in configurations:")));
+ for (const QFileInfo &fi : confResourceDir.entryInfoList(QDir::Files))
+ printf(" %s\n", qPrintable(fi.baseName()));
+ exit(0);
+}
+
#ifdef QT_GUI_LIB
// Loads qml after receiving a QFileOpenEvent
@@ -435,8 +454,11 @@ int main(int argc, char *argv[])
QCoreApplication::translate("main", "Load the given file as a QML file."), QStringLiteral("file"));
parser.addOption(qmlFileOption);
QCommandLineOption configOption(QStringList() << QStringLiteral("c") << QStringLiteral("config"),
- QCoreApplication::translate("main", "Load the given file as the configuration file."), QStringLiteral("file"));
+ QCoreApplication::translate("main", "Load the given built-in configuration or configuration file."), QStringLiteral("file"));
parser.addOption(configOption);
+ QCommandLineOption listConfOption(QStringList() << QStringLiteral("list-conf"),
+ QCoreApplication::translate("main", "List the built-in configurations."));
+ parser.addOption(listConfOption);
QCommandLineOption translationOption(QStringLiteral("translation"),
QCoreApplication::translate("main", "Load the given file as the translations file."), QStringLiteral("file"));
parser.addOption(translationOption);
@@ -486,6 +508,8 @@ int main(int argc, char *argv[])
parser.showVersion();
if (parser.isSet(helpOption))
parser.showHelp();
+ if (parser.isSet(listConfOption))
+ listConfFiles();
if (applicationType == QmlApplicationTypeUnknown) {
#ifdef QT_WIDGETS_LIB
qWarning() << QCoreApplication::translate("main", "--apptype must be followed by one of the following: core gui widget\n");