1
/* This file is part of the KDE project.
3
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5
This library is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 2.1 or 3 of the License.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with this library. If not, see <http://www.gnu.org/licenses/>.
31
* Depth-first iterator for QObject tree
33
class DepthFirstConstIterator
36
DepthFirstConstIterator();
37
DepthFirstConstIterator(const QObject& root);
39
DepthFirstConstIterator& operator++();
41
inline bool operator==(const DepthFirstConstIterator& other) const
42
{ return other.m_pointee == m_pointee; }
44
inline bool operator!=(const DepthFirstConstIterator& other) const
45
{ return other.m_pointee != m_pointee; }
47
inline const QObject* operator->() const { return m_pointee; }
48
inline const QObject& operator*() const { return *m_pointee; }
54
const QObject* m_pointee;
55
QStack<int> m_history;
59
* Ancestor iterator for QObject tree
61
class AncestorConstIterator
64
AncestorConstIterator();
65
AncestorConstIterator(const QObject& root);
67
inline AncestorConstIterator& operator++()
68
{ m_ancestors.pop(); return *this; }
70
inline bool operator==(const AncestorConstIterator& other) const
71
{ return other.m_ancestors == m_ancestors; }
73
inline bool operator!=(const AncestorConstIterator& other) const
74
{ return other.m_ancestors != m_ancestors; }
76
inline const QObject* operator->() const { return m_ancestors.top(); }
77
inline const QObject& operator*() const { return *m_ancestors.top(); }
80
QStack<const QObject*> m_ancestors;
85
* Generic algorithm for visiting nodes in an object tree. Nodes in the
86
* tree are visited in a const context, therefore they are not modified
89
* Visitor must provide functions with the following signatures:
91
* Called before visit begins
94
* Called on each node visited
95
* void visitNode(const QObject& object)
97
* Called when visit is complete
98
* void visitComplete()
100
template <class Iterator, class Visitor>
101
void visit(Iterator begin, Iterator end, Visitor& visitor)
103
visitor.visitPrepare();
105
for ( ; begin != end; ++begin)
106
visitor.visitNode(*begin);
108
visitor.visitComplete();
111
} // namespace ObjectTree
115
#endif // OBJECTTREE_H