Qt 4.8
qtableview.h
Go to the documentation of this file.
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 
48 
50 
51 QT_MODULE(Gui)
52 
53 #ifndef QT_NO_TABLEVIEW
54 
55 class QHeaderView;
56 class QTableViewPrivate;
57 
59 {
60  Q_OBJECT
61  bool showGrid;
64  bool wordWrap;
66 
67 public:
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 
124 public 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 
138 protected 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 
146 protected:
148  void scrollContentsBy(int dx, int dy);
149 
151  void paintEvent(QPaintEvent *e);
152 
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;
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 
178 private:
179  friend class QAccessibleItemView;
180  int visualIndex(const QModelIndex &index) const;
181 
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 
195 
197 
198 #endif // QTABLEVIEW_H
static QItemSelection rowAt(const QModelIndex &idx)
The QItemSelectionModel class keeps track of a view&#39;s selected items.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual QStyleOptionViewItem viewOptions() const
Returns a QStyleOptionViewItem structure populated with the view&#39;s palette, font, state...
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
Sets the current selection model to the given selectionModel.
bool sortingEnabled
whether sorting is enabled
Definition: qtableview.h:63
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
virtual bool isIndexHidden(const QModelIndex &index) const =0
Returns true if the item referred to by the given index is hidden in the view, otherwise returns fals...
virtual QRect visualRect(const QModelIndex &index) const =0
Returns the rectangle on the viewport occupied by the item at index.
bool cornerButtonEnabled
whether the button in the top-left corner is enabled
Definition: qtableview.h:65
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void timerEvent(QTimerEvent *event)
This function is called with the given event when a timer event is sent to the widget.
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
virtual void verticalScrollbarAction(int action)
Qt::PenStyle gridStyle
the pen style used to draw the grid.
Definition: qtableview.h:62
virtual int sizeHintForColumn(int column) const
Returns the width size hint for the specified column or -1 if there is no model.
#define Q_SLOTS
Definition: qobjectdefs.h:71
virtual void doItemsLayout()
This function is intended to lay out the items in the view.
virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)=0
Returns a QModelIndex object pointing to the next object in the view, based on the given cursorAction...
PenStyle
Definition: qnamespace.h:1134
virtual int verticalOffset() const =0
Returns the vertical offset of the view.
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
SortOrder
Definition: qnamespace.h:189
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events (passed in event)...
virtual void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)=0
Scrolls the view if necessary to ensure that the item at index is visible.
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
virtual int horizontalOffset() const =0
Returns the horizontal offset of the view.
The QTableView class provides a default model/view implementation of a table view.
Definition: qtableview.h:58
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QAbstractItemModel class provides the abstract interface for item model classes.
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This slot is called when the selection is changed.
bool wordWrap
the item text word-wrapping policy
Definition: qtableview.h:64
The QAbstractItemView class provides the basic functionality for item view classes.
The QItemSelection class manages information about selected items in a model.
virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)=0
Applies the selection flags to the items in or touched by the rectangle, rect.
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
virtual QModelIndexList selectedIndexes() const
This convenience function returns a list of all selected and non-hidden item indexes in the view...
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QModelIndex class is used to locate data in a data model.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
virtual void scrollContentsBy(int dx, int dy)
This virtual handler is called when the scroll bars are moved by dx, dy, and consequently the viewpor...
quint16 index
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const =0
Returns the region from the viewport of the items in the given selection.
virtual void updateGeometries()
Updates the geometry of the child widgets of the view.
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
CursorAction
This enum describes the different ways to navigate between items,.
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
Definition: qstyleoption.h:539
virtual void horizontalScrollbarAction(int action)
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
#define QT_END_HEADER
Definition: qglobal.h:137
bool showGrid
whether the grid is shown
Definition: qtableview.h:61
virtual int sizeHintForRow(int row) const
Returns the height size hint for the specified row or -1 if there is no model.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
virtual QModelIndex indexAt(const QPoint &point) const =0
Returns the model index of the item at the viewport coordinates point.