Qt 4.8
Public Functions | Public Variables | Private Functions | List of all members
QListModeViewBase Class Reference

#include <qlistview_p.h>

Inheritance diagram for QListModeViewBase:
QCommonListViewBase

Public Functions

void clear ()
 
void dataChanged (const QModelIndex &, const QModelIndex &)
 
bool doBatchedItemLayout (const QListViewLayoutInfo &info, int max)
 
void dragMoveEvent (QDragMoveEvent *e)
 
bool dropOn (QDropEvent *event, int *row, int *col, QModelIndex *index)
 If the event hasn't already been accepted, determines the index to drop on. More...
 
int horizontalOffset () const
 
int horizontalScrollToValue (int index, QListView::ScrollHint hint, bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const
 
QListViewItem indexToListViewItem (const QModelIndex &index) const
 
QVector< QModelIndexintersectingSet (const QRect &area) const
 Finds the set of items intersecting with area. More...
 
int itemIndex (const QListViewItem &item) const
 
QRect mapToViewport (const QRect &rect) const
 
QAbstractItemView::DropIndicatorPosition position (const QPoint &pos, const QRect &rect, const QModelIndex &idx) const
 
 QListModeViewBase (QListView *q, QListViewPrivate *d)
 
void scrollContentsBy (int dx, int dy, bool scrollElasticBand)
 
void setRowCount (int rowCount)
 
void updateHorizontalScrollBar (const QSize &step)
 
void updateVerticalScrollBar (const QSize &step)
 
int verticalOffset () const
 
int verticalScrollToValue (int index, QListView::ScrollHint hint, bool above, bool below, const QRect &area, const QRect &rect) const
 
- Public Functions inherited from QCommonListViewBase
virtual void appendHiddenRow (int row)
 
QSize cachedItemSize () const
 
QRect clipRect () const
 
int column () const
 
QAbstractItemDelegatedelegate (const QModelIndex &idx) const
 
virtual bool filterDragLeaveEvent (QDragLeaveEvent *)
 
virtual bool filterDragMoveEvent (QDragMoveEvent *)
 
virtual bool filterDropEvent (QDropEvent *)
 
virtual bool filterStartDrag (Qt::DropActions)
 
QListView::Flow flow () const
 
QSize gridSize () const
 
int hiddenCount () const
 
QScrollBarhorizontalScrollBar () const
 
QListView::ScrollMode horizontalScrollMode () const
 
bool isHidden (int row) const
 
bool isRightToLeft () const
 
bool isWrapping () const
 
QSize itemSize (const QStyleOptionViewItemV2 &opt, const QModelIndex &idx) const
 
QModelIndex modelIndex (int row) const
 
QListView::Movement movement () const
 
QPoint offset () const
 
void paintDragDrop (QPainter *painter)
 
QPoint pressedPosition () const
 
 QCommonListViewBase (QListView *q, QListViewPrivate *d)
 
virtual void removeHiddenRow (int row)
 
int rowCount () const
 
virtual void setPositionForIndex (const QPoint &, const QModelIndex &)
 
int spacing () const
 
bool uniformItemSizes () const
 
QScrollBarverticalScrollBar () const
 
QListView::ScrollMode verticalScrollMode () const
 
QRect viewItemRect (const QListViewItem &item) const
 
QStyleOptionViewItemV4 viewOptions () const
 
QWidgetviewport () const
 
virtual ~QCommonListViewBase ()
 

Public Variables

int batchSavedPosition
 
QVector< int > flowPositions
 
QVector< int > scrollValueMap
 
QVector< int > segmentExtents
 
QVector< int > segmentPositions
 
QVector< int > segmentStartRows
 
- Public Variables inherited from QCommonListViewBase
int batchSavedDeltaSeg
 
int batchStartRow
 
QSize contentsSize
 
QListViewPrivatedd
 
QListViewqq
 

Private Functions

void doStaticLayout (const QListViewLayoutInfo &info)
 
QPoint initStaticLayout (const QListViewLayoutInfo &info)
 
int perItemScrollingPageSteps (int length, int bounds, bool wrap) const
 
int perItemScrollToValue (int index, int value, int height, QAbstractItemView::ScrollHint hint, Qt::Orientation orientation, bool wrap, int extent) const
 

Detailed Description

Definition at line 199 of file qlistview_p.h.

Constructors and Destructors

◆ QListModeViewBase()

QListModeViewBase::QListModeViewBase ( QListView q,
QListViewPrivate d 
)
inline

Definition at line 202 of file qlistview_p.h.

202 : QCommonListViewBase(q, d) {}
QCommonListViewBase(QListView *q, QListViewPrivate *d)
Definition: qlistview_p.h:123

Functions

◆ clear()

void QListModeViewBase::clear ( )
virtual

Implements QCommonListViewBase.

Definition at line 2702 of file qlistview.cpp.

2703 {
2704  flowPositions.clear();
2708  batchSavedPosition = 0;
2709  batchStartRow = 0;
2710  batchSavedDeltaSeg = 0;
2711 }
QVector< int > segmentStartRows
Definition: qlistview_p.h:206
QVector< int > segmentPositions
Definition: qlistview_p.h:205
QVector< int > flowPositions
Definition: qlistview_p.h:204
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QVector< int > segmentExtents
Definition: qlistview_p.h:207

◆ dataChanged()

void QListModeViewBase::dataChanged ( const QModelIndex ,
const QModelIndex  
)
virtual

Implements QCommonListViewBase.

Definition at line 2576 of file qlistview.cpp.

2577 {
2579 }
void doDelayedItemsLayout(int delay=0)
QListViewPrivate * dd
Definition: qlistview_p.h:192

◆ doBatchedItemLayout()

bool QListModeViewBase::doBatchedItemLayout ( const QListViewLayoutInfo info,
int  max 
)
virtual

Implements QCommonListViewBase.

Definition at line 2337 of file qlistview.cpp.

2338 {
2339  doStaticLayout(info);
2340  if (batchStartRow > max) { // stop items layout
2344  return true; // done
2345  }
2346  return false; // not done
2347 }
void doStaticLayout(const QListViewLayoutInfo &info)
Definition: qlistview.cpp:2421
QVector< int > segmentStartRows
Definition: qlistview_p.h:206
QVector< int > segmentPositions
Definition: qlistview_p.h:205
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< int > flowPositions
Definition: qlistview_p.h:204
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342

◆ doStaticLayout()

void QListModeViewBase::doStaticLayout ( const QListViewLayoutInfo info)
private
Warning
This function is not part of the public interface.

Definition at line 2421 of file qlistview.cpp.

2422 {
2423  const bool useItemSize = !info.grid.isValid();
2424  const QPoint topLeft = initStaticLayout(info);
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
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
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);
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 }
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:267
QVector< int > segmentStartRows
Definition: qlistview_p.h:206
QVector< int > segmentPositions
Definition: qlistview_p.h:205
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< int > flowPositions
Definition: qlistview_p.h:204
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
int width() const
Returns the width.
Definition: qsize.h:126
QListView::Flow flow
Definition: qlistview_p.h:113
bool isHidden(int row) const
Definition: qlistview_p.h:480
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
QSize itemSize(const QStyleOptionViewItemV2 &opt, const QModelIndex &idx) const
Definition: qlistview_p.h:474
QVector< int > scrollValueMap
Definition: qlistview_p.h:208
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
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QVector< int > segmentExtents
Definition: qlistview_p.h:207
QPoint initStaticLayout(const QListViewLayoutInfo &info)
Definition: qlistview.cpp:2385
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
QModelIndex modelIndex(int row) const
Definition: qlistview_p.h:464
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QRect clipRect() const
Definition: qlistview_p.h:470
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
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
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
static QFixed flowPosition(const QTextFrame::iterator it)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
#define INT_MAX
QWidget * viewport() const
Definition: qlistview_p.h:469
QStyleOptionViewItemV4 viewOptions() const
Definition: qlistview_p.h:468

