source: trunk/src/3rdparty/phonon/mmf/objecttree.cpp

Last change on this file was 561, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.1 sources.

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1/* This file is part of the KDE project.
2
3Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
5This library is free software: you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation, either version 2.1 or 3 of the License.
8
9This library is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU Lesser General Public License for more details.
13
14You should have received a copy of the GNU Lesser General Public License
15along with this library. If not, see <http://www.gnu.org/licenses/>.
16
17*/
18
19#include <QTextStream>
20#include <QWidget>
21#include "objecttree.h"
22
23QT_BEGIN_NAMESPACE
24
25namespace ObjectTree
26{
27
28DepthFirstConstIterator::DepthFirstConstIterator()
29 : m_pointee(0)
30{
31
32}
33
34DepthFirstConstIterator::DepthFirstConstIterator
35 (const QObject& root)
36 : m_pointee(&root)
37{
38
39}
40
41DepthFirstConstIterator&
42 DepthFirstConstIterator::operator++()
43{
44 const QObjectList& children = m_pointee->children();
45
46 if (children.count() == 0) {
47 backtrack();
48 }
49 else {
50 m_history.push(0);
51 m_pointee = children.first();
52 }
53
54 return *this;
55}
56
57void DepthFirstConstIterator::backtrack()
58{
59 if (m_history.count()) {
60 const int index = m_history.top();
61 m_history.pop();
62
63 const QObjectList& siblings = m_pointee->parent()->children();
64 if (siblings.count() > index + 1) {
65 m_history.push(index + 1);
66 m_pointee = siblings[index + 1];
67 }
68 else {
69 m_pointee = m_pointee->parent();
70 backtrack();
71 }
72 }
73 else {
74 // Reached end of search
75 m_pointee = 0;
76 }
77}
78
79
80
81AncestorConstIterator::AncestorConstIterator()
82{
83
84}
85
86AncestorConstIterator::AncestorConstIterator(const QObject& leaf)
87{
88 m_ancestors.push(&leaf);
89 QObject* ancestor = leaf.parent();
90 while(ancestor)
91 {
92 m_ancestors.push(ancestor);
93 ancestor = ancestor->parent();
94 }
95}
96
97} // namespace ObjectTree
98
99QT_END_NAMESPACE
100
Note: See TracBrowser for help on using the repository browser.