1// Copyright (C) 2016 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 QTABLEVIEW_H
5#define QTABLEVIEW_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qabstractitemview.h>
9
10QT_REQUIRE_CONFIG(tableview);
11
12QT_BEGIN_NAMESPACE
13
14class QHeaderView;
15class QTableViewPrivate;
16
17class Q_WIDGETS_EXPORT QTableView : public QAbstractItemView
18{
19 Q_OBJECT
20 Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid)
21 Q_PROPERTY(Qt::PenStyle gridStyle READ gridStyle WRITE setGridStyle)
22 Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
23 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
24#if QT_CONFIG(abstractbutton)
25 Q_PROPERTY(bool cornerButtonEnabled READ isCornerButtonEnabled WRITE setCornerButtonEnabled)
26#endif
27
28public:
29 explicit QTableView(QWidget *parent = nullptr);
30 ~QTableView();
31
32 void setModel(QAbstractItemModel *model) override;
33 void setRootIndex(const QModelIndex &index) override;
34 void setSelectionModel(QItemSelectionModel *selectionModel) override;
35 void doItemsLayout() override;
36
37 QHeaderView *horizontalHeader() const;
38 QHeaderView *verticalHeader() const;
39 void setHorizontalHeader(QHeaderView *header);
40 void setVerticalHeader(QHeaderView *header);
41
42 int rowViewportPosition(int row) const;
43 int rowAt(int y) const;
44
45 void setRowHeight(int row, int height);
46 int rowHeight(int row) const;
47
48 int columnViewportPosition(int column) const;
49 int columnAt(int x) const;
50
51 void setColumnWidth(int column, int width);
52 int columnWidth(int column) const;
53
54 bool isRowHidden(int row) const;
55 void setRowHidden(int row, bool hide);
56
57 bool isColumnHidden(int column) const;
58 void setColumnHidden(int column, bool hide);
59
60 void setSortingEnabled(bool enable);
61 bool isSortingEnabled() const;
62
63 bool showGrid() const;
64
65 Qt::PenStyle gridStyle() const;
66 void setGridStyle(Qt::PenStyle style);
67
68 void setWordWrap(bool on);
69 bool wordWrap() const;
70
71#if QT_CONFIG(abstractbutton)
72 void setCornerButtonEnabled(bool enable);
73 bool isCornerButtonEnabled() const;
74#endif
75
76 QRect visualRect(const QModelIndex &index) const override;
77 void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
78 QModelIndex indexAt(const QPoint &p) const override;
79
80 void setSpan(int row, int column, int rowSpan, int columnSpan);
81 int rowSpan(int row, int column) const;
82 int columnSpan(int row, int column) const;
83 void clearSpans();
84
85
86public Q_SLOTS:
87 void selectRow(int row);
88 void selectColumn(int column);
89 void hideRow(int row);
90 void hideColumn(int column);
91 void showRow(int row);
92 void showColumn(int column);
93 void resizeRowToContents(int row);
94 void resizeRowsToContents();
95 void resizeColumnToContents(int column);
96 void resizeColumnsToContents();
97 void sortByColumn(int column, Qt::SortOrder order);
98 void setShowGrid(bool show);
99
100protected Q_SLOTS:
101 void rowMoved(int row, int oldIndex, int newIndex);
102 void columnMoved(int column, int oldIndex, int newIndex);
103 void rowResized(int row, int oldHeight, int newHeight);
104 void columnResized(int column, int oldWidth, int newWidth);
105 void rowCountChanged(int oldCount, int newCount);
106 void columnCountChanged(int oldCount, int newCount);
107
108protected:
109 QTableView(QTableViewPrivate &, QWidget *parent);
110 void scrollContentsBy(int dx, int dy) override;
111
112 void initViewItemOption(QStyleOptionViewItem *option) const override;
113 void paintEvent(QPaintEvent *e) override;
114
115 void timerEvent(QTimerEvent *event) override;
116
117 int horizontalOffset() const override;
118 int verticalOffset() const override;
119 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
120
121 void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
122 QRegion visualRegionForSelection(const QItemSelection &selection) const override;
123 QModelIndexList selectedIndexes() const override;
124
125 void updateGeometries() override;
126
127 QSize viewportSizeHint() const override;
128
129 int sizeHintForRow(int row) const override;
130 int sizeHintForColumn(int column) const override;
131
132 void verticalScrollbarAction(int action) override;
133 void horizontalScrollbarAction(int action) override;
134
135 bool isIndexHidden(const QModelIndex &index) const override;
136
137 void selectionChanged(const QItemSelection &selected,
138 const QItemSelection &deselected) override;
139 void currentChanged(const QModelIndex &current,
140 const QModelIndex &previous) override;
141
142private:
143 friend class QAccessibleItemView;
144 int visualIndex(const QModelIndex &index) const;
145
146 Q_DECLARE_PRIVATE(QTableView)
147 Q_DISABLE_COPY(QTableView)
148 Q_PRIVATE_SLOT(d_func(), void _q_selectRow(int))
149 Q_PRIVATE_SLOT(d_func(), void _q_selectColumn(int))
150 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedRows(QModelIndex,int,int))
151 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedColumns(QModelIndex,int,int))
152 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedRows(QModelIndex,int,int))
153 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedColumns(QModelIndex,int,int))
154 Q_PRIVATE_SLOT(d_func(), void _q_sortIndicatorChanged(int column, Qt::SortOrder order))
155};
156
157QT_END_NAMESPACE
158
159#endif // QTABLEVIEW_H
160

source code of qtbase/src/widgets/itemviews/qtableview.h