Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmljscontextualtypes_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
5#ifndef QQMLJSCONTEXTUALTYPES_P_H
6#define QQMLJSCONTEXTUALTYPES_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#include <QtCore/qstring.h>
19#include <QtCore/qhash.h>
20#include <private/qqmljsscope_p.h>
21
22#include <QtCore/qtyperevision.h>
23
24QT_BEGIN_NAMESPACE
25
26namespace QQmlJS {
27
28// note: like QQmlImportInstance::Precedence, except that inline components are 0 and
29// "Precedence::Highest" is 1 instead of 0.
35
37{
39 ContextualType(const ImportedScope<QQmlJSScope::ConstPtr> &type, quint8 precedence)
41 {
42 }
43 ContextualType(const QQmlJSScope::ConstPtr &type, QTypeRevision revision, quint8 precedence)
45 {
46 }
48};
59
60/*! \internal
61 * Maps type names to types and the compile context of the types. The context can be
62 * INTERNAL (for c++ and synthetic jsrootgen types) or QML (for qml types).
63 */
65{
67
69 CompileContext context,
70 const QHash<QString, ContextualType> &types,
71 const QMultiHash<QQmlJSScope::ConstPtr, QString> &names,
72 const QQmlJSScope::ConstPtr &arrayType)
73 : m_types(types)
74 , m_names(names)
75 , m_context(context)
77 {}
78
79 CompileContext context() const { return m_context; }
80 QQmlJSScope::ConstPtr arrayType() const { return m_arrayType; }
81
82 bool hasType(const QString &name) const { return m_types.contains(name); }
83
84 ContextualType type(const QString &name) const { return m_types[name]; }
85 QString name(const QQmlJSScope::ConstPtr &type) const { return m_names[type]; }
86
87 void setType(const QString &name, const ContextualType &type);
88 void setFileSelectedType(const QString &fileSelector, const QString &name,
89 const ContextualType &type);
90 void clearType(const QString &name)
91 {
92 auto &scope = m_types[name].scope;
93 auto it = m_names.find(scope);
94 while (it != m_names.end() && it.key() == scope)
95 it = m_names.erase(it);
96 scope = QQmlJSScope::ConstPtr();
97 }
98
99 bool isNullType(const QString &name) const
100 {
101 const auto it = m_types.constFind(name);
102 return it != m_types.constEnd() && it->scope.isNull();
103 }
104
105 void addTypes(const ContextualTypes &types)
106 {
107 Q_ASSERT(types.m_context == m_context);
108 for (auto it = types.m_types.cbegin(), end = types.m_types.cend(); it != end; ++it) {
109 setType(it.key(), it.value());
110 }
111 for (auto it = types.m_fileSelectedTypes.cbegin(), end = types.m_fileSelectedTypes.cend();
112 it != end; ++it) {
113 setFileSelectedType(it->fileSelector, it.key(), it->type);
114 }
115 }
116
117 const QHash<QString, ContextualType> &types() const { return m_types; }
118 auto fileSelectionsEqualRange(const QString &name) const
119 {
120 return m_fileSelectedTypes.equal_range(name);
121 }
122 bool hasFileSelectors() const { return m_fileSelectedTypes.size() > 0; }
123 Q_QMLCOMPILER_EXPORT FileSelectorInfo
125 const auto &names() const { return m_names; }
126
128 {
129 m_names.clear();
130 m_types.clear();
131 }
132
133private:
134 QHash<QString, ContextualType> m_types;
135 QMultiHash<QString, FileSelectedType> m_fileSelectedTypes;
136 QMultiHash<QQmlJSScope::ConstPtr, QString> m_names;
137 CompileContext m_context;
138
139 // For resolving sequence types
140 QQmlJSScope::ConstPtr m_arrayType;
141};
142}
143
144QT_END_NAMESPACE
145
146#endif // QQMLJSCONTEXTUALTYPES_P_H
Combined button and popup list for selecting options.
ContextualType(const QQmlJSScope::ConstPtr &type, QTypeRevision revision, quint8 precedence)
ContextualType(const ImportedScope< QQmlJSScope::ConstPtr > &type, quint8 precedence)
ContextualType type(const QString &name) const
const QHash< QString, ContextualType > & types() const
QString name(const QQmlJSScope::ConstPtr &type) const
void addTypes(const ContextualTypes &types)
auto fileSelectionsEqualRange(const QString &name) const
CompileContext context() const
bool isNullType(const QString &name) const
ContextualTypes(CompileContext context, const QHash< QString, ContextualType > &types, const QMultiHash< QQmlJSScope::ConstPtr, QString > &names, const QQmlJSScope::ConstPtr &arrayType)
bool hasType(const QString &name) const
void setType(const QString &name, const ContextualType &type)
QQmlJSScope::ConstPtr arrayType() const
void setFileSelectedType(const QString &fileSelector, const QString &name, const ContextualType &type)
void clearType(const QString &name)
QList< FileSelectedType > fileSelectedTypes