◆ dragMoveEvent()

void QListModeViewBase::dragMoveEvent ( QDragMoveEvent e)

Definition at line 2027 of file qlistview.cpp.

2028 {
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();
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 }
QAbstractItemView::DropIndicatorPosition dropIndicatorPosition
QPersistentModelIndex hover
EventRef event
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool isIndexDropEnabled(const QModelIndex &index) const
DragDropMode dragDropMode() const
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int horizontalOffset() const
Definition: qlistview.cpp:2229
QVector< QModelIndex > intersectingSet(const QRect &area, bool doLayout=true) const
Definition: qlistview_p.h:314
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QAbstractItemView::DropIndicatorPosition position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const
Definition: qlistview.cpp:2001
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
bool canDecode(QDropEvent *e) const
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int spacing() const
Definition: qlistview_p.h:373
QListViewPrivate * dd
Definition: qlistview_p.h:192
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
QRect visualRect(const QModelIndex &index) const
Reimplemented Function
Definition: qlistview.cpp:588
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
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
The QModelIndex class is used to locate data in a data model.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int verticalOffset() const
Definition: qlistview.cpp:2250
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
quint16 index
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QModelIndex rootIndex() const
Returns the model index of the model&#39;s root item.
bool droppingOnItself(QDropEvent *event, const QModelIndex &index)
Return true if this is a move from ourself and index is a child of the selection that is being moved...
bool shouldAutoScroll(const QPoint &pos) const

◆ dropOn()

bool QListModeViewBase::dropOn ( QDropEvent event,
int *  dropRow,
int *  dropCol,
QModelIndex dropIndex 
)

If the event hasn't already been accepted, determines the index to drop on.

if (row == -1 && col == -1) append to this drop index else place at row, col in drop index

If it returns true a drop can be done, and dropRow, dropCol and dropIndex reflects the position of the drop.
\warning This function is not part of the public interface.

Definition at line 2108 of file qlistview.cpp.

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 {
2149  }
2150  *dropIndex = index;
2151  *dropRow = row;
2152  *dropCol = col;
2153  if (!dd->droppingOnItself(event, index))
2154  return true;
2155  }
2156  return false;
2157 }
QAbstractItemView::DropIndicatorPosition dropIndicatorPosition
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
virtual Qt::DropActions supportedDropActions() const
Returns the drop actions supported by this model.
int horizontalOffset() const
Definition: qlistview.cpp:2229
QVector< QModelIndex > intersectingSet(const QRect &area, bool doLayout=true) const
Definition: qlistview_p.h:314
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
QAbstractItemView::DropIndicatorPosition position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const
Definition: qlistview.cpp:2001
bool isAccepted() const
Definition: qcoreevent.h:307
int row() const
Returns the row this model index refers to.
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
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
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
int spacing() const
Definition: qlistview_p.h:373
QPersistentModelIndex root
QListViewPrivate * dd
Definition: qlistview_p.h:192
QRect visualRect(const QModelIndex &index) const
Reimplemented Function
Definition: qlistview.cpp:588
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
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
The QModelIndex class is used to locate data in a data model.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int verticalOffset() const
Definition: qlistview.cpp:2250
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
quint16 index
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QAbstractItemModel * model
bool droppingOnItself(QDropEvent *event, const QModelIndex &index)
Return true if this is a move from ourself and index is a child of the selection that is being moved...
const QPoint & pos() const
Returns the position where the drop was made.
Definition: qevent.h:486
int column() const
Returns the column this model index refers to.

◆ horizontalOffset()

int QListModeViewBase::horizontalOffset ( ) const
virtual

Reimplemented from QCommonListViewBase.

Definition at line 2229 of file qlistview.cpp.

2230 {
2232  if (isWrapping()) {
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 }
QVector< int > segmentPositions
Definition: qlistview_p.h:205
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< int > flowPositions
Definition: qlistview_p.h:204
QListView::ScrollMode horizontalScrollMode() const
Definition: qlistview_p.h:462
QListView::Flow flow() const
Definition: qlistview_p.h:451
virtual int horizontalOffset() const
Definition: qlistview.cpp:1965
QAbstractItemView::DropIndicatorPosition position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const
Definition: qlistview.cpp:2001
QVector< int > scrollValueMap
Definition: qlistview_p.h:208
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QScrollBar * horizontalScrollBar() const
Definition: qlistview_p.h:460
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
bool isRightToLeft() const
Definition: qlistview_p.h:483
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
bool isWrapping() const
Definition: qlistview_p.h:449

◆ horizontalScrollToValue()

int QListModeViewBase::horizontalScrollToValue ( int  index,
QListView::ScrollHint  hint,
bool  leftOf,
bool  rightOf,
const QRect area,
const QRect rect 
) const
virtual

Reimplemented from QCommonListViewBase.

Definition at line 2270 of file qlistview.cpp.

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 }
virtual int horizontalScrollToValue(int index, QListView::ScrollHint hint, bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const
Definition: qlistview.cpp:1970
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< int > flowPositions
Definition: qlistview_p.h:204
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int perItemScrollToValue(int index, int value, int height, QAbstractItemView::ScrollHint hint, Qt::Orientation orientation, bool wrap, int extent) const
Definition: qlistview.cpp:2634
QListView::ScrollMode horizontalScrollMode() const
Definition: qlistview_p.h:462
QVector< int > scrollValueMap
Definition: qlistview_p.h:208
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QScrollBar * horizontalScrollBar() const
Definition: qlistview_p.h:460
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
quint16 index
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
bool isWrapping() const
Definition: qlistview_p.h:449

◆ indexToListViewItem()

QListViewItem QListModeViewBase::indexToListViewItem ( const QModelIndex index) const
virtual

Implements QCommonListViewBase.

Definition at line 2349 of file qlistview.cpp.

2350 {
2351  if (flowPositions.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 }
QVector< int > segmentStartRows
Definition: qlistview_p.h:206
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
QVector< int > segmentPositions
Definition: qlistview_p.h:205
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool uniformItemSizes() const
Definition: qlistview_p.h:456
QVector< int > flowPositions
Definition: qlistview_p.h:204
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
QSize cachedItemSize() const
Definition: qlistview_p.h:472
QListView::Flow flow() const
Definition: qlistview_p.h:451
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
int width() const
Returns the width.
Definition: qsize.h:126
QSize itemSize(const QStyleOptionViewItemV2 &opt, const QModelIndex &idx) const
Definition: qlistview_p.h:474
int row() const
Returns the row this model index refers to.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void setY(int y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qpoint.h:137
int spacing() const
Definition: qlistview_p.h:448
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
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
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
bool isWrapping() const
Definition: qlistview_p.h:449
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134
QWidget * viewport() const
Definition: qlistview_p.h:469
QStyleOptionViewItemV4 viewOptions() const
Definition: qlistview_p.h:468

◆ initStaticLayout()

QPoint QListModeViewBase::initStaticLayout ( const QListViewLayoutInfo info)
private

Definition at line 2385 of file qlistview.cpp.

2386 {
2387  int x, y;
2388  if (info.first == 0) {
2389  flowPositions.clear();
2394  x = info.bounds.left() + info.spacing;
2395  y = info.bounds.top() + info.spacing;
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 }
QVector< int > segmentStartRows
Definition: qlistview_p.h:206
QVector< int > segmentPositions
Definition: qlistview_p.h:205
QVector< int > flowPositions
Definition: qlistview_p.h:204
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
QListView::Flow flow
Definition: qlistview_p.h:113
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QVector< int > scrollValueMap
Definition: qlistview_p.h:208
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QVector< int > segmentExtents
Definition: qlistview_p.h:207
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
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

◆ intersectingSet()

QVector< QModelIndex > QListModeViewBase::intersectingSet ( const QRect area) const
virtual

Finds the set of items intersecting with area.

Warning
This function is not part of the public interface.

In this function, itemsize is counted from topleft to the start of the next item.

Implements QCommonListViewBase.

Definition at line 2532 of file qlistview.cpp.

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  }
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 }
QVector< int > segmentStartRows
Definition: qlistview_p.h:206
QVector< int > segmentPositions
Definition: qlistview_p.h:205
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< int > flowPositions
Definition: qlistview_p.h:204
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
QListView::Flow flow() const
Definition: qlistview_p.h:451
bool isHidden(int row) const
Definition: qlistview_p.h:480
Q_CORE_EXPORT void qWarning(const char *,...)
QVector< int > segmentExtents
Definition: qlistview_p.h:207
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
QModelIndex modelIndex(int row) const
Definition: qlistview_p.h:464
The QModelIndex class is used to locate data in a data model.
quint16 index
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ itemIndex()

int QListModeViewBase::itemIndex ( const QListViewItem item) const
inlinevirtual

Implements QCommonListViewBase.

Definition at line 214 of file qlistview_p.h.

214 { return item.indexHint; }

◆ mapToViewport()

QRect QListModeViewBase::mapToViewport ( const QRect rect) const
virtual

Reimplemented from QCommonListViewBase.

Definition at line 2582 of file qlistview.cpp.

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 }
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QListView::Flow flow() const
Definition: qlistview_p.h:451
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int width() const
Returns the width.
Definition: qsize.h:126
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:261
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
int spacing() const
Definition: qlistview_p.h:448
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isWrapping() const
Definition: qlistview_p.h:449
QWidget * viewport() const
Definition: qlistview_p.h:469

◆ perItemScrollingPageSteps()

int QListModeViewBase::perItemScrollingPageSteps ( int  length,
int  bounds,
bool  wrap 
) const
private

Definition at line 2599 of file qlistview.cpp.

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 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QVector< int > segmentPositions
Definition: qlistview_p.h:205
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool uniformItemSizes() const
Definition: qlistview_p.h:456
QVector< int > flowPositions
Definition: qlistview_p.h:204
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static const QCssKnownValue positions[NumKnownPositionModes - 1]
Definition: qcssparser.cpp:329
QVector< int > scrollValueMap
Definition: qlistview_p.h:208
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ perItemScrollToValue()

int QListModeViewBase::perItemScrollToValue ( int  index,
int  value,
int  height,
QAbstractItemView::ScrollHint  hint,
Qt::Orientation  orientation,
bool  wrap,
int  extent 
) const
private

Definition at line 2634 of file qlistview.cpp.

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 }
QVector< int > segmentStartRows
Definition: qlistview_p.h:206
QVector< int > segmentPositions
Definition: qlistview_p.h:205
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< int > flowPositions
Definition: qlistview_p.h:204
QListView::Flow flow() const
Definition: qlistview_p.h:451
bool isHidden(int row) const
Definition: qlistview_p.h:480
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
quint16 index
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
Orientation
Definition: qnamespace.h:174

