44 #ifndef QT_NO_ACCESSIBILITY
51 #if QT_CONFIG(draganddrop)
56 #if QT_CONFIG(rubberband)
61 #include <private/qapplication_p.h>
62 #include <private/qlistview_p.h>
63 #include <private/qscrollbar_p.h>
185 setSelectionMode(SingleSelection);
188 d->updateStyledFrameWidths();
201 d->updateStyledFrameWidths();
236 #if QT_CONFIG(draganddrop)
238 setDragEnabled(movable);
239 d->viewport->setAcceptDrops(movable);
241 d->doDelayedItemsLayout();
272 d->doDelayedItemsLayout();
301 d->doDelayedItemsLayout();
307 return d->isWrapping();
326 d->resizeMode =
mode;
332 return d->resizeMode;
351 d->layoutMode =
mode;
357 return d->layoutMode;
378 d->setSpacing(space);
379 d->doDelayedItemsLayout();
433 d->setGridSize(
size);
434 d->doDelayedItemsLayout();
440 return d->gridSize();
461 if (
d->commonListView &&
d->viewMode ==
mode)
465 delete d->commonListView;
469 d->setWrapping(
false);
481 d->showElasticBand =
false;
485 d->setWrapping(
true);
497 d->showElasticBand =
true;
500 #if QT_CONFIG(draganddrop)
501 bool movable = (
d->movement !=
Static);
502 setDragEnabled(movable);
503 setAcceptDrops(movable);
506 d->doDelayedItemsLayout();
527 d->modeProperties = 0;
536 return d->isHidden(
row);
546 const bool hidden =
d->isHidden(
row);
548 d->commonListView->appendHiddenRow(
row);
549 else if (!
hide && hidden)
550 d->commonListView->removeHiddenRow(
row);
551 d->doDelayedItemsLayout();
552 d->viewport->update();
571 if (
index.parent() !=
d->root ||
index.column() !=
d->column)
578 d->viewport->update(
rect);
583 verticalScrollBar()->setValue(
d->verticalScrollToValue(
index,
rect, hint));
586 horizontalScrollBar()->setValue(
d->horizontalScrollToValue(
index,
rect, hint));
594 const bool leftOf =
q->isRightToLeft()
597 const bool rightOf =
q->isRightToLeft()
662 std::sort(visibleIndexes.
begin(), visibleIndexes.
end());
663 for (
const auto &
index : indexes) {
664 if (std::binary_search(visibleIndexes.
cbegin(), visibleIndexes.
cend(),
index)) {
683 d->hiddenRows.clear();
693 d->column = qMax(0, qMin(
d->column,
d->model->columnCount(
index) - 1));
697 d->hiddenRows.clear();
709 d->delayedAutoScroll.stop();
731 return d->contentsSize();
740 d_func()->commonListView->dataChanged(topLeft, bottomRight);
752 d->doDelayedItemsLayout();
766 while (
it !=
d->hiddenRows.end()) {
767 int hiddenRow =
it->row();
768 if (hiddenRow >=
start && hiddenRow <=
end) {
769 it =
d->hiddenRows.erase(
it);
776 d->doDelayedItemsLayout();
789 &&
d->showElasticBand
794 d->viewport->update(
d->mapToViewport(
rect.united(
d->elasticBand)));
795 d->elasticBand =
rect;
807 if (
d->showElasticBand &&
d->elasticBand.isValid()) {
808 d->viewport->update(
d->mapToViewport(
d->elasticBand));
813 #if QT_CONFIG(wheelevent)
817 void QListView::wheelEvent(QWheelEvent *
e)
820 if (
qAbs(
e->angleDelta().y()) >
qAbs(
e->angleDelta().x())) {
821 if (
e->angleDelta().x() == 0
823 &&
d->vbar->minimum() == 0 &&
d->vbar->maximum() == 0) {
824 QPoint pixelDelta(
e->pixelDelta().y(),
e->pixelDelta().x());
825 QPoint angleDelta(
e->angleDelta().y(),
e->angleDelta().x());
826 QWheelEvent hwe(
e->position(),
e->globalPosition(), pixelDelta, angleDelta,
827 e->buttons(),
e->modifiers(),
e->phase(),
e->inverted(),
e->source());
828 if (
e->spontaneous())
832 e->setAccepted(hwe.isAccepted());
848 if (
e->timerId() ==
d->batchLayoutTimer.timerId()) {
849 if (
d->doItemsLayout(
d->batchSize)) {
850 d->batchLayoutTimer.stop();
852 d->viewport->update();
864 if (
d->delayedPendingLayout)
867 QSize delta =
e->size() -
e->oldSize();
872 bool listWrap = (
d->viewMode ==
ListMode) &&
d->wrapItemText;
881 d->doDelayedItemsLayout(100);
887 #if QT_CONFIG(draganddrop)
892 void QListView::dragMoveEvent(QDragMoveEvent *
e)
895 if (!
d->commonListView->filterDragMoveEvent(
e)) {
899 QAbstractItemView::dragMoveEvent(
e);
907 void QListView::dragLeaveEvent(QDragLeaveEvent *
e)
909 if (!d_func()->commonListView->filterDragLeaveEvent(
e))
910 QAbstractItemView::dragLeaveEvent(
e);
916 void QListView::dropEvent(QDropEvent *
event)
921 dragDropMode() == QAbstractItemView::InternalMove)) {
923 bool topIndexDropped =
false;
927 if (!
event->isAccepted() &&
d->dropOn(
event, &
row, &col, &topIndex)) {
932 for (
const auto &
index : selIndexes) {
934 if (
index == topIndex) {
935 topIndexDropped =
true;
940 if (!topIndexDropped && !topIndex.
isValid()) {
941 std::sort(persIndexes.
begin(), persIndexes.
end());
946 bool dataMoved =
false;
947 for (
int i = 0;
i < persIndexes.
count(); ++
i) {
949 if (
r != pIndex.
row()) {
958 r = pIndex.
row() + 1;
967 if (
event->isAccepted())
968 d->dropEventMoved =
true;
971 if (!
d->commonListView->filterDropEvent(
event) || !
d->dropEventMoved) {
973 if (!
d->dropEventMoved)
975 QAbstractItemView::dropEvent(
event);
982 void QListView::startDrag(Qt::DropActions supportedActions)
984 if (!d_func()->commonListView->filterStartDrag(supportedActions))
985 QAbstractItemView::startDrag(supportedActions);
997 if (!
d->iconSize.isValid()) {
1004 option->showDecorationSelected =
false;
1011 if (
d->gridSize().isValid()) {
1012 option->rect.setSize(
d->gridSize());
1023 if (!
d->itemDelegate)
1025 QStyleOptionViewItem
option;
1036 const bool focus = (hasFocus() ||
d->viewport->hasFocus()) && current.
isValid();
1037 const bool alternate =
d->alternatingColors;
1042 bool alternateBase =
false;
1043 int previousRow = -2;
1046 ? qMax(
viewport()->size().width(),
d->contentsSize().width()) - 2 *
d->spacing()
1055 option.rect.setWidth(qMin(maxSize,
option.rect.width()));
1057 option.rect.setHeight(qMin(maxSize,
option.rect.height()));
1070 option.palette.setCurrentColorGroup(cg);
1072 if (
focus && current == *
it) {
1080 int row = (*it).row();
1081 if (
row != previousRow + 1) {
1083 if (!
d->hiddenRows.isEmpty()) {
1084 for (
int r = qMax(previousRow + 1, 0);
r <
row; ++
r) {
1085 if (!
d->isHidden(
r))
1086 alternateBase = !alternateBase;
1089 alternateBase = (
row & 1) != 0;
1092 option.features.setFlag(QStyleOptionViewItem::Alternate, alternateBase);
1101 alternateBase = !alternateBase;
1108 #if QT_CONFIG(draganddrop)
1109 d->commonListView->paintDragDrop(&
painter);
1112 #if QT_CONFIG(rubberband)
1114 if (
d->showElasticBand &&
d->elasticBand.isValid()) {
1115 QStyleOptionRubberBand
opt;
1119 opt.
rect =
d->mapToViewport(
d->elasticBand,
false).intersected(
1120 d->viewport->rect().adjusted(-16, -16, 16, 16));
1148 return d_func()->commonListView->horizontalOffset();
1156 return d_func()->commonListView->verticalOffset();
1167 auto findAvailableRowBackward = [
d](
int row) {
1168 while (
row >= 0 &&
d->isHiddenOrDisabled(
row))
1173 auto findAvailableRowForward = [
d](
int row) {
1186 int row = findAvailableRowForward(0);
1189 return d->model->index(
row,
d->column,
d->root);
1194 const int row = findAvailableRowBackward(current.
row() - 1);
1197 return d->model->index(
row,
d->column,
d->root);
1200 const int row = findAvailableRowForward(current.
row() + 1);
1203 return d->model->index(
row,
d->column,
d->root);
1208 if (
rect.isEmpty()) {
1209 return d->model->index(0,
d->column,
d->root);
1211 if (
d->gridSize().isValid())
rect.setSize(
d->gridSize());
1216 switch (cursorAction) {
1218 while (intersectVector.
isEmpty()) {
1220 if (
rect.right() <= 0)
1222 if (
rect.left() < 0)
1224 intersectVector =
d->intersectingSet(
rect);
1225 d->removeCurrentAndDisabled(&intersectVector, current);
1227 return d->closestIndex(initialRect, intersectVector);
1229 while (intersectVector.
isEmpty()) {
1235 intersectVector =
d->intersectingSet(
rect);
1236 d->removeCurrentAndDisabled(&intersectVector, current);
1238 return d->closestIndex(initialRect, intersectVector);
1240 rect.moveTop(
rect.top() -
d->viewport->height() + 1 );
1246 while (intersectVector.
isEmpty()
1248 ||
rect.top() <= 0) {
1249 rect.translate(0, 1);
1250 if (
rect.bottom() <= 0) {
1253 intersectVector =
d->intersectingSet(
rect);
1254 findindex =
d->closestIndex(initialRect, intersectVector);
1260 while (intersectVector.
isEmpty()) {
1262 if (
rect.bottom() <= 0) {
1263 #ifdef QT_KEYPAD_NAVIGATION
1264 if (QApplicationPrivate::keypadNavigationEnabled()) {
1265 int row =
d->batchStartRow() - 1;
1266 while (
row >= 0 &&
d->isHiddenOrDisabled(
row))
1269 return d->model->index(
row,
d->column,
d->root);
1276 intersectVector =
d->intersectingSet(
rect);
1277 d->removeCurrentAndDisabled(&intersectVector, current);
1279 return d->closestIndex(initialRect, intersectVector);
1281 rect.moveTop(
rect.top() +
d->viewport->height() - 1 );
1288 while (intersectVector.
isEmpty()
1291 rect.translate(0, -1);
1295 intersectVector =
d->intersectingSet(
rect);
1296 index =
d->closestIndex(initialRect, intersectVector);
1302 while (intersectVector.
isEmpty()) {
1305 #ifdef QT_KEYPAD_NAVIGATION
1306 if (QApplicationPrivate::keypadNavigationEnabled()) {
1312 return d->model->index(
row,
d->column,
d->root);
1319 intersectVector =
d->intersectingSet(
rect);
1320 d->removeCurrentAndDisabled(&intersectVector, current);
1322 return d->closestIndex(initialRect, intersectVector);
1324 return d->model->index(0,
d->column,
d->root);
1326 return d->model->index(
d->batchStartRow() - 1,
d->column,
d->root);}
1339 return d_func()->rectForIndex(
index);
1354 || !
d->isIndexValid(
index)
1355 ||
index.parent() !=
d->root
1356 ||
index.column() !=
d->column)
1359 d->executePostedLayout();
1369 if (!
d->selectionModel)
1373 int w = qMax(
d->contentsSize().width(),
d->viewport->width());
1374 int h = qMax(
d->contentsSize().height(),
d->viewport->height());
1380 if (
rect.width() == 1 &&
rect.height() == 1) {
1384 if (!intersectVector.
isEmpty())
1385 tl = intersectVector.
last();
1386 if (tl.
isValid() &&
d->isIndexEnabled(tl))
1396 if (!intersectVector.
isEmpty())
1397 tl = intersectVector.
last();
1400 intersectVector =
d->intersectingSet(bottomRight);
1401 if (!intersectVector.
isEmpty())
1402 br = intersectVector.
last();
1406 &&
d->isIndexEnabled(tl)
1407 &&
d->isIndexEnabled(br)) {
1409 QRect last =
d->cellRectForIndex(br);
1415 if (
top.center().y() >
bottom.center().y()) {
1432 }
else if (
top.left() >
bottom.right()) {
1456 if (
left.center().x() >
right.center().x())
1480 }
else if (
left.bottom() <
right.top()) {
1499 d->selectionModel->select(
selection, command);
1514 const QRect &viewportRect =
d->viewport->rect();
1516 if (!elem.isValid())
1523 int t = elem.topLeft().row();
1524 int b = elem.bottomRight().row();
1525 if (
d->viewMode ==
IconMode ||
d->isWrapping()) {
1526 for (
int r =
t;
r <=
b; ++
r) {
1529 selectionRegion +=
rect;
1533 while (
b >=
t &&
d->isHidden(
b)) --
b;
1539 selectionRegion +=
rect;
1543 return selectionRegion;
1552 if (!
d->selectionModel)
1560 return viewSelected;
1576 if (
d->model->columnCount(
d->root) > 0) {
1577 d->resetBatchStartRow();
1579 d->doItemsLayout(
d->model->rowCount(
d->root));
1580 }
else if (!
d->batchLayoutTimer.isActive()) {
1581 if (!
d->doItemsLayout(
d->batchSize))
1582 d->batchLayoutTimer.start(0,
this);
1597 if (geometry().isEmpty() ||
d->model->rowCount(
d->root) <= 0 ||
d->model->columnCount(
d->root) <= 0) {
1598 horizontalScrollBar()->setRange(0, 0);
1599 verticalScrollBar()->setRange(0, 0);
1602 QStyleOptionViewItem
option;
1605 d->commonListView->updateHorizontalScrollBar(
step);
1606 d->commonListView->updateVerticalScrollBar(
step);
1612 if (
d->movement ==
Static && !
d->isWrapping()) {
1613 d->layoutChildren();
1617 horizontalScrollBar()->setRange(0, 0);
1622 verticalScrollBar()->setRange(0, 0);
1635 return (
d->isHidden(
index.row())
1636 && (
index.parent() ==
d->root)
1637 &&
index.column() ==
d->column);
1653 d->doDelayedItemsLayout();
1682 return d->uniformItemSizes;
1702 if (
d->wrapItemText == on)
1704 d->wrapItemText = on;
1705 d->doDelayedItemsLayout();
1711 return d->wrapItemText;
1733 d->setSelectionRectVisible(
show);
1739 return d->isSelectionRectVisible();
1759 d->doDelayedItemsLayout();
1765 return d->itemAlignment;
1792 uniformItemSizes(
false),
1794 showElasticBand(
false),
1819 int frameAroundContents = 0;
1850 int last = qMin(
first + delta - 1, max);
1857 if (max < 0 || last <
first) {
1885 if (!
rect.isValid())
1889 int dx = -
q->horizontalOffset();
1890 int dy = -
q->verticalOffset();
1891 return result.adjusted(dx, dy, dx, dy);
1898 int shortest = INT_MAX;
1902 for (;
it != candidates.
end(); ++
it) {
1903 if (!(*it).isValid())
1911 if ((
target.center().x() >= indexRect.
x() &&
target.center().x() < indexRect.
right())
1915 }
else if ((
target.center().y() >= indexRect.
y() &&
target.center().y() < indexRect.
bottom())
1952 for (;
it != intersectVector.
end(); ++
it) {
1955 }
else if ((*it).row() == (tl.
row() - 1)) {
1957 }
else if ((*it).row() == (br.
row() + 1)) {
1975 #if QT_CONFIG(draganddrop)
1984 bool QListViewPrivate::dropOn(QDropEvent *
event,
int *dropRow,
int *dropCol,
QModelIndex *dropIndex)
1989 return QAbstractItemViewPrivate::dropOn(
event, dropRow, dropCol, dropIndex);
1999 indexes->
removeIf(isCurrentOrDisabled);
2016 #if QT_CONFIG(draganddrop)
2027 return v->contentsRect().marginsRemoved(
v->viewportMargins()).size();
2045 bool horizontalWantsToShow;
2046 if (verticalWantsToShow)
2051 if (bothScrollBarsAuto && !horizontalWantsToShow) {
2075 bool verticalWantsToShow;
2076 if (horizontalWantsToShow)
2081 if (bothScrollBarsAuto && !verticalWantsToShow) {
2096 bool above,
bool below,
const QRect &area,
const QRect &
rect)
const
2101 verticalValue += adjusted.
top();
2103 verticalValue += qMin(adjusted.
top(), adjusted.
bottom() - area.
height() + 1);
2105 verticalValue += adjusted.
top() - ((area.
height() - adjusted.
height()) / 2);
2106 return verticalValue;
2115 bool leftOf,
bool rightOf,
const QRect &area,
const QRect &
rect)
const
2120 horizontalValue += ((area.
width() -
rect.width()) / 2) -
rect.left();
2123 horizontalValue -=
rect.left();
2125 horizontalValue += qMin(
rect.left(), area.
width() -
rect.right());
2129 horizontalValue +=
rect.left() - ((area.
width()-
rect.width()) / 2);
2132 horizontalValue +=
rect.left();
2134 horizontalValue += qMin(
rect.left(),
rect.right() - area.
width());
2137 return horizontalValue;
2146 #if QT_CONFIG(draganddrop)
2151 #if QT_CONFIG(draganddrop)
2154 QAbstractItemView::DropIndicatorPosition
r = QAbstractItemView::OnViewport;
2155 if (!
dd->overwrite) {
2156 const int margin = 2;
2157 if (
pos.x() -
rect.left() < margin) {
2158 r = QAbstractItemView::AboveItem;
2159 }
else if (
rect.right() -
pos.x() < margin) {
2160 r = QAbstractItemView::BelowItem;
2161 }
else if (
rect.contains(
pos,
true)) {
2162 r = QAbstractItemView::OnItem;
2166 touchingRect.
adjust(-1, -1, 1, 1);
2168 r = QAbstractItemView::OnItem;
2173 r =
pos.x() <
rect.center().x() ? QAbstractItemView::AboveItem : QAbstractItemView::BelowItem;
2178 void QListModeViewBase::dragMoveEvent(QDragMoveEvent *
event)
2180 if (
qq->dragDropMode() == QAbstractItemView::InternalMove
2188 QPoint p =
event->position().toPoint();
2198 if (
index.isValid() &&
dd->showDropIndicator) {
2202 switch (
dd->dropIndicatorPosition) {
2203 case QAbstractItemView::AboveItem:
2208 dd->dropIndicatorRect =
QRect();
2211 case QAbstractItemView::BelowItem:
2216 dd->dropIndicatorRect =
QRect();
2219 case QAbstractItemView::OnItem:
2221 dd->dropIndicatorRect =
rect;
2224 dd->dropIndicatorRect =
QRect();
2227 case QAbstractItemView::OnViewport:
2228 dd->dropIndicatorRect =
QRect();
2235 dd->dropIndicatorRect =
QRect();
2236 dd->dropIndicatorPosition = QAbstractItemView::OnViewport;
2241 dd->viewport->update();
2259 bool QListModeViewBase::dropOn(QDropEvent *
event,
int *dropRow,
int *dropCol,
QModelIndex *dropIndex)
2261 if (
event->isAccepted())
2265 if (
dd->viewport->rect().contains(
event->position().toPoint())) {
2267 QPoint p =
event->position().toPoint();
2273 if (!
index.isValid())
2283 switch (
dd->dropIndicatorPosition) {
2284 case QAbstractItemView::AboveItem:
2286 col =
index.column();
2289 case QAbstractItemView::BelowItem:
2291 col =
index.column();
2294 case QAbstractItemView::OnItem:
2295 case QAbstractItemView::OnViewport:
2299 dd->dropIndicatorPosition = QAbstractItemView::OnViewport;
2353 bool above,
bool below,
const QRect &area,
const QRect &
rect)
const
2363 if (
idx.row() <= scrollBarValue)
2422 bool leftOf,
bool rightOf,
const QRect &area,
const QRect &
rect)
const
2459 dx = previousCoordinate - currentCoordinate;
2465 dy = previousCoordinate - currentCoordinate;
2476 dy = previousCoordinate - currentCoordinate;
2482 dx = previousCoordinate - currentCoordinate;
2490 doStaticLayout(
info);
2505 QStyleOptionViewItem options;
2545 if (
info.first == 0) {
2555 }
else if (
info.wrap) {
2580 const bool useItemSize = !
info.grid.isValid();
2581 const QPoint topLeft = initStaticLayout(
info);
2582 QStyleOptionViewItem
option;
2593 int segStartPosition;
2595 int deltaFlowPosition;
2596 int deltaSegPosition;
2602 segStartPosition =
info.bounds.left();
2603 segEndPosition =
info.bounds.width();
2604 flowPosition = topLeft.
x();
2605 segPosition = topLeft.
y();
2606 deltaFlowPosition =
info.grid.width();
2608 deltaSegHint =
info.grid.height();
2610 segStartPosition =
info.bounds.top();
2611 segEndPosition =
info.bounds.height();
2612 flowPosition = topLeft.
y();
2613 segPosition = topLeft.
x();
2614 deltaFlowPosition =
info.grid.height();
2616 deltaSegHint =
info.grid.width();
2627 deltaFlowPosition = hint.
width() +
info.spacing;
2630 deltaFlowPosition = hint.
height() +
info.spacing;
2631 deltaSegHint = hint.
width() +
info.spacing;
2635 if (
info.wrap && (flowPosition + deltaFlowPosition >= segEndPosition)) {
2637 flowPosition =
info.spacing + segStartPosition;
2638 segPosition +=
info.spacing + deltaSegPosition;
2641 deltaSegPosition = 0;
2647 deltaSegPosition = qMax(deltaSegHint, deltaSegPosition);
2648 flowPosition +=
info.spacing + deltaFlowPosition;
2656 flowPosition -=
info.spacing;
2661 rect.setBottom(segPosition + deltaSegPosition);
2663 rect.setRight(segPosition + deltaSegPosition);
2675 QRect changedRect(topLeft,
rect.bottomRight());
2676 if (
clipRect().intersects(changedRect))
2688 int segStartPosition;
2690 int flowStartPosition;
2691 int flowEndPosition;
2693 segStartPosition = area.
top();
2694 segEndPosition = area.
bottom();
2695 flowStartPosition = area.
left();
2696 flowEndPosition = area.
right();
2698 segStartPosition = area.
left();
2699 segEndPosition = area.
right();
2700 flowStartPosition = area.
top();
2701 flowEndPosition = area.
bottom();
2707 int seg = qBinarySearch<int>(
segmentPositions, segStartPosition, 0, segLast + 1);
2718 if (
index.isValid()) {
2723 const int iw = viewItem.width();
2726 if (endPos >= viewItem.x && startPos < viewItem.x + iw)
2732 qWarning(
"intersectingSet: row %d was invalid",
row);
2762 int QListModeViewBase::perItemScrollingPageSteps(
int length,
int bounds,
bool wrap)
const
2773 return positions.
count();
2775 for (
int i = 1;
i < positions.
count(); ++
i)
2776 if (positions.
at(
i) > 0)
2781 int steps = positions.
count() - 1;
2782 int max = qMax(
length, bounds);
2783 int min = qMin(
length, bounds);
2786 while (
pos >= 0 && steps > 0) {
2787 pos -= (positions.
at(steps) - positions.
at(steps - 1));
2794 return qMax(pageSteps, 1);
2797 int QListModeViewBase::perItemScrollToValue(
int index,
int scrollValue,
int viewportSize,
2806 std::sort(hiddenRows.
begin(), hiddenRows.
end());
2807 int hiddenRowsBefore = 0;
2808 for (
int i = 0;
i < hiddenRows.
size() - 1; ++
i)
2809 if (hiddenRows.
at(
i) >
index + hiddenRowsBefore)
2814 int topIndex =
index;
2815 const int bottomIndex = topIndex;
2817 while (topIndex > 0 &&
2821 while (hiddenRowsBefore > 0 && hiddenRows.
at(hiddenRowsBefore - 1) >= topIndex + hiddenRowsBefore - 1)
2825 const int itemCount = bottomIndex - topIndex + 1;
2830 return index - itemCount + 1;
2832 return index - (itemCount / 2);
2839 if (flowOrientation == orientation) {
2845 const int rightSegment = leftSegment;
2848 while (leftSegment > scrollValue &&
2853 const int segmentCount = rightSegment - leftSegment + 1;
2858 return segment - segmentCount + 1;
2860 return segment - (segmentCount / 2);
2911 #if QT_CONFIG(draganddrop)
2912 bool QIconModeViewBase::filterStartDrag(Qt::DropActions supportedActions)
2918 if (indexes.
count() > 0 ) {
2934 dd->dropEventMoved =
false;
2939 if (
dd->dragDropMode != QAbstractItemView::InternalMove || drag->
target() ==
qq->viewport())
2942 dd->dropEventMoved =
false;
2947 bool QIconModeViewBase::filterDropEvent(QDropEvent *
e)
2949 if (
e->source() !=
qq)
2955 if (
qq->acceptDrops()) {
2959 if ((
index.flags() & dropableFlags) == dropableFlags)
2965 for (
const auto &
index : indexes) {
2969 if (
qq->isRightToLeft())
2971 moveItem(
index.row(), dest);
2978 dd->dropEventMoved =
true;
2984 updateContentsSize();
2991 bool QIconModeViewBase::filterDragLeaveEvent(QDragLeaveEvent *
e)
2995 return QCommonListViewBase::filterDragLeaveEvent(
e);
2998 bool QIconModeViewBase::filterDragMoveEvent(QDragMoveEvent *
e)
3000 const bool wasAccepted =
e->isAccepted();
3005 if (
e->source() !=
qq || !
dd->canDrop(
e)) {
3007 e->setAccepted(wasAccepted);
3032 else if (!
index.isValid())
3049 if (scrollElasticBand)
3060 QStyleOptionViewItem
option;
3081 QStyleOptionViewItem
option;
3088 doDynamicLayout(
info);
3104 for (
int l = 0;
l < leafCount; ++
l)
3120 if (
info.first == 0) {
3144 const bool useItemSize = !
info.grid.isValid();
3145 const QPoint topLeft = initDynamicLayout(
info);
3147 int segStartPosition;
3149 int deltaFlowPosition;
3150 int deltaSegPosition;
3156 segStartPosition =
info.bounds.left() +
info.spacing;
3157 segEndPosition =
info.bounds.right();
3158 deltaFlowPosition =
info.grid.width();
3160 deltaSegHint =
info.grid.height();
3161 flowPosition = topLeft.
x();
3162 segPosition = topLeft.
y();
3164 segStartPosition =
info.bounds.top() +
info.spacing;
3165 segEndPosition =
info.bounds.bottom();
3166 deltaFlowPosition =
info.grid.height();
3168 deltaSegHint =
info.grid.width();
3169 flowPosition = topLeft.
y();
3170 segPosition = topLeft.
x();
3187 deltaFlowPosition =
item->w +
info.spacing;
3189 deltaFlowPosition =
item->h +
info.spacing;
3197 && flowPosition + deltaFlowPosition > segEndPosition
3198 && flowPosition > segStartPosition) {
3199 flowPosition = segStartPosition;
3200 segPosition += deltaSegPosition;
3202 deltaSegPosition = 0;
3208 deltaSegHint =
item->h +
info.spacing;
3210 deltaSegHint =
item->w +
info.spacing;
3211 deltaSegPosition = qMax(deltaSegPosition, deltaSegHint);
3220 item->
x = flowPosition;
3221 item->
y = segPosition;
3223 item->
x = flowPosition + ((deltaFlowPosition -
item->w) / 2);
3224 item->
y = segPosition;
3228 item->
y = flowPosition;
3229 item->
x = segPosition;
3231 item->
y = flowPosition + ((deltaFlowPosition -
item->h) / 2);
3232 item->
x = segPosition;
3241 rect |=
QRect(flowPosition, segPosition, deltaFlowPosition, deltaSegPosition);
3243 rect |=
QRect(segPosition, flowPosition, deltaSegPosition, deltaFlowPosition);
3246 flowPosition += deltaFlowPosition;
3261 if (
rect.size().isEmpty())
3264 int insertFrom =
info.first;
3266 initBspTree(
rect.size());
3273 QRect changedRect(topLeft,
rect.bottomRight());
3274 if (
clipRect().intersects(changedRect))
3292 for (
const auto &
index : indexes)
3299 if (!
item.isValid())
3301 int i =
item.indexHint;
3338 for (
int i = 0;
i < leaf.
count(); ++
i) {
3348 vi->visited = visited;
3353 void QIconModeViewBase::moveItem(
int index,
const QPoint &dest)
3380 QPoint QIconModeViewBase::draggedItemsDelta()
const
3390 QRect QIconModeViewBase::draggedItemsRect()
const
3393 rect.translate(draggedItemsDelta());
3418 void QIconModeViewBase::updateContentsSize()
3431 #ifndef QT_NO_ACCESSIBILITY
3434 int entry = visualIndex(current);
3436 event.setChild(
entry);
3450 #ifndef QT_NO_ACCESSIBILITY
3455 int entry = visualIndex(sel);
3457 event.setChild(
entry);
3462 int entry = visualIndex(desel);
3464 event.setChild(
entry);
3475 d->executePostedLayout();
3477 int visualIndex =
d->commonListView->itemIndex(itm);
3478 for (
const auto &
idx : qAsConst(
d->hiddenRows)) {
3496 const int rc =
d->model->rowCount();
3500 QStyleOptionViewItem
option;
3504 QSize sz =
d->cachedItemSize;
3516 int maximumRows = 1000;
3518 if (userOverrideValue.
isValid() && userOverrideValue.
toInt() > 0) {
3519 maximumRows = userOverrideValue.
toInt();
3521 const int rowCount = qMin(rc, maximumRows);
3530 w = qMax(
w, itemSize.
width());
3537 #include "moc_qlistview.cpp"
small capitals from c petite p scientific i
[1]
The QAbstractItemDelegate class is used to display and edit data items from a model.
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const =0
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const =0
The QAbstractItemModel class provides the abstract interface for item model classes.
virtual Qt::DropActions supportedDropActions() const
virtual Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
bool moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild)
virtual Q_INVOKABLE int columnCount(const QModelIndex &parent=QModelIndex()) const =0
virtual Q_INVOKABLE QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
The QAbstractItemView class provides the basic functionality for item view classes.
friend class QListModeViewBase
QAbstractItemModel * model() const
bool event(QEvent *event) override
void timerEvent(QTimerEvent *event) override
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void mouseReleaseEvent(QMouseEvent *event) override
virtual QAbstractItemDelegate * itemDelegateForIndex(const QModelIndex &index) const
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
QModelIndex currentIndex() const
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
virtual void setRootIndex(const QModelIndex &index)
virtual void initViewItemOption(QStyleOptionViewItem *option) const
virtual void doItemsLayout()
void update(const QModelIndex &index)
QModelIndex rootIndex() const
virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
void resizeEvent(QResizeEvent *event) override
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
void setState(State state)
void mouseMoveEvent(QMouseEvent *event) override
void setSelectionMode(QAbstractItemView::SelectionMode mode)
virtual void updateGeometries()
QSize viewportSizeHint() const override
void doDelayedItemsLayout(int delay=0)
void scrollContentsBy(int dx, int dy)
QPointer< QItemSelectionModel > selectionModel
bool shouldAutoScroll(const QPoint &pos) const
QPersistentModelIndex root
bool droppingOnItself(QDropEvent *event, const QModelIndex &index)
QPixmap renderToPixmap(const QModelIndexList &indexes, QRect *r) const
QAbstractItemModel * model
bool isIndexDropEnabled(const QModelIndex &index) const
QPersistentModelIndex hover
bool isIndexEnabled(const QModelIndex &index) const
int value
the slider's current value
void setRange(int min, int max)
The QAccessibleEvent class is the base class for accessibility notifications.
static void updateAccessibility(QAccessibleEvent *event)
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
bool testBit(qsizetype i) const
void resize(qsizetype size)
QList< int > & leaf(int i)
void insertLeaf(const QRect &r, int i)
void create(int n, int d=-1)
void climbTree(const QRect &rect, callback *function, QBspTreeData data)
void init(const QRect &area, NodeType type)
void removeLeaf(const QRect &r, int i)
virtual int horizontalScrollToValue(int index, QListView::ScrollHint hint, bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const
QListView::Movement movement() const
QRect viewItemRect(const QListViewItem &item) const
QListView::ScrollMode horizontalScrollMode() const
QListView::ScrollMode verticalScrollMode() const
virtual void updateHorizontalScrollBar(const QSize &step)
virtual int horizontalOffset() const
QWidget * viewport() const
void initViewItemOption(QStyleOptionViewItem *option) const
virtual bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max)=0
virtual void appendHiddenRow(int row)
virtual void updateVerticalScrollBar(const QSize &step)
virtual QListViewItem indexToListViewItem(const QModelIndex &index) const =0
virtual void removeHiddenRow(int row)
bool uniformItemSizes() const
QSize cachedItemSize() const
virtual void scrollContentsBy(int dx, int dy, bool scrollElasticBand)
virtual int verticalOffset() const
bool isHidden(int row) const
QScrollBar * verticalScrollBar() const
QSize itemSize(const QStyleOptionViewItem &opt, const QModelIndex &idx) const
QListView::Flow flow() const
virtual void setRowCount(int)=0
virtual QRect mapToViewport(const QRect &rect) const
QScrollBar * horizontalScrollBar() const
bool isRightToLeft() const
QModelIndex modelIndex(int row) const
virtual int verticalScrollToValue(int index, QListView::ScrollHint hint, bool above, bool below, const QRect &area, const QRect &rect) const
QPoint pressedPosition() const
static bool sendEvent(QObject *receiver, QEvent *event)
The QDrag class provides support for MIME-based drag and drop data transfer.
void setHotSpot(const QPoint &hotspot)
Qt::DropAction exec(Qt::DropActions supportedActions=Qt::MoveAction)
void setMimeData(QMimeData *data)
void setPixmap(const QPixmap &)
The QEvent class is the base class of all event classes. Event objects contain event parameters.
QList< QListViewItem > items
int itemIndex(const QListViewItem &item) const override
QList< QModelIndex > draggedItems
QListViewItem indexToListViewItem(const QModelIndex &index) const override
void setPositionForIndex(const QPoint &position, const QModelIndex &index) override
void setRowCount(int rowCount) override
void scrollContentsBy(int dx, int dy, bool scrollElasticBand) override
QList< QModelIndex > intersectingSet(const QRect &area) const override
void appendHiddenRow(int row) override
QList< QModelIndex > * interSectingVector
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) override
void removeHiddenRow(int row) override
bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max) override
The QItemSelection class manages information about selected items in a model.
Q_CORE_EXPORT QModelIndexList indexes() const
Q_CORE_EXPORT void select(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Q_CORE_EXPORT void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
Q_INVOKABLE bool isSelected(const QModelIndex &index) const
QModelIndexList selectedIndexes
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
The QItemSelectionRange class manages information about a range of selected items in a model.
qsizetype size() const noexcept
bool isEmpty() const noexcept
void push_back(parameter_type t)
const_reference at(qsizetype i) const noexcept
T value(qsizetype i) const
const_iterator constBegin() const noexcept
qsizetype removeIf(Predicate pred)
qsizetype count() const noexcept
void reserve(qsizetype size)
const T & constLast() const noexcept
void resize(qsizetype size)
const_iterator cend() const noexcept
void append(parameter_type t)
const_iterator constEnd() const noexcept
const_iterator cbegin() const noexcept
const_iterator ConstIterator
void updateHorizontalScrollBar(const QSize &step) override
bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max) override
QList< int > segmentExtents
QList< int > segmentPositions
QList< int > flowPositions
void updateVerticalScrollBar(const QSize &step) override
void scrollContentsBy(int dx, int dy, bool scrollElasticBand) override
QList< QModelIndex > intersectingSet(const QRect &area) const override
int horizontalOffset() const override
QRect mapToViewport(const QRect &rect) const override
int verticalOffset() const override
QListViewItem indexToListViewItem(const QModelIndex &index) const override
int verticalScrollToValue(int index, QListView::ScrollHint hint, bool above, bool below, const QRect &area, const QRect &rect) const override
int horizontalScrollToValue(int index, QListView::ScrollHint hint, bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const override
QListModeViewBase(QListView *q, QListViewPrivate *d)
static QSize viewportSize(const QAbstractItemView *v)
void dataChanged(const QModelIndex &, const QModelIndex &) override
QList< int > segmentStartRows
QList< int > scrollValueMap
The QListView class provides a list or icon view onto a model.
LayoutMode layoutMode
determines whether the layout of items should happen immediately or be delayed.
void resizeEvent(QResizeEvent *e) override
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >()) override
void setSpacing(int space)
bool isSelectionRectVisible() const
int spacing
the space around the items in the layout
bool isWrapping
whether the items layout should wrap.
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible) override
void initViewItemOption(QStyleOptionViewItem *option) const override
void setRowHidden(int row, bool hide)
void setLayoutMode(LayoutMode mode)
int batchSize
the number of items laid out in each batch if \l layoutMode is set to \l Batched
ViewMode viewMode
the view mode of the QListView.
void setWordWrap(bool on)
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override
int verticalOffset() const override
void timerEvent(QTimerEvent *e) override
bool uniformItemSizes
whether all items in the listview have the same size
bool wordWrap
the item text word-wrapping policy
QSize gridSize
the size of the layout grid
QSize contentsSize() const
void setViewMode(ViewMode mode)
QListView(QWidget *parent=nullptr)
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override
void setRootIndex(const QModelIndex &index) override
int modelColumn
the column in the model that is visible
QRegion visualRegionForSelection(const QItemSelection &selection) const override
void setGridSize(const QSize &size)
Movement movement
whether the items can be moved freely, are snapped to a grid, or cannot be moved at all.
QRect rectForIndex(const QModelIndex &index) const
bool event(QEvent *e) override
void setModelColumn(int column)
void setWrapping(bool enable)
bool isRowHidden(int row) const
QRect visualRect(const QModelIndex &index) const override
int horizontalOffset() const override
void setMovement(Movement movement)
void setBatchSize(int batchSize)
void setPositionForIndex(const QPoint &position, const QModelIndex &index)
Qt::Alignment itemAlignment
the alignment of each item in its cell
void clearPropertyFlags()
void setItemAlignment(Qt::Alignment alignment)
void mouseReleaseEvent(QMouseEvent *e) override
void setSelectionRectVisible(bool show)
void updateGeometries() override
void mouseMoveEvent(QMouseEvent *e) override
void setUniformItemSizes(bool enable)
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override
void setResizeMode(ResizeMode mode)
QModelIndexList selectedIndexes() const override
void scrollContentsBy(int dx, int dy) override
QSize viewportSizeHint() const override
bool isIndexHidden(const QModelIndex &index) const override
void resizeContents(int width, int height)
ResizeMode resizeMode
whether the items are laid out again when the view is resized.
QModelIndex indexAt(const QPoint &p) const override
void paintEvent(QPaintEvent *e) override
Flow flow
which direction the items layout should flow.
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override
void rowsInserted(const QModelIndex &parent, int start, int end) override
void doItemsLayout() override
constexpr bool isValid() const
QListView::ViewMode viewMode
QSet< QPersistentModelIndex > hiddenRows
int horizontalScrollToValue(const QModelIndex &index, const QRect &rect, QListView::ScrollHint hint) const
QListView::Movement movement
QModelIndex closestIndex(const QRect &target, const QList< QModelIndex > &candidates) const
int batchStartRow() const
QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const override
int verticalScrollToValue(const QModelIndex &index, const QRect &rect, QListView::ScrollHint hint) const
void scrollElasticBandBy(int dx, int dy)
Qt::Alignment itemAlignment
QRect rectForIndex(const QModelIndex &index) const
QSize itemSize(const QStyleOptionViewItem &option, const QModelIndex &index) const
void selectAll(QItemSelectionModel::SelectionFlags command) override
bool doItemsLayout(int num)
QListViewItem indexToListViewItem(const QModelIndex &index) const
QModelIndex listViewItemToIndex(const QListViewItem &item) const
QList< QModelIndex > intersectingSet(const QRect &area, bool doLayout=true) const
QItemSelection selection(const QRect &rect) const
QCommonListViewBase * commonListView
void prepareItemsLayout()
void emitIndexesMoved(const QModelIndexList &indexes)
QRect mapToViewport(const QRect &rect, bool extend=true) const
void viewUpdateGeometries()
bool isHidden(int row) const
void removeCurrentAndDisabled(QList< QModelIndex > *indexes, const QModelIndex ¤t) const
QList< int > hiddenRowIds() const
The QModelIndex class is used to locate data in a data model.
constexpr int row() const noexcept
constexpr int column() const noexcept
constexpr bool isValid() const noexcept
The QMouseEvent class contains parameters that describe a mouse event.
The QObject class is the base class of all Qt objects.
The QPaintEvent class contains event parameters for paint events. \inmodule QtGui.
The QPainter class performs low-level painting on widgets and other paint devices.
The QPersistentModelIndex class is used to locate data in a data model.
The QPixmap class is an off-screen image representation that can be used as a paint device.
The QPoint class defines a point in the plane using integer precision.
constexpr int x() const noexcept
constexpr int y() const noexcept
constexpr void setX(int x) noexcept
The QRect class defines a rectangle in the plane using integer precision.
bool intersects(const QRect &r) const noexcept
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
constexpr void moveBottom(int pos) noexcept
constexpr void moveRight(int pos) noexcept
constexpr int height() const noexcept
constexpr int bottom() const noexcept
constexpr void setRight(int pos) noexcept
constexpr int top() const noexcept
constexpr void moveLeft(int pos) noexcept
constexpr void setBottom(int pos) noexcept
bool contains(const QRect &r, bool proper=false) const noexcept
constexpr void setLeft(int pos) noexcept
constexpr int left() const noexcept
constexpr int x() const noexcept
constexpr QSize size() const noexcept
constexpr int width() const noexcept
constexpr QRect translated(int dx, int dy) const noexcept
constexpr int y() const noexcept
constexpr void moveTop(int pos) noexcept
constexpr QPoint center() const noexcept
constexpr int right() const noexcept
constexpr void setTop(int pos) noexcept
The QRegion class specifies a clip region for a painter.
The QResizeEvent class contains event parameters for resize events. \inmodule QtGui.
bool remove(const T &value)
iterator insert(const T &value)
The QSize class defines the size of a two-dimensional object using integer point precision.
constexpr int height() const noexcept
constexpr int width() const noexcept
constexpr int & rheight() noexcept
constexpr void setWidth(int w) noexcept
constexpr int & rwidth() noexcept
constexpr bool isNull() const noexcept
constexpr void setHeight(int h) noexcept
constexpr bool isValid() const noexcept
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
@ SH_ScrollView_FrameOnlyAroundContents
@ PM_ScrollView_ScrollBarOverlap
The QStyleOption class stores the parameters used by QStyle functions.
void initFrom(const QWidget *w)
The QTimerEvent class contains parameters that describe a timer event.
The QVariant class acts like a union for the most common Qt data types.
int toInt(bool *ok=nullptr) const
union Alignment_ Alignment
backing_store_ptr info
[4]
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isRightToLeft(QStringView string) noexcept
QList< QModelIndex > QModelIndexList
EGLOutputLayerEXT EGLint EGLAttrib value
QT_BEGIN_NAMESPACE bool done
QT_BEGIN_NAMESPACE bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
GLenum GLuint GLenum GLsizei length
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLsizei GLsizei GLfloat distance
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLfloat GLfloat GLfloat GLfloat h
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
dialog setViewMode(QFileDialog::Detail)
[3]
view viewport() -> scroll(dx, dy, deviceRect)
QItemSelection * selection
[0]
app setAttribute(Qt::AA_DontShowIconsInMenus)
bool contains(const AT &t) const noexcept
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent