aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltyperegistrar
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2020-03-26 01:00:11 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2020-04-09 10:08:41 +0200
commit2812184e1bb87cd94d2989162bc6ea954bb585c4 (patch)
tree25460548730e2ddc1f6f328d54e97d3fbfb49d21 /src/qmltyperegistrar
parentcd4a99a7ba92968bf88da9af2624bb738d71e726 (diff)
parentbf205b45a29ba80d94df3b6bac5fec4c7cd79bf9 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: src/qml/jsruntime/qv4executablecompilationunit.cpp src/qml/jsruntime/qv4executablecompilationunit_p.h src/qml/qml/qqmlobjectcreator.cpp src/qml/qml/qqmlpropertycachecreator_p.h src/qml/qml/qqmltypecompiler.cpp src/qml/qml/qqmltypedata.cpp tests/auto/qml/qmlformat/tst_qmlformat.cpp tools/qmllint/scopetree.cpp src/qml/qml/qqmlapplicationengine_p.h Adjusted tools/qmllint/findunqualified.cpp to use newer API Change-Id: Ibfb4678ca39d626d47527265e3c96e43313873d4
Diffstat (limited to 'src/qmltyperegistrar')
-rw-r--r--src/qmltyperegistrar/qmltyperegistrar.cpp47
-rw-r--r--src/qmltyperegistrar/qmltypes.prf12
-rw-r--r--src/qmltyperegistrar/qmltypesclassdescription.cpp2
-rw-r--r--src/qmltyperegistrar/qmltypesclassdescription.h1
-rw-r--r--src/qmltyperegistrar/qmltypescreator.cpp2
5 files changed, 40 insertions, 24 deletions
diff --git a/src/qmltyperegistrar/qmltyperegistrar.cpp b/src/qmltyperegistrar/qmltyperegistrar.cpp
index 33f1ebbbd5..e6b0ee8cd9 100644
--- a/src/qmltyperegistrar/qmltyperegistrar.cpp
+++ b/src/qmltyperegistrar/qmltyperegistrar.cpp
@@ -331,25 +331,37 @@ int main(int argc, char **argv)
}
}
+ const bool privateIncludes = parser.isSet(privateIncludesOption);
+ auto resolvedInclude = [&](const QString &include) {
+ return (privateIncludes && include.endsWith(QLatin1String("_p.h")))
+ ? QLatin1String("private/") + include
+ : include;
+ };
+
auto processMetaObject = [&](const QJsonObject &metaObject) {
+ const QString include = resolvedInclude(metaObject[QLatin1String("inputFile")].toString());
const QJsonArray classes = metaObject[QLatin1String("classes")].toArray();
for (const auto &cls : classes) {
QJsonObject classDef = cls.toObject();
+ classDef.insert(QLatin1String("inputFile"), include);
+
switch (qmlTypeRegistrationMode(classDef)) {
case NamespaceRegistration:
case GadgetRegistration:
case ObjectRegistration: {
- const QString include = metaObject[QLatin1String("inputFile")].toString();
- const bool declaredInHeader = include.endsWith(QLatin1String(".h"));
- if (declaredInHeader) {
- includes.append(include);
- classDef.insert(QLatin1String("registerable"), true);
- } else {
- fprintf(stderr, "Cannot generate QML type registration for class %s "
- "because it is not declared in a header.",
+ if (!include.endsWith(QLatin1String(".h"))
+ && !include.endsWith(QLatin1String(".hpp"))
+ && !include.endsWith(QLatin1String(".hxx"))
+ && include.contains(QLatin1Char('.'))) {
+ fprintf(stderr,
+ "Class %s is declared in %s, which appears not to be a header.\n"
+ "The compilation of its registration to QML may fail.\n",
qPrintable(classDef.value(QLatin1String("qualifiedClassName"))
- .toString()));
+ .toString()),
+ qPrintable(include));
}
+ includes.append(include);
+ classDef.insert(QLatin1String("registerable"), true);
types.append(classDef);
break;
@@ -395,13 +407,8 @@ int main(int argc, char **argv)
const auto newEnd = std::unique(includes.begin(), includes.end());
includes.erase(newEnd, includes.end());
- const bool privateIncludes = parser.isSet(privateIncludesOption);
- for (const QString &include : qAsConst(includes)) {
- if (privateIncludes && include.endsWith(QLatin1String("_p.h")))
- fprintf(output, "\n#include <private/%s>", qPrintable(include));
- else
- fprintf(output, "\n#include <%s>", qPrintable(include));
- }
+ for (const QString &include : qAsConst(includes))
+ fprintf(output, "\n#include <%s>", qPrintable(include));
fprintf(output, "\n\n");
@@ -463,9 +470,13 @@ int main(int argc, char **argv)
continue;
}
+ const QString include = metaObject[QLatin1String("inputFile")].toString();
const QJsonArray classes = metaObject[QLatin1String("classes")].toArray();
- for (const auto &cls : classes)
- foreignTypes.append(cls.toObject());
+ for (const auto &cls : classes) {
+ QJsonObject classDef = cls.toObject();
+ classDef.insert(QLatin1String("inputFile"), include);
+ foreignTypes.append(classDef);
+ }
}
}
}
diff --git a/src/qmltyperegistrar/qmltypes.prf b/src/qmltyperegistrar/qmltypes.prf
index fbb00dbe2d..0d5a6ded24 100644
--- a/src/qmltyperegistrar/qmltypes.prf
+++ b/src/qmltyperegistrar/qmltypes.prf
@@ -31,7 +31,7 @@ isEmpty(QML_IMPORT_MINOR_VERSION) {
isEmpty(QMLTYPES_FILENAME) {
plugin: QMLTYPES_FILENAME = plugins.qmltypes
- else: QMLTYPES_FILENAME = $${TEMPLATE}.qmltypes
+ else: QMLTYPES_FILENAME = $${TARGET}.qmltypes
}
qt_module_deps = $$replace(QT, -private$, '')
@@ -40,25 +40,25 @@ qt_module_deps = $$resolve_depends(qt_module_deps, "QT.", ".depends" ".run_depen
qt_module_deps = $$replace(qt_module_deps, _private$, '')
qt_module_deps = $$unique(qt_module_deps)
-foreign_types =
for(dep, qt_module_deps) {
METATYPES_FILENAME = $$lower($$eval(QT.$${dep}.module))_metatypes.json
INSTALLED_METATYPES = $$[QT_INSTALL_LIBS]/metatypes/$$METATYPES_FILENAME
isEmpty(MODULE_BASE_OUTDIR) {
- foreign_types += $$INSTALLED_METATYPES
+ QML_FOREIGN_METATYPES += $$INSTALLED_METATYPES
} else {
MODULE_BASE_METATYPES = $$MODULE_BASE_OUTDIR/lib/metatypes/$$METATYPES_FILENAME
- exists($$MODULE_BASE_METATYPES): foreign_types += $$MODULE_BASE_METATYPES
- else: foreign_types += $$INSTALLED_METATYPES
+ exists($$MODULE_BASE_METATYPES): QML_FOREIGN_METATYPES += $$MODULE_BASE_METATYPES
+ else: QML_FOREIGN_METATYPES += $$INSTALLED_METATYPES
}
}
+
QML_TYPEREGISTRAR_FLAGS = \
--generate-qmltypes=$$QMLTYPES_FILENAME \
--import-name=$$QML_IMPORT_NAME \
--major-version=$$QML_IMPORT_MAJOR_VERSION \
--minor-version=$$QML_IMPORT_MINOR_VERSION \
- --foreign-types=$$join(foreign_types, ',')
+ --foreign-types=$$join(QML_FOREIGN_METATYPES, ',')
DEPENDENCIESFILE = $$_PRO_FILE_PWD_/dependencies.json
exists($$DEPENDENCIESFILE): QML_TYPEREGISTRAR_FLAGS += --dependencies=$$DEPENDENCIESFILE
diff --git a/src/qmltyperegistrar/qmltypesclassdescription.cpp b/src/qmltyperegistrar/qmltypesclassdescription.cpp
index e21abd97bc..778d057240 100644
--- a/src/qmltyperegistrar/qmltypesclassdescription.cpp
+++ b/src/qmltyperegistrar/qmltypesclassdescription.cpp
@@ -63,6 +63,8 @@ void QmlTypesClassDescription::collect(const QJsonObject *classDef,
const QVector<QJsonObject> &foreign,
CollectMode mode, QTypeRevision defaultRevision)
{
+ if (file.isEmpty() && classDef->value(QLatin1String("registerable")).toBool())
+ file = classDef->value(QLatin1String("inputFile")).toString();
const auto classInfos = classDef->value(QLatin1String("classInfos")).toArray();
for (const QJsonValue &classInfo : classInfos) {
const QJsonObject obj = classInfo.toObject();
diff --git a/src/qmltyperegistrar/qmltypesclassdescription.h b/src/qmltyperegistrar/qmltypesclassdescription.h
index e4ae37a84e..abe68d42ed 100644
--- a/src/qmltyperegistrar/qmltypesclassdescription.h
+++ b/src/qmltyperegistrar/qmltypesclassdescription.h
@@ -38,6 +38,7 @@
struct QmlTypesClassDescription
{
const QJsonObject *resolvedClass = nullptr;
+ QString file;
QString elementName;
QString defaultProp;
QString superClass;
diff --git a/src/qmltyperegistrar/qmltypescreator.cpp b/src/qmltyperegistrar/qmltypescreator.cpp
index 3569bbe253..d1378d809d 100644
--- a/src/qmltyperegistrar/qmltypescreator.cpp
+++ b/src/qmltyperegistrar/qmltypescreator.cpp
@@ -46,6 +46,8 @@ static QString enquote(const QString &string)
void QmlTypesCreator::writeClassProperties(const QmlTypesClassDescription &collector)
{
+ if (!collector.file.isEmpty())
+ m_qml.writeScriptBinding(QLatin1String("file"), enquote(collector.file));
m_qml.writeScriptBinding(
QLatin1String("name"),
enquote(collector.resolvedClass->value(