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.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_H
6#define QQUICKTABLEVIEW_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
19#include <private/qtquickglobal_p.h>
21
22#include <QtCore/qpointer.h>
23#include <QtCore/qpoint.h>
24#include <QtCore/qrect.h>
25#include <QtQuick/private/qtquickglobal_p.h>
26#include <QtQuick/private/qquickflickable_p.h>
27#include <QtQml/qqmlcomponent.h>
28#include <QtQml/private/qqmlnullablevalue_p.h>
29#include <QtQml/private/qqmlfinalizer_p.h>
30#include <QtQml/private/qqmlguard_p.h>
31#include <QtQmlModels/private/qqmldelegatemodel_p.h>
32
33QT_BEGIN_NAMESPACE
34
35class QQuickTableViewAttached;
36class QQuickTableViewPrivate;
37class QItemSelectionModel;
38
39class Q_QUICK_EXPORT QQuickTableView : public QQuickFlickable, public QQmlFinalizerHook
40{
41 Q_OBJECT
42 Q_INTERFACES(QQmlFinalizerHook)
43
44 Q_PROPERTY(int rows READ rows NOTIFY rowsChanged)
45 Q_PROPERTY(int columns READ columns NOTIFY columnsChanged)
46 Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged)
47 Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged)
48 Q_PROPERTY(QJSValue rowHeightProvider READ rowHeightProvider WRITE setRowHeightProvider NOTIFY rowHeightProviderChanged)
49 Q_PROPERTY(QJSValue columnWidthProvider READ columnWidthProvider WRITE setColumnWidthProvider NOTIFY columnWidthProviderChanged)
50 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
51 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
52 Q_PROPERTY(bool reuseItems READ reuseItems WRITE setReuseItems NOTIFY reuseItemsChanged)
53 Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged OVERRIDE)
54 Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged OVERRIDE)
55 Q_PROPERTY(QQuickTableView *syncView READ syncView WRITE setSyncView NOTIFY syncViewChanged REVISION(2, 14))
56 Q_PROPERTY(Qt::Orientations syncDirection READ syncDirection WRITE setSyncDirection NOTIFY syncDirectionChanged REVISION(2, 14))
57 Q_PROPERTY(int leftColumn READ leftColumn NOTIFY leftColumnChanged REVISION(6, 0))
58 Q_PROPERTY(int rightColumn READ rightColumn NOTIFY rightColumnChanged REVISION(6, 0))
59 Q_PROPERTY(int topRow READ topRow NOTIFY topRowChanged REVISION(6, 0))
60 Q_PROPERTY(int bottomRow READ bottomRow NOTIFY bottomRowChanged REVISION(6, 0))
61 Q_PROPERTY(QItemSelectionModel *selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged REVISION(6, 2))
62 Q_PROPERTY(bool animate READ animate WRITE setAnimate NOTIFY animateChanged REVISION(6, 4))
63 Q_PROPERTY(bool keyNavigationEnabled READ keyNavigationEnabled WRITE setKeyNavigationEnabled NOTIFY keyNavigationEnabledChanged REVISION(6, 4))
64 Q_PROPERTY(bool pointerNavigationEnabled READ pointerNavigationEnabled WRITE setPointerNavigationEnabled NOTIFY pointerNavigationEnabledChanged REVISION(6, 4))
65 Q_PROPERTY(int currentRow READ currentRow NOTIFY currentRowChanged REVISION(6, 4) FINAL)
66 Q_PROPERTY(int currentColumn READ currentColumn NOTIFY currentColumnChanged REVISION(6, 4) FINAL)
67 Q_PROPERTY(bool alternatingRows READ alternatingRows WRITE setAlternatingRows NOTIFY alternatingRowsChanged REVISION(6, 4) FINAL)
68 Q_PROPERTY(SelectionBehavior selectionBehavior READ selectionBehavior WRITE setSelectionBehavior NOTIFY selectionBehaviorChanged REVISION(6, 4) FINAL)
69 Q_PROPERTY(bool resizableColumns READ resizableColumns WRITE setResizableColumns NOTIFY resizableColumnsChanged REVISION(6, 5) FINAL)
70 Q_PROPERTY(bool resizableRows READ resizableRows WRITE setResizableRows NOTIFY resizableRowsChanged REVISION(6, 5) FINAL)
71 Q_PROPERTY(EditTriggers editTriggers READ editTriggers WRITE setEditTriggers NOTIFY editTriggersChanged REVISION(6, 5) FINAL)
72 Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode NOTIFY selectionModeChanged REVISION(6, 6) FINAL)
73 Q_PROPERTY(QQmlDelegateModel::DelegateModelAccess delegateModelAccess READ delegateModelAccess
74 WRITE setDelegateModelAccess NOTIFY delegateModelAccessChanged REVISION(6, 10) FINAL)
75 Q_PROPERTY(bool sortingEnabled READ sortingEnabled WRITE setSortingEnabled
76 NOTIFY sortingEnabledChanged REVISION(6, 13))
77 Q_PROPERTY(int sortColumn READ sortColumn WRITE setSortColumn NOTIFY sortColumnChanged REVISION(6, 13))
78 Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged REVISION(6, 13))
79
80 QML_NAMED_ELEMENT(TableView)
81 QML_ADDED_IN_VERSION(2, 12)
82 QML_ATTACHED(QQuickTableViewAttached)
84public:
85 enum SelectionBehavior {
86 SelectionDisabled,
87 SelectCells,
88 SelectRows,
89 SelectColumns
90 };
91 Q_ENUM(SelectionBehavior)
93 enum SelectionMode {
94 SingleSelection,
95 ContiguousSelection,
96 ExtendedSelection
97 };
98 Q_ENUM(SelectionMode)
100 enum EditTrigger {
101 NoEditTriggers = 0x0,
102 SingleTapped = 0x1,
103 DoubleTapped = 0x2,
104 SelectedTapped = 0x4,
105 EditKeyPressed = 0x8,
106 AnyKeyPressed = 0x10,
107 };
108 Q_DECLARE_FLAGS(EditTriggers, EditTrigger)
109 Q_FLAG(EditTriggers)
110
111 QQuickTableView(QQuickItem *parent = nullptr);
112 ~QQuickTableView() override;
113 int rows() const;
114 int columns() const;
115
116 qreal rowSpacing() const;
117 void setRowSpacing(qreal spacing);
118
119 qreal columnSpacing() const;
120 void setColumnSpacing(qreal spacing);
121
122 QJSValue rowHeightProvider() const;
123 void setRowHeightProvider(const QJSValue &provider);
124
125 QJSValue columnWidthProvider() const;
126 void setColumnWidthProvider(const QJSValue &provider);
127
128 QVariant model() const;
129 void setModel(const QVariant &newModel);
130
131 QQmlComponent *delegate() const;
132 void setDelegate(QQmlComponent *);
133
134 bool reuseItems() const;
135 void setReuseItems(bool reuseItems);
136
137 void setContentWidth(qreal width);
138 void setContentHeight(qreal height);
139
140 QQuickTableView *syncView() const;
141 void setSyncView(QQuickTableView *view);
142
143 Qt::Orientations syncDirection() const;
144 void setSyncDirection(Qt::Orientations direction);
145
146 QItemSelectionModel *selectionModel() const;
147 void setSelectionModel(QItemSelectionModel *selectionModel);
148
149 bool animate() const;
150 void setAnimate(bool animate);
151
152 bool keyNavigationEnabled() const;
153 void setKeyNavigationEnabled(bool enabled);
154 bool pointerNavigationEnabled() const;
155 void setPointerNavigationEnabled(bool enabled);
156
157 int leftColumn() const;
158 int rightColumn() const;
159 int topRow() const;
160 int bottomRow() const;
161
162 int currentRow() const;
163 int currentColumn() const;
164
165 bool alternatingRows() const;
166 void setAlternatingRows(bool alternatingRows);
167
168 SelectionBehavior selectionBehavior() const;
169 void setSelectionBehavior(SelectionBehavior selectionBehavior);
170 SelectionMode selectionMode() const;
171 void setSelectionMode(SelectionMode selectionMode);
172
173 bool resizableColumns() const;
174 void setResizableColumns(bool enabled);
175
176 bool resizableRows() const;
177 void setResizableRows(bool enabled);
178
179 EditTriggers editTriggers() const;
180 void setEditTriggers(EditTriggers editTriggers);
181
182 QQmlDelegateModel::DelegateModelAccess delegateModelAccess() const;
183 void setDelegateModelAccess(QQmlDelegateModel::DelegateModelAccess delegateModelAccess);
184
185 bool sortingEnabled() const;
186 void setSortingEnabled(bool enabled);
187
188 int sortColumn() const;
189 void setSortColumn(int column);
190
191 Qt::SortOrder sortOrder() const;
192 void setSortOrder(Qt::SortOrder order);
193
194 Q_INVOKABLE void forceLayout();
195 Q_INVOKABLE void positionViewAtCell(const QPoint &cell, QQuickFlickable::PositionMode mode, const QPointF &offset = QPointF(), const QRectF &subRect = QRectF());
196 Q_INVOKABLE void positionViewAtIndex(const QModelIndex &index, QQuickFlickable::PositionMode mode, const QPointF &offset = QPointF(), const QRectF &subRect = QRectF());
197 Q_INVOKABLE void positionViewAtRow(int row, QQuickFlickable::PositionMode mode, qreal offset = 0, const QRectF &subRect = QRectF());
198 Q_INVOKABLE void positionViewAtColumn(int column, QQuickFlickable::PositionMode mode, qreal offset = 0, const QRectF &subRect = QRectF());
199 Q_INVOKABLE QQuickItem *itemAtCell(const QPoint &cell) const;
201 Q_REVISION(6, 4) Q_INVOKABLE QPoint cellAtPosition(const QPointF &position, bool includeSpacing = false) const;
202 Q_REVISION(6, 4) Q_INVOKABLE QPoint cellAtPosition(qreal x, qreal y, bool includeSpacing = false) const;
203#if QT_DEPRECATED_SINCE(6, 4)
204 QT_DEPRECATED_VERSION_X_6_4("Use index(row, column) instead")
205 Q_REVISION(6, 4) Q_INVOKABLE virtual QModelIndex modelIndex(int row, int column) const;
206 QT_DEPRECATED_VERSION_X_6_4("Use cellAtPosition() instead")
207 Q_INVOKABLE QPoint cellAtPos(const QPointF &position, bool includeSpacing = false) const;
208 Q_INVOKABLE QPoint cellAtPos(qreal x, qreal y, bool includeSpacing = false) const;
209#endif
211 Q_REVISION(6, 2) Q_INVOKABLE bool isColumnLoaded(int column) const;
212 Q_REVISION(6, 2) Q_INVOKABLE bool isRowLoaded(int row) const;
214 Q_REVISION(6, 2) Q_INVOKABLE qreal columnWidth(int column) const;
215 Q_REVISION(6, 2) Q_INVOKABLE qreal rowHeight(int row) const;
216 Q_REVISION(6, 2) Q_INVOKABLE qreal implicitColumnWidth(int column) const;
217 Q_REVISION(6, 2) Q_INVOKABLE qreal implicitRowHeight(int row) const;
219 Q_REVISION(6, 4) Q_INVOKABLE QModelIndex index(int row, int column) const;
220 Q_REVISION(6, 4) Q_INVOKABLE virtual QModelIndex modelIndex(const QPoint &cell) const;
221 Q_REVISION(6, 4) Q_INVOKABLE virtual QPoint cellAtIndex(const QModelIndex &index) const;
222 Q_REVISION(6, 4) Q_INVOKABLE int rowAtIndex(const QModelIndex &index) const;
223 Q_REVISION(6, 4) Q_INVOKABLE int columnAtIndex(const QModelIndex &index) const;
225 Q_REVISION(6, 5) Q_INVOKABLE void setColumnWidth(int column, qreal size);
226 Q_REVISION(6, 5) Q_INVOKABLE void clearColumnWidths();
227 Q_REVISION(6, 5) Q_INVOKABLE qreal explicitColumnWidth(int column) const;
229 Q_REVISION(6, 5) Q_INVOKABLE void setRowHeight(int row, qreal size);
230 Q_REVISION(6, 5) Q_INVOKABLE void clearRowHeights();
231 Q_REVISION(6, 5) Q_INVOKABLE qreal explicitRowHeight(int row) const;
233 Q_REVISION(6, 5) Q_INVOKABLE void edit(const QModelIndex &index);
234 Q_REVISION(6, 5) Q_INVOKABLE void closeEditor();
235
236 Q_REVISION(6, 5) Q_INVOKABLE QQuickItem *itemAtIndex(const QModelIndex &index) const;
237
238#if QT_DEPRECATED_SINCE(6, 5)
239 QT_DEPRECATED_VERSION_X_6_5("Use itemAtIndex(index(row, column)) instead")
240 Q_INVOKABLE QQuickItem *itemAtCell(int column, int row) const;
241 QT_DEPRECATED_VERSION_X_6_5("Use positionViewAtIndex(index(row, column)) instead")
242 Q_INVOKABLE void positionViewAtCell(int column, int row, QQuickFlickable::PositionMode mode, const QPointF &offset = QPointF(), const QRectF &subRect = QRectF());
243#endif
245 Q_REVISION(6, 8) Q_INVOKABLE void moveColumn(int source, int destination);
246 Q_REVISION(6, 8) Q_INVOKABLE void moveRow(int source, int destination);
247 Q_REVISION(6, 8) Q_INVOKABLE void clearColumnReordering();
248 Q_REVISION(6, 8) Q_INVOKABLE void clearRowReordering();
249
250 Q_REVISION(6, 13) Q_INVOKABLE void sortByColumn(int column, Qt::SortOrder order);
251
252 static QQuickTableViewAttached *qmlAttachedProperties(QObject *);
254Q_SIGNALS:
255 void rowsChanged();
256 void columnsChanged();
257 void rowSpacingChanged();
258 void columnSpacingChanged();
259 void rowHeightProviderChanged();
260 void columnWidthProviderChanged();
261 void modelChanged();
262 void delegateChanged();
263 void reuseItemsChanged();
264 Q_REVISION(2, 14) void syncViewChanged();
265 Q_REVISION(2, 14) void syncDirectionChanged();
266 Q_REVISION(6, 0) void leftColumnChanged();
267 Q_REVISION(6, 0) void rightColumnChanged();
268 Q_REVISION(6, 0) void topRowChanged();
269 Q_REVISION(6, 0) void bottomRowChanged();
270 Q_REVISION(6, 2) void selectionModelChanged();
271 Q_REVISION(6, 4) void animateChanged();
272 Q_REVISION(6, 4) void keyNavigationEnabledChanged();
273 Q_REVISION(6, 4) void pointerNavigationEnabledChanged();
274 Q_REVISION(6, 4) void currentRowChanged();
275 Q_REVISION(6, 4) void currentColumnChanged();
276 Q_REVISION(6, 4) void alternatingRowsChanged();
277 Q_REVISION(6, 4) void selectionBehaviorChanged();
278 Q_REVISION(6, 5) void resizableColumnsChanged();
279 Q_REVISION(6, 5) void resizableRowsChanged();
280 Q_REVISION(6, 5) void editTriggersChanged();
281 Q_REVISION(6, 5) void layoutChanged();
282 Q_REVISION(6, 6) void selectionModeChanged();
283 Q_REVISION(6, 8) void rowMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex);
284 Q_REVISION(6, 8) void columnMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex);
285 Q_REVISION(6, 10) void delegateModelAccessChanged();
286 Q_REVISION(6, 13) void sortingEnabledChanged();
287 Q_REVISION(6, 13) void sortColumnChanged();
288 Q_REVISION(6, 13) void sortOrderChanged();
289
290protected:
291 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
292 void viewportMoved(Qt::Orientations orientation) override;
293 void keyPressEvent(QKeyEvent *e) override;
294 bool eventFilter(QObject *obj, QEvent *event) override;
295
296protected:
297 QQuickTableView(QQuickTableViewPrivate &dd, QQuickItem *parent);
298 // QQmlFinalizerHook interface
299 void componentFinalized() override;
300
301private:
302 Q_DISABLE_COPY(QQuickTableView)
303 Q_DECLARE_PRIVATE(QQuickTableView)
304
305 qreal minXExtent() const override;
306 qreal maxXExtent() const override;
307 qreal minYExtent() const override;
308 qreal maxYExtent() const override;
309};
310
311class Q_QUICK_EXPORT QQuickTableViewAttached : public QObject
312{
313 Q_OBJECT
314 Q_PROPERTY(QQuickTableView *view READ view NOTIFY viewChanged FINAL)
315 Q_PROPERTY(QQmlComponent *editDelegate READ editDelegate WRITE setEditDelegate NOTIFY editDelegateChanged FINAL)
316
317public:
318 QQuickTableViewAttached(QObject *parent);
319
320 QQuickTableView *view() const { return m_view; }
321 void setView(QQuickTableView *newTableView) {
322 if (newTableView == m_view)
323 return;
324 m_view = newTableView;
325 Q_EMIT viewChanged();
326 }
327
328 QQmlComponent *editDelegate() const { return m_editDelegate; }
329 void setEditDelegate(QQmlComponent *newEditDelegate)
330 {
331 if (m_editDelegate == newEditDelegate)
332 return;
333 m_editDelegate = newEditDelegate;
334 Q_EMIT editDelegateChanged();
335 }
336
337Q_SIGNALS:
338 void viewChanged();
339 void pooled();
340 void reused();
341 void editDelegateChanged();
342 void commit();
343
344private:
345 QPointer<QQuickTableView> m_view;
346 QQmlGuard<QQmlComponent> m_editDelegate;
347
348 friend class QQuickTableViewPrivate;
349};
350
351Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickTableView::EditTriggers)
352
353QT_END_NAMESPACE
354
355#endif // QQUICKTABLEVIEW_P_H
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,...
QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2620
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
#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)