1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QTREEWIDGETITEMITERATOR_H
41#define QTREEWIDGETITEMITERATOR_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtCore/qscopedpointer.h>
45
46QT_REQUIRE_CONFIG(treewidget);
47
48QT_BEGIN_NAMESPACE
49
50class QTreeWidget;
51class QTreeWidgetItem;
52class QTreeModel;
53
54class QTreeWidgetItemIteratorPrivate;
55class Q_WIDGETS_EXPORT QTreeWidgetItemIterator
56{
57 friend class QTreeModel;
58
59public:
60 enum IteratorFlag {
61 All = 0x00000000,
62 Hidden = 0x00000001,
63 NotHidden = 0x00000002,
64 Selected = 0x00000004,
65 Unselected = 0x00000008,
66 Selectable = 0x00000010,
67 NotSelectable = 0x00000020,
68 DragEnabled = 0x00000040,
69 DragDisabled = 0x00000080,
70 DropEnabled = 0x00000100,
71 DropDisabled = 0x00000200,
72 HasChildren = 0x00000400,
73 NoChildren = 0x00000800,
74 Checked = 0x00001000,
75 NotChecked = 0x00002000,
76 Enabled = 0x00004000,
77 Disabled = 0x00008000,
78 Editable = 0x00010000,
79 NotEditable = 0x00020000,
80 UserFlag = 0x01000000 // The first flag that can be used by the user.
81 };
82 Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)
83
84 QTreeWidgetItemIterator(const QTreeWidgetItemIterator &it);
85 explicit QTreeWidgetItemIterator(QTreeWidget *widget, IteratorFlags flags = All);
86 explicit QTreeWidgetItemIterator(QTreeWidgetItem *item, IteratorFlags flags = All);
87 ~QTreeWidgetItemIterator();
88
89 QTreeWidgetItemIterator &operator=(const QTreeWidgetItemIterator &it);
90
91 QTreeWidgetItemIterator &operator++();
92 inline const QTreeWidgetItemIterator operator++(int);
93 inline QTreeWidgetItemIterator &operator+=(int n);
94
95 QTreeWidgetItemIterator &operator--();
96 inline const QTreeWidgetItemIterator operator--(int);
97 inline QTreeWidgetItemIterator &operator-=(int n);
98
99 inline QTreeWidgetItem *operator*() const;
100
101private:
102 bool matchesFlags(const QTreeWidgetItem *item) const;
103 QScopedPointer<QTreeWidgetItemIteratorPrivate> d_ptr;
104 QTreeWidgetItem *current;
105 IteratorFlags flags;
106 Q_DECLARE_PRIVATE(QTreeWidgetItemIterator)
107};
108
109inline const QTreeWidgetItemIterator QTreeWidgetItemIterator::operator++(int)
110{
111 QTreeWidgetItemIterator it = *this;
112 ++(*this);
113 return it;
114}
115
116inline const QTreeWidgetItemIterator QTreeWidgetItemIterator::operator--(int)
117{
118 QTreeWidgetItemIterator it = *this;
119 --(*this);
120 return it;
121}
122
123inline QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator+=(int n)
124{
125 if (n < 0)
126 return (*this) -= (-n);
127 while (current && n--)
128 ++(*this);
129 return *this;
130}
131
132inline QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator-=(int n)
133{
134 if (n < 0)
135 return (*this) += (-n);
136 while (current && n--)
137 --(*this);
138 return *this;
139}
140
141inline QTreeWidgetItem *QTreeWidgetItemIterator::operator*() const
142{
143 return current;
144}
145
146Q_DECLARE_OPERATORS_FOR_FLAGS(QTreeWidgetItemIterator::IteratorFlags)
147
148QT_END_NAMESPACE
149#endif // QTREEWIDGETITEMITERATOR_H
150

source code of qtbase/src/widgets/itemviews/qtreewidgetitemiterator.h