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 void sortByColumn(int column, Qt::SortOrder order);
134 void setShowGrid(bool show);
135
136protected Q_SLOTS:
137 void rowMoved(int row, int oldIndex, int newIndex);
138 void columnMoved(int column, int oldIndex, int newIndex);
139 void rowResized(int row, int oldHeight, int newHeight);
140 void columnResized(int column, int oldWidth, int newWidth);
141 void rowCountChanged(int oldCount, int newCount);
142 void columnCountChanged(int oldCount, int newCount);
143
144protected:
145 QTableView(QTableViewPrivate &, QWidget *parent);
146 void scrollContentsBy(int dx, int dy) override;
147
148 void initViewItemOption(QStyleOptionViewItem *option) const override;
149 void paintEvent(QPaintEvent *e) override;
150
151 void timerEvent(QTimerEvent *event) override;
152
153 int horizontalOffset() const override;
154 int verticalOffset() const override;
155 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
156
157 void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
158 QRegion visualRegionForSelection(const QItemSelection &selection) const override;
159 QModelIndexList selectedIndexes() const override;
160
161 void updateGeometries() override;
162
163 QSize viewportSizeHint() const override;
164
165 int sizeHintForRow(int row) const override;
166 int sizeHintForColumn(int column) const override;
167
168 void verticalScrollbarAction(int action) override;
169 void horizontalScrollbarAction(int action) override;
170
171 bool isIndexHidden(const QModelIndex &index) const override;
172
173 void selectionChanged(const QItemSelection &selected,
174 const QItemSelection &deselected) override;
175 void currentChanged(const QModelIndex &current,
176 const QModelIndex &previous) override;
177
178private:
179 friend class QAccessibleItemView;
180 int visualIndex(const QModelIndex &index) const;
181
182 Q_DECLARE_PRIVATE(QTableView)
183 Q_DISABLE_COPY(QTableView)
184 Q_PRIVATE_SLOT(d_func(), void _q_selectRow(int))
185 Q_PRIVATE_SLOT(d_func(), void _q_selectColumn(int))
186 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedRows(QModelIndex,int,int))
187 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedColumns(QModelIndex,int,int))
188 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedRows(QModelIndex,int,int))
189 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedColumns(QModelIndex,int,int))
190 Q_PRIVATE_SLOT(d_func(), void _q_sortIndicatorChanged(int column, Qt::SortOrder order))
191};
192
193QT_END_NAMESPACE
194
195#endif // QTABLEVIEW_H
196