Qt 4.8
qlistview.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qlistview.h"
43 
44 #ifndef QT_NO_LISTVIEW
45 #include <qabstractitemdelegate.h>
46 #include <qapplication.h>
47 #include <qpainter.h>
48 #include <qbitmap.h>
49 #include <qvector.h>
50 #include <qstyle.h>
51 #include <qevent.h>
52 #include <qscrollbar.h>
53 #include <qrubberband.h>
54 #include <private/qlistview_p.h>
55 #include <qdebug.h>
56 #ifndef QT_NO_ACCESSIBILITY
57 #include <qaccessible.h>
58 #endif
59 
61 
186  : QAbstractItemView(*new QListViewPrivate, parent)
187 {
191  Q_D(QListView); // We rely on a qobject_cast for PM_DefaultFrameWidth to change
192  d->updateStyledFrameWidths(); // hence we have to force an update now that the object has been constructed
193 }
194 
199  : QAbstractItemView(dd, parent)
200 {
204  Q_D(QListView); // We rely on a qobject_cast for PM_DefaultFrameWidth to change
205  d->updateStyledFrameWidths(); // hence we have to force an update now that the object has been constructed
206 }
207 
212 {
213 }
214 
237 {
238  Q_D(QListView);
239  d->modeProperties |= uint(QListViewPrivate::Movement);
240  d->movement = movement;
241 
242 #ifndef QT_NO_DRAGANDDROP
243  bool movable = (movement != Static);
244  setDragEnabled(movable);
245  d->viewport->setAcceptDrops(movable);
246 #endif
247  d->doDelayedItemsLayout();
248 }
249 
251 {
252  Q_D(const QListView);
253  return d->movement;
254 }
255 
277 {
278  Q_D(QListView);
279  d->modeProperties |= uint(QListViewPrivate::Flow);
280  d->flow = flow;
281  d->doDelayedItemsLayout();
282 }
283 
285 {
286  Q_D(const QListView);
287  return d->flow;
288 }
289 
308 void QListView::setWrapping(bool enable)
309 {
310  Q_D(QListView);
311  d->modeProperties |= uint(QListViewPrivate::Wrap);
312  d->setWrapping(enable);
313  d->doDelayedItemsLayout();
314 }
315 
316 bool QListView::isWrapping() const
317 {
318  Q_D(const QListView);
319  return d->isWrapping();
320 }
321 
338 {
339  Q_D(QListView);
340  d->modeProperties |= uint(QListViewPrivate::ResizeMode);
341  d->resizeMode = mode;
342 }
343 
345 {
346  Q_D(const QListView);
347  return d->resizeMode;
348 }
349 
367 {
368  Q_D(QListView);
369  d->layoutMode = mode;
370 }
371 
373 {
374  Q_D(const QListView);
375  return d->layoutMode;
376 }
377 
395 // ### Qt5: Use same semantic as layouts (spacing is the size of space
396 // *between* items)
397 void QListView::setSpacing(int space)
398 {
399  Q_D(QListView);
400  d->modeProperties |= uint(QListViewPrivate::Spacing);
401  d->setSpacing(space);
402  d->doDelayedItemsLayout();
403 }
404 
405 int QListView::spacing() const
406 {
407  Q_D(const QListView);
408  return d->spacing();
409 }
410 
425 {
426  Q_D(QListView);
427  if (batchSize <= 0) {
428  qWarning("Invalid batchSize (%d)", batchSize);
429  return;
430  }
431  d->batchSize = batchSize;
432 }
433 
434 int QListView::batchSize() const
435 {
436  Q_D(const QListView);
437  return d->batchSize;
438 }
439 
459 {
460  Q_D(QListView);
461  d->modeProperties |= uint(QListViewPrivate::GridSize);
462  d->setGridSize(size);
463  d->doDelayedItemsLayout();
464 }
465 
467 {
468  Q_D(const QListView);
469  return d->gridSize();
470 }
471 
491 {
492  Q_D(QListView);
493  if (d->commonListView && d->viewMode == mode)
494  return;
495  d->viewMode = mode;
496 
497  delete d->commonListView;
498  if (mode == ListMode) {
499  d->commonListView = new QListModeViewBase(this, d);
500  if (!(d->modeProperties & QListViewPrivate::Wrap))
501  d->setWrapping(false);
502  if (!(d->modeProperties & QListViewPrivate::Spacing))
503  d->setSpacing(0);
504  if (!(d->modeProperties & QListViewPrivate::GridSize))
505  d->setGridSize(QSize());
506  if (!(d->modeProperties & QListViewPrivate::Flow))
507  d->flow = TopToBottom;
508  if (!(d->modeProperties & QListViewPrivate::Movement))
509  d->movement = Static;
510  if (!(d->modeProperties & QListViewPrivate::ResizeMode))
511  d->resizeMode = Fixed;
512  if (!(d->modeProperties & QListViewPrivate::SelectionRectVisible))
513  d->showElasticBand = false;
514  } else {
515  d->commonListView = new QIconModeViewBase(this, d);
516  if (!(d->modeProperties & QListViewPrivate::Wrap))
517  d->setWrapping(true);
518  if (!(d->modeProperties & QListViewPrivate::Spacing))
519  d->setSpacing(0);
520  if (!(d->modeProperties & QListViewPrivate::GridSize))
521  d->setGridSize(QSize());
522  if (!(d->modeProperties & QListViewPrivate::Flow))
523  d->flow = LeftToRight;
524  if (!(d->modeProperties & QListViewPrivate::Movement))
525  d->movement = Free;
526  if (!(d->modeProperties & QListViewPrivate::ResizeMode))
527  d->resizeMode = Fixed;
528  if (!(d->modeProperties & QListViewPrivate::SelectionRectVisible))
529  d->showElasticBand = true;
530  }
531 
532 #ifndef QT_NO_DRAGANDDROP
533  bool movable = (d->movement != Static);
534  setDragEnabled(movable);
535  setAcceptDrops(movable);
536 #endif
537  d->clear();
538  d->doDelayedItemsLayout();
539 }
540 
542 {
543  Q_D(const QListView);
544  return d->viewMode;
545 }
546 
555 {
556  Q_D(QListView);
557  d->modeProperties = 0;
558 }
559 
563 bool QListView::isRowHidden(int row) const
564 {
565  Q_D(const QListView);
566  return d->isHidden(row);
567 }
568 
573 void QListView::setRowHidden(int row, bool hide)
574 {
575  Q_D(QListView);
576  const bool hidden = d->isHidden(row);
577  if (hide && !hidden)
578  d->commonListView->appendHiddenRow(row);
579  else if (!hide && hidden)
580  d->commonListView->removeHiddenRow(row);
581  d->doDelayedItemsLayout();
582  d->viewport->update();
583 }
584 
589 {
590  Q_D(const QListView);
591  return d->mapToViewport(rectForIndex(index));
592 }
593 
598 {
599  Q_D(QListView);
600 
601  if (index.parent() != d->root || index.column() != d->column)
602  return;
603 
604  const QRect rect = visualRect(index);
605  if (hint == EnsureVisible && d->viewport->rect().contains(rect)) {
606  d->viewport->update(rect);
607  return;
608  }
609 
610  if (d->flow == QListView::TopToBottom || d->isWrapping()) // vertical
611  verticalScrollBar()->setValue(d->verticalScrollToValue(index, rect, hint));
612 
613  if (d->flow == QListView::LeftToRight || d->isWrapping()) // horizontal
614  horizontalScrollBar()->setValue(d->horizontalScrollToValue(index, rect, hint));
615 }
616 
618  QListView::ScrollHint hint) const
619 {
620  Q_Q(const QListView);
621  const QRect area = viewport->rect();
622  const bool leftOf = q->isRightToLeft()
623  ? (rect.left() < area.left()) && (rect.right() < area.right())
624  : rect.left() < area.left();
625  const bool rightOf = q->isRightToLeft()
626  ? rect.right() > area.right()
627  : (rect.right() > area.right()) && (rect.left() > area.left());
628  return commonListView->horizontalScrollToValue(q->visualIndex(index), hint, leftOf, rightOf, area, rect);
629 }
630 
632  QListView::ScrollHint hint) const
633 {
634  Q_Q(const QListView);
635  const QRect area = viewport->rect();
636  const bool above = (hint == QListView::EnsureVisible && rect.top() < area.top());
637  const bool below = (hint == QListView::EnsureVisible && rect.bottom() > area.bottom());
638  return commonListView->verticalScrollToValue(q->visualIndex(index), hint, above, below, area, rect);
639 }
640 
641 void QListViewPrivate::selectAll(QItemSelectionModel::SelectionFlags command)
642 {
643  if (!selectionModel)
644  return;
645 
646  QItemSelection selection;
647  QModelIndex topLeft;
648  int row = 0;
649  const int colCount = model->columnCount(root);
650  for(; row < model->rowCount(root); ++row) {
651  if (isHidden(row)) {
652  //it might be the end of a selection range
653  if (topLeft.isValid()) {
654  QModelIndex bottomRight = model->index(row - 1, colCount - 1, root);
655  selection.append(QItemSelectionRange(topLeft, bottomRight));
656  topLeft = QModelIndex();
657  }
658  continue;
659  }
660 
661  if (!topLeft.isValid()) //start of a new selection range
662  topLeft = model->index(row, 0, root);
663  }
664 
665  if (topLeft.isValid()) {
666  //last selected range
667  QModelIndex bottomRight = model->index(row - 1, colCount - 1, root);
668  selection.append(QItemSelectionRange(topLeft, bottomRight));
669  }
670 
671  if (!selection.isEmpty())
672  selectionModel->select(selection, command);
673 }
674 
682 {
683  Q_ASSERT(r);
684  Q_Q(const QListView);
685  QRect &rect = *r;
686  const QRect viewportRect = viewport->rect();
688  const QSet<QModelIndex> visibleIndexes = intersectingSet(viewportRect).toList().toSet();
689  for (int i = 0; i < indexes.count(); ++i) {
690  const QModelIndex &index = indexes.at(i);
691  if (visibleIndexes.contains(index)) {
692  const QRect current = q->visualRect(index);
693  ret += qMakePair(current, index);
694  rect |= current;
695  }
696  }
697  rect &= viewportRect;
698  return ret;
699 }
700 
705 {
706  Q_D(QListView);
707  d->clear();
708  d->hiddenRows.clear();
710 }
711 
716 {
717  Q_D(QListView);
718  d->column = qBound(0, d->column, d->model->columnCount(index) - 1);
720  // sometimes we get an update before reset() is called
721  d->clear();
722  d->hiddenRows.clear();
723 }
724 
734 void QListView::scrollContentsBy(int dx, int dy)
735 {
736  Q_D(QListView);
737  d->delayedAutoScroll.stop(); // auto scroll was canceled by the user scrolling
738  d->commonListView->scrollContentsBy(dx, dy, d->state == QListView::DragSelectingState);
739 }
740 
751 {
752  Q_D(QListView);
753  d->setContentsSize(width, height);
754 }
755 
760 {
761  Q_D(const QListView);
762  return d->contentsSize();
763 }
764 
768 void QListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
769 {
770  d_func()->commonListView->dataChanged(topLeft, bottomRight);
771  QAbstractItemView::dataChanged(topLeft, bottomRight);
772 }
773 
777 void QListView::rowsInserted(const QModelIndex &parent, int start, int end)
778 {
779  Q_D(QListView);
780  // ### be smarter about inserted items
781  d->clear();
782  d->doDelayedItemsLayout();
783  QAbstractItemView::rowsInserted(parent, start, end);
784 }
785 
790 {
791  Q_D(QListView);
792  // if the parent is above d->root in the tree, nothing will happen
793  QAbstractItemView::rowsAboutToBeRemoved(parent, start, end);
794  if (parent == d->root) {
795  QSet<QPersistentModelIndex>::iterator it = d->hiddenRows.begin();
796  while (it != d->hiddenRows.end()) {
797  int hiddenRow = it->row();
798  if (hiddenRow >= start && hiddenRow <= end) {
799  it = d->hiddenRows.erase(it);
800  } else {
801  ++it;
802  }
803  }
804  }
805  d->clear();
806  d->doDelayedItemsLayout();
807 }
808 
813 {
814  if (!isVisible())
815  return;
816  Q_D(QListView);
818  if (state() == DragSelectingState
819  && d->showElasticBand
820  && d->selectionMode != SingleSelection
821  && d->selectionMode != NoSelection) {
822  QRect rect(d->pressedPosition, e->pos() + QPoint(horizontalOffset(), verticalOffset()));
823  rect = rect.normalized();
824  d->viewport->update(d->mapToViewport(rect.united(d->elasticBand)));
825  d->elasticBand = rect;
826  }
827 }
828 
833 {
834  Q_D(QListView);
836  // #### move this implementation into a dynamic class
837  if (d->showElasticBand && d->elasticBand.isValid()) {
838  d->viewport->update(d->mapToViewport(d->elasticBand));
839  d->elasticBand = QRect();
840  }
841 }
842 
847 {
848  Q_D(QListView);
849  if (e->timerId() == d->batchLayoutTimer.timerId()) {
850  if (d->doItemsLayout(d->batchSize)) { // layout is done
851  d->batchLayoutTimer.stop();
853  d->viewport->update();
854  }
855  }
857 }
858 
863 {
864  Q_D(QListView);
865  if (d->delayedPendingLayout)
866  return;
867 
868  QSize delta = e->size() - e->oldSize();
869 
870  if (delta.isNull())
871  return;
872 
873  bool listWrap = (d->viewMode == ListMode) && d->wrapItemText;
874  bool flowDimensionChanged = (d->flow == LeftToRight && delta.width() != 0)
875  || (d->flow == TopToBottom && delta.height() != 0);
876 
877  // We post a delayed relayout in the following cases :
878  // - we're wrapping
879  // - the state is NoState, we're adjusting and the size has changed in the flowing direction
880  if (listWrap
881  || (state() == NoState && d->resizeMode == Adjust && flowDimensionChanged)) {
882  d->doDelayedItemsLayout(100); // wait 1/10 sec before starting the layout
883  } else {
885  }
886 }
887 
888 #ifndef QT_NO_DRAGANDDROP
889 
894 {
895  Q_D(QListView);
896  if (!d->commonListView->filterDragMoveEvent(e)) {
898  static_cast<QListModeViewBase *>(d->commonListView)->dragMoveEvent(e);
899  else
901  }
902 }
903 
904 
909 {
910  if (!d_func()->commonListView->filterDragLeaveEvent(e))
912 }
913 
918 {
919  if (!d_func()->commonListView->filterDropEvent(e))
921 }
922 
926 void QListView::startDrag(Qt::DropActions supportedActions)
927 {
928  if (!d_func()->commonListView->filterStartDrag(supportedActions))
929  QAbstractItemView::startDrag(supportedActions);
930 }
931 
942 {
943  // ### Qt5: remove that function
944  Q_UNUSED(event);
945 }
946 
956 void QListView::internalDrag(Qt::DropActions supportedActions)
957 {
958  // ### Qt5: remove that function
959  Q_UNUSED(supportedActions);
960 }
961 
962 #endif // QT_NO_DRAGANDDROP
963 
968 {
969  Q_D(const QListView);
971  if (!d->iconSize.isValid()) { // otherwise it was already set in abstractitemview
972  int pm = (d->viewMode == ListMode
975  option.decorationSize = QSize(pm, pm);
976  }
977  if (d->viewMode == IconMode) {
978  option.showDecorationSelected = false;
981  } else {
983  }
984 
985  if (d->gridSize().isValid()) {
986  option.rect.setSize(d->gridSize());
987  }
988 
989  return option;
990 }
991 
992 
997 {
998  Q_D(QListView);
999  if (!d->itemDelegate)
1000  return;
1001  QStyleOptionViewItemV4 option = d->viewOptionsV4();
1002  QPainter painter(d->viewport);
1003 
1004  const QVector<QModelIndex> toBeRendered = d->intersectingSet(e->rect().translated(horizontalOffset(), verticalOffset()), false);
1005 
1006  const QModelIndex current = currentIndex();
1007  const QModelIndex hover = d->hover;
1008  const QAbstractItemModel *itemModel = d->model;
1009  const QItemSelectionModel *selections = d->selectionModel;
1010  const bool focus = (hasFocus() || d->viewport->hasFocus()) && current.isValid();
1011  const bool alternate = d->alternatingColors;
1012  const QStyle::State state = option.state;
1013  const QAbstractItemView::State viewState = this->state();
1014  const bool enabled = (state & QStyle::State_Enabled) != 0;
1015 
1016  bool alternateBase = false;
1017  int previousRow = -2; // trigger the alternateBase adjustment on first pass
1018 
1019  int maxSize = (flow() == TopToBottom)
1020  ? qMax(viewport()->size().width(), d->contentsSize().width()) - 2 * d->spacing()
1021  : qMax(viewport()->size().height(), d->contentsSize().height()) - 2 * d->spacing();
1022 
1024  for (QVector<QModelIndex>::const_iterator it = toBeRendered.constBegin(); it != end; ++it) {
1025  Q_ASSERT((*it).isValid());
1026  option.rect = visualRect(*it);
1027 
1028  if (flow() == TopToBottom)
1029  option.rect.setWidth(qMin(maxSize, option.rect.width()));
1030  else
1031  option.rect.setHeight(qMin(maxSize, option.rect.height()));
1032 
1033  option.state = state;
1034  if (selections && selections->isSelected(*it))
1035  option.state |= QStyle::State_Selected;
1036  if (enabled) {
1038  if ((itemModel->flags(*it) & Qt::ItemIsEnabled) == 0) {
1039  option.state &= ~QStyle::State_Enabled;
1040  cg = QPalette::Disabled;
1041  } else {
1042  cg = QPalette::Normal;
1043  }
1044  option.palette.setCurrentColorGroup(cg);
1045  }
1046  if (focus && current == *it) {
1047  option.state |= QStyle::State_HasFocus;
1048  if (viewState == EditingState)
1049  option.state |= QStyle::State_Editing;
1050  }
1051  if (*it == hover)
1052  option.state |= QStyle::State_MouseOver;
1053  else
1054  option.state &= ~QStyle::State_MouseOver;
1055 
1056  if (alternate) {
1057  int row = (*it).row();
1058  if (row != previousRow + 1) {
1059  // adjust alternateBase according to rows in the "gap"
1060  if (!d->hiddenRows.isEmpty()) {
1061  for (int r = qMax(previousRow + 1, 0); r < row; ++r) {
1062  if (!d->isHidden(r))
1063  alternateBase = !alternateBase;
1064  }
1065  } else {
1066  alternateBase = (row & 1) != 0;
1067  }
1068  }
1069  if (alternateBase) {
1071  } else {
1072  option.features &= ~QStyleOptionViewItemV2::Alternate;
1073  }
1074 
1075  // draw background of the item (only alternate row). rest of the background
1076  // is provided by the delegate
1077  QStyle::State oldState = option.state;
1078  option.state &= ~QStyle::State_Selected;
1079  style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &option, &painter, this);
1080  option.state = oldState;
1081 
1082  alternateBase = !alternateBase;
1083  previousRow = row;
1084  }
1085 
1086  d->delegateForIndex(*it)->paint(&painter, option, *it);
1087  }
1088 
1089 #ifndef QT_NO_DRAGANDDROP
1090  d->commonListView->paintDragDrop(&painter);
1091 #endif
1092 
1093 #ifndef QT_NO_RUBBERBAND
1094  // #### move this implementation into a dynamic class
1095  if (d->showElasticBand && d->elasticBand.isValid()) {
1097  opt.initFrom(this);
1099  opt.opaque = false;
1100  opt.rect = d->mapToViewport(d->elasticBand, false).intersected(
1101  d->viewport->rect().adjusted(-16, -16, 16, 16));
1102  painter.save();
1103  style()->drawControl(QStyle::CE_RubberBand, &opt, &painter);
1104  painter.restore();
1105  }
1106 #endif
1107 }
1108 
1113 {
1114  Q_D(const QListView);
1115  QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1);
1116  const QVector<QModelIndex> intersectVector = d->intersectingSet(rect);
1117  QModelIndex index = intersectVector.count() > 0
1118  ? intersectVector.last() : QModelIndex();
1119  if (index.isValid() && visualRect(index).contains(p))
1120  return index;
1121  return QModelIndex();
1122 }
1123 
1128 {
1129  return d_func()->commonListView->horizontalOffset();
1130 }
1131 
1136 {
1137  return d_func()->commonListView->verticalOffset();
1138 }
1139 
1143 QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
1144 {
1145  Q_D(QListView);
1146  Q_UNUSED(modifiers);
1147 
1148  QModelIndex current = currentIndex();
1149  if (!current.isValid()) {
1150  int rowCount = d->model->rowCount(d->root);
1151  if (!rowCount)
1152  return QModelIndex();
1153  int row = 0;
1154  while (row < rowCount && d->isHiddenOrDisabled(row))
1155  ++row;
1156  if (row >= rowCount)
1157  return QModelIndex();
1158  return d->model->index(row, d->column, d->root);
1159  }
1160 
1161  const QRect initialRect = rectForIndex(current);
1162  QRect rect = initialRect;
1163  if (rect.isEmpty()) {
1164  return d->model->index(0, d->column, d->root);
1165  }
1166  if (d->gridSize().isValid()) rect.setSize(d->gridSize());
1167 
1168  QSize contents = d->contentsSize();
1169  QVector<QModelIndex> intersectVector;
1170 
1171  switch (cursorAction) {
1172  case MoveLeft:
1173  while (intersectVector.isEmpty()) {
1174  rect.translate(-rect.width(), 0);
1175  if (rect.right() <= 0)
1176  return current;
1177  if (rect.left() < 0)
1178  rect.setLeft(0);
1179  intersectVector = d->intersectingSet(rect);
1180  d->removeCurrentAndDisabled(&intersectVector, current);
1181  }
1182  return d->closestIndex(initialRect, intersectVector);
1183  case MoveRight:
1184  while (intersectVector.isEmpty()) {
1185  rect.translate(rect.width(), 0);
1186  if (rect.left() >= contents.width())
1187  return current;
1188  if (rect.right() > contents.width())
1189  rect.setRight(contents.width());
1190  intersectVector = d->intersectingSet(rect);
1191  d->removeCurrentAndDisabled(&intersectVector, current);
1192  }
1193  return d->closestIndex(initialRect, intersectVector);
1194  case MovePageUp:
1195  // move current by (visibileRowCount - 1) items.
1196  // rect.translate(0, -rect.height()); will happen in the switch fallthrough for MoveUp.
1197  rect.moveTop(rect.top() - d->viewport->height() + 2 * rect.height());
1198  if (rect.top() < rect.height())
1199  rect.moveTop(rect.height());
1200  case MovePrevious:
1201  case MoveUp:
1202  while (intersectVector.isEmpty()) {
1203  rect.translate(0, -rect.height());
1204  if (rect.bottom() <= 0) {
1205 #ifdef QT_KEYPAD_NAVIGATION
1206  if (QApplication::keypadNavigationEnabled()) {
1207  int row = d->batchStartRow() - 1;
1208  while (row >= 0 && d->isHiddenOrDisabled(row))
1209  --row;
1210  if (row >= 0)
1211  return d->model->index(row, d->column, d->root);
1212  }
1213 #endif
1214  return current;
1215  }
1216  if (rect.top() < 0)
1217  rect.setTop(0);
1218  intersectVector = d->intersectingSet(rect);
1219  d->removeCurrentAndDisabled(&intersectVector, current);
1220  }
1221  return d->closestIndex(initialRect, intersectVector);
1222  case MovePageDown:
1223  // move current by (visibileRowCount - 1) items.
1224  // rect.translate(0, rect.height()); will happen in the switch fallthrough for MoveDown.
1225  rect.moveTop(rect.top() + d->viewport->height() - 2 * rect.height());
1226  if (rect.bottom() > contents.height() - rect.height())
1227  rect.moveBottom(contents.height() - rect.height());
1228  case MoveNext:
1229  case MoveDown:
1230  while (intersectVector.isEmpty()) {
1231  rect.translate(0, rect.height());
1232  if (rect.top() >= contents.height()) {
1233 #ifdef QT_KEYPAD_NAVIGATION
1234  if (QApplication::keypadNavigationEnabled()) {
1235  int rowCount = d->model->rowCount(d->root);
1236  int row = 0;
1237  while (row < rowCount && d->isHiddenOrDisabled(row))
1238  ++row;
1239  if (row < rowCount)
1240  return d->model->index(row, d->column, d->root);
1241  }
1242 #endif
1243  return current;
1244  }
1245  if (rect.bottom() > contents.height())
1246  rect.setBottom(contents.height());
1247  intersectVector = d->intersectingSet(rect);
1248  d->removeCurrentAndDisabled(&intersectVector, current);
1249  }
1250  return d->closestIndex(initialRect, intersectVector);
1251  case MoveHome:
1252  return d->model->index(0, d->column, d->root);
1253  case MoveEnd:
1254  return d->model->index(d->batchStartRow() - 1, d->column, d->root);}
1255 
1256  return current;
1257 }
1258 
1266 {
1267  return d_func()->rectForIndex(index);
1268 }
1269 
1282 {
1283  Q_D(QListView);
1284  if (d->movement == Static
1285  || !d->isIndexValid(index)
1286  || index.parent() != d->root
1287  || index.column() != d->column)
1288  return;
1289 
1290  d->executePostedLayout();
1291  d->commonListView->setPositionForIndex(position, index);
1292 }
1293 
1297 void QListView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
1298 {
1299  Q_D(QListView);
1300  if (!d->selectionModel)
1301  return;
1302 
1303  // if we are wrapping, we can only selecte inside the contents rectangle
1304  int w = qMax(d->contentsSize().width(), d->viewport->width());
1305  int h = qMax(d->contentsSize().height(), d->viewport->height());
1306  if (d->wrap && !QRect(0, 0, w, h).intersects(rect))
1307  return;
1308 
1309  QItemSelection selection;
1310 
1311  if (rect.width() == 1 && rect.height() == 1) {
1312  const QVector<QModelIndex> intersectVector = d->intersectingSet(rect.translated(horizontalOffset(), verticalOffset()));
1313  QModelIndex tl;
1314  if (!intersectVector.isEmpty())
1315  tl = intersectVector.last(); // special case for mouse press; only select the top item
1316  if (tl.isValid() && d->isIndexEnabled(tl))
1317  selection.select(tl, tl);
1318  } else {
1319  if (state() == DragSelectingState) { // visual selection mode (rubberband selection)
1320  selection = d->selection(rect.translated(horizontalOffset(), verticalOffset()));
1321  } else { // logical selection mode (key and mouse click selection)
1322  QModelIndex tl, br;
1323  // get the first item
1324  const QRect topLeft(rect.left() + horizontalOffset(), rect.top() + verticalOffset(), 1, 1);
1325  QVector<QModelIndex> intersectVector = d->intersectingSet(topLeft);
1326  if (!intersectVector.isEmpty())
1327  tl = intersectVector.last();
1328  // get the last item
1329  const QRect bottomRight(rect.right() + horizontalOffset(), rect.bottom() + verticalOffset(), 1, 1);
1330  intersectVector = d->intersectingSet(bottomRight);
1331  if (!intersectVector.isEmpty())
1332  br = intersectVector.last();
1333 
1334  // get the ranges
1335  if (tl.isValid() && br.isValid()
1336  && d->isIndexEnabled(tl)
1337  && d->isIndexEnabled(br)) {
1338  QRect first = rectForIndex(tl);
1339  QRect last = rectForIndex(br);
1340  QRect middle;
1341  if (d->flow == LeftToRight) {
1342  QRect &top = first;
1343  QRect &bottom = last;
1344  // if bottom is above top, swap them
1345  if (top.center().y() > bottom.center().y()) {
1346  QRect tmp = top;
1347  top = bottom;
1348  bottom = tmp;
1349  }
1350  // if the rect are on differnet lines, expand
1351  if (top.top() != bottom.top()) {
1352  // top rectangle
1353  if (isRightToLeft())
1354  top.setLeft(0);
1355  else
1356  top.setRight(contentsSize().width());
1357  // bottom rectangle
1358  if (isRightToLeft())
1359  bottom.setRight(contentsSize().width());
1360  else
1361  bottom.setLeft(0);
1362  } else if (top.left() > bottom.right()) {
1363  if (isRightToLeft())
1364  bottom.setLeft(top.right());
1365  else
1366  bottom.setRight(top.left());
1367  } else {
1368  if (isRightToLeft())
1369  top.setLeft(bottom.right());
1370  else
1371  top.setRight(bottom.left());
1372  }
1373  // middle rectangle
1374  if (top.bottom() < bottom.top()) {
1375  if (gridSize().isValid() && !gridSize().isNull())
1376  middle.setTop(top.top() + gridSize().height());
1377  else
1378  middle.setTop(top.bottom() + 1);
1379  middle.setLeft(qMin(top.left(), bottom.left()));
1380  middle.setBottom(bottom.top() - 1);
1381  middle.setRight(qMax(top.right(), bottom.right()));
1382  }
1383  } else { // TopToBottom
1384  QRect &left = first;
1385  QRect &right = last;
1386  if (left.center().x() > right.center().x())
1387  qSwap(left, right);
1388 
1389  int ch = contentsSize().height();
1390  if (left.left() != right.left()) {
1391  // left rectangle
1392  if (isRightToLeft())
1393  left.setTop(0);
1394  else
1395  left.setBottom(ch);
1396 
1397  // top rectangle
1398  if (isRightToLeft())
1399  right.setBottom(ch);
1400  else
1401  right.setTop(0);
1402  // only set middle if the
1403  middle.setTop(0);
1404  middle.setBottom(ch);
1405  if (gridSize().isValid() && !gridSize().isNull())
1406  middle.setLeft(left.left() + gridSize().width());
1407  else
1408  middle.setLeft(left.right() + 1);
1409  middle.setRight(right.left() - 1);
1410  } else if (left.bottom() < right.top()) {
1411  left.setBottom(right.top() - 1);
1412  } else {
1413  right.setBottom(left.top() - 1);
1414  }
1415  }
1416 
1417  // do the selections
1418  QItemSelection topSelection = d->selection(first);
1419  QItemSelection middleSelection = d->selection(middle);
1420  QItemSelection bottomSelection = d->selection(last);
1421  // merge
1422  selection.merge(topSelection, QItemSelectionModel::Select);
1423  selection.merge(middleSelection, QItemSelectionModel::Select);
1424  selection.merge(bottomSelection, QItemSelectionModel::Select);
1425  }
1426  }
1427  }
1428 
1429  d->selectionModel->select(selection, command);
1430 }
1431 
1442 {
1443  Q_D(const QListView);
1444  // ### NOTE: this is a potential bottleneck in non-static mode
1445  int c = d->column;
1446  QRegion selectionRegion;
1447  const QRect &viewportRect = d->viewport->rect();
1448  for (int i = 0; i < selection.count(); ++i) {
1449  if (!selection.at(i).isValid())
1450  continue;
1451  QModelIndex parent = selection.at(i).topLeft().parent();
1452  //we only display the children of the root in a listview
1453  //we're not interested in the other model indexes
1454  if (parent != d->root)
1455  continue;
1456  int t = selection.at(i).topLeft().row();
1457  int b = selection.at(i).bottomRight().row();
1458  if (d->viewMode == IconMode || d->isWrapping()) { // in non-static mode, we have to go through all selected items
1459  for (int r = t; r <= b; ++r) {
1460  const QRect &rect = visualRect(d->model->index(r, c, parent));
1461  if (viewportRect.intersects(rect))
1462  selectionRegion += rect;
1463  }
1464  } else { // in static mode, we can optimize a bit
1465  while (t <= b && d->isHidden(t)) ++t;
1466  while (b >= t && d->isHidden(b)) --b;
1467  const QModelIndex top = d->model->index(t, c, parent);
1468  const QModelIndex bottom = d->model->index(b, c, parent);
1469  QRect rect(visualRect(top).topLeft(),
1470  visualRect(bottom).bottomRight());
1471  if (viewportRect.intersects(rect))
1472  selectionRegion += rect;
1473  }
1474  }
1475 
1476  return selectionRegion;
1477 }
1478 
1483 {
1484  Q_D(const QListView);
1485  if (!d->selectionModel)
1486  return QModelIndexList();
1487 
1488  QModelIndexList viewSelected = d->selectionModel->selectedIndexes();
1489  for (int i = 0; i < viewSelected.count(); ++i) {
1490  const QModelIndex &index = viewSelected.at(i);
1491  if (!isIndexHidden(index) && index.parent() == d->root && index.column() == d->column)
1492  ++i;
1493  else
1494  viewSelected.removeAt(i);
1495  }
1496  return viewSelected;
1497 }
1498 
1508 {
1509  Q_D(QListView);
1510  // showing the scroll bars will trigger a resize event,
1511  // so we set the state to expanding to avoid
1512  // triggering another layout
1513  QAbstractItemView::State oldState = state();
1515  if (d->model->columnCount(d->root) > 0) { // no columns means no contents
1516  d->resetBatchStartRow();
1517  if (layoutMode() == SinglePass)
1518  d->doItemsLayout(d->model->rowCount(d->root)); // layout everything
1519  else if (!d->batchLayoutTimer.isActive()) {
1520  if (!d->doItemsLayout(d->batchSize)) // layout is done
1521  d->batchLayoutTimer.start(0, this); // do a new batch as fast as possible
1522  }
1523  }
1525  setState(oldState); // restoring the oldState
1526 }
1527 
1532 {
1533  Q_D(QListView);
1534  if (geometry().isEmpty() || d->model->rowCount(d->root) <= 0 || d->model->columnCount(d->root) <= 0) {
1535  horizontalScrollBar()->setRange(0, 0);
1536  verticalScrollBar()->setRange(0, 0);
1537  } else {
1538  QModelIndex index = d->model->index(0, d->column, d->root);
1539  QStyleOptionViewItemV4 option = d->viewOptionsV4();
1540  QSize step = d->itemSize(option, index);
1541  d->commonListView->updateHorizontalScrollBar(step);
1542  d->commonListView->updateVerticalScrollBar(step);
1543  }
1544 
1546 
1547  // if the scroll bars are turned off, we resize the contents to the viewport
1548  if (d->movement == Static && !d->isWrapping()) {
1549  d->layoutChildren(); // we need the viewport size to be updated
1550  if (d->flow == TopToBottom) {
1552  d->setContentsSize(viewport()->width(), contentsSize().height());
1553  horizontalScrollBar()->setRange(0, 0); // we see all the contents anyway
1554  }
1555  } else { // LeftToRight
1557  d->setContentsSize(contentsSize().width(), viewport()->height());
1558  verticalScrollBar()->setRange(0, 0); // we see all the contents anyway
1559  }
1560  }
1561  }
1562 
1563 }
1564 
1569 {
1570  Q_D(const QListView);
1571  return (d->isHidden(index.row())
1572  && (index.parent() == d->root)
1573  && index.column() == d->column);
1574 }
1575 
1587 {
1588  Q_D(QListView);
1589  if (column < 0 || column >= d->model->columnCount(d->root))
1590  return;
1591  d->column = column;
1592  d->doDelayedItemsLayout();
1593 }
1594 
1595 int QListView::modelColumn() const
1596 {
1597  Q_D(const QListView);
1598  return d->column;
1599 }
1600 
1616 {
1617  Q_D(QListView);
1618  d->uniformItemSizes = enable;
1619 }
1620 
1621 bool QListView::uniformItemSizes() const
1622 {
1623  Q_D(const QListView);
1624  return d->uniformItemSizes;
1625 }
1626 
1645 {
1646  Q_D(QListView);
1647  if (d->wrapItemText == on)
1648  return;
1649  d->wrapItemText = on;
1650  d->doDelayedItemsLayout();
1651 }
1652 
1653 bool QListView::wordWrap() const
1654 {
1655  Q_D(const QListView);
1656  return d->wrapItemText;
1657 }
1658 
1678 {
1679  Q_D(QListView);
1680  d->modeProperties |= uint(QListViewPrivate::SelectionRectVisible);
1681  d->setSelectionRectVisible(show);
1682 }
1683 
1685 {
1686  Q_D(const QListView);
1687  return d->isSelectionRectVisible();
1688 }
1689 
1694 {
1695  return QAbstractItemView::event(e);
1696 }
1697 
1698 /*
1699  * private object implementation
1700  */
1701 
1704  commonListView(0),
1705  wrap(false),
1706  space(0),
1712  modeProperties(0),
1713  column(0),
1714  uniformItemSizes(false),
1715  batchSize(100),
1716  showElasticBand(false)
1717 {
1718 }
1719 
1721 {
1722  delete commonListView;
1723 }
1724 
1726 {
1727  // initialization of data structs
1728  cachedItemSize = QSize();
1729  commonListView->clear();
1730 }
1731 
1733 {
1734  Q_Q(QListView);
1735  clear();
1736 
1737  //take the size as if there were scrollbar in order to prevent scrollbar to blink
1738  layoutBounds = QRect(QPoint(), q->maximumViewportSize());
1739 
1740  int frameAroundContents = 0;
1741  if (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents))
1742  frameAroundContents = q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth) * 2;
1743 
1744  // maximumViewportSize() already takes scrollbar into account if policy is
1745  // Qt::ScrollBarAlwaysOn but scrollbar extent must be deduced if policy
1746  // is Qt::ScrollBarAsNeeded
1747  int verticalMargin = vbarpolicy==Qt::ScrollBarAsNeeded
1748  ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, vbar) + frameAroundContents
1749  : 0;
1750  int horizontalMargin = hbarpolicy==Qt::ScrollBarAsNeeded
1751  ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, hbar) + frameAroundContents
1752  : 0;
1753 
1754  layoutBounds.adjust(0, 0, -verticalMargin, -horizontalMargin);
1755 
1756  int rowCount = model->columnCount(root) <= 0 ? 0 : model->rowCount(root);
1757  commonListView->setRowCount(rowCount);
1758 }
1759 
1764 {
1765  int max = model->rowCount(root) - 1;
1766  int first = batchStartRow();
1767  int last = qMin(first + delta - 1, max);
1768 
1769  if (first == 0) {
1770  layoutChildren(); // make sure the viewport has the right size
1772  }
1773 
1774  if (max < 0 || last < first) {
1775  return true; // nothing to do
1776  }
1777 
1779  info.bounds = layoutBounds;
1780  info.grid = gridSize();
1781  info.spacing = (info.grid.isValid() ? 0 : spacing());
1782  info.first = first;
1783  info.last = last;
1784  info.wrap = isWrapping();
1785  info.flow = flow;
1786  info.max = max;
1787 
1788  return commonListView->doBatchedItemLayout(info, max);
1789 }
1790 
1792 {
1793  if (!index.isValid() || isHidden(index.row()))
1794  return QListViewItem();
1795 
1796  return commonListView->indexToListViewItem(index);
1797 }
1798 
1799 QRect QListViewPrivate::mapToViewport(const QRect &rect, bool extend) const
1800 {
1801  Q_Q(const QListView);
1802  if (!rect.isValid())
1803  return rect;
1804 
1805  QRect result = extend ? commonListView->mapToViewport(rect) : rect;
1806  int dx = -q->horizontalOffset();
1807  int dy = -q->verticalOffset();
1808  return result.adjusted(dx, dy, dx, dy);
1809 }
1810 
1812  const QVector<QModelIndex> &candidates) const
1813 {
1814  int distance = 0;
1815  int shortest = INT_MAX;
1816  QModelIndex closest;
1818 
1819  for (; it != candidates.end(); ++it) {
1820  if (!(*it).isValid())
1821  continue;
1822 
1823  const QRect indexRect = indexToListViewItem(*it).rect();
1824 
1825  //if the center x (or y) position of an item is included in the rect of the other item,
1826  //we define the distance between them as the difference in x (or y) of their respective center.
1827  // Otherwise, we use the nahattan length between the 2 items
1828  if ((target.center().x() >= indexRect.x() && target.center().x() < indexRect.right())
1829  || (indexRect.center().x() >= target.x() && indexRect.center().x() < target.right())) {
1830  //one item's center is at the vertical of the other
1831  distance = qAbs(indexRect.center().y() - target.center().y());
1832  } else if ((target.center().y() >= indexRect.y() && target.center().y() < indexRect.bottom())
1833  || (indexRect.center().y() >= target.y() && indexRect.center().y() < target.bottom())) {
1834  //one item's center is at the vertical of the other
1835  distance = qAbs(indexRect.center().x() - target.center().x());
1836  } else {
1837  distance = (indexRect.center() - target.center()).manhattanLength();
1838  }
1839  if (distance < shortest) {
1840  shortest = distance;
1841  closest = *it;
1842  }
1843  }
1844  return closest;
1845 }
1846 
1848 {
1849  if (!uniformItemSizes) {
1850  const QAbstractItemDelegate *delegate = delegateForIndex(index);
1851  return delegate ? delegate->sizeHint(option, index) : QSize();
1852  }
1853  if (!cachedItemSize.isValid()) { // the last item is probaly the largest, so we use its size
1854  int row = model->rowCount(root) - 1;
1855  QModelIndex sample = model->index(row, column, root);
1856  const QAbstractItemDelegate *delegate = delegateForIndex(sample);
1857  cachedItemSize = delegate ? delegate->sizeHint(option, sample) : QSize();
1858  }
1859  return cachedItemSize;
1860 }
1861 
1863 {
1865  QModelIndex tl, br;
1866  const QVector<QModelIndex> intersectVector = intersectingSet(rect);
1867  QVector<QModelIndex>::const_iterator it = intersectVector.begin();
1868  for (; it != intersectVector.end(); ++it) {
1869  if (!tl.isValid() && !br.isValid()) {
1870  tl = br = *it;
1871  } else if ((*it).row() == (tl.row() - 1)) {
1872  tl = *it; // expand current range
1873  } else if ((*it).row() == (br.row() + 1)) {
1874  br = (*it); // expand current range
1875  } else {
1876  selection.select(tl, br); // select current range
1877  tl = br = *it; // start new range
1878  }
1879  }
1880 
1881  if (tl.isValid() && br.isValid())
1882  selection.select(tl, br);
1883  else if (tl.isValid())
1884  selection.select(tl, tl);
1885  else if (br.isValid())
1886  selection.select(br, br);
1887 
1888  return selection;
1889 }
1890 
1891 #ifndef QT_NO_DRAGANDDROP
1893 {
1895  return static_cast<QListModeViewBase *>(commonListView)->position(pos, rect, idx);
1896  else
1897  return QAbstractItemViewPrivate::position(pos, rect, idx);
1898 }
1899 
1900 bool QListViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QModelIndex *dropIndex)
1901 {
1903  return static_cast<QListModeViewBase *>(commonListView)->dropOn(event, dropRow, dropCol, dropIndex);
1904  else
1905  return QAbstractItemViewPrivate::dropOn(event, dropRow, dropCol, dropIndex);
1906 }
1907 #endif
1908 
1909 /*
1910  * Common ListView Implementation
1911 */
1912 
1914 {
1915  dd->hiddenRows.insert(dd->model->index(row, 0, qq->rootIndex()));
1916 }
1917 
1919 {
1920  dd->hiddenRows.remove(dd->model->index(row, 0, qq->rootIndex()));
1921 }
1922 
1923 #ifndef QT_NO_DRAGANDDROP
1925 {
1926  // FIXME: Until the we can provide a proper drop indicator
1927  // in IconMode, it makes no sense to show it
1928  dd->paintDropIndicator(painter);
1929 }
1930 #endif
1931 
1933 {
1934  horizontalScrollBar()->setSingleStep(step.width() + spacing());
1935  horizontalScrollBar()->setPageStep(viewport()->width());
1936  horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width());
1937 }
1938 
1940 {
1941  verticalScrollBar()->setSingleStep(step.height() + spacing());
1942  verticalScrollBar()->setPageStep(viewport()->height());
1943  verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height());
1944 }
1945 
1946 void QCommonListViewBase::scrollContentsBy(int dx, int dy, bool /*scrollElasticBand*/)
1947 {
1948  dd->scrollContentsBy(isRightToLeft() ? -dx : dx, dy);
1949 }
1950 
1952  bool above, bool below, const QRect &area, const QRect &rect) const
1953 {
1954  int verticalValue = verticalScrollBar()->value();
1955  QRect adjusted = rect.adjusted(-spacing(), -spacing(), spacing(), spacing());
1956  if (hint == QListView::PositionAtTop || above)
1957  verticalValue += adjusted.top();
1958  else if (hint == QListView::PositionAtBottom || below)
1959  verticalValue += qMin(adjusted.top(), adjusted.bottom() - area.height() + 1);
1960  else if (hint == QListView::PositionAtCenter)
1961  verticalValue += adjusted.top() - ((area.height() - adjusted.height()) / 2);
1962  return verticalValue;
1963 }
1964 
1966 {
1967  return (isRightToLeft() ? horizontalScrollBar()->maximum() - horizontalScrollBar()->value() : horizontalScrollBar()->value());
1968 }
1969 
1971  bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const
1972 {
1973  int horizontalValue = horizontalScrollBar()->value();
1974  if (isRightToLeft()) {
1975  if (hint == QListView::PositionAtCenter) {
1976  horizontalValue += ((area.width() - rect.width()) / 2) - rect.left();
1977  } else {
1978  if (leftOf)
1979  horizontalValue -= rect.left();
1980  else if (rightOf)
1981  horizontalValue += qMin(rect.left(), area.width() - rect.right());
1982  }
1983  } else {
1984  if (hint == QListView::PositionAtCenter) {
1985  horizontalValue += rect.left() - ((area.width()- rect.width()) / 2);
1986  } else {
1987  if (leftOf)
1988  horizontalValue += rect.left();
1989  else if (rightOf)
1990  horizontalValue += qMin(rect.left(), rect.right() - area.width());
1991  }
1992  }
1993  return horizontalValue;
1994 }
1995 
1996 /*
1997  * ListMode ListView Implementation
1998 */
1999 
2000 #ifndef QT_NO_DRAGANDDROP
2002 {
2004  if (!dd->overwrite) {
2005  const int margin = 2;
2006  if (pos.x() - rect.left() < margin) {
2007  r = QAbstractItemView::AboveItem; // Visually, on the left
2008  } else if (rect.right() - pos.x() < margin) {
2009  r = QAbstractItemView::BelowItem; // Visually, on the right
2010  } else if (rect.contains(pos, true)) {
2012  }
2013  } else {
2014  QRect touchingRect = rect;
2015  touchingRect.adjust(-1, -1, 1, 1);
2016  if (touchingRect.contains(pos, false)) {
2018  }
2019  }
2020 
2021  if (r == QAbstractItemView::OnItem && (!(dd->model->flags(index) & Qt::ItemIsDropEnabled)))
2023 
2024  return r;
2025 }
2026 
2028 {
2029  if (qq->dragDropMode() == QAbstractItemView::InternalMove
2030  && (event->source() != qq || !(event->possibleActions() & Qt::MoveAction)))
2031  return;
2032 
2033  // ignore by default
2034  event->ignore();
2035 
2036  // can't use indexAt, doesn't account for spacing.
2037  QPoint p = event->pos();
2038  QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1);
2039  rect.adjust(-dd->spacing(), -dd->spacing(), dd->spacing(), dd->spacing());
2040  const QVector<QModelIndex> intersectVector = dd->intersectingSet(rect);
2041  QModelIndex index = intersectVector.count() > 0
2042  ? intersectVector.last() : QModelIndex();
2043  dd->hover = index;
2044  if (!dd->droppingOnItself(event, index)
2045  && dd->canDecode(event)) {
2046 
2047  if (index.isValid() && dd->showDropIndicator) {
2048  QRect rect = qq->visualRect(index);
2049  dd->dropIndicatorPosition = position(event->pos(), rect, index);
2050  // if spacing, should try to draw between items, not just next to item.
2051  switch (dd->dropIndicatorPosition) {
2053  if (dd->isIndexDropEnabled(index.parent())) {
2054  dd->dropIndicatorRect = QRect(rect.left()-dd->spacing(), rect.top(), 0, rect.height());
2055  event->accept();
2056  } else {
2057  dd->dropIndicatorRect = QRect();
2058  }
2059  break;
2061  if (dd->isIndexDropEnabled(index.parent())) {
2062  dd->dropIndicatorRect = QRect(rect.right()+dd->spacing(), rect.top(), 0, rect.height());
2063  event->accept();
2064  } else {
2065  dd->dropIndicatorRect = QRect();
2066  }
2067  break;
2069  if (dd->isIndexDropEnabled(index)) {
2070  dd->dropIndicatorRect = rect;
2071  event->accept();
2072  } else {
2073  dd->dropIndicatorRect = QRect();
2074  }
2075  break;
2077  dd->dropIndicatorRect = QRect();
2078  if (dd->isIndexDropEnabled(qq->rootIndex())) {
2079  event->accept(); // allow dropping in empty areas
2080  }
2081  break;
2082  }
2083  } else {
2084  dd->dropIndicatorRect = QRect();
2085  dd->dropIndicatorPosition = QAbstractItemView::OnViewport;
2086  if (dd->isIndexDropEnabled(qq->rootIndex())) {
2087  event->accept(); // allow dropping in empty areas
2088  }
2089  }
2090  dd->viewport->update();
2091  } // can decode
2092 
2093  if (dd->shouldAutoScroll(event->pos()))
2094  qq->startAutoScroll();
2095 }
2096 
2108 bool QListModeViewBase::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QModelIndex *dropIndex)
2109 {
2110  if (event->isAccepted())
2111  return false;
2112 
2114  if (dd->viewport->rect().contains(event->pos())) {
2115  // can't use indexAt, doesn't account for spacing.
2116  QPoint p = event->pos();
2117  QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1);
2118  rect.adjust(-dd->spacing(), -dd->spacing(), dd->spacing(), dd->spacing());
2119  const QVector<QModelIndex> intersectVector = dd->intersectingSet(rect);
2120  index = intersectVector.count() > 0
2121  ? intersectVector.last() : QModelIndex();
2122  if (!index.isValid())
2123  index = dd->root;
2124  }
2125 
2126  // If we are allowed to do the drop
2127  if (dd->model->supportedDropActions() & event->dropAction()) {
2128  int row = -1;
2129  int col = -1;
2130  if (index != dd->root) {
2131  dd->dropIndicatorPosition = position(event->pos(), qq->visualRect(index), index);
2132  switch (dd->dropIndicatorPosition) {
2134  row = index.row();
2135  col = index.column();
2136  index = index.parent();
2137  break;
2139  row = index.row() + 1;
2140  col = index.column();
2141  index = index.parent();
2142  break;
2145  break;
2146  }
2147  } else {
2148  dd->dropIndicatorPosition = QAbstractItemView::OnViewport;
2149  }
2150  *dropIndex = index;
2151  *dropRow = row;
2152  *dropCol = col;
2153  if (!dd->droppingOnItself(event, index))
2154  return true;
2155  }
2156  return false;
2157 }
2158 
2159 #endif //QT_NO_DRAGANDDROP
2160 
2162 {
2164  && ((flow() == QListView::TopToBottom && !isWrapping())
2165  || (flow() == QListView::LeftToRight && isWrapping()))) {
2166  const int steps = (flow() == QListView::TopToBottom ? scrollValueMap : segmentPositions).count() - 1;
2167  if (steps > 0) {
2168  const int pageSteps = perItemScrollingPageSteps(viewport()->height(), contentsSize.height(), isWrapping());
2169  verticalScrollBar()->setSingleStep(1);
2170  verticalScrollBar()->setPageStep(pageSteps);
2171  verticalScrollBar()->setRange(0, steps - pageSteps);
2172  } else {
2173  verticalScrollBar()->setRange(0, 0);
2174  }
2175  // } else if (vertical && d->isWrapping() && d->movement == Static) {
2176  // ### wrapped scrolling in flow direction
2177  } else {
2179  }
2180 }
2181 
2183 {
2185  && ((flow() == QListView::TopToBottom && isWrapping())
2186  || (flow() == QListView::LeftToRight && !isWrapping()))) {
2187  int steps = (flow() == QListView::TopToBottom ? segmentPositions : scrollValueMap).count() - 1;
2188  if (steps > 0) {
2189  const int pageSteps = perItemScrollingPageSteps(viewport()->width(), contentsSize.width(), isWrapping());
2190  horizontalScrollBar()->setSingleStep(1);
2191  horizontalScrollBar()->setPageStep(pageSteps);
2192  horizontalScrollBar()->setRange(0, steps - pageSteps);
2193  } else {
2194  horizontalScrollBar()->setRange(0, 0);
2195  }
2196  } else {
2198  }
2199 }
2200 
2202  bool above, bool below, const QRect &area, const QRect &rect) const
2203 {
2205  int value;
2206  if (scrollValueMap.isEmpty()) {
2207  value = 0;
2208  } else {
2209  int scrollBarValue = verticalScrollBar()->value();
2210  int numHidden = 0;
2211  for (int i = 0; i < flowPositions.count() - 1 && i <= scrollBarValue; ++i)
2212  if (isHidden(i))
2213  ++numHidden;
2214  value = qBound(0, scrollValueMap.at(verticalScrollBar()->value()) - numHidden, flowPositions.count() - 1);
2215  }
2216  if (above)
2217  hint = QListView::PositionAtTop;
2218  else if (below)
2220  if (hint == QListView::EnsureVisible)
2221  return value;
2222 
2223  return perItemScrollToValue(index, value, area.height(), hint, Qt::Vertical, isWrapping(), rect.height());
2224  }
2225 
2226  return QCommonListViewBase::verticalScrollToValue(index, hint, above, below, area, rect);
2227 }
2228 
2230 {
2232  if (isWrapping()) {
2233  if (flow() == QListView::TopToBottom && !segmentPositions.isEmpty()) {
2234  const int max = segmentPositions.count() - 1;
2235  int currentValue = qBound(0, horizontalScrollBar()->value(), max);
2236  int position = segmentPositions.at(currentValue);
2237  int maximumValue = qBound(0, horizontalScrollBar()->maximum(), max);
2238  int maximum = segmentPositions.at(maximumValue);
2239  return (isRightToLeft() ? maximum - position : position);
2240  }
2241  } else if (flow() == QListView::LeftToRight && !flowPositions.isEmpty()) {
2242  int position = flowPositions.at(scrollValueMap.at(horizontalScrollBar()->value()));
2243  int maximum = flowPositions.at(scrollValueMap.at(horizontalScrollBar()->maximum()));
2244  return (isRightToLeft() ? maximum - position : position);
2245  }
2246  }
2248 }
2249 
2251 {
2253  if (isWrapping()) {
2254  if (flow() == QListView::LeftToRight && !segmentPositions.isEmpty()) {
2255  int value = verticalScrollBar()->value();
2256  if (value >= segmentPositions.count())
2257  return 0;
2258  return segmentPositions.at(value) - spacing();
2259  }
2260  } else if (flow() == QListView::TopToBottom && !flowPositions.isEmpty()) {
2261  int value = verticalScrollBar()->value();
2262  if (value > scrollValueMap.count())
2263  return 0;
2264  return flowPositions.at(scrollValueMap.at(value)) - spacing();
2265  }
2266  }
2268 }
2269 
2271  bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const
2272 {
2274  return QCommonListViewBase::horizontalScrollToValue(index, hint, leftOf, rightOf, area, rect);
2275 
2276  int value;
2277  if (scrollValueMap.isEmpty())
2278  value = 0;
2279  else
2280  value = qBound(0, scrollValueMap.at(horizontalScrollBar()->value()), flowPositions.count() - 1);
2281  if (leftOf)
2282  hint = QListView::PositionAtTop;
2283  else if (rightOf)
2285  if (hint == QListView::EnsureVisible)
2286  return value;
2287 
2288  return perItemScrollToValue(index, value, area.width(), hint, Qt::Horizontal, isWrapping(), rect.width());
2289 }
2290 
2291 void QListModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand)
2292 {
2293  // ### reorder this logic
2294  const int verticalValue = verticalScrollBar()->value();
2295  const int horizontalValue = horizontalScrollBar()->value();
2296  const bool vertical = (verticalScrollMode() == QAbstractItemView::ScrollPerItem);
2297  const bool horizontal = (horizontalScrollMode() == QAbstractItemView::ScrollPerItem);
2298 
2299  if (isWrapping()) {
2300  if (segmentPositions.isEmpty())
2301  return;
2302  const int max = segmentPositions.count() - 1;
2303  if (horizontal && flow() == QListView::TopToBottom && dx != 0) {
2304  int currentValue = qBound(0, horizontalValue, max);
2305  int previousValue = qBound(0, currentValue + dx, max);
2306  int currentCoordinate = segmentPositions.at(currentValue) - spacing();
2307  int previousCoordinate = segmentPositions.at(previousValue) - spacing();
2308  dx = previousCoordinate - currentCoordinate;
2309  } else if (vertical && flow() == QListView::LeftToRight && dy != 0) {
2310  int currentValue = qBound(0, verticalValue, max);
2311  int previousValue = qBound(0, currentValue + dy, max);
2312  int currentCoordinate = segmentPositions.at(currentValue) - spacing();
2313  int previousCoordinate = segmentPositions.at(previousValue) - spacing();
2314  dy = previousCoordinate - currentCoordinate;
2315  }
2316  } else {
2317  if (flowPositions.isEmpty())
2318  return;
2319  const int max = scrollValueMap.count() - 1;
2320  if (vertical && flow() == QListView::TopToBottom && dy != 0) {
2321  int currentValue = qBound(0, verticalValue, max);
2322  int previousValue = qBound(0, currentValue + dy, max);
2323  int currentCoordinate = flowPositions.at(scrollValueMap.at(currentValue));
2324  int previousCoordinate = flowPositions.at(scrollValueMap.at(previousValue));
2325  dy = previousCoordinate - currentCoordinate;
2326  } else if (horizontal && flow() == QListView::LeftToRight && dx != 0) {
2327  int currentValue = qBound(0, horizontalValue, max);
2328  int previousValue = qBound(0, currentValue + dx, max);
2329  int currentCoordinate = flowPositions.at(scrollValueMap.at(currentValue));
2330  int previousCoordinate = flowPositions.at(scrollValueMap.at(previousValue));
2331  dx = previousCoordinate - currentCoordinate;
2332  }
2333  }
2334  QCommonListViewBase::scrollContentsBy(dx, dy, scrollElasticBand);
2335 }
2336 
2338 {
2339  doStaticLayout(info);
2340  if (batchStartRow > max) { // stop items layout
2341  flowPositions.resize(flowPositions.count());
2342  segmentPositions.resize(segmentPositions.count());
2343  segmentStartRows.resize(segmentStartRows.count());
2344  return true; // done
2345  }
2346  return false; // not done
2347 }
2348 
2350 {
2351  if (flowPositions.isEmpty()
2352  || segmentPositions.isEmpty()
2353  || index.row() >= flowPositions.count())
2354  return QListViewItem();
2355 
2356  const int segment = qBinarySearch<int>(segmentStartRows, index.row(),
2357  0, segmentStartRows.count() - 1);
2358 
2359 
2360  QStyleOptionViewItemV4 options = viewOptions();
2361  options.rect.setSize(contentsSize);
2362  QSize size = (uniformItemSizes() && cachedItemSize().isValid())
2363  ? cachedItemSize() : itemSize(options, index);
2364 
2365  QPoint pos;
2366  if (flow() == QListView::LeftToRight) {
2367  pos.setX(flowPositions.at(index.row()));
2368  pos.setY(segmentPositions.at(segment));
2369  } else { // TopToBottom
2370  pos.setY(flowPositions.at(index.row()));
2371  pos.setX(segmentPositions.at(segment));
2372  if (isWrapping()) { // make the items as wide as the segment
2373  int right = (segment + 1 >= segmentPositions.count()
2374  ? contentsSize.width()
2375  : segmentPositions.at(segment + 1));
2376  size.setWidth(right - pos.x());
2377  } else { // make the items as wide as the viewport
2378  size.setWidth(qMax(size.width(), viewport()->width() - 2 * spacing()));
2379  }
2380  }
2381 
2382  return QListViewItem(QRect(pos, size), index.row());
2383 }
2384 
2386 {
2387  int x, y;
2388  if (info.first == 0) {
2389  flowPositions.clear();
2390  segmentPositions.clear();
2391  segmentStartRows.clear();
2392  segmentExtents.clear();
2393  scrollValueMap.clear();
2394  x = info.bounds.left() + info.spacing;
2395  y = info.bounds.top() + info.spacing;
2396  segmentPositions.append(info.flow == QListView::LeftToRight ? y : x);
2397  segmentStartRows.append(0);
2398  } else if (info.wrap) {
2399  if (info.flow == QListView::LeftToRight) {
2400  x = batchSavedPosition;
2401  y = segmentPositions.last();
2402  } else { // flow == QListView::TopToBottom
2403  x = segmentPositions.last();
2404  y = batchSavedPosition;
2405  }
2406  } else { // not first and not wrap
2407  if (info.flow == QListView::LeftToRight) {
2408  x = batchSavedPosition;
2409  y = info.bounds.top() + info.spacing;
2410  } else { // flow == QListView::TopToBottom
2411  x = info.bounds.left() + info.spacing;
2412  y = batchSavedPosition;
2413  }
2414  }
2415  return QPoint(x, y);
2416 }
2417 
2422 {
2423  const bool useItemSize = !info.grid.isValid();
2424  const QPoint topLeft = initStaticLayout(info);
2425  QStyleOptionViewItemV4 option = viewOptions();
2426  option.rect = info.bounds;
2427  option.rect.adjust(info.spacing, info.spacing, -info.spacing, -info.spacing);
2428 
2429  // The static layout data structures are as follows:
2430  // One vector contains the coordinate in the direction of layout flow.
2431  // Another vector contains the coordinates of the segments.
2432  // A third vector contains the index (model row) of the first item
2433  // of each segment.
2434 
2435  int segStartPosition;
2436  int segEndPosition;
2437  int deltaFlowPosition;
2438  int deltaSegPosition;
2439  int deltaSegHint;
2440  int flowPosition;
2441  int segPosition;
2442 
2443  if (info.flow == QListView::LeftToRight) {
2444  segStartPosition = info.bounds.left();
2445  segEndPosition = info.bounds.width();
2446  flowPosition = topLeft.x();
2447  segPosition = topLeft.y();
2448  deltaFlowPosition = info.grid.width(); // dx
2449  deltaSegPosition = useItemSize ? batchSavedDeltaSeg : info.grid.height(); // dy
2450  deltaSegHint = info.grid.height();
2451  } else { // flow == QListView::TopToBottom
2452  segStartPosition = info.bounds.top();
2453  segEndPosition = info.bounds.height();
2454  flowPosition = topLeft.y();
2455  segPosition = topLeft.x();
2456  deltaFlowPosition = info.grid.height(); // dy
2457  deltaSegPosition = useItemSize ? batchSavedDeltaSeg : info.grid.width(); // dx
2458  deltaSegHint = info.grid.width();
2459  }
2460 
2461  for (int row = info.first; row <= info.last; ++row) {
2462  if (isHidden(row)) { // ###
2463  flowPositions.append(flowPosition);
2464  } else {
2465  // if we are not using a grid, we need to find the deltas
2466  if (useItemSize) {
2467  QSize hint = itemSize(option, modelIndex(row));
2468  if (info.flow == QListView::LeftToRight) {
2469  deltaFlowPosition = hint.width() + info.spacing;
2470  deltaSegHint = hint.height() + info.spacing;
2471  } else { // TopToBottom
2472  deltaFlowPosition = hint.height() + info.spacing;
2473  deltaSegHint = hint.width() + info.spacing;
2474  }
2475  }
2476  // create new segment
2477  if (info.wrap && (flowPosition + deltaFlowPosition >= segEndPosition)) {
2478  segmentExtents.append(flowPosition);
2479  flowPosition = info.spacing + segStartPosition;
2480  segPosition += deltaSegPosition;
2481  if (info.wrap)
2482  segPosition += info.spacing;
2483  segmentPositions.append(segPosition);
2484  segmentStartRows.append(row);
2485  deltaSegPosition = 0;
2486  }
2487  // save the flow position of this item
2488  scrollValueMap.append(flowPositions.count());
2489  flowPositions.append(flowPosition);
2490  // prepare for the next item
2491  deltaSegPosition = qMax(deltaSegHint, deltaSegPosition);
2492  flowPosition += info.spacing + deltaFlowPosition;
2493  }
2494  }
2495  // used when laying out next batch
2496  batchSavedPosition = flowPosition;
2497  batchSavedDeltaSeg = deltaSegPosition;
2498  batchStartRow = info.last + 1;
2499  if (info.last == info.max)
2500  flowPosition -= info.spacing; // remove extra spacing
2501  // set the contents size
2502  QRect rect = info.bounds;
2503  if (info.flow == QListView::LeftToRight) {
2504  rect.setRight(segmentPositions.count() == 1 ? flowPosition : info.bounds.right());
2505  rect.setBottom(segPosition + deltaSegPosition);
2506  } else { // TopToBottom
2507  rect.setRight(segPosition + deltaSegPosition);
2508  rect.setBottom(segmentPositions.count() == 1 ? flowPosition : info.bounds.bottom());
2509  }
2510  contentsSize = QSize(rect.right(), rect.bottom());
2511  // if it is the last batch, save the end of the segments
2512  if (info.last == info.max) {
2513  segmentExtents.append(flowPosition);
2514  scrollValueMap.append(flowPositions.count());
2515  flowPositions.append(flowPosition);
2516  segmentPositions.append(info.wrap ? segPosition + deltaSegPosition : INT_MAX);
2517  }
2518  // if the new items are visble, update the viewport
2519  QRect changedRect(topLeft, rect.bottomRight());
2520  if (clipRect().intersects(changedRect))
2521  viewport()->update();
2522 }
2523 
2533 {
2535  int segStartPosition;
2536  int segEndPosition;
2537  int flowStartPosition;
2538  int flowEndPosition;
2539  if (flow() == QListView::LeftToRight) {
2540  segStartPosition = area.top();
2541  segEndPosition = area.bottom();
2542  flowStartPosition = area.left();
2543  flowEndPosition = area.right();
2544  } else {
2545  segStartPosition = area.left();
2546  segEndPosition = area.right();
2547  flowStartPosition = area.top();
2548  flowEndPosition = area.bottom();
2549  }
2550  if (segmentPositions.count() < 2 || flowPositions.isEmpty())
2551  return ret;
2552  // the last segment position is actually the edge of the last segment
2553  const int segLast = segmentPositions.count() - 2;
2554  int seg = qBinarySearch<int>(segmentPositions, segStartPosition, 0, segLast + 1);
2555  for (; seg <= segLast && segmentPositions.at(seg) <= segEndPosition; ++seg) {
2556  int first = segmentStartRows.at(seg);
2557  int last = (seg < segLast ? segmentStartRows.at(seg + 1) : batchStartRow) - 1;
2558  if (segmentExtents.at(seg) < flowStartPosition)
2559  continue;
2560  int row = qBinarySearch<int>(flowPositions, flowStartPosition, first, last);
2561  for (; row <= last && flowPositions.at(row) <= flowEndPosition; ++row) {
2562  if (isHidden(row))
2563  continue;
2564  QModelIndex index = modelIndex(row);
2565  if (index.isValid())
2566  ret += index;
2567 #if 0 // for debugging
2568  else
2569  qWarning("intersectingSet: row %d was invalid", row);
2570 #endif
2571  }
2572  }
2573  return ret;
2574 }
2575 
2577 {
2578  dd->doDelayedItemsLayout();
2579 }
2580 
2581 
2583 {
2584  if (isWrapping())
2585  return rect;
2586  // If the listview is in "listbox-mode", the items are as wide as the view.
2587  // But we don't shrink the items.
2588  QRect result = rect;
2589  if (flow() == QListView::TopToBottom) {
2590  result.setLeft(spacing());
2591  result.setWidth(qMax(rect.width(), qMax(contentsSize.width(), viewport()->width()) - 2 * spacing()));
2592  } else { // LeftToRight
2593  result.setTop(spacing());
2594  result.setHeight(qMax(rect.height(), qMax(contentsSize.height(), viewport()->height()) - 2 * spacing()));
2595  }
2596  return result;
2597 }
2598 
2599 int QListModeViewBase::perItemScrollingPageSteps(int length, int bounds, bool wrap) const
2600 {
2602  if (wrap)
2603  positions = segmentPositions;
2604  else if (!flowPositions.isEmpty()) {
2605  positions.reserve(scrollValueMap.size());
2606  foreach (int itemShown, scrollValueMap)
2607  positions.append(flowPositions.at(itemShown));
2608  }
2609  if (positions.isEmpty() || bounds <= length)
2610  return positions.count();
2611  if (uniformItemSizes()) {
2612  for (int i = 1; i < positions.count(); ++i)
2613  if (positions.at(i) > 0)
2614  return length / positions.at(i);
2615  return 0; // all items had height 0
2616  }
2617  int pageSteps = 0;
2618  int steps = positions.count() - 1;
2619  int max = qMax(length, bounds);
2620  int min = qMin(length, bounds);
2621  int pos = min - (max - positions.last());
2622 
2623  while (pos >= 0 && steps > 0) {
2624  pos -= (positions.at(steps) - positions.at(steps - 1));
2625  if (pos >= 0) //this item should be visible
2626  ++pageSteps;
2627  --steps;
2628  }
2629 
2630  // at this point we know that positions has at least one entry
2631  return qMax(pageSteps, 1);
2632 }
2633 
2634 int QListModeViewBase::perItemScrollToValue(int index, int scrollValue, int viewportSize,
2636  Qt::Orientation orientation, bool wrap, int itemExtent) const
2637 {
2638  if (index < 0)
2639  return scrollValue;
2640 
2641  QVector<int> visibleFlowPositions;
2642  visibleFlowPositions.reserve(flowPositions.count() - 1);
2643  for (int i = 0; i < flowPositions.count() - 1; i++) { // flowPositions count is +1 larger than actual row count
2644  if (!isHidden(i))
2645  visibleFlowPositions.append(flowPositions.at(i));
2646  }
2647 
2648  if (!wrap) {
2649  int topIndex = index;
2650  const int bottomIndex = topIndex;
2651  const int bottomCoordinate = visibleFlowPositions.at(index);
2652 
2653  while (topIndex > 0 &&
2654  (bottomCoordinate - visibleFlowPositions.at(topIndex - 1) + itemExtent) <= (viewportSize)) {
2655  topIndex--;
2656  }
2657 
2658  const int itemCount = bottomIndex - topIndex + 1;
2659  switch (hint) {
2661  return index;
2663  return index - itemCount + 1;
2665  return index - (itemCount / 2);
2666  default:
2667  break;
2668  }
2669  } else { // wrapping
2670  Qt::Orientation flowOrientation = (flow() == QListView::LeftToRight
2672  if (flowOrientation == orientation) { // scrolling in the "flow" direction
2673  // ### wrapped scrolling in the flow direction
2674  return visibleFlowPositions.at(index); // ### always pixel based for now
2675  } else if (!segmentStartRows.isEmpty()) { // we are scrolling in the "segment" direction
2676  int segment = qBinarySearch<int>(segmentStartRows, index, 0, segmentStartRows.count() - 1);
2677  int leftSegment = segment;
2678  const int rightSegment = leftSegment;
2679  const int bottomCoordinate = segmentPositions.at(segment);
2680 
2681  while (leftSegment > scrollValue &&
2682  (bottomCoordinate - segmentPositions.at(leftSegment-1) + itemExtent) <= (viewportSize)) {
2683  leftSegment--;
2684  }
2685 
2686  const int segmentCount = rightSegment - leftSegment + 1;
2687  switch (hint) {
2689  return segment;
2691  return segment - segmentCount + 1;
2693  return segment - (segmentCount / 2);
2694  default:
2695  break;
2696  }
2697  }
2698  }
2699  return scrollValue;
2700 }
2701 
2703 {
2704  flowPositions.clear();
2705  segmentPositions.clear();
2706  segmentStartRows.clear();
2707  segmentExtents.clear();
2708  batchSavedPosition = 0;
2709  batchStartRow = 0;
2710  batchSavedDeltaSeg = 0;
2711 }
2712 
2713 /*
2714  * IconMode ListView Implementation
2715 */
2716 
2718 {
2719  if (index.row() >= items.count())
2720  return;
2721  const QSize oldContents = contentsSize;
2722  qq->update(index); // update old position
2723  moveItem(index.row(), position);
2724  qq->update(index); // update new position
2725 
2726  if (contentsSize != oldContents)
2727  dd->viewUpdateGeometries(); // update the scroll bars
2728 }
2729 
2731 {
2732  if (row >= 0 && row < items.count()) //remove item
2733  tree.removeLeaf(items.at(row).rect(), row);
2735 }
2736 
2738 {
2740  if (row >= 0 && row < items.count()) //insert item
2741  tree.insertLeaf(items.at(row).rect(), row);
2742 }
2743 
2744 #ifndef QT_NO_DRAGANDDROP
2745 bool QIconModeViewBase::filterStartDrag(Qt::DropActions supportedActions)
2746 {
2747  // This function does the same thing as in QAbstractItemView::startDrag(),
2748  // plus adding viewitems to the draggedItems list.
2749  // We need these items to draw the drag items
2750  QModelIndexList indexes = dd->selectionModel->selectedIndexes();
2751  if (indexes.count() > 0 ) {
2752  if (viewport()->acceptDrops()) {
2754  for (; it != indexes.constEnd(); ++it)
2755  if (dd->model->flags(*it) & Qt::ItemIsDragEnabled
2756  && (*it).column() == dd->column)
2757  draggedItems.push_back(*it);
2758  }
2759 
2760  QRect rect;
2761  QPixmap pixmap = dd->renderToPixmap(indexes, &rect);
2762  rect.adjust(horizontalOffset(), verticalOffset(), 0, 0);
2763 
2764  QDrag *drag = new QDrag(qq);
2765  drag->setPixmap(pixmap);
2766  drag->setHotSpot(dd->pressedPosition - rect.topLeft());
2767  drag->setMimeData(dd->model->mimeData(indexes));
2768  Qt::DropAction action = drag->exec(supportedActions, Qt::CopyAction);
2769  draggedItems.clear();
2770  if (action == Qt::MoveAction)
2771  dd->clearOrRemove();
2772  }
2773  return true;
2774 }
2775 
2777 {
2778  if (e->source() != qq)
2779  return false;
2780 
2781  const QSize contents = contentsSize;
2782  QPoint offset(horizontalOffset(), verticalOffset());
2783  QPoint end = e->pos() + offset;
2784  if (qq->acceptDrops()) {
2785  const Qt::ItemFlags dropableFlags = Qt::ItemIsDropEnabled|Qt::ItemIsEnabled;
2786  const QVector<QModelIndex> &dropIndices = intersectingSet(QRect(end, QSize(1, 1)));
2787  foreach (const QModelIndex &index, dropIndices)
2788  if ((index.flags() & dropableFlags) == dropableFlags)
2789  return false;
2790  }
2791  QPoint start = dd->pressedPosition;
2792  QPoint delta = (dd->movement == QListView::Snap ? snapToGrid(end) - snapToGrid(start) : end - start);
2793  QList<QModelIndex> indexes = dd->selectionModel->selectedIndexes();
2794  for (int i = 0; i < indexes.count(); ++i) {
2795  QModelIndex index = indexes.at(i);
2796  QRect rect = dd->rectForIndex(index);
2797  viewport()->update(dd->mapToViewport(rect, false));
2798  QPoint dest = rect.topLeft() + delta;
2799  if (qq->isRightToLeft())
2800  dest.setX(dd->flipX(dest.x()) - rect.width());
2801  moveItem(index.row(), dest);
2802  qq->update(index);
2803  }
2804  dd->stopAutoScroll();
2805  draggedItems.clear();
2806  dd->emitIndexesMoved(indexes);
2807  e->accept(); // we have handled the event
2808  // if the size has not grown, we need to check if it has shrinked
2809  if (contentsSize != contents) {
2810  if ((contentsSize.width() <= contents.width()
2811  || contentsSize.height() <= contents.height())) {
2812  updateContentsSize();
2813  }
2814  dd->viewUpdateGeometries();
2815  }
2816  return true;
2817 }
2818 
2820 {
2821  viewport()->update(draggedItemsRect()); // erase the area
2822  draggedItemsPos = QPoint(-1, -1); // don't draw the dragged items
2824 }
2825 
2827 {
2828  if (e->source() != qq || !dd->canDecode(e))
2829  return false;
2830 
2831  // ignore by default
2832  e->ignore();
2833  // get old dragged items rect
2834  QRect itemsRect = this->itemsRect(draggedItems);
2835  viewport()->update(itemsRect.translated(draggedItemsDelta()));
2836  // update position
2837  draggedItemsPos = e->pos();
2838  // get new items rect
2839  viewport()->update(itemsRect.translated(draggedItemsDelta()));
2840  // set the item under the cursor to current
2842  if (movement() == QListView::Snap) {
2843  QRect rect(snapToGrid(e->pos() + offset()), gridSize());
2844  const QVector<QModelIndex> intersectVector = intersectingSet(rect);
2845  index = intersectVector.count() > 0 ? intersectVector.last() : QModelIndex();
2846  } else {
2847  index = qq->indexAt(e->pos());
2848  }
2849  // check if we allow drops here
2850  if (draggedItems.contains(index))
2851  e->accept(); // allow changing item position
2852  else if (dd->model->flags(index) & Qt::ItemIsDropEnabled)
2853  e->accept(); // allow dropping on dropenabled items
2854  else if (!index.isValid())
2855  e->accept(); // allow dropping in empty areas
2856 
2857  // the event was treated. do autoscrolling
2858  if (dd->shouldAutoScroll(e->pos()))
2859  dd->startAutoScroll();
2860  return true;
2861 }
2862 #endif // QT_NO_DRAGANDDROP
2863 
2865 {
2866  tree.create(qMax(rowCount - hiddenCount(), 0));
2867 }
2868 
2869 void QIconModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand)
2870 {
2871  if (scrollElasticBand)
2872  dd->scrollElasticBandBy(isRightToLeft() ? -dx : dx, dy);
2873 
2874  QCommonListViewBase::scrollContentsBy(dx, dy, scrollElasticBand);
2875  if (!draggedItems.isEmpty())
2876  viewport()->update(draggedItemsRect().translated(dx, dy));
2877 }
2878 
2879 void QIconModeViewBase::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
2880 {
2881  if (column() >= topLeft.column() && column() <= bottomRight.column()) {
2882  QStyleOptionViewItemV4 option = viewOptions();
2883  int bottom = qMin(items.count(), bottomRight.row() + 1);
2884  for (int row = topLeft.row(); row < bottom; ++row)
2885  items[row].resize(itemSize(option, modelIndex(row)));
2886  }
2887 }
2888 
2890 {
2891  if (info.last >= items.count()) {
2892  //first we create the items
2893  QStyleOptionViewItemV4 option = viewOptions();
2894  for (int row = items.count(); row <= info.last; ++row) {
2895  QSize size = itemSize(option, modelIndex(row));
2896  QListViewItem item(QRect(0, 0, size.width(), size.height()), row); // default pos
2897  items.append(item);
2898  }
2899  doDynamicLayout(info);
2900  }
2901  return (batchStartRow > max); // done
2902 }
2903 
2905 {
2906  if (index.isValid() && index.row() < items.count())
2907  return items.at(index.row());
2908  return QListViewItem();
2909 }
2910 
2912 {
2913  // remove all items from the tree
2914  int leafCount = tree.leafCount();
2915  for (int l = 0; l < leafCount; ++l)
2916  tree.leaf(l).clear();
2917  // we have to get the bounding rect of the items before we can initialize the tree
2919  // simple heuristics to get better bsp
2920  if (contents.height() / contents.width() >= 3)
2922  else if (contents.width() / contents.height() >= 3)
2924  // build tree for the bounding rect (not just the contents rect)
2925  tree.init(QRect(0, 0, contents.width(), contents.height()), type);
2926 }
2927 
2929 {
2930  int x, y;
2931  if (info.first == 0) {
2932  x = info.bounds.x() + info.spacing;
2933  y = info.bounds.y() + info.spacing;
2934  items.reserve(rowCount() - hiddenCount());
2935  } else {
2936  int idx = info.first - 1;
2937  while (idx > 0 && !items.at(idx).isValid())
2938  --idx;
2939  const QListViewItem &item = items.at(idx);
2940  x = item.x;
2941  y = item.y;
2942  if (info.flow == QListView::LeftToRight)
2943  x += (info.grid.isValid() ? info.grid.width() : item.w) + info.spacing;
2944  else
2945  y += (info.grid.isValid() ? info.grid.height() : item.h) + info.spacing;
2946  }
2947  return QPoint(x, y);
2948 }
2949 
2954 {
2955  const bool useItemSize = !info.grid.isValid();
2956  const QPoint topLeft = initDynamicLayout(info);
2957 
2958  int segStartPosition;
2959  int segEndPosition;
2960  int deltaFlowPosition;
2961  int deltaSegPosition;
2962  int deltaSegHint;
2963  int flowPosition;
2964  int segPosition;
2965 
2966  if (info.flow == QListView::LeftToRight) {
2967  segStartPosition = info.bounds.left() + info.spacing;
2968  segEndPosition = info.bounds.right();
2969  deltaFlowPosition = info.grid.width(); // dx
2970  deltaSegPosition = (useItemSize ? batchSavedDeltaSeg : info.grid.height()); // dy
2971  deltaSegHint = info.grid.height();
2972  flowPosition = topLeft.x();
2973  segPosition = topLeft.y();
2974  } else { // flow == QListView::TopToBottom
2975  segStartPosition = info.bounds.top() + info.spacing;
2976  segEndPosition = info.bounds.bottom();
2977  deltaFlowPosition = info.grid.height(); // dy
2978  deltaSegPosition = (useItemSize ? batchSavedDeltaSeg : info.grid.width()); // dx
2979  deltaSegHint = info.grid.width();
2980  flowPosition = topLeft.y();
2981  segPosition = topLeft.x();
2982  }
2983 
2984  if (moved.count() != items.count())
2985  moved.resize(items.count());
2986 
2987  QRect rect(QPoint(), topLeft);
2988  QListViewItem *item = 0;
2989  for (int row = info.first; row <= info.last; ++row) {
2990  item = &items[row];
2991  if (isHidden(row)) {
2992  item->invalidate();
2993  } else {
2994  // if we are not using a grid, we need to find the deltas
2995  if (useItemSize) {
2996  if (info.flow == QListView::LeftToRight)
2997  deltaFlowPosition = item->w + info.spacing;
2998  else
2999  deltaFlowPosition = item->h + info.spacing;
3000  } else {
3001  item->w = qMin<int>(info.grid.width(), item->w);
3002  item->h = qMin<int>(info.grid.height(), item->h);
3003  }
3004 
3005  // create new segment
3006  if (info.wrap
3007  && flowPosition + deltaFlowPosition > segEndPosition
3008  && flowPosition > segStartPosition) {
3009  flowPosition = segStartPosition;
3010  segPosition += deltaSegPosition;
3011  if (useItemSize)
3012  deltaSegPosition = 0;
3013  }
3014  // We must delay calculation of the seg adjustment, as this item
3015  // may have caused a wrap to occur
3016  if (useItemSize) {
3017  if (info.flow == QListView::LeftToRight)
3018  deltaSegHint = item->h + info.spacing;
3019  else
3020  deltaSegHint = item->w + info.spacing;
3021  deltaSegPosition = qMax(deltaSegPosition, deltaSegHint);
3022  }
3023 
3024  // set the position of the item
3025  // ### idealy we should have some sort of alignment hint for the item
3026  // ### (normally that would be a point between the icon and the text)
3027  if (!moved.testBit(row)) {
3028  if (info.flow == QListView::LeftToRight) {
3029  if (useItemSize) {
3030  item->x = flowPosition;
3031  item->y = segPosition;
3032  } else { // use grid
3033  item->x = flowPosition + ((deltaFlowPosition - item->w) / 2);
3034  item->y = segPosition;
3035  }
3036  } else { // TopToBottom
3037  if (useItemSize) {
3038  item->y = flowPosition;
3039  item->x = segPosition;
3040  } else { // use grid
3041  item->y = flowPosition + ((deltaFlowPosition - item->h) / 2);
3042  item->x = segPosition;
3043  }
3044  }
3045  }
3046 
3047  // let the contents contain the new item
3048  if (useItemSize)
3049  rect |= item->rect();
3050  else if (info.flow == QListView::LeftToRight)
3051  rect |= QRect(flowPosition, segPosition, deltaFlowPosition, deltaSegPosition);
3052  else // flow == TopToBottom
3053  rect |= QRect(segPosition, flowPosition, deltaSegPosition, deltaFlowPosition);
3054 
3055  // prepare for next item
3056  flowPosition += deltaFlowPosition; // current position + item width + gap
3057  }
3058  }
3059  batchSavedDeltaSeg = deltaSegPosition;
3060  batchStartRow = info.last + 1;
3061  bool done = (info.last >= rowCount() - 1);
3062  // resize the content area
3063  if (done || !info.bounds.contains(item->rect())) {
3064  contentsSize = rect.size();
3065  if (info.flow == QListView::LeftToRight)
3066  contentsSize.rheight() += info.spacing;
3067  else
3068  contentsSize.rwidth() += info.spacing;
3069  }
3070  if (rect.size().isEmpty())
3071  return;
3072  // resize tree
3073  int insertFrom = info.first;
3074  if (done || info.first == 0) {
3075  initBspTree(rect.size());
3076  insertFrom = 0;
3077  }
3078  // insert items in tree
3079  for (int row = insertFrom; row <= info.last; ++row)
3080  tree.insertLeaf(items.at(row).rect(), row);
3081  // if the new items are visble, update the viewport
3082  QRect changedRect(topLeft, rect.bottomRight());
3083  if (clipRect().intersects(changedRect))
3084  viewport()->update();
3085 }
3086 
3088 {
3089  QIconModeViewBase *that = const_cast<QIconModeViewBase*>(this);
3090  QBspTree::Data data(static_cast<void*>(that));
3092  that->interSectingVector = &res;
3093  that->tree.climbTree(area, &QIconModeViewBase::addLeaf, data);
3094  that->interSectingVector = 0;
3095  return res;
3096 }
3097 
3099 {
3101  QListViewItem item = indexToListViewItem(*it);
3102  QRect rect(item.x, item.y, item.w, item.h);
3103  for (; it != indexes.end(); ++it) {
3104  item = indexToListViewItem(*it);
3105  rect |= viewItemRect(item);
3106  }
3107  return rect;
3108 }
3109 
3111 {
3112  if (!item.isValid())
3113  return -1;
3114  int i = item.indexHint;
3115  if (i < items.count()) {
3116  if (items.at(i) == item)
3117  return i;
3118  } else {
3119  i = items.count() - 1;
3120  }
3121 
3122  int j = i;
3123  int c = items.count();
3124  bool a = true;
3125  bool b = true;
3126 
3127  while (a || b) {
3128  if (a) {
3129  if (items.at(i) == item) {
3130  items.at(i).indexHint = i;
3131  return i;
3132  }
3133  a = ++i < c;
3134  }
3135  if (b) {
3136  if (items.at(j) == item) {
3137  items.at(j).indexHint = j;
3138  return j;
3139  }
3140  b = --j > -1;
3141  }
3142  }
3143  return -1;
3144 }
3145 
3147  uint visited, QBspTree::Data data)
3148 {
3149  QListViewItem *vi;
3150  QIconModeViewBase *_this = static_cast<QIconModeViewBase *>(data.ptr);
3151  for (int i = 0; i < leaf.count(); ++i) {
3152  int idx = leaf.at(i);
3153  if (idx < 0 || idx >= _this->items.count())
3154  continue;
3155  vi = &_this->items[idx];
3156  Q_ASSERT(vi);
3157  if (vi->isValid() && vi->rect().intersects(area) && vi->visited != visited) {
3158  QModelIndex index = _this->dd->listViewItemToIndex(*vi);
3159  Q_ASSERT(index.isValid());
3160  _this->interSectingVector->append(index);
3161  vi->visited = visited;
3162  }
3163  }
3164 }
3165 
3167 {
3168  // does not impact on the bintree itself or the contents rect
3169  QListViewItem *item = &items[index];
3170  QRect rect = item->rect();
3171 
3172  // move the item without removing it from the tree
3173  tree.removeLeaf(rect, index);
3174  item->move(dest);
3175  tree.insertLeaf(QRect(dest, rect.size()), index);
3176 
3177  // resize the contents area
3178  contentsSize = (QRect(QPoint(0, 0), contentsSize)|QRect(dest, rect.size())).size();
3179 
3180  // mark the item as moved
3181  if (moved.count() != items.count())
3182  moved.resize(items.count());
3183  moved.setBit(index, true);
3184 }
3185 
3187 {
3188  int x = pos.x() - (pos.x() % gridSize().width());
3189  int y = pos.y() - (pos.y() % gridSize().height());
3190  return QPoint(x, y);
3191 }
3192 
3194 {
3195  if (movement() == QListView::Snap) {
3196  QPoint snapdelta = QPoint((offset().x() % gridSize().width()),
3197  (offset().y() % gridSize().height()));
3198  return snapToGrid(draggedItemsPos + snapdelta) - snapToGrid(pressedPosition()) - snapdelta;
3199  }
3200  return draggedItemsPos - pressedPosition();
3201 }
3202 
3204 {
3205  QRect rect = itemsRect(draggedItems);
3206  rect.translate(draggedItemsDelta());
3207  return rect;
3208 }
3209 
3211 {
3212  if (dx > 0) // right
3214  else if (dx < 0) // left
3216  if (dy > 0) // down
3218  else if (dy < 0) // up
3220 }
3221 
3223 {
3224  tree.destroy();
3225  items.clear();
3226  moved.clear();
3227  batchStartRow = 0;
3228  batchSavedDeltaSeg = 0;
3229 }
3230 
3232 {
3233  QRect bounding;
3234  for (int i = 0; i < items.count(); ++i)
3235  bounding |= items.at(i).rect();
3236  contentsSize = bounding.size();
3237 }
3238 
3242 void QListView::currentChanged(const QModelIndex &current, const QModelIndex &previous)
3243 {
3244 #ifndef QT_NO_ACCESSIBILITY
3245  if (QAccessible::isActive()) {
3246  if (current.isValid()) {
3247  int entry = visualIndex(current) + 1;
3248 #ifdef Q_WS_X11
3250 #else
3252 #endif
3253  }
3254  }
3255 #endif
3256  QAbstractItemView::currentChanged(current, previous);
3257 }
3258 
3263  const QItemSelection &deselected)
3264 {
3265 #ifndef QT_NO_ACCESSIBILITY
3266  if (QAccessible::isActive()) {
3267  // ### does not work properly for selection ranges.
3268  QModelIndex sel = selected.indexes().value(0);
3269  if (sel.isValid()) {
3270  int entry = visualIndex(sel) + 1;
3271 #ifdef Q_WS_X11
3273 #else
3275 #endif
3276  }
3277  QModelIndex desel = deselected.indexes().value(0);
3278  if (desel.isValid()) {
3279  int entry = visualIndex(desel) + 1;
3280 #ifdef Q_WS_X11
3282 #else
3284 #endif
3285  }
3286  }
3287 #endif
3288  QAbstractItemView::selectionChanged(selected, deselected);
3289 }
3290 
3292 {
3293  Q_D(const QListView);
3294  d->executePostedLayout();
3295  QListViewItem itm = d->indexToListViewItem(index);
3296  int visualIndex = d->commonListView->itemIndex(itm);
3297  for (int row = 0; row <= index.row() && visualIndex >= 0; row++) {
3298  if (d->isHidden(row))
3299  visualIndex--;
3300  }
3301  return visualIndex;
3302 }
3303 
3305 
3306 #endif // QT_NO_LISTVIEW
void doStaticLayout(const QListViewLayoutInfo &info)
Definition: qlistview.cpp:2421
void prepareItemsLayout()
Definition: qlistview.cpp:1732
void dragMoveEvent(QDragMoveEvent *e)
Definition: qlistview.cpp:2027
QListView(QWidget *parent=0)
Creates a new QListView with the given parent to view a model.
Definition: qlistview.cpp:185
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
virtual bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max)=0
double d
Definition: qnumeric_p.h:62
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
void setSpacing(int space)
Definition: qlistview.cpp:397
int horizontalOffset() const
Reimplemented Function
Definition: qlistview.cpp:1127
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
This slot is called when rows are about to be removed.
bool enabled
whether the widget is enabled
Definition: qwidget.h:157
void dragLeaveEvent(QDragLeaveEvent *e)
Reimplemented Function
Definition: qlistview.cpp:908
bool filterDragLeaveEvent(QDragLeaveEvent *)
Definition: qlistview.cpp:2819
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
void setMovement(Movement movement)
Definition: qlistview.cpp:236
int spacing() const
The QAbstractItemDelegate class is used to display and edit data items from a model.
void setSelectionMode(QAbstractItemView::SelectionMode mode)
The QItemSelectionModel class keeps track of a view&#39;s selected items.
QPoint snapToGrid(const QPoint &pos) const
Definition: qlistview.cpp:3186
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
Merges the other selection with this QItemSelection using the command given.
int type
Definition: qmetatype.cpp:239
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:267
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
void setRowHidden(int row, bool hide)
If hide is true, the given row will be hidden; otherwise the row will be shown.
Definition: qlistview.cpp:573
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
virtual QAbstractItemView::DropIndicatorPosition position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setPixmap(const QPixmap &)
Sets pixmap as the pixmap used to represent the data in a drag and drop operation.
Definition: qdrag.cpp:166
The QDrag class provides support for MIME-based drag and drop data transfer.
Definition: qdrag.h:61
EventRef event
QSize size() const
void setMimeData(QMimeData *data)
Sets the data to be sent to the given MIME data.
Definition: qdrag.cpp:142
void reset()
Definition: qlistview.cpp:704
virtual int horizontalScrollToValue(int index, QListView::ScrollHint hint, bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const
Definition: qlistview.cpp:1970
virtual QStyleOptionViewItem viewOptions() const
Returns a QStyleOptionViewItem structure populated with the view&#39;s palette, font, state...
QRect mapToViewport(const QRect &rect, bool extend=true) const
Definition: qlistview.cpp:1799
void moveLeft(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s left edge at the given x coordinate...
Definition: qrect.h:350
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
QModelIndex bottomRight() const
Returns the index for the item located at the bottom-right corner of the selection range...
void scrollContentsBy(int dx, int dy, bool scrollElasticBand)
Definition: qlistview.cpp:2869
QVector< QModelIndex > intersectingSet(const QRect &area) const
Definition: qlistview.cpp:3087
void removeHiddenRow(int row)
Definition: qlistview.cpp:2737
void mouseMoveEvent(QMouseEvent *event)
This function is called with the given event when a mouse move event is sent to the widget...
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
#define it(className, varName)
virtual void removeHiddenRow(int row)
Definition: qlistview.cpp:1918
void setBatchSize(int batchSize)
Definition: qlistview.cpp:424
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const
Reimplemented Function
Definition: qlistview.cpp:681
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const =0
This pure abstract function must be reimplemented if you want to provide custom rendering.
int itemIndex(const QListViewItem &item) const
Definition: qlistview.cpp:3110
QItemSelection selection(const QRect &rect) const
Definition: qlistview.cpp:1862
void timerEvent(QTimerEvent *e)
Reimplemented Function
Definition: qlistview.cpp:846
bool isVisible() const
Definition: qwidget.h:1005
QListViewItem indexToListViewItem(const QModelIndex &index) const
Definition: qlistview.cpp:1791
bool isValid() const
Returns true if the selection range is valid; otherwise returns false.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
bool filterDropEvent(QDropEvent *e)
Definition: qlistview.cpp:2776
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
Reimplemented Function
Definition: qlistview.cpp:1297
bool isSelectionRectVisible() const
Definition: qlistview.cpp:1684
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)
Reimplemented Function
Definition: qlistview.cpp:597
QListViewItem indexToListViewItem(const QModelIndex &index) const
Definition: qlistview.cpp:2904
QRect clipRect() const
Definition: qwidget.cpp:1997
bool wordWrap() const
QVector< QListViewItem > items
Definition: qlistview_p.h:256
virtual int verticalScrollToValue(int index, QListView::ScrollHint hint, bool above, bool below, const QRect &area, const QRect &rect) const
Definition: qlistview.cpp:1951
int horizontalScrollToValue(int index, QListView::ScrollHint hint, bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const
Definition: qlistview.cpp:2270
static void addLeaf(QVector< int > &leaf, const QRect &area, uint visited, QBspTree::Data data)
Definition: qlistview.cpp:3146
QRect itemsRect(const QVector< QModelIndex > &indexes) const
Definition: qlistview.cpp:3098
QSize contentsSize() const
Definition: qlistview.cpp:759
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
QListView::ViewMode viewMode
Definition: qlistview_p.h:413
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
Position decorationPosition
the position of the decoration for the item
Definition: qstyleoption.h:550
QRect normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:322
void setResizeMode(ResizeMode mode)
Definition: qlistview.cpp:337
void startDrag(Qt::DropActions supportedActions)
Reimplemented Function
Definition: qlistview.cpp:926
void moveRight(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s right edge at the given x coordinate...
Definition: qrect.h:356
int verticalOffset() const
Reimplemented Function
Definition: qlistview.cpp:1135
The QItemSelectionRange class manages information about a range of selected items in a model...
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
void updateContentsSize()
Definition: qlistview.cpp:3231
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
void accept()
Calls QDropEvent::accept().
Definition: qevent.h:539
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
QModelIndex modelIndex(int row) const
Definition: qlistview_p.h:377
QRect rect() const
Definition: qlistview_p.h:97
void timerEvent(QTimerEvent *event)
This function is called with the given event when a timer event is sent to the widget.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
virtual QRect mapToViewport(const QRect &rect) const
Definition: qlistview_p.h:140
Qt::ScrollBarPolicy horizontalScrollBarPolicy() const
void paintEvent(QPaintEvent *e)
Reimplemented Function
Definition: qlistview.cpp:996
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int perItemScrollToValue(int index, int value, int height, QAbstractItemView::ScrollHint hint, Qt::Orientation orientation, bool wrap, int extent) const
Definition: qlistview.cpp:2634
bool filterStartDrag(Qt::DropActions)
Definition: qlistview.cpp:2745
void updateVerticalScrollBar(const QSize &step)
Definition: qlistview.cpp:2161
DropIndicatorPosition
This enum indicates the position of the drop indicator in relation to the index at the current mouse ...
QAbstractItemView::ScrollMode horizontalScrollMode
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
Qt::DropAction exec(Qt::DropActions supportedActions=Qt::MoveAction)
Starts the drag and drop operation and returns a value indicating the requested drop action when it i...
Definition: qdrag.cpp:243
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
bool filterDragMoveEvent(QDragMoveEvent *)
Definition: qlistview.cpp:2826
bool hasFocus() const
Definition: qwidget.cpp:6583
QModelIndex closestIndex(const QRect &target, const QVector< QModelIndex > &candidates) const
Definition: qlistview.cpp:1811
virtual void doItemsLayout()
This function is intended to lay out the items in the view.
bool isIndexHidden(const QModelIndex &index) const
Reimplemented Function
Definition: qlistview.cpp:1568
void initBspTree(const QSize &contents)
Definition: qlistview.cpp:2911
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
int verticalScrollToValue(int index, QListView::ScrollHint hint, bool above, bool below, const QRect &area, const QRect &rect) const
Definition: qlistview.cpp:2201
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
int horizontalOffset() const
Definition: qlistview.cpp:2229
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isValid() const
Definition: qlistview_p.h:86
void moveBottom(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s bottom edge at the given y coordinate...
Definition: qrect.h:362
#define Q_D(Class)
Definition: qglobal.h:2482
QSize gridSize() const
Definition: qlistview_p.h:369
bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max)
Definition: qlistview.cpp:2889
int height() const
QVector< QModelIndex > intersectingSet(const QRect &area, bool doLayout=true) const
Definition: qlistview_p.h:314
void dragMoveEvent(QDragMoveEvent *event)
This function is called continuously with the given event during a drag and drop operation over the w...
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void setUniformItemSizes(bool enable)
Definition: qlistview.cpp:1615
QModelIndex indexAt(const QPoint &p) const
Reimplemented Function
Definition: qlistview.cpp:1112
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
Reimplemented Function
Definition: qlistview.cpp:789
void setWordWrap(bool on)
Definition: qlistview.cpp:1644
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setRange(int min, int max)
Sets the slider&#39;s minimum to min and its maximum to max.
QRect rectForIndex(const QModelIndex &index) const
Returns the rectangle of the item at position index in the model.
Definition: qlistview.cpp:1265
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QStyle * style() const
Definition: qwidget.cpp:2742
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
virtual int horizontalOffset() const
Definition: qlistview.cpp:1965
#define Q_Q(Class)
Definition: qglobal.h:2483
The QStyleOptionViewItemV2 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:562
ColorGroup
Definition: qpalette.h:92
bool isHidden(int row) const
Definition: qlistview_p.h:378
bool event(QEvent *e)
Reimplemented Function
Definition: qlistview.cpp:1693
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Definition: qlistview.cpp:2879
void currentChanged(const QModelIndex &current, const QModelIndex &previous)
Reimplemented Function
Definition: qlistview.cpp:3242
QWidgetData data
Definition: qwidget_p.h:755
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void dropEvent(QDropEvent *event)
This function is called with the given event when a drop event occurs over the widget.
bool focus
whether this widget (or its focus proxy) has the keyboard input focus
Definition: qwidget.h:188
QWidget * viewport() const
Returns the viewport widget.
QModelIndex topLeft() const
Returns the index for the item located at the top-left corner of the selection range.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
void scrollContentsBy(int dx, int dy, bool scrollElasticBand)
Definition: qlistview.cpp:2291
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
LayoutMode layoutMode() const
int width() const
Returns the width.
Definition: qsize.h:126
void mouseMoveEvent(QMouseEvent *e)
Reimplemented Function
Definition: qlistview.cpp:812
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QListView::Flow flow
Definition: qlistview_p.h:113
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QAbstractItemView::DropIndicatorPosition position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const
Definition: qlistview.cpp:2001
virtual QAbstractItemView::DropIndicatorPosition position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const
Definition: qlistview.cpp:1892
ViewItemFeatures features
a bitwise OR of the features that describe this view item
Definition: qstyleoption.h:577
bool isAccepted() const
Definition: qcoreevent.h:307
void dragMoveEvent(QDragMoveEvent *e)
Reimplemented Function
Definition: qlistview.cpp:893
static bool isEmpty(const char *str)
QRect viewItemRect(const QListViewItem &item) const
Definition: qlistview_p.h:331
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
virtual bool dropOn(QDropEvent *event, int *row, int *col, QModelIndex *index)
If the event hasn&#39;t already been accepted, determines the index to drop on.
friend class QListModeViewBase
QAbstractItemView::ScrollMode verticalScrollMode
bool contains(const T &value) const
Definition: qset.h:91
virtual bool filterDragLeaveEvent(QDragLeaveEvent *)
Definition: qlistview_p.h:152
QList< T > toList() const
Definition: qset.h:296
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
void dataChanged(const QModelIndex &, const QModelIndex &)
Definition: qlistview.cpp:2576
void setRootIndex(const QModelIndex &index)
Definition: qlistview.cpp:715
QItemSelectionModel * selectionModel() const
Returns the current selection model.
static const QCssKnownValue positions[NumKnownPositionModes - 1]
Definition: qcssparser.cpp:329
QPoint draggedItemsDelta() const
Definition: qlistview.cpp:3193
bool isSelected(const QModelIndex &index) const
Returns true if the given model item index is selected.
int width() const
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
void resizeContents(int width, int height)
Resize the internal contents to width and height and set the scroll bar ranges accordingly.
Definition: qlistview.cpp:750
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:261
int row() const
Returns the row this model index refers to.
void move(const QPoint &position)
Definition: qlistview_p.h:92
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
int visualIndex(const QModelIndex &index) const
Definition: qlistview.cpp:3291
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
QRect mapToViewport(const QRect &rect) const
Definition: qlistview.cpp:2582
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
Q_CORE_EXPORT void qWarning(const char *,...)
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
Flow flow() const
bool showDecorationSelected
whether the decoration should be highlighted on selected items
Definition: qstyleoption.h:553
QRect draggedItemsRect() const
Definition: qlistview.cpp:3203
unsigned int uint
Definition: qglobal.h:996
bool isWrapping() const
Definition: qlistview_p.h:371
void setPositionForIndex(const QPoint &position, const QModelIndex &index)
Definition: qlistview.cpp:2717
static int distance(QWidget *source, QWidget *target, QAccessible::RelationFlag relation)
const QSize & oldSize() const
Returns the old size of the widget.
Definition: qevent.h:356
virtual void reset()
Reset the internal state of the view.
QModelIndex currentIndex() const
Returns the model index of the current item.
QSize itemSize(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: qlistview.cpp:1847
bool doItemsLayout(int num)
Definition: qlistview.cpp:1763
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
State
Describes the different states the view can be in.
void rowsInserted(const QModelIndex &parent, int start, int end)
Reimplemented Function
Definition: qlistview.cpp:777
DropAction
Definition: qnamespace.h:1597
void clearPropertyFlags()
Clears the QListView-specific property flags.
Definition: qlistview.cpp:554
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
void scrollElasticBandBy(int dx, int dy)
Definition: qlistview.cpp:3210
void climbTree(const QRect &rect, callback *function, QBspTreeData data)
Definition: qbsptree.cpp:71
void select(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Adds the items in the range that extends from the top-left model item, specified by the topLeft index...
int verticalScrollToValue(const QModelIndex &index, const QRect &rect, QListView::ScrollHint hint) const
Definition: qlistview.cpp:631
void show()
Shows the widget and its child widgets.
void setPositionForIndex(const QPoint &position, const QModelIndex &index)
Sets the contents position of the item at index in the model to the given position.
Definition: qlistview.cpp:1281
void setDragEnabled(bool enable)
bool opaque
whether the rubber band is required to be drawn in an opaque style
Definition: qstyleoption.h:676
void doItemsLayout()
Layout the items according to the flow and wrapping properties.
Definition: qlistview.cpp:1507
The QStyleOptionRubberBand class is used to describe the parameters needed for drawing a rubber band...
Definition: qstyleoption.h:669
void setModelColumn(int column)
Definition: qlistview.cpp:1586
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
bool acceptDrops
whether drop events are enabled for this widget
Definition: qwidget.h:197
QRect rect() const
void internalDrop(QDropEvent *e)
Called whenever items from the view is dropped on the viewport.
Definition: qlistview.cpp:941
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
void selectAll(QItemSelectionModel::SelectionFlags command)
Definition: qlistview.cpp:641
bool uniformItemSizes() const
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
Reimplemented Function
Definition: qlistview.cpp:1143
void hide()
Hides the widget.
Definition: qwidget.h:501
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
virtual int verticalOffset() const
Definition: qlistview_p.h:142
The QAbstractItemModel class provides the abstract interface for item model classes.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Reimplemented Function
Definition: qlistview.cpp:768
int batchSize() const
Qt::ItemFlags flags() const
Returns the flags for the item referred to by the index.
static bool isActive()
Returns true if an accessibility implementation has been requested during the runtime of the applicat...
int spacing() const
Definition: qlistview_p.h:373
void setWrapping(bool enable)
Definition: qlistview.cpp:308
virtual void setRowCount(int)=0
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
QPoint initDynamicLayout(const QListViewLayoutInfo &info)
Definition: qlistview.cpp:2928
QPersistentModelIndex root
virtual void appendHiddenRow(int row)
Definition: qlistview.cpp:1913
QListView::Movement movement
Definition: qlistview_p.h:410
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
QList< QModelIndex > QModelIndexList
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
void moveItem(int index, const QPoint &dest)
Definition: qlistview.cpp:3166
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This slot is called when the selection is changed.
Qt::ScrollBarPolicy verticalScrollBarPolicy() const
The QAbstractItemView class provides the basic functionality for item view classes.
QPoint initStaticLayout(const QListViewLayoutInfo &info)
Definition: qlistview.cpp:2385
QListViewPrivate * dd
Definition: qlistview_p.h:192
void setY(int y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qpoint.h:137
QSize gridSize() const
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
The QItemSelection class manages information about selected items in a model.
QRect visualRect(const QModelIndex &index) const
Reimplemented Function
Definition: qlistview.cpp:588
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
void setAcceptDrops(bool on)
Definition: qwidget.cpp:3534
The QListView class provides a list or icon view onto a model.
Definition: qlistview.h:57
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
QVector< QModelIndex > intersectingSet(const QRect &area) const
Finds the set of items intersecting with area.
Definition: qlistview.cpp:2532
QCommonListViewBase * commonListView
Definition: qlistview_p.h:401
QListViewItem indexToListViewItem(const QModelIndex &index) const
Definition: qlistview.cpp:2349
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
void setViewMode(ViewMode mode)
Definition: qlistview.cpp:490
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Reimplemented Function
Definition: qlistview.cpp:3262
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
State
Definition: qaudio.h:59
bool dropOn(QDropEvent *event, int *row, int *col, QModelIndex *index)
If the event hasn&#39;t already been accepted, determines the index to drop on.
Definition: qlistview.cpp:1900
void appendHiddenRow(int row)
Definition: qlistview.cpp:2730
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
The Flow item arranges its children side by side, wrapping as necessary.
void resizeEvent(QResizeEvent *event)
This function is called with the given event when a resize event is sent to the widget.
const QSize & size() const
Returns the new size of the widget.
Definition: qevent.h:355
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
Movement movement() const
QWidget * source() const
If the source of the drag operation is a widget in this application, this function returns that sourc...
Definition: qevent.cpp:2739
~QListView()
Destroys the view.
Definition: qlistview.cpp:211
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
Qt::Alignment displayAlignment
the alignment of the display value for the item
Definition: qstyleoption.h:547
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
The QModelIndex class is used to locate data in a data model.
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
QSize decorationSize
the size of the decoration for the item
Definition: qstyleoption.h:551
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
ResizeMode resizeMode() const
QAbstractItemDelegate * delegateForIndex(const QModelIndex &index) const
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
int & rheight()
Returns a reference to the height.
Definition: qsize.h:144
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
void invalidate()
Definition: qlistview_p.h:88
int height() const
Returns the height.
Definition: qsize.h:129
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QVector< QModelIndex > * interSectingVector
Definition: qlistview_p.h:263
QModelIndexList selectedIndexes() const
Reimplemented Function
Definition: qlistview.cpp:1482
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
QFactoryLoader * l
QRubberBand::Shape shape
the shape of the rubber band
Definition: qstyleoption.h:675
int verticalOffset() const
Definition: qlistview.cpp:2250
int batchStartRow() const
Definition: qlistview_p.h:321
State state() const
Returns the item view&#39;s state.
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
quint16 index
void mouseReleaseEvent(QMouseEvent *event)
This function is called with the given event when a mouse button is released, after a mouse press eve...
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows are inserted.
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This slot is called when items are changed in the model.
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
virtual void updateGeometries()
Updates the geometry of the child widgets of the view.
void setFlow(Flow flow)
Definition: qlistview.cpp:276
void scrollContentsBy(int dx, int dy)
Scroll the view contents by dx and dy.
Definition: qlistview.cpp:734
static QFixed flowPosition(const QTextFrame::iterator it)
bool isNull() const
Returns true if both the width and height is 0; otherwise returns false.
Definition: qsize.h:117
int perItemScrollingPageSteps(int length, int bounds, bool wrap) const
Definition: qlistview.cpp:2599
void setRowCount(int rowCount)
Definition: qlistview.cpp:2864
virtual void updateVerticalScrollBar(const QSize &step)
Definition: qlistview.cpp:1939
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setHotSpot(const QPoint &hotspot)
Sets the position of the hot spot relative to the top-left corner of the pixmap used to the point spe...
Definition: qdrag.cpp:189
bool isRightToLeft() const
Definition: qwidget.h:428
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
void updateHorizontalScrollBar(const QSize &step)
Definition: qlistview.cpp:2182
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
CursorAction
This enum describes the different ways to navigate between items,.
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
void setGridSize(const QSize &size)
Definition: qlistview.cpp:458
QModelIndexList indexes() const
Returns a list of model indexes that correspond to the selected items.
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
Definition: qstyleoption.h:539
void setSelectionRectVisible(bool show)
Definition: qlistview.cpp:1677
bool dropOn(QDropEvent *event, int *row, int *col, QModelIndex *index)
If the event hasn&#39;t already been accepted, determines the index to drop on.
Definition: qlistview.cpp:2108
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top edge at the given y coordinate.
Definition: qrect.h:353
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
void resizeEvent(QResizeEvent *e)
Reimplemented Function
Definition: qlistview.cpp:862
const QRect & rect() const
Returns the rectangle that needs to be updated.
Definition: qevent.h:305
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
const QRect & geometry() const
bool isWrapping() const
QListView::Flow flow
Definition: qlistview_p.h:409
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
virtual void clear()=0
QAbstractItemModel * model() const
Returns the model that this view is presenting.
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
static const KeyPair *const end
void dragLeaveEvent(QDragLeaveEvent *event)
This function is called when the item being dragged leaves the view.
QModelIndex listViewItemToIndex(const QListViewItem &item) const
Definition: qlistview_p.h:335
Orientation
Definition: qnamespace.h:174
bool event(QEvent *event)
Reimplemented Function
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134
void doDynamicLayout(const QListViewLayoutInfo &info)
Definition: qlistview.cpp:2953
void updateGeometries()
Reimplemented Function
Definition: qlistview.cpp:1531
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QAbstractItemModel * model
QRegion visualRegionForSelection(const QItemSelection &selection) const
Since 4.
Definition: qlistview.cpp:1441
void setState(State state)
Sets the item view&#39;s state to the given state.
void mouseReleaseEvent(QMouseEvent *e)
Reimplemented Function
Definition: qlistview.cpp:832
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
#define INT_MAX
ViewMode viewMode() const
QStyleOptionViewItem viewOptions() const
Reimplemented Function
Definition: qlistview.cpp:967
void setLayoutMode(LayoutMode mode)
Definition: qlistview.cpp:366
void ignore()
Calls QDropEvent::ignore().
Definition: qevent.h:540
void internalDrag(Qt::DropActions supportedActions)
Called whenever the user starts dragging items and the items are movable, enabling internal dragging ...
Definition: qlistview.cpp:956
int modelColumn() const
void paintDragDrop(QPainter *painter)
Definition: qlistview.cpp:1924
bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max)
Definition: qlistview.cpp:2337
virtual QListViewItem indexToListViewItem(const QModelIndex &index) const =0
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
const QPoint & pos() const
Returns the position where the drop was made.
Definition: qevent.h:486
int & rwidth()
Returns a reference to the width.
Definition: qsize.h:141
void dropEvent(QDropEvent *e)
Reimplemented Function
Definition: qlistview.cpp:917
virtual void updateHorizontalScrollBar(const QSize &step)
Definition: qlistview.cpp:1932
int column() const
Returns the column this model index refers to.
virtual void startDrag(Qt::DropActions supportedActions)
Starts a drag by calling drag->exec() using the given supportedActions.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static int area(const QSize &s)
Definition: qicon.cpp:155
int horizontalScrollToValue(const QModelIndex &index, const QRect &rect, QListView::ScrollHint hint) const
Definition: qlistview.cpp:617
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
bool isRowHidden(int row) const
Returns true if the row is hidden; otherwise returns false.
Definition: qlistview.cpp:563
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
virtual void scrollContentsBy(int dx, int dy, bool scrollElasticBand)
Definition: qlistview.cpp:1946
QSize contentsSize() const
Definition: qlistview_p.h:322
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480