9void QQmlPreviewBlacklist::blacklist(
const QString &path)
12 m_root.insert(path, 0);
15void QQmlPreviewBlacklist::whitelist(
const QString &path)
18 m_root.remove(path, 0);
21bool QQmlPreviewBlacklist::isBlacklisted(
const QString &path)
const
23 return path.isEmpty() ?
true : m_root.findPrefix(path, 0) == Node::MatchedLeaf;
26void QQmlPreviewBlacklist::clear()
31QQmlPreviewBlacklist::Node::Node()
35QQmlPreviewBlacklist::Node::Node(
const QQmlPreviewBlacklist::Node &other) :
36 m_mine(other.m_mine), m_isLeaf(other.m_isLeaf)
38 for (
auto it = other.m_next.begin(), end = other.m_next.end(); it != end; ++it)
39 m_next.insert(it.key(),
new Node(**it));
42QQmlPreviewBlacklist::Node::Node(QQmlPreviewBlacklist::Node &&other)
noexcept
44 m_mine.swap(other.m_mine);
45 m_next.swap(other.m_next);
46 m_isLeaf = other.m_isLeaf;
49QQmlPreviewBlacklist::Node::~Node()
54QQmlPreviewBlacklist::Node &QQmlPreviewBlacklist::Node::operator=(
55 const QQmlPreviewBlacklist::Node &other)
58 m_mine = other.m_mine;
59 for (
auto it = other.m_next.begin(), end = other.m_next.end(); it != end; ++it)
60 m_next.insert(it.key(),
new Node(**it));
61 m_isLeaf = other.m_isLeaf;
66QQmlPreviewBlacklist::Node &QQmlPreviewBlacklist::Node::operator=(
67 QQmlPreviewBlacklist::Node &&other)
noexcept
70 m_mine.swap(other.m_mine);
71 m_next.swap(other.m_next);
72 m_isLeaf = other.m_isLeaf;
77void QQmlPreviewBlacklist::Node::split(QString::iterator it, QString::iterator end)
80 existing.resize(end - it - 1);
81 std::copy(it + 1, end, existing.begin());
83 Node *node =
new Node(existing, m_next, m_isLeaf);
85 m_next.insert(*it, node);
86 m_mine.resize(it - m_mine.begin());
90void QQmlPreviewBlacklist::Node::insert(
const QString &path,
int offset)
92 for (
auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
93 if (offset == path.size()) {
99 if (path.at(offset) != *it) {
103 inserted.resize(path.size() - offset - 1);
104 std::copy(path.begin() + offset + 1, path.end(), inserted.begin());
105 m_next.insert(path.at(offset),
new Node(inserted));
112 if (offset == path.size()) {
117 Node *&node = m_next[path.at(offset++)];
118 if (node ==
nullptr) {
120 inserted.resize(path.size() - offset);
121 std::copy(path.begin() + offset, path.end(), inserted.begin());
122 node =
new Node(inserted);
124 node->insert(path, offset);
128void QQmlPreviewBlacklist::Node::remove(
const QString &path,
int offset)
130 for (
auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
131 if (offset == path.size() || path.at(offset) != *it) {
139 if (offset == path.size())
142 Node *&node = m_next[path.at(offset++)];
144 node->remove(path, offset);
147 inserted.resize(path.size() - offset);
148 std::copy(path.begin() + offset, path.end(), inserted.begin());
149 node =
new Node(inserted, {},
false);
153QQmlPreviewBlacklist::Node::PrefixResult QQmlPreviewBlacklist::Node::findPrefix(
154 const QString &path,
int offset)
const
156 if (offset == path.size()) {
157 if (!m_mine.isEmpty())
159 return m_isLeaf ? MatchedLeaf : MatchedBranch;
162 for (
auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
163 if (path.at(offset) != *it)
166 if (++offset == path.size()) {
169 return m_isLeaf ? MatchedLeaf : MatchedBranch;
173 const QChar c = path.at(offset);
174 const auto it = m_next.find(c);
175 if (it != m_next.end()) {
176 const PrefixResult result = (*it)->findPrefix(path, offset + 1);
177 if (result != Unmatched)
182 return m_isLeaf ? MatchedLeaf : MatchedBranch;
187QQmlPreviewBlacklist::Node::Node(
const QString &mine,
188 const QHash<QChar, QQmlPreviewBlacklist::Node *> &next,
190 : m_mine(mine), m_next(next), m_isLeaf(isLeaf)
Combined button and popup list for selecting options.