diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-02 16:50:20 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-09 08:01:02 +0200 |
commit | 5dc14c88f9510795835fb4f0a0d46d67c40f7020 (patch) | |
tree | 937173d548a6ad0d4c46cf75914adb6f6b140254 /src/qml/qmldirparser | |
parent | 6a48a81319b886c8a3f85e1eb024186b05d0f3af (diff) |
Allow QML plugins to be optional
If a plugin does nothing but load the library that provides the types,
we can skip the plugin loading by linking the library directly. State
that in the qmldir file, and evaluate it when loading the module.
Task-number: QTBUG-84639
Change-Id: I2097237866a50f66c55e4653ad119fe10e18a893
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qmldirparser')
-rw-r--r-- | src/qml/qmldirparser/qqmldirparser.cpp | 21 | ||||
-rw-r--r-- | src/qml/qmldirparser/qqmldirparser_p.h | 5 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/qml/qmldirparser/qqmldirparser.cpp b/src/qml/qmldirparser/qqmldirparser.cpp index cb16d2e57a..a8a450d2ca 100644 --- a/src/qml/qmldirparser/qqmldirparser.cpp +++ b/src/qml/qmldirparser/qqmldirparser.cpp @@ -178,15 +178,32 @@ bool QQmlDirParser::parse(const QString &source) } else if (sections[0] == QLatin1String("plugin")) { if (sectionCount < 2 || sectionCount > 3) { reportError(lineNumber, 0, - QStringLiteral("plugin directive requires one or two arguments, but %1 were provided").arg(sectionCount - 1)); + QStringLiteral("plugin directive requires one or two arguments, but %1 were provided") + .arg(sectionCount - 1)); continue; } - const Plugin entry(sections[1], sections[2]); + const Plugin entry(sections[1], sections[2], false); _plugins.append(entry); + } else if (sections[0] == QLatin1String("optional")) { + if (sectionCount < 2 || sections[1] != QLatin1String("plugin")) { + reportError(lineNumber, 0, QStringLiteral("only plugins can be optional")); + continue; + } + + if (sectionCount < 3 || sectionCount > 4) { + reportError(lineNumber, 0, + QStringLiteral("plugin directive requires one or two arguments, but %1 were provided") + .arg(sectionCount - 2)); + continue; + } + + const Plugin entry(sections[2], sections[3], true); + _plugins.append(entry); + } else if (sections[0] == QLatin1String("classname")) { if (sectionCount < 2) { reportError(lineNumber, 0, diff --git a/src/qml/qmldirparser/qqmldirparser_p.h b/src/qml/qmldirparser/qqmldirparser_p.h index ccdac8f484..a5a548daca 100644 --- a/src/qml/qmldirparser/qqmldirparser_p.h +++ b/src/qml/qmldirparser/qqmldirparser_p.h @@ -88,14 +88,15 @@ public: { Plugin() = default; - Plugin(const QString &name, const QString &path) - : name(name), path(path) + Plugin(const QString &name, const QString &path, bool optional) + : name(name), path(path), optional(optional) { checkNonRelative("Plugin", name, path); } QString name; QString path; + bool optional = false; }; struct Component |