Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : */
8 :
9 : #include "findvisitor.hpp"
10 : #include "treeviewmodel.hpp"
11 :
12 0 : FindVisitor::FindVisitor (TreeViewModel * searchResults, QString term) : m_searchResults (searchResults), m_term (std::move (term))
13 : {
14 0 : }
15 :
16 0 : void FindVisitor::visit (ConfigNode & node)
17 : {
18 0 : bool termFound = false;
19 :
20 0 : if (node.getPath ().contains (m_term) || node.getValue ().toString ().contains (m_term))
21 : {
22 0 : termFound = true;
23 : }
24 :
25 0 : if (node.getMetaKeys () && !termFound)
26 : {
27 0 : foreach (ConfigNodePtr metaNode, node.getMetaKeys ()->model ())
28 : {
29 0 : if (metaNode->getName ().contains (m_term) || metaNode->getValue ().toString ().contains (m_term))
30 : {
31 : termFound = true;
32 : break;
33 : }
34 : }
35 : }
36 :
37 0 : if (termFound)
38 : // let the other model delete this node
39 0 : m_searchResults->insertRow (m_searchResults->rowCount (), ConfigNodePtr (&node, &ConfigNode::dontDelete), false);
40 0 : }
41 :
42 0 : void FindVisitor::visit (TreeViewModel * model)
43 : {
44 0 : foreach (ConfigNodePtr node, model->model ())
45 : {
46 0 : node->accept (*this);
47 : }
48 0 : }
|