qlistview.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qlistview.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event);-
11QListView::QListView(QWidget *parent)-
12 : QAbstractItemView(*new QListViewPrivate, parent)-
13{-
14 setViewMode(ListMode);-
15 setSelectionMode(SingleSelection);-
16 setAttribute(Qt::WA_MacShowFocusRect);-
17 QListViewPrivate * const d = d_func();-
18 d->updateStyledFrameWidths();-
19}-
20-
21-
22-
23-
24QListView::QListView(QListViewPrivate &dd, QWidget *parent)-
25 : QAbstractItemView(dd, parent)-
26{-
27 setViewMode(ListMode);-
28 setSelectionMode(SingleSelection);-
29 setAttribute(Qt::WA_MacShowFocusRect);-
30 QListViewPrivate * const d = d_func();-
31 d->updateStyledFrameWidths();-
32}-
33-
34-
35-
36-
37QListView::~QListView()-
38{-
39}-
40void QListView::setMovement(Movement movement)-
41{-
42 QListViewPrivate * const d = d_func();-
43 d->modeProperties |= uint(QListViewPrivate::Movement);-
44 d->movement = movement;-
45-
46-
47 bool movable = (movement != Static);-
48 setDragEnabled(movable);-
49 d->viewport->setAcceptDrops(movable);-
50-
51 d->doDelayedItemsLayout();-
52}-
53-
54QListView::Movement QListView::movement() const-
55{-
56 const QListViewPrivate * const d = d_func();-
57 return d->movement;-
58}-
59void QListView::setFlow(Flow flow)-
60{-
61 QListViewPrivate * const d = d_func();-
62 d->modeProperties |= uint(QListViewPrivate::Flow);-
63 d->flow = flow;-
64 d->doDelayedItemsLayout();-
65}-
66-
67QListView::Flow QListView::flow() const-
68{-
69 const QListViewPrivate * const d = d_func();-
70 return d->flow;-
71}-
72void QListView::setWrapping(bool enable)-
73{-
74 QListViewPrivate * const d = d_func();-
75 d->modeProperties |= uint(QListViewPrivate::Wrap);-
76 d->setWrapping(enable);-
77 d->doDelayedItemsLayout();-
78}-
79-
80bool QListView::isWrapping() const-
81{-
82 const QListViewPrivate * const d = d_func();-
83 return d->isWrapping();-
84}-
85void QListView::setResizeMode(ResizeMode mode)-
86{-
87 QListViewPrivate * const d = d_func();-
88 d->modeProperties |= uint(QListViewPrivate::ResizeMode);-
89 d->resizeMode = mode;-
90}-
91-
92QListView::ResizeMode QListView::resizeMode() const-
93{-
94 const QListViewPrivate * const d = d_func();-
95 return d->resizeMode;-
96}-
97void QListView::setLayoutMode(LayoutMode mode)-
98{-
99 QListViewPrivate * const d = d_func();-
100 d->layoutMode = mode;-
101}-
102-
103QListView::LayoutMode QListView::layoutMode() const-
104{-
105 const QListViewPrivate * const d = d_func();-
106 return d->layoutMode;-
107}-
108void QListView::setSpacing(int space)-
109{-
110 QListViewPrivate * const d = d_func();-
111 d->modeProperties |= uint(QListViewPrivate::Spacing);-
112 d->setSpacing(space);-
113 d->doDelayedItemsLayout();-
114}-
115-
116int QListView::spacing() const-
117{-
118 const QListViewPrivate * const d = d_func();-
119 return d->spacing();-
120}-
121void QListView::setBatchSize(int batchSize)-
122{-
123 QListViewPrivate * const d = d_func();-
124 if (__builtin_expect(!!(
__builtin_expe... <= 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
batchSize <= 0)), false)
__builtin_expe... <= 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
125 QMessageLogger(__FILE__, 396405, __PRETTY_FUNCTION__).warning("Invalid batchSize (%d)", batchSize);-
126 return;
never executed: return;
0
127 }-
128 d->batchSize = batchSize;-
129}
never executed: end of block
0
130-
131int QListView::batchSize() const-
132{-
133 const QListViewPrivate * const d = d_func();-
134 return d->batchSize;-
135}-
136void QListView::setGridSize(const QSize &size)-
137{-
138 QListViewPrivate * const d = d_func();-
139 d->modeProperties |= uint(QListViewPrivate::GridSize);-
140 d->setGridSize(size);-
141 d->doDelayedItemsLayout();-
142}-
143-
144QSize QListView::gridSize() const-
145{-
146 const QListViewPrivate * const d = d_func();-
147 return d->gridSize();-
148}-
149void QListView::setViewMode(ViewMode mode)-
150{-
151 QListViewPrivate * const d = d_func();-
152 if (d->commonListView && d->viewMode == mode)-
153 return;-
154 d->viewMode = mode;-
155-
156 delete d->commonListView;-
157 if (mode == ListMode) {-
158 d->commonListView = new QListModeViewBase(this, d);-
159 if (!(d->modeProperties & QListViewPrivate::Wrap))-
160 d->setWrapping(false);-
161 if (!(d->modeProperties & QListViewPrivate::Spacing))-
162 d->setSpacing(0);-
163 if (!(d->modeProperties & QListViewPrivate::GridSize))-
164 d->setGridSize(QSize());-
165 if (!(d->modeProperties & QListViewPrivate::Flow))-
166 d->flow = TopToBottom;-
167 if (!(d->modeProperties & QListViewPrivate::Movement))-
168 d->movement = Static;-
169 if (!(d->modeProperties & QListViewPrivate::ResizeMode))-
170 d->resizeMode = Fixed;-
171 if (!(d->modeProperties & QListViewPrivate::SelectionRectVisible))-
172 d->showElasticBand = false;-
173 } else {-
174 d->commonListView = new QIconModeViewBase(this, d);-
175 if (!(d->modeProperties & QListViewPrivate::Wrap))-
176 d->setWrapping(true);-
177 if (!(d->modeProperties & QListViewPrivate::Spacing))-
178 d->setSpacing(0);-
179 if (!(d->modeProperties & QListViewPrivate::GridSize))-
180 d->setGridSize(QSize());-
181 if (!(d->modeProperties & QListViewPrivate::Flow))-
182 d->flow = LeftToRight;-
183 if (!(d->modeProperties & QListViewPrivate::Movement))-
184 d->movement = Free;-
185 if (!(d->modeProperties & QListViewPrivate::ResizeMode))-
186 d->resizeMode = Fixed;-
187 if (!(d->modeProperties & QListViewPrivate::SelectionRectVisible))-
188 d->showElasticBand = true;-
189 }-
190-
191-
192 bool movable = (d->movement != Static);-
193 setDragEnabled(movable);-
194 setAcceptDrops(movable);-
195-
196 d->clear();-
197 d->doDelayedItemsLayout();-
198}-
199-
200QListView::ViewMode QListView::viewMode() const-
201{-
202 const QListViewPrivate * const d = d_func();-
203 return d->viewMode;-
204}-
205void QListView::clearPropertyFlags()-
206{-
207 QListViewPrivate * const d = d_func();-
208 d->modeProperties = 0;-
209}-
210-
211-
212-
213-
214bool QListView::isRowHidden(int row) const-
215{-
216 const QListViewPrivate * const d = d_func();-
217 return d->isHidden(row);-
218}-
219-
220-
221-
222-
223-
224void QListView::setRowHidden(int row, bool hide)-
225{-
226 QListViewPrivate * const d = d_func();-
227 const bool hidden = d->isHidden(row);-
228 if (hide && !hidden)-
229 d->commonListView->appendHiddenRow(row);-
230 else if (!hide && hidden)-
231 d->commonListView->removeHiddenRow(row);-
232 d->doDelayedItemsLayout();-
233 d->viewport->update();-
234}-
235-
236-
237-
238-
239QRect QListView::visualRect(const QModelIndex &index) const-
240{-
241 const QListViewPrivate * const d = d_func();-
242 return d->mapToViewport(rectForIndex(index));-
243}-
244-
245-
246-
247-
248void QListView::scrollTo(const QModelIndex &index, ScrollHint hint)-
249{-
250 QListViewPrivate * const d = d_func();-
251-
252 if (index.parent() != d->root || index.column() != d->column)-
253 return;-
254-
255 const QRect rect = visualRect(index);-
256 if (hint == EnsureVisible && d->viewport->rect().contains(rect)) {-
257 d->viewport->update(rect);-
258 return;-
259 }-
260-
261 if (d->flow == QListView::TopToBottom || d->isWrapping())-
262 verticalScrollBar()->setValue(d->verticalScrollToValue(index, rect, hint));-
263-
264 if (d->flow == QListView::LeftToRight || d->isWrapping())-
265 horizontalScrollBar()->setValue(d->horizontalScrollToValue(index, rect, hint));-
266}-
267-
268int QListViewPrivate::horizontalScrollToValue(const QModelIndex &index, const QRect &rect,-
269 QListView::ScrollHint hint) const-
270{-
271 const QListView * const q = q_func();-
272 const QRect area = viewport->rect();-
273 const bool leftOf = q->isRightToLeft()-
274 ? (rect.left() < area.left()) && (rect.right() < area.right())-
275 : rect.left() < area.left();-
276 const bool rightOf = q->isRightToLeft()-
277 ? rect.right() > area.right()-
278 : (rect.right() > area.right()) && (rect.left() > area.left());-
279 return commonListView->horizontalScrollToValue(q->visualIndex(index), hint, leftOf, rightOf, area, rect);-
280}-
281-
282int QListViewPrivate::verticalScrollToValue(const QModelIndex &index, const QRect &rect,-
283 QListView::ScrollHint hint) const-
284{-
285 const QListView * const q = q_func();-
286 const QRect area = viewport->rect();-
287 const bool above = (hint == QListView::EnsureVisible && rect.top() < area.top());-
288 const bool below = (hint == QListView::EnsureVisible && rect.bottom() > area.bottom());-
289 return commonListView->verticalScrollToValue(q->visualIndex(index), hint, above, below, area, rect);-
290}-
291-
292void QListViewPrivate::selectAll(QItemSelectionModel::SelectionFlags command)-
293{-
294 if (!selectionModel)-
295 return;-
296-
297 QItemSelection selection;-
298 QModelIndex topLeft;-
299 int row = 0;-
300 const int colCount = model->columnCount(root);-
301 for(; row < model->rowCount(root); ++row) {-
302 if (isHidden(row)) {-
303-
304 if (topLeft.isValid()) {-
305 QModelIndex bottomRight = model->index(row - 1, colCount - 1, root);-
306 selection.append(QItemSelectionRange(topLeft, bottomRight));-
307 topLeft = QModelIndex();-
308 }-
309 continue;-
310 }-
311-
312 if (!topLeft.isValid())-
313 topLeft = model->index(row, 0, root);-
314 }-
315-
316 if (topLeft.isValid()) {-
317-
318 QModelIndex bottomRight = model->index(row - 1, colCount - 1, root);-
319 selection.append(QItemSelectionRange(topLeft, bottomRight));-
320 }-
321-
322 if (!selection.isEmpty())-
323 selectionModel->select(selection, command);-
324}-
325-
326-
327-
328-
329-
330-
331-
332QItemViewPaintPairs QListViewPrivate::draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const-
333{-
334 ((!(r)) ? qt_assert("r",__FILE__,647656) : qt_noop());-
335 const QListView * const q = q_func();-
336 QRect &rect = *r;-
337 const QRect viewportRect = viewport->rect();-
338 QItemViewPaintPairs ret;-
339 const QSetQVector<QModelIndex> visibleIndexes = intersectingSet(viewportRect.translated(q->horizontalOffset(), q->verticalOffset())).toList().toSet();-
for()));
340 std::sort(int i = 0; i < indexesvisibleIndexes.count(); ++i) {begin(), visibleIndexes.end());-
341 for (const QModelIndexauto &index =: indexes.at(i);) {-
342 if (std::binary_search
std::binary_se...cend(), index)Description
TRUEnever evaluated
FALSEnever evaluated
(visibleIndexes.contains(cbegin(), visibleIndexes.cend(), index)
std::binary_se...cend(), index)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
343 const QRect current = q->visualRect(index);-
344 ret += qMakePair(QItemViewPaintPair p = { current, index );};-
345 ret += p;-
346 rect |= current;-
347 }
never executed: end of block
0
348 }
never executed: end of block
0
349 rect &= viewportRect;-
350 return
never executed: return ret;
ret;
never executed: return ret;
0
351}-
352-
353-
354-
355-
356void QListView::reset()-
357{-
358 QListViewPrivate * const d = d_func();-
359 d->clear();-
360 d->hiddenRows.clear();-
361 QAbstractItemView::reset();-
362}-
363-
364-
365-
366-
367void QListView::setRootIndex(const QModelIndex &index)-
368{-
369 QListViewPrivate * const d = d_func();-
370 d->column = qBound(0, d->column, d->model->columnCount(index) - 1);-
371 QAbstractItemView::setRootIndex(index);-
372-
373 d->clear();-
374 d->hiddenRows.clear();-
375}-
376-
377-
378-
379-
380-
381-
382-
383void QListView::scrollContentsBy(int dx, int dy)-
384{-
385 QListViewPrivate * const d = d_func();-
386 d->delayedAutoScroll.stop();-
387 d->commonListView->scrollContentsBy(dx, dy, d->state == QListView::DragSelectingState);-
388}-
389-
390-
391-
392-
393-
394-
395-
396void QListView::resizeContents(int width, int height)-
397{-
398 QListViewPrivate * const d = d_func();-
399 d->setContentsSize(width, height);-
400}-
401-
402-
403-
404-
405QSize QListView::contentsSize() const-
406{-
407 const QListViewPrivate * const d = d_func();-
408 return d->contentsSize();-
409}-
410-
411-
412-
413-
414void QListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)-
415{-
416 d_func()->commonListView->dataChanged(topLeft, bottomRight);-
417 QAbstractItemView::dataChanged(topLeft, bottomRight, roles);-
418}-
419-
420-
421-
422-
423void QListView::rowsInserted(const QModelIndex &parent, int start, int end)-
424{-
425 QListViewPrivate * const d = d_func();-
426-
427 d->clear();-
428 d->doDelayedItemsLayout();-
429 QAbstractItemView::rowsInserted(parent, start, end);-
430}-
431-
432-
433-
434-
435void QListView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)-
436{-
437 QListViewPrivate * const d = d_func();-
438-
439 QAbstractItemView::rowsAboutToBeRemoved(parent, start, end);-
440 if (parent == d->root) {-
441 QSet<QPersistentModelIndex>::iterator it = d->hiddenRows.begin();-
442 while (it != d->hiddenRows.end()) {-
443 int hiddenRow = it->row();-
444 if (hiddenRow >= start && hiddenRow <= end) {-
445 it = d->hiddenRows.erase(it);-
446 } else {-
447 ++it;-
448 }-
449 }-
450 }-
451 d->clear();-
452 d->doDelayedItemsLayout();-
453}-
454-
455-
456-
457-
458void QListView::mouseMoveEvent(QMouseEvent *e)-
459{-
460 if (!isVisible())-
461 return;-
462 QListViewPrivate * const d = d_func();-
463 QAbstractItemView::mouseMoveEvent(e);-
464 if (state() == DragSelectingState-
465 && d->showElasticBand-
466 && d->selectionMode != SingleSelection-
467 && d->selectionMode != NoSelection) {-
468 QRect rect(d->pressedPosition, e->pos() + QPoint(horizontalOffset(), verticalOffset()));-
469 rect = rect.normalized();-
470 d->viewport->update(d->mapToViewport(rect.united(d->elasticBand)));-
471 d->elasticBand = rect;-
472 }-
473}-
474-
475-
476-
477-
478void QListView::mouseReleaseEvent(QMouseEvent *e)-
479{-
480 QListViewPrivate * const d = d_func();-
481 QAbstractItemView::mouseReleaseEvent(e);-
482-
483 if (d->showElasticBand && d->elasticBand.isValid()) {-
484 d->viewport->update(d->mapToViewport(d->elasticBand));-
485 d->elasticBand = QRect();-
486 }-
487}-
488-
489-
490-
491-
492-
493void QListView::wheelEvent(QWheelEvent *e)-
494{-
495 QListViewPrivate * const d = d_func();-
496 if (e->orientation() == Qt::Vertical
e->orientation...= Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
497 if (e->angleDelta().x() == 0
e->angleDelta().x() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
498 && ((d->flow == TopToBottom
d->flow == TopToBottomDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->wrap
d->wrapDescription
TRUEnever evaluated
FALSEnever evaluated
) || (d->flow == LeftToRight
d->flow == LeftToRightDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->wrap
!d->wrapDescription
TRUEnever evaluated
FALSEnever evaluated
))
0
499 && d->vbar->minimum() == 0
d->vbar->minimum() == 0Description
TRUEnever evaluated
FALSEnever evaluated
&& d->vbar->maximum() == 0
d->vbar->maximum() == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
500 QPoint pixelDelta(e->pixelDelta().y(), e->pixelDelta().x());-
501 QPoint angleDelta(e->angleDelta().y(), e->angleDelta().x());-
502 QWheelEvent hwe(e->pos(), e->globalPos(), pixelDelta, angleDelta, e->delta(),-
503 Qt::Horizontal, e->buttons(), e->modifiers(), e->phase(), e->source(), e->inverted());-
504 if (e->spontaneous()
e->spontaneous()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
505 qt_sendSpontaneousEvent(d->hbar, &hwe);
never executed: qt_sendSpontaneousEvent(d->hbar, &hwe);
0
506 else-
507 QApplication::sendEvent(d->hbar, &hwe);
never executed: QApplication::sendEvent(d->hbar, &hwe);
0
508 e->setAccepted(hwe.isAccepted());-
509 }
never executed: end of block
else {
0
510 QApplication::sendEvent(d->vbar, e);-
511 }
never executed: end of block
0
512 } else {-
513 QApplication::sendEvent(d->hbar, e);-
514 }
never executed: end of block
0
515}-
516-
517-
518-
519-
520-
521void QListView::timerEvent(QTimerEvent *e)-
522{-
523 QListViewPrivate * const d = d_func();-
524 if (e->timerId() == d->batchLayoutTimer.timerId()) {-
525 if (d->doItemsLayout(d->batchSize)) {-
526 d->batchLayoutTimer.stop();-
527 updateGeometries();-
528 d->viewport->update();-
529 }-
530 }-
531 QAbstractItemView::timerEvent(e);-
532}-
533-
534-
535-
536-
537void QListView::resizeEvent(QResizeEvent *e)-
538{-
539 QListViewPrivate * const d = d_func();-
540 if (d->delayedPendingLayout)-
541 return;-
542-
543 QSize delta = e->size() - e->oldSize();-
544-
545 if (delta.isNull())-
546 return;-
547-
548 bool listWrap = (d->viewMode == ListMode) && d->wrapItemText;-
549 bool flowDimensionChanged = (d->flow == LeftToRight && delta.width() != 0)-
550 || (d->flow == TopToBottom && delta.height() != 0);-
551-
552-
553-
554-
555 if (listWrap-
556 || (state() == NoState && d->resizeMode == Adjust && flowDimensionChanged)) {-
557 d->doDelayedItemsLayout(100);-
558 } else {-
559 QAbstractItemView::resizeEvent(e);-
560 }-
561}-
562-
563-
564-
565-
566-
567-
568void QListView::dragMoveEvent(QDragMoveEvent *e)-
569{-
570 QListViewPrivate * const d = d_func();-
571 if (!d->commonListView->filterDragMoveEvent(e)) {-
572 if (viewMode() == QListView::ListMode && flow() == QListView::LeftToRight)-
573 static_cast<QListModeViewBase *>(d->commonListView)->dragMoveEvent(e);-
574 else-
575 QAbstractItemView::dragMoveEvent(e);-
576 }-
577}-
578-
579-
580-
581-
582-
583void QListView::dragLeaveEvent(QDragLeaveEvent *e)-
584{-
585 if (!d_func()->commonListView->filterDragLeaveEvent(e))-
586 QAbstractItemView::dragLeaveEvent(e);-
587}-
588-
589-
590-
591-
592void QListView::dropEvent(QDropEvent *e)-
593{-
594 if (!d_func()->commonListView->filterDropEvent(e))-
595 QAbstractItemView::dropEvent(e);-
596}-
597-
598-
599-
600-
601void QListView::startDrag(Qt::DropActions supportedActions)-
602{-
603 if (!d_func()->commonListView->filterStartDrag(supportedActions))-
604 QAbstractItemView::startDrag(supportedActions);-
605}-
606-
607-
608-
609-
610-
611-
612QStyleOptionViewItem QListView::viewOptions() const-
613{-
614 const QListViewPrivate * const d = d_func();-
615 QStyleOptionViewItem option = QAbstractItemView::viewOptions();-
616 if (!d->iconSize.isValid()) {-
617 int pm = (d->viewMode == QListView::ListMode-
618 ? style()->pixelMetric(QStyle::PM_ListViewIconSize, 0, this)-
619 : style()->pixelMetric(QStyle::PM_IconViewIconSize, 0, this));-
620 option.decorationSize = QSize(pm, pm);-
621 }-
622 if (d->viewMode == QListView::IconMode) {-
623 option.showDecorationSelected = false;-
624 option.decorationPosition = QStyleOptionViewItem::Top;-
625 option.displayAlignment = Qt::AlignCenter;-
626 } else {-
627 option.decorationPosition = QStyleOptionViewItem::Left;-
628 }-
629-
630 if (d->gridSize().isValid()) {-
631 option.rect.setSize(d->gridSize());-
632 }-
633-
634 return option;-
635}-
636-
637-
638-
639-
640-
641void QListView::paintEvent(QPaintEvent *e)-
642{-
643 QListViewPrivate * const d = d_func();-
644 if (!d->itemDelegate
!d->itemDelegateDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
645 return;
never executed: return;
0
646 QStyleOptionViewItem option = d->viewOptionsV1();-
647 QPainter painter(d->viewport);-
648-
649 const QVector<QModelIndex> toBeRendered = d->intersectingSet(e->rect().translated(horizontalOffset(), verticalOffset()), false);-
650-
651 const QModelIndex current = currentIndex();-
652 const QModelIndex hover = d->hover;-
653 const QAbstractItemModel *itemModel = d->model;-
654 const QItemSelectionModel *selections = d->selectionModel;-
655 const bool focus = (hasFocus()
hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
|| d->viewport->hasFocus()
d->viewport->hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
) && current.isValid()
current.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
;
0
656 const bool alternate = d->alternatingColors;-
657 const QStyle::State state = option.state;-
658 const QAbstractItemView::State viewState = this->state();-
659 const bool enabled = (state & QStyle::State_Enabled) != 0;-
660-
661 bool alternateBase = false;-
662 int previousRow = -2;-
663-
664 int maxSize = (
(flow() == TopToBottom)Description
TRUEnever evaluated
FALSEnever evaluated
flow() == TopToBottom)
(flow() == TopToBottom)Description
TRUEnever evaluated
FALSEnever evaluated
0
665 ? qMax(viewport()->size().width(), d->contentsSize().width()) - 2 * d->spacing()-
666 : qMax(viewport()->size().height(), d->contentsSize().height()) - 2 * d->spacing();-
667-
668 QVector<QModelIndex>::const_iterator end = toBeRendered.constEnd();-
669 for (QVector<QModelIndex>::const_iterator it = toBeRendered.constBegin(); it != end
it != endDescription
TRUEnever evaluated
FALSEnever evaluated
; ++it) {
0
670 ((!((*it).isValid())) ? qt_assert("(*it).isValid()",__FILE__,982992) : qt_noop());-
671 option.rect = visualRect(*it);-
672-
673 if (flow() == TopToBottom
flow() == TopToBottomDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
674 option.rect.setWidth(qMin(maxSize, option.rect.width()));
never executed: option.rect.setWidth(qMin(maxSize, option.rect.width()));
0
675 else-
676 option.rect.setHeight(qMin(maxSize, option.rect.height()));
never executed: option.rect.setHeight(qMin(maxSize, option.rect.height()));
0
677-
678 option.state = state;-
679 if (selections
selectionsDescription
TRUEnever evaluated
FALSEnever evaluated
&& selections->isSelected(*it)
selections->isSelected(*it)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
680 option.state |= QStyle::State_Selected;
never executed: option.state |= QStyle::State_Selected;
0
681 if (enabled
enabledDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
682 QPalette::ColorGroup cg;-
683 if ((
(itemModel->fl...sEnabled) == 0Description
TRUEnever evaluated
FALSEnever evaluated
itemModel->flags(*it) & Qt::ItemIsEnabled) == 0
(itemModel->fl...sEnabled) == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
684 option.state &= ~QStyle::State_Enabled;-
685 cg = QPalette::Disabled;-
686 }
never executed: end of block
else {
0
687 cg = QPalette::Normal;-
688 }
never executed: end of block
0
689 option.palette.setCurrentColorGroup(cg);-
690 }
never executed: end of block
0
691 if (focus
focusDescription
TRUEnever evaluated
FALSEnever evaluated
&& current == *it
current == *itDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
692 option.state |= QStyle::State_HasFocus;-
693 if (viewState == EditingState
viewState == EditingStateDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
694 option.state |= QStyle::State_Editing;
never executed: option.state |= QStyle::State_Editing;
0
695 }
never executed: end of block
0
696 if (*it == hover)option.state|= QStyle::State_MouseOver;-
else
option.state &= ~setFlag(QStyle::State_MouseOver;, *it == hover);
697-
698 if (alternate
alternateDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
699 int row = (*it).row();-
700 if (row != previousRow + 1
row != previousRow + 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
701-
702 if (!d->hiddenRows.isEmpty()
!d->hiddenRows.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
703 for (int r = qMax(previousRow + 1, 0); r < row
r < rowDescription
TRUEnever evaluated
FALSEnever evaluated
; ++r) {
0
704 if (!d->isHidden(r)
!d->isHidden(r)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
705 alternateBase = !alternateBase;
never executed: alternateBase = !alternateBase;
0
706 }
never executed: end of block
0
707 }
never executed: end of block
else {
0
708 alternateBase = (row & 1) != 0;-
709 }
never executed: end of block
0
710 }-
711 if (alternateBase) {option.features|= QStyleOptionViewItem::Alternate;-
} else {
option.features &= ~setFlag(QStyleOptionViewItem::Alternate;
}, alternateBase);
712-
713-
714-
715 QStyle::State oldState = option.state;-
716 option.state &= ~QStyle::State_Selected;-
717 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &option, &painter, this);-
718 option.state = oldState;-
719-
720 alternateBase = !alternateBase;-
721 previousRow = row;-
722 }
never executed: end of block
0
723-
724 d->delegateForIndex(*it)->paint(&painter, option, *it);-
725 }
never executed: end of block
0
726-
727-
728 d->commonListView->paintDragDrop(&painter);-
729-
730-
731-
732-
733 if (d->showElasticBand
d->showElasticBandDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->elasticBand.isValid()
d->elasticBand.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
734 QStyleOptionRubberBand opt;-
735 opt.initFrom(this);-
736 opt.shape = QRubberBand::Rectangle;-
737 opt.opaque = false;-
738 opt.rect = d->mapToViewport(d->elasticBand, false).intersected(-
739 d->viewport->rect().adjusted(-16, -16, 16, 16));-
740 painter.save();-
741 style()->drawControl(QStyle::CE_RubberBand, &opt, &painter);-
742 painter.restore();-
743 }
never executed: end of block
0
744-
745}
never executed: end of block
0
746-
747-
748-
749-
750QModelIndex QListView::indexAt(const QPoint &p) const-
751{-
752 const QListViewPrivate * const d = d_func();-
753 QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1);-
754 const QVector<QModelIndex> intersectVector = d->intersectingSet(rect);-
755 QModelIndex index = intersectVector.count() > 0-
756 ? intersectVector.last() : QModelIndex();-
757 if (index.isValid() && visualRect(index).contains(p))-
758 return index;-
759 return QModelIndex();-
760}-
761-
762-
763-
764-
765int QListView::horizontalOffset() const-
766{-
767 return d_func()->commonListView->horizontalOffset();-
768}-
769-
770-
771-
772-
773int QListView::verticalOffset() const-
774{-
775 return d_func()->commonListView->verticalOffset();-
776}-
777-
778-
779-
780-
781QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)-
782{-
783 QListViewPrivate * const d = d_func();-
784 (void)modifiers;;-
785-
786 QModelIndex current = currentIndex();-
787 if (!current.isValid()) {-
788 int rowCount = d->model->rowCount(d->root);-
789 if (!rowCount)-
790 return QModelIndex();-
791 int row = 0;-
792 while (row < rowCount && d->isHiddenOrDisabled(row))-
793 ++row;-
794 if (row >= rowCount)-
795 return QModelIndex();-
796 return d->model->index(row, d->column, d->root);-
797 }-
798-
799 const QRect initialRect = rectForIndex(current);-
800 QRect rect = initialRect;-
801 if (rect.isEmpty()) {-
802 return d->model->index(0, d->column, d->root);-
803 }-
804 if (d->gridSize().isValid()) rect.setSize(d->gridSize());-
805-
806 QSize contents = d->contentsSize();-
807 QVector<QModelIndex> intersectVector;-
808-
809 switch (cursorAction) {-
810 case MoveLeft:-
811 while (intersectVector.isEmpty()) {-
812 rect.translate(-rect.width(), 0);-
813 if (rect.right() <= 0)-
814 return current;-
815 if (rect.left() < 0)-
816 rect.setLeft(0);-
817 intersectVector = d->intersectingSet(rect);-
818 d->removeCurrentAndDisabled(&intersectVector, current);-
819 }-
820 return d->closestIndex(initialRect, intersectVector);-
821 case MoveRight:-
822 while (intersectVector.isEmpty()) {-
823 rect.translate(rect.width(), 0);-
824 if (rect.left() >= contents.width())-
825 return current;-
826 if (rect.right() > contents.width())-
827 rect.setRight(contents.width());-
828 intersectVector = d->intersectingSet(rect);-
829 d->removeCurrentAndDisabled(&intersectVector, current);-
830 }-
831 return d->closestIndex(initialRect, intersectVector);-
832 case MovePageUp:-
833-
834-
835 rect.moveTop(rect.top() - d->viewport->height() + 2 * rect.height());-
836 if (rect.top() < rect.height())-
837 rect.moveTop(rect.height());-
838 case MovePrevious:-
839 case MoveUp:-
840 while (intersectVector.isEmpty()) {-
841 rect.translate(0, -rect.height());-
842 if (rect.bottom() <= 0) {-
843 return current;-
844 }-
845 if (rect.top() < 0)-
846 rect.setTop(0);-
847 intersectVector = d->intersectingSet(rect);-
848 d->removeCurrentAndDisabled(&intersectVector, current);-
849 }-
850 return d->closestIndex(initialRect, intersectVector);-
851 case MovePageDown:-
852-
853-
854 rect.moveTop(rect.top() + d->viewport->height() - 2 * rect.height());-
855 if (rect.bottom() > contents.height() - rect.height())-
856 rect.moveBottom(contents.height() - rect.height());-
857 case MoveNext:-
858 case MoveDown:-
859 while (intersectVector.isEmpty()) {-
860 rect.translate(0, rect.height());-
861 if (rect.top() >= contents.height()) {-
862 return current;-
863 }-
864 if (rect.bottom() > contents.height())-
865 rect.setBottom(contents.height());-
866 intersectVector = d->intersectingSet(rect);-
867 d->removeCurrentAndDisabled(&intersectVector, current);-
868 }-
869 return d->closestIndex(initialRect, intersectVector);-
870 case MoveHome:-
871 return d->model->index(0, d->column, d->root);-
872 case MoveEnd:-
873 return d->model->index(d->batchStartRow() - 1, d->column, d->root);}-
874-
875 return current;-
876}-
877-
878-
879-
880-
881-
882-
883-
884QRect QListView::rectForIndex(const QModelIndex &index) const-
885{-
886 return d_func()->rectForIndex(index);-
887}-
888void QListView::setPositionForIndex(const QPoint &position, const QModelIndex &index)-
889{-
890 QListViewPrivate * const d = d_func();-
891 if (d->movement == Static-
892 || !d->isIndexValid(index)-
893 || index.parent() != d->root-
894 || index.column() != d->column)-
895 return;-
896-
897 d->executePostedLayout();-
898 d->commonListView->setPositionForIndex(position, index);-
899}-
900-
901-
902-
903-
904void QListView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)-
905{-
906 QListViewPrivate * const d = d_func();-
907 if (!d->selectionModel)-
908 return;-
909-
910-
911 int w = qMax(d->contentsSize().width(), d->viewport->width());-
912 int h = qMax(d->contentsSize().height(), d->viewport->height());-
913 if (d->wrap && !QRect(0, 0, w, h).intersects(rect))-
914 return;-
915-
916 QItemSelection selection;-
917-
918 if (rect.width() == 1 && rect.height() == 1) {-
919 const QVector<QModelIndex> intersectVector = d->intersectingSet(rect.translated(horizontalOffset(), verticalOffset()));-
920 QModelIndex tl;-
921 if (!intersectVector.isEmpty())-
922 tl = intersectVector.last();-
923 if (tl.isValid() && d->isIndexEnabled(tl))-
924 selection.select(tl, tl);-
925 } else {-
926 if (state() == DragSelectingState) {-
927 selection = d->selection(rect.translated(horizontalOffset(), verticalOffset()));-
928 } else {-
929 QModelIndex tl, br;-
930-
931 const QRect topLeft(rect.left() + horizontalOffset(), rect.top() + verticalOffset(), 1, 1);-
932 QVector<QModelIndex> intersectVector = d->intersectingSet(topLeft);-
933 if (!intersectVector.isEmpty())-
934 tl = intersectVector.last();-
935-
936 const QRect bottomRight(rect.right() + horizontalOffset(), rect.bottom() + verticalOffset(), 1, 1);-
937 intersectVector = d->intersectingSet(bottomRight);-
938 if (!intersectVector.isEmpty())-
939 br = intersectVector.last();-
940-
941-
942 if (tl.isValid() && br.isValid()-
943 && d->isIndexEnabled(tl)-
944 && d->isIndexEnabled(br)) {-
945 QRect first = rectForIndex(tl);-
946 QRect last = rectForIndex(br);-
947 QRect middle;-
948 if (d->flow == LeftToRight) {-
949 QRect &top = first;-
950 QRect &bottom = last;-
951-
952 if (top.center().y() > bottom.center().y()) {-
953 QRect tmp = top;-
954 top = bottom;-
955 bottom = tmp;-
956 }-
957-
958 if (top.top() != bottom.top()) {-
959-
960 if (isRightToLeft())-
961 top.setLeft(0);-
962 else-
963 top.setRight(contentsSize().width());-
964-
965 if (isRightToLeft())-
966 bottom.setRight(contentsSize().width());-
967 else-
968 bottom.setLeft(0);-
969 } else if (top.left() > bottom.right()) {-
970 if (isRightToLeft())-
971 bottom.setLeft(top.right());-
972 else-
973 bottom.setRight(top.left());-
974 } else {-
975 if (isRightToLeft())-
976 top.setLeft(bottom.right());-
977 else-
978 top.setRight(bottom.left());-
979 }-
980-
981 if (top.bottom() < bottom.top()) {-
982 if (gridSize().isValid() && !gridSize().isNull())-
983 middle.setTop(top.top() + gridSize().height());-
984 else-
985 middle.setTop(top.bottom() + 1);-
986 middle.setLeft(qMin(top.left(), bottom.left()));-
987 middle.setBottom(bottom.top() - 1);-
988 middle.setRight(qMax(top.right(), bottom.right()));-
989 }-
990 } else {-
991 QRect &left = first;-
992 QRect &right = last;-
993 if (left.center().x() > right.center().x())-
994 qSwap(left, right);-
995-
996 int ch = contentsSize().height();-
997 if (left.left() != right.left()) {-
998-
999 if (isRightToLeft())-
1000 left.setTop(0);-
1001 else-
1002 left.setBottom(ch);-
1003-
1004-
1005 if (isRightToLeft())-
1006 right.setBottom(ch);-
1007 else-
1008 right.setTop(0);-
1009-
1010 middle.setTop(0);-
1011 middle.setBottom(ch);-
1012 if (gridSize().isValid() && !gridSize().isNull())-
1013 middle.setLeft(left.left() + gridSize().width());-
1014 else-
1015 middle.setLeft(left.right() + 1);-
1016 middle.setRight(right.left() - 1);-
1017 } else if (left.bottom() < right.top()) {-
1018 left.setBottom(right.top() - 1);-
1019 } else {-
1020 right.setBottom(left.top() - 1);-
1021 }-
1022 }-
1023-
1024-
1025 QItemSelection topSelection = d->selection(first);-
1026 QItemSelection middleSelection = d->selection(middle);-
1027 QItemSelection bottomSelection = d->selection(last);-
1028-
1029 selection.merge(topSelection, QItemSelectionModel::Select);-
1030 selection.merge(middleSelection, QItemSelectionModel::Select);-
1031 selection.merge(bottomSelection, QItemSelectionModel::Select);-
1032 }-
1033 }-
1034 }-
1035-
1036 d->selectionModel->select(selection, command);-
1037}-
1038-
1039-
1040-
1041-
1042-
1043-
1044-
1045QRegion QListView::visualRegionForSelection(const QItemSelection &selection) const-
1046{-
1047 const QListViewPrivate * const d = d_func();-
1048-
1049 int c = d->column;-
1050 QRegion selectionRegion;-
1051 const QRect &viewportRect = d->viewport->rect();-
1052 for (int i = 0; i <const auto &elem : selection.count(); ++i) {-
1053 if (!selectionelem.at(i).isValid()
!elem.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1054 continue;
never executed: continue;
0
1055 QModelIndex parent = selectionelem.at(i).topLeft().parent();-
1056-
1057-
1058 if (parent != d->root
parent != d->rootDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1059 continue;
never executed: continue;
0
1060 int t = selectionelem.at(i).topLeft().row();-
1061 int b = selectionelem.at(i).bottomRight().row();-
1062 if (d->viewMode == IconMode
d->viewMode == IconModeDescription
TRUEnever evaluated
FALSEnever evaluated
|| d->isWrapping()
d->isWrapping()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1063 for (int r = t; r <= b
r <= bDescription
TRUEnever evaluated
FALSEnever evaluated
; ++r) {
0
1064 const QRect &rect = visualRect(d->model->index(r, c, parent));-
1065 if (viewportRect.intersects(rect)
viewportRect.intersects(rect)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1066 selectionRegion += rect;
never executed: selectionRegion += rect;
0
1067 }
never executed: end of block
0
1068 }
never executed: end of block
else {
0
1069 while (t <= b
t <= bDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->isHidden(t)
d->isHidden(t)Description
TRUEnever evaluated
FALSEnever evaluated
) ++
never executed: ++t;
t;
never executed: ++t;
0
1070 while (b >= t
b >= tDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->isHidden(b)
d->isHidden(b)Description
TRUEnever evaluated
FALSEnever evaluated
) --
never executed: --b;
b;
never executed: --b;
0
1071 const QModelIndex top = d->model->index(t, c, parent);-
1072 const QModelIndex bottom = d->model->index(b, c, parent);-
1073 QRect rect(visualRect(top).topLeft(),-
1074 visualRect(bottom).bottomRight());-
1075 if (viewportRect.intersects(rect)
viewportRect.intersects(rect)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1076 selectionRegion += rect;
never executed: selectionRegion += rect;
0
1077 }
never executed: end of block
0
1078 }-
1079-
1080 return
never executed: return selectionRegion;
selectionRegion;
never executed: return selectionRegion;
0
1081}-
1082-
1083-
1084-
1085-
1086QModelIndexList QListView::selectedIndexes() const-
1087{-
1088 const QListViewPrivate * const d = d_func();-
1089 if (!d->selectionModel
!d->selectionModelDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1090 return
never executed: return QModelIndexList();
QModelIndexList();
never executed: return QModelIndexList();
0
1091-
1092 QModelIndexList viewSelected = d->selectionModel->selectedIndexes();-
1093 for (int iauto ignorable = 0; i < viewSelected.count();) {[this, d](const QModelIndex &index= viewSelected.at(i);-
if (!isIndexHidden(index) &&{
1094 return
never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index);
never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index);
never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index);
index.parentcolumn() ==!= d->root &&column || index.columnparent() ==!= d->column)
never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index);
0
++i;
never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index);
else
never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index);
never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index);
root || isIndexHidden(index);
never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index);
1095 };-
1096 viewSelected.removeAterase(i);-
}std::remove_if(viewSelected.begin(), viewSelected.end(), ignorable),
1097 viewSelected.end());-
1098 return
never executed: return viewSelected;
viewSelected;
never executed: return viewSelected;
0
1099}-
1100-
1101-
1102-
1103-
1104-
1105-
1106void QListView::doItemsLayout()-
1107{-
1108 QListViewPrivate * const d = d_func();-
1109-
1110-
1111-
1112 QAbstractItemView::State oldState = state();-
1113 setState(ExpandingState);-
1114 if (d->model->columnCount(d->root) > 0) {-
1115 d->resetBatchStartRow();-
1116 if (layoutMode() == SinglePass)-
1117 d->doItemsLayout(d->model->rowCount(d->root));-
1118 else if (!d->batchLayoutTimer.isActive()) {-
1119 if (!d->doItemsLayout(d->batchSize))-
1120 d->batchLayoutTimer.start(0, this);-
1121 }-
1122 }-
1123 QAbstractItemView::doItemsLayout();-
1124 setState(oldState);-
1125}-
1126-
1127-
1128-
1129-
1130void QListView::updateGeometries()-
1131{-
1132 QListViewPrivate * const d = d_func();-
1133 if (geometry().isEmpty() || d->model->rowCount(d->root) <= 0 || d->model->columnCount(d->root) <= 0) {-
1134 horizontalScrollBar()->setRange(0, 0);-
1135 verticalScrollBar()->setRange(0, 0);-
1136 } else {-
1137 QModelIndex index = d->model->index(0, d->column, d->root);-
1138 QStyleOptionViewItem option = d->viewOptionsV1();-
1139 QSize step = d->itemSize(option, index);-
1140 d->commonListView->updateHorizontalScrollBar(step);-
1141 d->commonListView->updateVerticalScrollBar(step);-
1142 }-
1143-
1144 QAbstractItemView::updateGeometries();-
1145-
1146-
1147 if (d->movement == Static && !d->isWrapping()) {-
1148 d->layoutChildren();-
1149 if (d->flow == TopToBottom) {-
1150 if (horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) {-
1151 d->setContentsSize(viewport()->width(), contentsSize().height());-
1152 horizontalScrollBar()->setRange(0, 0);-
1153 }-
1154 } else {-
1155 if (verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) {-
1156 d->setContentsSize(contentsSize().width(), viewport()->height());-
1157 verticalScrollBar()->setRange(0, 0);-
1158 }-
1159 }-
1160 }-
1161-
1162}-
1163-
1164-
1165-
1166-
1167bool QListView::isIndexHidden(const QModelIndex &index) const-
1168{-
1169 const QListViewPrivate * const d = d_func();-
1170 return (d->isHidden(index.row())-
1171 && (index.parent() == d->root)-
1172 && index.column() == d->column);-
1173}-
1174void QListView::setModelColumn(int column)-
1175{-
1176 QListViewPrivate * const d = d_func();-
1177 if (column < 0 || column >= d->model->columnCount(d->root))-
1178 return;-
1179 d->column = column;-
1180 d->doDelayedItemsLayout();-
1181}-
1182-
1183int QListView::modelColumn() const-
1184{-
1185 const QListViewPrivate * const d = d_func();-
1186 return d->column;-
1187}-
1188void QListView::setUniformItemSizes(bool enable)-
1189{-
1190 QListViewPrivate * const d = d_func();-
1191 d->uniformItemSizes = enable;-
1192}-
1193-
1194bool QListView::uniformItemSizes() const-
1195{-
1196 const QListViewPrivate * const d = d_func();-
1197 return d->uniformItemSizes;-
1198}-
1199void QListView::setWordWrap(bool on)-
1200{-
1201 QListViewPrivate * const d = d_func();-
1202 if (d->wrapItemText == on)-
1203 return;-
1204 d->wrapItemText = on;-
1205 d->doDelayedItemsLayout();-
1206}-
1207-
1208bool QListView::wordWrap() const-
1209{-
1210 const QListViewPrivate * const d = d_func();-
1211 return d->wrapItemText;-
1212}-
1213void QListView::setSelectionRectVisible(bool show)-
1214{-
1215 QListViewPrivate * const d = d_func();-
1216 d->modeProperties |= uint(QListViewPrivate::SelectionRectVisible);-
1217 d->setSelectionRectVisible(show);-
1218}-
1219-
1220bool QListView::isSelectionRectVisible() const-
1221{-
1222 const QListViewPrivate * const d = d_func();-
1223 return d->isSelectionRectVisible();-
1224}-
1225-
1226-
1227-
1228-
1229bool QListView::event(QEvent *e)-
1230{-
1231 return QAbstractItemView::event(e);-
1232}-
1233-
1234-
1235-
1236-
1237-
1238QListViewPrivate::QListViewPrivate()-
1239 : QAbstractItemViewPrivate(),-
1240 commonListView(0),-
1241 wrap(false),-
1242 space(0),-
1243 flow(QListView::TopToBottom),-
1244 movement(QListView::Static),-
1245 resizeMode(QListView::Fixed),-
1246 layoutMode(QListView::SinglePass),-
1247 viewMode(QListView::ListMode),-
1248 modeProperties(0),-
1249 column(0),-
1250 uniformItemSizes(false),-
1251 batchSize(100),-
1252 showElasticBand(false)-
1253{-
1254}-
1255-
1256QListViewPrivate::~QListViewPrivate()-
1257{-
1258 delete commonListView;-
1259}-
1260-
1261void QListViewPrivate::clear()-
1262{-
1263-
1264 cachedItemSize = QSize();-
1265 commonListView->clear();-
1266}-
1267-
1268void QListViewPrivate::prepareItemsLayout()-
1269{-
1270 QListView * const q = q_func();-
1271 clear();-
1272-
1273-
1274 layoutBounds = QRect(QPoint(), q->maximumViewportSize());-
1275-
1276 int frameAroundContents = 0;-
1277 if (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents))-
1278 frameAroundContents = q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth) * 2;-
1279-
1280-
1281-
1282-
1283 int verticalMargin = vbarpolicy==Qt::ScrollBarAsNeeded-
1284 ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, vbar) + frameAroundContents-
1285 : 0;-
1286 int horizontalMargin = hbarpolicy==Qt::ScrollBarAsNeeded-
1287 ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, hbar) + frameAroundContents-
1288 : 0;-
1289-
1290 layoutBounds.adjust(0, 0, -verticalMargin, -horizontalMargin);-
1291-
1292 int rowCount = model->columnCount(root) <= 0 ? 0 : model->rowCount(root);-
1293 commonListView->setRowCount(rowCount);-
1294}-
1295-
1296-
1297-
1298-
1299bool QListViewPrivate::doItemsLayout(int delta)-
1300{-
1301 int max = model->rowCount(root) - 1;-
1302 int first = batchStartRow();-
1303 int last = qMin(first + delta - 1, max);-
1304-
1305 if (first == 0) {-
1306 layoutChildren();-
1307 prepareItemsLayout();-
1308 }-
1309-
1310 if (max < 0 || last < first) {-
1311 return true;-
1312 }-
1313-
1314 QListViewLayoutInfo info;-
1315 info.bounds = layoutBounds;-
1316 info.grid = gridSize();-
1317 info.spacing = (info.grid.isValid() ? 0 : spacing());-
1318 info.first = first;-
1319 info.last = last;-
1320 info.wrap = isWrapping();-
1321 info.flow = flow;-
1322 info.max = max;-
1323-
1324 return commonListView->doBatchedItemLayout(info, max);-
1325}-
1326-
1327QListViewItem QListViewPrivate::indexToListViewItem(const QModelIndex &index) const-
1328{-
1329 if (!index.isValid() || isHidden(index.row()))-
1330 return QListViewItem();-
1331-
1332 return commonListView->indexToListViewItem(index);-
1333}-
1334-
1335QRect QListViewPrivate::mapToViewport(const QRect &rect, bool extend) const-
1336{-
1337 const QListView * const q = q_func();-
1338 if (!rect.isValid())-
1339 return rect;-
1340-
1341 QRect result = extend ? commonListView->mapToViewport(rect) : rect;-
1342 int dx = -q->horizontalOffset();-
1343 int dy = -q->verticalOffset();-
1344 return result.adjusted(dx, dy, dx, dy);-
1345}-
1346-
1347QModelIndex QListViewPrivate::closestIndex(const QRect &target,-
1348 const QVector<QModelIndex> &candidates) const-
1349{-
1350 int distance = 0;-
1351 int shortest = 2147483647;-
1352 QModelIndex closest;-
1353 QVector<QModelIndex>::const_iterator it = candidates.begin();-
1354-
1355 for (; it != candidates.end(); ++it) {-
1356 if (!(*it).isValid())-
1357 continue;-
1358-
1359 const QRect indexRect = indexToListViewItem(*it).rect();-
1360-
1361-
1362-
1363-
1364 if ((target.center().x() >= indexRect.x() && target.center().x() < indexRect.right())-
1365 || (indexRect.center().x() >= target.x() && indexRect.center().x() < target.right())) {-
1366-
1367 distance = qAbs(indexRect.center().y() - target.center().y());-
1368 } else if ((target.center().y() >= indexRect.y() && target.center().y() < indexRect.bottom())-
1369 || (indexRect.center().y() >= target.y() && indexRect.center().y() < target.bottom())) {-
1370-
1371 distance = qAbs(indexRect.center().x() - target.center().x());-
1372 } else {-
1373 distance = (indexRect.center() - target.center()).manhattanLength();-
1374 }-
1375 if (distance < shortest) {-
1376 shortest = distance;-
1377 closest = *it;-
1378 }-
1379 }-
1380 return closest;-
1381}-
1382-
1383QSize QListViewPrivate::itemSize(const QStyleOptionViewItem &option, const QModelIndex &index) const-
1384{-
1385 if (!uniformItemSizes) {-
1386 const QAbstractItemDelegate *delegate = delegateForIndex(index);-
1387 return delegate ? delegate->sizeHint(option, index) : QSize();-
1388 }-
1389 if (!cachedItemSize.isValid()) {-
1390 int row = model->rowCount(root) - 1;-
1391 QModelIndex sample = model->index(row, column, root);-
1392 const QAbstractItemDelegate *delegate = delegateForIndex(sample);-
1393 cachedItemSize = delegate ? delegate->sizeHint(option, sample) : QSize();-
1394 }-
1395 return cachedItemSize;-
1396}-
1397-
1398QItemSelection QListViewPrivate::selection(const QRect &rect) const-
1399{-
1400 QItemSelection selection;-
1401 QModelIndex tl, br;-
1402 const QVector<QModelIndex> intersectVector = intersectingSet(rect);-
1403 QVector<QModelIndex>::const_iterator it = intersectVector.begin();-
1404 for (; it != intersectVector.end(); ++it) {-
1405 if (!tl.isValid() && !br.isValid()) {-
1406 tl = br = *it;-
1407 } else if ((*it).row() == (tl.row() - 1)) {-
1408 tl = *it;-
1409 } else if ((*it).row() == (br.row() + 1)) {-
1410 br = (*it);-
1411 } else {-
1412 selection.select(tl, br);-
1413 tl = br = *it;-
1414 }-
1415 }-
1416-
1417 if (tl.isValid() && br.isValid())-
1418 selection.select(tl, br);-
1419 else if (tl.isValid())-
1420 selection.select(tl, tl);-
1421 else if (br.isValid())-
1422 selection.select(br, br);-
1423-
1424 return selection;-
1425}-
1426-
1427-
1428QAbstractItemView::DropIndicatorPosition QListViewPrivate::position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const-
1429{-
1430 if (viewMode == QListView::ListMode && flow == QListView::LeftToRight)-
1431 return static_cast<QListModeViewBase *>(commonListView)->position(pos, rect, idx);-
1432 else-
1433 return QAbstractItemViewPrivate::position(pos, rect, idx);-
1434}-
1435-
1436bool QListViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QModelIndex *dropIndex)-
1437{-
1438 if (viewMode == QListView::ListMode && flow == QListView::LeftToRight)-
1439 return static_cast<QListModeViewBase *>(commonListView)->dropOn(event, dropRow, dropCol, dropIndex);-
1440 else-
1441 return QAbstractItemViewPrivate::dropOn(event, dropRow, dropCol, dropIndex);-
1442}-
1443-
1444-
1445void QListViewPrivate::removeCurrentAndDisabled(QVector<QModelIndex> *indexes, const QModelIndex &current) const-
1446{-
1447 auto isCurrentOrDisabled = [=](const QModelIndex &index) {-
1448 return
never executed: return !isIndexEnabled(index) || index == current;
!isIndexEnabled(index) || index == current;
never executed: return !isIndexEnabled(index) || index == current;
0
1449 };-
1450 indexes->erase(std::remove_if(indexes->begin(), indexes->end(),-
1451 isCurrentOrDisabled),-
1452 indexes->end());-
1453}
never executed: end of block
0
1454-
1455-
1456-
1457-
1458-
1459void QCommonListViewBase::appendHiddenRow(int row)-
1460{-
1461 dd->hiddenRows.insert(dd->model->index(row, 0, qq->rootIndex()));-
1462}-
1463-
1464void QCommonListViewBase::removeHiddenRow(int row)-
1465{-
1466 dd->hiddenRows.remove(dd->model->index(row, 0, qq->rootIndex()));-
1467}-
1468-
1469-
1470void QCommonListViewBase::paintDragDrop(QPainter *painter)-
1471{-
1472-
1473-
1474 dd->paintDropIndicator(painter);-
1475}-
1476-
1477-
1478void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step)-
1479{-
1480 horizontalScrollBar()->setSingleStepd_func()->itemviewChangeSingleStep(step.width() + spacing());-
1481 horizontalScrollBar()->setPageStep(viewport()->width());-
1482-
1483-
1484-
1485-
1486-
1487 const bool bothScrollBarsAuto = qq->verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded
qq->verticalSc...ollBarAsNeededDescription
TRUEnever evaluated
FALSEnever evaluated
&&
0
1488 qq->horizontalScrollBarPolicy() == Qt::ScrollBarAsNeeded
qq->horizontal...ollBarAsNeededDescription
TRUEnever evaluated
FALSEnever evaluated
;
0
1489-
1490 const QSize viewportSize = qq->contentsRect().size();-
1491-
1492 bool verticalWantsToShow = contentsSize.height() > viewportSize.height();-
1493 bool horizontalWantsToShow;-
1494 if (verticalWantsToShow
verticalWantsToShowDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1495 horizontalWantsToShow = contentsSize.width() > viewportSize.width() - qq->verticalScrollBar()->width();
never executed: horizontalWantsToShow = contentsSize.width() > viewportSize.width() - qq->verticalScrollBar()->width();
0
1496 else-
1497 horizontalWantsToShow = contentsSize.width() > viewportSize.width();
never executed: horizontalWantsToShow = contentsSize.width() > viewportSize.width();
0
1498-
1499 if (bothScrollBarsAuto
bothScrollBarsAutoDescription
TRUEnever evaluated
FALSEnever evaluated
&& !horizontalWantsToShow
!horizontalWantsToShowDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1500-
1501-
1502 horizontalScrollBar()->setRange(0, 0);-
1503 }
never executed: end of block
else {
0
1504 horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width());-
1505 }
never executed: end of block
0
1506}-
1507-
1508void QCommonListViewBase::updateVerticalScrollBar(const QSize &step)-
1509{-
1510 verticalScrollBar()->setSingleStepd_func()->itemviewChangeSingleStep(step.height() + spacing());-
1511 verticalScrollBar()->setPageStep(viewport()->height());-
1512-
1513-
1514-
1515-
1516-
1517 const bool bothScrollBarsAuto = qq->verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded
qq->verticalSc...ollBarAsNeededDescription
TRUEnever evaluated
FALSEnever evaluated
&&
0
1518 qq->horizontalScrollBarPolicy() == Qt::ScrollBarAsNeeded
qq->horizontal...ollBarAsNeededDescription
TRUEnever evaluated
FALSEnever evaluated
;
0
1519-
1520 const QSize viewportSize = qq->contentsRect().size();-
1521-
1522 bool horizontalWantsToShow = contentsSize.width() > viewportSize.width();-
1523 bool verticalWantsToShow;-
1524 if (horizontalWantsToShow
horizontalWantsToShowDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1525 verticalWantsToShow = contentsSize.height() > viewportSize.height() - qq->horizontalScrollBar()->height();
never executed: verticalWantsToShow = contentsSize.height() > viewportSize.height() - qq->horizontalScrollBar()->height();
0
1526 else-
1527 verticalWantsToShow = contentsSize.height() > viewportSize.height();
never executed: verticalWantsToShow = contentsSize.height() > viewportSize.height();
0
1528-
1529 if (bothScrollBarsAuto
bothScrollBarsAutoDescription
TRUEnever evaluated
FALSEnever evaluated
&& !verticalWantsToShow
!verticalWantsToShowDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1530-
1531-
1532 verticalScrollBar()->setRange(0, 0);-
1533 }
never executed: end of block
else {
0
1534 verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height());-
1535 }
never executed: end of block
0
1536}-
1537-
1538void QCommonListViewBase::scrollContentsBy(int dx, int dy, bool )-
1539{-
1540 dd->scrollContentsBy(isRightToLeft() ? -dx : dx, dy);-
1541}-
1542-
1543int QCommonListViewBase::verticalScrollToValue(int , QListView::ScrollHint hint,-
1544 bool above, bool below, const QRect &area, const QRect &rect) const-
1545{-
1546 int verticalValue = verticalScrollBar()->value();-
1547 QRect adjusted = rect.adjusted(-spacing(), -spacing(), spacing(), spacing());-
1548 if (hint == QListView::PositionAtTop || above)-
1549 verticalValue += adjusted.top();-
1550 else if (hint == QListView::PositionAtBottom || below)-
1551 verticalValue += qMin(adjusted.top(), adjusted.bottom() - area.height() + 1);-
1552 else if (hint == QListView::PositionAtCenter)-
1553 verticalValue += adjusted.top() - ((area.height() - adjusted.height()) / 2);-
1554 return verticalValue;-
1555}-
1556-
1557int QCommonListViewBase::horizontalOffset() const-
1558{-
1559 return (isRightToLeft() ? horizontalScrollBar()->maximum() - horizontalScrollBar()->value() : horizontalScrollBar()->value());-
1560}-
1561-
1562int QCommonListViewBase::horizontalScrollToValue(const int , QListView::ScrollHint hint,-
1563 bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const-
1564{-
1565 int horizontalValue = horizontalScrollBar()->value();-
1566 if (isRightToLeft()) {-
1567 if (hint == QListView::PositionAtCenter) {-
1568 horizontalValue += ((area.width() - rect.width()) / 2) - rect.left();-
1569 } else {-
1570 if (leftOf)-
1571 horizontalValue -= rect.left();-
1572 else if (rightOf)-
1573 horizontalValue += qMin(rect.left(), area.width() - rect.right());-
1574 }-
1575 } else {-
1576 if (hint == QListView::PositionAtCenter) {-
1577 horizontalValue += rect.left() - ((area.width()- rect.width()) / 2);-
1578 } else {-
1579 if (leftOf)-
1580 horizontalValue += rect.left();-
1581 else if (rightOf)-
1582 horizontalValue += qMin(rect.left(), rect.right() - area.width());-
1583 }-
1584 }-
1585 return horizontalValue;-
1586}-
1587-
1588-
1589-
1590-
1591QListModeViewBase::QListModeViewBase(QListView *q, QListViewPrivate *d)-
1592 : QCommonListViewBase(q, d)-
1593{-
1594 dd->defaultDropAction = Qt::CopyAction;-
1595}-
1596-
1597-
1598QAbstractItemView::DropIndicatorPosition QListModeViewBase::position(const QPoint &pos, const QRect &rect, const QModelIndex &index) const-
1599{-
1600 QAbstractItemView::DropIndicatorPosition r = QAbstractItemView::OnViewport;-
1601 if (!dd->overwrite) {-
1602 const int margin = 2;-
1603 if (pos.x() - rect.left() < margin) {-
1604 r = QAbstractItemView::AboveItem;-
1605 } else if (rect.right() - pos.x() < margin) {-
1606 r = QAbstractItemView::BelowItem;-
1607 } else if (rect.contains(pos, true)) {-
1608 r = QAbstractItemView::OnItem;-
1609 }-
1610 } else {-
1611 QRect touchingRect = rect;-
1612 touchingRect.adjust(-1, -1, 1, 1);-
1613 if (touchingRect.contains(pos, false)) {-
1614 r = QAbstractItemView::OnItem;-
1615 }-
1616 }-
1617-
1618 if (r == QAbstractItemView::OnItem && (!(dd->model->flags(index) & Qt::ItemIsDropEnabled)))-
1619 r = pos.x() < rect.center().x() ? QAbstractItemView::AboveItem : QAbstractItemView::BelowItem;-
1620-
1621 return r;-
1622}-
1623-
1624void QListModeViewBase::dragMoveEvent(QDragMoveEvent *event)-
1625{-
1626 if (qq->dragDropMode() == QAbstractItemView::InternalMove-
1627 && (event->source() != qq || !(event->possibleActions() & Qt::MoveAction)))-
1628 return;-
1629-
1630-
1631 event->ignore();-
1632-
1633-
1634 QPoint p = event->pos();-
1635 QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1);-
1636 rect.adjust(-dd->spacing(), -dd->spacing(), dd->spacing(), dd->spacing());-
1637 const QVector<QModelIndex> intersectVector = dd->intersectingSet(rect);-
1638 QModelIndex index = intersectVector.count() > 0-
1639 ? intersectVector.last() : QModelIndex();-
1640 dd->hover = index;-
1641 if (!dd->droppingOnItself(event, index)-
1642 && dd->canDrop(event)) {-
1643-
1644 if (index.isValid() && dd->showDropIndicator) {-
1645 QRect rect = qq->visualRect(index);-
1646 dd->dropIndicatorPosition = position(event->pos(), rect, index);-
1647-
1648 switch (dd->dropIndicatorPosition) {-
1649 case QAbstractItemView::AboveItem:-
1650 if (dd->isIndexDropEnabled(index.parent())) {-
1651 dd->dropIndicatorRect = QRect(rect.left()-dd->spacing(), rect.top(), 0, rect.height());-
1652 event->accept();-
1653 } else {-
1654 dd->dropIndicatorRect = QRect();-
1655 }-
1656 break;-
1657 case QAbstractItemView::BelowItem:-
1658 if (dd->isIndexDropEnabled(index.parent())) {-
1659 dd->dropIndicatorRect = QRect(rect.right()+dd->spacing(), rect.top(), 0, rect.height());-
1660 event->accept();-
1661 } else {-
1662 dd->dropIndicatorRect = QRect();-
1663 }-
1664 break;-
1665 case QAbstractItemView::OnItem:-
1666 if (dd->isIndexDropEnabled(index)) {-
1667 dd->dropIndicatorRect = rect;-
1668 event->accept();-
1669 } else {-
1670 dd->dropIndicatorRect = QRect();-
1671 }-
1672 break;-
1673 case QAbstractItemView::OnViewport:-
1674 dd->dropIndicatorRect = QRect();-
1675 if (dd->isIndexDropEnabled(qq->rootIndex())) {-
1676 event->accept();-
1677 }-
1678 break;-
1679 }-
1680 } else {-
1681 dd->dropIndicatorRect = QRect();-
1682 dd->dropIndicatorPosition = QAbstractItemView::OnViewport;-
1683 if (dd->isIndexDropEnabled(qq->rootIndex())) {-
1684 event->accept();-
1685 }-
1686 }-
1687 dd->viewport->update();-
1688 }-
1689-
1690 if (dd->shouldAutoScroll(event->pos()))-
1691 qq->startAutoScroll();-
1692}-
1693bool QListModeViewBase::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QModelIndex *dropIndex)-
1694{-
1695 if (event->isAccepted())-
1696 return false;-
1697-
1698 QModelIndex index;-
1699 if (dd->viewport->rect().contains(event->pos())) {-
1700-
1701 QPoint p = event->pos();-
1702 QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1);-
1703 rect.adjust(-dd->spacing(), -dd->spacing(), dd->spacing(), dd->spacing());-
1704 const QVector<QModelIndex> intersectVector = dd->intersectingSet(rect);-
1705 index = intersectVector.count() > 0-
1706 ? intersectVector.last() : QModelIndex();-
1707 if (!index.isValid())-
1708 index = dd->root;-
1709 }-
1710-
1711-
1712 if (dd->model->supportedDropActions() & event->dropAction()) {-
1713 int row = -1;-
1714 int col = -1;-
1715 if (index != dd->root) {-
1716 dd->dropIndicatorPosition = position(event->pos(), qq->visualRect(index), index);-
1717 switch (dd->dropIndicatorPosition) {-
1718 case QAbstractItemView::AboveItem:-
1719 row = index.row();-
1720 col = index.column();-
1721 index = index.parent();-
1722 break;-
1723 case QAbstractItemView::BelowItem:-
1724 row = index.row() + 1;-
1725 col = index.column();-
1726 index = index.parent();-
1727 break;-
1728 case QAbstractItemView::OnItem:-
1729 case QAbstractItemView::OnViewport:-
1730 break;-
1731 }-
1732 } else {-
1733 dd->dropIndicatorPosition = QAbstractItemView::OnViewport;-
1734 }-
1735 *dropIndex = index;-
1736 *dropRow = row;-
1737 *dropCol = col;-
1738 if (!dd->droppingOnItself(event, index))-
1739 return true;-
1740 }-
1741 return false;-
1742}-
1743-
1744-
1745-
1746void QListModeViewBase::updateVerticalScrollBar(const QSize &step)-
1747{-
1748 if (verticalScrollMode() == QAbstractItemView::ScrollPerItem-
1749 && ((flow() == QListView::TopToBottom && !isWrapping())-
1750 || (flow() == QListView::LeftToRight && isWrapping()))) {-
1751 const int steps = (flow() == QListView::TopToBottom ? scrollValueMap : segmentPositions).count() - 1;-
1752 if (steps > 0) {-
1753 const int pageSteps = perItemScrollingPageSteps(viewport()->height(), contentsSize.height(), isWrapping());-
1754 verticalScrollBar()->setSingleStep(1);-
1755 verticalScrollBar()->setPageStep(pageSteps);-
1756 verticalScrollBar()->setRange(0, steps - pageSteps);-
1757 } else {-
1758 verticalScrollBar()->setRange(0, 0);-
1759 }-
1760-
1761-
1762 } else {-
1763 QCommonListViewBase::updateVerticalScrollBar(step);-
1764 }-
1765}-
1766-
1767void QListModeViewBase::updateHorizontalScrollBar(const QSize &step)-
1768{-
1769 if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem-
1770 && ((flow() == QListView::TopToBottom && isWrapping())-
1771 || (flow() == QListView::LeftToRight && !isWrapping()))) {-
1772 int steps = (flow() == QListView::TopToBottom ? segmentPositions : scrollValueMap).count() - 1;-
1773 if (steps > 0) {-
1774 const int pageSteps = perItemScrollingPageSteps(viewport()->width(), contentsSize.width(), isWrapping());-
1775 horizontalScrollBar()->setSingleStep(1);-
1776 horizontalScrollBar()->setPageStep(pageSteps);-
1777 horizontalScrollBar()->setRange(0, steps - pageSteps);-
1778 } else {-
1779 horizontalScrollBar()->setRange(0, 0);-
1780 }-
1781 } else {-
1782 QCommonListViewBase::updateHorizontalScrollBar(step);-
1783 }-
1784}-
1785-
1786int QListModeViewBase::verticalScrollToValue(int index, QListView::ScrollHint hint,-
1787 bool above, bool below, const QRect &area, const QRect &rect) const-
1788{-
1789 if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {-
1790 int value;-
1791 if (scrollValueMap.isEmpty()) {-
1792 value = 0;-
1793 } else {-
1794 int scrollBarValue = verticalScrollBar()->value();-
1795 int numHidden = 0;-
1796 for (int i = 0; i < flowPositions.count() - 1 && i <= scrollBarValue; ++i)-
1797 if (isHidden(i))-
1798 ++numHidden;-
1799 value = qBound(0, scrollValueMap.at(verticalScrollBar()->value()) - numHidden, flowPositions.count() - 1);-
1800 }-
1801 if (above)-
1802 hint = QListView::PositionAtTop;-
1803 else if (below)-
1804 hint = QListView::PositionAtBottom;-
1805 if (hint == QListView::EnsureVisible)-
1806 return value;-
1807-
1808 return perItemScrollToValue(index, value, area.height(), hint, Qt::Vertical, isWrapping(), rect.height());-
1809 }-
1810-
1811 return QCommonListViewBase::verticalScrollToValue(index, hint, above, below, area, rect);-
1812}-
1813-
1814int QListModeViewBase::horizontalOffset() const-
1815{-
1816 if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) {-
1817 if (isWrapping()) {-
1818 if (flow() == QListView::TopToBottom && !segmentPositions.isEmpty()) {-
1819 const int max = segmentPositions.count() - 1;-
1820 int currentValue = qBound(0, horizontalScrollBar()->value(), max);-
1821 int position = segmentPositions.at(currentValue);-
1822 int maximumValue = qBound(0, horizontalScrollBar()->maximum(), max);-
1823 int maximum = segmentPositions.at(maximumValue);-
1824 return (isRightToLeft() ? maximum - position : position);-
1825 }-
1826 } else if (flow() == QListView::LeftToRight && !flowPositions.isEmpty()) {-
1827 int position = flowPositions.at(scrollValueMap.at(horizontalScrollBar()->value()));-
1828 int maximum = flowPositions.at(scrollValueMap.at(horizontalScrollBar()->maximum()));-
1829 return (isRightToLeft() ? maximum - position : position);-
1830 }-
1831 }-
1832 return QCommonListViewBase::horizontalOffset();-
1833}-
1834-
1835int QListModeViewBase::verticalOffset() const-
1836{-
1837 if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {-
1838 if (isWrapping()) {-
1839 if (flow() == QListView::LeftToRight && !segmentPositions.isEmpty()) {-
1840 int value = verticalScrollBar()->value();-
1841 if (value >= segmentPositions.count())-
1842 return 0;-
1843 return segmentPositions.at(value) - spacing();-
1844 }-
1845 } else if (flow() == QListView::TopToBottom && !flowPositions.isEmpty()) {-
1846 int value = verticalScrollBar()->value();-
1847 if (value > scrollValueMap.count())-
1848 return 0;-
1849 return flowPositions.at(scrollValueMap.at(value)) - spacing();-
1850 }-
1851 }-
1852 return QCommonListViewBase::verticalOffset();-
1853}-
1854-
1855int QListModeViewBase::horizontalScrollToValue(int index, QListView::ScrollHint hint,-
1856 bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const-
1857{-
1858 if (horizontalScrollMode() != QAbstractItemView::ScrollPerItem)-
1859 return QCommonListViewBase::horizontalScrollToValue(index, hint, leftOf, rightOf, area, rect);-
1860-
1861 int value;-
1862 if (scrollValueMap.isEmpty())-
1863 value = 0;-
1864 else-
1865 value = qBound(0, scrollValueMap.at(horizontalScrollBar()->value()), flowPositions.count() - 1);-
1866 if (leftOf)-
1867 hint = QListView::PositionAtTop;-
1868 else if (rightOf)-
1869 hint = QListView::PositionAtBottom;-
1870 if (hint == QListView::EnsureVisible)-
1871 return value;-
1872-
1873 return perItemScrollToValue(index, value, area.width(), hint, Qt::Horizontal, isWrapping(), rect.width());-
1874}-
1875-
1876void QListModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand)-
1877{-
1878-
1879 const int verticalValue = verticalScrollBar()->value();-
1880 const int horizontalValue = horizontalScrollBar()->value();-
1881 const bool vertical = (verticalScrollMode() == QAbstractItemView::ScrollPerItem);-
1882 const bool horizontal = (horizontalScrollMode() == QAbstractItemView::ScrollPerItem);-
1883-
1884 if (isWrapping()) {-
1885 if (segmentPositions.isEmpty())-
1886 return;-
1887 const int max = segmentPositions.count() - 1;-
1888 if (horizontal && flow() == QListView::TopToBottom && dx != 0) {-
1889 int currentValue = qBound(0, horizontalValue, max);-
1890 int previousValue = qBound(0, currentValue + dx, max);-
1891 int currentCoordinate = segmentPositions.at(currentValue) - spacing();-
1892 int previousCoordinate = segmentPositions.at(previousValue) - spacing();-
1893 dx = previousCoordinate - currentCoordinate;-
1894 } else if (vertical && flow() == QListView::LeftToRight && dy != 0) {-
1895 int currentValue = qBound(0, verticalValue, max);-
1896 int previousValue = qBound(0, currentValue + dy, max);-
1897 int currentCoordinate = segmentPositions.at(currentValue) - spacing();-
1898 int previousCoordinate = segmentPositions.at(previousValue) - spacing();-
1899 dy = previousCoordinate - currentCoordinate;-
1900 }-
1901 } else {-
1902 if (flowPositions.isEmpty())-
1903 return;-
1904 const int max = scrollValueMap.count() - 1;-
1905 if (vertical && flow() == QListView::TopToBottom && dy != 0) {-
1906 int currentValue = qBound(0, verticalValue, max);-
1907 int previousValue = qBound(0, currentValue + dy, max);-
1908 int currentCoordinate = flowPositions.at(scrollValueMap.at(currentValue));-
1909 int previousCoordinate = flowPositions.at(scrollValueMap.at(previousValue));-
1910 dy = previousCoordinate - currentCoordinate;-
1911 } else if (horizontal && flow() == QListView::LeftToRight && dx != 0) {-
1912 int currentValue = qBound(0, horizontalValue, max);-
1913 int previousValue = qBound(0, currentValue + dx, max);-
1914 int currentCoordinate = flowPositions.at(scrollValueMap.at(currentValue));-
1915 int previousCoordinate = flowPositions.at(scrollValueMap.at(previousValue));-
1916 dx = previousCoordinate - currentCoordinate;-
1917 }-
1918 }-
1919 QCommonListViewBase::scrollContentsBy(dx, dy, scrollElasticBand);-
1920}-
1921-
1922bool QListModeViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, int max)-
1923{-
1924 doStaticLayout(info);-
1925 if (batchStartRow > max) {-
1926 flowPositions.resize(flowPositions.count());-
1927 segmentPositions.resize(segmentPositions.count());-
1928 segmentStartRows.resize(segmentStartRows.count());-
1929 return true;-
1930 }-
1931 return false;-
1932}-
1933-
1934QListViewItem QListModeViewBase::indexToListViewItem(const QModelIndex &index) const-
1935{-
1936 if (flowPositions.isEmpty()-
1937 || segmentPositions.isEmpty()-
1938 || index.row() >= flowPositions.count())-
1939 return QListViewItem();-
1940-
1941 const int segment = qBinarySearch<int>(segmentStartRows, index.row(),-
1942 0, segmentStartRows.count() - 1);-
1943-
1944-
1945 QStyleOptionViewItem options = viewOptions();-
1946 options.rect.setSize(contentsSize);-
1947 QSize size = (uniformItemSizes() && cachedItemSize().isValid())-
1948 ? cachedItemSize() : itemSize(options, index);-
1949-
1950 QPoint pos;-
1951 if (flow() == QListView::LeftToRight) {-
1952 pos.setX(flowPositions.at(index.row()));-
1953 pos.setY(segmentPositions.at(segment));-
1954 } else {-
1955 pos.setY(flowPositions.at(index.row()));-
1956 pos.setX(segmentPositions.at(segment));-
1957 if (isWrapping()) {-
1958 int right = (segment + 1 >= segmentPositions.count()-
1959 ? contentsSize.width()-
1960 : segmentPositions.at(segment + 1));-
1961 size.setWidth(right - pos.x());-
1962 } else {-
1963 size.setWidth(qMax(size.width(), viewport()->width() - 2 * spacing()));-
1964 }-
1965 }-
1966-
1967 return QListViewItem(QRect(pos, size), index.row());-
1968}-
1969-
1970QPoint QListModeViewBase::initStaticLayout(const QListViewLayoutInfo &info)-
1971{-
1972 int x, y;-
1973 if (info.first == 0
info.first == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1974 flowPositions.clear();-
1975 segmentPositions.clear();-
1976 segmentStartRows.clear();-
1977 segmentExtents.clear();-
1978 scrollValueMap.clear();-
1979 x = info.bounds.left() + info.spacing;-
1980 y = info.bounds.top() + info.spacing;-
1981 segmentPositions.append(info.flow == QListView::LeftToRight ? y : x);-
1982 segmentStartRows.append(0);-
1983 }
never executed: end of block
else if (info.wrap
info.wrapDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1984 if (info.flow == QListView::LeftToRight
info.flow == Q...w::LeftToRightDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1985 x = batchSavedPosition;-
1986 y = segmentPositions.lastconstLast();-
1987 }
never executed: end of block
else {
0
1988 x = segmentPositions.lastconstLast();-
1989 y = batchSavedPosition;-
1990 }
never executed: end of block
0
1991 } else {-
1992 if (info.flow == QListView::LeftToRight
info.flow == Q...w::LeftToRightDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1993 x = batchSavedPosition;-
1994 y = info.bounds.top() + info.spacing;-
1995 }
never executed: end of block
else {
0
1996 x = info.bounds.left() + info.spacing;-
1997 y = batchSavedPosition;-
1998 }
never executed: end of block
0
1999 }-
2000 return
never executed: return QPoint(x, y);
QPoint(x, y);
never executed: return QPoint(x, y);
0
2001}-
2002-
2003-
2004-
2005-
2006void QListModeViewBase::doStaticLayout(const QListViewLayoutInfo &info)-
2007{-
2008 const bool useItemSize = !info.grid.isValid();-
2009 const QPoint topLeft = initStaticLayout(info);-
2010 QStyleOptionViewItem option = viewOptions();-
2011 option.rect = info.bounds;-
2012 option.rect.adjust(info.spacing, info.spacing, -info.spacing, -info.spacing);-
2013-
2014-
2015-
2016-
2017-
2018-
2019-
2020 int segStartPosition;-
2021 int segEndPosition;-
2022 int deltaFlowPosition;-
2023 int deltaSegPosition;-
2024 int deltaSegHint;-
2025 int flowPosition;-
2026 int segPosition;-
2027-
2028 if (info.flow == QListView::LeftToRight) {-
2029 segStartPosition = info.bounds.left();-
2030 segEndPosition = info.bounds.width();-
2031 flowPosition = topLeft.x();-
2032 segPosition = topLeft.y();-
2033 deltaFlowPosition = info.grid.width();-
2034 deltaSegPosition = useItemSize ? batchSavedDeltaSeg : info.grid.height();-
2035 deltaSegHint = info.grid.height();-
2036 } else {-
2037 segStartPosition = info.bounds.top();-
2038 segEndPosition = info.bounds.height();-
2039 flowPosition = topLeft.y();-
2040 segPosition = topLeft.x();-
2041 deltaFlowPosition = info.grid.height();-
2042 deltaSegPosition = useItemSize ? batchSavedDeltaSeg : info.grid.width();-
2043 deltaSegHint = info.grid.width();-
2044 }-
2045-
2046 for (int row = info.first; row <= info.last; ++row) {-
2047 if (isHidden(row)) {-
2048 flowPositions.append(flowPosition);-
2049 } else {-
2050-
2051 if (useItemSize) {-
2052 QSize hint = itemSize(option, modelIndex(row));-
2053 if (info.flow == QListView::LeftToRight) {-
2054 deltaFlowPosition = hint.width() + info.spacing;-
2055 deltaSegHint = hint.height() + info.spacing;-
2056 } else {-
2057 deltaFlowPosition = hint.height() + info.spacing;-
2058 deltaSegHint = hint.width() + info.spacing;-
2059 }-
2060 }-
2061-
2062 if (info.wrap && (flowPosition + deltaFlowPosition >= segEndPosition)) {-
2063 segmentExtents.append(flowPosition);-
2064 flowPosition = info.spacing + segStartPosition;-
2065 segPosition += deltaSegPosition;-
2066 if (info.wrap)-
2067 segPosition += info.spacing;-
2068 segmentPositions.append(segPosition);-
2069 segmentStartRows.append(row);-
2070 deltaSegPosition = 0;-
2071 }-
2072-
2073 scrollValueMap.append(flowPositions.count());-
2074 flowPositions.append(flowPosition);-
2075-
2076 deltaSegPosition = qMax(deltaSegHint, deltaSegPosition);-
2077 flowPosition += info.spacing + deltaFlowPosition;-
2078 }-
2079 }-
2080-
2081 batchSavedPosition = flowPosition;-
2082 batchSavedDeltaSeg = deltaSegPosition;-
2083 batchStartRow = info.last + 1;-
2084 if (info.last == info.max)-
2085 flowPosition -= info.spacing;-
2086-
2087 QRect rect = info.bounds;-
2088 if (info.flow == QListView::LeftToRight) {-
2089 rect.setRight(segmentPositions.count() == 1 ? flowPosition : info.bounds.right());-
2090 rect.setBottom(segPosition + deltaSegPosition);-
2091 } else {-
2092 rect.setRight(segPosition + deltaSegPosition);-
2093 rect.setBottom(segmentPositions.count() == 1 ? flowPosition : info.bounds.bottom());-
2094 }-
2095 contentsSize = QSize(rect.right(), rect.bottom());-
2096-
2097 if (info.last == info.max) {-
2098 segmentExtents.append(flowPosition);-
2099 scrollValueMap.append(flowPositions.count());-
2100 flowPositions.append(flowPosition);-
2101 segmentPositions.append(info.wrap ? segPosition + deltaSegPosition : 2147483647);-
2102 }-
2103-
2104 QRect changedRect(topLeft, rect.bottomRight());-
2105 if (clipRect().intersects(changedRect))-
2106 viewport()->update();-
2107}-
2108-
2109-
2110-
2111-
2112-
2113-
2114QVector<QModelIndex> QListModeViewBase::intersectingSet(const QRect &area) const-
2115{-
2116 QVector<QModelIndex> ret;-
2117 int segStartPosition;-
2118 int segEndPosition;-
2119 int flowStartPosition;-
2120 int flowEndPosition;-
2121 if (flow() == QListView::LeftToRight) {-
2122 segStartPosition = area.top();-
2123 segEndPosition = area.bottom();-
2124 flowStartPosition = area.left();-
2125 flowEndPosition = area.right();-
2126 } else {-
2127 segStartPosition = area.left();-
2128 segEndPosition = area.right();-
2129 flowStartPosition = area.top();-
2130 flowEndPosition = area.bottom();-
2131 }-
2132 if (segmentPositions.count() < 2 || flowPositions.isEmpty())-
2133 return ret;-
2134-
2135 const int segLast = segmentPositions.count() - 2;-
2136 int seg = qBinarySearch<int>(segmentPositions, segStartPosition, 0, segLast + 1);-
2137 for (; seg <= segLast && segmentPositions.at(seg) <= segEndPosition; ++seg) {-
2138 int first = segmentStartRows.at(seg);-
2139 int last = (seg < segLast ? segmentStartRows.at(seg + 1) : batchStartRow) - 1;-
2140 if (segmentExtents.at(seg) < flowStartPosition)-
2141 continue;-
2142 int row = qBinarySearch<int>(flowPositions, flowStartPosition, first, last);-
2143 for (; row <= last && flowPositions.at(row) <= flowEndPosition; ++row) {-
2144 if (isHidden(row))-
2145 continue;-
2146 QModelIndex index = modelIndex(row);-
2147 if (index.isValid())-
2148 ret += index;-
2149-
2150-
2151-
2152-
2153 }-
2154 }-
2155 return ret;-
2156}-
2157-
2158void QListModeViewBase::dataChanged(const QModelIndex &, const QModelIndex &)-
2159{-
2160 dd->doDelayedItemsLayout();-
2161}-
2162-
2163-
2164QRect QListModeViewBase::mapToViewport(const QRect &rect) const-
2165{-
2166 if (isWrapping())-
2167 return rect;-
2168-
2169-
2170 QRect result = rect;-
2171 if (flow() == QListView::TopToBottom) {-
2172 result.setLeft(spacing());-
2173 result.setWidth(qMax(rect.width(), qMax(contentsSize.width(), viewport()->width()) - 2 * spacing()));-
2174 } else {-
2175 result.setTop(spacing());-
2176 result.setHeight(qMax(rect.height(), qMax(contentsSize.height(), viewport()->height()) - 2 * spacing()));-
2177 }-
2178 return result;-
2179}-
2180-
2181int QListModeViewBase::perItemScrollingPageSteps(int length, int bounds, bool wrap) const-
2182{-
2183 QVector<int> positions;-
2184 if (wrap
wrapDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2185 positions = segmentPositions;
never executed: positions = segmentPositions;
0
2186 else if (!flowPositions.isEmpty()
!flowPositions.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2187 positions.reserve(scrollValueMap.size());-
2188 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(scrollValueMap)>::type> _container_((scrollValueMap)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (int itemShown = *_container_.i; _container_.control; _container_.control = 0)-
2189 positions.append(flowPositions.at(itemShown));
never executed: positions.append(flowPositions.at(itemShown));
0
2190 }
never executed: end of block
0
2191 if (positions.isEmpty()
positions.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
|| bounds <= length
bounds <= lengthDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2192 return
never executed: return positions.count();
positions.count();
never executed: return positions.count();
0
2193 if (uniformItemSizes()
uniformItemSizes()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2194 for (int i = 1; i < positions.count()
i < positions.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
2195 if (positions.at(i) > 0
positions.at(i) > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2196 return
never executed: return length / positions.at(i);
length / positions.at(i);
never executed: return length / positions.at(i);
0
2197 return
never executed: return 0;
0;
never executed: return 0;
0
2198 }-
2199 int pageSteps = 0;-
2200 int steps = positions.count() - 1;-
2201 int max = qMax(length, bounds);-
2202 int min = qMin(length, bounds);-
2203 int pos = min - (max - positions.lastconstLast());-
2204-
2205 while (pos >= 0
pos >= 0Description
TRUEnever evaluated
FALSEnever evaluated
&& steps > 0
steps > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2206 pos -= (positions.at(steps) - positions.at(steps - 1));-
2207 if (pos >= 0
pos >= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2208 ++
never executed: ++pageSteps;
pageSteps;
never executed: ++pageSteps;
0
2209 --steps;-
2210 }
never executed: end of block
0
2211-
2212-
2213 return
never executed: return qMax(pageSteps, 1);
qMax(pageSteps, 1);
never executed: return qMax(pageSteps, 1);
0
2214}-
2215-
2216int QListModeViewBase::perItemScrollToValue(int index, int scrollValue, int viewportSize,-
2217 QAbstractItemView::ScrollHint hint,-
2218 Qt::Orientation orientation, bool wrap, int itemExtent) const-
2219{-
2220 if (index < 0)-
2221 return scrollValue;-
2222-
2223 itemExtent += spacing();-
2224 QVector<int> visibleFlowPositions;-
2225 visibleFlowPositions.reserve(flowPositions.count() - 1);-
2226 for (int i = 0; i < flowPositions.count() - 1; i++) {-
2227 if (!isHidden(i))-
2228 visibleFlowPositions.append(flowPositions.at(i));-
2229 }-
2230-
2231 if (!wrap) {-
2232 int topIndex = index;-
2233 const int bottomIndex = topIndex;-
2234 const int bottomCoordinate = visibleFlowPositions.at(index);-
2235-
2236 while (topIndex > 0 &&-
2237 (bottomCoordinate - visibleFlowPositions.at(topIndex - 1) + itemExtent) <= (viewportSize)) {-
2238 topIndex--;-
2239 }-
2240-
2241 const int itemCount = bottomIndex - topIndex + 1;-
2242 switch (hint) {-
2243 case QAbstractItemView::PositionAtTop:-
2244 return index;-
2245 case QAbstractItemView::PositionAtBottom:-
2246 return index - itemCount + 1;-
2247 case QAbstractItemView::PositionAtCenter:-
2248 return index - (itemCount / 2);-
2249 default:-
2250 break;-
2251 }-
2252 } else {-
2253 Qt::Orientation flowOrientation = (flow() == QListView::LeftToRight-
2254 ? Qt::Horizontal : Qt::Vertical);-
2255 if (flowOrientation == orientation) {-
2256-
2257 return visibleFlowPositions.at(index);-
2258 } else if (!segmentStartRows.isEmpty()) {-
2259 int segment = qBinarySearch<int>(segmentStartRows, index, 0, segmentStartRows.count() - 1);-
2260 int leftSegment = segment;-
2261 const int rightSegment = leftSegment;-
2262 const int bottomCoordinate = segmentPositions.at(segment);-
2263-
2264 while (leftSegment > scrollValue &&-
2265 (bottomCoordinate - segmentPositions.at(leftSegment-1) + itemExtent) <= (viewportSize)) {-
2266 leftSegment--;-
2267 }-
2268-
2269 const int segmentCount = rightSegment - leftSegment + 1;-
2270 switch (hint) {-
2271 case QAbstractItemView::PositionAtTop:-
2272 return segment;-
2273 case QAbstractItemView::PositionAtBottom:-
2274 return segment - segmentCount + 1;-
2275 case QAbstractItemView::PositionAtCenter:-
2276 return segment - (segmentCount / 2);-
2277 default:-
2278 break;-
2279 }-
2280 }-
2281 }-
2282 return scrollValue;-
2283}-
2284-
2285void QListModeViewBase::clear()-
2286{-
2287 flowPositions.clear();-
2288 segmentPositions.clear();-
2289 segmentStartRows.clear();-
2290 segmentExtents.clear();-
2291 batchSavedPosition = 0;-
2292 batchStartRow = 0;-
2293 batchSavedDeltaSeg = 0;-
2294}-
2295-
2296-
2297-
2298-
2299-
2300void QIconModeViewBase::setPositionForIndex(const QPoint &position, const QModelIndex &index)-
2301{-
2302 if (index.row() >= items.count())-
2303 return;-
2304 const QSize oldContents = contentsSize;-
2305 qq->update(index);-
2306 moveItem(index.row(), position);-
2307 qq->update(index);-
2308-
2309 if (contentsSize != oldContents)-
2310 dd->viewUpdateGeometries();-
2311}-
2312-
2313void QIconModeViewBase::appendHiddenRow(int row)-
2314{-
2315 if (row >= 0 && row < items.count())-
2316 tree.removeLeaf(items.at(row).rect(), row);-
2317 QCommonListViewBase::appendHiddenRow(row);-
2318}-
2319-
2320void QIconModeViewBase::removeHiddenRow(int row)-
2321{-
2322 QCommonListViewBase::removeHiddenRow(row);-
2323 if (row >= 0 && row < items.count())-
2324 tree.insertLeaf(items.at(row).rect(), row);-
2325}-
2326-
2327-
2328bool QIconModeViewBase::filterStartDrag(Qt::DropActions supportedActions)-
2329{-
2330-
2331-
2332-
2333 QModelIndexList indexes = dd->selectionModel->selectedIndexes();-
2334 if (indexes.count() > 0 ) {-
2335 if (viewport()->acceptDrops()) {-
2336 QModelIndexList::ConstIterator it = indexes.constBegin();-
2337 for (; it != indexes.constEnd(); ++it)-
2338 if (dd->model->flags(*it) & Qt::ItemIsDragEnabled-
2339 && (*it).column() == dd->column)-
2340 draggedItems.push_back(*it);-
2341 }-
2342-
2343 QRect rect;-
2344 QPixmap pixmap = dd->renderToPixmap(indexes, &rect);-
2345 rect.adjust(horizontalOffset(), verticalOffset(), 0, 0);-
2346 QDrag *drag = new QDrag(qq);-
2347 drag->setMimeData(dd->model->mimeData(indexes));-
2348 drag->setPixmap(pixmap);-
2349 drag->setHotSpot(dd->pressedPosition - rect.topLeft());-
2350 Qt::DropAction action = drag->exec(supportedActions, dd->defaultDropAction);-
2351 draggedItems.clear();-
2352 if (action == Qt::MoveAction)-
2353 dd->clearOrRemove();-
2354 }-
2355 return true;-
2356}-
2357-
2358bool QIconModeViewBase::filterDropEvent(QDropEvent *e)-
2359{-
2360 if (e->source() != qq
e->source() != qqDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2361 return
never executed: return false;
false;
never executed: return false;
0
2362-
2363 const QSize contents = contentsSize;-
2364 QPoint offset(horizontalOffset(), verticalOffset());-
2365 QPoint end = e->pos() + offset;-
2366 if (qq->acceptDrops()
qq->acceptDrops()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
2367 const Qt::ItemFlags dropableFlags = Qt::ItemIsDropEnabled|Qt::ItemIsEnabled;-
2368 const QVector<QModelIndex> &dropIndices = intersectingSet(QRect(end, QSize(1, 1)));-
2369 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(dropIndices)>::type> _container_((dropIndices)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QModelIndex &index = *_container_.i; _container_.control; _container_.control = 0)-
2370 if ((
(index.flags()... dropableFlagsDescription
TRUEnever evaluated
FALSEnever evaluated
index.flags() & dropableFlags) == dropableFlags
(index.flags()... dropableFlagsDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2371 return
never executed: return false;
false;
never executed: return false;
0
2372 }
never executed: end of block
0
2373 QPoint start = dd->pressedPosition;-
2374 QPoint delta = (dd->movement == QListView::Snap
dd->movement =...ListView::SnapDescription
TRUEnever evaluated
FALSEnever evaluated
? snapToGrid(end) - snapToGrid(start) : end - start);
0
2375 const QList<QModelIndex> indexes = dd->selectionModel->selectedIndexes();-
2376 for (int i = 0; i <const auto &index : indexes.count(); ++i) {-
2377 QModelIndex index = indexes.at(i);QRect rect = dd->rectForIndex(index);-
2378 viewport()->update(dd->mapToViewport(rect, false));-
2379 QPoint dest = rect.topLeft() + delta;-
2380 if (qq->isRightToLeft()
qq->isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2381 dest.setX(dd->flipX(dest.x()) - rect.width());
never executed: dest.setX(dd->flipX(dest.x()) - rect.width());
0
2382 moveItem(index.row(), dest);-
2383 qq->update(index);-
2384 }
never executed: end of block
0
2385 dd->stopAutoScroll();-
2386 draggedItems.clear();-
2387 dd->emitIndexesMoved(indexes);-
2388 e->accept();-
2389-
2390 if (contentsSize != contents
contentsSize != contentsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
2391 if ((contentsSize.width() <= contents.width()
contentsSize.w...ntents.width()Description
TRUEnever evaluated
FALSEnever evaluated
0
2392 || contentsSize.height() <= contents.height()
contentsSize.h...tents.height()Description
TRUEnever evaluated
FALSEnever evaluated
)) {
0
2393 updateContentsSize();-
2394 }
never executed: end of block
0
2395 dd->viewUpdateGeometries();-
2396 }
never executed: end of block
0
2397 return
never executed: return true;
true;
never executed: return true;
0
2398}-
2399-
2400bool QIconModeViewBase::filterDragLeaveEvent(QDragLeaveEvent *e)-
2401{-
2402 viewport()->update(draggedItemsRect());-
2403 draggedItemsPos = QPoint(-1, -1);-
2404 return QCommonListViewBase::filterDragLeaveEvent(e);-
2405}-
2406-
2407bool QIconModeViewBase::filterDragMoveEvent(QDragMoveEvent *e)-
2408{-
2409 if (e->source() != qq || !dd->canDrop(e))-
2410 return false;-
2411-
2412-
2413 e->ignore();-
2414-
2415 QRect itemsRect = this->itemsRect(draggedItems);-
2416 viewport()->update(itemsRect.translated(draggedItemsDelta()));-
2417-
2418 draggedItemsPos = e->pos();-
2419-
2420 viewport()->update(itemsRect.translated(draggedItemsDelta()));-
2421-
2422 QModelIndex index;-
2423 if (movement() == QListView::Snap) {-
2424 QRect rect(snapToGrid(e->pos() + offset()), gridSize());-
2425 const QVector<QModelIndex> intersectVector = intersectingSet(rect);-
2426 index = intersectVector.count() > 0 ? intersectVector.last() : QModelIndex();-
2427 } else {-
2428 index = qq->indexAt(e->pos());-
2429 }-
2430-
2431 if (draggedItems.contains(index))-
2432 e->accept();-
2433 else if (dd->model->flags(index) & Qt::ItemIsDropEnabled)-
2434 e->accept();-
2435 else if (!index.isValid())-
2436 e->accept();-
2437-
2438-
2439 if (dd->shouldAutoScroll(e->pos()))-
2440 dd->startAutoScroll();-
2441 return true;-
2442}-
2443-
2444-
2445void QIconModeViewBase::setRowCount(int rowCount)-
2446{-
2447 tree.create(qMax(rowCount - hiddenCount(), 0));-
2448}-
2449-
2450void QIconModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand)-
2451{-
2452 if (scrollElasticBand)-
2453 dd->scrollElasticBandBy(isRightToLeft() ? -dx : dx, dy);-
2454-
2455 QCommonListViewBase::scrollContentsBy(dx, dy, scrollElasticBand);-
2456 if (!draggedItems.isEmpty())-
2457 viewport()->update(draggedItemsRect().translated(dx, dy));-
2458}-
2459-
2460void QIconModeViewBase::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)-
2461{-
2462 if (column() >= topLeft.column() && column() <= bottomRight.column()) {-
2463 QStyleOptionViewItem option = viewOptions();-
2464 int bottom = qMin(items.count(), bottomRight.row() + 1);-
2465 for (int row = topLeft.row(); row < bottom; ++row)-
2466 items[row].resize(itemSize(option, modelIndex(row)));-
2467 }-
2468}-
2469-
2470bool QIconModeViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, int max)-
2471{-
2472 if (info.last >= items.count()) {-
2473-
2474 QStyleOptionViewItem option = viewOptions();-
2475 for (int row = items.count(); row <= info.last; ++row) {-
2476 QSize size = itemSize(option, modelIndex(row));-
2477 QListViewItem item(QRect(0, 0, size.width(), size.height()), row);-
2478 items.append(item);-
2479 }-
2480 doDynamicLayout(info);-
2481 }-
2482 return (batchStartRow > max);-
2483}-
2484-
2485QListViewItem QIconModeViewBase::indexToListViewItem(const QModelIndex &index) const-
2486{-
2487 if (index.isValid() && index.row() < items.count())-
2488 return items.at(index.row());-
2489 return QListViewItem();-
2490}-
2491-
2492void QIconModeViewBase::initBspTree(const QSize &contents)-
2493{-
2494-
2495 int leafCount = tree.leafCount();-
2496 for (int l = 0; l < leafCount; ++l)-
2497 tree.leaf(l).clear();-
2498-
2499 QBspTree::Node::Type type = QBspTree::Node::Both;-
2500-
2501 if (contents.height() / contents.width() >= 3)-
2502 type = QBspTree::Node::HorizontalPlane;-
2503 else if (contents.width() / contents.height() >= 3)-
2504 type = QBspTree::Node::VerticalPlane;-
2505-
2506 tree.init(QRect(0, 0, contents.width(), contents.height()), type);-
2507}-
2508-
2509QPoint QIconModeViewBase::initDynamicLayout(const QListViewLayoutInfo &info)-
2510{-
2511 int x, y;-
2512 if (info.first == 0) {-
2513 x = info.bounds.x() + info.spacing;-
2514 y = info.bounds.y() + info.spacing;-
2515 items.reserve(rowCount() - hiddenCount());-
2516 } else {-
2517 int idx = info.first - 1;-
2518 while (idx > 0 && !items.at(idx).isValid())-
2519 --idx;-
2520 const QListViewItem &item = items.at(idx);-
2521 x = item.x;-
2522 y = item.y;-
2523 if (info.flow == QListView::LeftToRight)-
2524 x += (info.grid.isValid() ? info.grid.width() : item.w) + info.spacing;-
2525 else-
2526 y += (info.grid.isValid() ? info.grid.height() : item.h) + info.spacing;-
2527 }-
2528 return QPoint(x, y);-
2529}-
2530-
2531-
2532-
2533-
2534void QIconModeViewBase::doDynamicLayout(const QListViewLayoutInfo &info)-
2535{-
2536 const bool useItemSize = !info.grid.isValid();-
2537 const QPoint topLeft = initDynamicLayout(info);-
2538-
2539 int segStartPosition;-
2540 int segEndPosition;-
2541 int deltaFlowPosition;-
2542 int deltaSegPosition;-
2543 int deltaSegHint;-
2544 int flowPosition;-
2545 int segPosition;-
2546-
2547 if (info.flow == QListView::LeftToRight) {-
2548 segStartPosition = info.bounds.left() + info.spacing;-
2549 segEndPosition = info.bounds.right();-
2550 deltaFlowPosition = info.grid.width();-
2551 deltaSegPosition = (useItemSize ? batchSavedDeltaSeg : info.grid.height());-
2552 deltaSegHint = info.grid.height();-
2553 flowPosition = topLeft.x();-
2554 segPosition = topLeft.y();-
2555 } else {-
2556 segStartPosition = info.bounds.top() + info.spacing;-
2557 segEndPosition = info.bounds.bottom();-
2558 deltaFlowPosition = info.grid.height();-
2559 deltaSegPosition = (useItemSize ? batchSavedDeltaSeg : info.grid.width());-
2560 deltaSegHint = info.grid.width();-
2561 flowPosition = topLeft.y();-
2562 segPosition = topLeft.x();-
2563 }-
2564-
2565 if (moved.count() != items.count())-
2566 moved.resize(items.count());-
2567-
2568 QRect rect(QPoint(), topLeft);-
2569 QListViewItem *item = 0;-
2570 for (int row = info.first; row <= info.last; ++row) {-
2571 item = &items[row];-
2572 if (isHidden(row)) {-
2573 item->invalidate();-
2574 } else {-
2575-
2576 if (useItemSize) {-
2577 if (info.flow == QListView::LeftToRight)-
2578 deltaFlowPosition = item->w + info.spacing;-
2579 else-
2580 deltaFlowPosition = item->h + info.spacing;-
2581 } else {-
2582 item->w = qMin<int>(info.grid.width(), item->w);-
2583 item->h = qMin<int>(info.grid.height(), item->h);-
2584 }-
2585-
2586-
2587 if (info.wrap-
2588 && flowPosition + deltaFlowPosition > segEndPosition-
2589 && flowPosition > segStartPosition) {-
2590 flowPosition = segStartPosition;-
2591 segPosition += deltaSegPosition;-
2592 if (useItemSize)-
2593 deltaSegPosition = 0;-
2594 }-
2595-
2596-
2597 if (useItemSize) {-
2598 if (info.flow == QListView::LeftToRight)-
2599 deltaSegHint = item->h + info.spacing;-
2600 else-
2601 deltaSegHint = item->w + info.spacing;-
2602 deltaSegPosition = qMax(deltaSegPosition, deltaSegHint);-
2603 }-
2604-
2605-
2606-
2607-
2608 if (!moved.testBit(row)) {-
2609 if (info.flow == QListView::LeftToRight) {-
2610 if (useItemSize) {-
2611 item->x = flowPosition;-
2612 item->y = segPosition;-
2613 } else {-
2614 item->x = flowPosition + ((deltaFlowPosition - item->w) / 2);-
2615 item->y = segPosition;-
2616 }-
2617 } else {-
2618 if (useItemSize) {-
2619 item->y = flowPosition;-
2620 item->x = segPosition;-
2621 } else {-
2622 item->y = flowPosition + ((deltaFlowPosition - item->h) / 2);-
2623 item->x = segPosition;-
2624 }-
2625 }-
2626 }-
2627-
2628-
2629 if (useItemSize)-
2630 rect |= item->rect();-
2631 else if (info.flow == QListView::LeftToRight)-
2632 rect |= QRect(flowPosition, segPosition, deltaFlowPosition, deltaSegPosition);-
2633 else-
2634 rect |= QRect(segPosition, flowPosition, deltaSegPosition, deltaFlowPosition);-
2635-
2636-
2637 flowPosition += deltaFlowPosition;-
2638 }-
2639 }-
2640 batchSavedDeltaSeg = deltaSegPosition;-
2641 batchStartRow = info.last + 1;-
2642 bool done = (info.last >= rowCount() - 1);-
2643-
2644 if (done || !info.bounds.contains(item->rect())) {-
2645 contentsSize = rect.size();-
2646 if (info.flow == QListView::LeftToRight)-
2647 contentsSize.rheight() += info.spacing;-
2648 else-
2649 contentsSize.rwidth() += info.spacing;-
2650 }-
2651 if (rect.size().isEmpty())-
2652 return;-
2653-
2654 int insertFrom = info.first;-
2655 if (done || info.first == 0) {-
2656 initBspTree(rect.size());-
2657 insertFrom = 0;-
2658 }-
2659-
2660 for (int row = insertFrom; row <= info.last; ++row)-
2661 tree.insertLeaf(items.at(row).rect(), row);-
2662-
2663 QRect changedRect(topLeft, rect.bottomRight());-
2664 if (clipRect().intersects(changedRect))-
2665 viewport()->update();-
2666}-
2667-
2668QVector<QModelIndex> QIconModeViewBase::intersectingSet(const QRect &area) const-
2669{-
2670 QIconModeViewBase *that = const_cast<QIconModeViewBase*>(this);-
2671 QBspTree::Data data(static_cast<void*>(that));-
2672 QVector<QModelIndex> res;-
2673 that->interSectingVector = &res;-
2674 that->tree.climbTree(area, &QIconModeViewBase::addLeaf, data);-
2675 that->interSectingVector = 0;-
2676 return res;-
2677}-
2678-
2679QRect QIconModeViewBase::itemsRect(const QVector<QModelIndex> &indexes) const-
2680{-
2681 QVector<QModelIndex>::const_iterator it = indexes.begin();-
2682 QListViewItem item = indexToListViewItem(*it);-
2683 QRect rect(item.x, item.y, item.w, item.h);-
2684 for (; it != indexes.end(); ++it) {-
2685 item = indexToListViewItem(*it);-
2686 rect |= viewItemRect(item);-
2687 }-
2688 return rect;-
2689}-
2690-
2691int QIconModeViewBase::itemIndex(const QListViewItem &item) const-
2692{-
2693 if (!item.isValid())-
2694 return -1;-
2695 int i = item.indexHint;-
2696 if (i < items.count()) {-
2697 if (items.at(i) == item)-
2698 return i;-
2699 } else {-
2700 i = items.count() - 1;-
2701 }-
2702-
2703 int j = i;-
2704 int c = items.count();-
2705 bool a = true;-
2706 bool b = true;-
2707-
2708 while (a || b) {-
2709 if (a) {-
2710 if (items.at(i) == item) {-
2711 items.at(i).indexHint = i;-
2712 return i;-
2713 }-
2714 a = ++i < c;-
2715 }-
2716 if (b) {-
2717 if (items.at(j) == item) {-
2718 items.at(j).indexHint = j;-
2719 return j;-
2720 }-
2721 b = --j > -1;-
2722 }-
2723 }-
2724 return -1;-
2725}-
2726-
2727void QIconModeViewBase::addLeaf(QVector<int> &leaf, const QRect &area,-
2728 uint visited, QBspTree::Data data)-
2729{-
2730 QListViewItem *vi;-
2731 QIconModeViewBase *_this = static_cast<QIconModeViewBase *>(data.ptr);-
2732 for (int i = 0; i < leaf.count(); ++i) {-
2733 int idx = leaf.at(i);-
2734 if (idx < 0 || idx >= _this->items.count())-
2735 continue;-
2736 vi = &_this->items[idx];-
2737 ((!(vi)) ? qt_assert("vi",__FILE__,31403150) : qt_noop());-
2738 if (vi->isValid() && vi->rect().intersects(area) && vi->visited != visited) {-
2739 QModelIndex index = _this->dd->listViewItemToIndex(*vi);-
2740 ((!(index.isValid())) ? qt_assert("index.isValid()",__FILE__,31433153) : qt_noop());-
2741 _this->interSectingVector->append(index);-
2742 vi->visited = visited;-
2743 }-
2744 }-
2745}-
2746-
2747void QIconModeViewBase::moveItem(int index, const QPoint &dest)-
2748{-
2749-
2750 QListViewItem *item = &items[index];-
2751 QRect rect = item->rect();-
2752-
2753-
2754 tree.removeLeaf(rect, index);-
2755 item->move(dest);-
2756 tree.insertLeaf(QRect(dest, rect.size()), index);-
2757-
2758-
2759 contentsSize = (QRect(QPoint(0, 0), contentsSize)|QRect(dest, rect.size())).size();-
2760-
2761-
2762 if (moved.count() != items.count())-
2763 moved.resize(items.count());-
2764 moved.setBit(index, true);-
2765}-
2766-
2767QPoint QIconModeViewBase::snapToGrid(const QPoint &pos) const-
2768{-
2769 int x = pos.x() - (pos.x() % gridSize().width());-
2770 int y = pos.y() - (pos.y() % gridSize().height());-
2771 return QPoint(x, y);-
2772}-
2773-
2774QPoint QIconModeViewBase::draggedItemsDelta() const-
2775{-
2776 if (movement() == QListView::Snap) {-
2777 QPoint snapdelta = QPoint((offset().x() % gridSize().width()),-
2778 (offset().y() % gridSize().height()));-
2779 return snapToGrid(draggedItemsPos + snapdelta) - snapToGrid(pressedPosition()) - snapdelta;-
2780 }-
2781 return draggedItemsPos - pressedPosition();-
2782}-
2783-
2784QRect QIconModeViewBase::draggedItemsRect() const-
2785{-
2786 QRect rect = itemsRect(draggedItems);-
2787 rect.translate(draggedItemsDelta());-
2788 return rect;-
2789}-
2790-
2791void QListViewPrivate::scrollElasticBandBy(int dx, int dy)-
2792{-
2793 if (dx > 0)-
2794 elasticBand.moveRight(elasticBand.right() + dx);-
2795 else if (dx < 0)-
2796 elasticBand.moveLeft(elasticBand.left() - dx);-
2797 if (dy > 0)-
2798 elasticBand.moveBottom(elasticBand.bottom() + dy);-
2799 else if (dy < 0)-
2800 elasticBand.moveTop(elasticBand.top() - dy);-
2801}-
2802-
2803void QIconModeViewBase::clear()-
2804{-
2805 tree.destroy();-
2806 items.clear();-
2807 moved.clear();-
2808 batchStartRow = 0;-
2809 batchSavedDeltaSeg = 0;-
2810}-
2811-
2812void QIconModeViewBase::updateContentsSize()-
2813{-
2814 QRect bounding;-
2815 for (int i = 0; i < items.count(); ++i)-
2816 bounding |= items.at(i).rect();-
2817 contentsSize = bounding.size();-
2818}-
2819-
2820-
2821-
2822-
2823void QListView::currentChanged(const QModelIndex &current, const QModelIndex &previous)-
2824{-
2825-
2826 if (QAccessible::isActive()) {-
2827 if (current.isValid()) {-
2828 int entry = visualIndex(current);-
2829 QAccessibleEvent event(this, QAccessible::Focus);-
2830 event.setChild(entry);-
2831 QAccessible::updateAccessibility(&event);-
2832 }-
2833 }-
2834-
2835 QAbstractItemView::currentChanged(current, previous);-
2836}-
2837-
2838-
2839-
2840-
2841void QListView::selectionChanged(const QItemSelection &selected,-
2842 const QItemSelection &deselected)-
2843{-
2844-
2845 if (QAccessible::isActive()) {-
2846-
2847 QModelIndex sel = selected.indexes().value(0);-
2848 if (sel.isValid()) {-
2849 int entry = visualIndex(sel);-
2850 QAccessibleEvent event(this, QAccessible::SelectionAdd);-
2851 event.setChild(entry);-
2852 QAccessible::updateAccessibility(&event);-
2853 }-
2854 QModelIndex desel = deselected.indexes().value(0);-
2855 if (desel.isValid()) {-
2856 int entry = visualIndex(desel);-
2857 QAccessibleEvent event(this, QAccessible::SelectionRemove);-
2858 event.setChild(entry);-
2859 QAccessible::updateAccessibility(&event);-
2860 }-
2861 }-
2862-
2863 QAbstractItemView::selectionChanged(selected, deselected);-
2864}-
2865-
2866int QListView::visualIndex(const QModelIndex &index) const-
2867{-
2868 const QListViewPrivate * const d = d_func();-
2869 d->executePostedLayout();-
2870 QListViewItem itm = d->indexToListViewItem(index);-
2871 int visualIndex = d->commonListView->itemIndex(itm);-
2872 for (int row = 0; row <= index.row() && visualIndex >= 0; row++) {-
2873 if (d->isHidden(row))-
2874 visualIndex--;-
2875 }-
2876 return visualIndex;-
2877}-
2878-
2879-
2880-
2881-
2882-
2883-
2884QSize QListView::viewportSizeHint() const-
2885{-
2886 return QAbstractItemView::viewportSizeHint();-
2887}-
2888-
2889-
2890-
Switch to Source codePreprocessed file

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