38 if (
x.removedIn.isValid())
39 return y.addedIn.
isValid() ?
x.removedIn <=
y.addedIn :
true;
51 return !(
x <
y) && !(
y <
x);
62 optionsFile.remove(0, 1);
63 if (optionsFile.isEmpty()) {
64 warning(optionsFile) <<
"The @ option requires an input file";
69 warning(optionsFile) <<
"Cannot open options file specified with @";
86 if (processor.types().isEmpty()) {
87 error(baseName) <<
"No types to register found in library";
90 QFile headerFile(baseName + u
".h");
93 error(headerFile.fileName()) <<
"Cannot open header file for writing";
104 "#include <QtQml/qqml.h>\n"
105 "#include <QtQml/qqmlmoduleregistration.h>\n").arg(
includeGuard);
106 const QList<QString> includes = processor.includes();
107 for (
const QString &include: includes)
108 prefix += u
"\n#include <%1>"_s.arg(include);
109 headerFile.write((prefix + processor.extractRegisteredTypes()).toUtf8() +
"\n#endif\n");
111 QFile sourceFile(baseName + u
".cpp");
114 error(sourceFile.
fileName()) <<
"Cannot open implementation file for writing";
118 QString code = u
"#include \"%1.h\"\n#include "_s.
arg(baseName);
119 code += uR
"("moc_%1.cpp")"_s.arg(baseName);
121 sourceFile.write("\n");
128 if (
type.qualifiedClassName() !=
name)
138 if (
type.qualifiedClassName() !=
name)
150 if (
r.addedIn.isValid()) {
151 s += u
" (added in %1.%2)"_s.
arg(
r.addedIn.majorVersion()).
arg(
r.addedIn.minorVersion());
153 if (
r.removedIn.isValid()) {
154 s += u
" (removed in %1.%2)"_s.
arg(
r.removedIn.majorVersion())
155 .
arg(
r.removedIn.minorVersion());
164 auto specialCharPred = [](
QChar c) {
return !
c.isLetterOrNumber(); };
168 return result +
"Registration"_L1;
173 output << uR
"(/****************************************************************************
174** Generated QML type registration code
176** WARNING! All changes made in this file will be lost!
177*****************************************************************************/
181 output << u"#include <QtQml/qqml.h>\n"_s;
182 output << u
"#include <QtQml/qqmlmoduleregistration.h>\n"_s;
184 for (
const QString &include : m_includes)
185 output << u
"\n#include <%1>"_s.arg(include);
190 QString moduleAsSymbol = m_module;
194 QString underscoredModuleAsSymbol = m_module;
197 if (underscoredModuleAsSymbol != moduleAsSymbol
198 || underscoredModuleAsSymbol.isEmpty()
199 || underscoredModuleAsSymbol.front().isDigit()) {
200 warning(outFileName) << m_module <<
"is an invalid QML module URI. You cannot import this.";
205#if !defined(QT_STATIC)
206#define Q_QMLTYPE_EXPORT Q_DECL_EXPORT
208#define Q_QMLTYPE_EXPORT
212 if (!m_targetNamespace.
isEmpty())
213 output << u
"namespace "_s << m_targetNamespace << u
" {\n"_s;
215 output << u
"Q_QMLTYPE_EXPORT void "_s << functionName << u
"()\n{"_s;
219 for (
const auto &version : m_pastMajorVersions) {
221 qmlRegisterModule("%1", %2, 0);
222 qmlRegisterModule("%1", %2, 254);)"_s.arg(m_module)
226 if (minorVersion != 0) {
228 qmlRegisterModule("%1", %2, 0);)"_s.arg(m_module)
232 QVector<QAnyStringView> typesRegisteredAnonymously;
235 bool foundRevisionEntry =
false;
237 if (
entry.revision.isValid()) {
238 foundRevisionEntry =
true;
243 if (!foundRevisionEntry)
246 if (typesRegisteredAnonymously.contains(
typeName))
249 typesRegisteredAnonymously.append(
typeName);
251 if (m_followForeignVersioning) {
253 qmlRegisterAnonymousTypesAndRevisions<%1>("%2", %3);)"_s.arg(typeName.toString(), m_module)
258 for (
const auto &version
259 : m_pastMajorVersions +
decltype(m_pastMajorVersions){ majorVersion }) {
261 qmlRegisterAnonymousType<%1, 254>("%2", %3);)"_s.arg(typeName.toString(), m_module)
269 QHash<QString, QList<ExclusiveVersionRange>> qmlElementInfos;
271 for (
const MetaType &classDef : std::as_const(m_types)) {
274 if (classDef.inputFile().isEmpty())
282 bool targetIsNamespace = classDef.kind() == MetaType::Kind::Namespace;
285 QList<QString> qmlElementNames;
289 for (
const ClassInfo &
v : classDef.classInfos()) {
292 qmlElementNames.append(
v.value.toString());
294 targetName =
v.value.toString();
296 targetIsNamespace = targetIsNamespace || (
v.value ==
S_TRUE);
298 extendedName =
v.value;
300 int version =
toInt(
v.value);
304 int version =
toInt(
v.value);
310 for (
QString qmlElementName : std::as_const(qmlElementNames)) {
313 if (qmlElementName ==
S_AUTO)
315 qmlElementInfos[qmlElementName].append({
316 classDef.inputFile(),
326 if (targetIsNamespace) {
330 QString targetTypeName = targetName;
332 const QList<QAnyStringView> namespaces
336 m_types, m_foreignTypes, targetName, namespaces);
338 if (!
target.javaScript.isEmpty() &&
target.native.isEmpty())
339 warning(
target.javaScript) <<
"JavaScript type cannot be used as namespace";
341 if (
target.native.kind() == MetaType::Kind::Object)
342 targetTypeName +=
" *"_L1;
347 if (
className == targetName ||
target.native.kind() == MetaType::Kind::Namespace) {
350 Q_CONSTINIT static auto metaType = QQmlPrivate::metaTypeForNamespace(
351 [](const QtPrivate::QMetaTypeInterface *) {return &%1::staticMetaObject;},
353 QMetaType(&metaType).id();
354 })"_s.arg(targetName, targetTypeName);
356 Q_ASSERT(!targetTypeName.isEmpty());
357 output << u
"\n QMetaType::fromType<%1>().id();"_s.arg(targetTypeName);
366 result.append(staticMetaObject);
370 if (!qmlElementNames.isEmpty()) {
372 qmlRegisterNamespaceAndRevisions(%1, "%2", %3, nullptr, %4, %5);)"_s
373 .arg(metaObjectPointer(targetName), m_module)
377 : metaObjectPointer(extendedName));
380 if (!qmlElementNames.isEmpty()) {
383 if (!
it->revision.isValid())
387 if (m_moduleVersion < revision) {
391 <<
"with future version" << revision
392 <<
"when module version is only" << m_moduleVersion;
398 const Property::Container
properties = classDef.properties();
400 if (m_moduleVersion.
isValid()) {
406 qmlRegisterTypesAndRevisions<%1>("%2", %3);)"_s.arg(className, m_module).arg(majorVersion);
410 for (
const BaseType &
object : classDef.superClasses()) {
416 QVector<QAnyStringView> classesToCheck;
419 auto typeAsMap = findType(
typeName);
421 if (typeAsMap.isEmpty()) {
422 typeAsMap = findTypeForeign(
typeName);
423 if (typeAsMap.isEmpty())
426 if (!fillTypesRegisteredAnonymously(
427 typeAsMap.properties(),
typeName)) {
428 if (!fillTypesRegisteredAnonymously(
430 fillTypesRegisteredAnonymously(
436 for (
const BaseType &
object : typeAsMap.superClasses()) {
438 classesToCheck <<
object.name;
442 checkForRevisions(superClassName);
444 while (!classesToCheck.isEmpty())
445 checkForRevisions(classesToCheck.takeFirst());
450 QMetaType::fromType<%1%2>().id();)"_s.arg(
451 className, classDef.kind() == MetaType::Kind::Object ? u" *" : u
"");
456 for (
const auto [qmlName, exportsForSameQmlName] : qmlElementInfos.asKeyValueRange()) {
459 if (exportsForSameQmlName.size() < 2)
463 std::sort(exportsForSameQmlName.begin(), exportsForSameQmlName.end());
464 auto conflictingExportStartIt = exportsForSameQmlName.cbegin();
467 conflictingExportStartIt =
468 std::adjacent_find(conflictingExportStartIt, exportsForSameQmlName.cend());
469 if (conflictingExportStartIt == exportsForSameQmlName.cend())
472 auto conflictingExportEndIt = std::find_if_not(
473 conflictingExportStartIt, exportsForSameQmlName.cend(),
474 [=](
const auto &
x) ->
bool { return x == *conflictingExportStartIt; });
475 QString registeringCppClasses = conflictingExportStartIt->claimerName;
476 std::for_each(std::next(conflictingExportStartIt), conflictingExportEndIt,
480 warning(conflictingExportStartIt->fileName)
481 << qmlName <<
"is registered multiple times by the following C++ classes:"
482 << registeringCppClasses;
483 conflictingExportStartIt = conflictingExportEndIt;
488 qmlRegisterModule("%1", %2, %3);
491static const QQmlModuleRegistration %5("%1", %4);
497 if (!m_targetNamespace.
isEmpty())
498 output << u
"} // namespace %1\n"_s.arg(m_targetNamespace);
505 creator.setForeignTypes(m_foreignTypes);
506 creator.setReferencedTypes(m_referencedTypes);
510 return creator.generate(pluginTypesFile);
514 const QString &targetNamespace)
517 m_targetNamespace = targetNamespace;
520 const QList<quint8> &pastMajorVersions,
521 bool followForeignVersioning)
523 m_moduleVersion = moduleVersion;
524 m_pastMajorVersions = pastMajorVersions;
525 m_followForeignVersioning = followForeignVersioning;
529 m_includes = includes;
532 const QVector<MetaType> &
types,
const QVector<MetaType> &foreignTypes)
535 m_foreignTypes = foreignTypes;
539 m_referencedTypes = referencedTypes;
static JNINativeMethod methods[]
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
QString fileName() const override
Returns the name set by setFileName() or to the QFile constructors.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
constexpr qsizetype length() const noexcept
qsizetype size() const noexcept
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString & replace(qsizetype i, qsizetype len, QChar after)
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
QByteArray toUtf8() const &
static constexpr QTypeRevision fromVersion(Major majorVersion, Minor minorVersion)
Produces a QTypeRevision from the given majorVersion and minorVersion, both of which need to be a val...
constexpr quint8 minorVersion() const
Returns the minor version encoded in the revision.
constexpr bool isValid() const
Returns true if the major version or the minor version is known, otherwise false.
static constexpr QTypeRevision fromEncodedVersion(Integer value)
Produces a QTypeRevision from the given value.
constexpr quint8 majorVersion() const
Returns the major version encoded in the revision.
void setModuleNameAndNamespace(const QString &module, const QString &targetNamespace)
static bool argumentsFromCommandLineAndFile(QStringList &allArguments, const QStringList &arguments)
void setTypes(const QVector< MetaType > &types, const QVector< MetaType > &foreignTypes)
void setIncludes(const QList< QString > &includes)
void write(QTextStream &os, QAnyStringView outFileName) const
void setModuleVersions(QTypeRevision moduleVersion, const QList< quint8 > &pastMajorVersions, bool followForeignVersioning)
bool generatePluginTypes(const QString &pluginTypesFile)
void setReferencedTypes(const QList< QAnyStringView > &referencedTypes)
static int runExtract(const QString &baseName, const MetaTypesJsonProcessor &processor)
QSet< QString >::iterator it
QList< QVariant > arguments
QString includeGuard(const QString &filename)
Combined button and popup list for selecting options.
static const QCssKnownValue properties[NumProperties - 1]
DBusConnection const char DBusError * error
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLsizei GLenum GLenum * types
GLdouble GLdouble GLdouble GLdouble q
static QString registrationVarName(const QString &module)
bool operator<(const ExclusiveVersionRange &x, const ExclusiveVersionRange &y)
True if x was removed before y was introduced.
QString conflictingVersionToString(const ExclusiveVersionRange &r)
bool operator==(const ExclusiveVersionRange &x, const ExclusiveVersionRange &y)
True when x and y share a common version.
QT_BEGIN_NAMESPACE QTypeRevision handleInMinorVersion(QTypeRevision revision, int majorVersion)
QDebug warning(QAnyStringView fileName, int lineNumber)
Members members(const Members &candidates, QTypeRevision maxMajorVersion, Postprocess &&process)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
static int toInt(const QChar &qc, int R)
QT_BEGIN_NAMESPACE typedef uchar * output
const char className[16]
[1]
QItemEditorCreatorBase * creator
std::vector< Method > Container
\inmodule QtCore \reentrant
static FoundType findType(const QVector< MetaType > &types, const QVector< MetaType > &foreign, const QAnyStringView &name, const QList< QAnyStringView > &namespaces)