Qt 4.8
qheaderview.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 QHEADERVIEW_H
43 #define QHEADERVIEW_H
44 
45 #include <QtGui/qabstractitemview.h>
46 
48 
50 
51 QT_MODULE(Gui)
52 
53 #ifndef QT_NO_ITEMVIEWS
54 
55 class QHeaderViewPrivate;
56 class QStyleOptionHeader;
57 
59 {
60  Q_OBJECT
67  Qt::Alignment defaultAlignment;
69 
70 public:
71 
73  {
78  Custom = Fixed
79  };
80 
81  explicit QHeaderView(Qt::Orientation orientation, QWidget *parent = 0);
82  virtual ~QHeaderView();
83 
84  void setModel(QAbstractItemModel *model);
85 
86  Qt::Orientation orientation() const;
87  int offset() const;
88  int length() const;
89  QSize sizeHint() const;
90  int sectionSizeHint(int logicalIndex) const;
91 
92  int visualIndexAt(int position) const;
93  int logicalIndexAt(int position) const;
94 
95  inline int logicalIndexAt(int x, int y) const;
96  inline int logicalIndexAt(const QPoint &pos) const;
97 
98  int sectionSize(int logicalIndex) const;
99  int sectionPosition(int logicalIndex) const;
100  int sectionViewportPosition(int logicalIndex) const;
101 
102  void moveSection(int from, int to);
103  void swapSections(int first, int second);
104  void resizeSection(int logicalIndex, int size);
105  void resizeSections(QHeaderView::ResizeMode mode);
106 
107  bool isSectionHidden(int logicalIndex) const;
108  void setSectionHidden(int logicalIndex, bool hide);
109  int hiddenSectionCount() const;
110 
111  inline void hideSection(int logicalIndex);
112  inline void showSection(int logicalIndex);
113 
114  int count() const;
115  int visualIndex(int logicalIndex) const;
116  int logicalIndex(int visualIndex) const;
117 
118  void setMovable(bool movable);
119  bool isMovable() const;
120 
121  void setClickable(bool clickable);
122  bool isClickable() const;
123 
124  void setHighlightSections(bool highlight);
125  bool highlightSections() const;
126 
127  void setResizeMode(ResizeMode mode);
128  void setResizeMode(int logicalIndex, ResizeMode mode);
129  ResizeMode resizeMode(int logicalIndex) const;
130  int stretchSectionCount() const;
131 
132  void setSortIndicatorShown(bool show);
133  bool isSortIndicatorShown() const;
134 
135  void setSortIndicator(int logicalIndex, Qt::SortOrder order);
136  int sortIndicatorSection() const;
137  Qt::SortOrder sortIndicatorOrder() const;
138 
139  bool stretchLastSection() const;
140  void setStretchLastSection(bool stretch);
141 
142  bool cascadingSectionResizes() const;
143  void setCascadingSectionResizes(bool enable);
144 
145  int defaultSectionSize() const;
146  void setDefaultSectionSize(int size);
147 
148  int minimumSectionSize() const;
149  void setMinimumSectionSize(int size);
150 
151  Qt::Alignment defaultAlignment() const;
152  void setDefaultAlignment(Qt::Alignment alignment);
153 
154  void doItemsLayout();
155  bool sectionsMoved() const;
156  bool sectionsHidden() const;
157 
158 #ifndef QT_NO_DATASTREAM
159  QByteArray saveState() const;
160  bool restoreState(const QByteArray &state);
161 #endif
162 
163  void reset();
164 
165 public Q_SLOTS:
166  void setOffset(int offset);
167  void setOffsetToSectionPosition(int visualIndex);
168  void setOffsetToLastSection();
169  void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast);
170 
171 Q_SIGNALS:
172  void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex);
173  void sectionResized(int logicalIndex, int oldSize, int newSize);
174  void sectionPressed(int logicalIndex);
175  void sectionClicked(int logicalIndex);
176  void sectionEntered(int logicalIndex);
177  void sectionDoubleClicked(int logicalIndex);
178  void sectionCountChanged(int oldCount, int newCount);
179  void sectionHandleDoubleClicked(int logicalIndex);
180  void sectionAutoResize(int logicalIndex, QHeaderView::ResizeMode mode);
181  void geometriesChanged();
182  void sortIndicatorChanged(int logicalIndex, Qt::SortOrder order);
183 
184 protected Q_SLOTS:
185  void updateSection(int logicalIndex);
186  void resizeSections();
187  void sectionsInserted(const QModelIndex &parent, int logicalFirst, int logicalLast);
188  void sectionsAboutToBeRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast);
189 
190 protected:
191  QHeaderView(QHeaderViewPrivate &dd, Qt::Orientation orientation, QWidget *parent = 0);
192  void initialize();
193 
194  void initializeSections();
195  void initializeSections(int start, int end);
196  void currentChanged(const QModelIndex &current, const QModelIndex &old);
197 
198  bool event(QEvent *e);
199  void paintEvent(QPaintEvent *e);
200  void mousePressEvent(QMouseEvent *e);
201  void mouseMoveEvent(QMouseEvent *e);
204  bool viewportEvent(QEvent *e);
205 
206  virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
207  virtual QSize sectionSizeFromContents(int logicalIndex) const;
208 
209  int horizontalOffset() const;
210  int verticalOffset() const;
211  void updateGeometries();
212  void scrollContentsBy(int dx, int dy);
213 
214  void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
215  void rowsInserted(const QModelIndex &parent, int start, int end);
216 
217  QRect visualRect(const QModelIndex &index) const;
218  void scrollTo(const QModelIndex &index, ScrollHint hint);
219 
220  QModelIndex indexAt(const QPoint &p) const;
221  bool isIndexHidden(const QModelIndex &index) const;
222 
223  QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
224  void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags);
225  QRegion visualRegionForSelection(const QItemSelection &selection) const;
226  void initStyleOption(QStyleOptionHeader *option) const;
227 
228 private:
229  Q_PRIVATE_SLOT(d_func(), void _q_sectionsRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast))
230  Q_PRIVATE_SLOT(d_func(), void _q_layoutAboutToBeChanged())
233 };
234 
235 inline int QHeaderView::logicalIndexAt(int ax, int ay) const
236 { return orientation() == Qt::Horizontal ? logicalIndexAt(ax) : logicalIndexAt(ay); }
237 inline int QHeaderView::logicalIndexAt(const QPoint &apos) const
238 { return logicalIndexAt(apos.x(), apos.y()); }
239 inline void QHeaderView::hideSection(int alogicalIndex)
240 { setSectionHidden(alogicalIndex, true); }
241 inline void QHeaderView::showSection(int alogicalIndex)
242 { setSectionHidden(alogicalIndex, false); }
243 
244 #endif // QT_NO_ITEMVIEWS
245 
247 
249 
250 #endif // QHEADERVIEW_H
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
int defaultSectionSize
the default size of the header sections before resizing.
Definition: qheaderview.h:65
bool showSortIndicator
whether the sort indicator is shown
Definition: qheaderview.h:61
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
void mouseMoveEvent(QMouseEvent *event)
This function is called with the given event when a mouse move event is sent to the widget...
The QStyleOptionHeader class is used to describe the parameters for drawing a header.
Definition: qstyleoption.h:251
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.
void mouseDoubleClickEvent(QMouseEvent *event)
This function is called with the given event when a mouse button is double clicked inside the widget...
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#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
#define Q_SLOTS
Definition: qobjectdefs.h:71
virtual void doItemsLayout()
This function is intended to lay out the items in the view.
ResizeMode
The resize mode specifies the behavior of the header sections.
Definition: qheaderview.h:72
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...
#define Q_SIGNALS
Definition: qobjectdefs.h:72
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
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
int minimumSectionSize
the minimum size of the header sections.
Definition: qheaderview.h:66
#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.
bool highlightSections
whether the sections containing selected items are highlighted
Definition: qheaderview.h:62
virtual void reset()
Reset the internal state of the view.
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.
bool cascadingSectionResizes
whether interactive resizing will be cascaded to the following sections once the section being resize...
Definition: qheaderview.h:64
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QAbstractItemModel class provides the abstract interface for item model classes.
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
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.
void hideSection(int logicalIndex)
Hides the section specified by logicalIndex.
Definition: qheaderview.h:239
void showSection(int logicalIndex)
Shows the section specified by logicalIndex.
Definition: qheaderview.h:241
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
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
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
void mouseReleaseEvent(QMouseEvent *event)
This function is called with the given event when a mouse button is released, after a mouse press eve...
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows are inserted.
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This slot is called when items are changed in the model.
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.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
CursorAction
This enum describes the different ways to navigate between items,.
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
Qt::Alignment defaultAlignment
the default alignment of the text in each header section
Definition: qheaderview.h:67
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
static const KeyPair *const end
Orientation
Definition: qnamespace.h:174
bool event(QEvent *event)
Reimplemented Function
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
QSize sizeHint() const
Reimplemented Function
void mousePressEvent(QMouseEvent *event)
This function is called with the given event when a mouse button is pressed while the cursor is insid...
bool viewportEvent(QEvent *event)
This function is used to handle tool tips, and What&#39;s This? mode, if the given event is a QEvent::Too...
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.
bool stretchLastSection
whether the last visible section in the header takes up all the available space
Definition: qheaderview.h:63