Newer
Older
* \file
* \author Lars Bilke
* \date 2010-06-23
* \brief Definition of the TreeModelIterator class.
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
*/
#ifndef TREEMODELITERATOR_H
#define TREEMODELITERATOR_H
// ** INCLUDES **
#include <QStack>
class TreeModel;
class TreeItem;
/**
* \brief TreeModelIterator provides a way to iterate over TreeItems in a TreeModel.
* Usage: \code
* TreeModelIterator it(model);
* while(*it)
* {
* QVariant var = (*it)->data(0);
* std::cout << var.toString().toStdString() << std::endl;
* ++it;
* } \endcode
*/
class TreeModelIterator
{
public:
/// \brief Constructor. Provide a tree model to iterate over.
TreeModelIterator(TreeModel* model);
/// \brief Dereferencing the iterator to retrieve the current TreeItem.
/// Returns NULL if the iterator is at the end.
TreeItem* operator* () const;
/// \brief Advance the iterator to the next TreeItem.
TreeModelIterator& operator++ ();
private:
/// \brief The current TreeItem.
TreeItem* _current;
/// \brief The current child index.
int _currentIndex;
/// \brief Stack to save the child indices of the parent TreeItems.
QStack<int> _parentIndex;
/// \brief The model to iterate over.
TreeModel* _model;
/// \brief The traversal implementation.
TreeItem* next(const TreeItem* current);
};
#endif // TREEMODELITERATOR_H