18#include <QtWidgets/private/qtwidgetsglobal_p.h>
20#include "private/qabstractitemview_p.h"
24#include <qscrollbar.h>
32 friend class QListViewPrivate;
33 friend class QListModeViewBase;
34 friend class QIconModeViewBase;
36 constexpr QListViewItem()
37 : x(-1), y(-1), w(0), h(0), indexHint(-1), visited(0xffff) {}
38 constexpr QListViewItem(QRect r,
int i)
39 : x(r.x()), y(r.y()), w(qMin(r.width(), SHRT_MAX)), h(qMin(r.height(), SHRT_MAX)),
40 indexHint(i), visited(0xffff) {}
41 constexpr bool operator==(
const QListViewItem &other)
const {
42 return (x == other.x && y == other.y && w == other.w && h == other.h &&
43 indexHint == other.indexHint); }
44 constexpr bool operator!=(
const QListViewItem &other)
const
45 {
return !(*
this == other); }
46 constexpr bool isValid()
const
47 {
return rect().isValid() && (indexHint > -1); }
48 constexpr void invalidate()
49 { x = -1; y = -1; w = 0; h = 0; }
50 constexpr void resize(QSize size)
51 { w = qMin(size.width(), SHRT_MAX); h = qMin(size.height(), SHRT_MAX); }
52 constexpr void move(QPoint position)
53 { x = position.x(); y = position.y(); }
54 constexpr int width()
const {
return w; }
55 constexpr int height()
const {
return h; }
57 constexpr QRect rect()
const
58 {
return QRect(x, y, w, h); }
61 mutable int indexHint;
80class QListViewPrivate;
89 virtual int itemIndex(
const QListViewItem &item)
const = 0;
95 virtual void dataChanged(
const QModelIndex &,
const QModelIndex &) = 0;
98 bool leftOf,
bool rightOf,
const QRect &area,
const QRect &rect)
const;
100 bool above,
bool below,
const QRect &area,
const QRect &rect)
const;
111#if QT_CONFIG(draganddrop)
130 inline int column()
const;
146 inline QSize itemSize(
const QStyleOptionViewItem &opt,
const QModelIndex &idx)
const;
149 inline bool isHidden(
int row)
const;
154 QListViewPrivate *
dd;
176 int itemIndex(
const QListViewItem &item)
const override {
return item.indexHint; }
179 void clear()
override;
180 void setRowCount(
int rowCount)
override { flowPositions.resize(rowCount); }
182 void dataChanged(
const QModelIndex &,
const QModelIndex &)
override;
185 bool leftOf,
bool rightOf,
const QRect &area,
const QRect &rect)
const override;
187 bool above,
bool below,
const QRect &area,
const QRect &rect)
const override;
196#if QT_CONFIG(draganddrop)
207 int perItemScrollToValue(
int index,
int value,
int height,
208 QAbstractItemView::ScrollHint hint,
209 Qt::Orientation orientation,
bool wrap,
int extent)
const;
210 int perItemScrollingPageSteps(
int length,
int bounds,
bool wrap)
const;
229 int itemIndex(
const QListViewItem &item)
const override;
232 void clear()
override;
237 void dataChanged(
const QModelIndex &topLeft,
const QModelIndex &bottomRight)
override;
242#if QT_CONFIG(draganddrop)
250 void initBspTree(
const QSize &contents);
253 static void addLeaf(
QList<
int> &leaf,
const QRect &area, uint visited,
QBspTree::
Data data);
254 QRect itemsRect(
const QList<QModelIndex> &indexes)
const;
255 QRect draggedItemsRect()
const;
256 QPoint snapToGrid(
const QPoint &pos)
const;
257 void updateContentsSize();
258 QPoint draggedItemsDelta()
const;
259 void drawItems(QPainter *painter,
const QList<QModelIndex> &indexes)
const;
260 void moveItem(
int index,
const QPoint &dest);
266 Q_DECLARE_PUBLIC(QListView)
272 void prepareItemsLayout();
274 bool doItemsLayout(
int num);
276 inline QList<QModelIndex> intersectingSet(
const QRect &area,
bool doLayout =
true)
const
278 if (doLayout) executePostedLayout();
279 QRect a = (q_func()->isRightToLeft() ? flipX(area.normalized()) : area.normalized());
280 return commonListView->intersectingSet(a);
283 inline void resetBatchStartRow() { commonListView->batchStartRow = 0; }
284 inline int batchStartRow()
const {
return commonListView->batchStartRow; }
285 inline QSize contentsSize()
const {
return commonListView->contentsSize; }
286 inline void setContentsSize(
int w,
int h) { commonListView->contentsSize = QSize(w, h); }
288 inline int flipX(
int x)
const
289 {
return qMax(viewport->width(), contentsSize().width()) - x; }
290 inline QPoint flipX(
const QPoint &p)
const
291 {
return QPoint(flipX(p.x()), p.y()); }
292 inline QRect flipX(
const QRect &r)
const
293 {
return QRect(flipX(r.x()) - r.width(), r.y(), r.width(), r.height()); }
294 inline QRect viewItemRect(
const QListViewItem &item)
const
295 {
if (q_func()->isRightToLeft())
return flipX(item.rect());
return item.rect(); }
297 QListViewItem indexToListViewItem(
const QModelIndex &index)
const;
298 inline QModelIndex listViewItemToIndex(
const QListViewItem &item)
const
299 {
return model->index(commonListView->itemIndex(item), column, root); }
301 inline bool hasRectForIndex(
const QModelIndex &index)
const
303 return isIndexValid(index) && index.parent() == root && index.column() == column && !isHidden(index.row());
306 QRect rectForIndex(
const QModelIndex &index)
const
308 if (!hasRectForIndex(index))
310 executePostedLayout();
311 return viewItemRect(indexToListViewItem(index));
314 QRect cellRectForIndex(
const QModelIndex &index)
316 if (!hasRectForIndex(index))
318 executePostedLayout();
319 auto oldItemAlignment = itemAlignment;
320 itemAlignment = Qt::Alignment();
321 const QRect rect = rectForIndex(index);
322 itemAlignment = oldItemAlignment;
326 void viewUpdateGeometries() { q_func()->updateGeometries(); }
329 QRect mapToViewport(
const QRect &rect,
bool extend =
true)
const;
331 QModelIndex closestIndex(
const QRect &target,
const QList<QModelIndex> &candidates)
const;
332 QSize itemSize(
const QStyleOptionViewItem &option,
const QModelIndex &index)
const;
334 bool selectionAllowed(
const QModelIndex &index)
const override
335 {
if (viewMode == QListView::ListMode && !showElasticBand)
return index.isValid();
return true; }
337 int horizontalScrollToValue(
const QModelIndex &index,
const QRect &rect, QListView::ScrollHint hint)
const;
338 int verticalScrollToValue(
const QModelIndex &index,
const QRect &rect, QListView::ScrollHint hint)
const;
340 QItemSelection selection(
const QRect &rect)
const;
341 void selectAll(QItemSelectionModel::SelectionFlags command) override;
343#if QT_CONFIG(draganddrop)
344 QAbstractItemView::DropIndicatorPosition position(
const QPoint &pos,
const QRect &rect,
const QModelIndex &idx)
const override;
345 bool dropOn(QDropEvent *event,
int *row,
int *col, QModelIndex *index) override;
348 inline void setGridSize(
const QSize &size) { grid = size; }
349 inline QSize gridSize()
const {
return grid; }
350 inline void setWrapping(
bool b) { wrap = b; }
351 inline bool isWrapping()
const {
return wrap; }
352 inline void setSpacing(
int s) { space = s; }
353 inline int spacing()
const {
return space; }
354 inline void setSelectionRectVisible(
bool visible) { showElasticBand = visible; }
355 inline bool isSelectionRectVisible()
const {
return showElasticBand; }
357 inline QModelIndex modelIndex(
int row)
const {
return model->index(row, column, root); }
358 inline bool isHidden(
int row)
const {
359 QModelIndex idx = model->index(row, 0, root);
360 return isPersistent(idx) && hiddenRows.contains(idx);
363 QList<
int> hiddenRowIds()
const
366 rowIds.reserve(hiddenRows.size());
367 for (
const auto &idx : hiddenRows)
371 inline bool isHiddenOrDisabled(
int row)
const {
return isHidden(row) || !isIndexEnabled(modelIndex(row)); }
373 void removeCurrentAndDisabled(QList<QModelIndex> *indexes,
const QModelIndex ¤t)
const;
375 void scrollElasticBandBy(
int dx,
int dy);
377 QItemViewPaintPairs draggablePaintPairs(
const QModelIndexList &indexes, QRect *r)
const override;
379 void emitIndexesMoved(
const QModelIndexList &indexes) { emit q_func()->indexesMoved(indexes); }
382 QCommonListViewBase *commonListView;
390 QListView::Flow flow;
391 QListView::Movement movement;
392 QListView::ResizeMode resizeMode;
393 QListView::LayoutMode layoutMode;
394 QListView::ViewMode viewMode;
398 enum ModeProperties {
405 SelectionRectVisible = 64
408 uint modeProperties : 8;
413 QBasicTimer batchLayoutTimer;
416 QSet<QPersistentModelIndex> hiddenRows;
419 bool uniformItemSizes;
420 mutable QSize cachedItemSize;
424 bool showElasticBand;
426 Qt::Alignment itemAlignment;
448 {
return dd->model->index(row,
dd->column,
dd->root); }
458 {
return dd->itemSize(opt, idx); }
461 {
return qq->itemDelegateForIndex(idx); }
virtual void setPositionForIndex(const QPoint &, const QModelIndex &)
virtual void dataChanged(const QModelIndex &, const QModelIndex &)=0
virtual ~QCommonListViewBase()
virtual int horizontalScrollToValue(int index, QListView::ScrollHint hint, bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const
virtual QList< QModelIndex > intersectingSet(const QRect &area) const =0
QAbstractItemDelegate * delegate(const QModelIndex &idx) const
QListView::Movement movement() const
QRect viewItemRect(const QListViewItem &item) const
QListView::ScrollMode horizontalScrollMode() const
QListView::ScrollMode verticalScrollMode() const
virtual void updateHorizontalScrollBar(const QSize &step)
virtual int horizontalOffset() const
virtual int itemIndex(const QListViewItem &item) const =0
QWidget * viewport() const
void initViewItemOption(QStyleOptionViewItem *option) const
virtual bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max)=0
virtual void appendHiddenRow(int row)
virtual void updateVerticalScrollBar(const QSize &step)
virtual QListViewItem indexToListViewItem(const QModelIndex &index) const =0
virtual void removeHiddenRow(int row)
bool uniformItemSizes() const
QSize cachedItemSize() const
virtual void scrollContentsBy(int dx, int dy, bool scrollElasticBand)
virtual int verticalOffset() const
bool isHidden(int row) const
QScrollBar * verticalScrollBar() const
QSize itemSize(const QStyleOptionViewItem &opt, const QModelIndex &idx) const
QListView::Flow flow() const
virtual void setRowCount(int)=0
virtual QRect mapToViewport(const QRect &rect) const
QScrollBar * horizontalScrollBar() const
bool isRightToLeft() const
QModelIndex modelIndex(int row) const
virtual int verticalScrollToValue(int index, QListView::ScrollHint hint, bool above, bool below, const QRect &area, const QRect &rect) const
QPoint pressedPosition() const
QCommonListViewBase(QListView *q, QListViewPrivate *d)
QList< QListViewItem > items
int itemIndex(const QListViewItem &item) const override
QList< QModelIndex > draggedItems
QListViewItem indexToListViewItem(const QModelIndex &index) const override
void setPositionForIndex(const QPoint &position, const QModelIndex &index) override
void setRowCount(int rowCount) override
void scrollContentsBy(int dx, int dy, bool scrollElasticBand) override
QList< QModelIndex > intersectingSet(const QRect &area) const override
QIconModeViewBase(QListView *q, QListViewPrivate *d)
void appendHiddenRow(int row) override
QList< QModelIndex > * interSectingVector
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) override
void removeHiddenRow(int row) override
bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max) override
void updateHorizontalScrollBar(const QSize &step) override
bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max) override
QList< int > segmentExtents
int itemIndex(const QListViewItem &item) const override
QList< int > segmentPositions
QList< int > flowPositions
void updateVerticalScrollBar(const QSize &step) override
void scrollContentsBy(int dx, int dy, bool scrollElasticBand) override
QList< QModelIndex > intersectingSet(const QRect &area) const override
int horizontalOffset() const override
QRect mapToViewport(const QRect &rect) const override
int verticalOffset() const override
QListViewItem indexToListViewItem(const QModelIndex &index) const override
void setRowCount(int rowCount) override
int verticalScrollToValue(int index, QListView::ScrollHint hint, bool above, bool below, const QRect &area, const QRect &rect) const override
int horizontalScrollToValue(int index, QListView::ScrollHint hint, bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const override
QListModeViewBase(QListView *q, QListViewPrivate *d)
static QSize viewportSize(const QAbstractItemView *v)
void dataChanged(const QModelIndex &, const QModelIndex &) override
QList< int > segmentStartRows
QList< int > scrollValueMap
QT_REQUIRE_CONFIG(animation)
Q_DECLARE_TYPEINFO(QListViewItem, Q_PRIMITIVE_TYPE)
Q_DECLARE_TYPEINFO(QListViewLayoutInfo, Q_PRIMITIVE_TYPE)