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