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
qqmljsscopesbyid_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef QQMLJSSCOPESBYID_P_H
5#define QQMLJSSCOPESBYID_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 "qqmljsscope_p.h"
19
20#include <QtCore/qhash.h>
21#include <QtCore/qstring.h>
22
24
29Q_DECLARE_FLAGS(QQmlJSScopesByIdOptions, QQmlJSScopesByIdOption);
30
32{
33public:
34 bool componentsAreBound() const { return m_componentsAreBound; }
35 void setComponentsAreBound(bool bound) { m_componentsAreBound = bound; }
36
37 void setSignaturesAreEnforced(bool enforced) { m_signaturesAreEnforced = enforced; }
38 bool signaturesAreEnforced() const { return m_signaturesAreEnforced; }
39
40 void setValueTypesAreAddressable(bool addressable) { m_valueTypesAreAddressable = addressable; }
41 bool valueTypesAreAddressable() const { return m_valueTypesAreAddressable; }
42
44 QQmlJSScopesByIdOptions options = Default) const
45 {
46 const QQmlJSScope::ConstPtr referrerRoot = componentRoot(referrer);
47 for (auto it = m_scopesById.begin(), end = m_scopesById.end(); it != end; ++it) {
48 if (*it == scope && isComponentVisible(componentRoot(*it), referrerRoot, options))
49 return it.key();
50 }
51 return QString();
52 }
53
60 QQmlJSScopesByIdOptions options = Default) const
61 {
62 Q_ASSERT(!id.isEmpty());
63 const auto range = m_scopesById.equal_range(id);
64 if (range.first == range.second)
65 return QQmlJSScope::ConstPtr();
66 const QQmlJSScope::ConstPtr referrerRoot = componentRoot(referrer);
67
68 for (auto it = range.first; it != range.second; ++it) {
69 if (isComponentVisible(componentRoot(*it), referrerRoot, options))
70 return *it;
71 }
72
73 return QQmlJSScope::ConstPtr();
74 }
75
76 void insert(const QString &id, const QQmlJSScope::ConstPtr &scope)
77 {
78 Q_ASSERT(!id.isEmpty());
79 m_scopesById.insert(id, scope);
80 }
81
82 void clear() { m_scopesById.clear(); }
83
91 bool existsAnywhereInDocument(const QString &id) const { return m_scopesById.contains(id); }
92
93private:
94 static QQmlJSScope::ConstPtr componentRoot(const QQmlJSScope::ConstPtr &inner)
95 {
99 scope = parent;
100 else
101 break;
102 }
103 return scope;
104 }
105
106 bool isComponentVisible(const QQmlJSScope::ConstPtr &observed,
107 const QQmlJSScope::ConstPtr &observer,
108 QQmlJSScopesByIdOptions options) const
109 {
110 if (!m_componentsAreBound && !options.testAnyFlag(AssumeComponentsAreBound))
111 return observed == observer;
112
113 for (QQmlJSScope::ConstPtr scope = observer; scope; scope = scope->parentScope()) {
114 if (scope == observed)
115 return true;
116 }
117
118 return false;
119 }
120
121 QMultiHash<QString, QQmlJSScope::ConstPtr> m_scopesById;
122 bool m_componentsAreBound = false;
123 bool m_signaturesAreEnforced = true;
124 bool m_valueTypesAreAddressable = false;
125};
126
128
129#endif // QQMLJSSCOPESBYID_P_H
bool isComponentRootElement() const
QQmlJSScope::Ptr parentScope()
bool isInlineComponent() const
QDeferredSharedPointer< const QQmlJSScope > ConstPtr
bool signaturesAreEnforced() const
bool componentsAreBound() const
bool existsAnywhereInDocument(const QString &id) const
void setValueTypesAreAddressable(bool addressable)
void setComponentsAreBound(bool bound)
QString id(const QQmlJSScope::ConstPtr &scope, const QQmlJSScope::ConstPtr &referrer, QQmlJSScopesByIdOptions options=Default) const
void setSignaturesAreEnforced(bool enforced)
bool valueTypesAreAddressable() const
QQmlJSScope::ConstPtr scope(const QString &id, const QQmlJSScope::ConstPtr &referrer, QQmlJSScopesByIdOptions options=Default) const
void insert(const QString &id, const QQmlJSScope::ConstPtr &scope)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
GLuint GLuint end
GLsizei range
QQmlJSScopesByIdOption
@ Default
@ AssumeComponentsAreBound
#define Q_ASSERT(cond)
Definition qrandom.cpp:47