Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qqmldirparser_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQMLDIRPARSER_P_H
5#define QQMLDIRPARSER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/QUrl>
19#include <QtCore/QHash>
20#include <QtCore/QDebug>
21#include <QtCore/QTypeRevision>
22#include <private/qtqmlcompilerglobal_p.h>
23#include <private/qqmljsdiagnosticmessage_p.h>
24
26
27class QQmlEngine;
29{
30public:
31 void clear();
32 bool parse(const QString &source);
33
34 bool hasError() const { return !_errors.isEmpty(); }
36 QList<QQmlJS::DiagnosticMessage> errors(const QString &uri) const;
37
38 QString typeNamespace() const { return _typeNamespace; }
39 void setTypeNamespace(const QString &s) { _typeNamespace = s; }
40
41 static void checkNonRelative(const char *item, const QString &typeName, const QString &fileName)
42 {
43 if (fileName.startsWith(QLatin1Char('/'))) {
44 qWarning() << item << typeName
45 << "is specified with non-relative URL" << fileName << "in a qmldir file."
46 << "URLs in qmldir files should be relative to the qmldir file's directory.";
47 }
48 }
49
50 struct Plugin
51 {
52 Plugin() = default;
53
54 Plugin(const QString &name, const QString &path, bool optional)
55 : name(name), path(path), optional(optional)
56 {
57 checkNonRelative("Plugin", name, path);
58 }
59
62 bool optional = false;
63 };
64
65 struct Component
66 {
67 Component() = default;
68
70 : typeName(typeName), fileName(fileName), version(version),
71 internal(false), singleton(false)
72 {
73 checkNonRelative("Component", typeName, fileName);
74 }
75
79 bool internal = false;
80 bool singleton = false;
81 };
82
83 struct Script
84 {
85 Script() = default;
86
87 Script(const QString &nameSpace, const QString &fileName, QTypeRevision version)
88 : nameSpace(nameSpace), fileName(fileName), version(version)
89 {
90 checkNonRelative("Script", nameSpace, fileName);
91 }
92
96 };
97
98 struct Import
99 {
100 enum Flag {
101 Default = 0x0,
102 Auto = 0x1, // forward the version of the importing module
103 Optional = 0x2, // is not automatically imported but only a tooling hint
104 OptionalDefault =
105 0x4, // tooling hint only, denotes this entry should be imported by tooling
106 };
108
109 Import() = default;
111 : module(module), version(version), flags(flags)
112 {
113 }
114
116 QTypeRevision version; // invalid version is latest version, unless Flag::Auto
118
119 friend bool operator==(const Import &a, const Import &b)
120 {
121 return a.module == b.module && a.version == b.version && a.flags == b.flags;
122 }
123 };
124
125 QMultiHash<QString,Component> components() const { return _components; }
126 QList<Import> dependencies() const { return _dependencies; }
127 QList<Import> imports() const { return _imports; }
128 QList<Script> scripts() const { return _scripts; }
129 QList<Plugin> plugins() const { return _plugins; }
130 bool designerSupported() const { return _designerSupported; }
131 bool isStaticModule() const { return _isStaticModule; }
132 bool isSystemModule() const { return _isSystemModule; }
133
134 QStringList typeInfos() const { return _typeInfos; }
135 QStringList classNames() const { return _classNames; }
136 QString preferredPath() const { return _preferredPath; }
137 QString linkTarget() const { return _linkTarget; }
138
139private:
140 bool maybeAddComponent(const QString &typeName, const QString &fileName, const QString &version, QHash<QString,Component> &hash, int lineNumber = -1, bool multi = true);
141 void reportError(quint16 line, quint16 column, const QString &message);
142
143private:
145 QString _typeNamespace;
146 QString _preferredPath;
148 QList<Import> _dependencies;
149 QList<Import> _imports;
150 QList<Script> _scripts;
151 QList<Plugin> _plugins;
152 bool _designerSupported = false;
153 bool _isStaticModule = false;
154 bool _isSystemModule = false;
155 QStringList _typeInfos;
156 QStringList _classNames;
157 QString _linkTarget;
158};
159
164
167
169
170#endif // QQMLDIRPARSER_P_H
\inmodule QtCore
\inmodule QtCore
Definition qhash.h:818
Definition qlist.h:74
\inmodule QtCore
Definition qhash.h:1348
void setTypeNamespace(const QString &s)
QList< Import > dependencies() const
bool hasError() const
QMultiHash< QString, Component > components() const
QList< Script > scripts() const
QString linkTarget() const
QList< Import > imports() const
static void checkNonRelative(const char *item, const QString &typeName, const QString &fileName)
QStringList typeInfos() const
bool designerSupported() const
QStringList classNames() const
bool isStaticModule() const
bool isSystemModule() const
QString preferredPath() const
QString typeNamespace() const
QList< Plugin > plugins() const
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
static constexpr QTypeRevision zero()
Produces a QTypeRevision with major and minor version {0}.
QHash< int, QWidget * > hash
[35multi]
b clear()
Combined button and popup list for selecting options.
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
Flags
#define qWarning
Definition qlogging.h:162
const char * typeName
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLbitfield flags
GLuint GLsizei const GLchar * message
GLuint name
GLsizei GLsizei GLchar * source
GLenum GLenum GLsizei void GLsizei void * column
GLsizei const GLchar *const * path
GLdouble s
[6]
Definition qopenglext.h:235
QDebug & operator<<(QDebug &, const QQmlDirParser::Component &)
static void setError(QJsonObject *response, const QString &msg)
static QT_BEGIN_NAMESPACE const uint Default
Definition qsplitter_p.h:25
#define Q_QML_COMPILER_PRIVATE_EXPORT
unsigned short quint16
Definition qtypes.h:43
QGraphicsItem * item
\inmodule QtCore \reentrant
Definition qchar.h:17
Component(const QString &typeName, const QString &fileName, QTypeRevision version)
friend bool operator==(const Import &a, const Import &b)
Plugin(const QString &name, const QString &path, bool optional)
Script(const QString &nameSpace, const QString &fileName, QTypeRevision version)