9void QQmlPreviewBlacklist::blacklist(
const QStringList &paths)
11 for (
const QString &path : paths)
15void QQmlPreviewBlacklist::blacklist(
const QString &path)
18 m_root.insert(path, 0);
21void QQmlPreviewBlacklist::whitelist(
const QStringList &paths)
23 for (
const QString &path : paths)
27void QQmlPreviewBlacklist::whitelist(
const QString &path)
30 m_root.remove(path, 0);
33bool QQmlPreviewBlacklist::isBlacklisted(
const QString &path)
const
35 return path.isEmpty() ?
true : m_root.findPrefix(path, 0) == Node::MatchedLeaf;
38void QQmlPreviewBlacklist::clear()
43QQmlPreviewBlacklist::Node::Node()
47QQmlPreviewBlacklist::Node::Node(
const QQmlPreviewBlacklist::Node &other) :
48 m_mine(other.m_mine), m_isLeaf(other.m_isLeaf)
50 for (
auto it = other.m_next.begin(), end = other.m_next.end(); it != end; ++it)
51 m_next.insert(it.key(),
new Node(**it));
54QQmlPreviewBlacklist::Node::Node(QQmlPreviewBlacklist::Node &&other)
noexcept
56 m_mine.swap(other.m_mine);
57 m_next.swap(other.m_next);
58 m_isLeaf = other.m_isLeaf;
61QQmlPreviewBlacklist::Node::~Node()
66QQmlPreviewBlacklist::Node &QQmlPreviewBlacklist::Node::operator=(
67 const QQmlPreviewBlacklist::Node &other)
70 m_mine = other.m_mine;
71 for (
auto it = other.m_next.begin(), end = other.m_next.end(); it != end; ++it)
72 m_next.insert(it.key(),
new Node(**it));
73 m_isLeaf = other.m_isLeaf;
78QQmlPreviewBlacklist::Node &QQmlPreviewBlacklist::Node::operator=(
79 QQmlPreviewBlacklist::Node &&other)
noexcept
82 m_mine.swap(other.m_mine);
83 m_next.swap(other.m_next);
84 m_isLeaf = other.m_isLeaf;
89void QQmlPreviewBlacklist::Node::split(QString::iterator it, QString::iterator end)
92 existing.resize(end - it - 1);
93 std::copy(it + 1, end, existing.begin());
95 Node *node =
new Node(existing, m_next, m_isLeaf);
97 m_next.insert(*it, node);
98 m_mine.resize(it - m_mine.begin());
102void QQmlPreviewBlacklist::Node::insert(
const QString &path,
int offset)
104 for (
auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
105 if (offset == path.size()) {
111 if (path.at(offset) != *it) {
115 inserted.resize(path.size() - offset - 1);
116 std::copy(path.begin() + offset + 1, path.end(), inserted.begin());
117 m_next.insert(path.at(offset),
new Node(inserted));
124 if (offset == path.size()) {
129 Node *&node = m_next[path.at(offset++)];
130 if (node ==
nullptr) {
132 inserted.resize(path.size() - offset);
133 std::copy(path.begin() + offset, path.end(), inserted.begin());
134 node =
new Node(inserted);
136 node->insert(path, offset);
140void QQmlPreviewBlacklist::Node::remove(
const QString &path,
int offset)
142 for (
auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
143 if (offset == path.size() || path.at(offset) != *it) {
151 if (offset == path.size())
154 Node *&node = m_next[path.at(offset++)];
156 node->remove(path, offset);
159 inserted.resize(path.size() - offset);
160 std::copy(path.begin() + offset, path.end(), inserted.begin());
161 node =
new Node(inserted, {},
false);
165QQmlPreviewBlacklist::Node::PrefixResult QQmlPreviewBlacklist::Node::findPrefix(
166 const QString &path,
int offset)
const
168 if (offset == path.size()) {
169 if (!m_mine.isEmpty())
171 return m_isLeaf ? MatchedLeaf : MatchedBranch;
174 for (
auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
175 if (path.at(offset) != *it)
178 if (++offset == path.size()) {
181 return m_isLeaf ? MatchedLeaf : MatchedBranch;
185 const QChar c = path.at(offset);
186 const auto it = m_next.find(c);
187 if (it != m_next.end()) {
188 const PrefixResult result = (*it)->findPrefix(path, offset + 1);
189 if (result != Unmatched)
194 return m_isLeaf ? MatchedLeaf : MatchedBranch;
199QQmlPreviewBlacklist::Node::Node(
const QString &mine,
200 const QHash<QChar, QQmlPreviewBlacklist::Node *> &next,
202 : m_mine(mine), m_next(next), m_isLeaf(isLeaf)
Combined button and popup list for selecting options.