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

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