itemviews/qtreewidgetitemiterator.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
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 qt_noop(); -
11 d->m_model->iterators.append(this); -
12}
executed: }
Execution Count:56
56
13QTreeWidgetItemIterator::QTreeWidgetItemIterator(QTreeWidget *widget, IteratorFlags flags) -
14: current(0), flags(flags) -
15{ -
16 qt_noop(); -
17 QTreeModel *model = qobject_cast<QTreeModel*>(widget->model()); -
18 qt_noop(); -
19 d_ptr.reset(new QTreeWidgetItemIteratorPrivate(this, model)); -
20 model->iterators.append(this); -
21 if (!model->rootItem->children.isEmpty()) current = model->rootItem->children.first();
executed: current = model->rootItem->children.first();
Execution Count:97
evaluated: !model->rootItem->children.isEmpty()
TRUEFALSE
yes
Evaluation Count:97
yes
Evaluation Count:1
1-97
22 if (current && !matchesFlags(current))
evaluated: current
TRUEFALSE
yes
Evaluation Count:97
yes
Evaluation Count:1
evaluated: !matchesFlags(current)
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:82
1-97
23 ++(*this);
executed: ++(*this);
Execution Count:15
15
24}
executed: }
Execution Count:98
98
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 qt_noop(); -
32 QTreeModel *model = qobject_cast<QTreeModel*>(item->view->model()); -
33 qt_noop(); -
34 model->iterators.append(this); -
35 -
36 -
37 -
38 QTreeWidgetItem *parent = item; -
39 parent = parent->parent(); -
40 QList<QTreeWidgetItem *> children = parent ? parent->children : d->m_model->rootItem->children;
evaluated: parent
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:20
18-20
41 d->m_currentIndex = children.indexOf(item); -
42 -
43 while (parent) {
evaluated: parent
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:38
18-38
44 QTreeWidgetItem *itm = parent; -
45 parent = parent->parent(); -
46 QList<QTreeWidgetItem *> children = parent ? parent->children : d->m_model->rootItem->children;
partially evaluated: parent
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
47 int index = children.indexOf(itm); -
48 d->m_parentIndex.prepend(index); -
49 }
executed: }
Execution Count:18
18
50 -
51 if (current && !matchesFlags(current))
partially evaluated: current
TRUEFALSE
yes
Evaluation Count:38
no
Evaluation Count:0
evaluated: !matchesFlags(current)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:37
0-38
52 ++(*this);
executed: ++(*this);
Execution Count:1
1
53}
executed: }
Execution Count:38
38
54 -
55 -
56 -
57 -
58 -
59QTreeWidgetItemIterator::~QTreeWidgetItemIterator() -
60{ -
61 d_func()->m_model->iterators.removeAll(this); -
62}
executed: }
Execution Count:192
192
63 -
64 -
65 -
66 -
67 -
68 -
69QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator=(const QTreeWidgetItemIterator &it) -
70{ -
71 QTreeWidgetItemIteratorPrivate * const d = d_func(); -
72 if (d_func()->m_model != it.d_func()->m_model) {
partially evaluated: d_func()->m_model != it.d_func()->m_model
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:32
0-32
73 d_func()->m_model->iterators.removeAll(this); -
74 it.d_func()->m_model->iterators.append(this); -
75 }
never executed: }
0
76 current = it.current; -
77 flags = it.flags; -
78 d->operator=(*it.d_func()); -
79 return *this;
executed: return *this;
Execution Count:32
32
80} -
81 -
82 -
83 -
84 -
85 -
86 -
87 -
88QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator++() -
89{ -
90 if (current)
evaluated: current
TRUEFALSE
yes
Evaluation Count:2257
yes
Evaluation Count:7
7-2257
91 do { -
92 current = d_func()->next(current); -
93 } while (current && !matchesFlags(current));
executed: }
Execution Count:7376
evaluated: current
TRUEFALSE
yes
Evaluation Count:7347
yes
Evaluation Count:29
evaluated: !matchesFlags(current)
TRUEFALSE
yes
Evaluation Count:5119
yes
Evaluation Count:2228
29-7376
94 return *this;
executed: return *this;
Execution Count:2264
2264
95} -
96 -
97 -
98 -
99 -
100 -
101 -
102 -
103QTreeWidgetItemIterator &QTreeWidgetItemIterator::operator--() -
104{ -
105 if (current)
partially evaluated: current
TRUEFALSE
yes
Evaluation Count:13
no
Evaluation Count:0
0-13
106 do { -
107 current = d_func()->previous(current); -
108 } while (current && !matchesFlags(current));
executed: }
Execution Count:13
evaluated: current
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:1
partially evaluated: !matchesFlags(current)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-13
109 return *this;
executed: return *this;
Execution Count:13
13
110} -
111 -
112 -
113 -
114 -
115bool QTreeWidgetItemIterator::matchesFlags(const QTreeWidgetItem *item) const -
116{ -
117 if (!item)
partially evaluated: !item
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7526
0-7526
118 return false;
never executed: return false;
0
119 -
120 if (flags == All)
evaluated: flags == All
TRUEFALSE
yes
Evaluation Count:1097
yes
Evaluation Count:6429
1097-6429
121 return true;
executed: return true;
Execution Count:1097
1097
122 -
123 { -
124 Qt::ItemFlags itemFlags = item->flags(); -
125 if ((flags & Selectable) && !(itemFlags & Qt::ItemIsSelectable))
evaluated: (flags & Selectable)
TRUEFALSE
yes
Evaluation Count:612
yes
Evaluation Count:5817
evaluated: !(itemFlags & Qt::ItemIsSelectable)
TRUEFALSE
yes
Evaluation Count:324
yes
Evaluation Count:288
288-5817
126 return false;
executed: return false;
Execution Count:324
324
127 if ((flags & NotSelectable) && (itemFlags & Qt::ItemIsSelectable))
evaluated: (flags & NotSelectable)
TRUEFALSE
yes
Evaluation Count:144
yes
Evaluation Count:5961
partially evaluated: (itemFlags & Qt::ItemIsSelectable)
TRUEFALSE
yes
Evaluation Count:144
no
Evaluation Count:0
0-5961
128 return false;
executed: return false;
Execution Count:144
144
129 if ((flags & DragEnabled) && !(itemFlags & Qt::ItemIsDragEnabled))
evaluated: (flags & DragEnabled)
TRUEFALSE
yes
Evaluation Count:612
yes
Evaluation Count:5349
evaluated: !(itemFlags & Qt::ItemIsDragEnabled)
TRUEFALSE
yes
Evaluation Count:324
yes
Evaluation Count:288
288-5349
130 return false;
executed: return false;
Execution Count:324
324
131 if ((flags & DragDisabled) && (itemFlags & Qt::ItemIsDragEnabled))
evaluated: (flags & DragDisabled)
TRUEFALSE
yes
Evaluation Count:450
yes
Evaluation Count:5187
evaluated: (itemFlags & Qt::ItemIsDragEnabled)
TRUEFALSE
yes
Evaluation Count:288
yes
Evaluation Count:162
162-5187
132 return false;
executed: return false;
Execution Count:288
288
133 if ((flags & DropEnabled) && !(itemFlags & Qt::ItemIsDropEnabled))
evaluated: (flags & DropEnabled)
TRUEFALSE
yes
Evaluation Count:612
yes
Evaluation Count:4737
evaluated: !(itemFlags & Qt::ItemIsDropEnabled)
TRUEFALSE
yes
Evaluation Count:324
yes
Evaluation Count:288
288-4737
134 return false;
executed: return false;
Execution Count:324
324
135 if ((flags & DropDisabled) && (itemFlags & Qt::ItemIsDropEnabled))
evaluated: (flags & DropDisabled)
TRUEFALSE
yes
Evaluation Count:144
yes
Evaluation Count:4881
partially evaluated: (itemFlags & Qt::ItemIsDropEnabled)
TRUEFALSE
yes
Evaluation Count:144
no
Evaluation Count:0
0-4881
136 return false;
executed: return false;
Execution Count:144
144
137 if ((flags & Enabled) && !(itemFlags & Qt::ItemIsEnabled))
evaluated: (flags & Enabled)
TRUEFALSE
yes
Evaluation Count:306
yes
Evaluation Count:4575
evaluated: !(itemFlags & Qt::ItemIsEnabled)
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:272
34-4575
138 return false;
executed: return false;
Execution Count:34
34
139 if ((flags & Disabled) && (itemFlags & Qt::ItemIsEnabled))
evaluated: (flags & Disabled)
TRUEFALSE
yes
Evaluation Count:578
yes
Evaluation Count:4269
evaluated: (itemFlags & Qt::ItemIsEnabled)
TRUEFALSE
yes
Evaluation Count:544
yes
Evaluation Count:34
34-4269
140 return false;
executed: return false;
Execution Count:544
544
141 if ((flags & Editable) && !(itemFlags & Qt::ItemIsEditable))
evaluated: (flags & Editable)
TRUEFALSE
yes
Evaluation Count:612
yes
Evaluation Count:3691
evaluated: !(itemFlags & Qt::ItemIsEditable)
TRUEFALSE
yes
Evaluation Count:576
yes
Evaluation Count:36
36-3691
142 return false;
executed: return false;
Execution Count:576
576
143 if ((flags & NotEditable) && (itemFlags & Qt::ItemIsEditable))
evaluated: (flags & NotEditable)
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:3709
partially evaluated: (itemFlags & Qt::ItemIsEditable)
TRUEFALSE
yes
Evaluation Count:18
no
Evaluation Count:0
0-3709
144 return false;
executed: return false;
Execution Count:18
18
145 } -
146 -
147 if (flags & (Checked|NotChecked)) {
evaluated: flags & (Checked|NotChecked)
TRUEFALSE
yes
Evaluation Count:918
yes
Evaluation Count:2791
918-2791
148 -
149 Qt::CheckState check = item->checkState(0); -
150 -
151 if ((flags & Checked) && (check == Qt::Unchecked))
evaluated: (flags & Checked)
TRUEFALSE
yes
Evaluation Count:612
yes
Evaluation Count:306
evaluated: (check == Qt::Unchecked)
TRUEFALSE
yes
Evaluation Count:540
yes
Evaluation Count:72
72-612
152 return false;
executed: return false;
Execution Count:540
540
153 if ((flags & NotChecked) && (check != Qt::Unchecked))
evaluated: (flags & NotChecked)
TRUEFALSE
yes
Evaluation Count:342
yes
Evaluation Count:36
evaluated: (check != Qt::Unchecked)
TRUEFALSE
yes
Evaluation Count:72
yes
Evaluation Count:270
36-342
154 return false;
executed: return false;
Execution Count:72
72
155 }
executed: }
Execution Count:306
306
156 -
157 if ((flags & HasChildren) && !item->childCount())
evaluated: (flags & HasChildren)
TRUEFALSE
yes
Evaluation Count:612
yes
Evaluation Count:2485
evaluated: !item->childCount()
TRUEFALSE
yes
Evaluation Count:578
yes
Evaluation Count:34
34-2485
158 return false;
executed: return false;
Execution Count:578
578
159 if ((flags & NoChildren) && item->childCount())
evaluated: (flags & NoChildren)
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:2502
partially evaluated: item->childCount()
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
0-2502
160 return false;
executed: return false;
Execution Count:17
17
161 -
162 if ((flags & Hidden) && !item->isHidden())
evaluated: (flags & Hidden)
TRUEFALSE
yes
Evaluation Count:612
yes
Evaluation Count:1890
evaluated: !item->isHidden()
TRUEFALSE
yes
Evaluation Count:576
yes
Evaluation Count:36
36-1890
163 return false;
executed: return false;
Execution Count:576
576
164 if ((flags & NotHidden) && item->isHidden())
evaluated: (flags & NotHidden)
TRUEFALSE
yes
Evaluation Count:327
yes
Evaluation Count:1599
evaluated: item->isHidden()
TRUEFALSE
yes
Evaluation Count:38
yes
Evaluation Count:289
38-1599
165 return false;
executed: return false;
Execution Count:38
38
166 -
167 if ((flags & Selected) && !item->isSelected())
evaluated: (flags & Selected)
TRUEFALSE
yes
Evaluation Count:612
yes
Evaluation Count:1276
evaluated: !item->isSelected()
TRUEFALSE
yes
Evaluation Count:576
yes
Evaluation Count:36
36-1276
168 return false;
executed: return false;
Execution Count:576
576
169 if ((flags & Unselected) && item->isSelected())
evaluated: (flags & Unselected)
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:1294
partially evaluated: item->isSelected()
TRUEFALSE
yes
Evaluation Count:18
no
Evaluation Count:0
0-1294
170 return false;
executed: return false;
Execution Count:18
18
171 -
172 return true;
executed: return true;
Execution Count:1294
1294
173} -
174 -
175 -
176 -
177 -
178QTreeWidgetItem* QTreeWidgetItemIteratorPrivate::nextSibling(const QTreeWidgetItem* item) const -
179{ -
180 qt_noop(); -
181 QTreeWidgetItem *next = 0; -
182 if (QTreeWidgetItem *par = item->parent()) {
evaluated: QTreeWidgetItem *par = item->parent()
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:22
15-22
183 int i = par->indexOfChild(const_cast<QTreeWidgetItem*>(item)); -
184 next = par->child(i + 1); -
185 } else {
executed: }
Execution Count:15
15
186 QTreeWidget *tw = item->treeWidget(); -
187 int i = tw->indexOfTopLevelItem(const_cast<QTreeWidgetItem*>(item)); -
188 next = tw->topLevelItem(i + 1); -
189 }
executed: }
Execution Count:22
22
190 return next;
executed: return next;
Execution Count:37
37
191} -
192 -
193QTreeWidgetItem *QTreeWidgetItemIteratorPrivate::next(const QTreeWidgetItem *current) -
194{ -
195 if (!current) return 0;
never executed: return 0;
partially evaluated: !current
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7376
0-7376
196 -
197 QTreeWidgetItem *next = 0; -
198 if (current->childCount()) {
evaluated: current->childCount()
TRUEFALSE
yes
Evaluation Count:490
yes
Evaluation Count:6886
490-6886
199 -
200 m_parentIndex.push(m_currentIndex); -
201 m_currentIndex = 0; -
202 next = current->child(0); -
203 } else {
executed: }
Execution Count:490
490
204 -
205 QTreeWidgetItem *parent = current->parent(); -
206 next = parent ? parent->child(m_currentIndex + 1)
evaluated: parent
TRUEFALSE
yes
Evaluation Count:6839
yes
Evaluation Count:47
47-6839
207 : m_model->rootItem->child(m_currentIndex + 1); -
208 while (!next && parent) {
evaluated: !next
TRUEFALSE
yes
Evaluation Count:472
yes
Evaluation Count:6857
evaluated: parent
TRUEFALSE
yes
Evaluation Count:443
yes
Evaluation Count:29
29-6857
209 -
210 parent = parent->parent(); -
211 m_currentIndex = m_parentIndex.pop(); -
212 next = parent ? parent->child(m_currentIndex + 1)
evaluated: parent
TRUEFALSE
yes
Evaluation Count:37
yes
Evaluation Count:406
37-406
213 : m_model->rootItem->child(m_currentIndex + 1); -
214 }
executed: }
Execution Count:443
443
215 if (next) ++(m_currentIndex);
executed: ++(m_currentIndex);
Execution Count:6857
evaluated: next
TRUEFALSE
yes
Evaluation Count:6857
yes
Evaluation Count:29
29-6857
216 }
executed: }
Execution Count:6886
6886
217 return next;
executed: return next;
Execution Count:7376
7376
218} -
219 -
220QTreeWidgetItem *QTreeWidgetItemIteratorPrivate::previous(const QTreeWidgetItem *current) -
221{ -
222 if (!current) return 0;
never executed: return 0;
partially evaluated: !current
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
223 -
224 QTreeWidgetItem *prev = 0; -
225 -
226 QTreeWidgetItem *parent = current->parent(); -
227 prev = parent ? parent->child(m_currentIndex - 1)
evaluated: parent
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:3
3-10
228 : m_model->rootItem->child(m_currentIndex - 1); -
229 if (prev) {
evaluated: prev
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:6
6-7
230 -
231 --m_currentIndex; -
232 while (prev && prev->childCount()) {
partially evaluated: prev
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
evaluated: prev->childCount()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:7
0-10
233 m_parentIndex.push(m_currentIndex); -
234 m_currentIndex = prev->childCount() - 1; -
235 prev = prev->child(m_currentIndex); -
236 }
executed: }
Execution Count:3
3
237 } else if (parent) {
executed: }
Execution Count:7
evaluated: parent
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:1
1-7
238 m_currentIndex = m_parentIndex.pop(); -
239 prev = parent; -
240 }
executed: }
Execution Count:5
5
241 return prev;
executed: return prev;
Execution Count:13
13
242} -
243 -
244void QTreeWidgetItemIteratorPrivate::ensureValidIterator(const QTreeWidgetItem *itemToBeRemoved) -
245{ -
246 QTreeWidgetItemIterator * const q = q_func(); -
247 qt_noop(); -
248 -
249 if (!q->current) return;
never executed: return;
partially evaluated: !q->current
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:46
0-46
250 QTreeWidgetItem *nextItem = q->current; -
251 -
252 -
253 if (nextItem->parent() != itemToBeRemoved->parent()) {
evaluated: nextItem->parent() != itemToBeRemoved->parent()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:40
6-40
254 while (nextItem->parent() && nextItem != itemToBeRemoved) {
evaluated: nextItem->parent()
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:5
evaluated: nextItem != itemToBeRemoved
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:1
1-10
255 nextItem = nextItem->parent(); -
256 }
executed: }
Execution Count:9
9
257 }
executed: }
Execution Count:6
6
258 -
259 -
260 if (nextItem == itemToBeRemoved) {
evaluated: nextItem == itemToBeRemoved
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:10
10-36
261 QTreeWidgetItem *parent = nextItem; -
262 nextItem = 0; -
263 while (parent && !nextItem) {
evaluated: parent
TRUEFALSE
yes
Evaluation Count:51
yes
Evaluation Count:22
evaluated: !nextItem
TRUEFALSE
yes
Evaluation Count:37
yes
Evaluation Count:14
14-51
264 nextItem = nextSibling(parent); -
265 parent = parent->parent(); -
266 }
executed: }
Execution Count:37
37
267 if (nextItem) {
evaluated: nextItem
TRUEFALSE
yes
Evaluation Count:32
yes
Evaluation Count:4
4-32
268 -
269 *q = QTreeWidgetItemIterator(nextItem, q->flags); -
270 if (!(q->matchesFlags(nextItem))) ++(*q);
never executed: ++(*q);
partially evaluated: !(q->matchesFlags(nextItem))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:32
0-32
271 } else {
executed: }
Execution Count:32
32
272 -
273 q->current = 0; -
274 m_parentIndex.clear(); -
275 return;
executed: return;
Execution Count:4
4
276 } -
277 } -
278 if (nextItem->parent() == itemToBeRemoved->parent()) {
evaluated: nextItem->parent() == itemToBeRemoved->parent()
TRUEFALSE
yes
Evaluation Count:40
yes
Evaluation Count:2
2-40
279 -
280 -
281 -
282 QTreeWidgetItem *par = itemToBeRemoved->parent(); -
283 QTreeWidget *tw = itemToBeRemoved->treeWidget(); -
284 int indexOfItemToBeRemoved = par ? par->indexOfChild(const_cast<QTreeWidgetItem *>(itemToBeRemoved))
evaluated: par
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:22
18-22
285 : tw->indexOfTopLevelItem(const_cast<QTreeWidgetItem *>(itemToBeRemoved)); -
286 int indexOfNextItem = par ? par->indexOfChild(nextItem) : tw->indexOfTopLevelItem(nextItem);
evaluated: par
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:22
18-22
287 -
288 if (indexOfItemToBeRemoved <= indexOfNextItem) {
evaluated: indexOfItemToBeRemoved <= indexOfNextItem
TRUEFALSE
yes
Evaluation Count:37
yes
Evaluation Count:3
3-37
289 -
290 -
291 m_currentIndex--; -
292 }
executed: }
Execution Count:37
37
293 }
executed: }
Execution Count:40
40
294}
executed: }
Execution Count:42
42
295 -
296 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial