Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | QTreeView::QTreeView(QWidget *parent) | - |
11 | : QAbstractItemView(*new QTreeViewPrivate, parent) | - |
12 | { | - |
13 | QTreeViewPrivate * const d = d_func(); | - |
14 | d->initialize(); | - |
15 | } | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | QTreeView::QTreeView(QTreeViewPrivate &dd, QWidget *parent) | - |
21 | : QAbstractItemView(dd, parent) | - |
22 | { | - |
23 | QTreeViewPrivate * const d = d_func(); | - |
24 | d->initialize(); | - |
25 | } | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | QTreeView::~QTreeView() | - |
31 | { | - |
32 | } | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | void QTreeView::setModel(QAbstractItemModel *model) | - |
38 | { | - |
39 | QTreeViewPrivate * const d = d_func(); | - |
40 | if (model == d->model) | - |
41 | return; | - |
42 | if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) { | - |
43 | disconnect(d->model, qFlagLocation("2""rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "219""226"), | - |
44 | this, qFlagLocation("1""rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "220""227")); | - |
45 | | - |
46 | disconnect(d->model, qFlagLocation("2""modelAboutToBeReset()" "\0" __FILE__ ":" "222""229"), this, qFlagLocation("1""_q_modelAboutToBeReset()" "\0" __FILE__ ":" "222""229")); | - |
47 | } | - |
48 | | - |
49 | if (d->selectionModel) { | - |
50 | disconnect(d->selectionModel, qFlagLocation("2""currentRowChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "226""233"), | - |
51 | d->model, qFlagLocation("1""submit()" "\0" __FILE__ ":" "227""234")); | - |
52 | disconnect(d->model, qFlagLocation("2""rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "228""235"), | - |
53 | this, qFlagLocation("1""rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "229""236")); | - |
54 | disconnect(d->model, qFlagLocation("2""modelAboutToBeReset()" "\0" __FILE__ ":" "230""237"), this, qFlagLocation("1""_q_modelAboutToBeReset()" "\0" __FILE__ ":" "230""237")); | - |
55 | } | - |
56 | d->viewItems.clear(); | - |
57 | d->expandedIndexes.clear(); | - |
58 | d->hiddenIndexes.clear(); | - |
59 | d->header->setModel(model); | - |
60 | QAbstractItemView::setModel(model); | - |
61 | | - |
62 | | - |
63 | disconnect(d->model, qFlagLocation("2""rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "239""246"), | - |
64 | this, qFlagLocation("1""_q_rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "240""247")); | - |
65 | | - |
66 | disconnect(d->model, qFlagLocation("2""layoutChanged()" "\0" __FILE__ ":" "242""249"), | - |
67 | d->header, qFlagLocation("1""_q_layoutChanged()" "\0" __FILE__ ":" "243""250")); | - |
68 | | - |
69 | connect(d->model, qFlagLocation("2""rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "245""252"), | - |
70 | this, qFlagLocation("1""rowsRemoved(QModelIndex,int,int)" "\0" __FILE__ ":" "246""253")); | - |
71 | | - |
72 | connect(d->model, qFlagLocation("2""modelAboutToBeReset()" "\0" __FILE__ ":" "248""255"), qFlagLocation("1""_q_modelAboutToBeReset()" "\0" __FILE__ ":" "248""255")); | - |
73 | | - |
74 | if (d->sortingEnabled) | - |
75 | d->_q_sortIndicatorChanged(header()->sortIndicatorSection(), header()->sortIndicatorOrder()); | - |
76 | } | - |
77 | | - |
78 | | - |
79 | | - |
80 | | - |
81 | void QTreeView::setRootIndex(const QModelIndex &index) | - |
82 | { | - |
83 | QTreeViewPrivate * const d = d_func(); | - |
84 | d->header->setRootIndex(index); | - |
85 | QAbstractItemView::setRootIndex(index); | - |
86 | } | - |
87 | | - |
88 | | - |
89 | | - |
90 | | - |
91 | void QTreeView::setSelectionModel(QItemSelectionModel *selectionModel) | - |
92 | { | - |
93 | QTreeViewPrivate * const d = d_func(); | - |
94 | ((!(selectionModel)) ? qt_assert("selectionModel",__FILE__,270277) : qt_noop()); | - |
95 | if (d->selectionModel) { | - |
96 | | - |
97 | disconnect(d->selectionModel, qFlagLocation("2""currentRowChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "273""280"), | - |
98 | d->model, qFlagLocation("1""submit()" "\0" __FILE__ ":" "274""281")); | - |
99 | } | - |
100 | | - |
101 | d->header->setSelectionModel(selectionModel); | - |
102 | QAbstractItemView::setSelectionModel(selectionModel); | - |
103 | | - |
104 | if (d->selectionModel) { | - |
105 | | - |
106 | connect(d->selectionModel, qFlagLocation("2""currentRowChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "282""289"), | - |
107 | d->model, qFlagLocation("1""submit()" "\0" __FILE__ ":" "283""290")); | - |
108 | } | - |
109 | } | - |
110 | | - |
111 | | - |
112 | | - |
113 | | - |
114 | | - |
115 | | - |
116 | QHeaderView *QTreeView::header() const | - |
117 | { | - |
118 | const QTreeViewPrivate * const d = d_func(); | - |
119 | return d->header; | - |
120 | } | - |
121 | void QTreeView::setHeader(QHeaderView *header) | - |
122 | { | - |
123 | QTreeViewPrivate * const d = d_func(); | - |
124 | if (header == d->header || !header) | - |
125 | return; | - |
126 | if (d->header && d->header->parent() == this) | - |
127 | delete d->header; | - |
128 | d->header = header; | - |
129 | d->header->setParent(this); | - |
130 | d->header->d_func()->setAllowUserMoveOfSection0(false); | - |
131 | | - |
132 | if (!d->header->model()) { | - |
133 | d->header->setModel(d->model); | - |
134 | if (d->selectionModel) | - |
135 | d->header->setSelectionModel(d->selectionModel); | - |
136 | } | - |
137 | | - |
138 | connect(d->header, qFlagLocation("2""sectionResized(int,int,int)" "\0" __FILE__ ":" "323""330"), | - |
139 | this, qFlagLocation("1""columnResized(int,int,int)" "\0" __FILE__ ":" "324""331")); | - |
140 | connect(d->header, qFlagLocation("2""sectionMoved(int,int,int)" "\0" __FILE__ ":" "325""332"), | - |
141 | this, qFlagLocation("1""columnMoved()" "\0" __FILE__ ":" "326""333")); | - |
142 | connect(d->header, qFlagLocation("2""sectionCountChanged(int,int)" "\0" __FILE__ ":" "327""334"), | - |
143 | this, qFlagLocation("1""columnCountChanged(int,int)" "\0" __FILE__ ":" "328""335")); | - |
144 | connect(d->header, qFlagLocation("2""sectionHandleDoubleClicked(int)" "\0" __FILE__ ":" "329""336"), | - |
145 | this, qFlagLocation("1""resizeColumnToContents(int)" "\0" __FILE__ ":" "330""337")); | - |
146 | connect(d->header, qFlagLocation("2""geometriesChanged()" "\0" __FILE__ ":" "331""338"), | - |
147 | this, qFlagLocation("1""updateGeometries()" "\0" __FILE__ ":" "332""339")); | - |
148 | | - |
149 | setSortingEnabled(d->sortingEnabled); | - |
150 | d->updateGeometry(); | - |
151 | } | - |
152 | int QTreeView::autoExpandDelay() const | - |
153 | { | - |
154 | const QTreeViewPrivate * const d = d_func(); | - |
155 | return d->autoExpandDelay; | - |
156 | } | - |
157 | | - |
158 | void QTreeView::setAutoExpandDelay(int delay) | - |
159 | { | - |
160 | QTreeViewPrivate * const d = d_func(); | - |
161 | d->autoExpandDelay = delay; | - |
162 | } | - |
163 | int QTreeView::indentation() const | - |
164 | { | - |
165 | const QTreeViewPrivate * const d = d_func(); | - |
166 | return d->indent; | - |
167 | } | - |
168 | | - |
169 | void QTreeView::setIndentation(int i) | - |
170 | { | - |
171 | QTreeViewPrivate * const d = d_func(); | - |
172 | if (!d->customIndent || (i != d->indent)) { | - |
173 | d->indent = i; | - |
174 | d->customIndent = true; | - |
175 | d->viewport->update(); | - |
176 | } | - |
177 | } | - |
178 | | - |
179 | void QTreeView::resetIndentation() | - |
180 | { | - |
181 | QTreeViewPrivate * const d = d_func(); | - |
182 | if (d->customIndent) { | - |
183 | d->updateIndentationFromStyle(); | - |
184 | d->customIndent = false; | - |
185 | } | - |
186 | } | - |
187 | bool QTreeView::rootIsDecorated() const | - |
188 | { | - |
189 | const QTreeViewPrivate * const d = d_func(); | - |
190 | return d->rootDecoration; | - |
191 | } | - |
192 | | - |
193 | void QTreeView::setRootIsDecorated(bool show) | - |
194 | { | - |
195 | QTreeViewPrivate * const d = d_func(); | - |
196 | if (show != d->rootDecoration) { | - |
197 | d->rootDecoration = show; | - |
198 | d->viewport->update(); | - |
199 | } | - |
200 | } | - |
201 | bool QTreeView::uniformRowHeights() const | - |
202 | { | - |
203 | const QTreeViewPrivate * const d = d_func(); | - |
204 | return d->uniformRowHeights; | - |
205 | } | - |
206 | | - |
207 | void QTreeView::setUniformRowHeights(bool uniform) | - |
208 | { | - |
209 | QTreeViewPrivate * const d = d_func(); | - |
210 | d->uniformRowHeights = uniform; | - |
211 | } | - |
212 | bool QTreeView::itemsExpandable() const | - |
213 | { | - |
214 | const QTreeViewPrivate * const d = d_func(); | - |
215 | return d->itemsExpandable; | - |
216 | } | - |
217 | | - |
218 | void QTreeView::setItemsExpandable(bool enable) | - |
219 | { | - |
220 | QTreeViewPrivate * const d = d_func(); | - |
221 | d->itemsExpandable = enable; | - |
222 | } | - |
223 | bool QTreeView::expandsOnDoubleClick() const | - |
224 | { | - |
225 | const QTreeViewPrivate * const d = d_func(); | - |
226 | return d->expandsOnDoubleClick; | - |
227 | } | - |
228 | | - |
229 | void QTreeView::setExpandsOnDoubleClick(bool enable) | - |
230 | { | - |
231 | QTreeViewPrivate * const d = d_func(); | - |
232 | d->expandsOnDoubleClick = enable; | - |
233 | } | - |
234 | | - |
235 | | - |
236 | | - |
237 | | - |
238 | int QTreeView::columnViewportPosition(int column) const | - |
239 | { | - |
240 | const QTreeViewPrivate * const d = d_func(); | - |
241 | return d->header->sectionViewportPosition(column); | - |
242 | } | - |
243 | | - |
244 | | - |
245 | | - |
246 | | - |
247 | | - |
248 | | - |
249 | int QTreeView::columnWidth(int column) const | - |
250 | { | - |
251 | const QTreeViewPrivate * const d = d_func(); | - |
252 | return d->header->sectionSize(column); | - |
253 | } | - |
254 | void QTreeView::setColumnWidth(int column, int width) | - |
255 | { | - |
256 | QTreeViewPrivate * const d = d_func(); | - |
257 | d->header->resizeSection(column, width); | - |
258 | } | - |
259 | | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | int QTreeView::columnAt(int x) const | - |
265 | { | - |
266 | const QTreeViewPrivate * const d = d_func(); | - |
267 | return d->header->logicalIndexAt(x); | - |
268 | } | - |
269 | | - |
270 | | - |
271 | | - |
272 | | - |
273 | | - |
274 | | - |
275 | bool QTreeView::isColumnHidden(int column) const | - |
276 | { | - |
277 | const QTreeViewPrivate * const d = d_func(); | - |
278 | return d->header->isSectionHidden(column); | - |
279 | } | - |
280 | | - |
281 | | - |
282 | | - |
283 | | - |
284 | | - |
285 | | - |
286 | void QTreeView::setColumnHidden(int column, bool hide) | - |
287 | { | - |
288 | QTreeViewPrivate * const d = d_func(); | - |
289 | if (column < 0 || column >= d->header->count()) | - |
290 | return; | - |
291 | d->header->setSectionHidden(column, hide); | - |
292 | } | - |
293 | bool QTreeView::isHeaderHidden() const | - |
294 | { | - |
295 | const QTreeViewPrivate * const d = d_func(); | - |
296 | return d->header->isHidden(); | - |
297 | } | - |
298 | | - |
299 | void QTreeView::setHeaderHidden(bool hide) | - |
300 | { | - |
301 | QTreeViewPrivate * const d = d_func(); | - |
302 | d->header->setHidden(hide); | - |
303 | } | - |
304 | | - |
305 | | - |
306 | | - |
307 | | - |
308 | | - |
309 | | - |
310 | | - |
311 | bool QTreeView::isRowHidden(int row, const QModelIndex &parent) const | - |
312 | { | - |
313 | const QTreeViewPrivate * const d = d_func(); | - |
314 | if (!d->model) | - |
315 | return false; | - |
316 | return d->isRowHidden(d->model->index(row, 0, parent)); | - |
317 | } | - |
318 | | - |
319 | | - |
320 | | - |
321 | | - |
322 | | - |
323 | | - |
324 | void QTreeView::setRowHidden(int row, const QModelIndex &parent, bool hide) | - |
325 | { | - |
326 | QTreeViewPrivate * const d = d_func(); | - |
327 | if (!d->model) | - |
328 | return; | - |
329 | QModelIndex index = d->model->index(row, 0, parent); | - |
330 | if (!index.isValid()) | - |
331 | return; | - |
332 | | - |
333 | if (hide) { | - |
334 | d->hiddenIndexes.insert(index); | - |
335 | } else if(d->isPersistent(index)) { | - |
336 | d->hiddenIndexes.remove(index); | - |
337 | } | - |
338 | | - |
339 | d->doDelayedItemsLayout(); | - |
340 | } | - |
341 | bool QTreeView::isFirstColumnSpanned(int row, const QModelIndex &parent) const | - |
342 | { | - |
343 | const QTreeViewPrivate * const d = d_func(); | - |
344 | if (d->spanningIndexes.isEmpty() || !d->model) | - |
345 | return false; | - |
346 | QModelIndex index = d->model->index(row, 0, parent); | - |
347 | for (int i = 0; i < d->spanningIndexes.count(); ++i) | - |
348 | if (d->spanningIndexes.at(i) == index) | - |
349 | return true; | - |
350 | return false; | - |
351 | } | - |
352 | void QTreeView::setFirstColumnSpanned(int row, const QModelIndex &parent, bool span) | - |
353 | { | - |
354 | QTreeViewPrivate * const d = d_func(); | - |
355 | if (!d->model) | - |
356 | return; | - |
357 | QModelIndex index = d->model->index(row, 0, parent); | - |
358 | if (!index.isValid()) | - |
359 | return; | - |
360 | | - |
361 | if (span) { | - |
362 | QPersistentModelIndex persistent(index); | - |
363 | if (!d->spanningIndexes.contains(persistent)) | - |
364 | d->spanningIndexes.append(persistent); | - |
365 | } else { | - |
366 | QPersistentModelIndex persistent(index); | - |
367 | int i = d->spanningIndexes.indexOf(persistent); | - |
368 | if (i >= 0) | - |
369 | d->spanningIndexes.remove(i); | - |
370 | } | - |
371 | | - |
372 | d->executePostedLayout(); | - |
373 | int i = d->viewIndex(index); | - |
374 | if (i >= 0) | - |
375 | d->viewItems[i].spanning = span; | - |
376 | | - |
377 | d->viewport->update(); | - |
378 | } | - |
379 | | - |
380 | | - |
381 | | - |
382 | | - |
383 | void QTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) | - |
384 | { | - |
385 | QTreeViewPrivate * const d = d_func(); | - |
386 | | - |
387 | | - |
388 | if (d->delayedPendingLayout) | - |
389 | return; | - |
390 | | - |
391 | | - |
392 | | - |
393 | | - |
394 | bool sizeChanged = false; | - |
395 | int topViewIndex = d->viewIndex(topLeft); | - |
396 | if (topViewIndex == 0) { | - |
397 | int newDefaultItemHeight = indexRowSizeHint(topLeft); | - |
398 | sizeChanged = d->defaultItemHeight != newDefaultItemHeight; | - |
399 | d->defaultItemHeight = newDefaultItemHeight; | - |
400 | } | - |
401 | | - |
402 | if (topViewIndex != -1) { | - |
403 | if (topLeft.row() == bottomRight.row()) { | - |
404 | int oldHeight = d->itemHeight(topViewIndex); | - |
405 | d->invalidateHeightCache(topViewIndex); | - |
406 | sizeChanged |= (oldHeight != d->itemHeight(topViewIndex)); | - |
407 | if (topLeft.column() == 0) | - |
408 | d->viewItems[topViewIndex].hasChildren = d->hasVisibleChildren(topLeft); | - |
409 | } else { | - |
410 | int bottomViewIndex = d->viewIndex(bottomRight); | - |
411 | for (int i = topViewIndex; i <= bottomViewIndex; ++i) { | - |
412 | int oldHeight = d->itemHeight(i); | - |
413 | d->invalidateHeightCache(i); | - |
414 | sizeChanged |= (oldHeight != d->itemHeight(i)); | - |
415 | if (topLeft.column() == 0) | - |
416 | d->viewItems[i].hasChildren = d->hasVisibleChildren(d->viewItems.at(i).index); | - |
417 | } | - |
418 | } | - |
419 | } | - |
420 | | - |
421 | if (sizeChanged) { | - |
422 | d->updateScrollBars(); | - |
423 | d->viewport->update(); | - |
424 | } | - |
425 | QAbstractItemView::dataChanged(topLeft, bottomRight, roles); | - |
426 | } | - |
427 | void QTreeView::hideColumn(int column) | - |
428 | { | - |
429 | QTreeViewPrivate * const d = d_func(); | - |
430 | d->header->hideSection(column); | - |
431 | } | - |
432 | | - |
433 | | - |
434 | | - |
435 | | - |
436 | | - |
437 | | - |
438 | void QTreeView::showColumn(int column) | - |
439 | { | - |
440 | QTreeViewPrivate * const d = d_func(); | - |
441 | d->header->showSection(column); | - |
442 | } | - |
443 | void QTreeView::expand(const QModelIndex &index) | - |
444 | { | - |
445 | QTreeViewPrivate * const d = d_func(); | - |
446 | if (!d->isIndexValid(index)) | - |
447 | return; | - |
448 | if (index.flags() & Qt::ItemNeverHasChildren) | - |
449 | return; | - |
450 | if (d->isIndexExpanded(index)) | - |
451 | return; | - |
452 | if (d->delayedPendingLayout) { | - |
453 | | - |
454 | if (d->storeExpanded(index)) | - |
455 | expanded(index); | - |
456 | return; | - |
457 | } | - |
458 | | - |
459 | int i = d->viewIndex(index); | - |
460 | if (i != -1) { | - |
461 | d->expand(i, true); | - |
462 | if (!d->isAnimating()) { | - |
463 | updateGeometries(); | - |
464 | d->viewport->update(); | - |
465 | } | - |
466 | } else if (d->storeExpanded(index)) { | - |
467 | expanded(index); | - |
468 | } | - |
469 | } | - |
470 | void QTreeView::collapse(const QModelIndex &index) | - |
471 | { | - |
472 | QTreeViewPrivate * const d = d_func(); | - |
473 | if (!d->isIndexValid(index)) | - |
474 | return; | - |
475 | if (!d->isIndexExpanded(index)) | - |
476 | return; | - |
477 | | - |
478 | d->delayedAutoScroll.stop(); | - |
479 | | - |
480 | if (d->delayedPendingLayout) { | - |
481 | | - |
482 | if (d->isPersistent(index) && d->expandedIndexes.remove(index)) | - |
483 | collapsed(index); | - |
484 | return; | - |
485 | } | - |
486 | int i = d->viewIndex(index); | - |
487 | if (i != -1) { | - |
488 | d->collapse(i, true); | - |
489 | if (!d->isAnimating()) { | - |
490 | updateGeometries(); | - |
491 | viewport()->update(); | - |
492 | } | - |
493 | } else { | - |
494 | if (d->isPersistent(index) && d->expandedIndexes.remove(index)) | - |
495 | collapsed(index); | - |
496 | } | - |
497 | } | - |
498 | bool QTreeView::isExpanded(const QModelIndex &index) const | - |
499 | { | - |
500 | const QTreeViewPrivate * const d = d_func(); | - |
501 | return d->isIndexExpanded(index); | - |
502 | } | - |
503 | | - |
504 | | - |
505 | | - |
506 | | - |
507 | | - |
508 | | - |
509 | | - |
510 | void QTreeView::setExpanded(const QModelIndex &index, bool expanded) | - |
511 | { | - |
512 | if (expanded) | - |
513 | this->expand(index); | - |
514 | else | - |
515 | this->collapse(index); | - |
516 | } | - |
517 | void QTreeView::setSortingEnabled(bool enable) | - |
518 | { | - |
519 | QTreeViewPrivate * const d = d_func(); | - |
520 | header()->setSortIndicatorShown(enable); | - |
521 | header()->setSectionsClickable(enable); | - |
522 | if (enable) { | - |
523 | | - |
524 | | - |
525 | sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder()); | - |
526 | connect(header(), qFlagLocation("2""sortIndicatorChanged(int,Qt::SortOrder)" "\0" __FILE__ ":" "878""885"), | - |
527 | this, qFlagLocation("1""_q_sortIndicatorChanged(int,Qt::SortOrder)" "\0" __FILE__ ":" "879""886"), Qt::UniqueConnection); | - |
528 | } else { | - |
529 | disconnect(header(), qFlagLocation("2""sortIndicatorChanged(int,Qt::SortOrder)" "\0" __FILE__ ":" "881""888"), | - |
530 | this, qFlagLocation("1""_q_sortIndicatorChanged(int,Qt::SortOrder)" "\0" __FILE__ ":" "882""889")); | - |
531 | } | - |
532 | d->sortingEnabled = enable; | - |
533 | } | - |
534 | | - |
535 | bool QTreeView::isSortingEnabled() const | - |
536 | { | - |
537 | const QTreeViewPrivate * const d = d_func(); | - |
538 | return d->sortingEnabled; | - |
539 | } | - |
540 | void QTreeView::setAnimated(bool animate) | - |
541 | { | - |
542 | QTreeViewPrivate * const d = d_func(); | - |
543 | d->animationsEnabled = animate; | - |
544 | } | - |
545 | | - |
546 | bool QTreeView::isAnimated() const | - |
547 | { | - |
548 | const QTreeViewPrivate * const d = d_func(); | - |
549 | return d->animationsEnabled; | - |
550 | } | - |
551 | void QTreeView::setAllColumnsShowFocus(bool enable) | - |
552 | { | - |
553 | QTreeViewPrivate * const d = d_func(); | - |
554 | if (d->allColumnsShowFocus == enable) | - |
555 | return; | - |
556 | d->allColumnsShowFocus = enable; | - |
557 | d->viewport->update(); | - |
558 | } | - |
559 | | - |
560 | bool QTreeView::allColumnsShowFocus() const | - |
561 | { | - |
562 | const QTreeViewPrivate * const d = d_func(); | - |
563 | return d->allColumnsShowFocus; | - |
564 | } | - |
565 | void QTreeView::setWordWrap(bool on) | - |
566 | { | - |
567 | QTreeViewPrivate * const d = d_func(); | - |
568 | if (d->wrapItemText == on) | - |
569 | return; | - |
570 | d->wrapItemText = on; | - |
571 | d->doDelayedItemsLayout(); | - |
572 | } | - |
573 | | - |
574 | bool QTreeView::wordWrap() const | - |
575 | { | - |
576 | const QTreeViewPrivate * const d = d_func(); | - |
577 | return d->wrapItemText; | - |
578 | } | - |
579 | void QTreeView::setTreePosition(int index) | - |
580 | { | - |
581 | QTreeViewPrivate * const d = d_func(); | - |
582 | d->treePosition = index; | - |
583 | update(); | - |
584 | } | - |
585 | int QTreeView::treePosition() const | - |
586 | { | - |
587 | const QTreeViewPrivate * const d = d_func(); | - |
588 | return d->treePosition; | - |
589 | } | - |
590 | | - |
591 | | - |
592 | | - |
593 | | - |
594 | void QTreeView::keyboardSearch(const QString &search) | - |
595 | { | - |
596 | QTreeViewPrivate * const d = d_func(); | - |
597 | if (!d->model->rowCount(d->root) || !d->model->columnCount(d->root)) | - |
598 | return; | - |
599 | | - |
600 | QModelIndex start; | - |
601 | if (currentIndex().isValid()) | - |
602 | start = currentIndex(); | - |
603 | else | - |
604 | start = d->model->index(0, 0, d->root); | - |
605 | | - |
606 | bool skipRow = false; | - |
607 | bool keyboardTimeWasValid = d->keyboardInputTime.isValid(); | - |
608 | qint64 keyboardInputTimeElapsed; | - |
609 | if (keyboardTimeWasValid) | - |
610 | keyboardInputTimeElapsed = d->keyboardInputTime.restart(); | - |
611 | else | - |
612 | d->keyboardInputTime.start(); | - |
613 | if (search.isEmpty() || !keyboardTimeWasValid | - |
614 | || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) { | - |
615 | d->keyboardInput = search; | - |
616 | skipRow = currentIndex().isValid(); | - |
617 | } else { | - |
618 | d->keyboardInput += search; | - |
619 | } | - |
620 | | - |
621 | | - |
622 | bool sameKey = false; | - |
623 | if (d->keyboardInput.length() > 1) { | - |
624 | int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.length() - 1)); | - |
625 | sameKey = (c == d->keyboardInput.length()); | - |
626 | if (sameKey) | - |
627 | skipRow = true; | - |
628 | } | - |
629 | | - |
630 | | - |
631 | if (skipRow) { | - |
632 | if (indexBelow(start).isValid()) | - |
633 | start = indexBelow(start); | - |
634 | else | - |
635 | start = d->model->index(0, start.column(), d->root); | - |
636 | } | - |
637 | | - |
638 | d->executePostedLayout(); | - |
639 | int startIndex = d->viewIndex(start); | - |
640 | if (startIndex <= -1) | - |
641 | return; | - |
642 | | - |
643 | int previousLevel = -1; | - |
644 | int bestAbove = -1; | - |
645 | int bestBelow = -1; | - |
646 | QString searchString = sameKey ? QString(d->keyboardInput.at(0)) : d->keyboardInput; | - |
647 | for (int i = 0; i < d->viewItems.count(); ++i) { | - |
648 | if ((int)d->viewItems.at(i).level > previousLevel) { | - |
649 | QModelIndex searchFrom = d->viewItems.at(i).index; | - |
650 | if (start.column() > 0) | - |
651 | searchFrom = searchFrom.sibling(searchFrom.row(), start.column()); | - |
652 | if (searchFrom.parent() == start.parent()) | - |
653 | searchFrom = start; | - |
654 | QModelIndexList match = d->model->match(searchFrom, Qt::DisplayRole, searchString); | - |
655 | if (match.count()) { | - |
656 | int hitIndex = d->viewIndex(match.at(0)); | - |
657 | if (hitIndex >= 0 && hitIndex < startIndex) | - |
658 | bestAbove = bestAbove == -1 ? hitIndex : qMin(hitIndex, bestAbove); | - |
659 | else if (hitIndex >= startIndex) | - |
660 | bestBelow = bestBelow == -1 ? hitIndex : qMin(hitIndex, bestBelow); | - |
661 | } | - |
662 | } | - |
663 | previousLevel = d->viewItems.at(i).level; | - |
664 | } | - |
665 | | - |
666 | QModelIndex index; | - |
667 | if (bestBelow > -1) | - |
668 | index = d->viewItems.at(bestBelow).index; | - |
669 | else if (bestAbove > -1) | - |
670 | index = d->viewItems.at(bestAbove).index; | - |
671 | | - |
672 | if (start.column() > 0) | - |
673 | index = index.sibling(index.row(), start.column()); | - |
674 | | - |
675 | if (index.isValid()) { | - |
676 | QItemSelectionModel::SelectionFlags flags = (d->selectionMode == SingleSelection | - |
677 | ? QItemSelectionModel::SelectionFlags( | - |
678 | QItemSelectionModel::ClearAndSelect | - |
679 | |d->selectionBehaviorFlags()) | - |
680 | : QItemSelectionModel::SelectionFlags( | - |
681 | QItemSelectionModel::NoUpdate)); | - |
682 | selectionModel()->setCurrentIndex(index, flags); | - |
683 | } | - |
684 | } | - |
685 | | - |
686 | | - |
687 | | - |
688 | | - |
689 | | - |
690 | QRect QTreeView::visualRect(const QModelIndex &index) const | - |
691 | { | - |
692 | const QTreeViewPrivate * const d = d_func(); | - |
693 | | - |
694 | if (!d->isIndexValid(index) || isIndexHidden(index)) | - |
695 | return QRect(); | - |
696 | | - |
697 | d->executePostedLayout(); | - |
698 | | - |
699 | int vi = d->viewIndex(index); | - |
700 | if (vi < 0) | - |
701 | return QRect(); | - |
702 | | - |
703 | bool spanning = d->viewItems.at(vi).spanning; | - |
704 | | - |
705 | | - |
706 | int x = (spanning ? 0 : columnViewportPosition(index.column())); | - |
707 | int w = (spanning ? d->header->length() : columnWidth(index.column())); | - |
708 | | - |
709 | if (d->isTreePosition(index.column())) { | - |
710 | int i = d->indentationForItem(vi); | - |
711 | w -= i; | - |
712 | if (!isRightToLeft()) | - |
713 | x += i; | - |
714 | } | - |
715 | | - |
716 | int y = d->coordinateForItem(vi); | - |
717 | int h = d->itemHeight(vi); | - |
718 | | - |
719 | return QRect(x, y, w, h); | - |
720 | } | - |
721 | void QTreeView::scrollTo(const QModelIndex &index, ScrollHint hint) | - |
722 | { | - |
723 | QTreeViewPrivate * const d = d_func(); | - |
724 | | - |
725 | if (!d->isIndexValid(index)) | - |
726 | return; | - |
727 | | - |
728 | d->executePostedLayout(); | - |
729 | d->updateScrollBars(); | - |
730 | | - |
731 | | - |
732 | QModelIndex parent = index.parent(); | - |
733 | while (parent != d->root && parent.isValid() && state() == NoState && d->itemsExpandable) { | - |
734 | if (!isExpanded(parent)) | - |
735 | expand(parent); | - |
736 | parent = d->model->parent(parent); | - |
737 | } | - |
738 | | - |
739 | int item = d->viewIndex(index); | - |
740 | if (item < 0) | - |
741 | return; | - |
742 | | - |
743 | QRect area = d->viewport->rect(); | - |
744 | | - |
745 | | - |
746 | if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) { | - |
747 | int top = verticalScrollBar()->value(); | - |
748 | int bottom = top + verticalScrollBar()->pageStep(); | - |
749 | if (hint == EnsureVisible && item >= top && item < bottom) { | - |
750 | | - |
751 | } else if (hint == PositionAtTop || (hint == EnsureVisible && item < top)) { | - |
752 | verticalScrollBar()->setValue(item); | - |
753 | } else { | - |
754 | const int currentItemHeight = d->itemHeight(item); | - |
755 | int y = (hint == PositionAtCenter | - |
756 | | - |
757 | ? area.height() / 2 + currentItemHeight - 1 | - |
758 | | - |
759 | : area.height()); | - |
760 | if (y > currentItemHeight) { | - |
761 | while (item >= 0) { | - |
762 | y -= d->itemHeight(item); | - |
763 | if (y < 0) { | - |
764 | item++; | - |
765 | break; | - |
766 | } | - |
767 | item--; | - |
768 | } | - |
769 | } | - |
770 | verticalScrollBar()->setValue(item); | - |
771 | } | - |
772 | } else { | - |
773 | QRect rect(columnViewportPosition(index.column()), | - |
774 | d->coordinateForItem(item), | - |
775 | columnWidth(index.column()), | - |
776 | d->itemHeight(item)); | - |
777 | | - |
778 | if (rect.isEmpty()) { | - |
779 | | - |
780 | } else if (hint == EnsureVisible && area.contains(rect)) { | - |
781 | d->viewport->update(rect); | - |
782 | | - |
783 | } else { | - |
784 | bool above = (hint == EnsureVisible | - |
785 | && (rect.top() < area.top() | - |
786 | || area.height() < rect.height())); | - |
787 | bool below = (hint == EnsureVisible | - |
788 | && rect.bottom() > area.bottom() | - |
789 | && rect.height() < area.height()); | - |
790 | | - |
791 | int verticalValue = verticalScrollBar()->value(); | - |
792 | if (hint == PositionAtTop || above) | - |
793 | verticalValue += rect.top(); | - |
794 | else if (hint == PositionAtBottom || below) | - |
795 | verticalValue += rect.bottom() - area.height(); | - |
796 | else if (hint == PositionAtCenter) | - |
797 | verticalValue += rect.top() - ((area.height() - rect.height()) / 2); | - |
798 | verticalScrollBar()->setValue(verticalValue); | - |
799 | } | - |
800 | } | - |
801 | | - |
802 | int viewportWidth = d->viewport->width(); | - |
803 | int horizontalOffset = d->header->offset(); | - |
804 | int horizontalPosition = d->header->sectionPosition(index.column()); | - |
805 | int cellWidth = d->header->sectionSize(index.column()); | - |
806 | | - |
807 | if (hint == PositionAtCenter) { | - |
808 | horizontalScrollBar()->setValue(horizontalPosition - ((viewportWidth - cellWidth) / 2)); | - |
809 | } else { | - |
810 | if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth) | - |
811 | horizontalScrollBar()->setValue(horizontalPosition); | - |
812 | else if (horizontalPosition - horizontalOffset + cellWidth > viewportWidth) | - |
813 | horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth); | - |
814 | } | - |
815 | } | - |
816 | | - |
817 | | - |
818 | | - |
819 | | - |
820 | void QTreeView::timerEvent(QTimerEvent *event) | - |
821 | { | - |
822 | QTreeViewPrivate * const d = d_func(); | - |
823 | if (event->timerId() == d->columnResizeTimerID) { | - |
824 | updateGeometries(); | - |
825 | killTimer(d->columnResizeTimerID); | - |
826 | d->columnResizeTimerID = 0; | - |
827 | QRect rect; | - |
828 | int viewportHeight = d->viewport->height(); | - |
829 | int viewportWidth = d->viewport->width(); | - |
830 | for (int i = d->columnsToUpdate.size() - 1; i >= 0; --i) { | - |
831 | int column = d->columnsToUpdate.at(i); | - |
832 | int x = columnViewportPosition(column); | - |
833 | if (isRightToLeft()) | - |
834 | rect |= QRect(0, 0, x + columnWidth(column), viewportHeight); | - |
835 | else | - |
836 | rect |= QRect(x, 0, viewportWidth - x, viewportHeight); | - |
837 | } | - |
838 | d->viewport->update(rect.normalized()); | - |
839 | d->columnsToUpdate.clear(); | - |
840 | } else if (event->timerId() == d->openTimer.timerId()) { | - |
841 | QPoint pos = d->viewport->mapFromGlobal(QCursor::pos()); | - |
842 | if (state() == QAbstractItemView::DraggingState | - |
843 | && d->viewport->rect().contains(pos)) { | - |
844 | QModelIndex index = indexAt(pos); | - |
845 | setExpanded(index, !isExpanded(index)); | - |
846 | } | - |
847 | d->openTimer.stop(); | - |
848 | } | - |
849 | | - |
850 | QAbstractItemView::timerEvent(event); | - |
851 | } | - |
852 | | - |
853 | | - |
854 | | - |
855 | | - |
856 | | - |
857 | void QTreeView::dragMoveEvent(QDragMoveEvent *event) | - |
858 | { | - |
859 | QTreeViewPrivate * const d = d_func(); | - |
860 | if (d->autoExpandDelay >= 0) | - |
861 | d->openTimer.start(d->autoExpandDelay, this); | - |
862 | QAbstractItemView::dragMoveEvent(event); | - |
863 | } | - |
864 | | - |
865 | | - |
866 | | - |
867 | | - |
868 | | - |
869 | bool QTreeView::viewportEvent(QEvent *event) | - |
870 | { | - |
871 | QTreeViewPrivate * const d = d_func(); | - |
872 | switch (event->type()) { | - |
873 | case QEvent::HoverEnter: | - |
874 | case QEvent::HoverLeave: | - |
875 | case QEvent::HoverMove: { | - |
876 | QHoverEvent *he = static_cast<QHoverEvent*>(event); | - |
877 | int oldBranch = d->hoverBranch; | - |
878 | d->hoverBranch = d->itemDecorationAt(he->pos()); | - |
879 | QModelIndex newIndex = indexAt(he->pos()); | - |
880 | if (d->hover != newIndex || d->hoverBranch != oldBranch) { | - |
881 | | - |
882 | | - |
883 | QRect rect = visualRect(newIndex); | - |
884 | rect.setX(0); | - |
885 | rect.setWidth(viewport()->width()); | - |
886 | viewport()->update(rect); | - |
887 | } | - |
888 | break; } | - |
889 | default: | - |
890 | break; | - |
891 | } | - |
892 | return QAbstractItemView::viewportEvent(event); | - |
893 | } | - |
894 | | - |
895 | | - |
896 | | - |
897 | | - |
898 | void QTreeView::paintEvent(QPaintEvent *event) | - |
899 | { | - |
900 | QTreeViewPrivate * const d = d_func(); | - |
901 | d->executePostedLayout(); | - |
902 | QPainter painter(viewport()); | - |
903 | | - |
904 | if (d->isAnimating()) { | - |
905 | drawTree(&painter, event->region() - d->animatedOperation.rect()); | - |
906 | d->drawAnimatedOperation(&painter); | - |
907 | } else | - |
908 | | - |
909 | { | - |
910 | drawTree(&painter, event->region()); | - |
911 | | - |
912 | d->paintDropIndicator(&painter); | - |
913 | | - |
914 | } | - |
915 | } | - |
916 | | - |
917 | int QTreeViewPrivate::logicalIndexForTree() const | - |
918 | { | - |
919 | int index = treePosition; | - |
920 | if (index < 0) | - |
921 | index = header->logicalIndex(0); | - |
922 | return index; | - |
923 | } | - |
924 | | - |
925 | void QTreeViewPrivate::paintAlternatingRowColors(QPainter *painter, QStyleOptionViewItem *option, int y, int bottom) const | - |
926 | { | - |
927 | const QTreeView * const q = q_func(); | - |
928 | if (!alternatingColorsTRUE | never evaluated | FALSE | never evaluated |
|| !q->style()->styleHint(QStyle::SH_ItemView_PaintAlternatingRowColorsForEmptyArea, option, q)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
929 | return; never executed: return; | 0 |
930 | int rowHeight = defaultItemHeight; | - |
931 | if (rowHeight <= 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
932 | rowHeight = itemDelegate->sizeHint(*option, QModelIndex()).height(); | - |
933 | if (rowHeight <= 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
934 | return; never executed: return; | 0 |
935 | } never executed: end of block | 0 |
936 | while (y <= bottomTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
937 | option->rect.setRect(0, y, viewport->width(), rowHeight); | - |
938 | if (current & 1) {option->features|=.setFlag(QStyleOptionViewItem::Alternate; | - |
| } else { | |
| option->features, current & = ~QStyleOptionViewItem::Alternate; | |
| }1); | |
939 | ++current; | - |
940 | q->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, option, painter, q); | - |
941 | y += rowHeight; | - |
942 | } never executed: end of block | 0 |
943 | } never executed: end of block | 0 |
944 | | - |
945 | bool QTreeViewPrivate::expandOrCollapseItemAtPos(const QPoint &pos) | - |
946 | { | - |
947 | QTreeView * const q = q_func(); | - |
948 | | - |
949 | if ((state != QAbstractItemView::NoState | - |
950 | && state != QAbstractItemView::EditingState) | - |
951 | || !viewport->rect().contains(pos)) | - |
952 | return true; | - |
953 | | - |
954 | int i = itemDecorationAt(pos); | - |
955 | if ((i != -1) && itemsExpandable && hasVisibleChildren(viewItems.at(i).index)) { | - |
956 | if (viewItems.at(i).expanded) | - |
957 | collapse(i, true); | - |
958 | else | - |
959 | expand(i, true); | - |
960 | if (!isAnimating()) { | - |
961 | q->updateGeometries(); | - |
962 | viewport->update(); | - |
963 | } | - |
964 | return true; | - |
965 | } | - |
966 | return false; | - |
967 | } | - |
968 | | - |
969 | void QTreeViewPrivate::_q_modelDestroyed() | - |
970 | { | - |
971 | | - |
972 | | - |
973 | viewItems.clear(); | - |
974 | QAbstractItemViewPrivate::_q_modelDestroyed(); | - |
975 | } | - |
976 | | - |
977 | | - |
978 | | - |
979 | | - |
980 | | - |
981 | | - |
982 | QItemViewPaintPairs QTreeViewPrivate::draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const | - |
983 | { | - |
984 | ((!(r)) ? qt_assert("r",__FILE__,14091412) : qt_noop()); | - |
985 | const QTreeView * const q = q_func(); | - |
986 | if (spanningIndexes.isEmpty()) | - |
987 | return QAbstractItemViewPrivate::draggablePaintPairs(indexes, r); | - |
988 | QModelIndexList list; | - |
989 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(indexes)>::type> _container_((indexes)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QModelIndex &idx = *_container_.i; _container_.control; _container_.control = 0) { | - |
990 | if (idx.column() > 0 && q->isFirstColumnSpanned(idx.row(), idx.parent())) | - |
991 | continue; | - |
992 | list << idx; | - |
993 | } | - |
994 | return QAbstractItemViewPrivate::draggablePaintPairs(list, r); | - |
995 | } | - |
996 | | - |
997 | void QTreeViewPrivate::adjustViewOptionsForIndex(QStyleOptionViewItem *option, const QModelIndex ¤t) const | - |
998 | { | - |
999 | const int row = viewIndex(current); | - |
1000 | option->state = option->state | (viewItems.at(row).expanded ? QStyle::State_Open : QStyle::State_None) | - |
1001 | | (viewItems.at(row).hasChildren ? QStyle::State_Children : QStyle::State_None) | - |
1002 | | (viewItems.at(row).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None); | - |
1003 | | - |
1004 | option->showDecorationSelected = (selectionBehavior & QTreeView::SelectRows) | - |
1005 | || option->showDecorationSelected; | - |
1006 | | - |
1007 | QVector<int> logicalIndices; | - |
1008 | QVector<QStyleOptionViewItem::ViewItemPosition> viewItemPosList; | - |
1009 | const bool spanning = viewItems.at(row).spanning; | - |
1010 | const int left = (spanning ? header->visualIndex(0) : 0); | - |
1011 | const int right = (spanning ? header->visualIndex(0) : header->count() - 1 ); | - |
1012 | calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right); | - |
1013 | | - |
1014 | const int visualIndex = logicalIndices.indexOf(current.column()); | - |
1015 | option->viewItemPosition = viewItemPosList.at(visualIndex); | - |
1016 | } | - |
1017 | void QTreeView::drawTree(QPainter *painter, const QRegion ®ion) const | - |
1018 | { | - |
1019 | const QTreeViewPrivate * const d = d_func(); | - |
1020 | const QVector<QTreeViewItem> viewItems = d->viewItems; | - |
1021 | | - |
1022 | QStyleOptionViewItem option = d->viewOptionsV1(); | - |
1023 | const QStyle::State state = option.state; | - |
1024 | d->current = 0; | - |
1025 | | - |
1026 | if (viewItems.count() == 0 || d->header->count() == 0 || !d->itemDelegate) { | - |
1027 | d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1); | - |
1028 | return; | - |
1029 | } | - |
1030 | | - |
1031 | int firstVisibleItemOffset = 0; | - |
1032 | const int firstVisibleItem = d->firstVisibleItem(&firstVisibleItemOffset); | - |
1033 | if (firstVisibleItem < 0) { | - |
1034 | d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1); | - |
1035 | return; | - |
1036 | } | - |
1037 | | - |
1038 | const int viewportWidth = d->viewport->width(); | - |
1039 | | - |
1040 | QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos()); | - |
1041 | d->hoverBranch = d->itemDecorationAt(hoverPos); | - |
1042 | | - |
1043 | QVector<QRect> rects = region.rects(); | - |
1044 | QVector<int> drawn; | - |
1045 | bool multipleRects = (rects.size() > 1); | - |
1046 | for (int a = 0; a < rects.size(); ++a) { | - |
1047 | const QRect area = (multipleRects | - |
1048 | ? QRect(0, rects.at(a).y(), viewportWidth, rects.at(a).height()) | - |
1049 | : rects.at(a)); | - |
1050 | d->leftAndRight = d->startAndEndColumns(area); | - |
1051 | | - |
1052 | int i = firstVisibleItem; | - |
1053 | int y = firstVisibleItemOffset; | - |
1054 | | - |
1055 | | - |
1056 | for (; i < viewItems.count(); ++i) { | - |
1057 | const int itemHeight = d->itemHeight(i); | - |
1058 | if (y + itemHeight > area.top()) | - |
1059 | break; | - |
1060 | y += itemHeight; | - |
1061 | } | - |
1062 | | - |
1063 | | - |
1064 | for (; i < viewItems.count() && y <= area.bottom(); ++i) { | - |
1065 | const int itemHeight = d->itemHeight(i); | - |
1066 | option.rect.setRect(0, y, viewportWidth, itemHeight); | - |
1067 | option.state = state | (viewItems.at(i).expanded ? QStyle::State_Open : QStyle::State_None) | - |
1068 | | (viewItems.at(i).hasChildren ? QStyle::State_Children : QStyle::State_None) | - |
1069 | | (viewItems.at(i).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None); | - |
1070 | d->current = i; | - |
1071 | d->spanning = viewItems.at(i).spanning; | - |
1072 | if (!multipleRects || !drawn.contains(i)) { | - |
1073 | drawRow(painter, option, viewItems.at(i).index); | - |
1074 | if (multipleRects) | - |
1075 | drawn.append(i); | - |
1076 | } | - |
1077 | y += itemHeight; | - |
1078 | } | - |
1079 | | - |
1080 | if (y <= area.bottom()) { | - |
1081 | d->current = i; | - |
1082 | d->paintAlternatingRowColors(painter, &option, y, area.bottom()); | - |
1083 | } | - |
1084 | } | - |
1085 | } | - |
1086 | | - |
1087 | | - |
1088 | static inline bool ancestorOf(QObject *widget, QObject *other) | - |
1089 | { | - |
1090 | for (QObject *parent = other; parent != 0; parent = parent->parent()) { | - |
1091 | if (parent == widget) | - |
1092 | return true; | - |
1093 | } | - |
1094 | return false; | - |
1095 | } | - |
1096 | | - |
1097 | void QTreeViewPrivate::calcLogicalIndices(QVector<int> *logicalIndices, QVector<QStyleOptionViewItem::ViewItemPosition> *itemPositions, int left, int right) const | - |
1098 | { | - |
1099 | const int columnCount = header->count(); | - |
1100 | | - |
1101 | | - |
1102 | | - |
1103 | int logicalIndexBeforeLeft = -1, logicalIndexAfterRight = -1; | - |
1104 | for (int visualIndex = left - 1; visualIndex >= 0; --visualIndex) { | - |
1105 | int logicalIndex = header->logicalIndex(visualIndex); | - |
1106 | if (!header->isSectionHidden(logicalIndex)) { | - |
1107 | logicalIndexBeforeLeft = logicalIndex; | - |
1108 | break; | - |
1109 | } | - |
1110 | } | - |
1111 | | - |
1112 | for (int visualIndex = left; visualIndex < columnCount; ++visualIndex) { | - |
1113 | int logicalIndex = header->logicalIndex(visualIndex); | - |
1114 | if (!header->isSectionHidden(logicalIndex)) { | - |
1115 | if (visualIndex > right) { | - |
1116 | logicalIndexAfterRight = logicalIndex; | - |
1117 | break; | - |
1118 | } | - |
1119 | logicalIndices->append(logicalIndex); | - |
1120 | } | - |
1121 | } | - |
1122 | | - |
1123 | itemPositions->resize(logicalIndices->count()); | - |
1124 | for (int currentLogicalSection = 0; currentLogicalSection < logicalIndices->count(); ++currentLogicalSection) { | - |
1125 | const int headerSection = logicalIndices->at(currentLogicalSection); | - |
1126 | | - |
1127 | int nextLogicalSection = currentLogicalSection + 1 >= logicalIndices->count() | - |
1128 | ? logicalIndexAfterRight | - |
1129 | : logicalIndices->at(currentLogicalSection + 1); | - |
1130 | int prevLogicalSection = currentLogicalSection - 1 < 0 | - |
1131 | ? logicalIndexBeforeLeft | - |
1132 | : logicalIndices->at(currentLogicalSection - 1); | - |
1133 | QStyleOptionViewItem::ViewItemPosition pos; | - |
1134 | if (columnCount == 1 || (nextLogicalSection == 0 && prevLogicalSection == -1) | - |
1135 | || (headerSection == 0 && nextLogicalSection == -1) || spanning) | - |
1136 | pos = QStyleOptionViewItem::OnlyOne; | - |
1137 | else if (isTreePosition(headerSection) || (nextLogicalSection != 0 && prevLogicalSection == -1)) | - |
1138 | pos = QStyleOptionViewItem::Beginning; | - |
1139 | else if (nextLogicalSection == 0 || nextLogicalSection == -1) | - |
1140 | pos = QStyleOptionViewItem::End; | - |
1141 | else | - |
1142 | pos = QStyleOptionViewItem::Middle; | - |
1143 | (*itemPositions)[currentLogicalSection] = pos; | - |
1144 | } | - |
1145 | } | - |
1146 | | - |
1147 | | - |
1148 | | - |
1149 | | - |
1150 | | - |
1151 | int QTreeViewPrivate::widthHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option, int i) const | - |
1152 | { | - |
1153 | QWidget *editor = editorForIndex(index).widget.data(); | - |
1154 | if (editor && persistent.contains(editor)) { | - |
1155 | hint = qMax(hint, editor->sizeHint().width()); | - |
1156 | int min = editor->minimumSize().width(); | - |
1157 | int max = editor->maximumSize().width(); | - |
1158 | hint = qBound(min, hint, max); | - |
1159 | } | - |
1160 | int xhint = delegateForIndex(index)->sizeHint(option, index).width(); | - |
1161 | hint = qMax(hint, xhint + (isTreePosition(index.column()) ? indentationForItem(i) : 0)); | - |
1162 | return hint; | - |
1163 | } | - |
1164 | void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, | - |
1165 | const QModelIndex &index) const | - |
1166 | { | - |
1167 | const QTreeViewPrivate * const d = d_func(); | - |
1168 | QStyleOptionViewItem opt = option; | - |
1169 | const QPoint offset = d->scrollDelayOffset; | - |
1170 | const int y = option.rect.y() + offset.y(); | - |
1171 | const QModelIndex parent = index.parent(); | - |
1172 | const QHeaderView *header = d->header; | - |
1173 | const QModelIndex current = currentIndex(); | - |
1174 | const QModelIndex hover = d->hover; | - |
1175 | const bool reverse = isRightToLeft(); | - |
1176 | const QStyle::State state = opt.state; | - |
1177 | const bool spanning = d->spanning; | - |
1178 | const int left = (spanningTRUE | never evaluated | FALSE | never evaluated |
? header->visualIndex(0) : d->leftAndRight.first); | 0 |
1179 | const int right = (spanningTRUE | never evaluated | FALSE | never evaluated |
? header->visualIndex(0) : d->leftAndRight.second); | 0 |
1180 | const bool alternate = d->alternatingColors; | - |
1181 | const bool enabled = (state & QStyle::State_Enabled) != 0; | - |
1182 | const bool allColumnsShowFocus = d->allColumnsShowFocus; | - |
1183 | | - |
1184 | | - |
1185 | | - |
1186 | | - |
1187 | bool indexWidgetHasFocus = false; | - |
1188 | if ((TRUE | never evaluated | FALSE | never evaluated |
current.row() == index.row())TRUE | never evaluated | FALSE | never evaluated |
&& !d->editorIndexHash.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1189 | const int r = index.row(); | - |
1190 | QWidget *fw = QApplication::focusWidget(); | - |
1191 | for (int c = 0; c < header->count()TRUE | never evaluated | FALSE | never evaluated |
; ++c) { | 0 |
1192 | QModelIndex idx = d->model->index(r, c, parent); | - |
1193 | if (QWidget *editor = indexWidget(idx)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1194 | if (ancestorOf(editor, fw)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1195 | indexWidgetHasFocus = true; | - |
1196 | break; never executed: break; | 0 |
1197 | } | - |
1198 | } never executed: end of block | 0 |
1199 | } never executed: end of block | 0 |
1200 | } never executed: end of block | 0 |
1201 | | - |
1202 | const bool widgetHasFocus = hasFocus(); | - |
1203 | bool currentRowHasFocus = false; | - |
1204 | if (allColumnsShowFocusTRUE | never evaluated | FALSE | never evaluated |
&& widgetHasFocusTRUE | never evaluated | FALSE | never evaluated |
&& current.isValid()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1205 | | - |
1206 | const int r = index.row(); | - |
1207 | for (int c = 0; c < leftTRUE | never evaluated | FALSE | never evaluated |
&& !currentRowHasFocusTRUE | never evaluated | FALSE | never evaluated |
; ++c) { | 0 |
1208 | QModelIndex idx = d->model->index(r, c, parent); | - |
1209 | currentRowHasFocus = (idx == current); | - |
1210 | } never executed: end of block | 0 |
1211 | QModelIndex parent = d->model->parent(index); | - |
1212 | for (int c = right; c < header->count()TRUE | never evaluated | FALSE | never evaluated |
&& !currentRowHasFocusTRUE | never evaluated | FALSE | never evaluated |
; ++c) { | 0 |
1213 | currentRowHasFocus = (d->model->index(r, c, parent) == current); | - |
1214 | } never executed: end of block | 0 |
1215 | } never executed: end of block | 0 |
1216 | | - |
1217 | | - |
1218 | | - |
1219 | opt.showDecorationSelected = (TRUE | never evaluated | FALSE | never evaluated |
d->selectionBehavior & SelectRows)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1220 | || option.showDecorationSelectedTRUE | never evaluated | FALSE | never evaluated |
; | 0 |
1221 | | - |
1222 | int width, height = option.rect.height(); | - |
1223 | int position; | - |
1224 | QModelIndex modelIndex; | - |
1225 | const bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRowsTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1226 | && index.parent() == hover.parent()TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1227 | && index.row() == hover.row()TRUE | never evaluated | FALSE | never evaluated |
; | 0 |
1228 | | - |
1229 | QVector<int> logicalIndices; | - |
1230 | QVector<QStyleOptionViewItem::ViewItemPosition> viewItemPosList; | - |
1231 | d->calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right); | - |
1232 | | - |
1233 | for (int currentLogicalSection = 0; currentLogicalSection < logicalIndices.count()TRUE | never evaluated | FALSE | never evaluated |
; ++currentLogicalSection) { | 0 |
1234 | int headerSection = logicalIndices.at(currentLogicalSection); | - |
1235 | position = columnViewportPosition(headerSection) + offset.x(); | - |
1236 | width = header->sectionSize(headerSection); | - |
1237 | | - |
1238 | if (spanningTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1239 | int lastSection = header->logicalIndex(header->count() - 1); | - |
1240 | if (!reverseTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1241 | width = columnViewportPosition(lastSection) + header->sectionSize(lastSection) - position; | - |
1242 | } never executed: end of block else { | 0 |
1243 | width += position - columnViewportPosition(lastSection); | - |
1244 | position = columnViewportPosition(lastSection); | - |
1245 | } never executed: end of block | 0 |
1246 | } | - |
1247 | | - |
1248 | modelIndex = d->model->index(index.row(), headerSection, parent); | - |
1249 | if (!modelIndex.isValid()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1250 | continue; never executed: continue; | 0 |
1251 | opt.state = state; | - |
1252 | | - |
1253 | opt.viewItemPosition = viewItemPosList.at(currentLogicalSection); | - |
1254 | | - |
1255 | | - |
1256 | if (indexWidgetHasFocusTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1257 | opt.state |= QStyle::State_Active; never executed: opt.state |= QStyle::State_Active; | 0 |
1258 | | - |
1259 | if (d->selectionModel->isSelected(modelIndex)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1260 | opt.state |= QStyle::State_Selected; never executed: opt.state |= QStyle::State_Selected; | 0 |
1261 | if (widgetHasFocusTRUE | never evaluated | FALSE | never evaluated |
&& (TRUE | never evaluated | FALSE | never evaluated |
current == modelIndex)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1262 | if (allColumnsShowFocusTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1263 | currentRowHasFocus = true; never executed: currentRowHasFocus = true; | 0 |
1264 | else | - |
1265 | opt.state |= QStyle::State_HasFocus; never executed: opt.state |= QStyle::State_HasFocus; | 0 |
1266 | } | - |
1267 | if ((opt.state.setFlag(QStyle::State_MouseOver, | - |
1268 | (hoverRow || modelIndex == hover) | - |
1269 | && (option.showDecorationSelected || (d->hoverBranch == -1))) | - |
| opt.state |= QStyle::State_MouseOver; | |
| else | |
| opt.state &= ~QStyle::State_MouseOver;)); | |
1270 | | - |
1271 | if (enabledTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1272 | QPalette::ColorGroup cg; | - |
1273 | if ((TRUE | never evaluated | FALSE | never evaluated |
d->model->flags(modelIndex) & Qt::ItemIsEnabled) == 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1274 | opt.state &= ~QStyle::State_Enabled; | - |
1275 | cg = QPalette::Disabled; | - |
1276 | } never executed: end of block else if (opt.state & QStyle::State_ActiveTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1277 | cg = QPalette::Active; | - |
1278 | } never executed: end of block else { | 0 |
1279 | cg = QPalette::Inactive; | - |
1280 | } never executed: end of block | 0 |
1281 | opt.palette.setCurrentColorGroup(cg); | - |
1282 | } never executed: end of block | 0 |
1283 | | - |
1284 | if (alternate) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
| if (d->current & 1TRUE | never evaluated | FALSE | never evaluated |
) { | |
1285 | opt.features|= QStyleOptionViewItem::Alternate; | - |
| } else { | |
| opt.features &= ~setFlag(QStyleOptionViewItem::Alternate; | |
| }, d->current & 1); | |
1286 | } never executed: end of block | 0 |
1287 | | - |
1288 | | - |
1289 | | - |
1290 | | - |
1291 | | - |
1292 | if (d->isTreePosition(headerSection)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1293 | const int i = d->indentationForItem(d->current); | - |
1294 | QRect branches(reverse ? position + width - i : position, y, i, height); | - |
1295 | const bool setClipRect = branches.width() > width; | - |
1296 | if (setClipRectTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1297 | painter->save(); | - |
1298 | painter->setClipRect(QRect(position, y, width, height)); | - |
1299 | } never executed: end of block | 0 |
1300 | | - |
1301 | opt.rect = branches; | - |
1302 | style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this); | - |
1303 | | - |
1304 | | - |
1305 | | - |
1306 | QStyle::State oldState = opt.state; | - |
1307 | opt.state &= ~QStyle::State_Selected; | - |
1308 | opt.rect.setRect(reverse ? position : i + position, y, width - i, height); | - |
1309 | style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this); | - |
1310 | opt.state = oldState; | - |
1311 | | - |
1312 | if (d->indent != 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1313 | drawBranches(painter, branches, index); never executed: drawBranches(painter, branches, index); | 0 |
1314 | if (setClipRectTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1315 | painter->restore(); never executed: painter->restore(); | 0 |
1316 | } never executed: end of block else { | 0 |
1317 | QStyle::State oldState = opt.state; | - |
1318 | opt.state &= ~QStyle::State_Selected; | - |
1319 | opt.rect.setRect(position, y, width, height); | - |
1320 | style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this); | - |
1321 | opt.state = oldState; | - |
1322 | } never executed: end of block | 0 |
1323 | | - |
1324 | d->delegateForIndex(modelIndex)->paint(painter, opt, modelIndex); | - |
1325 | } never executed: end of block | 0 |
1326 | | - |
1327 | if (currentRowHasFocusTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1328 | QStyleOptionFocusRect o; | - |
1329 | o.QStyleOption::operator=(option); | - |
1330 | o.state |= QStyle::State_KeyboardFocusChange; | - |
1331 | QPalette::ColorGroup cg = (TRUE | never evaluated | FALSE | never evaluated |
option.state & QStyle::State_Enabled)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1332 | ? QPalette::Normal : QPalette::Disabled; | - |
1333 | o.backgroundColor = option.palette.color(cg, d->selectionModel->isSelected(index) | - |
1334 | ? QPalette::Highlight : QPalette::Background); | - |
1335 | int x = 0; | - |
1336 | if (!option.showDecorationSelectedTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1337 | x = header->sectionPosition(0) + d->indentationForItem(d->current); never executed: x = header->sectionPosition(0) + d->indentationForItem(d->current); | 0 |
1338 | QRect focusRect(x - header->offset(), y, header->length() - x, height); | - |
1339 | o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), focusRect); | - |
1340 | style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter); | - |
1341 | | - |
1342 | | - |
1343 | if (allColumnsShowFocusTRUE | never evaluated | FALSE | never evaluated |
&& !option.showDecorationSelectedTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1344 | && header->sectionsMoved()TRUE | never evaluated | FALSE | never evaluated |
&& (TRUE | never evaluated | FALSE | never evaluated |
header->visualIndex(0) != 0)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1345 | QRect sectionRect(0, y, header->sectionPosition(0), height); | - |
1346 | o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), sectionRect); | - |
1347 | style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter); | - |
1348 | } never executed: end of block | 0 |
1349 | } never executed: end of block | 0 |
1350 | } never executed: end of block | 0 |
1351 | | - |
1352 | | - |
1353 | | - |
1354 | | - |
1355 | | - |
1356 | | - |
1357 | void QTreeView::drawBranches(QPainter *painter, const QRect &rect, | - |
1358 | const QModelIndex &index) const | - |
1359 | { | - |
1360 | const QTreeViewPrivate * const d = d_func(); | - |
1361 | const bool reverse = isRightToLeft(); | - |
1362 | const int indent = d->indent; | - |
1363 | const int outer = d->rootDecorationTRUE | never evaluated | FALSE | never evaluated |
? 0 : 1; | 0 |
1364 | const int item = d->current; | - |
1365 | const QTreeViewItem &viewItem = d->viewItems.at(item); | - |
1366 | int level = viewItem.level; | - |
1367 | QRect primitive(reverse ? rect.left() : rect.right() + 1, rect.top(), indent, rect.height()); | - |
1368 | | - |
1369 | QModelIndex parent = index.parent(); | - |
1370 | QModelIndex current = parent; | - |
1371 | QModelIndex ancestor = current.parent(); | - |
1372 | | - |
1373 | QStyleOptionViewItem opt = viewOptions(); | - |
1374 | QStyle::State extraFlags = QStyle::State_None; | - |
1375 | if (isEnabled()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1376 | extraFlags |= QStyle::State_Enabled; never executed: extraFlags |= QStyle::State_Enabled; | 0 |
1377 | if (window()->isActiveWindow()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1378 | extraFlags |= QStyle::State_Active; never executed: extraFlags |= QStyle::State_Active; | 0 |
1379 | QPoint oldBO = painter->brushOrigin(); | - |
1380 | if (verticalScrollMode() == QAbstractItemView::ScrollPerPixelTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1381 | painter->setBrushOrigin(QPoint(0, verticalOffset())); never executed: painter->setBrushOrigin(QPoint(0, verticalOffset())); | 0 |
1382 | | - |
1383 | if (d->alternatingColors) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
| if (d->current & 1TRUE | never evaluated | FALSE | never evaluated |
) { | |
1384 | opt.features|= QStyleOptionViewItem::Alternate; | - |
| } else { | |
| opt.features &= ~setFlag(QStyleOptionViewItem::Alternate; | |
| }, d->current & 1); | |
1385 | } never executed: end of block | 0 |
1386 | | - |
1387 | | - |
1388 | | - |
1389 | bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRowsTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1390 | && opt.showDecorationSelectedTRUE | never evaluated | FALSE | never evaluated |
| 0 |
1391 | && index.parent() == d->hover.parent()TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1392 | && index.row() == d->hover.row()TRUE | never evaluated | FALSE | never evaluated |
; | 0 |
1393 | | - |
1394 | if (d->selectionModel->isSelected(index)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1395 | extraFlags |= QStyle::State_Selected; never executed: extraFlags |= QStyle::State_Selected; | 0 |
1396 | | - |
1397 | if (level >= outerTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1398 | | - |
1399 | primitive.moveLeft(reverse ? primitive.left() : primitive.left() - indent); | - |
1400 | opt.rect = primitive; | - |
1401 | | - |
1402 | const bool expanded = viewItem.expanded; | - |
1403 | const bool children = viewItem.hasChildren; | - |
1404 | bool moreSiblings = viewItem.hasMoreSiblings; | - |
1405 | | - |
1406 | opt.state = QStyle::State_Item | extraFlags | - |
1407 | | (moreSiblings ? QStyle::State_Sibling : QStyle::State_None) | - |
1408 | | (children ? QStyle::State_Children : QStyle::State_None) | - |
1409 | | (expanded ? QStyle::State_Open : QStyle::State_None); | - |
1410 | ifopt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch) | - |
| opt.state |= QStyle::State_MouseOver; | |
| else | |
| opt.state &= ~QStyle::State_MouseOver;); | |
1411 | | - |
1412 | style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this); | - |
1413 | } never executed: end of block | 0 |
1414 | | - |
1415 | for (--level; level >= outerTRUE | never evaluated | FALSE | never evaluated |
; --level) { | 0 |
1416 | primitive.moveLeft(reverse ? primitive.left() + indent : primitive.left() - indent); | - |
1417 | opt.rect = primitive; | - |
1418 | opt.state = extraFlags; | - |
1419 | bool moreSiblings = false; | - |
1420 | if (d->hiddenIndexes.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1421 | moreSiblings = (d->model->rowCount(ancestor) - 1 > current.row()); | - |
1422 | } never executed: end of block else { | 0 |
1423 | int successor = item + viewItem.total + 1; | - |
1424 | while (successor < d->viewItems.size()TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1425 | && d->viewItems.at(successor).level >= uint(level)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1426 | const QTreeViewItem &successorItem = d->viewItems.at(successor); | - |
1427 | if (successorItem.level == uint(level)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1428 | moreSiblings = true; | - |
1429 | break; never executed: break; | 0 |
1430 | } | - |
1431 | successor += successorItem.total + 1; | - |
1432 | } never executed: end of block | 0 |
1433 | } never executed: end of block | 0 |
1434 | if (moreSiblingsTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1435 | opt.state |= QStyle::State_Sibling; never executed: opt.state |= QStyle::State_Sibling; | 0 |
1436 | ifopt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch) | - |
| opt.state |= QStyle::State_MouseOver; | |
| else | |
| opt.state &= ~QStyle::State_MouseOver;); | |
1437 | | - |
1438 | style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this); | - |
1439 | current = ancestor; | - |
1440 | ancestor = current.parent(); | - |
1441 | } never executed: end of block | 0 |
1442 | painter->setBrushOrigin(oldBO); | - |
1443 | } never executed: end of block | 0 |
1444 | | - |
1445 | | - |
1446 | | - |
1447 | | - |
1448 | void QTreeView::mousePressEvent(QMouseEvent *event) | - |
1449 | { | - |
1450 | QTreeViewPrivate * const d = d_func(); | - |
1451 | bool handled = false; | - |
1452 | if (style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, 0, this) == QEvent::MouseButtonPress) | - |
1453 | handled = d->expandOrCollapseItemAtPos(event->pos()); | - |
1454 | if (!handled && d->itemDecorationAt(event->pos()) == -1) | - |
1455 | QAbstractItemView::mousePressEvent(event); | - |
1456 | } | - |
1457 | | - |
1458 | | - |
1459 | | - |
1460 | | - |
1461 | void QTreeView::mouseReleaseEvent(QMouseEvent *event) | - |
1462 | { | - |
1463 | QTreeViewPrivate * const d = d_func(); | - |
1464 | if (d->itemDecorationAt(event->pos()) == -1) { | - |
1465 | QAbstractItemView::mouseReleaseEvent(event); | - |
1466 | } else { | - |
1467 | if (state() == QAbstractItemView::DragSelectingState || state() == QAbstractItemView::DraggingState) | - |
1468 | setState(QAbstractItemView::NoState); | - |
1469 | if (style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, 0, this) == QEvent::MouseButtonRelease) | - |
1470 | d->expandOrCollapseItemAtPos(event->pos()); | - |
1471 | } | - |
1472 | } | - |
1473 | | - |
1474 | | - |
1475 | | - |
1476 | | - |
1477 | void QTreeView::mouseDoubleClickEvent(QMouseEvent *event) | - |
1478 | { | - |
1479 | QTreeViewPrivate * const d = d_func(); | - |
1480 | if (state() != NoState || !d->viewport->rect().contains(event->pos())) | - |
1481 | return; | - |
1482 | | - |
1483 | int i = d->itemDecorationAt(event->pos()); | - |
1484 | if (i == -1) { | - |
1485 | i = d->itemAtCoordinate(event->y()); | - |
1486 | if (i == -1) | - |
1487 | return; | - |
1488 | | - |
1489 | const QPersistentModelIndex firstColumnIndex = d->viewItems.at(i).index; | - |
1490 | const QPersistentModelIndex persistent = indexAt(event->pos()); | - |
1491 | | - |
1492 | if (d->pressedIndex != persistent) { | - |
1493 | mousePressEvent(event); | - |
1494 | return; | - |
1495 | } | - |
1496 | | - |
1497 | | - |
1498 | doubleClicked(persistent); | - |
1499 | | - |
1500 | if (!persistent.isValid()) | - |
1501 | return; | - |
1502 | | - |
1503 | if (edit(persistent, DoubleClicked, event) || state() != NoState) | - |
1504 | return; | - |
1505 | | - |
1506 | if (!style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this)) | - |
1507 | activated(persistent); | - |
1508 | | - |
1509 | d->executePostedLayout(); | - |
1510 | if (d->itemsExpandable | - |
1511 | && d->expandsOnDoubleClick | - |
1512 | && d->hasVisibleChildren(persistent)) { | - |
1513 | if (!((i < d->viewItems.count()) && (d->viewItems.at(i).index == firstColumnIndex))) { | - |
1514 | | - |
1515 | for (i = 0; i < d->viewItems.count(); ++i) { | - |
1516 | if (d->viewItems.at(i).index == firstColumnIndex) | - |
1517 | break; | - |
1518 | } | - |
1519 | if (i == d->viewItems.count()) | - |
1520 | return; | - |
1521 | } | - |
1522 | if (d->viewItems.at(i).expanded) | - |
1523 | d->collapse(i, true); | - |
1524 | else | - |
1525 | d->expand(i, true); | - |
1526 | updateGeometries(); | - |
1527 | viewport()->update(); | - |
1528 | } | - |
1529 | } | - |
1530 | } | - |
1531 | | - |
1532 | | - |
1533 | | - |
1534 | | - |
1535 | void QTreeView::mouseMoveEvent(QMouseEvent *event) | - |
1536 | { | - |
1537 | QTreeViewPrivate * const d = d_func(); | - |
1538 | if (d->itemDecorationAt(event->pos()) == -1) | - |
1539 | QAbstractItemView::mouseMoveEvent(event); | - |
1540 | } | - |
1541 | | - |
1542 | | - |
1543 | | - |
1544 | | - |
1545 | void QTreeView::keyPressEvent(QKeyEvent *event) | - |
1546 | { | - |
1547 | QTreeViewPrivate * const d = d_func(); | - |
1548 | QModelIndex current = currentIndex(); | - |
1549 | | - |
1550 | if (d->isIndexValid(current) && d->model && d->itemsExpandable) { | - |
1551 | switch (event->key()) { | - |
1552 | case Qt::Key_Asterisk: { | - |
1553 | QStack<QModelIndex> parents; | - |
1554 | parents.push(current); | - |
1555 | while (!parents.isEmpty()) { | - |
1556 | QModelIndex parent = parents.pop(); | - |
1557 | for (int row = 0; row < d->model->rowCount(parent); ++row) { | - |
1558 | QModelIndex child = d->model->index(row, 0, parent); | - |
1559 | if (!d->isIndexValid(child)) | - |
1560 | break; | - |
1561 | parents.push(child); | - |
1562 | expand(child); | - |
1563 | } | - |
1564 | } | - |
1565 | expand(current); | - |
1566 | break; } | - |
1567 | case Qt::Key_Plus: | - |
1568 | expand(current); | - |
1569 | break; | - |
1570 | case Qt::Key_Minus: | - |
1571 | collapse(current); | - |
1572 | break; | - |
1573 | } | - |
1574 | } | - |
1575 | | - |
1576 | QAbstractItemView::keyPressEvent(event); | - |
1577 | } | - |
1578 | | - |
1579 | | - |
1580 | | - |
1581 | | - |
1582 | QModelIndex QTreeView::indexAt(const QPoint &point) const | - |
1583 | { | - |
1584 | const QTreeViewPrivate * const d = d_func(); | - |
1585 | d->executePostedLayout(); | - |
1586 | | - |
1587 | int visualIndex = d->itemAtCoordinate(point.y()); | - |
1588 | QModelIndex idx = d->modelIndex(visualIndex); | - |
1589 | if (!idx.isValid()) | - |
1590 | return QModelIndex(); | - |
1591 | | - |
1592 | if (d->viewItems.at(visualIndex).spanning) | - |
1593 | return idx; | - |
1594 | | - |
1595 | int column = d->columnAt(point.x()); | - |
1596 | if (column == idx.column()) | - |
1597 | return idx; | - |
1598 | if (column < 0) | - |
1599 | return QModelIndex(); | - |
1600 | return idx.sibling(idx.row(), column); | - |
1601 | } | - |
1602 | | - |
1603 | | - |
1604 | | - |
1605 | | - |
1606 | QModelIndex QTreeView::indexAbove(const QModelIndex &index) const | - |
1607 | { | - |
1608 | const QTreeViewPrivate * const d = d_func(); | - |
1609 | if (!d->isIndexValid(index)) | - |
1610 | return QModelIndex(); | - |
1611 | d->executePostedLayout(); | - |
1612 | int i = d->viewIndex(index); | - |
1613 | if (--i < 0) | - |
1614 | return QModelIndex(); | - |
1615 | const QModelIndex firstColumnIndex = d->viewItems.at(i).index; | - |
1616 | return firstColumnIndex.sibling(firstColumnIndex.row(), index.column()); | - |
1617 | } | - |
1618 | | - |
1619 | | - |
1620 | | - |
1621 | | - |
1622 | QModelIndex QTreeView::indexBelow(const QModelIndex &index) const | - |
1623 | { | - |
1624 | const QTreeViewPrivate * const d = d_func(); | - |
1625 | if (!d->isIndexValid(index)) | - |
1626 | return QModelIndex(); | - |
1627 | d->executePostedLayout(); | - |
1628 | int i = d->viewIndex(index); | - |
1629 | if (++i >= d->viewItems.count()) | - |
1630 | return QModelIndex(); | - |
1631 | const QModelIndex firstColumnIndex = d->viewItems.at(i).index; | - |
1632 | return firstColumnIndex.sibling(firstColumnIndex.row(), index.column()); | - |
1633 | } | - |
1634 | | - |
1635 | | - |
1636 | | - |
1637 | | - |
1638 | | - |
1639 | | - |
1640 | void QTreeView::doItemsLayout() | - |
1641 | { | - |
1642 | QTreeViewPrivate * const d = d_func(); | - |
1643 | if (!d->customIndent) { | - |
1644 | | - |
1645 | | - |
1646 | | - |
1647 | d->updateIndentationFromStyle(); | - |
1648 | } | - |
1649 | if (d->hasRemovedItems) { | - |
1650 | | - |
1651 | d->hasRemovedItems = false; | - |
1652 | QSet<QPersistentModelIndex>::iterator it = d->expandedIndexes.begin(); | - |
1653 | while (it != d->expandedIndexes.end()) { | - |
1654 | if (!it->isValid()) | - |
1655 | it = d->expandedIndexes.erase(it); | - |
1656 | else | - |
1657 | ++it; | - |
1658 | } | - |
1659 | it = d->hiddenIndexes.begin(); | - |
1660 | while (it != d->hiddenIndexes.end()) { | - |
1661 | if (!it->isValid()) | - |
1662 | it = d->hiddenIndexes.erase(it); | - |
1663 | else | - |
1664 | ++it; | - |
1665 | } | - |
1666 | } | - |
1667 | d->viewItems.clear(); | - |
1668 | QModelIndex parent = d->root; | - |
1669 | if (d->model->hasChildren(parent)) { | - |
1670 | d->layout(-1); | - |
1671 | } | - |
1672 | QAbstractItemView::doItemsLayout(); | - |
1673 | d->header->doItemsLayout(); | - |
1674 | } | - |
1675 | | - |
1676 | | - |
1677 | | - |
1678 | | - |
1679 | void QTreeView::reset() | - |
1680 | { | - |
1681 | QTreeViewPrivate * const d = d_func(); | - |
1682 | d->expandedIndexes.clear(); | - |
1683 | d->hiddenIndexes.clear(); | - |
1684 | d->spanningIndexes.clear(); | - |
1685 | d->viewItems.clear(); | - |
1686 | QAbstractItemView::reset(); | - |
1687 | } | - |
1688 | int QTreeView::horizontalOffset() const | - |
1689 | { | - |
1690 | const QTreeViewPrivate * const d = d_func(); | - |
1691 | return d->header->offset(); | - |
1692 | } | - |
1693 | | - |
1694 | | - |
1695 | | - |
1696 | | - |
1697 | | - |
1698 | | - |
1699 | int QTreeView::verticalOffset() const | - |
1700 | { | - |
1701 | const QTreeViewPrivate * const d = d_func(); | - |
1702 | if (d->verticalScrollMode == QAbstractItemView::ScrollPerItem) { | - |
1703 | if (d->uniformRowHeights) | - |
1704 | return verticalScrollBar()->value() * d->defaultItemHeight; | - |
1705 | | - |
1706 | | - |
1707 | | - |
1708 | d->executePostedLayout(); | - |
1709 | int offset = 0; | - |
1710 | for (int i = 0; i < d->viewItems.count(); ++i) { | - |
1711 | if (i == verticalScrollBar()->value()) | - |
1712 | return offset; | - |
1713 | offset += d->itemHeight(i); | - |
1714 | } | - |
1715 | return 0; | - |
1716 | } | - |
1717 | | - |
1718 | return verticalScrollBar()->value(); | - |
1719 | } | - |
1720 | | - |
1721 | | - |
1722 | | - |
1723 | | - |
1724 | | - |
1725 | QModelIndex QTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) | - |
1726 | { | - |
1727 | QTreeViewPrivate * const d = d_func(); | - |
1728 | (void)modifiers;; | - |
1729 | | - |
1730 | d->executePostedLayout(); | - |
1731 | | - |
1732 | QModelIndex current = currentIndex(); | - |
1733 | if (!current.isValid()) { | - |
1734 | int i = d->below(-1); | - |
1735 | int c = 0; | - |
1736 | while (c < d->header->count() && d->header->isSectionHidden(d->header->logicalIndex(c))) | - |
1737 | ++c; | - |
1738 | if (i < d->viewItems.count() && c < d->header->count()) { | - |
1739 | return d->modelIndex(i, d->header->logicalIndex(c)); | - |
1740 | } | - |
1741 | return QModelIndex(); | - |
1742 | } | - |
1743 | int vi = -1; | - |
1744 | if (vi < 0) | - |
1745 | vi = qMax(0, d->viewIndex(current)); | - |
1746 | | - |
1747 | if (isRightToLeft()) { | - |
1748 | if (cursorAction == MoveRight) | - |
1749 | cursorAction = MoveLeft; | - |
1750 | else if (cursorAction == MoveLeft) | - |
1751 | cursorAction = MoveRight; | - |
1752 | } | - |
1753 | switch (cursorAction) { | - |
1754 | case MoveNext: | - |
1755 | case MoveDown: | - |
1756 | | - |
1757 | | - |
1758 | | - |
1759 | | - |
1760 | return d->modelIndex(d->below(vi), current.column()); | - |
1761 | case MovePrevious: | - |
1762 | case MoveUp: | - |
1763 | | - |
1764 | | - |
1765 | | - |
1766 | | - |
1767 | return d->modelIndex(d->above(vi), current.column()); | - |
1768 | case MoveLeft: { | - |
1769 | QScrollBar *sb = horizontalScrollBar(); | - |
1770 | if (vi < d->viewItems.count() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) { | - |
1771 | d->collapse(vi, true); | - |
1772 | d->moveCursorUpdatedView = true; | - |
1773 | } else { | - |
1774 | bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, this); | - |
1775 | if (descend) { | - |
1776 | QModelIndex par = current.parent(); | - |
1777 | if (par.isValid() && par != rootIndex()) | - |
1778 | return par; | - |
1779 | else | - |
1780 | descend = false; | - |
1781 | } | - |
1782 | if (!descend) { | - |
1783 | if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) { | - |
1784 | int visualColumn = d->header->visualIndex(current.column()) - 1; | - |
1785 | while (visualColumn >= 0 && isColumnHidden(d->header->logicalIndex(visualColumn))) | - |
1786 | visualColumn--; | - |
1787 | int newColumn = d->header->logicalIndex(visualColumn); | - |
1788 | QModelIndex next = current.sibling(current.row(), newColumn); | - |
1789 | if (next.isValid()) | - |
1790 | return next; | - |
1791 | } | - |
1792 | | - |
1793 | int oldValue = sb->value(); | - |
1794 | sb->setValue(sb->value() - sb->singleStep()); | - |
1795 | if (oldValue != sb->value()) | - |
1796 | d->moveCursorUpdatedView = true; | - |
1797 | } | - |
1798 | | - |
1799 | } | - |
1800 | updateGeometries(); | - |
1801 | viewport()->update(); | - |
1802 | break; | - |
1803 | } | - |
1804 | case MoveRight: | - |
1805 | if (vi < d->viewItems.count() && !d->viewItems.at(vi).expanded && d->itemsExpandable | - |
1806 | && d->hasVisibleChildren(d->viewItems.at(vi).index)) { | - |
1807 | d->expand(vi, true); | - |
1808 | d->moveCursorUpdatedView = true; | - |
1809 | } else { | - |
1810 | bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, this); | - |
1811 | if (descend) { | - |
1812 | QModelIndex idx = d->modelIndex(d->below(vi)); | - |
1813 | if (idx.parent() == current) | - |
1814 | return idx; | - |
1815 | else | - |
1816 | descend = false; | - |
1817 | } | - |
1818 | if (!descend) { | - |
1819 | if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) { | - |
1820 | int visualColumn = d->header->visualIndex(current.column()) + 1; | - |
1821 | while (visualColumn < d->model->columnCount(current.parent()) && isColumnHidden(d->header->logicalIndex(visualColumn))) | - |
1822 | visualColumn++; | - |
1823 | const int newColumn = d->header->logicalIndex(visualColumn); | - |
1824 | const QModelIndex next = current.sibling(current.row(), newColumn); | - |
1825 | if (next.isValid()) | - |
1826 | return next; | - |
1827 | } | - |
1828 | | - |
1829 | | - |
1830 | QScrollBar *sb = horizontalScrollBar(); | - |
1831 | int oldValue = sb->value(); | - |
1832 | sb->setValue(sb->value() + sb->singleStep()); | - |
1833 | if (oldValue != sb->value()) | - |
1834 | d->moveCursorUpdatedView = true; | - |
1835 | } | - |
1836 | } | - |
1837 | updateGeometries(); | - |
1838 | viewport()->update(); | - |
1839 | break; | - |
1840 | case MovePageUp: | - |
1841 | return d->modelIndex(d->pageUp(vi), current.column()); | - |
1842 | case MovePageDown: | - |
1843 | return d->modelIndex(d->pageDown(vi), current.column()); | - |
1844 | case MoveHome: | - |
1845 | return d->model->index(0, current.column(), d->root); | - |
1846 | case MoveEnd: | - |
1847 | return d->modelIndex(d->viewItems.count() - 1, current.column()); | - |
1848 | } | - |
1849 | return current; | - |
1850 | } | - |
1851 | | - |
1852 | | - |
1853 | | - |
1854 | | - |
1855 | | - |
1856 | | - |
1857 | | - |
1858 | void QTreeView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) | - |
1859 | { | - |
1860 | QTreeViewPrivate * const d = d_func(); | - |
1861 | if (!selectionModel()TRUE | never evaluated | FALSE | never evaluated |
|| rect.isNull()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1862 | return; never executed: return; | 0 |
1863 | | - |
1864 | d->executePostedLayout(); | - |
1865 | QPoint tl(isRightToLeft() ? qMax(rect.left(), rect.right()) | - |
1866 | : qMin(rect.left(), rect.right()), qMin(rect.top(), rect.bottom())); | - |
1867 | QPoint br(isRightToLeft() ? qMin(rect.left(), rect.right()) : | - |
1868 | qMax(rect.left(), rect.right()), qMax(rect.top(), rect.bottom())); | - |
1869 | QModelIndex topLeft = indexAt(tl); | - |
1870 | QModelIndex bottomRight = indexAt(br); | - |
1871 | if (!topLeft.isValid()TRUE | never evaluated | FALSE | never evaluated |
&& !bottomRight.isValid()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1872 | if (command & QItemSelectionModel::ClearTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1873 | selectionModel()->clear(); never executed: selectionModel()->clear(); | 0 |
1874 | return; never executed: return; | 0 |
1875 | } | - |
1876 | if (!topLeft.isValid()TRUE | never evaluated | FALSE | never evaluated |
&& !d->viewItems.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1877 | topLeft = d->viewItems.firstconstFirst().index; never executed: topLeft = d->viewItems.constFirst().index; | 0 |
1878 | if (!bottomRight.isValid()TRUE | never evaluated | FALSE | never evaluated |
&& !d->viewItems.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1879 | const int column = d->header->logicalIndex(d->header->count() - 1); | - |
1880 | const QModelIndex index = d->viewItems.lastconstLast().index; | - |
1881 | bottomRight = index.sibling(index.row(), column); | - |
1882 | } never executed: end of block | 0 |
1883 | | - |
1884 | if (!d->isIndexEnabled(topLeft)TRUE | never evaluated | FALSE | never evaluated |
|| !d->isIndexEnabled(bottomRight)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1885 | return; never executed: return; | 0 |
1886 | | - |
1887 | d->select(topLeft, bottomRight, command); | - |
1888 | } never executed: end of block | 0 |
1889 | QRegion QTreeView::visualRegionForSelection(const QItemSelection &selection) const | - |
1890 | { | - |
1891 | const QTreeViewPrivate * const d = d_func(); | - |
1892 | if (selection.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1893 | return never executed: return QRegion(); QRegion();never executed: return QRegion(); | 0 |
1894 | | - |
1895 | QRegion selectionRegion; | - |
1896 | const QRect &viewportRect = d->viewport->rect(); | - |
1897 | for (int i = 0; i <const auto &range : selection.count(); ++i) { | - |
1898 | QItemSelectionRange range = selection.at(i);if (!range.isValid()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1899 | continue; never executed: continue; | 0 |
1900 | QModelIndex parent = range.parent(); | - |
1901 | QModelIndex leftIndex = range.topLeft(); | - |
1902 | int columnCount = d->model->columnCount(parent); | - |
1903 | while (leftIndex.isValid()TRUE | never evaluated | FALSE | never evaluated |
&& isIndexHidden(leftIndex)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1904 | if (leftIndex.column() + 1 < columnCountTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1905 | leftIndex = d->model->index(leftIndex.row(), leftIndex.column() + 1, parent); never executed: leftIndex = d->model->index(leftIndex.row(), leftIndex.column() + 1, parent); | 0 |
1906 | else | - |
1907 | leftIndex = QModelIndex(); never executed: leftIndex = QModelIndex(); | 0 |
1908 | } | - |
1909 | if (!leftIndex.isValid()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1910 | continue; never executed: continue; | 0 |
1911 | const QRect leftRect = visualRect(leftIndex); | - |
1912 | int top = leftRect.top(); | - |
1913 | QModelIndex rightIndex = range.bottomRight(); | - |
1914 | while (rightIndex.isValid()TRUE | never evaluated | FALSE | never evaluated |
&& isIndexHidden(rightIndex)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1915 | if (rightIndex.column() - 1 >= 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1916 | rightIndex = d->model->index(rightIndex.row(), rightIndex.column() - 1, parent); never executed: rightIndex = d->model->index(rightIndex.row(), rightIndex.column() - 1, parent); | 0 |
1917 | else | - |
1918 | rightIndex = QModelIndex(); never executed: rightIndex = QModelIndex(); | 0 |
1919 | } | - |
1920 | if (!rightIndex.isValid()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1921 | continue; never executed: continue; | 0 |
1922 | const QRect rightRect = visualRect(rightIndex); | - |
1923 | int bottom = rightRect.bottom(); | - |
1924 | if (top > bottomTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1925 | qSwap<int>(top, bottom); never executed: qSwap<int>(top, bottom); | 0 |
1926 | int height = bottom - top + 1; | - |
1927 | if (d->header->sectionsMoved()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1928 | for (int c = range.left(); c <= range.right()TRUE | never evaluated | FALSE | never evaluated |
; ++c) { | 0 |
1929 | const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height); | - |
1930 | if (viewportRect.intersects(rangeRect)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1931 | selectionRegion += rangeRect; never executed: selectionRegion += rangeRect; | 0 |
1932 | } never executed: end of block | 0 |
1933 | } never executed: end of block else { | 0 |
1934 | QRect combined = leftRect|rightRect; | - |
1935 | combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left())); | - |
1936 | if (viewportRect.intersects(combined)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1937 | selectionRegion += combined; never executed: selectionRegion += combined; | 0 |
1938 | } never executed: end of block | 0 |
1939 | } | - |
1940 | return never executed: return selectionRegion; selectionRegion;never executed: return selectionRegion; | 0 |
1941 | } | - |
1942 | | - |
1943 | | - |
1944 | | - |
1945 | | - |
1946 | QModelIndexList QTreeView::selectedIndexes() const | - |
1947 | { | - |
1948 | QModelIndexList viewSelected; | - |
1949 | QModelIndexList modelSelected; | - |
1950 | if (selectionModel()) | - |
1951 | modelSelected = selectionModel()->selectedIndexes(); | - |
1952 | for (int i = 0; i < modelSelected.count(); ++i) { | - |
1953 | | - |
1954 | QModelIndex index = modelSelected.at(i); | - |
1955 | while (index.isValid() && !isIndexHidden(index)) | - |
1956 | index = index.parent(); | - |
1957 | if (index.isValid()) | - |
1958 | continue; | - |
1959 | viewSelected.append(modelSelected.at(i)); | - |
1960 | } | - |
1961 | return viewSelected; | - |
1962 | } | - |
1963 | | - |
1964 | | - |
1965 | | - |
1966 | | - |
1967 | void QTreeView::scrollContentsBy(int dx, int dy) | - |
1968 | { | - |
1969 | QTreeViewPrivate * const d = d_func(); | - |
1970 | | - |
1971 | d->delayedAutoScroll.stop(); | - |
1972 | | - |
1973 | dx = isRightToLeft() ? -dx : dx; | - |
1974 | if (dx) { | - |
1975 | int oldOffset = d->header->offset(); | - |
1976 | d->header->d_func()->setScrollOffset(horizontalScrollBar(), horizontalScrollMode()); | - |
1977 | if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) { | - |
1978 | int newOffset = d->header->offset(); | - |
1979 | dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset; | - |
1980 | } | - |
1981 | } | - |
1982 | | - |
1983 | const int itemHeight = d->defaultItemHeight <= 0 ? sizeHintForRow(0) : d->defaultItemHeight; | - |
1984 | if (d->viewItems.isEmpty() || itemHeight == 0) | - |
1985 | return; | - |
1986 | | - |
1987 | | - |
1988 | int viewCount = d->viewport->height() / itemHeight; | - |
1989 | int maxDeltaY = qMin(d->viewItems.count(), viewCount); | - |
1990 | | - |
1991 | if (qAbs(dy) > qAbs(maxDeltaY) && d->editorIndexHash.isEmpty()) { | - |
1992 | verticalScrollBar()->update(); | - |
1993 | d->viewport->update(); | - |
1994 | return; | - |
1995 | } | - |
1996 | | - |
1997 | if (dy && verticalScrollMode() == QAbstractItemView::ScrollPerItem) { | - |
1998 | int currentScrollbarValue = verticalScrollBar()->value(); | - |
1999 | int previousScrollbarValue = currentScrollbarValue + dy; | - |
2000 | int currentViewIndex = currentScrollbarValue; | - |
2001 | int previousViewIndex = previousScrollbarValue; | - |
2002 | const QVector<QTreeViewItem> viewItems = d->viewItems; | - |
2003 | dy = 0; | - |
2004 | if (previousViewIndex < currentViewIndex) { | - |
2005 | for (int i = previousViewIndex; i < currentViewIndex; ++i) { | - |
2006 | if (i < d->viewItems.count()) | - |
2007 | dy -= d->itemHeight(i); | - |
2008 | } | - |
2009 | } else if (previousViewIndex > currentViewIndex) { | - |
2010 | for (int i = previousViewIndex - 1; i >= currentViewIndex; --i) { | - |
2011 | if (i < d->viewItems.count()) | - |
2012 | dy += d->itemHeight(i); | - |
2013 | } | - |
2014 | } | - |
2015 | } | - |
2016 | | - |
2017 | d->scrollContentsBy(dx, dy); | - |
2018 | } | - |
2019 | | - |
2020 | | - |
2021 | | - |
2022 | | - |
2023 | void QTreeView::columnMoved() | - |
2024 | { | - |
2025 | QTreeViewPrivate * const d = d_func(); | - |
2026 | updateEditorGeometries(); | - |
2027 | d->viewport->update(); | - |
2028 | } | - |
2029 | | - |
2030 | | - |
2031 | | - |
2032 | | - |
2033 | void QTreeView::reexpand() | - |
2034 | { | - |
2035 | | - |
2036 | } | - |
2037 | | - |
2038 | | - |
2039 | | - |
2040 | | - |
2041 | | - |
2042 | void QTreeView::rowsInserted(const QModelIndex &parent, int start, int end) | - |
2043 | { | - |
2044 | QTreeViewPrivate * const d = d_func(); | - |
2045 | | - |
2046 | if (d->delayedPendingLayout) { | - |
2047 | QAbstractItemView::rowsInserted(parent, start, end); | - |
2048 | return; | - |
2049 | } | - |
2050 | | - |
2051 | | - |
2052 | if (parent.column() != 0 && parent.isValid()) { | - |
2053 | QAbstractItemView::rowsInserted(parent, start, end); | - |
2054 | return; | - |
2055 | } | - |
2056 | | - |
2057 | const int parentRowCount = d->model->rowCount(parent); | - |
2058 | const int delta = end - start + 1; | - |
2059 | if (parent != d->root && !d->isIndexExpanded(parent) && parentRowCount > delta) { | - |
2060 | QAbstractItemView::rowsInserted(parent, start, end); | - |
2061 | return; | - |
2062 | } | - |
2063 | | - |
2064 | const int parentItem = d->viewIndex(parent); | - |
2065 | if (((parentItem != -1) && d->viewItems.at(parentItem).expanded) | - |
2066 | || (parent == d->root)) { | - |
2067 | d->doDelayedItemsLayout(); | - |
2068 | } else if (parentItem != -1 && parentRowCount == delta) { | - |
2069 | | - |
2070 | d->viewItems[parentItem].hasChildren = true; | - |
2071 | viewport()->update(); | - |
2072 | } | - |
2073 | QAbstractItemView::rowsInserted(parent, start, end); | - |
2074 | } | - |
2075 | | - |
2076 | | - |
2077 | | - |
2078 | | - |
2079 | | - |
2080 | void QTreeView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) | - |
2081 | { | - |
2082 | QTreeViewPrivate * const d = d_func(); | - |
2083 | QAbstractItemView::rowsAboutToBeRemoved(parent, start, end); | - |
2084 | d->viewItems.clear(); | - |
2085 | } | - |
2086 | | - |
2087 | | - |
2088 | | - |
2089 | | - |
2090 | | - |
2091 | | - |
2092 | | - |
2093 | void QTreeView::rowsRemoved(const QModelIndex &parent, int start, int end) | - |
2094 | { | - |
2095 | QTreeViewPrivate * const d = d_func(); | - |
2096 | d->viewItems.clear(); | - |
2097 | d->doDelayedItemsLayout(); | - |
2098 | d->hasRemovedItems = true; | - |
2099 | d->_q_rowsRemoved(parent, start, end); | - |
2100 | } | - |
2101 | | - |
2102 | | - |
2103 | | - |
2104 | | - |
2105 | | - |
2106 | void QTreeView::columnCountChanged(int oldCount, int newCount) | - |
2107 | { | - |
2108 | QTreeViewPrivate * const d = d_func(); | - |
2109 | if (oldCount == 0 && newCount > 0) { | - |
2110 | | - |
2111 | d->doDelayedItemsLayout(); | - |
2112 | } | - |
2113 | | - |
2114 | if (isVisible()) | - |
2115 | updateGeometries(); | - |
2116 | viewport()->update(); | - |
2117 | } | - |
2118 | | - |
2119 | | - |
2120 | | - |
2121 | | - |
2122 | | - |
2123 | | - |
2124 | void QTreeView::resizeColumnToContents(int column) | - |
2125 | { | - |
2126 | QTreeViewPrivate * const d = d_func(); | - |
2127 | d->executePostedLayout(); | - |
2128 | if (column < 0 || column >= d->header->count()) | - |
2129 | return; | - |
2130 | int contents = sizeHintForColumn(column); | - |
2131 | int header = d->header->isHidden() ? 0 : d->header->sectionSizeHint(column); | - |
2132 | d->header->resizeSection(column, qMax(contents, header)); | - |
2133 | } | - |
2134 | | - |
2135 | | - |
2136 | | - |
2137 | | - |
2138 | | - |
2139 | | - |
2140 | | - |
2141 | void QTreeView::sortByColumn(int column) | - |
2142 | { | - |
2143 | QTreeViewPrivate * const d = d_func(); | - |
2144 | sortByColumn(column, d->header->sortIndicatorOrder()); | - |
2145 | } | - |
2146 | void QTreeView::sortByColumn(int column, Qt::SortOrder order) | - |
2147 | { | - |
2148 | QTreeViewPrivate * const d = d_func(); | - |
2149 | | - |
2150 | | - |
2151 | d->header->setSortIndicator(column, order); | - |
2152 | | - |
2153 | if (!d->sortingEnabled) | - |
2154 | d->model->sort(column, order); | - |
2155 | } | - |
2156 | | - |
2157 | | - |
2158 | | - |
2159 | | - |
2160 | void QTreeView::selectAll() | - |
2161 | { | - |
2162 | QTreeViewPrivate * const d = d_func(); | - |
2163 | if (!selectionModel()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
2164 | return; never executed: return; | 0 |
2165 | SelectionMode mode = d->selectionMode; | - |
2166 | d->executePostedLayout(); | - |
2167 | if (mode != SingleSelectionTRUE | never evaluated | FALSE | never evaluated |
&& mode != NoSelectionTRUE | never evaluated | FALSE | never evaluated |
&& !d->viewItems.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
2168 | const QModelIndex &idx = d->viewItems.lastconstLast().index; | - |
2169 | QModelIndex lastItemIndex = idx.sibling(idx.row(), d->model->columnCount(idx.parent()) - 1); | - |
2170 | d->select(d->viewItems.firstconstFirst().index, lastItemIndex, | - |
2171 | QItemSelectionModel::ClearAndSelect | - |
2172 | |QItemSelectionModel::Rows); | - |
2173 | } never executed: end of block | 0 |
2174 | } never executed: end of block | 0 |
2175 | | - |
2176 | | - |
2177 | | - |
2178 | | - |
2179 | QSize QTreeView::viewportSizeHint() const | - |
2180 | { | - |
2181 | const QTreeViewPrivate * const d = d_func(); | - |
2182 | d->executePostedLayout(); | - |
2183 | | - |
2184 | if (d->viewItems.size() == 0) | - |
2185 | return QAbstractItemView::viewportSizeHint(); | - |
2186 | | - |
2187 | | - |
2188 | const QRect deepestRect = visualRect(d->viewItems.last().index); | - |
2189 | | - |
2190 | if (!deepestRect.isValid()) | - |
2191 | return QAbstractItemView::viewportSizeHint(); | - |
2192 | | - |
2193 | QSize result = QSize(d->header->length(), deepestRect.bottom() + 1); | - |
2194 | | - |
2195 | | - |
2196 | result += QSize(0, d->header->isVisible() ? d->header->height() : 0); | - |
2197 | | - |
2198 | | - |
2199 | result += QSize(verticalScrollBar()->isVisible() ? verticalScrollBar()->width() : 0, | - |
2200 | horizontalScrollBar()->isVisible() ? horizontalScrollBar()->height() : 0); | - |
2201 | | - |
2202 | return result; | - |
2203 | } | - |
2204 | void QTreeView::expandAll() | - |
2205 | { | - |
2206 | QTreeViewPrivate * const d = d_func(); | - |
2207 | d->viewItems.clear(); | - |
2208 | d->interruptDelayedItemsLayout(); | - |
2209 | d->layout(-1, true); | - |
2210 | updateGeometries(); | - |
2211 | d->viewport->update(); | - |
2212 | } | - |
2213 | void QTreeView::collapseAll() | - |
2214 | { | - |
2215 | QTreeViewPrivate * const d = d_func(); | - |
2216 | QSet<QPersistentModelIndex> old_expandedIndexes; | - |
2217 | old_expandedIndexes = d->expandedIndexes; | - |
2218 | d->expandedIndexes.clear(); | - |
2219 | if (!signalsBlocked() && isSignalConnected(QMetaMethod::fromSignal(&QTreeView::collapsed))) { | - |
2220 | QSet<QPersistentModelIndex>::const_iterator i = old_expandedIndexes.constBegin(); | - |
2221 | for (; i != old_expandedIndexes.constEnd(); ++i) { | - |
2222 | const QPersistentModelIndex &mi = (*i); | - |
2223 | if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren)) | - |
2224 | collapsed(mi); | - |
2225 | } | - |
2226 | } | - |
2227 | doItemsLayout(); | - |
2228 | } | - |
2229 | | - |
2230 | | - |
2231 | | - |
2232 | | - |
2233 | | - |
2234 | | - |
2235 | | - |
2236 | void QTreeView::expandToDepth(int depth) | - |
2237 | { | - |
2238 | QTreeViewPrivate * const d = d_func(); | - |
2239 | d->viewItems.clear(); | - |
2240 | QSet<QPersistentModelIndex> old_expandedIndexes; | - |
2241 | old_expandedIndexes = d->expandedIndexes; | - |
2242 | d->expandedIndexes.clear(); | - |
2243 | d->interruptDelayedItemsLayout(); | - |
2244 | d->layout(-1); | - |
2245 | for (int i = 0; i < d->viewItems.count(); ++i) { | - |
2246 | if (d->viewItems.at(i).level <= (uint)depth) { | - |
2247 | d->viewItems[i].expanded = true; | - |
2248 | d->layout(i); | - |
2249 | d->storeExpanded(d->viewItems.at(i).index); | - |
2250 | } | - |
2251 | } | - |
2252 | | - |
2253 | bool someSignalEnabled = isSignalConnected(QMetaMethod::fromSignal(&QTreeView::collapsed)); | - |
2254 | someSignalEnabled |= isSignalConnected(QMetaMethod::fromSignal(&QTreeView::expanded)); | - |
2255 | | - |
2256 | if (!signalsBlocked() && someSignalEnabled) { | - |
2257 | | - |
2258 | QSet<QPersistentModelIndex> collapsedIndexes = old_expandedIndexes - d->expandedIndexes; | - |
2259 | QSet<QPersistentModelIndex>::const_iterator i = collapsedIndexes.constBegin(); | - |
2260 | for (; i != collapsedIndexes.constEnd(); ++i) { | - |
2261 | const QPersistentModelIndex &mi = (*i); | - |
2262 | if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren)) | - |
2263 | collapsed(mi); | - |
2264 | } | - |
2265 | | - |
2266 | QSet<QPersistentModelIndex> expandedIndexs = d->expandedIndexes - old_expandedIndexes; | - |
2267 | i = expandedIndexs.constBegin(); | - |
2268 | for (; i != expandedIndexs.constEnd(); ++i) { | - |
2269 | const QPersistentModelIndex &mi = (*i); | - |
2270 | if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren)) | - |
2271 | expanded(mi); | - |
2272 | } | - |
2273 | } | - |
2274 | | - |
2275 | updateGeometries(); | - |
2276 | d->viewport->update(); | - |
2277 | } | - |
2278 | void QTreeView::columnResized(int column, int , int ) | - |
2279 | { | - |
2280 | QTreeViewPrivate * const d = d_func(); | - |
2281 | d->columnsToUpdate.append(column); | - |
2282 | if (d->columnResizeTimerID == 0) | - |
2283 | d->columnResizeTimerID = startTimer(0); | - |
2284 | } | - |
2285 | | - |
2286 | | - |
2287 | | - |
2288 | | - |
2289 | void QTreeView::updateGeometries() | - |
2290 | { | - |
2291 | QTreeViewPrivate * const d = d_func(); | - |
2292 | if (d->header) { | - |
2293 | if (d->geometryRecursionBlock) | - |
2294 | return; | - |
2295 | d->geometryRecursionBlock = true; | - |
2296 | int height = 0; | - |
2297 | if (!d->header->isHidden()) { | - |
2298 | height = qMax(d->header->minimumHeight(), d->header->sizeHint().height()); | - |
2299 | height = qMin(height, d->header->maximumHeight()); | - |
2300 | } | - |
2301 | setViewportMargins(0, height, 0, 0); | - |
2302 | QRect vg = d->viewport->geometry(); | - |
2303 | QRect geometryRect(vg.left(), vg.top() - height, vg.width(), height); | - |
2304 | d->header->setGeometry(geometryRect); | - |
2305 | QMetaObject::invokeMethod(d->header, "updateGeometries"); | - |
2306 | d->updateScrollBars(); | - |
2307 | d->geometryRecursionBlock = false; | - |
2308 | } | - |
2309 | QAbstractItemView::updateGeometries(); | - |
2310 | } | - |
2311 | int QTreeView::sizeHintForColumn(int column) const | - |
2312 | { | - |
2313 | const QTreeViewPrivate * const d = d_func(); | - |
2314 | d->executePostedLayout(); | - |
2315 | if (d->viewItems.isEmpty()) | - |
2316 | return -1; | - |
2317 | ensurePolished(); | - |
2318 | int w = 0; | - |
2319 | QStyleOptionViewItem option = d->viewOptionsV1(); | - |
2320 | const QVector<QTreeViewItem> viewItems = d->viewItems; | - |
2321 | | - |
2322 | const int maximumProcessRows = d->header->resizeContentsPrecision(); | - |
2323 | | - |
2324 | int offset = 0; | - |
2325 | int start = d->firstVisibleItem(&offset); | - |
2326 | int end = d->lastVisibleItem(start, offset); | - |
2327 | if (start < 0 || end < 0 || end == viewItems.size() - 1) { | - |
2328 | end = viewItems.size() - 1; | - |
2329 | if (maximumProcessRows < 0) { | - |
2330 | start = 0; | - |
2331 | } else if (maximumProcessRows == 0) { | - |
2332 | start = qMax(0, end - 1); | - |
2333 | int remainingHeight = viewport()->height(); | - |
2334 | while (start > 0 && remainingHeight > 0) { | - |
2335 | remainingHeight -= d->itemHeight(start); | - |
2336 | --start; | - |
2337 | } | - |
2338 | } else { | - |
2339 | start = qMax(0, end - maximumProcessRows); | - |
2340 | } | - |
2341 | } | - |
2342 | | - |
2343 | int rowsProcessed = 0; | - |
2344 | | - |
2345 | for (int i = start; i <= end; ++i) { | - |
2346 | if (viewItems.at(i).spanning) | - |
2347 | continue; | - |
2348 | QModelIndex index = viewItems.at(i).index; | - |
2349 | index = index.sibling(index.row(), column); | - |
2350 | w = d->widthHintForIndex(index, w, option, i); | - |
2351 | ++rowsProcessed; | - |
2352 | if (rowsProcessed == maximumProcessRows) | - |
2353 | break; | - |
2354 | } | - |
2355 | | - |
2356 | --end; | - |
2357 | int actualBottom = viewItems.size() - 1; | - |
2358 | | - |
2359 | if (maximumProcessRows == 0) | - |
2360 | rowsProcessed = 0; | - |
2361 | | - |
2362 | while (rowsProcessed != maximumProcessRows && (start > 0 || end < actualBottom)) { | - |
2363 | int idx = -1; | - |
2364 | | - |
2365 | if ((rowsProcessed % 2 && start > 0) || end == actualBottom) { | - |
2366 | while (start > 0) { | - |
2367 | --start; | - |
2368 | if (viewItems.at(start).spanning) | - |
2369 | continue; | - |
2370 | idx = start; | - |
2371 | break; | - |
2372 | } | - |
2373 | } else { | - |
2374 | while (end < actualBottom) { | - |
2375 | ++end; | - |
2376 | if (viewItems.at(end).spanning) | - |
2377 | continue; | - |
2378 | idx = end; | - |
2379 | break; | - |
2380 | } | - |
2381 | } | - |
2382 | if (idx < 0) | - |
2383 | continue; | - |
2384 | | - |
2385 | QModelIndex index = viewItems.at(idx).index; | - |
2386 | index = index.sibling(index.row(), column); | - |
2387 | w = d->widthHintForIndex(index, w, option, idx); | - |
2388 | ++rowsProcessed; | - |
2389 | } | - |
2390 | return w; | - |
2391 | } | - |
2392 | | - |
2393 | | - |
2394 | | - |
2395 | | - |
2396 | | - |
2397 | | - |
2398 | int QTreeView::indexRowSizeHint(const QModelIndex &index) const | - |
2399 | { | - |
2400 | const QTreeViewPrivate * const d = d_func(); | - |
2401 | if (!d->isIndexValid(index) || !d->itemDelegate) | - |
2402 | return 0; | - |
2403 | | - |
2404 | int start = -1; | - |
2405 | int end = -1; | - |
2406 | int indexRow = index.row(); | - |
2407 | int count = d->header->count(); | - |
2408 | bool emptyHeader = (count == 0); | - |
2409 | QModelIndex parent = index.parent(); | - |
2410 | | - |
2411 | if (count && isVisible()) { | - |
2412 | | - |
2413 | start = d->header->visualIndexAt(0); | - |
2414 | } else { | - |
2415 | | - |
2416 | count = d->model->columnCount(parent); | - |
2417 | } | - |
2418 | | - |
2419 | if (isRightToLeft()) { | - |
2420 | start = (start == -1 ? count - 1 : start); | - |
2421 | end = 0; | - |
2422 | } else { | - |
2423 | start = (start == -1 ? 0 : start); | - |
2424 | end = count - 1; | - |
2425 | } | - |
2426 | | - |
2427 | if (end < start) | - |
2428 | qSwap(end, start); | - |
2429 | | - |
2430 | int height = -1; | - |
2431 | QStyleOptionViewItem option = d->viewOptionsV1(); | - |
2432 | | - |
2433 | | - |
2434 | | - |
2435 | | - |
2436 | | - |
2437 | option.rect.setWidth(-1); | - |
2438 | | - |
2439 | for (int column = start; column <= end; ++column) { | - |
2440 | int logicalColumn = emptyHeader ? column : d->header->logicalIndex(column); | - |
2441 | if (d->header->isSectionHidden(logicalColumn)) | - |
2442 | continue; | - |
2443 | QModelIndex idx = d->model->index(indexRow, logicalColumn, parent); | - |
2444 | if (idx.isValid()) { | - |
2445 | QWidget *editor = d->editorForIndex(idx).widget.data(); | - |
2446 | if (editor && d->persistent.contains(editor)) { | - |
2447 | height = qMax(height, editor->sizeHint().height()); | - |
2448 | int min = editor->minimumSize().height(); | - |
2449 | int max = editor->maximumSize().height(); | - |
2450 | height = qBound(min, height, max); | - |
2451 | } | - |
2452 | int hint = d->delegateForIndex(idx)->sizeHint(option, idx).height(); | - |
2453 | height = qMax(height, hint); | - |
2454 | } | - |
2455 | } | - |
2456 | | - |
2457 | return height; | - |
2458 | } | - |
2459 | | - |
2460 | | - |
2461 | | - |
2462 | | - |
2463 | | - |
2464 | | - |
2465 | int QTreeView::rowHeight(const QModelIndex &index) const | - |
2466 | { | - |
2467 | const QTreeViewPrivate * const d = d_func(); | - |
2468 | d->executePostedLayout(); | - |
2469 | int i = d->viewIndex(index); | - |
2470 | if (i == -1) | - |
2471 | return 0; | - |
2472 | return d->itemHeight(i); | - |
2473 | } | - |
2474 | | - |
2475 | | - |
2476 | | - |
2477 | | - |
2478 | void QTreeView::horizontalScrollbarAction(int action) | - |
2479 | { | - |
2480 | QAbstractItemView::horizontalScrollbarAction(action); | - |
2481 | } | - |
2482 | | - |
2483 | | - |
2484 | | - |
2485 | | - |
2486 | bool QTreeView::isIndexHidden(const QModelIndex &index) const | - |
2487 | { | - |
2488 | return (isColumnHidden(index.column()) || isRowHidden(index.row(), index.parent())); | - |
2489 | } | - |
2490 | | - |
2491 | | - |
2492 | | - |
2493 | | - |
2494 | void QTreeViewPrivate::initialize() | - |
2495 | { | - |
2496 | QTreeView * const q = q_func(); | - |
2497 | | - |
2498 | updateIndentationFromStyle(); | - |
2499 | updateStyledFrameWidths(); | - |
2500 | q->setSelectionBehavior(QAbstractItemView::SelectRows); | - |
2501 | q->setSelectionMode(QAbstractItemView::SingleSelection); | - |
2502 | q->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); | - |
2503 | q->setAttribute(Qt::WA_MacShowFocusRect); | - |
2504 | | - |
2505 | QHeaderView *header = new QHeaderView(Qt::Horizontal, q); | - |
2506 | header->setSectionsMovable(true); | - |
2507 | header->setStretchLastSection(true); | - |
2508 | header->setDefaultAlignment(Qt::AlignLeft|Qt::AlignVCenter); | - |
2509 | q->setHeader(header); | - |
2510 | | - |
2511 | animationsEnabled = q->style()->styleHint(QStyle::SH_Widget_Animate, 0, q); | - |
2512 | QObject::connect(&animatedOperation, qFlagLocation("2""finished()" "\0" __FILE__ ":" "3068""3056"), q, qFlagLocation("1""_q_endAnimatedOperation()" "\0" __FILE__ ":" "3068""3056")); | - |
2513 | | - |
2514 | } | - |
2515 | | - |
2516 | void QTreeViewPrivate::expand(int item, bool emitSignal) | - |
2517 | { | - |
2518 | QTreeView * const q = q_func(); | - |
2519 | | - |
2520 | if (item == -1 || viewItems.at(item).expanded) | - |
2521 | return; | - |
2522 | const QModelIndex index = viewItems.at(item).index; | - |
2523 | if (index.flags() & Qt::ItemNeverHasChildren) | - |
2524 | return; | - |
2525 | | - |
2526 | | - |
2527 | if (emitSignal && animationsEnabled) | - |
2528 | prepareAnimatedOperation(item, QVariantAnimation::Forward); | - |
2529 | | - |
2530 | | - |
2531 | if (state != QAbstractItemView::AnimatingState) | - |
2532 | stateBeforeAnimation = state; | - |
2533 | q->setState(QAbstractItemView::ExpandingState); | - |
2534 | storeExpanded(index); | - |
2535 | viewItems[item].expanded = true; | - |
2536 | layout(item); | - |
2537 | q->setState(stateBeforeAnimation); | - |
2538 | | - |
2539 | if (model->canFetchMore(index)) | - |
2540 | model->fetchMore(index); | - |
2541 | if (emitSignal) { | - |
2542 | q->expanded(index); | - |
2543 | | - |
2544 | if (animationsEnabled) | - |
2545 | beginAnimatedOperation(); | - |
2546 | | - |
2547 | } | - |
2548 | } | - |
2549 | | - |
2550 | void QTreeViewPrivate::insertViewItems(int pos, int count, const QTreeViewItem &viewItem) | - |
2551 | { | - |
2552 | viewItems.insert(pos, count, viewItem); | - |
2553 | QTreeViewItem *items = viewItems.data(); | - |
2554 | for (int i = pos + count; i < viewItems.count(); i++) | - |
2555 | if (items[i].parentItem >= pos) | - |
2556 | items[i].parentItem += count; | - |
2557 | } | - |
2558 | | - |
2559 | void QTreeViewPrivate::removeViewItems(int pos, int count) | - |
2560 | { | - |
2561 | viewItems.remove(pos, count); | - |
2562 | QTreeViewItem *items = viewItems.data(); | - |
2563 | for (int i = pos; i < viewItems.count(); i++) | - |
2564 | if (items[i].parentItem >= pos) | - |
2565 | items[i].parentItem -= count; | - |
2566 | } | - |
2567 | void QTreeViewPrivate::collapse(int item, bool emitSignal) | - |
2568 | { | - |
2569 | QTreeView * const q = q_func(); | - |
2570 | | - |
2571 | if (item == -1 || expandedIndexes.isEmpty()) | - |
2572 | return; | - |
2573 | | - |
2574 | | - |
2575 | delayedAutoScroll.stop(); | - |
2576 | | - |
2577 | int total = viewItems.at(item).total; | - |
2578 | const QModelIndex &modelIndex = viewItems.at(item).index; | - |
2579 | if (!isPersistent(modelIndex)) | - |
2580 | return; | - |
2581 | QSet<QPersistentModelIndex>::iterator it = expandedIndexes.find(modelIndex); | - |
2582 | if (it == expandedIndexes.end() || viewItems.at(item).expanded == false) | - |
2583 | return; | - |
2584 | | - |
2585 | | - |
2586 | if (emitSignal && animationsEnabled) | - |
2587 | prepareAnimatedOperation(item, QVariantAnimation::Backward); | - |
2588 | | - |
2589 | | - |
2590 | | - |
2591 | if (state != QAbstractItemView::AnimatingState) | - |
2592 | stateBeforeAnimation = state; | - |
2593 | q->setState(QAbstractItemView::CollapsingState); | - |
2594 | expandedIndexes.erase(it); | - |
2595 | viewItems[item].expanded = false; | - |
2596 | int index = item; | - |
2597 | while (index > -1) { | - |
2598 | viewItems[index].total -= total; | - |
2599 | index = viewItems[index].parentItem; | - |
2600 | } | - |
2601 | removeViewItems(item + 1, total); | - |
2602 | q->setState(stateBeforeAnimation); | - |
2603 | | - |
2604 | if (emitSignal) { | - |
2605 | q->collapsed(modelIndex); | - |
2606 | | - |
2607 | if (animationsEnabled) | - |
2608 | beginAnimatedOperation(); | - |
2609 | | - |
2610 | } | - |
2611 | } | - |
2612 | | - |
2613 | | - |
2614 | void QTreeViewPrivate::prepareAnimatedOperation(int item, QVariantAnimation::Direction direction) | - |
2615 | { | - |
2616 | animatedOperation.item = item; | - |
2617 | animatedOperation.viewport = viewport; | - |
2618 | animatedOperation.setDirection(direction); | - |
2619 | | - |
2620 | int top = coordinateForItem(item) + itemHeight(item); | - |
2621 | QRect rect = viewport->rect(); | - |
2622 | rect.setTop(top); | - |
2623 | if (direction == QVariantAnimation::Backward) { | - |
2624 | const int limit = rect.height() * 2; | - |
2625 | int h = 0; | - |
2626 | int c = item + viewItems.at(item).total + 1; | - |
2627 | for (int i = item + 1; i < c && h < limit; ++i) | - |
2628 | h += itemHeight(i); | - |
2629 | rect.setHeight(h); | - |
2630 | animatedOperation.setEndValue(top + h); | - |
2631 | } | - |
2632 | animatedOperation.setStartValue(top); | - |
2633 | animatedOperation.before = renderTreeToPixmapForAnimation(rect); | - |
2634 | } | - |
2635 | | - |
2636 | void QTreeViewPrivate::beginAnimatedOperation() | - |
2637 | { | - |
2638 | QTreeView * const q = q_func(); | - |
2639 | | - |
2640 | QRect rect = viewport->rect(); | - |
2641 | rect.setTop(animatedOperation.top()); | - |
2642 | if (animatedOperation.direction() == QVariantAnimation::Forward) { | - |
2643 | const int limit = rect.height() * 2; | - |
2644 | int h = 0; | - |
2645 | int c = animatedOperation.item + viewItems.at(animatedOperation.item).total + 1; | - |
2646 | for (int i = animatedOperation.item + 1; i < c && h < limit; ++i) | - |
2647 | h += itemHeight(i); | - |
2648 | rect.setHeight(h); | - |
2649 | animatedOperation.setEndValue(animatedOperation.top() + h); | - |
2650 | } | - |
2651 | | - |
2652 | if (!rect.isEmpty()) { | - |
2653 | animatedOperation.after = renderTreeToPixmapForAnimation(rect); | - |
2654 | | - |
2655 | q->setState(QAbstractItemView::AnimatingState); | - |
2656 | animatedOperation.start(); | - |
2657 | } | - |
2658 | } | - |
2659 | | - |
2660 | void QTreeViewPrivate::drawAnimatedOperation(QPainter *painter) const | - |
2661 | { | - |
2662 | const int start = animatedOperation.startValue().toInt(), | - |
2663 | end = animatedOperation.endValue().toInt(), | - |
2664 | current = animatedOperation.currentValue().toInt(); | - |
2665 | bool collapsing = animatedOperation.direction() == QVariantAnimation::Backward; | - |
2666 | const QPixmap top = collapsing ? animatedOperation.before : animatedOperation.after; | - |
2667 | painter->drawPixmap(0, start, top, 0, end - current - 1, top.width(), top.height()); | - |
2668 | const QPixmap bottom = collapsing ? animatedOperation.after : animatedOperation.before; | - |
2669 | painter->drawPixmap(0, current, bottom); | - |
2670 | } | - |
2671 | | - |
2672 | QPixmap QTreeViewPrivate::renderTreeToPixmapForAnimation(const QRect &rect) const | - |
2673 | { | - |
2674 | const QTreeView * const q = q_func(); | - |
2675 | QPixmap pixmap(rect.size() * q->devicePixelRatio()); | - |
2676 | pixmap.setDevicePixelRatio(q->devicePixelRatio()); | - |
2677 | if (rect.size().isEmpty()) | - |
2678 | return pixmap; | - |
2679 | pixmap.fill(Qt::transparent); | - |
2680 | QPainter painter(&pixmap); | - |
2681 | painter.fillRect(QRect(QPoint(0,0), rect.size()), q->palette().base()); | - |
2682 | painter.translate(0, -rect.top()); | - |
2683 | q->drawTree(&painter, QRegion(rect)); | - |
2684 | painter.end(); | - |
2685 | | - |
2686 | | - |
2687 | QStyleOptionViewItem option = viewOptionsV1(); | - |
2688 | for (QEditorIndexHash::const_iterator it = editorIndexHash.constBegin(); it != editorIndexHash.constEnd(); ++it) { | - |
2689 | QWidget *editor = it.key(); | - |
2690 | const QModelIndex &index = it.value(); | - |
2691 | option.rect = q->visualRect(index); | - |
2692 | if (option.rect.isValid()) { | - |
2693 | | - |
2694 | if (QAbstractItemDelegate *delegate = delegateForIndex(index)) | - |
2695 | delegate->updateEditorGeometry(editor, option, index); | - |
2696 | | - |
2697 | const QPoint pos = editor->pos(); | - |
2698 | if (rect.contains(pos)) { | - |
2699 | editor->render(&pixmap, pos - rect.topLeft()); | - |
2700 | | - |
2701 | | - |
2702 | editor->hide(); | - |
2703 | } | - |
2704 | } | - |
2705 | } | - |
2706 | | - |
2707 | | - |
2708 | return pixmap; | - |
2709 | } | - |
2710 | | - |
2711 | void QTreeViewPrivate::_q_endAnimatedOperation() | - |
2712 | { | - |
2713 | QTreeView * const q = q_func(); | - |
2714 | q->setState(stateBeforeAnimation); | - |
2715 | q->updateGeometries(); | - |
2716 | viewport->update(); | - |
2717 | } | - |
2718 | | - |
2719 | | - |
2720 | void QTreeViewPrivate::_q_modelAboutToBeReset() | - |
2721 | { | - |
2722 | viewItems.clear(); | - |
2723 | } | - |
2724 | | - |
2725 | void QTreeViewPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end) | - |
2726 | { | - |
2727 | if (start <= 0 && 0 <= end) | - |
2728 | viewItems.clear(); | - |
2729 | QAbstractItemViewPrivate::_q_columnsAboutToBeRemoved(parent, start, end); | - |
2730 | } | - |
2731 | | - |
2732 | void QTreeViewPrivate::_q_columnsRemoved(const QModelIndex &parent, int start, int end) | - |
2733 | { | - |
2734 | if (start <= 0 && 0 <= end) | - |
2735 | doDelayedItemsLayout(); | - |
2736 | QAbstractItemViewPrivate::_q_columnsRemoved(parent, start, end); | - |
2737 | } | - |
2738 | void QTreeViewPrivate::layout(int i, bool recursiveExpanding, bool afterIsUninitialized) | - |
2739 | { | - |
2740 | QTreeView * const q = q_func(); | - |
2741 | QModelIndex current; | - |
2742 | QModelIndex parent = (i < 0) ? (QModelIndex)root : modelIndex(i); | - |
2743 | | - |
2744 | if (i>=0 && !parent.isValid()) { | - |
2745 | | - |
2746 | | - |
2747 | | - |
2748 | return; | - |
2749 | } | - |
2750 | | - |
2751 | int count = 0; | - |
2752 | if (model->hasChildren(parent)) { | - |
2753 | if (model->canFetchMore(parent)) | - |
2754 | model->fetchMore(parent); | - |
2755 | count = model->rowCount(parent); | - |
2756 | } | - |
2757 | | - |
2758 | bool expanding = true; | - |
2759 | if (i == -1) { | - |
2760 | if (uniformRowHeights) { | - |
2761 | QModelIndex index = model->index(0, 0, parent); | - |
2762 | defaultItemHeight = q->indexRowSizeHint(index); | - |
2763 | } | - |
2764 | viewItems.resize(count); | - |
2765 | afterIsUninitialized = true; | - |
2766 | } else if (viewItems[i].total != (uint)count) { | - |
2767 | if (!afterIsUninitialized) | - |
2768 | insertViewItems(i + 1, count, QTreeViewItem()); | - |
2769 | else if (count > 0) | - |
2770 | viewItems.resize(viewItems.count() + count); | - |
2771 | } else { | - |
2772 | expanding = false; | - |
2773 | } | - |
2774 | | - |
2775 | int first = i + 1; | - |
2776 | int level = (i >= 0 ? viewItems.at(i).level + 1 : 0); | - |
2777 | int hidden = 0; | - |
2778 | int last = 0; | - |
2779 | int children = 0; | - |
2780 | QTreeViewItem *item = 0; | - |
2781 | for (int j = first; j < first + count; ++j) { | - |
2782 | current = model->index(j - first, 0, parent); | - |
2783 | if (isRowHidden(current)) { | - |
2784 | ++hidden; | - |
2785 | last = j - hidden + children; | - |
2786 | } else { | - |
2787 | last = j - hidden + children; | - |
2788 | if (item) | - |
2789 | item->hasMoreSiblings = true; | - |
2790 | item = &viewItems[last]; | - |
2791 | item->index = current; | - |
2792 | item->parentItem = i; | - |
2793 | item->level = level; | - |
2794 | item->height = 0; | - |
2795 | item->spanning = q->isFirstColumnSpanned(current.row(), parent); | - |
2796 | item->expanded = false; | - |
2797 | item->total = 0; | - |
2798 | item->hasMoreSiblings = false; | - |
2799 | if ((recursiveExpanding && !(current.flags() & Qt::ItemNeverHasChildren)) || isIndexExpanded(current)) { | - |
2800 | if (recursiveExpanding && storeExpanded(current) && !q->signalsBlocked()) | - |
2801 | q->expanded(current); | - |
2802 | item->expanded = true; | - |
2803 | layout(last, recursiveExpanding, afterIsUninitialized); | - |
2804 | item = &viewItems[last]; | - |
2805 | children += item->total; | - |
2806 | item->hasChildren = item->total > 0; | - |
2807 | last = j - hidden + children; | - |
2808 | } else { | - |
2809 | item->hasChildren = hasVisibleChildren(current); | - |
2810 | } | - |
2811 | } | - |
2812 | } | - |
2813 | | - |
2814 | | - |
2815 | if (hidden > 0) { | - |
2816 | if (!afterIsUninitialized) | - |
2817 | removeViewItems(last + 1, hidden); | - |
2818 | else | - |
2819 | viewItems.resize(viewItems.size() - hidden); | - |
2820 | } | - |
2821 | | - |
2822 | if (!expanding) | - |
2823 | return; | - |
2824 | | - |
2825 | while (i > -1) { | - |
2826 | viewItems[i].total += count - hidden; | - |
2827 | i = viewItems[i].parentItem; | - |
2828 | } | - |
2829 | } | - |
2830 | | - |
2831 | int QTreeViewPrivate::pageUp(int i) const | - |
2832 | { | - |
2833 | int index = itemAtCoordinate(coordinateForItem(i) - viewport->height()); | - |
2834 | while (isItemHiddenOrDisabled(index)) | - |
2835 | index--; | - |
2836 | return index == -1 ? 0 : index; | - |
2837 | } | - |
2838 | | - |
2839 | int QTreeViewPrivate::pageDown(int i) const | - |
2840 | { | - |
2841 | int index = itemAtCoordinate(coordinateForItem(i) + viewport->height()); | - |
2842 | while (isItemHiddenOrDisabled(index)) | - |
2843 | index++; | - |
2844 | return index == -1 ? viewItems.count() - 1 : index; | - |
2845 | } | - |
2846 | | - |
2847 | int QTreeViewPrivate::indentationForItem(int item) const | - |
2848 | { | - |
2849 | if (item < 0 || item >= viewItems.count()) | - |
2850 | return 0; | - |
2851 | int level = viewItems.at(item).level; | - |
2852 | if (rootDecoration) | - |
2853 | ++level; | - |
2854 | return level * indent; | - |
2855 | } | - |
2856 | | - |
2857 | int QTreeViewPrivate::itemHeight(int item) const | - |
2858 | { | - |
2859 | if (uniformRowHeights) | - |
2860 | return defaultItemHeight; | - |
2861 | if (viewItems.isEmpty()) | - |
2862 | return 0; | - |
2863 | const QModelIndex &index = viewItems.at(item).index; | - |
2864 | if (!index.isValid()) | - |
2865 | return 0; | - |
2866 | int height = viewItems.at(item).height; | - |
2867 | if (height <= 0) { | - |
2868 | height = q_func()->indexRowSizeHint(index); | - |
2869 | viewItems[item].height = height; | - |
2870 | } | - |
2871 | return qMax(height, 0); | - |
2872 | } | - |
2873 | | - |
2874 | | - |
2875 | | - |
2876 | | - |
2877 | | - |
2878 | | - |
2879 | int QTreeViewPrivate::coordinateForItem(int item) const | - |
2880 | { | - |
2881 | if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) { | - |
2882 | if (uniformRowHeights) | - |
2883 | return (item * defaultItemHeight) - vbar->value(); | - |
2884 | | - |
2885 | int y = 0; | - |
2886 | for (int i = 0; i < viewItems.count(); ++i) { | - |
2887 | if (i == item) | - |
2888 | return y - vbar->value(); | - |
2889 | y += itemHeight(i); | - |
2890 | } | - |
2891 | } else { | - |
2892 | int topViewItemIndex = vbar->value(); | - |
2893 | if (uniformRowHeights) | - |
2894 | return defaultItemHeight * (item - topViewItemIndex); | - |
2895 | if (item >= topViewItemIndex) { | - |
2896 | | - |
2897 | | - |
2898 | int viewItemCoordinate = 0; | - |
2899 | int viewItemIndex = topViewItemIndex; | - |
2900 | while (viewItemIndex < viewItems.count()) { | - |
2901 | if (viewItemIndex == item) | - |
2902 | return viewItemCoordinate; | - |
2903 | viewItemCoordinate += itemHeight(viewItemIndex); | - |
2904 | ++viewItemIndex; | - |
2905 | } | - |
2906 | | - |
2907 | ((!(false)) ? qt_assert("false",__FILE__,34873475) : qt_noop()); | - |
2908 | return viewItemCoordinate; | - |
2909 | } else { | - |
2910 | | - |
2911 | int viewItemCoordinate = 0; | - |
2912 | for (int viewItemIndex = topViewItemIndex; viewItemIndex > 0; --viewItemIndex) { | - |
2913 | if (viewItemIndex == item) | - |
2914 | return viewItemCoordinate; | - |
2915 | viewItemCoordinate -= itemHeight(viewItemIndex - 1); | - |
2916 | } | - |
2917 | return viewItemCoordinate; | - |
2918 | } | - |
2919 | } | - |
2920 | return 0; | - |
2921 | } | - |
2922 | int QTreeViewPrivate::itemAtCoordinate(int coordinate) const | - |
2923 | { | - |
2924 | const int itemCount = viewItems.count(); | - |
2925 | if (itemCount == 0) | - |
2926 | return -1; | - |
2927 | if (uniformRowHeights && defaultItemHeight <= 0) | - |
2928 | return -1; | - |
2929 | if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) { | - |
2930 | if (uniformRowHeights) { | - |
2931 | const int viewItemIndex = (coordinate + vbar->value()) / defaultItemHeight; | - |
2932 | return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex); | - |
2933 | } | - |
2934 | | - |
2935 | int viewItemCoordinate = 0; | - |
2936 | const int contentsCoordinate = coordinate + vbar->value(); | - |
2937 | for (int viewItemIndex = 0; viewItemIndex < viewItems.count(); ++viewItemIndex) { | - |
2938 | viewItemCoordinate += itemHeight(viewItemIndex); | - |
2939 | if (viewItemCoordinate >= contentsCoordinate) | - |
2940 | return (viewItemIndex >= itemCount ? -1 : viewItemIndex); | - |
2941 | } | - |
2942 | } else { | - |
2943 | int topViewItemIndex = vbar->value(); | - |
2944 | if (uniformRowHeights) { | - |
2945 | if (coordinate < 0) | - |
2946 | coordinate -= defaultItemHeight - 1; | - |
2947 | const int viewItemIndex = topViewItemIndex + (coordinate / defaultItemHeight); | - |
2948 | return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex); | - |
2949 | } | - |
2950 | if (coordinate >= 0) { | - |
2951 | | - |
2952 | int viewItemCoordinate = 0; | - |
2953 | for (int viewItemIndex = topViewItemIndex; viewItemIndex < viewItems.count(); ++viewItemIndex) { | - |
2954 | viewItemCoordinate += itemHeight(viewItemIndex); | - |
2955 | if (viewItemCoordinate > coordinate) | - |
2956 | return (viewItemIndex >= itemCount ? -1 : viewItemIndex); | - |
2957 | } | - |
2958 | } else { | - |
2959 | | - |
2960 | int viewItemCoordinate = 0; | - |
2961 | for (int viewItemIndex = topViewItemIndex; viewItemIndex >= 0; --viewItemIndex) { | - |
2962 | if (viewItemCoordinate <= coordinate) | - |
2963 | return (viewItemIndex >= itemCount ? -1 : viewItemIndex); | - |
2964 | viewItemCoordinate -= itemHeight(viewItemIndex); | - |
2965 | } | - |
2966 | } | - |
2967 | } | - |
2968 | return -1; | - |
2969 | } | - |
2970 | | - |
2971 | int QTreeViewPrivate::viewIndex(const QModelIndex &_index) const | - |
2972 | { | - |
2973 | if (!_index.isValid() || viewItems.isEmpty()) | - |
2974 | return -1; | - |
2975 | | - |
2976 | const int totalCount = viewItems.count(); | - |
2977 | const QModelIndex index = _index.sibling(_index.row(), 0); | - |
2978 | const int row = index.row(); | - |
2979 | const quintptr internalId = index.internalId(); | - |
2980 | | - |
2981 | | - |
2982 | int localCount = qMin(lastViewedItem - 1, totalCount - lastViewedItem); | - |
2983 | for (int i = 0; i < localCount; ++i) { | - |
2984 | const QModelIndex &idx1 = viewItems.at(lastViewedItem + i).index; | - |
2985 | if (idx1.row() == row && idx1.internalId() == internalId) { | - |
2986 | lastViewedItem = lastViewedItem + i; | - |
2987 | return lastViewedItem; | - |
2988 | } | - |
2989 | const QModelIndex &idx2 = viewItems.at(lastViewedItem - i - 1).index; | - |
2990 | if (idx2.row() == row && idx2.internalId() == internalId) { | - |
2991 | lastViewedItem = lastViewedItem - i - 1; | - |
2992 | return lastViewedItem; | - |
2993 | } | - |
2994 | } | - |
2995 | | - |
2996 | for (int j = qMax(0, lastViewedItem + localCount); j < totalCount; ++j) { | - |
2997 | const QModelIndex &idx = viewItems.at(j).index; | - |
2998 | if (idx.row() == row && idx.internalId() == internalId) { | - |
2999 | lastViewedItem = j; | - |
3000 | return j; | - |
3001 | } | - |
3002 | } | - |
3003 | for (int j = qMin(totalCount, lastViewedItem - localCount) - 1; j >= 0; --j) { | - |
3004 | const QModelIndex &idx = viewItems.at(j).index; | - |
3005 | if (idx.row() == row && idx.internalId() == internalId) { | - |
3006 | lastViewedItem = j; | - |
3007 | return j; | - |
3008 | } | - |
3009 | } | - |
3010 | | - |
3011 | | - |
3012 | return -1; | - |
3013 | } | - |
3014 | | - |
3015 | QModelIndex QTreeViewPrivate::modelIndex(int i, int column) const | - |
3016 | { | - |
3017 | if (i < 0 || i >= viewItems.count()) | - |
3018 | return QModelIndex(); | - |
3019 | | - |
3020 | QModelIndex ret = viewItems.at(i).index; | - |
3021 | if (column) | - |
3022 | ret = ret.sibling(ret.row(), column); | - |
3023 | return ret; | - |
3024 | } | - |
3025 | | - |
3026 | int QTreeViewPrivate::firstVisibleItem(int *offset) const | - |
3027 | { | - |
3028 | const int value = vbar->value(); | - |
3029 | if (verticalScrollMode == QAbstractItemView::ScrollPerItem) { | - |
3030 | if (offset) | - |
3031 | *offset = 0; | - |
3032 | return (value < 0 || value >= viewItems.count()) ? -1 : value; | - |
3033 | } | - |
3034 | | - |
3035 | if (uniformRowHeights) { | - |
3036 | if (!defaultItemHeight) | - |
3037 | return -1; | - |
3038 | | - |
3039 | if (offset) | - |
3040 | *offset = -(value % defaultItemHeight); | - |
3041 | return value / defaultItemHeight; | - |
3042 | } | - |
3043 | int y = 0; | - |
3044 | for (int i = 0; i < viewItems.count(); ++i) { | - |
3045 | y += itemHeight(i); | - |
3046 | if (y > value) { | - |
3047 | if (offset) | - |
3048 | *offset = y - value - itemHeight(i); | - |
3049 | return i; | - |
3050 | } | - |
3051 | } | - |
3052 | return -1; | - |
3053 | } | - |
3054 | | - |
3055 | int QTreeViewPrivate::lastVisibleItem(int firstVisual, int offset) const | - |
3056 | { | - |
3057 | if (firstVisual < 0 || offset < 0) { | - |
3058 | firstVisual = firstVisibleItem(&offset); | - |
3059 | if (firstVisual < 0) | - |
3060 | return -1; | - |
3061 | } | - |
3062 | int y = - offset; | - |
3063 | int value = viewport->height(); | - |
3064 | | - |
3065 | for (int i = firstVisual; i < viewItems.count(); ++i) { | - |
3066 | y += itemHeight(i); | - |
3067 | if (y > value) | - |
3068 | return i; | - |
3069 | } | - |
3070 | return viewItems.size() - 1; | - |
3071 | } | - |
3072 | | - |
3073 | int QTreeViewPrivate::columnAt(int x) const | - |
3074 | { | - |
3075 | return header->logicalIndexAt(x); | - |
3076 | } | - |
3077 | | - |
3078 | void QTreeViewPrivate::updateScrollBars() | - |
3079 | { | - |
3080 | QTreeView * const q = q_func(); | - |
3081 | QSize viewportSize = viewport->size(); | - |
3082 | if (!viewportSize.isValid()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
3083 | viewportSize = QSize(0, 0); never executed: viewportSize = QSize(0, 0); | 0 |
3084 | | - |
3085 | executePostedLayout(); | - |
3086 | if (viewItems.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3087 | q->doItemsLayout(); | - |
3088 | } never executed: end of block | 0 |
3089 | | - |
3090 | int itemsInViewport = 0; | - |
3091 | if (uniformRowHeightsTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3092 | if (defaultItemHeight <= 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
3093 | itemsInViewport = viewItems.count(); never executed: itemsInViewport = viewItems.count(); | 0 |
3094 | else | - |
3095 | itemsInViewport = viewportSize.height() / defaultItemHeight; never executed: itemsInViewport = viewportSize.height() / defaultItemHeight; | 0 |
3096 | } else { | - |
3097 | const int itemsCount = viewItems.count(); | - |
3098 | const int viewportHeight = viewportSize.height(); | - |
3099 | for (int height = 0, item = itemsCount - 1; item >= 0TRUE | never evaluated | FALSE | never evaluated |
; --item) { | 0 |
3100 | height += itemHeight(item); | - |
3101 | if (height > viewportHeightTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
3102 | break; never executed: break; | 0 |
3103 | ++itemsInViewport; | - |
3104 | } never executed: end of block | 0 |
3105 | } never executed: end of block | 0 |
3106 | if (verticalScrollMode == QAbstractItemView::ScrollPerItemTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3107 | if (!viewItems.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
3108 | itemsInViewport = qMax(1, itemsInViewport); never executed: itemsInViewport = qMax(1, itemsInViewport); | 0 |
3109 | vbar->setRange(0, viewItems.count() - itemsInViewport); | - |
3110 | vbar->setPageStep(itemsInViewport); | - |
3111 | vbar->setSingleStep(1); | - |
3112 | } never executed: end of block else { | 0 |
3113 | int contentsHeight = 0; | - |
3114 | if (uniformRowHeightsTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3115 | contentsHeight = defaultItemHeight * viewItems.count(); | - |
3116 | } never executed: end of block else { | 0 |
3117 | for (int i = 0; i < viewItems.count()TRUE | never evaluated | FALSE | never evaluated |
; ++i) | 0 |
3118 | contentsHeight += itemHeight(i); never executed: contentsHeight += itemHeight(i); | 0 |
3119 | } never executed: end of block | 0 |
3120 | vbar->setRange(0, contentsHeight - viewportSize.height()); | - |
3121 | vbar->setPageStep(viewportSize.height()); | - |
3122 | vbar->setSingleStepd_func()->itemviewChangeSingleStep(qMax(viewportSize.height() / (itemsInViewport + 1), 2)); | - |
3123 | } never executed: end of block | 0 |
3124 | | - |
3125 | const int columnCount = header->count(); | - |
3126 | const int viewportWidth = viewportSize.width(); | - |
3127 | int columnsInViewport = 0; | - |
3128 | for (int width = 0, column = columnCount - 1; column >= 0TRUE | never evaluated | FALSE | never evaluated |
; --column) { | 0 |
3129 | int logical = header->logicalIndex(column); | - |
3130 | width += header->sectionSize(logical); | - |
3131 | if (width > viewportWidthTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
3132 | break; never executed: break; | 0 |
3133 | ++columnsInViewport; | - |
3134 | } never executed: end of block | 0 |
3135 | if (columnCount > 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
3136 | columnsInViewport = qMax(1, columnsInViewport); never executed: columnsInViewport = qMax(1, columnsInViewport); | 0 |
3137 | if (horizontalScrollMode == QAbstractItemView::ScrollPerItemTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3138 | hbar->setRange(0, columnCount - columnsInViewport); | - |
3139 | hbar->setPageStep(columnsInViewport); | - |
3140 | hbar->setSingleStep(1); | - |
3141 | } never executed: end of block else { | 0 |
3142 | const int horizontalLength = header->length(); | - |
3143 | const QSize maxSize = q->maximumViewportSize(); | - |
3144 | if (maxSize.width() >= horizontalLengthTRUE | never evaluated | FALSE | never evaluated |
&& vbar->maximum() <= 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
3145 | viewportSize = maxSize; never executed: viewportSize = maxSize; | 0 |
3146 | hbar->setPageStep(viewportSize.width()); | - |
3147 | hbar->setRange(0, qMax(horizontalLength - viewportSize.width(), 0)); | - |
3148 | hbar->setSingleStepd_func()->itemviewChangeSingleStep(qMax(viewportSize.width() / (columnsInViewport + 1), 2)); | - |
3149 | } never executed: end of block | 0 |
3150 | } | - |
3151 | | - |
3152 | int QTreeViewPrivate::itemDecorationAt(const QPoint &pos) const | - |
3153 | { | - |
3154 | executePostedLayout(); | - |
3155 | int x = pos.x(); | - |
3156 | int column = header->logicalIndexAt(x); | - |
3157 | if (!isTreePosition(column)) | - |
3158 | return -1; | - |
3159 | | - |
3160 | int viewItemIndex = itemAtCoordinate(pos.y()); | - |
3161 | QRect returning = itemDecorationRect(modelIndex(viewItemIndex)); | - |
3162 | if (!returning.contains(pos)) | - |
3163 | return -1; | - |
3164 | | - |
3165 | return viewItemIndex; | - |
3166 | } | - |
3167 | | - |
3168 | QRect QTreeViewPrivate::itemDecorationRect(const QModelIndex &index) const | - |
3169 | { | - |
3170 | const QTreeView * const q = q_func(); | - |
3171 | if (!rootDecoration && index.parent() == root) | - |
3172 | return QRect(); | - |
3173 | | - |
3174 | int viewItemIndex = viewIndex(index); | - |
3175 | if (viewItemIndex < 0 || !hasVisibleChildren(viewItems.at(viewItemIndex).index)) | - |
3176 | return QRect(); | - |
3177 | | - |
3178 | int itemIndentation = indentationForItem(viewItemIndex); | - |
3179 | int position = header->sectionViewportPosition(logicalIndexForTree()); | - |
3180 | int size = header->sectionSize(logicalIndexForTree()); | - |
3181 | | - |
3182 | QRect rect; | - |
3183 | if (q->isRightToLeft()) | - |
3184 | rect = QRect(position + size - itemIndentation, coordinateForItem(viewItemIndex), | - |
3185 | indent, itemHeight(viewItemIndex)); | - |
3186 | else | - |
3187 | rect = QRect(position + itemIndentation - indent, coordinateForItem(viewItemIndex), | - |
3188 | indent, itemHeight(viewItemIndex)); | - |
3189 | QStyleOption opt; | - |
3190 | opt.initFrom(q); | - |
3191 | opt.rect = rect; | - |
3192 | return q->style()->subElementRect(QStyle::SE_TreeViewDisclosureItem, &opt, q); | - |
3193 | } | - |
3194 | | - |
| QListQVector<QPair<int, int> > QTreeViewPrivate::columnRanges(const QModelIndex &topIndex, | |
3196 | const QModelIndex &bottomIndex) const | - |
3197 | { | - |
3198 | const int topVisual = header->visualIndex(topIndex.column()), | - |
3199 | bottomVisual = header->visualIndex(bottomIndex.column()); | - |
3200 | | - |
3201 | const int start = qMin(topVisual, bottomVisual); | - |
3202 | const int end = qMax(topVisual, bottomVisual); | - |
3203 | | - |
3204 | QList<int> logicalIndexes; | - |
3205 | | - |
3206 | | - |
3207 | for (int c = start; c <= endTRUE | never evaluated | FALSE | never evaluated |
; c++) { | 0 |
3208 | const int logical = header->logicalIndex(c); | - |
3209 | if (!header->isSectionHidden(logical)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3210 | logicalIndexes << logical; | - |
3211 | } never executed: end of block | 0 |
3212 | } never executed: end of block | 0 |
3213 | | - |
3214 | std::sort(logicalIndexes.begin(), logicalIndexes.end()); | - |
3215 | | - |
3216 | QListQVector<QPair<int, int> > ret; | - |
3217 | QPair<int, int> current; | - |
3218 | current.first = -2; | - |
3219 | current.second = -2; | - |
3220 | for(int i = 0; i < logicalIndexes.count()TRUE | never evaluated | FALSE | never evaluated |
; ++i) { | 0 |
3221 | const int logicalColumn = logicalIndexes.at(i); | - |
3222 | if (current.second + 1 != logicalColumnTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3223 | if (current.first != -2TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3224 | | - |
3225 | ret += current; | - |
3226 | } never executed: end of block | 0 |
3227 | | - |
3228 | current.first = current.second = logicalColumn; | - |
3229 | } never executed: end of block else { | 0 |
3230 | current.second++; | - |
3231 | } never executed: end of block | 0 |
3232 | } | - |
3233 | | - |
3234 | | - |
3235 | if (current.first != -2TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3236 | ret += current; | - |
3237 | } never executed: end of block | 0 |
3238 | | - |
3239 | return never executed: return ret; ret;never executed: return ret; | 0 |
3240 | } | - |
3241 | | - |
3242 | void QTreeViewPrivate::select(const QModelIndex &topIndex, const QModelIndex &bottomIndex, | - |
3243 | QItemSelectionModel::SelectionFlags command) | - |
3244 | { | - |
3245 | QTreeView * const q = q_func(); | - |
3246 | QItemSelection selection; | - |
3247 | const int top = viewIndex(topIndex), | - |
3248 | bottom = viewIndex(bottomIndex); | - |
3249 | | - |
3250 | const QListQVector<QPair<int, int> > colRanges = columnRanges(topIndex, bottomIndex); | - |
3251 | QListQVector<QPair<int, int> >::const_iterator it; | - |
3252 | for (it = colRanges.begin(); it != colRanges.end()TRUE | never evaluated | FALSE | never evaluated |
; ++it) { | 0 |
3253 | const int left = (*it).first, | - |
3254 | right = (*it).second; | - |
3255 | | - |
3256 | QModelIndex previous; | - |
3257 | QItemSelectionRange currentRange; | - |
3258 | QStack<QItemSelectionRange> rangeStack; | - |
3259 | for (int i = top; i <= bottomTRUE | never evaluated | FALSE | never evaluated |
; ++i) { | 0 |
3260 | QModelIndex index = modelIndex(i); | - |
3261 | QModelIndex parent = index.parent(); | - |
3262 | QModelIndex previousParent = previous.parent(); | - |
3263 | if (previous.isValid()TRUE | never evaluated | FALSE | never evaluated |
&& parent == previousParentTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3264 | | - |
3265 | if (qAbs(previous.row() - index.row()) > 1TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3266 | | - |
3267 | if (currentRange.isValid()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3268 | selection.append(currentRange); | - |
3269 | } never executed: end of block | 0 |
3270 | | - |
3271 | currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right)); | - |
3272 | } never executed: end of block else { | 0 |
3273 | QModelIndex tl = model->index(currentRange.top(), currentRange.left(), | - |
3274 | currentRange.parent()); | - |
3275 | currentRange = QItemSelectionRange(tl, index.sibling(index.row(), right)); | - |
3276 | } never executed: end of block | 0 |
3277 | } else if (previous.isValid()TRUE | never evaluated | FALSE | never evaluated |
&& parent == model->index(previous.row(), 0, previousParent)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3278 | | - |
3279 | rangeStack.push(currentRange); | - |
3280 | currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right)); | - |
3281 | } never executed: end of block else { | 0 |
3282 | if (currentRange.isValid()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
3283 | selection.append(currentRange); never executed: selection.append(currentRange); | 0 |
3284 | if (rangeStack.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
3285 | currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right)); | - |
3286 | } never executed: end of block else { | 0 |
3287 | currentRange = rangeStack.pop(); | - |
3288 | index = currentRange.bottomRight(); | - |
3289 | --i; | - |
3290 | } never executed: end of block | 0 |
3291 | } | - |
3292 | previous = index; | - |
3293 | } never executed: end of block | 0 |
3294 | if (currentRange.isValid()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
3295 | selection.append(currentRange); never executed: selection.append(currentRange); | 0 |
3296 | for (int i = 0; i < rangeStack.count()TRUE | never evaluated | FALSE | never evaluated |
; ++i) | 0 |
3297 | selection.append(rangeStack.at(i)); never executed: selection.append(rangeStack.at(i)); | 0 |
3298 | } never executed: end of block | 0 |
3299 | q->selectionModel()->select(selection, command); | - |
3300 | } never executed: end of block | 0 |
3301 | | - |
3302 | QPair<int,int> QTreeViewPrivate::startAndEndColumns(const QRect &rect) const | - |
3303 | { | - |
3304 | const QTreeView * const q = q_func(); | - |
3305 | int start = header->visualIndexAt(rect.left()); | - |
3306 | int end = header->visualIndexAt(rect.right()); | - |
3307 | if (q->isRightToLeft()) { | - |
3308 | start = (start == -1 ? header->count() - 1 : start); | - |
3309 | end = (end == -1 ? 0 : end); | - |
3310 | } else { | - |
3311 | start = (start == -1 ? 0 : start); | - |
3312 | end = (end == -1 ? header->count() - 1 : end); | - |
3313 | } | - |
3314 | return qMakePair<int,int>(qMin(start, end), qMax(start, end)); | - |
3315 | } | - |
3316 | | - |
3317 | bool QTreeViewPrivate::hasVisibleChildren(const QModelIndex& parent) const | - |
3318 | { | - |
3319 | const QTreeView * const q = q_func(); | - |
3320 | if (parent.flags() & Qt::ItemNeverHasChildren) | - |
3321 | return false; | - |
3322 | if (model->hasChildren(parent)) { | - |
3323 | if (hiddenIndexes.isEmpty()) | - |
3324 | return true; | - |
3325 | if (q->isIndexHidden(parent)) | - |
3326 | return false; | - |
3327 | int rowCount = model->rowCount(parent); | - |
3328 | for (int i = 0; i < rowCount; ++i) { | - |
3329 | if (!q->isRowHidden(i, parent)) | - |
3330 | return true; | - |
3331 | } | - |
3332 | if (rowCount == 0) | - |
3333 | return true; | - |
3334 | } | - |
3335 | return false; | - |
3336 | } | - |
3337 | | - |
3338 | void QTreeViewPrivate::_q_sortIndicatorChanged(int column, Qt::SortOrder order) | - |
3339 | { | - |
3340 | model->sort(column, order); | - |
3341 | } | - |
3342 | | - |
3343 | int QTreeViewPrivate::accessibleTree2Index(const QModelIndex &index) const | - |
3344 | { | - |
3345 | const QTreeView * const q = q_func(); | - |
3346 | | - |
3347 | | - |
3348 | return (q->visualIndex(index) + (q->header() ? 1 : 0)) * index.model()->columnCount() + index.column(); | - |
3349 | } | - |
3350 | | - |
3351 | void QTreeViewPrivate::updateIndentationFromStyle() | - |
3352 | { | - |
3353 | const QTreeView * const q = q_func(); | - |
3354 | indent = q->style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0, q); | - |
3355 | } | - |
3356 | | - |
3357 | | - |
3358 | | - |
3359 | | - |
3360 | void QTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) | - |
3361 | { | - |
3362 | QAbstractItemView::currentChanged(current, previous); | - |
3363 | | - |
3364 | if (allColumnsShowFocus()) { | - |
3365 | if (previous.isValid()) { | - |
3366 | QRect previousRect = visualRect(previous); | - |
3367 | previousRect.setX(0); | - |
3368 | previousRect.setWidth(viewport()->width()); | - |
3369 | viewport()->update(previousRect); | - |
3370 | } | - |
3371 | if (current.isValid()) { | - |
3372 | QRect currentRect = visualRect(current); | - |
3373 | currentRect.setX(0); | - |
3374 | currentRect.setWidth(viewport()->width()); | - |
3375 | viewport()->update(currentRect); | - |
3376 | } | - |
3377 | } | - |
3378 | | - |
3379 | if (QAccessible::isActive() && current.isValid()) { | - |
3380 | QTreeViewPrivate * const d = d_func(); | - |
3381 | | - |
3382 | QAccessibleEvent event(this, QAccessible::Focus); | - |
3383 | event.setChild(d->accessibleTree2Index(current)); | - |
3384 | QAccessible::updateAccessibility(&event); | - |
3385 | } | - |
3386 | | - |
3387 | } | - |
3388 | | - |
3389 | | - |
3390 | | - |
3391 | | - |
3392 | void QTreeView::selectionChanged(const QItemSelection &selected, | - |
3393 | const QItemSelection &deselected) | - |
3394 | { | - |
3395 | QAbstractItemView::selectionChanged(selected, deselected); | - |
3396 | | - |
3397 | if (QAccessible::isActive()) { | - |
3398 | QTreeViewPrivate * const d = d_func(); | - |
3399 | | - |
3400 | | - |
3401 | QModelIndex sel = selected.indexes().value(0); | - |
3402 | if (sel.isValid()) { | - |
3403 | int entry = d->accessibleTree2Index(sel); | - |
3404 | ((!(entry >= 0)) ? qt_assert("entry >= 0",__FILE__,39923980) : qt_noop()); | - |
3405 | QAccessibleEvent event(this, QAccessible::SelectionAdd); | - |
3406 | event.setChild(entry); | - |
3407 | QAccessible::updateAccessibility(&event); | - |
3408 | } | - |
3409 | QModelIndex desel = deselected.indexes().value(0); | - |
3410 | if (desel.isValid()) { | - |
3411 | int entry = d->accessibleTree2Index(desel); | - |
3412 | ((!(entry >= 0)) ? qt_assert("entry >= 0",__FILE__,40003988) : qt_noop()); | - |
3413 | QAccessibleEvent event(this, QAccessible::SelectionRemove); | - |
3414 | event.setChild(entry); | - |
3415 | QAccessible::updateAccessibility(&event); | - |
3416 | } | - |
3417 | } | - |
3418 | | - |
3419 | } | - |
3420 | | - |
3421 | int QTreeView::visualIndex(const QModelIndex &index) const | - |
3422 | { | - |
3423 | const QTreeViewPrivate * const d = d_func(); | - |
3424 | d->executePostedLayout(); | - |
3425 | return d->viewIndex(index); | - |
3426 | } | - |
3427 | | - |
3428 | | - |
3429 | | - |
| | |