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
22QT_BEGIN_NAMESPACE
23
24namespace QQmlJS {
25
26// note: like QQmlImportInstance::Precedence, except that inline components are 0 and
27// "Precedence::Highest" is 1 instead of 0.
33
35{
37 ContextualType(const ImportedScope<QQmlJSScope::ConstPtr> &type, quint8 precedence)
39 {
40 }
41 ContextualType(const QQmlJSScope::ConstPtr &type, QTypeRevision revision, quint8 precedence)
43 {
44 }
46};
47
48/*! \internal
49 * Maps type names to types and the compile context of the types. The context can be
50 * INTERNAL (for c++ and synthetic jsrootgen types) or QML (for qml types).
51 */
53{
55
57 CompileContext context,
58 const QHash<QString, ContextualType> &types,
59 const QMultiHash<QQmlJSScope::ConstPtr, QString> &names,
60 const QQmlJSScope::ConstPtr &arrayType)
61 : m_types(types)
62 , m_names(names)
63 , m_context(context)
65 {}
66
67 CompileContext context() const { return m_context; }
68 QQmlJSScope::ConstPtr arrayType() const { return m_arrayType; }
69
70 bool hasType(const QString &name) const { return m_types.contains(name); }
71
72 ContextualType type(const QString &name) const { return m_types[name]; }
73 QString name(const QQmlJSScope::ConstPtr &type) const { return m_names[type]; }
74
75 void setType(const QString &name, const ContextualType &type);
76 void clearType(const QString &name)
77 {
78 auto &scope = m_types[name].scope;
79 auto it = m_names.find(scope);
80 while (it != m_names.end() && it.key() == scope)
81 it = m_names.erase(it);
82 scope = QQmlJSScope::ConstPtr();
83 }
84
85 bool isNullType(const QString &name) const
86 {
87 const auto it = m_types.constFind(name);
88 return it != m_types.constEnd() && it->scope.isNull();
89 }
90
91 void addTypes(const ContextualTypes &types)
92 {
93 Q_ASSERT(types.m_context == m_context);
94 for (auto it = types.m_types.cbegin(), end = types.m_types.cend(); it != end; ++it) {
95 setType(it.key(), it.value());
96 }
97 }
98
99 const QHash<QString, ContextualType> &types() const { return m_types; }
100 const auto &names() const { return m_names; }
101
103 {
104 m_names.clear();
105 m_types.clear();
106 }
107
108private:
109 QHash<QString, ContextualType> m_types;
110 QMultiHash<QQmlJSScope::ConstPtr, QString> m_names;
111 CompileContext m_context;
112
113 // For resolving sequence types
114 QQmlJSScope::ConstPtr m_arrayType;
115};
116}
117
118QT_END_NAMESPACE
119
120#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)
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 clearType(const QString &name)