1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QTREEWIDGETITEMITERATOR_H |
5 | #define QTREEWIDGETITEMITERATOR_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtCore/qscopedpointer.h> |
9 | |
10 | QT_REQUIRE_CONFIG(treewidget); |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | class QTreeWidget; |
15 | class QTreeWidgetItem; |
16 | class QTreeModel; |
17 | |
18 | class QTreeWidgetItemIteratorPrivate; |
19 | class Q_WIDGETS_EXPORT QTreeWidgetItemIterator |
20 | { |
21 | friend class QTreeModel; |
22 | |
23 | public: |
24 | enum IteratorFlag { |
25 | All = 0x00000000, |
26 | Hidden = 0x00000001, |
27 | NotHidden = 0x00000002, |
28 | Selected = 0x00000004, |
29 | Unselected = 0x00000008, |
30 | Selectable = 0x00000010, |
31 | NotSelectable = 0x00000020, |
32 | DragEnabled = 0x00000040, |
33 | DragDisabled = 0x00000080, |
34 | DropEnabled = 0x00000100, |
35 | DropDisabled = 0x00000200, |
36 | HasChildren = 0x00000400, |
37 | NoChildren = 0x00000800, |
38 | Checked = 0x00001000, |
39 | NotChecked = 0x00002000, |
40 | Enabled = 0x00004000, |
41 | Disabled = 0x00008000, |
42 | Editable = 0x00010000, |
43 | NotEditable = 0x00020000, |
44 | UserFlag = 0x01000000 // The first flag that can be used by the user. |
45 | }; |
46 | Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag) |
47 | |
48 | QTreeWidgetItemIterator(const QTreeWidgetItemIterator &it); |
49 | explicit QTreeWidgetItemIterator(QTreeWidget *widget, IteratorFlags flags = All); |
50 | explicit QTreeWidgetItemIterator(QTreeWidgetItem *item, IteratorFlags flags = All); |
51 | ~QTreeWidgetItemIterator(); |
52 | |
53 | QTreeWidgetItemIterator &operator=(const QTreeWidgetItemIterator &it); |
54 | |
55 | QTreeWidgetItemIterator &operator++(); |
56 | inline const QTreeWidgetItemIterator operator++(int); |
57 | inline QTreeWidgetItemIterator &operator+=(int n); |
58 | |
59 | QTreeWidgetItemIterator &operator--(); |
60 | inline const QTreeWidgetItemIterator operator--(int); |
61 | inline QTreeWidgetItemIterator &operator-=(int n); |
62 | |
63 | inline QTreeWidgetItem *operator*() const; |
64 | |
65 | private: |
66 | bool matchesFlags(const QTreeWidgetItem *item) const; |
67 | QScopedPointer<QTreeWidgetItemIteratorPrivate> d_ptr; |
68 | QTreeWidgetItem *current; |
69 | IteratorFlags flags; |
70 | Q_DECLARE_PRIVATE(QTreeWidgetItemIterator) |
71 | }; |
72 | |
73 | inline const QTreeWidgetItemIterator QTreeWidgetItemIterator::operator++(int) |
74 | { |
75 | QTreeWidgetItemIterator it = *this; |
76 | ++(*this); |
77 | return it; |
78 | } |
79 | |
80 | inline const QTreeWidgetItemIterator QTreeWidgetItemIterator::operator--(int) |
81 | { |
82 | QTreeWidgetItemIterator it = *this; |
83 | --(*this); |
84 | return it; |
85 | } |
86 | |
87 | inline QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator+=(int n) |
88 | { |
89 | if (n < 0) |
90 | return (*this) -= (-n); |
91 | while (current && n--) |
92 | ++(*this); |
93 | return *this; |
94 | } |
95 | |
96 | inline QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator-=(int n) |
97 | { |
98 | if (n < 0) |
99 | return (*this) += (-n); |
100 | while (current && n--) |
101 | --(*this); |
102 | return *this; |
103 | } |
104 | |
105 | inline QTreeWidgetItem *QTreeWidgetItemIterator::operator*() const |
106 | { |
107 | return current; |
108 | } |
109 | |
110 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTreeWidgetItemIterator::IteratorFlags) |
111 | |
112 | QT_END_NAMESPACE |
113 | #endif // QTREEWIDGETITEMITERATOR_H |
114 | |