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.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 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
7
9
10namespace QQmlJS {
11
12void ContextualTypes::setType(const QString &name, const ContextualType &type)
13{
14 if (const QString fileSelector = QQmlJSUtils::fileSelectorFor(type.scope);
15 !fileSelector.isEmpty()) {
16 setFileSelectedType(fileSelector, name, type);
17 return;
18 }
19 auto insertName = [this, &name, &type]() {
20 if (!name.startsWith(u'$')) {
21 if (!m_names.contains(type.scope, name))
22 m_names.insert(type.scope, name);
23 }
24 };
25
26 const auto it = m_types.find(name);
27 if (it == m_types.end()) {
28 m_types.insert(name, type);
29 insertName();
30 return;
31 }
32
33 if (it->m_precedence < type.m_precedence)
34 return;
35 // remove the old name from m_names
36 m_names.remove(it->scope, name);
37 *it = type;
38 insertName();
39}
40
41void ContextualTypes::setFileSelectedType(const QString &fileSelector, const QString &name,
42 const ContextualType &type)
43{
44 auto insertName = [this, &name, &type]() {
45 if (!name.startsWith(u'$')) {
46 if (!m_names.contains(type.scope, name))
47 m_names.insert(type.scope, name);
48 }
49 };
50
51 auto it = m_fileSelectedTypes.find(name);
52 if (it == m_fileSelectedTypes.end()) {
53 insertName();
54 m_fileSelectedTypes.insert(name, { fileSelector, type });
55 return;
56 }
57
58 if (it->type.m_precedence < type.m_precedence)
59 return;
60
61 m_names.remove(type.scope, name);
62 *it = { fileSelector, type };
63 insertName();
64}
65
66FileSelectorInfo ContextualTypes::fileSelectorInfoFor(const QQmlJSScope::ConstPtr &scope) const
67{
68 FileSelectorInfo result;
69 for (auto [it, end] = m_names.equal_range(scope); it != end; ++it) {
70 if (auto mainTypeIt = m_types.find(*it); mainTypeIt != m_types.end())
71 result.mainType = mainTypeIt->scope;
72
73 for (auto [it2, end2] = m_fileSelectedTypes.equal_range(*it); it2 != end2; ++it2) {
74 result.fileSelectedTypes.append(*it2);
75 }
76 }
77 return result;
78}
79} // namespace QQmlJS
80
81QT_END_NAMESPACE
Combined button and popup list for selecting options.
void setType(const QString &name, const ContextualType &type)
void setFileSelectedType(const QString &fileSelector, const QString &name, const ContextualType &type)