qtreewidgetitemiterator.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qtreewidgetitemiterator.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5QTreeWidgetItemIterator::QTreeWidgetItemIterator(const QTreeWidgetItemIterator &it)-
6 : d_ptr(new QTreeWidgetItemIteratorPrivate(*(it.d_ptr))),-
7 current(it.current), flags(it.flags)-
8{-
9 QTreeWidgetItemIteratorPrivate * const d = d_func();-
10 ((!(d->m_model)) ? qt_assert("d->m_model",__FILE__,81) : qt_noop());-
11 d->m_model->iterators.append(this);-
12}
never executed: end of block
0
13QTreeWidgetItemIterator::QTreeWidgetItemIterator(QTreeWidget *widget, IteratorFlags flags)-
14: current(0), flags(flags)-
15{-
16 ((!(widget)) ? qt_assert("widget",__FILE__,97) : qt_noop());-
17 QTreeModel *model = qobject_cast<QTreeModel*>(widget->model());-
18 ((!(model)) ? qt_assert("model",__FILE__,99) : qt_noop());-
19 d_ptr.reset(new QTreeWidgetItemIteratorPrivate(this, model));-
20 model->iterators.append(this);-
21 if (!model->rootItem->children.isEmpty()
!model->rootIt...dren.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) current = model->rootItem->child(0);
never executed: current = model->rootItem->child(0);
0
22 if (current
currentDescription
TRUEnever evaluated
FALSEnever evaluated
&& !matchesFlags(current)
!matchesFlags(current)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
23 ++(*
never executed: ++(*this);
this);
never executed: ++(*this);
0
24}
never executed: end of block
0
25QTreeWidgetItemIterator::QTreeWidgetItemIterator(QTreeWidgetItem *item, IteratorFlags flags)-
26 : d_ptr(new QTreeWidgetItemIteratorPrivate(-
27 this, qobject_cast<QTreeModel*>(item->view->model()))),-
28 current(item), flags(flags)-
29{-
30 QTreeWidgetItemIteratorPrivate * const d = d_func();-
31 ((!(item)) ? qt_assert("item",__FILE__,122) : qt_noop());-
32 QTreeModel *model = qobject_cast<QTreeModel*>(item->view->model());-
33 ((!(model)) ? qt_assert("model",__FILE__,124) : qt_noop());-
34 model->iterators.append(this);-
35-
36-
37-
38 QTreeWidgetItem *parent = item;-
39 parent = parent->parent();-
40 QTreeWidgetItem *root = d->m_model->rootItem;-
41 d->m_currentIndex = (parent
parentDescription
TRUEnever evaluated
FALSEnever evaluated
? parent : root)->indexOfChild(item);
0
42-
43 while (parent
parentDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
44 QTreeWidgetItem *itm = parent;-
45 parent = parent->parent();-
46 const int index = (parent
parentDescription
TRUEnever evaluated
FALSEnever evaluated
? parent : root)->indexOfChild(itm);
0
47 d->m_parentIndex.prepend(index);-
48 }
never executed: end of block
0
49-
50 if (current
currentDescription
TRUEnever evaluated
FALSEnever evaluated
&& !matchesFlags(current)
!matchesFlags(current)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
51 ++(*
never executed: ++(*this);
this);
never executed: ++(*this);
0
52}
never executed: end of block
0
53-
54-
55-
56-
57-
58QTreeWidgetItemIterator::~QTreeWidgetItemIterator()-
59{-
60 d_func()->m_model->iterators.removeAll(this);-
61}
never executed: end of block
0
62-
63-
64-
65-
66-
67-
68QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator=(const QTreeWidgetItemIterator &it)-
69{-
70 QTreeWidgetItemIteratorPrivate * const d = d_func();-
71 if (d_func()->m_model != it.d_func()->m_model
d_func()->m_mo...unc()->m_modelDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
72 d_func()->m_model->iterators.removeAll(this);-
73 it.d_func()->m_model->iterators.append(this);-
74 }
never executed: end of block
0
75 current = it.current;-
76 flags = it.flags;-
77 d->operator=(*it.d_func());-
78 return
never executed: return *this;
*this;
never executed: return *this;
0
79}-
80-
81-
82-
83-
84-
85-
86-
87QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator++()-
88{-
89 if (current
currentDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
90 do {-
91 current = d_func()->next(current);-
92 }
never executed: end of block
while (current
currentDescription
TRUEnever evaluated
FALSEnever evaluated
&& !matchesFlags(current)
!matchesFlags(current)Description
TRUEnever evaluated
FALSEnever evaluated
);
0
93 return
never executed: return *this;
*this;
never executed: return *this;
0
94}-
95-
96-
97-
98-
99-
100-
101-
102QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator--()-
103{-
104 if (current
currentDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
105 do {-
106 current = d_func()->previous(current);-
107 }
never executed: end of block
while (current
currentDescription
TRUEnever evaluated
FALSEnever evaluated
&& !matchesFlags(current)
!matchesFlags(current)Description
TRUEnever evaluated
FALSEnever evaluated
);
0
108 return
never executed: return *this;
*this;
never executed: return *this;
0
109}-
110-
111-
112-
113-
114bool QTreeWidgetItemIterator::matchesFlags(const QTreeWidgetItem *item) const-
115{-
116 if (!item
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
117 return
never executed: return false;
false;
never executed: return false;
0
118-
119 if (flags == All
flags == AllDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
120 return
never executed: return true;
true;
never executed: return true;
0
121-
122 {-
123 Qt::ItemFlags itemFlags = item->flags();-
124 if ((
(flags & Selectable)Description
TRUEnever evaluated
FALSEnever evaluated
flags & Selectable)
(flags & Selectable)Description
TRUEnever evaluated
FALSEnever evaluated
&& !(itemFlags & Qt::ItemIsSelectable)
!(itemFlags & ...mIsSelectable)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
125 return
never executed: return false;
false;
never executed: return false;
0
126 if ((
(flags & NotSelectable)Description
TRUEnever evaluated
FALSEnever evaluated
flags & NotSelectable)
(flags & NotSelectable)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(itemFlags & Q...mIsSelectable)Description
TRUEnever evaluated
FALSEnever evaluated
itemFlags & Qt::ItemIsSelectable)
(itemFlags & Q...mIsSelectable)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
127 return
never executed: return false;
false;
never executed: return false;
0
128 if ((
(flags & DragEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
flags & DragEnabled)
(flags & DragEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
&& !(itemFlags & Qt::ItemIsDragEnabled)
!(itemFlags & ...IsDragEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
129 return
never executed: return false;
false;
never executed: return false;
0
130 if ((
(flags & DragDisabled)Description
TRUEnever evaluated
FALSEnever evaluated
flags & DragDisabled)
(flags & DragDisabled)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(itemFlags & Q...IsDragEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
itemFlags & Qt::ItemIsDragEnabled)
(itemFlags & Q...IsDragEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
131 return
never executed: return false;
false;
never executed: return false;
0
132 if ((
(flags & DropEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
flags & DropEnabled)
(flags & DropEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
&& !(itemFlags & Qt::ItemIsDropEnabled)
!(itemFlags & ...IsDropEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
133 return
never executed: return false;
false;
never executed: return false;
0
134 if ((
(flags & DropDisabled)Description
TRUEnever evaluated
FALSEnever evaluated
flags & DropDisabled)
(flags & DropDisabled)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(itemFlags & Q...IsDropEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
itemFlags & Qt::ItemIsDropEnabled)
(itemFlags & Q...IsDropEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
135 return
never executed: return false;
false;
never executed: return false;
0
136 if ((
(flags & Enabled)Description
TRUEnever evaluated
FALSEnever evaluated
flags & Enabled)
(flags & Enabled)Description
TRUEnever evaluated
FALSEnever evaluated
&& !(itemFlags & Qt::ItemIsEnabled)
!(itemFlags & ...ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
137 return
never executed: return false;
false;
never executed: return false;
0
138 if ((
(flags & Disabled)Description
TRUEnever evaluated
FALSEnever evaluated
flags & Disabled)
(flags & Disabled)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(itemFlags & Q...ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
itemFlags & Qt::ItemIsEnabled)
(itemFlags & Q...ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
139 return
never executed: return false;
false;
never executed: return false;
0
140 if ((
(flags & Editable)Description
TRUEnever evaluated
FALSEnever evaluated
flags & Editable)
(flags & Editable)Description
TRUEnever evaluated
FALSEnever evaluated
&& !(itemFlags & Qt::ItemIsEditable)
!(itemFlags & ...temIsEditable)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
141 return
never executed: return false;
false;
never executed: return false;
0
142 if ((
(flags & NotEditable)Description
TRUEnever evaluated
FALSEnever evaluated
flags & NotEditable)
(flags & NotEditable)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(itemFlags & Q...temIsEditable)Description
TRUEnever evaluated
FALSEnever evaluated
itemFlags & Qt::ItemIsEditable)
(itemFlags & Q...temIsEditable)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
143 return
never executed: return false;
false;
never executed: return false;
0
144 }-
145-
146 if (flags & (Checked|NotChecked)
flags & (Checked|NotChecked)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
147-
148 Qt::CheckState check = item->checkState(0);-
149-
150 if ((
(flags & Checked)Description
TRUEnever evaluated
FALSEnever evaluated
flags & Checked)
(flags & Checked)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(check == Qt::Unchecked)Description
TRUEnever evaluated
FALSEnever evaluated
check == Qt::Unchecked)
(check == Qt::Unchecked)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
151 return
never executed: return false;
false;
never executed: return false;
0
152 if ((
(flags & NotChecked)Description
TRUEnever evaluated
FALSEnever evaluated
flags & NotChecked)
(flags & NotChecked)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(check != Qt::Unchecked)Description
TRUEnever evaluated
FALSEnever evaluated
check != Qt::Unchecked)
(check != Qt::Unchecked)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
153 return
never executed: return false;
false;
never executed: return false;
0
154 }
never executed: end of block
0
155-
156 if ((
(flags & HasChildren)Description
TRUEnever evaluated
FALSEnever evaluated
flags & HasChildren)
(flags & HasChildren)Description
TRUEnever evaluated
FALSEnever evaluated
&& !item->childCount()
!item->childCount()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
157 return
never executed: return false;
false;
never executed: return false;
0
158 if ((
(flags & NoChildren)Description
TRUEnever evaluated
FALSEnever evaluated
flags & NoChildren)
(flags & NoChildren)Description
TRUEnever evaluated
FALSEnever evaluated
&& item->childCount()
item->childCount()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
159 return
never executed: return false;
false;
never executed: return false;
0
160-
161 if ((
(flags & Hidden)Description
TRUEnever evaluated
FALSEnever evaluated
flags & Hidden)
(flags & Hidden)Description
TRUEnever evaluated
FALSEnever evaluated
&& !item->isHidden()
!item->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
162 return
never executed: return false;
false;
never executed: return false;
0
163 if ((
(flags & NotHidden)Description
TRUEnever evaluated
FALSEnever evaluated
flags & NotHidden)
(flags & NotHidden)Description
TRUEnever evaluated
FALSEnever evaluated
&& item->isHidden()
item->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
164 return
never executed: return false;
false;
never executed: return false;
0
165-
166 if ((
(flags & Selected)Description
TRUEnever evaluated
FALSEnever evaluated
flags & Selected)
(flags & Selected)Description
TRUEnever evaluated
FALSEnever evaluated
&& !item->isSelected()
!item->isSelected()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
167 return
never executed: return false;
false;
never executed: return false;
0
168 if ((
(flags & Unselected)Description
TRUEnever evaluated
FALSEnever evaluated
flags & Unselected)
(flags & Unselected)Description
TRUEnever evaluated
FALSEnever evaluated
&& item->isSelected()
item->isSelected()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
169 return
never executed: return false;
false;
never executed: return false;
0
170-
171 return
never executed: return true;
true;
never executed: return true;
0
172}-
173-
174-
175-
176-
177QTreeWidgetItem* QTreeWidgetItemIteratorPrivate::nextSibling(const QTreeWidgetItem* item) const-
178{-
179 ((!(item)) ? qt_assert("item",__FILE__,270) : qt_noop());-
180 QTreeWidgetItem *next = 0;-
181 if (QTreeWidgetItem *par = item->parent()
QTreeWidgetIte...item->parent()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
182 int i = par->indexOfChild(const_cast<QTreeWidgetItem*>(item));-
183 next = par->child(i + 1);-
184 }
never executed: end of block
else {
0
185 QTreeWidget *tw = item->treeWidget();-
186 int i = tw->indexOfTopLevelItem(const_cast<QTreeWidgetItem*>(item));-
187 next = tw->topLevelItem(i + 1);-
188 }
never executed: end of block
0
189 return
never executed: return next;
next;
never executed: return next;
0
190}-
191-
192QTreeWidgetItem *QTreeWidgetItemIteratorPrivate::next(const QTreeWidgetItem *current)-
193{-
194 if (!current
!currentDescription
TRUEnever evaluated
FALSEnever evaluated
) return
never executed: return 0;
0;
never executed: return 0;
0
195-
196 QTreeWidgetItem *next = 0;-
197 if (current->childCount()
current->childCount()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
198-
199 m_parentIndex.push(m_currentIndex);-
200 m_currentIndex = 0;-
201 next = current->child(0);-
202 }
never executed: end of block
else {
0
203-
204 QTreeWidgetItem *parent = current->parent();-
205 next = parent
parentDescription
TRUEnever evaluated
FALSEnever evaluated
? parent->child(m_currentIndex + 1)
0
206 : m_model->rootItem->child(m_currentIndex + 1);-
207 while (!next
!nextDescription
TRUEnever evaluated
FALSEnever evaluated
&& parent
parentDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
208-
209 parent = parent->parent();-
210 m_currentIndex = m_parentIndex.pop();-
211 next = parent
parentDescription
TRUEnever evaluated
FALSEnever evaluated
? parent->child(m_currentIndex + 1)
0
212 : m_model->rootItem->child(m_currentIndex + 1);-
213 }
never executed: end of block
0
214 if (next
nextDescription
TRUEnever evaluated
FALSEnever evaluated
) ++(
never executed: ++(m_currentIndex);
m_currentIndex);
never executed: ++(m_currentIndex);
0
215 }
never executed: end of block
0
216 return
never executed: return next;
next;
never executed: return next;
0
217}-
218-
219QTreeWidgetItem *QTreeWidgetItemIteratorPrivate::previous(const QTreeWidgetItem *current)-
220{-
221 if (!current
!currentDescription
TRUEnever evaluated
FALSEnever evaluated
) return
never executed: return 0;
0;
never executed: return 0;
0
222-
223 QTreeWidgetItem *prev = 0;-
224-
225 QTreeWidgetItem *parent = current->parent();-
226 prev = parent
parentDescription
TRUEnever evaluated
FALSEnever evaluated
? parent->child(m_currentIndex - 1)
0
227 : m_model->rootItem->child(m_currentIndex - 1);-
228 if (prev
prevDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
229-
230 --m_currentIndex;-
231 while (prev
prevDescription
TRUEnever evaluated
FALSEnever evaluated
&& prev->childCount()
prev->childCount()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
232 m_parentIndex.push(m_currentIndex);-
233 m_currentIndex = prev->childCount() - 1;-
234 prev = prev->child(m_currentIndex);-
235 }
never executed: end of block
0
236 }
never executed: end of block
else if (parent
parentDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
237 m_currentIndex = m_parentIndex.pop();-
238 prev = parent;-
239 }
never executed: end of block
0
240 return
never executed: return prev;
prev;
never executed: return prev;
0
241}-
242-
243void QTreeWidgetItemIteratorPrivate::ensureValidIterator(const QTreeWidgetItem *itemToBeRemoved)-
244{-
245 QTreeWidgetItemIterator * const q = q_func();-
246 ((!(itemToBeRemoved)) ? qt_assert("itemToBeRemoved",__FILE__,337) : qt_noop());-
247-
248 if (!q->current
!q->currentDescription
TRUEnever evaluated
FALSEnever evaluated
) return;
never executed: return;
0
249 QTreeWidgetItem *nextItem = q->current;-
250-
251-
252 if (nextItem->parent() != itemToBeRemoved->parent()
nextItem->pare...oved->parent()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
253 while (nextItem->parent()
nextItem->parent()Description
TRUEnever evaluated
FALSEnever evaluated
&& nextItem != itemToBeRemoved
nextItem != itemToBeRemovedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
254 nextItem = nextItem->parent();-
255 }
never executed: end of block
0
256 }
never executed: end of block
0
257-
258-
259 if (nextItem == itemToBeRemoved
nextItem == itemToBeRemovedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
260 QTreeWidgetItem *parent = nextItem;-
261 nextItem = 0;-
262 while (parent
parentDescription
TRUEnever evaluated
FALSEnever evaluated
&& !nextItem
!nextItemDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
263 nextItem = nextSibling(parent);-
264 parent = parent->parent();-
265 }
never executed: end of block
0
266 if (nextItem
nextItemDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
267-
268 *q = QTreeWidgetItemIterator(nextItem, q->flags);-
269 if (!(q->matchesFlags(nextItem))
!(q->matchesFlags(nextItem))Description
TRUEnever evaluated
FALSEnever evaluated
) ++(*
never executed: ++(*q);
q);
never executed: ++(*q);
0
270 }
never executed: end of block
else {
0
271-
272 q->current = 0;-
273 m_parentIndex.clear();-
274 return;
never executed: return;
0
275 }-
276 }-
277 if (nextItem->parent() == itemToBeRemoved->parent()
nextItem->pare...oved->parent()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
278-
279-
280-
281 QTreeWidgetItem *par = itemToBeRemoved->parent();-
282 QTreeWidget *tw = itemToBeRemoved->treeWidget();-
283 int indexOfItemToBeRemoved = par
parDescription
TRUEnever evaluated
FALSEnever evaluated
? par->indexOfChild(const_cast<QTreeWidgetItem *>(itemToBeRemoved))
0
284 : tw->indexOfTopLevelItem(const_cast<QTreeWidgetItem *>(itemToBeRemoved));-
285 int indexOfNextItem = par
parDescription
TRUEnever evaluated
FALSEnever evaluated
? par->indexOfChild(nextItem) : tw->indexOfTopLevelItem(nextItem);
0
286-
287 if (indexOfItemToBeRemoved <= indexOfNextItem
indexOfItemToB...ndexOfNextItemDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
288-
289-
290 m_currentIndex--;-
291 }
never executed: end of block
0
292 }
never executed: end of block
0
293}
never executed: end of block
0
294-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9