1 | // Copyright (C) 2020 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 QV4RESOLVEDTYPEREFERNCE_P_H |
5 | #define QV4RESOLVEDTYPEREFERNCE_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 <QtQml/private/qtqmlglobal_p.h> |
19 | #include <QtQml/private/qqmlrefcount_p.h> |
20 | #include <QtQml/private/qqmlpropertycache_p.h> |
21 | #include <QtQml/private/qqmltype_p.h> |
22 | #include <QtQml/private/qv4compileddata_p.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class QCryptographicHash; |
27 | namespace QV4 { |
28 | |
29 | class ResolvedTypeReference |
30 | { |
31 | Q_DISABLE_COPY_MOVE(ResolvedTypeReference) |
32 | public: |
33 | ResolvedTypeReference() = default; |
34 | ~ResolvedTypeReference() |
35 | { |
36 | if (m_stronglyReferencesCompilationUnit && m_compilationUnit) |
37 | m_compilationUnit->release(); |
38 | } |
39 | |
40 | QQmlPropertyCache::ConstPtr propertyCache() const; |
41 | QQmlPropertyCache::ConstPtr createPropertyCache(); |
42 | bool addToHash(QCryptographicHash *hash, QHash<quintptr, QByteArray> *checksums); |
43 | |
44 | void doDynamicTypeCheck(); |
45 | |
46 | QQmlType type() const { return m_type; } |
47 | void setType(QQmlType type) { m_type = std::move(type); } |
48 | |
49 | QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit() |
50 | { |
51 | return m_compilationUnit; |
52 | } |
53 | |
54 | void setCompilationUnit(QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit) |
55 | { |
56 | if (m_compilationUnit == unit.data()) |
57 | return; |
58 | if (m_stronglyReferencesCompilationUnit) { |
59 | if (m_compilationUnit) |
60 | m_compilationUnit->release(); |
61 | m_compilationUnit = unit.take(); |
62 | } else { |
63 | m_compilationUnit = unit.data(); |
64 | } |
65 | } |
66 | |
67 | bool referencesCompilationUnit() const { return m_stronglyReferencesCompilationUnit; } |
68 | void setReferencesCompilationUnit(bool doReference) |
69 | { |
70 | if (doReference == m_stronglyReferencesCompilationUnit) |
71 | return; |
72 | m_stronglyReferencesCompilationUnit = doReference; |
73 | if (!m_compilationUnit) |
74 | return; |
75 | if (doReference) { |
76 | m_compilationUnit->addref(); |
77 | } else if (m_compilationUnit->count() == 1) { |
78 | m_compilationUnit->release(); |
79 | m_compilationUnit = nullptr; |
80 | } else { |
81 | m_compilationUnit->release(); |
82 | } |
83 | } |
84 | |
85 | QQmlPropertyCache::ConstPtr typePropertyCache() const { return m_typePropertyCache; } |
86 | void setTypePropertyCache(QQmlPropertyCache::ConstPtr cache) |
87 | { |
88 | m_typePropertyCache = std::move(cache); |
89 | } |
90 | |
91 | QTypeRevision version() const { return m_version; } |
92 | void setVersion(QTypeRevision version) { m_version = version; } |
93 | |
94 | bool isFullyDynamicType() const { return m_isFullyDynamicType; } |
95 | void setFullyDynamicType(bool fullyDynamic) { m_isFullyDynamicType = fullyDynamic; } |
96 | |
97 | private: |
98 | QQmlType m_type; |
99 | QQmlPropertyCache::ConstPtr m_typePropertyCache; |
100 | QV4::CompiledData::CompilationUnit *m_compilationUnit = nullptr; |
101 | |
102 | QTypeRevision m_version = QTypeRevision::zero(); |
103 | // Types such as QQmlPropertyMap can add properties dynamically at run-time and |
104 | // therefore cannot have a property cache installed when instantiated. |
105 | bool m_isFullyDynamicType = false; |
106 | bool m_stronglyReferencesCompilationUnit = true; |
107 | }; |
108 | |
109 | } // namespace QV4 |
110 | |
111 | QT_END_NAMESPACE |
112 | |
113 | #endif // QV4RESOLVEDTYPEREFERNCE_P_H |
114 |
Definitions
Learn Advanced QML with KDAB
Find out more