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