diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-01 10:11:18 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-04 23:35:39 +0100 |
| commit | ce52c245aaccf3183ef4759882e25b51b539195a (patch) | |
| tree | 5229da9fac5299d95671e551bd2e513942b71d02 /src/qml/qmldirparser/qqmldirparser.cpp | |
| parent | 3881f0df3d115ba8e59a5cedea970f3b085aa84a (diff) | |
Add a "prefer" directive to qmldir
The argument is the path from which further files from the module should
be loaded. This allows us to load potentially pre-compiled files
from a resource contained in a plugin. The qmldir file has to be stored
outside the plugin in order for the QML engine to find it, but the QML
files can now be stored inside the plugin.
[ChangeLog][QtQml] You can now specify that QML files in a QML module
should be loaded from a different place than the directory where the
qmldir file is found. To do this, add a "prefer" directive to the qmldir
file. The most useful application of this is adding the QML files as
resources to a plugin, and using qmlcachegen to pre-compile them. You
can then add their path inside the resource file system as "prefer"
path in order to make the engine load the pre-compiled files. The plain
files should still be installed next to the qmldir file so that they
remain visible to tooling.
Change-Id: Ib281b39230621b3762432095a47fb499412cbaa6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qmldirparser/qqmldirparser.cpp')
| -rw-r--r-- | src/qml/qmldirparser/qqmldirparser.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/qml/qmldirparser/qqmldirparser.cpp b/src/qml/qmldirparser/qqmldirparser.cpp index 403c04b1e1..1dbf35f1d3 100644 --- a/src/qml/qmldirparser/qqmldirparser.cpp +++ b/src/qml/qmldirparser/qqmldirparser.cpp @@ -299,6 +299,28 @@ bool QQmlDirParser::parse(const QString &source) || sections[0] == QLatin1String("depends")) { if (!readImport(sections, sectionCount, Import::Default)) continue; + } else if (sections[0] == QLatin1String("prefer")) { + if (sectionCount < 2) { + reportError(lineNumber, 0, + QStringLiteral("prefer directive requires one argument, " + "but %1 were provided").arg(sectionCount - 1)); + continue; + } + + if (!_preferredPath.isEmpty()) { + reportError(lineNumber, 0, QStringLiteral( + "only one prefer directive may be defined in a qmldir file")); + continue; + } + + if (!sections[1].endsWith(u'/')) { + // Yes. People should realize it's a directory. + reportError(lineNumber, 0, QStringLiteral( + "the preferred directory has to end with a '/'")); + continue; + } + + _preferredPath = sections[1]; } else if (sectionCount == 2) { // No version specified (should only be used for relative qmldir files) const Component entry(sections[0], sections[1], QTypeRevision()); @@ -416,6 +438,11 @@ QStringList QQmlDirParser::classNames() const return _classNames; } +QString QQmlDirParser::preferredPath() const +{ + return _preferredPath; +} + QDebug &operator<< (QDebug &debug, const QQmlDirParser::Component &component) { const QString output = QStringLiteral("{%1 %2.%3}") |