◆ position()

QAbstractItemView::DropIndicatorPosition QListModeViewBase::position ( const QPoint pos,
const QRect rect,
const QModelIndex idx 
) const

Definition at line 2001 of file qlistview.cpp.

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 
2023 
2024  return r;
2025 }
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
DropIndicatorPosition
This enum indicates the position of the drop indicator in relation to the index at the current mouse ...
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
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
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
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
QListViewPrivate * dd
Definition: qlistview_p.h:192
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
quint16 index
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QAbstractItemModel * model

◆ scrollContentsBy()

void QListModeViewBase::scrollContentsBy ( int  dx,
int  dy,
bool  scrollElasticBand 
)
virtual

Reimplemented from QCommonListViewBase.

Definition at line 2291 of file qlistview.cpp.

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 }
QVector< int > segmentPositions
Definition: qlistview_p.h:205
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< int > flowPositions
Definition: qlistview_p.h:204
QListView::ScrollMode horizontalScrollMode() const
Definition: qlistview_p.h:462
QListView::Flow flow() const
Definition: qlistview_p.h:451
int value() const
QVector< int > scrollValueMap
Definition: qlistview_p.h:208
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QScrollBar * horizontalScrollBar() const
Definition: qlistview_p.h:460
int spacing() const
Definition: qlistview_p.h:448
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
bool isWrapping() const
Definition: qlistview_p.h:449
QScrollBar * verticalScrollBar() const
Definition: qlistview_p.h:459
QListView::ScrollMode verticalScrollMode() const
Definition: qlistview_p.h:461
virtual void scrollContentsBy(int dx, int dy, bool scrollElasticBand)
Definition: qlistview.cpp:1946

◆ setRowCount()

void QListModeViewBase::setRowCount ( int  rowCount)
inlinevirtual

Implements QCommonListViewBase.

Definition at line 218 of file qlistview_p.h.

int rowCount() const
Definition: qlistview_p.h:466
QVector< int > flowPositions
Definition: qlistview_p.h:204
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342

◆ updateHorizontalScrollBar()

void QListModeViewBase::updateHorizontalScrollBar ( const QSize step)
virtual

Reimplemented from QCommonListViewBase.

Definition at line 2182 of file qlistview.cpp.

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());
2191  horizontalScrollBar()->setPageStep(pageSteps);
2192  horizontalScrollBar()->setRange(0, steps - pageSteps);
2193  } else {
2194  horizontalScrollBar()->setRange(0, 0);
2195  }
2196  } else {
2198  }
2199 }
QVector< int > segmentPositions
Definition: qlistview_p.h:205
QListView::ScrollMode horizontalScrollMode() const
Definition: qlistview_p.h:462
QListView::Flow flow() const
Definition: qlistview_p.h:451
void setRange(int min, int max)
Sets the slider&#39;s minimum to min and its maximum to max.
int width() const
Returns the width.
Definition: qsize.h:126
QVector< int > scrollValueMap
Definition: qlistview_p.h:208
QScrollBar * horizontalScrollBar() const
Definition: qlistview_p.h:460
int perItemScrollingPageSteps(int length, int bounds, bool wrap) const
Definition: qlistview.cpp:2599
bool isWrapping() const
Definition: qlistview_p.h:449
QWidget * viewport() const
Definition: qlistview_p.h:469
virtual void updateHorizontalScrollBar(const QSize &step)
Definition: qlistview.cpp:1932

