1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKTABLEVIEW_P_P_H
5#define QQUICKTABLEVIEW_P_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qquicktableview_p.h"
19
20#include <QtCore/qtimer.h>
21#include <QtCore/qitemselectionmodel.h>
22#include <QtQmlModels/private/qqmltableinstancemodel_p.h>
23#include <QtQml/private/qqmlincubator_p.h>
24#include <QtQmlModels/private/qqmlchangeset_p.h>
25#include <QtQml/qqmlinfo.h>
26
27#include <QtQuick/private/qquickflickable_p_p.h>
28#include <QtQuick/private/qquickitemviewfxitem_p_p.h>
29#include <QtQuick/private/qquickanimation_p.h>
30#include <QtQuick/private/qquickselectable_p.h>
31#include <QtQuick/private/qquicksinglepointhandler_p.h>
32#include <QtQuick/private/qquickhoverhandler_p.h>
33#include <QtQuick/private/qquicktaphandler_p.h>
34
35#include <QtCore/private/qminimalflatset_p.h>
36
37#if QT_CONFIG(quick_draganddrop)
38#include <QtGui/qdrag.h>
39#include <QtQuick/private/qquickdroparea_p.h>
40#endif
41
42QT_BEGIN_NAMESPACE
43
44Q_DECLARE_LOGGING_CATEGORY(lcTableViewDelegateLifecycle)
45
46static const qreal kDefaultRowHeight = 50;
47static const qreal kDefaultColumnWidth = 50;
48static const int kEdgeIndexNotSet = -2;
49static const int kEdgeIndexAtEnd = -3;
50
51class FxTableItem;
52class QQuickTableSectionSizeProviderPrivate;
53
54/*! \internal
55 * TableView uses QQuickTableViewHoverHandler to track where the pointer is
56 * on top of the table, and change the cursor at the places where a drag
57 * would start a resize of a row or a column.
58 */
59class QQuickTableViewHoverHandler : public QQuickHoverHandler
60{
61 Q_OBJECT
62
63public:
64 QQuickTableViewHoverHandler(QQuickTableView *view);
65 inline bool isHoveringGrid() const { return m_row != -1 || m_column != -1; };
66
67 int m_row = -1;
68 int m_column = -1;
69
70 friend class QQuickTableViewPrivate;
71
72protected:
73 void handleEventPoint(QPointerEvent *event, QEventPoint &point) override;
74};
75
76class QQuickTableViewPointerHandler : public QQuickSinglePointHandler
77{
78 Q_OBJECT
79
80public:
81 enum State {
82 Listening, // the pointer is not being pressed between the cells
83 Tracking, // the pointer is being pressed between the cells
84 DraggingStarted, // dragging started
85 Dragging, // a drag is ongoing
86 DraggingFinished // dragging was finished
87 };
88
89 QQuickTableViewPointerHandler(QQuickTableView *view);
90
91 State m_state = Listening;
92 State state() { return m_state; }
93
94protected:
95 bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) override;
96};
97
98/*! \internal
99 * TableView uses QQuickTableViewResizeHandler to enable the user to resize
100 * rows and columns. By using a custom pointer handler, we can get away with
101 * using a single pointer handler for the whole content item, rather than
102 * e.g having to split it up into multiple items with drag handlers placed
103 * between the cells.
104 */
105class QQuickTableViewResizeHandler : public QQuickTableViewPointerHandler
106{
107 Q_OBJECT
108
109public:
110 QQuickTableViewResizeHandler(QQuickTableView *view);
111
112 int m_row = -1;
113 qreal m_rowStartY = -1;
114 qreal m_rowStartHeight = -1;
115
116 int m_column = -1;
117 qreal m_columnStartX = -1;
118 qreal m_columnStartWidth = -1;
119
120 void updateState(QEventPoint &point);
121 void updateDrag(QPointerEvent *event, QEventPoint &point);
122
123 friend class QQuickTableViewPrivate;
124
125protected:
126 void handleEventPoint(QPointerEvent *event, QEventPoint &point) override;
127 void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition,
128 QPointerEvent *ev, QEventPoint &point) override;
129};
130
131#if QT_CONFIG(quick_draganddrop)
132class QQuickTableViewSectionDragHandler : public QQuickTableViewPointerHandler
133{
134 Q_OBJECT
135
136public:
137 QQuickTableViewSectionDragHandler(QQuickTableView *view);
138 ~QQuickTableViewSectionDragHandler();
139
140 void grabSection();
141
142 void handleDrag(QQuickDragEvent *event);
143 void handleDrop(QQuickDragEvent *event);
144 void handleDragDropAction(Qt::DropAction action);
145
146 void setSectionOrientation(Qt::Orientation orientation) { m_sectionOrientation = orientation; }
147
148 friend class QQuickTableViewPrivate;
149
150protected:
151 void handleEventPoint(QPointerEvent *event, QEventPoint &point) override;
152
153private:
154 void resetDragData();
155 void resetSectionOverlay();
156
157 QSharedPointer<QQuickItemGrabResult> m_grabResult;
158 QPointer<QDrag> m_drag;
159 int m_source = -1;
160 int m_destination = -1;
161 QPointer<QQuickDropArea> m_dropArea;
162 Qt::Orientation m_sectionOrientation;
163
164 QPointF m_dragPoint;
165 QSizeF m_step = QSizeF(1, 1);
166 QTimer m_scrollTimer;
167};
168#endif // quick_draganddrop
169
170/*! \internal
171 * QQuickTableViewTapHandler used to handle tap events explicitly for table view
172 */
173class QQuickTableViewTapHandler : public QQuickTapHandler
174{
175 Q_OBJECT
176
177public:
178 explicit QQuickTableViewTapHandler(QQuickTableView *view);
179 bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) override;
180
181 friend class QQuickTableViewPrivate;
182};
183
184class Q_QUICK_EXPORT QQuickTableViewPrivate : public QQuickFlickablePrivate, public QQuickSelectable
185{
186public:
187 Q_DECLARE_PUBLIC(QQuickTableView)
188
189 class TableEdgeLoadRequest
190 {
191 // Whenever we need to load new rows or columns in the
192 // table, we fill out a TableEdgeLoadRequest.
193 // TableEdgeLoadRequest is just a struct that keeps track
194 // of which cells that needs to be loaded, and which cell
195 // the table is currently loading. The loading itself is
196 // done by QQuickTableView.
197
198 public:
199 void begin(const QPoint &cell, const QPointF &pos, QQmlIncubator::IncubationMode incubationMode)
200 {
201 Q_ASSERT(!m_active);
202 m_active = true;
203 m_edge = Qt::Edge(0);
204 m_mode = incubationMode;
205 m_edgeIndex = cell.x();
206 m_visibleCellsInEdge.clear();
207 m_visibleCellsInEdge.append(t: cell.y());
208 m_currentIndex = 0;
209 m_startPos = pos;
210 qCDebug(lcTableViewDelegateLifecycle()) << "begin top-left:" << toString();
211 }
212
213 void begin(Qt::Edge edgeToLoad, int edgeIndex, const QVector<int> visibleCellsInEdge, QQmlIncubator::IncubationMode incubationMode)
214 {
215 Q_ASSERT(!m_active);
216 m_active = true;
217 m_edge = edgeToLoad;
218 m_edgeIndex = edgeIndex;
219 m_visibleCellsInEdge = visibleCellsInEdge;
220 m_mode = incubationMode;
221 m_currentIndex = 0;
222 qCDebug(lcTableViewDelegateLifecycle()) << "begin:" << toString();
223 }
224
225 inline void markAsDone() { m_active = false; }
226 inline bool isActive() const { return m_active; }
227
228 inline QPoint currentCell() const { return cellAt(index: m_currentIndex); }
229 inline bool hasCurrentCell() const { return m_currentIndex < m_visibleCellsInEdge.size(); }
230 inline void moveToNextCell() { ++m_currentIndex; }
231
232 inline Qt::Edge edge() const { return m_edge; }
233 inline int row() const { return cellAt(index: 0).y(); }
234 inline int column() const { return cellAt(index: 0).x(); }
235 inline QQmlIncubator::IncubationMode incubationMode() const { return m_mode; }
236
237 inline QPointF startPosition() const { return m_startPos; }
238
239 QString toString() const
240 {
241 QString str;
242 QDebug dbg(&str);
243 dbg.nospace() << "TableSectionLoadRequest(" << "edge:"
244 << m_edge << ", edgeIndex:" << m_edgeIndex << ", incubation:";
245
246 switch (m_mode) {
247 case QQmlIncubator::Asynchronous:
248 dbg << "Asynchronous";
249 break;
250 case QQmlIncubator::AsynchronousIfNested:
251 dbg << "AsynchronousIfNested";
252 break;
253 case QQmlIncubator::Synchronous:
254 dbg << "Synchronous";
255 break;
256 }
257
258 return str;
259 }
260
261 private:
262 Qt::Edge m_edge = Qt::Edge(0);
263 QVector<int> m_visibleCellsInEdge;
264 int m_edgeIndex = 0;
265 int m_currentIndex = 0;
266 bool m_active = false;
267 QQmlIncubator::IncubationMode m_mode = QQmlIncubator::AsynchronousIfNested;
268 QPointF m_startPos;
269
270 inline QPoint cellAt(int index) const {
271 return !m_edge || (m_edge & (Qt::LeftEdge | Qt::RightEdge))
272 ? QPoint(m_edgeIndex, m_visibleCellsInEdge[index])
273 : QPoint(m_visibleCellsInEdge[index], m_edgeIndex);
274 }
275 };
276
277 class EdgeRange {
278 public:
279 EdgeRange();
280 bool containsIndex(Qt::Edge edge, int index);
281
282 int startIndex;
283 int endIndex;
284 qreal size;
285 };
286
287 enum class RebuildState {
288 Begin = 0,
289 LoadInitalTable,
290 VerifyTable,
291 LayoutTable,
292 CancelOvershoot,
293 UpdateContentSize,
294 PreloadColumns,
295 PreloadRows,
296 MovePreloadedItemsToPool,
297 Done
298 };
299
300 enum class SectionState {
301 Idle = 0,
302 Moving
303 };
304
305 enum class RebuildOption {
306 None = 0,
307 All = 0x1,
308 LayoutOnly = 0x2,
309 ViewportOnly = 0x4,
310 CalculateNewTopLeftRow = 0x8,
311 CalculateNewTopLeftColumn = 0x10,
312 CalculateNewContentWidth = 0x20,
313 CalculateNewContentHeight = 0x40,
314 PositionViewAtRow = 0x80,
315 PositionViewAtColumn = 0x100,
316 };
317 Q_DECLARE_FLAGS(RebuildOptions, RebuildOption)
318
319public:
320 QQuickTableViewPrivate();
321 ~QQuickTableViewPrivate() override;
322
323 static inline QQuickTableViewPrivate *get(QQuickTableView *q) { return q->d_func(); }
324
325 void updatePolish() override;
326 void fixup(AxisData &data, qreal minExtent, qreal maxExtent) override;
327
328public:
329 QHash<int, FxTableItem *> loadedItems;
330
331 // model, tableModel and modelVariant all point to the same model. modelVariant
332 // is the model assigned by the user. And tableModel is the wrapper model we create
333 // around it. But if the model is an instance model directly, we cannot wrap it, so
334 // we need a pointer for that case as well.
335 QQmlInstanceModel* model = nullptr;
336 QPointer<QQmlTableInstanceModel> tableModel = nullptr;
337 QVariant modelVariant;
338
339 // When the applications assignes a new model or delegate to the view, we keep them
340 // around until we're ready to take them into use (syncWithPendingChanges).
341 QVariant assignedModel = QVariant(int(0));
342 QQmlGuard<QQmlComponent> assignedDelegate;
343
344 // loadedRows/Columns describes the rows and columns that are currently loaded (from top left
345 // row/column to bottom right row/column). loadedTableOuterRect describes the actual
346 // pixels that all the loaded delegate items cover, and is matched agains the viewport to determine when
347 // we need to fill up with more rows/columns. loadedTableInnerRect describes the pixels
348 // that the loaded table covers if you remove one row/column on each side of the table, and
349 // is used to determine rows/columns that are no longer visible and can be unloaded.
350 QMinimalFlatSet<int> loadedColumns;
351 QMinimalFlatSet<int> loadedRows;
352 QRectF loadedTableOuterRect;
353 QRectF loadedTableInnerRect;
354
355 QPointF origin = QPointF(0, 0);
356 QSizeF endExtent = QSizeF(0, 0);
357
358 QRectF viewportRect = QRectF(0, 0, -1, -1);
359
360 QSize tableSize;
361
362 RebuildState rebuildState = RebuildState::Done;
363 RebuildOptions rebuildOptions = RebuildOption::All;
364 RebuildOptions scheduledRebuildOptions = RebuildOption::All;
365
366 TableEdgeLoadRequest loadRequest;
367
368 QSizeF cellSpacing = QSizeF(0, 0);
369
370 QQmlTableInstanceModel::ReusableFlag reusableFlag = QQmlTableInstanceModel::Reusable;
371
372 bool blockItemCreatedCallback = false;
373 mutable bool layoutWarningIssued = false;
374 bool polishing = false;
375 bool syncVertically = false;
376 bool syncHorizontally = false;
377 bool inSetLocalViewportPos = false;
378 bool inSyncViewportPosRecursive = false;
379 bool inUpdateContentSize = false;
380 bool animate = true;
381 bool keyNavigationEnabled = true;
382 bool pointerNavigationEnabled = true;
383 bool alternatingRows = true;
384 bool resizableColumns = false;
385 bool resizableRows = false;
386#if QT_CONFIG(cursor)
387 bool m_cursorSet = false;
388#endif
389
390 // isTransposed is currently only used by HeaderView.
391 // Consider making it public.
392 bool isTransposed = false;
393
394 bool warnNoSelectionModel = true;
395
396 QQmlDelegateModel::DelegateModelAccess assignedDelegateModelAccess
397 = QQmlDelegateModel::Qt5ReadWrite;
398
399 QJSValue rowHeightProvider;
400 QJSValue columnWidthProvider;
401
402 mutable EdgeRange cachedNextVisibleEdgeIndex[4];
403 mutable EdgeRange cachedColumnWidth;
404 mutable EdgeRange cachedRowHeight;
405
406 // TableView uses contentWidth/height to report the size of the table (this
407 // will e.g make scrollbars written for Flickable work out of the box). This
408 // value is continuously calculated, and will change/improve as more columns
409 // are loaded into view. At the same time, we want to open up for the
410 // possibility that the application can set the content width explicitly, in
411 // case it knows what the exact width should be from the start. We therefore
412 // override the contentWidth/height properties from QQuickFlickable, to be able
413 // to implement this combined behavior. This also lets us lazy build the table
414 // if the application needs to know the content size early on.
415 QQmlNullableValue<qreal> explicitContentWidth;
416 QQmlNullableValue<qreal> explicitContentHeight;
417
418 QSizeF averageEdgeSize;
419
420 QPointer<QQuickTableView> assignedSyncView;
421 QPointer<QQuickTableView> syncView;
422 QList<QPointer<QQuickTableView> > syncChildren;
423 Qt::Orientations assignedSyncDirection = Qt::Horizontal | Qt::Vertical;
424
425 QPointer<QItemSelectionModel> selectionModel;
426 QQuickTableView::SelectionBehavior selectionBehavior = QQuickTableView::SelectCells;
427 QQuickTableView::SelectionMode selectionMode = QQuickTableView::ExtendedSelection;
428 QItemSelectionModel::SelectionFlag selectionFlag = QItemSelectionModel::NoUpdate;
429 std::function<void(CallBackFlag)> selectableCallbackFunction;
430 bool inSelectionModelUpdate = false;
431
432 int assignedPositionViewAtRowAfterRebuild = 0;
433 int assignedPositionViewAtColumnAfterRebuild = 0;
434 int positionViewAtRowAfterRebuild = 0;
435 int positionViewAtColumnAfterRebuild = 0;
436 qreal positionViewAtRowOffset = 0;
437 qreal positionViewAtColumnOffset = 0;
438 QRectF positionViewAtRowSubRect;
439 QRectF positionViewAtColumnSubRect;
440 Qt::Alignment positionViewAtRowAlignment = Qt::AlignTop;
441 Qt::Alignment positionViewAtColumnAlignment = Qt::AlignLeft;
442
443 QQuickPropertyAnimation positionXAnimation;
444 QQuickPropertyAnimation positionYAnimation;
445
446 QPoint selectionStartCell = {-1, -1};
447 QPoint selectionEndCell = {-1, -1};
448 QItemSelection existingSelection;
449
450 QMargins edgesBeforeRebuild;
451 QSize tableSizeBeforeRebuild;
452
453 int currentRow = -1;
454 int currentColumn = -1;
455
456 QHash<int, qreal> explicitColumnWidths;
457 QHash<int, qreal> explicitRowHeights;
458
459 QQuickTableViewHoverHandler *hoverHandler = nullptr;
460 QQuickTableViewResizeHandler *resizeHandler = nullptr;
461#if QT_CONFIG(quick_draganddrop)
462 QQuickTableViewSectionDragHandler *sectionDragHandler = nullptr;
463#endif
464 QQuickTableViewPointerHandler *activePtrHandler = nullptr;
465
466 QQmlTableInstanceModel *editModel = nullptr;
467 QQuickItem *editItem = nullptr;
468 QPersistentModelIndex editIndex;
469 QQuickTableView::EditTriggers editTriggers = QQuickTableView::DoubleTapped | QQuickTableView::EditKeyPressed;
470
471#ifdef QT_DEBUG
472 QString forcedIncubationMode = qEnvironmentVariable(varName: "QT_TABLEVIEW_INCUBATION_MODE");
473#endif
474
475 struct SectionData {
476 int index = -1;
477 int prevIndex = -1;
478 };
479
480 QList<SectionData> visualIndices[Qt::Vertical];
481 QList<SectionData> logicalIndices[Qt::Vertical];
482
483 SectionState m_sectionState = SectionState::Idle;
484
485public:
486 void init();
487
488 QQuickTableViewAttached *getAttachedObject(const QObject *object) const;
489
490 int modelIndexAtCell(const QPoint &cell) const;
491 QPoint cellAtModelIndex(int modelIndex) const;
492 int modelIndexToCellIndex(const QModelIndex &modelIndex, bool visualIndex = true) const;
493 inline bool cellIsValid(const QPoint &cell) const { return cell.x() != -1 && cell.y() != -1; }
494
495 qreal sizeHintForColumn(int column) const;
496 qreal sizeHintForRow(int row) const;
497 QSize calculateTableSize();
498 void updateTableSize();
499
500 inline bool isColumnHidden(int column) const;
501 inline bool isRowHidden(int row) const;
502
503 qreal getColumnLayoutWidth(int column);
504 qreal getRowLayoutHeight(int row);
505 qreal getColumnWidth(int column) const;
506 qreal getRowHeight(int row) const;
507 qreal getEffectiveRowY(int row) const;
508 qreal getEffectiveRowHeight(int row) const;
509 qreal getEffectiveColumnX(int column) const;
510 qreal getEffectiveColumnWidth(int column) const;
511 qreal getAlignmentContentX(int column, Qt::Alignment alignment, const qreal offset, const QRectF &subRect);
512 qreal getAlignmentContentY(int row, Qt::Alignment alignment, const qreal offset, const QRectF &subRect);
513
514 int topRow() const { return *loadedRows.cbegin(); }
515 int bottomRow() const { return *loadedRows.crbegin(); }
516 int leftColumn() const { return *loadedColumns.cbegin(); }
517 int rightColumn() const { return *loadedColumns.crbegin(); }
518
519 QQuickTableView *rootSyncView() const;
520
521 bool updateTableRecursive();
522 bool updateTable();
523 void relayoutTableItems();
524
525 void layoutVerticalEdge(Qt::Edge tableEdge);
526 void layoutHorizontalEdge(Qt::Edge tableEdge);
527 void layoutTopLeftItem();
528 void layoutTableEdgeFromLoadRequest();
529
530 void updateContentWidth();
531 void updateContentHeight();
532 void updateAverageColumnWidth();
533 void updateAverageRowHeight();
534 RebuildOptions checkForVisibilityChanges();
535 void forceLayout(bool immediate);
536
537 void updateExtents();
538 void syncLoadedTableRectFromLoadedTable();
539 void syncLoadedTableFromLoadRequest();
540
541 int nextVisibleEdgeIndex(Qt::Edge edge, int startIndex) const;
542 int nextVisibleEdgeIndexAroundLoadedTable(Qt::Edge edge) const;
543 inline bool atTableEnd(Qt::Edge edge) const { return nextVisibleEdgeIndexAroundLoadedTable(edge) == kEdgeIndexAtEnd; }
544 inline bool atTableEnd(Qt::Edge edge, int startIndex) const { return nextVisibleEdgeIndex(edge, startIndex) == kEdgeIndexAtEnd; }
545 inline int edgeToArrayIndex(Qt::Edge edge) const;
546 void clearEdgeSizeCache();
547
548 bool canLoadTableEdge(Qt::Edge tableEdge, const QRectF fillRect) const;
549 bool canUnloadTableEdge(Qt::Edge tableEdge, const QRectF fillRect) const;
550 Qt::Edge nextEdgeToLoad(const QRectF rect);
551 Qt::Edge nextEdgeToUnload(const QRectF rect);
552
553 qreal cellWidth(const QPoint &cell) const;
554 qreal cellHeight(const QPoint &cell) const;
555
556 FxTableItem *loadedTableItem(const QPoint &cell) const;
557 FxTableItem *createFxTableItem(const QPoint &cell, QQmlIncubator::IncubationMode incubationMode);
558 FxTableItem *loadFxTableItem(const QPoint &cell, QQmlIncubator::IncubationMode incubationMode);
559
560 void releaseItem(FxTableItem *fxTableItem, QQmlTableInstanceModel::ReusableFlag reusableFlag);
561 void releaseLoadedItems(QQmlTableInstanceModel::ReusableFlag reusableFlag);
562
563 void unloadItem(const QPoint &cell);
564 void loadEdge(Qt::Edge edge, QQmlIncubator::IncubationMode incubationMode);
565 void unloadEdge(Qt::Edge edge);
566 void loadAndUnloadVisibleEdges(QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::AsynchronousIfNested);
567 void drainReusePoolAfterLoadRequest();
568 void processLoadRequest();
569
570 void processRebuildTable();
571 bool moveToNextRebuildState();
572 void calculateTopLeft(QPoint &topLeft, QPointF &topLeftPos);
573 void loadInitialTable();
574
575 void layoutAfterLoadingInitialTable();
576 void adjustViewportXAccordingToAlignment();
577 void adjustViewportYAccordingToAlignment();
578 void cancelOvershootAfterLayout();
579
580 void scheduleRebuildTable(QQuickTableViewPrivate::RebuildOptions options);
581
582#if QT_CONFIG(cursor)
583 void updateCursor();
584#endif
585 void updateEditItem();
586 void updateContentSize();
587
588 QTypeRevision resolveImportVersion();
589 void createWrapperModel();
590 QAbstractItemModel *qaim(QVariant modelAsVariant) const;
591
592 virtual void initItemCallback(int modelIndex, QObject *item);
593 virtual void itemCreatedCallback(int modelIndex, QObject *object);
594 virtual void itemPooledCallback(int modelIndex, QObject *object);
595 virtual void itemReusedCallback(int modelIndex, QObject *object);
596 virtual void modelUpdated(const QQmlChangeSet &changeSet, bool reset);
597
598 virtual void syncWithPendingChanges();
599 virtual void syncDelegate();
600 virtual void syncDelegateModelAccess();
601 virtual QVariant modelImpl() const;
602 virtual void setModelImpl(const QVariant &newModel);
603 virtual void syncModel();
604 virtual void syncSyncView();
605 virtual void syncPositionView();
606 virtual QAbstractItemModel *selectionSourceModel();
607 inline void syncRebuildOptions();
608
609 void connectToModel();
610 void disconnectFromModel();
611
612 void rowsMovedCallback(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row);
613 void columnsMovedCallback(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column);
614 void rowsInsertedCallback(const QModelIndex &parent, int begin, int end);
615 void rowsRemovedCallback(const QModelIndex &parent, int begin, int end);
616 void columnsInsertedCallback(const QModelIndex &parent, int begin, int end);
617 void columnsRemovedCallback(const QModelIndex &parent, int begin, int end);
618 void layoutChangedCallback(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
619 void modelResetCallback();
620 bool compareModel(const QVariant& model1, const QVariant& model2) const;
621
622 void positionViewAtRow(int row, Qt::Alignment alignment, qreal offset, const QRectF subRect = QRectF());
623 void positionViewAtColumn(int column, Qt::Alignment alignment, qreal offset, const QRectF subRect = QRectF());
624 bool scrollToRow(int row, Qt::Alignment alignment, qreal offset, const QRectF subRect = QRectF());
625 bool scrollToColumn(int column, Qt::Alignment alignment, qreal offset, const QRectF subRect = QRectF());
626
627 void scheduleRebuildIfFastFlick();
628 void setLocalViewportX(qreal contentX);
629 void setLocalViewportY(qreal contentY);
630 void syncViewportRect();
631 void syncViewportPosRecursive();
632
633 bool selectedInSelectionModel(const QPoint &cell) const;
634 void selectionChangedInSelectionModel(const QItemSelection &selected, const QItemSelection &deselected);
635 void updateSelectedOnAllDelegateItems();
636 void setSelectedOnDelegateItem(const QModelIndex &modelIndex, bool select);
637
638 bool currentInSelectionModel(const QPoint &cell) const;
639 void currentChangedInSelectionModel(const QModelIndex &current, const QModelIndex &previous);
640 void setCurrentOnDelegateItem(const QModelIndex &index, bool isCurrent);
641 void updateCurrentRowAndColumn();
642
643 void fetchMoreData();
644
645 void _q_componentFinalized();
646 void registerCallbackWhenBindingsAreEvaluated();
647
648 inline QString tableLayoutToString() const;
649 void dumpTable() const;
650
651 void setRequiredProperty(const char *property,
652 const QVariant &value,
653 int serializedModelIndex,
654 QObject *object, bool init);
655
656 void handleTap(const QQuickHandlerPoint &point);
657 void setCurrentIndexFromTap(const QPointF &pos);
658 void setCurrentIndex(const QPoint &cell);
659 bool setCurrentIndexFromKeyEvent(QKeyEvent *e);
660 bool canEdit(const QModelIndex tappedIndex, bool warn);
661 bool editFromKeyEvent(QKeyEvent *e);
662 void closeEditorAndCommit();
663 QObject *installEventFilterOnFocusObjectInsideEditItem();
664
665 // QQuickSelectable
666 QQuickItem *selectionPointerHandlerTarget() const override;
667 bool hasSelection() const override;
668 bool startSelection(const QPointF &pos, Qt::KeyboardModifiers modifiers) override;
669 void setSelectionStartPos(const QPointF &pos) override;
670 void setSelectionEndPos(const QPointF &pos) override;
671 void clearSelection() override;
672 void normalizeSelection() override;
673 QRectF selectionRectangle() const override;
674 QSizeF scrollTowardsPoint(const QPointF &pos, const QSizeF &step) override;
675 void setCallback(std::function<void(CallBackFlag)> func) override;
676 void cancelSelectionTracking();
677
678 QPoint clampedCellAtPos(const QPointF &pos) const;
679 virtual void updateSelection(const QRect &oldSelection, const QRect &newSelection);
680 QRect selection() const;
681 // ----------------
682
683 // Section drag handler
684#if QT_CONFIG(quick_draganddrop)
685 void initSectionDragHandler(Qt::Orientation orientation);
686 void destroySectionDragHandler();
687#endif
688 inline void setActivePointerHandler(QQuickTableViewPointerHandler *handler) { activePtrHandler = handler; }
689 inline QQuickTableViewPointerHandler* activePointerHandler() const { return activePtrHandler; }
690 // Row/Column reordering
691 void moveSection(int source , int destination, Qt::Orientations orientation);
692 void initializeIndexMapping();
693 void clearIndexMapping();
694 void clearSection(Qt::Orientations orientation);
695 virtual int logicalRowIndex(const int visualIndex) const;
696 virtual int logicalColumnIndex(const int visualIndex) const;
697 virtual int visualRowIndex(const int logicalIndex) const;
698 virtual int visualColumnIndex(const int logicalIndex) const;
699 void setContainsDragOnDelegateItem(const QModelIndex &modelIndex, bool overlay);
700 int getEditCellIndex(const QModelIndex &index) const;
701};
702
703class FxTableItem : public QQuickItemViewFxItem
704{
705public:
706 FxTableItem(QQuickItem *item, QQuickTableView *table, bool own)
707 : QQuickItemViewFxItem(item, own, QQuickTableViewPrivate::get(q: table))
708 {
709 }
710
711 qreal position() const override { return 0; }
712 qreal endPosition() const override { return 0; }
713 qreal size() const override { return 0; }
714 qreal sectionSize() const override { return 0; }
715 bool contains(qreal, qreal) const override { return false; }
716
717 QPoint cell;
718};
719
720Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickTableViewPrivate::RebuildOptions)
721
722QT_END_NAMESPACE
723
724#endif
725

source code of qtdeclarative/src/quick/items/qquicktableview_p_p.h