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
qqmlpreviewblacklist.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 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
5
7
9{
10 if (!path.isEmpty())
11 m_root.insert(path, 0);
12}
13
15{
16 if (!path.isEmpty())
17 m_root.remove(path, 0);
18}
19
21{
22 return path.isEmpty() ? true : m_root.containedPrefixLeaf(path, 0) > 0;
23}
24
26{
27 m_root = Node();
28}
29
30QQmlPreviewBlacklist::Node::Node()
31{
32}
33
34QQmlPreviewBlacklist::Node::Node(const QQmlPreviewBlacklist::Node &other) :
35 m_mine(other.m_mine), m_isLeaf(other.m_isLeaf)
36{
37 for (auto it = other.m_next.begin(), end = other.m_next.end(); it != end; ++it)
38 m_next.insert(it.key(), new Node(**it));
39}
40
41QQmlPreviewBlacklist::Node::Node(QQmlPreviewBlacklist::Node &&other) noexcept
42{
43 m_mine.swap(other.m_mine);
44 m_next.swap(other.m_next);
45 m_isLeaf = other.m_isLeaf;
46}
47
48QQmlPreviewBlacklist::Node::~Node()
49{
50 qDeleteAll(m_next);
51}
52
53QQmlPreviewBlacklist::Node &QQmlPreviewBlacklist::Node::operator=(
54 const QQmlPreviewBlacklist::Node &other)
55{
56 if (&other != this) {
57 m_mine = other.m_mine;
58 for (auto it = other.m_next.begin(), end = other.m_next.end(); it != end; ++it)
59 m_next.insert(it.key(), new Node(**it));
60 m_isLeaf = other.m_isLeaf;
61 }
62 return *this;
63}
64
65QQmlPreviewBlacklist::Node &QQmlPreviewBlacklist::Node::operator=(
66 QQmlPreviewBlacklist::Node &&other) noexcept
67{
68 if (&other != this) {
69 m_mine.swap(other.m_mine);
70 m_next.swap(other.m_next);
71 m_isLeaf = other.m_isLeaf;
72 }
73 return *this;
74}
75
76void QQmlPreviewBlacklist::Node::split(QString::iterator it, QString::iterator end)
77{
78 QString existing;
79 existing.resize(end - it - 1);
80 std::copy(it + 1, end, existing.begin());
81
82 Node *node = new Node(existing, m_next, m_isLeaf);
83 m_next.clear();
84 m_next.insert(*it, node);
85 m_mine.resize(it - m_mine.begin());
86 m_isLeaf = false;
87}
88
89void QQmlPreviewBlacklist::Node::insert(const QString &path, int offset)
90{
91 for (auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
92 if (offset == path.size()) {
93 split(it, end);
94 m_isLeaf = true;
95 return;
96 }
97
98 if (path.at(offset) != *it) {
99 split(it, end);
100
101 QString inserted;
102 inserted.resize(path.size() - offset - 1);
103 std::copy(path.begin() + offset + 1, path.end(), inserted.begin());
104 m_next.insert(path.at(offset), new Node(inserted));
105 return;
106 }
107
108 ++offset;
109 }
110
111 if (offset == path.size()) {
112 m_isLeaf = true;
113 return;
114 }
115
116 Node *&node = m_next[path.at(offset++)];
117 if (node == nullptr) {
118 QString inserted;
119 inserted.resize(path.size() - offset);
120 std::copy(path.begin() + offset, path.end(), inserted.begin());
121 node = new Node(inserted);
122 } else {
123 node->insert(path, offset);
124 }
125}
126
127void QQmlPreviewBlacklist::Node::remove(const QString &path, int offset)
128{
129 for (auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
130 if (offset == path.size() || path.at(offset) != *it) {
131 split(it, end);
132 return;
133 }
134 ++offset;
135 }
136
137 m_isLeaf = false;
138 if (offset == path.size())
139 return;
140
141 auto it = m_next.constFind(path.at(offset));
142 if (it != m_next.cend())
143 (*it)->remove(path, ++offset);
144}
145
146int QQmlPreviewBlacklist::Node::containedPrefixLeaf(const QString &path, int offset) const
147{
148 if (offset == path.size())
149 return (m_mine.isEmpty() && m_isLeaf) ? offset : -1;
150
151 for (auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
152 if (path.at(offset) != *it)
153 return -1;
154
155 if (++offset == path.size())
156 return (++it == end && m_isLeaf) ? offset : -1;
157 }
158
159 const QChar c = path.at(offset);
160 if (m_isLeaf && c == '/')
161 return offset;
162
163 auto it = m_next.find(c);
164 if (it == m_next.end())
165 return -1;
166
167 return (*it)->containedPrefixLeaf(path, ++offset);
168}
169
170QQmlPreviewBlacklist::Node::Node(const QString &mine,
171 const QHash<QChar, QQmlPreviewBlacklist::Node *> &next,
172 bool isLeaf)
173 : m_mine(mine), m_next(next), m_isLeaf(isLeaf)
174{
175}
176
Definition lalr.h:136
\inmodule QtCore
void blacklist(const QString &path)
void whitelist(const QString &path)
bool isBlacklisted(const QString &path) const
iterator begin()
Definition qset.h:136
iterator end()
Definition qset.h:140
const_iterator cend() const noexcept
Definition qset.h:142
const_iterator constFind(const T &value) const
Definition qset.h:161
iterator find(const T &value)
Definition qset.h:159
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
void resize(qsizetype size)
Sets the size of the string to size characters.
Definition qstring.cpp:2668
qDeleteAll(list.begin(), list.end())
QSet< QString >::iterator it
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
GLuint GLuint end
GLenum GLuint GLintptr offset
const GLubyte * c
GLsizei const GLchar *const * path
static void split(QT_FT_Vector *b)
QSharedPointer< T > other(t)
[5]