Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
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 | #include <private/qtreewidgetitemiterator_p.h> | - |
41 | #include "qtreewidget.h" | - |
42 | #include "qtreewidget_p.h" | - |
43 | #include "qwidgetitemdata_p.h" | - |
44 | | - |
45 | #ifndef QT_NO_TREEWIDGET | - |
46 | | - |
47 | QT_BEGIN_NAMESPACE | - |
48 | | - |
49 | | - |
50 | | - |
51 | | - |
52 | | - |
53 | | - |
54 | | - |
55 | | - |
56 | | - |
57 | | - |
58 | | - |
59 | | - |
60 | | - |
61 | | - |
62 | | - |
63 | | - |
64 | | - |
65 | | - |
66 | | - |
67 | | - |
68 | | - |
69 | | - |
70 | | - |
71 | | - |
72 | | - |
73 | | - |
74 | | - |
75 | | - |
76 | QTreeWidgetItemIterator::QTreeWidgetItemIterator(const QTreeWidgetItemIterator &it) | - |
77 | : d_ptr(new QTreeWidgetItemIteratorPrivate(*(it.d_ptr))), | - |
78 | current(it.current), flags(it.flags) | - |
79 | { | - |
80 | Q_D(QTreeWidgetItemIterator); | - |
81 | Q_ASSERT(d->m_model); | - |
82 | d->m_model->iterators.append(this); | - |
83 | } never executed: end of block | 0 |
84 | | - |
85 | | - |
86 | | - |
87 | | - |
88 | | - |
89 | | - |
90 | | - |
91 | | - |
92 | | - |
93 | | - |
94 | QTreeWidgetItemIterator::QTreeWidgetItemIterator(QTreeWidget *widget, IteratorFlags flags) | - |
95 | : current(0), flags(flags) | - |
96 | { | - |
97 | Q_ASSERT(widget); | - |
98 | QTreeModel *model = qobject_cast<QTreeModel*>(widget->model()); | - |
99 | Q_ASSERT(model); | - |
100 | d_ptr.reset(new QTreeWidgetItemIteratorPrivate(this, model)); | - |
101 | model->iterators.append(this); | - |
102 | if (!model->rootItem->children.isEmpty()) current = model->rootItem->child(0); never executed: current = model->rootItem->child(0); TRUE | never evaluated | FALSE | never evaluated |
| 0 |
103 | if (current && !matchesFlags(current))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
104 | ++(*this); never executed: ++(*this); | 0 |
105 | } never executed: end of block | 0 |
106 | | - |
107 | | - |
108 | | - |
109 | | - |
110 | | - |
111 | | - |
112 | | - |
113 | | - |
114 | | - |
115 | | - |
116 | QTreeWidgetItemIterator::QTreeWidgetItemIterator(QTreeWidgetItem *item, IteratorFlags flags) | - |
117 | : d_ptr(new QTreeWidgetItemIteratorPrivate( | - |
118 | this, qobject_cast<QTreeModel*>(item->view->model()))), | - |
119 | current(item), flags(flags) | - |
120 | { | - |
121 | Q_D(QTreeWidgetItemIterator); | - |
122 | Q_ASSERT(item); | - |
123 | QTreeModel *model = qobject_cast<QTreeModel*>(item->view->model()); | - |
124 | Q_ASSERT(model); | - |
125 | model->iterators.append(this); | - |
126 | | - |
127 | | - |
128 | | - |
129 | QTreeWidgetItem *parent = item; | - |
130 | parent = parent->parent(); | - |
131 | QTreeWidgetItem *root = d->m_model->rootItem; | - |
132 | d->m_currentIndex = (parent ? parent : root)->indexOfChild(item);TRUE | never evaluated | FALSE | never evaluated |
| 0 |
133 | | - |
134 | while (parent) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
135 | QTreeWidgetItem *itm = parent; | - |
136 | parent = parent->parent(); | - |
137 | const int index = (parent ? parent : root)->indexOfChild(itm);TRUE | never evaluated | FALSE | never evaluated |
| 0 |
138 | d->m_parentIndex.prepend(index); | - |
139 | } never executed: end of block | 0 |
140 | | - |
141 | if (current && !matchesFlags(current))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
142 | ++(*this); never executed: ++(*this); | 0 |
143 | } never executed: end of block | 0 |
144 | | - |
145 | | - |
146 | | - |
147 | | - |
148 | | - |
149 | QTreeWidgetItemIterator::~QTreeWidgetItemIterator() | - |
150 | { | - |
151 | d_func()->m_model->iterators.removeAll(this); | - |
152 | } never executed: end of block | 0 |
153 | | - |
154 | | - |
155 | | - |
156 | | - |
157 | | - |
158 | | - |
159 | QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator=(const QTreeWidgetItemIterator &it) | - |
160 | { | - |
161 | Q_D(QTreeWidgetItemIterator); | - |
162 | if (d_func()->m_model != it.d_func()->m_model) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
163 | d_func()->m_model->iterators.removeAll(this); | - |
164 | it.d_func()->m_model->iterators.append(this); | - |
165 | } never executed: end of block | 0 |
166 | current = it.current; | - |
167 | flags = it.flags; | - |
168 | d->operator=(*it.d_func()); | - |
169 | return *this; never executed: return *this; | 0 |
170 | } | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | | - |
178 | QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator++() | - |
179 | { | - |
180 | if (current)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
181 | do { | - |
182 | current = d_func()->next(current); | - |
183 | } while (current && !matchesFlags(current)); never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
184 | return *this; never executed: return *this; | 0 |
185 | } | - |
186 | | - |
187 | | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | | - |
193 | QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator--() | - |
194 | { | - |
195 | if (current)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
196 | do { | - |
197 | current = d_func()->previous(current); | - |
198 | } while (current && !matchesFlags(current)); never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
199 | return *this; never executed: return *this; | 0 |
200 | } | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | bool QTreeWidgetItemIterator::matchesFlags(const QTreeWidgetItem *item) const | - |
206 | { | - |
207 | if (!item)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
208 | return false; never executed: return false; | 0 |
209 | | - |
210 | if (flags == All)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
211 | return true; never executed: return true; | 0 |
212 | | - |
213 | { | - |
214 | Qt::ItemFlags itemFlags = item->flags(); | - |
215 | if ((flags & Selectable) && !(itemFlags & Qt::ItemIsSelectable))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
216 | return false; never executed: return false; | 0 |
217 | if ((flags & NotSelectable) && (itemFlags & Qt::ItemIsSelectable))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
218 | return false; never executed: return false; | 0 |
219 | if ((flags & DragEnabled) && !(itemFlags & Qt::ItemIsDragEnabled))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
220 | return false; never executed: return false; | 0 |
221 | if ((flags & DragDisabled) && (itemFlags & Qt::ItemIsDragEnabled))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
222 | return false; never executed: return false; | 0 |
223 | if ((flags & DropEnabled) && !(itemFlags & Qt::ItemIsDropEnabled))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
224 | return false; never executed: return false; | 0 |
225 | if ((flags & DropDisabled) && (itemFlags & Qt::ItemIsDropEnabled))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
226 | return false; never executed: return false; | 0 |
227 | if ((flags & Enabled) && !(itemFlags & Qt::ItemIsEnabled))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
228 | return false; never executed: return false; | 0 |
229 | if ((flags & Disabled) && (itemFlags & Qt::ItemIsEnabled))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
230 | return false; never executed: return false; | 0 |
231 | if ((flags & Editable) && !(itemFlags & Qt::ItemIsEditable))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
232 | return false; never executed: return false; | 0 |
233 | if ((flags & NotEditable) && (itemFlags & Qt::ItemIsEditable))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
234 | return false; never executed: return false; | 0 |
235 | } | - |
236 | | - |
237 | if (flags & (Checked|NotChecked)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
238 | | - |
239 | Qt::CheckState check = item->checkState(0); | - |
240 | | - |
241 | if ((flags & Checked) && (check == Qt::Unchecked))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
242 | return false; never executed: return false; | 0 |
243 | if ((flags & NotChecked) && (check != Qt::Unchecked))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
244 | return false; never executed: return false; | 0 |
245 | } never executed: end of block | 0 |
246 | | - |
247 | if ((flags & HasChildren) && !item->childCount())TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
248 | return false; never executed: return false; | 0 |
249 | if ((flags & NoChildren) && item->childCount())TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
250 | return false; never executed: return false; | 0 |
251 | | - |
252 | if ((flags & Hidden) && !item->isHidden())TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
253 | return false; never executed: return false; | 0 |
254 | if ((flags & NotHidden) && item->isHidden())TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
255 | return false; never executed: return false; | 0 |
256 | | - |
257 | if ((flags & Selected) && !item->isSelected())TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
258 | return false; never executed: return false; | 0 |
259 | if ((flags & Unselected) && item->isSelected())TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
260 | return false; never executed: return false; | 0 |
261 | | - |
262 | return true; never executed: return true; | 0 |
263 | } | - |
264 | | - |
265 | | - |
266 | | - |
267 | | - |
268 | QTreeWidgetItem* QTreeWidgetItemIteratorPrivate::nextSibling(const QTreeWidgetItem* item) const | - |
269 | { | - |
270 | Q_ASSERT(item); | - |
271 | QTreeWidgetItem *next = 0; | - |
272 | if (QTreeWidgetItem *par = item->parent()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
273 | int i = par->indexOfChild(const_cast<QTreeWidgetItem*>(item)); | - |
274 | next = par->child(i + 1); | - |
275 | } else { never executed: end of block | 0 |
276 | QTreeWidget *tw = item->treeWidget(); | - |
277 | int i = tw->indexOfTopLevelItem(const_cast<QTreeWidgetItem*>(item)); | - |
278 | next = tw->topLevelItem(i + 1); | - |
279 | } never executed: end of block | 0 |
280 | return next; never executed: return next; | 0 |
281 | } | - |
282 | | - |
283 | QTreeWidgetItem *QTreeWidgetItemIteratorPrivate::next(const QTreeWidgetItem *current) | - |
284 | { | - |
285 | if (!current) return 0; never executed: return 0; TRUE | never evaluated | FALSE | never evaluated |
| 0 |
286 | | - |
287 | QTreeWidgetItem *next = 0; | - |
288 | if (current->childCount()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
289 | | - |
290 | m_parentIndex.push(m_currentIndex); | - |
291 | m_currentIndex = 0; | - |
292 | next = current->child(0); | - |
293 | } else { never executed: end of block | 0 |
294 | | - |
295 | QTreeWidgetItem *parent = current->parent(); | - |
296 | next = parent ? parent->child(m_currentIndex + 1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
297 | : m_model->rootItem->child(m_currentIndex + 1); | - |
298 | while (!next && parent) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
299 | | - |
300 | parent = parent->parent(); | - |
301 | m_currentIndex = m_parentIndex.pop(); | - |
302 | next = parent ? parent->child(m_currentIndex + 1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
303 | : m_model->rootItem->child(m_currentIndex + 1); | - |
304 | } never executed: end of block | 0 |
305 | if (next) ++(m_currentIndex); never executed: ++(m_currentIndex); TRUE | never evaluated | FALSE | never evaluated |
| 0 |
306 | } never executed: end of block | 0 |
307 | return next; never executed: return next; | 0 |
308 | } | - |
309 | | - |
310 | QTreeWidgetItem *QTreeWidgetItemIteratorPrivate::previous(const QTreeWidgetItem *current) | - |
311 | { | - |
312 | if (!current) return 0; never executed: return 0; TRUE | never evaluated | FALSE | never evaluated |
| 0 |
313 | | - |
314 | QTreeWidgetItem *prev = 0; | - |
315 | | - |
316 | QTreeWidgetItem *parent = current->parent(); | - |
317 | prev = parent ? parent->child(m_currentIndex - 1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
318 | : m_model->rootItem->child(m_currentIndex - 1); | - |
319 | if (prev) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
320 | | - |
321 | --m_currentIndex; | - |
322 | while (prev && prev->childCount()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
323 | m_parentIndex.push(m_currentIndex); | - |
324 | m_currentIndex = prev->childCount() - 1; | - |
325 | prev = prev->child(m_currentIndex); | - |
326 | } never executed: end of block | 0 |
327 | } else if (parent) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
328 | m_currentIndex = m_parentIndex.pop(); | - |
329 | prev = parent; | - |
330 | } never executed: end of block | 0 |
331 | return prev; never executed: return prev; | 0 |
332 | } | - |
333 | | - |
334 | void QTreeWidgetItemIteratorPrivate::ensureValidIterator(const QTreeWidgetItem *itemToBeRemoved) | - |
335 | { | - |
336 | Q_Q(QTreeWidgetItemIterator); | - |
337 | Q_ASSERT(itemToBeRemoved); | - |
338 | | - |
339 | if (!q->current) return; never executed: return; TRUE | never evaluated | FALSE | never evaluated |
| 0 |
340 | QTreeWidgetItem *nextItem = q->current; | - |
341 | | - |
342 | | - |
343 | if (nextItem->parent() != itemToBeRemoved->parent()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
344 | while (nextItem->parent() && nextItem != itemToBeRemoved) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
345 | nextItem = nextItem->parent(); | - |
346 | } never executed: end of block | 0 |
347 | } never executed: end of block | 0 |
348 | | - |
349 | | - |
350 | if (nextItem == itemToBeRemoved) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
351 | QTreeWidgetItem *parent = nextItem; | - |
352 | nextItem = 0; | - |
353 | while (parent && !nextItem) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
354 | nextItem = nextSibling(parent); | - |
355 | parent = parent->parent(); | - |
356 | } never executed: end of block | 0 |
357 | if (nextItem) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
358 | | - |
359 | *q = QTreeWidgetItemIterator(nextItem, q->flags); | - |
360 | if (!(q->matchesFlags(nextItem))) ++(*q); never executed: ++(*q); TRUE | never evaluated | FALSE | never evaluated |
| 0 |
361 | } else { never executed: end of block | 0 |
362 | | - |
363 | q->current = 0; | - |
364 | m_parentIndex.clear(); | - |
365 | return; never executed: return; | 0 |
366 | } | - |
367 | } | - |
368 | if (nextItem->parent() == itemToBeRemoved->parent()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
369 | | - |
370 | | - |
371 | | - |
372 | QTreeWidgetItem *par = itemToBeRemoved->parent(); | - |
373 | QTreeWidget *tw = itemToBeRemoved->treeWidget(); | - |
374 | int indexOfItemToBeRemoved = par ? par->indexOfChild(const_cast<QTreeWidgetItem *>(itemToBeRemoved))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
375 | : tw->indexOfTopLevelItem(const_cast<QTreeWidgetItem *>(itemToBeRemoved)); | - |
376 | int indexOfNextItem = par ? par->indexOfChild(nextItem) : tw->indexOfTopLevelItem(nextItem);TRUE | never evaluated | FALSE | never evaluated |
| 0 |
377 | | - |
378 | if (indexOfItemToBeRemoved <= indexOfNextItem) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
379 | | - |
380 | | - |
381 | m_currentIndex--; | - |
382 | } never executed: end of block | 0 |
383 | } never executed: end of block | 0 |
384 | } never executed: end of block | 0 |
385 | | - |
386 | | - |
387 | | - |
388 | | - |
389 | | - |
390 | | - |
391 | | - |
392 | | - |
393 | | - |
394 | | - |
395 | | - |
396 | | - |
397 | | - |
398 | | - |
399 | | - |
400 | | - |
401 | | - |
402 | | - |
403 | | - |
404 | | - |
405 | | - |
406 | | - |
407 | | - |
408 | | - |
409 | | - |
410 | | - |
411 | | - |
412 | | - |
413 | | - |
414 | | - |
415 | | - |
416 | | - |
417 | | - |
418 | | - |
419 | | - |
420 | | - |
421 | | - |
422 | | - |
423 | | - |
424 | | - |
425 | | - |
426 | | - |
427 | | - |
428 | | - |
429 | | - |
430 | | - |
431 | | - |
432 | | - |
433 | | - |
434 | | - |
435 | | - |
436 | | - |
437 | | - |
438 | | - |
439 | | - |
440 | | - |
441 | | - |
442 | | - |
443 | | - |
444 | | - |
445 | | - |
446 | | - |
447 | | - |
448 | | - |
449 | | - |
450 | | - |
451 | | - |
452 | | - |
453 | | - |
454 | | - |
455 | QT_END_NAMESPACE | - |
456 | | - |
457 | #endif // QT_NO_TREEWIDGET | - |
| | |