63 Q_DECLARE_PUBLIC(QAbstractItemView)
66 QAbstractItemViewPrivate();
67 virtual ~QAbstractItemViewPrivate();
71 virtual void rowsRemoved(
const QModelIndex &parent,
int start,
int end);
72 virtual void rowsInserted(
const QModelIndex &parent,
int start,
int end);
73 virtual void columnsAboutToBeRemoved(
const QModelIndex &parent,
int start,
int end);
74 virtual void columnsRemoved(
const QModelIndex &parent,
int start,
int end);
75 virtual void columnsInserted(
const QModelIndex &parent,
int start,
int end);
76 virtual void modelDestroyed();
77 virtual void layoutChanged();
78 virtual void rowsMoved(
const QModelIndex &source,
int sourceStart,
int sourceEnd,
const QModelIndex &destination,
int destinationStart);
79 virtual void columnsMoved(
const QModelIndex &source,
int sourceStart,
int sourceEnd,
const QModelIndex &destination,
int destinationStart);
80 virtual QRect intersectedRect(
const QRect rect,
const QModelIndex &topLeft,
const QModelIndex &bottomRight)
const;
82 void headerDataChanged() { doDelayedItemsLayout(); }
83 void scrollerStateChanged();
84 void delegateSizeHintChanged(
const QModelIndex &index);
88 bool shouldEdit(QAbstractItemView::EditTrigger trigger,
const QModelIndex &index)
const;
89 bool shouldForwardEvent(QAbstractItemView::EditTrigger trigger,
const QEvent *event)
const;
90 bool shouldAutoScroll(
const QPoint &pos)
const;
91 void doDelayedItemsLayout(
int delay = 0);
92 void interruptDelayedItemsLayout()
const;
94 void updateGeometry();
96 void startAutoScroll()
98 int scrollInterval = (verticalScrollMode == QAbstractItemView::ScrollPerItem) ? 150 : 50;
99 autoScrollTimer.start(scrollInterval, q_func());
102 void stopAutoScroll() { autoScrollTimer.stop(); autoScrollCount = 0;}
104#if QT_CONFIG(draganddrop)
105 virtual bool dropOn(QDropEvent *event,
int *row,
int *col, QModelIndex *index);
107 bool droppingOnItself(QDropEvent *event,
const QModelIndex &index);
109 QWidget *editor(
const QModelIndex &index,
const QStyleOptionViewItem &options);
110 bool sendDelegateEvent(
const QModelIndex &index, QEvent *event)
const;
111 bool openEditor(
const QModelIndex &index, QEvent *event);
112 void updateEditorData(
const QModelIndex &topLeft,
const QModelIndex &bottomRight);
113 void selectAllInEditor(QWidget *w);
115 QItemSelectionModel::SelectionFlags multiSelectionCommand(
const QModelIndex &index,
116 const QEvent *event)
const;
117 QItemSelectionModel::SelectionFlags extendedSelectionCommand(
const QModelIndex &index,
118 const QEvent *event)
const;
119 QItemSelectionModel::SelectionFlags contiguousSelectionCommand(
const QModelIndex &index,
120 const QEvent *event)
const;
121 virtual void selectAll(QItemSelectionModel::SelectionFlags command);
123 void setHoverIndex(
const QPersistentModelIndex &index);
125 void checkMouseMove(
const QPersistentModelIndex &index);
126 inline void checkMouseMove(
const QPoint &pos) { checkMouseMove(q_func()->indexAt(pos)); }
128 inline QItemSelectionModel::SelectionFlags selectionBehaviorFlags()
const
130 switch (selectionBehavior) {
131 case QAbstractItemView::SelectRows:
return QItemSelectionModel::Rows;
132 case QAbstractItemView::SelectColumns:
return QItemSelectionModel::Columns;
133 case QAbstractItemView::SelectItems:
default:
return QItemSelectionModel::NoUpdate;
137#if QT_CONFIG(draganddrop)
138 virtual QAbstractItemView::DropIndicatorPosition position(
const QPoint &pos,
const QRect &rect,
const QModelIndex &idx)
const;
140 inline bool canDrop(QDropEvent *event) {
141 const QMimeData *mime = event->mimeData();
145 if (event->type() == QEvent::DragEnter && (event->dropAction() & model->supportedDropActions())) {
146 const QStringList modelTypes = model->mimeTypes();
147 for (
const auto &modelType : modelTypes) {
148 if (mime->hasFormat(modelType))
156 if (dropOn(event, &row, &col, &index)) {
157 return model->canDropMimeData(mime,
158 dragDropMode == QAbstractItemView::InternalMove ? Qt::MoveAction : event->dropAction(),
164 inline void paintDropIndicator(QPainter *painter)
166 if (showDropIndicator && state == QAbstractItemView::DraggingState
167 && !dropIndicatorRect.isNull()
169 && viewport->cursor().shape() != Qt::ForbiddenCursor
173 opt.initFrom(q_func());
174 opt.rect = dropIndicatorRect;
175 q_func()->style()->drawPrimitive(QStyle::PE_IndicatorItemViewItemDrop, &opt, painter, q_func());
180 virtual QItemViewPaintPairs draggablePaintPairs(
const QModelIndexList &indexes, QRect *r)
const;
182 virtual void adjustViewOptionsForIndex(QStyleOptionViewItem*,
const QModelIndex&)
const {}
184 inline void releaseEditor(QWidget *editor,
const QModelIndex &index = QModelIndex())
const {
186 Q_Q(
const QAbstractItemView);
187 QObject::disconnect(editor, &QWidget::destroyed,
188 q, &QAbstractItemView::editorDestroyed);
189 editor->removeEventFilter(itemDelegate);
191 QAbstractItemDelegate *delegate = q->itemDelegateForIndex(index);
194 delegate->destroyEditor(editor, index);
196 editor->deleteLater();
200 inline void executePostedLayout()
const {
201 if (delayedPendingLayout && state != QAbstractItemView::CollapsingState) {
202 interruptDelayedItemsLayout();
203 const_cast<QAbstractItemView*>(q_func())->doItemsLayout();
207 inline void setDirtyRegion(
const QRegion &visualRegion) {
208 updateRegion += visualRegion;
209 if (!updateTimer.isActive())
210 updateTimer.start(0, q_func());
213 inline void scrollDirtyRegion(
int dx,
int dy) {
214 scrollDelayOffset = QPoint(-dx, -dy);
216 scrollDelayOffset = QPoint(0, 0);
219 inline void scrollContentsBy(
int dx,
int dy) {
220 scrollDirtyRegion(dx, dy);
221 viewport->scroll(dx, dy);
224 void updateDirtyRegion() {
226 viewport->update(updateRegion);
227 updateRegion = QRegion();
230 void clearOrRemove();
231 void checkPersistentEditorFocus();
233 QPixmap renderToPixmap(
const QModelIndexList &indexes, QRect *r)
const;
235 inline QPoint offset()
const {
236 const Q_Q(QAbstractItemView);
237 return QPoint(q->isRightToLeft() ? -q->horizontalOffset()
238 : q->horizontalOffset(), q->verticalOffset());
241 const QEditorInfo &editorForIndex(
const QModelIndex &index)
const;
242 bool hasEditor(
const QModelIndex &index)
const;
244 QModelIndex indexForEditor(QWidget *editor)
const;
245 void addEditor(
const QModelIndex &index, QWidget *editor,
bool isStatic);
246 void removeEditor(QWidget *editor);
248 inline bool isAnimating()
const {
249 return state == QAbstractItemView::AnimatingState;
252 inline bool isIndexValid(
const QModelIndex &index)
const {
253 return (index.row() >= 0) && (index.column() >= 0) && (index.model() == model);
255 inline bool isIndexSelectable(
const QModelIndex &index)
const {
256 return (model->flags(index) & Qt::ItemIsSelectable);
258 inline bool isIndexEnabled(
const QModelIndex &index)
const {
259 return (model->flags(index) & Qt::ItemIsEnabled);
261#if QT_CONFIG(draganddrop)
262 inline bool isIndexDropEnabled(
const QModelIndex &index)
const {
263 return (model->flags(index) & Qt::ItemIsDropEnabled);
265 inline bool isIndexDragEnabled(
const QModelIndex &index)
const {
266 return (model->flags(index) & Qt::ItemIsDragEnabled);
270 virtual bool selectionAllowed(
const QModelIndex &index)
const {
272 return isIndexValid(index) && isIndexSelectable(index);
276 QPoint contentsOffset()
const override {
277 Q_Q(
const QAbstractItemView);
278 return QPoint(q->horizontalOffset(), q->verticalOffset());
282
283
284
285 int delegateRefCount(
const QAbstractItemDelegate *delegate)
const
288 if (itemDelegate == delegate)
291 for (
int maps = 0; maps < 2; ++maps) {
292 const QMap<
int, QPointer<QAbstractItemDelegate> > *delegates = maps ? &columnDelegates : &rowDelegates;
293 for (QMap<
int, QPointer<QAbstractItemDelegate> >::const_iterator it = delegates->begin();
294 it != delegates->end(); ++it) {
295 if (it.value() == delegate) {
308
309
310 inline bool isPersistent(
const QModelIndex &index)
const
312 return static_cast<QAbstractItemModelPrivate *>(model->d_ptr.data())->persistent.indexes.contains(index);
315#if QT_CONFIG(draganddrop)
316 QModelIndexList selectedDraggableIndexes()
const;
317 void maybeStartDrag(QPoint eventPoint);
320 void doDelayedReset()
325 if (!delayedReset.isActive())
326 delayedReset.start(0, q_func());
329 QAbstractItemModel *model;
330 QPointer<QAbstractItemDelegate> itemDelegate;
331 QMap<
int, QPointer<QAbstractItemDelegate> > rowDelegates;
332 QMap<
int, QPointer<QAbstractItemDelegate> > columnDelegates;
333 QPointer<QItemSelectionModel> selectionModel;
334 QItemSelectionModel::SelectionFlag ctrlDragSelectionFlag;
335 bool noSelectionOnMousePress;
337 QAbstractItemView::SelectionMode selectionMode;
338 QAbstractItemView::SelectionBehavior selectionBehavior;
340 QEditorIndexHash editorIndexHash;
341 QIndexEditorHash indexEditorHash;
342 QSet<QWidget*> persistent;
343 QWidget *currentlyCommittingEditor;
344 QBasicTimer pressClosedEditorWatcher;
345 QPersistentModelIndex lastEditedIndex;
346 bool pressClosedEditor;
347 bool waitForIMCommit;
349 QPersistentModelIndex enteredIndex;
350 QPersistentModelIndex pressedIndex;
351 QPersistentModelIndex currentSelectionStartIndex;
352 Qt::KeyboardModifiers pressedModifiers;
353 QPoint pressedPosition;
354 QPoint draggedPosition;
355 QPoint draggedPositionOffset;
356 bool pressedAlreadySelected;
357 bool releaseFromDoubleClick;
361 bool viewportEnteredNeeded;
363 QAbstractItemView::State state;
364 QAbstractItemView::State stateBeforeAnimation;
365 QAbstractItemView::EditTriggers editTriggers;
366 QAbstractItemView::EditTrigger lastTrigger;
368 QPersistentModelIndex root;
369 QPersistentModelIndex hover;
371 bool tabKeyNavigation;
373#if QT_CONFIG(draganddrop)
374 bool showDropIndicator;
375 QRect dropIndicatorRect;
377 QAbstractItemView::DragDropMode dragDropMode;
380 QAbstractItemView::DropIndicatorPosition dropIndicatorPosition;
381 Qt::DropAction defaultDropAction;
384 QString keyboardInput;
385 QElapsedTimer keyboardInputTime;
388 QBasicTimer autoScrollTimer;
389 int autoScrollMargin;
391 bool shouldScrollToCurrentOnShow;
392 bool shouldClearStatusTip;
394 bool alternatingColors;
397 Qt::TextElideMode textElideMode;
399 QRegion updateRegion;
400 QPoint scrollDelayOffset;
402 QBasicTimer updateTimer;
403 QBasicTimer delayedEditing;
404 QBasicTimer delayedAutoScroll;
405 QBasicTimer delayedReset;
407 QAbstractItemView::ScrollMode verticalScrollMode;
408 QAbstractItemView::ScrollMode horizontalScrollMode;
410#ifndef QT_NO_GESTURES
412 QItemSelection oldSelection;
413 QModelIndex oldCurrent;
416 bool currentIndexSet;
419 mutable bool delayedPendingLayout;
420 bool moveCursorUpdatedView;
423 bool verticalScrollModeSet;
424 bool horizontalScrollModeSet;
428 virtual QRect visualRect(
const QModelIndex &index)
const {
return q_func()->visualRect(index); }
430 std::array<QMetaObject::Connection, 14> modelConnections;
431 std::array<QMetaObject::Connection, 4> scrollbarConnections;
432#if QT_CONFIG(gestures) && QT_CONFIG(scroller)
433 QMetaObject::Connection scollerConnection;
437 void connectDelegate(QAbstractItemDelegate *delegate);
438 void disconnectDelegate(QAbstractItemDelegate *delegate);
439 void disconnectAll();
440 inline QAbstractItemDelegate *delegateForIndex(
const QModelIndex &index)
const {
441 QMap<
int, QPointer<QAbstractItemDelegate> >::ConstIterator it;
443 it = rowDelegates.find(index.row());
444 if (it != rowDelegates.end())
447 it = columnDelegates.find(index.column());
448 if (it != columnDelegates.end())
454 mutable QBasicTimer delayedLayout;
455 mutable QBasicTimer fetchMoreTimer;