1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtGui 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 Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QTABLEVIEW_H
43#define QTABLEVIEW_H
44
45#include <QtGui/qabstractitemview.h>
46
47QT_BEGIN_HEADER
48
49QT_BEGIN_NAMESPACE
50
51QT_MODULE(Gui)
52
53#ifndef QT_NO_TABLEVIEW
54
55class QHeaderView;
56class QTableViewPrivate;
57
58class Q_GUI_EXPORT QTableView : public QAbstractItemView
59{
60 Q_OBJECT
61 Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid)
62 Q_PROPERTY(Qt::PenStyle gridStyle READ gridStyle WRITE setGridStyle)
63 Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
64 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
65 Q_PROPERTY(bool cornerButtonEnabled READ isCornerButtonEnabled WRITE setCornerButtonEnabled)
66
67public:
68 explicit QTableView(QWidget *parent = 0);
69 ~QTableView();
70
71 void setModel(QAbstractItemModel *model);
72 void setRootIndex(const QModelIndex &index);
73 void setSelectionModel(QItemSelectionModel *selectionModel);
74 void doItemsLayout();
75
76 QHeaderView *horizontalHeader() const;
77 QHeaderView *verticalHeader() const;
78 void setHorizontalHeader(QHeaderView *header);
79 void setVerticalHeader(QHeaderView *header);
80
81 int rowViewportPosition(int row) const;
82 int rowAt(int y) const;
83
84 void setRowHeight(int row, int height);
85 int rowHeight(int row) const;
86
87 int columnViewportPosition(int column) const;
88 int columnAt(int x) const;
89
90 void setColumnWidth(int column, int width);
91 int columnWidth(int column) const;
92
93 bool isRowHidden(int row) const;
94 void setRowHidden(int row, bool hide);
95
96 bool isColumnHidden(int column) const;
97 void setColumnHidden(int column, bool hide);
98
99 void setSortingEnabled(bool enable);
100 bool isSortingEnabled() const;
101
102 bool showGrid() const;
103
104 Qt::PenStyle gridStyle() const;
105 void setGridStyle(Qt::PenStyle style);
106
107 void setWordWrap(bool on);
108 bool wordWrap() const;
109
110 void setCornerButtonEnabled(bool enable);
111 bool isCornerButtonEnabled() const;
112
113 QRect visualRect(const QModelIndex &index) const;
114 void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
115 QModelIndex indexAt(const QPoint &p) const;
116
117 void setSpan(int row, int column, int rowSpan, int columnSpan);
118 int rowSpan(int row, int column) const;
119 int columnSpan(int row, int column) const;
120 void clearSpans();
121
122 void sortByColumn(int column, Qt::SortOrder order);
123
124public Q_SLOTS:
125 void selectRow(int row);
126 void selectColumn(int column);
127 void hideRow(int row);
128 void hideColumn(int column);
129 void showRow(int row);
130 void showColumn(int column);
131 void resizeRowToContents(int row);
132 void resizeRowsToContents();
133 void resizeColumnToContents(int column);
134 void resizeColumnsToContents();
135 void sortByColumn(int column);
136 void setShowGrid(bool show);
137
138protected Q_SLOTS:
139 void rowMoved(int row, int oldIndex, int newIndex);
140 void columnMoved(int column, int oldIndex, int newIndex);
141 void rowResized(int row, int oldHeight, int newHeight);
142 void columnResized(int column, int oldWidth, int newWidth);
143 void rowCountChanged(int oldCount, int newCount);
144 void columnCountChanged(int oldCount, int newCount);
145
146protected:
147 QTableView(QTableViewPrivate &, QWidget *parent);
148 void scrollContentsBy(int dx, int dy);
149
150 QStyleOptionViewItem viewOptions() const;
151 void paintEvent(QPaintEvent *e);
152
153 void timerEvent(QTimerEvent *event);
154
155 int horizontalOffset() const;
156 int verticalOffset() const;
157 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
158
159 void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command);
160 QRegion visualRegionForSelection(const QItemSelection &selection) const;
161 QModelIndexList selectedIndexes() const;
162
163 void updateGeometries();
164
165 int sizeHintForRow(int row) const;
166 int sizeHintForColumn(int column) const;
167
168 void verticalScrollbarAction(int action);
169 void horizontalScrollbarAction(int action);
170
171 bool isIndexHidden(const QModelIndex &index) const;
172
173 void selectionChanged(const QItemSelection &selected,
174 const QItemSelection &deselected);
175 void currentChanged(const QModelIndex &current,
176 const QModelIndex &previous);
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};
191
192#endif // QT_NO_TABLEVIEW
193
194QT_END_NAMESPACE
195
196QT_END_HEADER
197
198#endif // QTABLEVIEW_H
199