1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QTABLEVIEW_H
41#define QTABLEVIEW_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtWidgets/qabstractitemview.h>
45
46QT_REQUIRE_CONFIG(tableview);
47
48QT_BEGIN_NAMESPACE
49
50class QHeaderView;
51class QTableViewPrivate;
52
53class Q_WIDGETS_EXPORT QTableView : public QAbstractItemView
54{
55 Q_OBJECT
56 Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid)
57 Q_PROPERTY(Qt::PenStyle gridStyle READ gridStyle WRITE setGridStyle)
58 Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
59 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
60#if QT_CONFIG(abstractbutton)
61 Q_PROPERTY(bool cornerButtonEnabled READ isCornerButtonEnabled WRITE setCornerButtonEnabled)
62#endif
63
64public:
65 explicit QTableView(QWidget *parent = nullptr);
66 ~QTableView();
67
68 void setModel(QAbstractItemModel *model) override;
69 void setRootIndex(const QModelIndex &index) override;
70 void setSelectionModel(QItemSelectionModel *selectionModel) override;
71 void doItemsLayout() override;
72
73 QHeaderView *horizontalHeader() const;
74 QHeaderView *verticalHeader() const;
75 void setHorizontalHeader(QHeaderView *header);
76 void setVerticalHeader(QHeaderView *header);
77
78 int rowViewportPosition(int row) const;
79 int rowAt(int y) const;
80
81 void setRowHeight(int row, int height);
82 int rowHeight(int row) const;
83
84 int columnViewportPosition(int column) const;
85 int columnAt(int x) const;
86
87 void setColumnWidth(int column, int width);
88 int columnWidth(int column) const;
89
90 bool isRowHidden(int row) const;
91 void setRowHidden(int row, bool hide);
92
93 bool isColumnHidden(int column) const;
94 void setColumnHidden(int column, bool hide);
95
96 void setSortingEnabled(bool enable);
97 bool isSortingEnabled() const;
98
99 bool showGrid() const;
100
101 Qt::PenStyle gridStyle() const;
102 void setGridStyle(Qt::PenStyle style);
103
104 void setWordWrap(bool on);
105 bool wordWrap() const;
106
107#if QT_CONFIG(abstractbutton)
108 void setCornerButtonEnabled(bool enable);
109 bool isCornerButtonEnabled() const;
110#endif
111
112 QRect visualRect(const QModelIndex &index) const override;
113 void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
114 QModelIndex indexAt(const QPoint &p) const override;
115
116 void setSpan(int row, int column, int rowSpan, int columnSpan);
117 int rowSpan(int row, int column) const;
118 int columnSpan(int row, int column) const;
119 void clearSpans();
120
121
122public Q_SLOTS:
123 void selectRow(int row);
124 void selectColumn(int column);
125 void hideRow(int row);
126 void hideColumn(int column);
127 void showRow(int row);
128 void showColumn(int column);
129 void resizeRowToContents(int row);
130 void resizeRowsToContents();
131 void resizeColumnToContents(int column);
132 void resizeColumnsToContents();
133#if QT_DEPRECATED_SINCE(5, 13)
134 QT_DEPRECATED_X ("Use QTableView::sortByColumn(int column, Qt::SortOrder order) instead")
135 void sortByColumn(int column);
136#endif
137 void sortByColumn(int column, Qt::SortOrder order);
138 void setShowGrid(bool show);
139
140protected Q_SLOTS:
141 void rowMoved(int row, int oldIndex, int newIndex);
142 void columnMoved(int column, int oldIndex, int newIndex);
143 void rowResized(int row, int oldHeight, int newHeight);
144 void columnResized(int column, int oldWidth, int newWidth);
145 void rowCountChanged(int oldCount, int newCount);
146 void columnCountChanged(int oldCount, int newCount);
147
148protected:
149 QTableView(QTableViewPrivate &, QWidget *parent);
150 void scrollContentsBy(int dx, int dy) override;
151
152 QStyleOptionViewItem viewOptions() const override;
153 void paintEvent(QPaintEvent *e) override;
154
155 void timerEvent(QTimerEvent *event) override;
156
157 int horizontalOffset() const override;
158 int verticalOffset() const override;
159 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
160
161 void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
162 QRegion visualRegionForSelection(const QItemSelection &selection) const override;
163 QModelIndexList selectedIndexes() const override;
164
165 void updateGeometries() override;
166
167 QSize viewportSizeHint() const override;
168
169 int sizeHintForRow(int row) const override;
170 int sizeHintForColumn(int column) const override;
171
172 void verticalScrollbarAction(int action) override;
173 void horizontalScrollbarAction(int action) override;
174
175 bool isIndexHidden(const QModelIndex &index) const override;
176
177 void selectionChanged(const QItemSelection &selected,
178 const QItemSelection &deselected) override;
179 void currentChanged(const QModelIndex &current,
180 const QModelIndex &previous) override;
181
182private:
183 friend class QAccessibleItemView;
184 int visualIndex(const QModelIndex &index) const;
185
186 Q_DECLARE_PRIVATE(QTableView)
187 Q_DISABLE_COPY(QTableView)
188 Q_PRIVATE_SLOT(d_func(), void _q_selectRow(int))
189 Q_PRIVATE_SLOT(d_func(), void _q_selectColumn(int))
190 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedRows(QModelIndex,int,int))
191 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedColumns(QModelIndex,int,int))
192 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedRows(QModelIndex,int,int))
193 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedColumns(QModelIndex,int,int))
194 Q_PRIVATE_SLOT(d_func(), void _q_sortIndicatorChanged(int column, Qt::SortOrder order))
195};
196
197QT_END_NAMESPACE
198
199#endif // QTABLEVIEW_H
200