Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
// Qt-Security score:significant
4
5
#
ifndef
QQMLDIRPARSER_P_H
6
#
define
QQMLDIRPARSER_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
QtCore
/
QUrl
>
20
#
include
<
QtCore
/
QHash
>
21
#
include
<
QtCore
/
QDebug
>
22
#
include
<
QtCore
/
QTypeRevision
>
23
#
include
<
private
/
qtqmlcompilerglobal_p
.
h
>
24
#
include
<
private
/
qqmljsdiagnosticmessage_p
.
h
>
25
26
QT_BEGIN_NAMESPACE
27
28
class
QQmlEngine;
29
class
Q_QML_COMPILER_EXPORT
QQmlDirParser
30
{
31
public
:
32
void
clear();
33
bool
parse(
const
QString &source);
34
void
disambiguateFileSelectors();
35
36
bool
hasError()
const
{
return
!_errors.isEmpty(); }
37
void
setError(
const
QQmlJS::DiagnosticMessage &);
38
QList<QQmlJS::DiagnosticMessage> errors(
const
QString &uri)
const
;
39
40
bool
hasTypeNamespace()
const
{
return
!_typeNamespace.isEmpty(); }
41
QString typeNamespace()
const
{
return
_typeNamespace; }
42
void
setTypeNamespace(
const
QString &s) { _typeNamespace = s; }
43
44
static
void
checkNonRelative(
const
char
*item,
const
QString &typeName,
const
QString &fileName)
45
{
46
if
(fileName.startsWith(QLatin1Char(
'/'
))) {
47
qWarning() << item << typeName
48
<<
"is specified with non-relative URL"
<< fileName <<
"in a qmldir file."
49
<<
"URLs in qmldir files should be relative to the qmldir file's directory."
;
50
}
51
}
52
53
struct
Plugin
54
{
55
Plugin() =
default
;
56
57
Plugin(
const
QString &name,
const
QString &path,
bool
optional)
58
: name(name), path(path), optional(optional)
59
{
60
checkNonRelative(
"Plugin"
, name, path);
61
}
62
63
QString name;
64
QString path;
65
bool
optional =
false
;
66
};
67
68
struct
Component
69
{
70
Component() =
default
;
71
72
Component(
const
QString &typeName,
const
QString &fileName, QTypeRevision version)
73
: typeName(typeName), fileName(fileName), version(version),
74
internal(
false
), singleton(
false
)
75
{
76
checkNonRelative(
"Component"
, typeName, fileName);
77
}
78
79
QString typeName;
80
QString fileName;
81
QTypeRevision version = QTypeRevision::zero();
82
bool
internal =
false
;
83
bool
singleton =
false
;
84
};
85
86
struct
Script
87
{
88
Script() =
default
;
89
90
Script(
const
QString &nameSpace,
const
QString &fileName, QTypeRevision version)
91
: nameSpace(nameSpace), fileName(fileName), version(version)
92
{
93
checkNonRelative(
"Script"
, nameSpace, fileName);
94
}
95
96
QString nameSpace;
97
QString fileName;
98
QTypeRevision version = QTypeRevision::zero();
99
};
100
101
struct
Import
102
{
103
enum
Flag {
104
Default = 0x0,
105
Auto = 0x1,
// forward the version of the importing module
106
Optional = 0x2,
// is not automatically imported but only a tooling hint
107
OptionalDefault =
108
0x4,
// tooling hint only, denotes this entry should be imported by tooling
109
};
110
Q_DECLARE_FLAGS(Flags, Flag)
111
112
Import() =
default
;
113
Import(QString module, QTypeRevision version, Flags flags)
114
: module(module), version(version), flags(flags)
115
{
116
}
117
118
QString module;
119
QTypeRevision version;
// invalid version is latest version, unless Flag::Auto
120
Flags flags;
121
122
friend
bool
comparesEqual(
const
Import &a,
const
Import &b)
noexcept
123
{
124
return
a.module == b.module && a.version == b.version && a.flags == b.flags;
125
}
126
Q_DECLARE_EQUALITY_COMPARABLE(Import)
127
};
128
129
using
Export = QTypeRevision;
130
131
QMultiHash<QString,Component> components()
const
{
return
_components; }
132
QList<Import> dependencies()
const
{
return
_dependencies; }
133
QList<Import> imports()
const
{
return
_imports; }
134
QList<Export> exports()
const
{
return
_exports; }
135
QList<Script> scripts()
const
{
return
_scripts; }
136
QList<Plugin> plugins()
const
{
return
_plugins; }
137
bool
designerSupported()
const
{
return
_designerSupported; }
138
139
// A static module has side effects outside the mere importing of types. We shall not warn
140
// about it being being "unused". The builtins are also a static module.
141
bool
isStaticModule()
const
{
return
_isStaticModule; }
142
143
// A system module includes the JavaScript root object
144
bool
isSystemModule()
const
{
return
_isSystemModule; }
145
146
QStringList typeInfos()
const
{
return
_typeInfos; }
147
QStringList classNames()
const
{
return
_classNames; }
148
QString preferredPath()
const
{
return
_preferredPath; }
149
QString linkTarget()
const
{
return
_linkTarget; }
150
151
private
:
152
bool
maybeAddComponent(
const
QString &typeName,
const
QString &fileName,
const
QString &version, QHash<QString,Component> &hash,
int
lineNumber = -1,
bool
multi =
true
);
153
void
reportError(quint16 line, quint16 column,
const
QString &message);
154
QString scanQuotedWord(
const
QChar *&ch, quint16 lineNumber, quint16 columnNumber);
155
void
insertComponentOrScript(
156
const
QString &name,
const
QString &fileName, QTypeRevision version);
157
158
private
:
159
QList<QQmlJS::DiagnosticMessage> _errors;
160
QString _typeNamespace;
161
QString _preferredPath;
162
QMultiHash<QString,Component> _components;
163
QList<Import> _dependencies;
164
QList<Import> _imports;
165
QList<Export> _exports;
166
QList<Script> _scripts;
167
QList<Plugin> _plugins;
168
bool
_designerSupported =
false
;
169
bool
_isStaticModule =
false
;
170
bool
_isSystemModule =
false
;
171
QStringList _typeInfos;
172
QStringList _classNames;
173
QString _linkTarget;
174
};
175
176
using
QQmlDirComponents = QMultiHash<QString,QQmlDirParser::Component>;
177
using
QQmlDirScripts = QList<QQmlDirParser::Script>;
178
using
QQmlDirPlugins = QList<QQmlDirParser::Plugin>;
179
using
QQmlDirImports = QList<QQmlDirParser::Import>;
180
using
QQmlDirExports = QList<QQmlDirParser::Export>;
181
182
QDebug
&
operator
<< (QDebug &,
const
QQmlDirParser::Component &);
183
QDebug
&
operator
<< (QDebug &,
const
QQmlDirParser::Script &);
184
185
QT_END_NAMESPACE
186
187
#
endif
// QQMLDIRPARSER_P_H
QQmlDirParser
Definition
qqmldirparser_p.h:30
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
scanSpace
static void scanSpace(const QChar *&ch)
Definition
qqmldirparser.cpp:57
disambiguateFileSelectedScripts
static void disambiguateFileSelectedScripts(QQmlDirScripts *scripts)
Definition
qqmldirparser.cpp:558
scanWord
static QString scanWord(const QChar *&ch)
Definition
qqmldirparser.cpp:67
pathWithoutFileSelectors
static QString pathWithoutFileSelectors(QString path, qsizetype firstPlus)
Definition
qqmldirparser.cpp:465
disambiguateFileSelectedComponents
static void disambiguateFileSelectedComponents(QQmlDirComponents *components)
Definition
qqmldirparser.cpp:518
scanToEnd
static void scanToEnd(const QChar *&ch)
Definition
qqmldirparser.cpp:62
parseVersion
static QTypeRevision parseVersion(const QString &str)
Definition
qqmldirparser.cpp:28
canDisambiguate
static bool canDisambiguate(const QString &fileName1, const QString &fileName2, QString *correctedFileName)
Definition
qqmldirparser.cpp:480
parseInt
static QT_BEGIN_NAMESPACE int parseInt(QStringView str, bool *ok)
Definition
qqmldirparser.cpp:11
operator<<
QDataStream & operator<<(QDataStream &stream, const QImage &image)
[0]
Definition
qimage.cpp:4045
qtdeclarative
src
qml
qmldirparser
qqmldirparser_p.h
Generated on
for Qt by
1.18.0