Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 void disambiguateFileSelectors();
34
35 bool hasError() const { return !_errors.isEmpty(); }
37 QList<QQmlJS::DiagnosticMessage> errors(const QString &uri) const;
38
39 QString typeNamespace() const { return _typeNamespace; }
40 void setTypeNamespace(const QString &s) { _typeNamespace = s; }
41
42 static void checkNonRelative(const char *item, const QString &typeName, const QString &fileName)
43 {
44 if (fileName.startsWith(QLatin1Char('/'))) {
45 qWarning() << item << typeName
46 << "is specified with non-relative URL" << fileName << "in a qmldir file."
47 << "URLs in qmldir files should be relative to the qmldir file's directory.";
48 }
49 }
50
51 struct Plugin
52 {
53 Plugin() = default;
54
55 Plugin(const QString &name, const QString &path, bool optional)
56 : name(name), path(path), optional(optional)
57 {
58 checkNonRelative("Plugin", name, path);
59 }
60
63 bool optional = false;
64 };
65
66 struct Component
67 {
68 Component() = default;
69
71 : typeName(typeName), fileName(fileName), version(version),
72 internal(false), singleton(false)
73 {
74 checkNonRelative("Component", typeName, fileName);
75 }
76
80 bool internal = false;
81 bool singleton = false;
82 };
83
84 struct Script
85 {
86 Script() = default;
87
88 Script(const QString &nameSpace, const QString &fileName, QTypeRevision version)
89 : nameSpace(nameSpace), fileName(fileName), version(version)
90 {
91 checkNonRelative("Script", nameSpace, fileName);
92 }
93
97 };
98
99 struct Import
100 {
101 enum Flag {
102 Default = 0x0,
103 Auto = 0x1, // forward the version of the importing module
104 Optional = 0x2, // is not automatically imported but only a tooling hint
105 OptionalDefault =
106 0x4, // tooling hint only, denotes this entry should be imported by tooling
107 };
109
110 Import() = default;
112 : module(module), version(version), flags(flags)
113 {
114 }
115
116 QString module;
117 QTypeRevision version; // invalid version is latest version, unless Flag::Auto
119
120 friend bool operator==(const Import &a, const Import &b)
121 {
122 return a.module == b.module && a.version == b.version && a.flags == b.flags;
123 }
124 };
125
126 QMultiHash<QString,Component> components() const { return _components; }
127 QList<Import> dependencies() const { return _dependencies; }
128 QList<Import> imports() const { return _imports; }
129 QList<Script> scripts() const { return _scripts; }
130 QList<Plugin> plugins() const { return _plugins; }
131 bool designerSupported() const { return _designerSupported; }
132 bool isStaticModule() const { return _isStaticModule; }
133 bool isSystemModule() const { return _isSystemModule; }
134
135 QStringList typeInfos() const { return _typeInfos; }
136 QStringList classNames() const { return _classNames; }
137 QString preferredPath() const { return _preferredPath; }
138 QString linkTarget() const { return _linkTarget; }
139
140private:
141 bool maybeAddComponent(const QString &typeName, const QString &fileName, const QString &version, QHash<QString,Component> &hash, int lineNumber = -1, bool multi = true);
142 void reportError(quint16 line, quint16 column, const QString &message);
143
144private:
145 QList<QQmlJS::DiagnosticMessage> _errors;
146 QString _typeNamespace;
147 QString _preferredPath;
148 QMultiHash<QString,Component> _components;
149 QList<Import> _dependencies;
150 QList<Import> _imports;
151 QList<Script> _scripts;
152 QList<Plugin> _plugins;
153 bool _designerSupported = false;
154 bool _isStaticModule = false;
155 bool _isSystemModule = false;
156 QStringList _typeInfos;
157 QStringList _classNames;
158 QString _linkTarget;
159};
160
161using QQmlDirComponents = QMultiHash<QString,QQmlDirParser::Component>;
162using QQmlDirScripts = QList<QQmlDirParser::Script>;
163using QQmlDirPlugins = QList<QQmlDirParser::Plugin>;
164using QQmlDirImports = QList<QQmlDirParser::Import>;
165
168
170
171#endif // QQMLDIRPARSER_P_H
\inmodule QtCore
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:129
\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:166
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
GLdouble s
[6]
Definition qopenglext.h:235
GLsizei const GLchar *const * path
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:27
#define Q_QML_COMPILER_EXPORT
unsigned short quint16
Definition qtypes.h:48
QGraphicsItem * item
\inmodule QtCore \reentrant
Definition qchar.h:18
Component(const QString &typeName, const QString &fileName, QTypeRevision version)
friend bool operator==(const Import &a, const Import &b)
QString QTypeRevision version
Plugin(const QString &name, const QString &path, bool optional)
Script(const QString &nameSpace, const QString &fileName, QTypeRevision version)