10#include <QtCore/qcborarray.h>
11#include <QtCore/qcbormap.h>
12#include <QtCore/qfile.h>
13#include <QtCore/qjsondocument.h>
14#include <QtCore/qqueue.h>
40 if (qualified != unqualified) {
72 fprintf(stderr,
"Error parsing %s: JSON is not an object\n",
79 }
else if (metaObjects.
isMap()) {
82 fprintf(stderr,
"Error parsing %s: JSON is not an object or an array\n",
98 fprintf(stderr,
"Cannot open foreign types file %s\n",
qPrintable(
types));
115 fprintf(stderr,
"Error parsing %s: JSON is not an object\n",
127template<
typename String>
143 sortTypes(m_foreignTypes);
152 for (
const auto &
obj: m_types) {
159 bool isSingleton =
false;
160 bool isExplicitlyUncreatable =
false;
167 qmlElement = u
"QML_NAMED_ELEMENT("_s +
className + u
")"_s;
169 qmlElement = u
"QML_ANONYMOUS"_s;
171 qmlElement = u
"QML_NAMED_ELEMENT("_s +
value.toString() + u
")";
174 isExplicitlyUncreatable =
true;
176 qmlUncreatable = u
"QML_UNCREATABLE(\""_s +
value.toString() + u
"\")";
178 qmlAttached = u
"QML_ATTACHED("_s +
value.toString() + u
")";
186 registrationHelper += u
"\nstruct "_s + foreignClassName + u
"{\n Q_GADGET\n"_s;
187 registrationHelper += spaces + u
"QML_FOREIGN(" +
className + u
")\n"_s;
188 registrationHelper += spaces + qmlElement + u
"\n"_s;
190 registrationHelper += spaces + u
"QML_SINGLETON\n"_s;
191 if (isExplicitlyUncreatable) {
193 registrationHelper += spaces + uR
"(QML_UNCREATABLE(""))" + u"n";
195 registrationHelper += spaces + qmlUncreatable + u
"\n";
198 registrationHelper += spaces + qmlAttached + u
"\n";
199 registrationHelper += u
"};\n";
201 return registrationHelper;
204MetaTypesJsonProcessor::RegistrationMode MetaTypesJsonProcessor::qmlTypeRegistrationMode(
213 return ObjectRegistration;
215 return GadgetRegistration;
217 return NamespaceRegistration;
218 qWarning() <<
"Not registering classInfo which is neither an object, "
219 "nor a gadget, nor a namespace:"
224 return NoRegistration;
230 return string.visit([
seed](
auto view) {
240void MetaTypesJsonProcessor::addRelatedTypes()
244 typeQueue.
append(m_types);
246 const auto addRelatedName
249 m_types, m_foreignTypes, relatedName,
namespaces)) {
258 for (
const QCborValue &classInfo : classInfos) {
269 for (
const QCborMap &foreignType : m_foreignTypes) {
270 const auto classInfos = foreignType.value(
S_CLASS_INFOS).toArray();
271 bool seenQmlPrefix =
false;
272 for (
const QCborValue &classInfo : classInfos) {
276 processedRelatedNames.
insert(
278 seenQmlPrefix =
true;
291 m_referencedTypes.
append(qualifiedName);
292 if (!processedRelatedNames.
contains(qualifiedName)) {
293 processedRelatedNames.
insert(qualifiedName);
294 m_types.append(*
other);
311 for (
const QCborValue &classInfo : classInfos) {
320 m_foreignTypes, {}, foreignClassName,
namespaces)) {
324 if (!otherSupers.isEmpty()) {
325 const QCborMap otherSuperObject = otherSupers.first().toMap();
331 for (
const QCborValue &otherClassInfo : otherClassInfos) {
347 const QCborMap superObject = super.toMap();
357 return toStringView(a, S_QUALIFIED_CLASS_NAME) <
358 toStringView(b, S_QUALIFIED_CLASS_NAME);
364 return (m_privateIncludes &&
endsWith(include,
"_p.h"_L1))
377 switch (qmlTypeRegistrationMode(classDef)) {
378 case NamespaceRegistration:
379 case GadgetRegistration:
380 case ObjectRegistration: {
388 "Class %s is declared in %s, which appears not to be a header.\n"
389 "The compilation of its registration to QML may fail.\n",
393 m_includes.
append(include);
394 m_types.append(classDef);
398 m_foreignTypes.append(classDef);
411 m_foreignTypes.append(classDef);
QString toString() const
Returns a deep copy of this string view's data as a QString.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
QCborValue value(qint64 key) const
Returns the QCborValue element in this map that corresponds to key key, if there is one.
iterator insert(qint64 key, const QCborValue &value_)
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore\reentrant
QString toString(const QString &defaultValue={}) const
Returns the string value stored in this QCborValue, if it is of the string type.
QCborArray toArray() const
bool isArray() const
Returns true if this QCborValue is of the array type.
static QCborValue fromJsonValue(const QJsonValue &v)
Converts the JSON value contained in v into its corresponding CBOR value and returns it.
bool isMap() const
Returns true if this QCborValue is of the map type.
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
\inmodule QtCore\reentrant
bool isArray() const
Returns true if the document contains an array.
QJsonArray array() const
Returns the QJsonArray contained in the document.
QJsonObject object() const
Returns the QJsonObject contained in the document.
bool isObject() const
Returns true if the document contains an object.
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=nullptr)
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
bool isEmpty() const noexcept
iterator erase(const_iterator begin, const_iterator end)
void append(parameter_type t)
const_iterator constEnd() const noexcept
void enqueue(const T &t)
Adds value t to the tail of the queue.
T dequeue()
Removes the head item in the queue and returns it.
bool contains(const T &value) const
iterator insert(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
bool startsWith(QAnyStringView whole, QAnyStringView part)
QAnyStringView toStringView(const QCborValue &value)
bool endsWith(QAnyStringView whole, QAnyStringView part)
const char * classInfo(const QMetaObject *metaObject, const char *key)
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static bool contains(const QJsonArray &haystack, unsigned needle)
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLsizei GLenum GLenum * types
GLsizei GLsizei GLchar * source
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
static void split(QT_FT_Vector *b)
#define qPrintable(string)
QLatin1StringView QLatin1String
const char className[16]
[1]
QFileInfo info(fileName)
[8]
obj metaObject() -> className()
\inmodule QtCore\reentrant
\inmodule QtCore \reentrant
static const QCborMap * findType(const QVector< QCborMap > &types, const QVector< QCborMap > &foreign, const QAnyStringView &name, const QList< QAnyStringView > &namespaces)
QT_BEGIN_NAMESPACE bool toBool(const QString &str)