◆ updateVerticalScrollBar()

void QListModeViewBase::updateVerticalScrollBar ( const QSize step)
virtual

Reimplemented from QCommonListViewBase.

Definition at line 2161 of file qlistview.cpp.

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());
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 }
QVector< int > segmentPositions
Definition: qlistview_p.h:205
QListView::Flow flow() const
Definition: qlistview_p.h:451
void setRange(int min, int max)
Sets the slider&#39;s minimum to min and its maximum to max.
QVector< int > scrollValueMap
Definition: qlistview_p.h:208
int height() const
Returns the height.
Definition: qsize.h:129
int perItemScrollingPageSteps(int length, int bounds, bool wrap) const
Definition: qlistview.cpp:2599
virtual void updateVerticalScrollBar(const QSize &step)
Definition: qlistview.cpp:1939
bool isWrapping() const
Definition: qlistview_p.h:449
QScrollBar * verticalScrollBar() const
Definition: qlistview_p.h:459
QListView::ScrollMode verticalScrollMode() const
Definition: qlistview_p.h:461
QWidget * viewport() const
Definition: qlistview_p.h:469

◆ verticalOffset()

int QListModeViewBase::verticalOffset ( ) const
virtual

Reimplemented from QCommonListViewBase.

Definition at line 2250 of file qlistview.cpp.

2251 {
2253  if (isWrapping()) {
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 }
QVector< int > segmentPositions
Definition: qlistview_p.h:205
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< int > flowPositions
Definition: qlistview_p.h:204
QListView::Flow flow() const
Definition: qlistview_p.h:451
int value() const
QVector< int > scrollValueMap
Definition: qlistview_p.h:208
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
int spacing() const
Definition: qlistview_p.h:448
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
bool isWrapping() const
Definition: qlistview_p.h:449
QScrollBar * verticalScrollBar() const
Definition: qlistview_p.h:459
QListView::ScrollMode verticalScrollMode() const
Definition: qlistview_p.h:461

◆ verticalScrollToValue()

int QListModeViewBase::verticalScrollToValue ( int  index,
QListView::ScrollHint  hint,
bool  above,
bool  below,
const QRect area,
const QRect rect 
) const
virtual

Reimplemented from QCommonListViewBase.

Definition at line 2201 of file qlistview.cpp.

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 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< int > flowPositions
Definition: qlistview_p.h:204
virtual int verticalScrollToValue(int index, QListView::ScrollHint hint, bool above, bool below, const QRect &area, const QRect &rect) const
Definition: qlistview.cpp:1951
int perItemScrollToValue(int index, int value, int height, QAbstractItemView::ScrollHint hint, Qt::Orientation orientation, bool wrap, int extent) const
Definition: qlistview.cpp:2634
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int value() const
bool isHidden(int row) const
Definition: qlistview_p.h:480
QVector< int > scrollValueMap
Definition: qlistview_p.h:208
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
quint16 index
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
bool isWrapping() const
Definition: qlistview_p.h:449
QScrollBar * verticalScrollBar() const
Definition: qlistview_p.h:459
QListView::ScrollMode verticalScrollMode() const
Definition: qlistview_p.h:461

Properties

◆ batchSavedPosition

int QListModeViewBase::batchSavedPosition

Definition at line 211 of file qlistview_p.h.

◆ flowPositions

QVector<int> QListModeViewBase::flowPositions

Definition at line 204 of file qlistview_p.h.

◆ scrollValueMap

QVector<int> QListModeViewBase::scrollValueMap

Definition at line 208 of file qlistview_p.h.

◆ segmentExtents

QVector<int> QListModeViewBase::segmentExtents

Definition at line 207 of file qlistview_p.h.

◆ segmentPositions

QVector<int> QListModeViewBase::segmentPositions

Definition at line 205 of file qlistview_p.h.

◆ segmentStartRows

QVector<int> QListModeViewBase::segmentStartRows

Definition at line 206 of file qlistview_p.h.


The documentation for this class was generated from the following files: