QtGui/qheaderview.h Source File

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 
46 
48 
50 
51 QT_MODULE(Gui)
52 
53 #ifndef QT_NO_ITEMVIEWS
54 
55 class QHeaderViewPrivate;
56 class QStyleOptionHeader;
57 
58 class Q_GUI_EXPORT QHeaderView : public QAbstractItemView
59 {
60  Q_OBJECT
61  Q_PROPERTY(bool showSortIndicator READ isSortIndicatorShown WRITE setSortIndicatorShown)
62  Q_PROPERTY(bool highlightSections READ highlightSections WRITE setHighlightSections)
63  Q_PROPERTY(bool stretchLastSection READ stretchLastSection WRITE setStretchLastSection)
64  Q_PROPERTY(bool cascadingSectionResizes READ cascadingSectionResizes WRITE setCascadingSectionResizes)
65  Q_PROPERTY(int defaultSectionSize READ defaultSectionSize WRITE setDefaultSectionSize)
66  Q_PROPERTY(int minimumSectionSize READ minimumSectionSize WRITE setMinimumSectionSize)
67  Q_PROPERTY(Qt::Alignment defaultAlignment READ defaultAlignment WRITE setDefaultAlignment)
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())
231  Q_DECLARE_PRIVATE(QHeaderView)
232  Q_DISABLE_COPY(QHeaderView)
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
GLenum GLint GLint y
Definition: GLee.h:876
GLint mode
Definition: GLee.h:4479
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
int int int int * dy
Definition: GLee.h:10535
#define QT_END_NAMESPACE
Definition: qglobal.h:128
GLintptr offset
Definition: GLee.h:1562
#define Q_PROPERTY(text)
Definition: qobjectdefs.h:80
GLuint start
Definition: GLee.h:872
void mouseReleaseEvent(QMouseEvent *event)
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
bool viewportEvent(QEvent *event)
void mousePressEvent(QMouseEvent *event)
virtual void updateGeometries()
virtual void reset()
void hideSection(int logicalIndex)
Definition: qheaderview.h:239
virtual void setModel(QAbstractItemModel *model)
virtual int verticalOffset() const =0
Definition: qnamespace.h:54
int logicalIndexAt(int position) const
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
#define Q_SLOTS
Definition: qobjectdefs.h:71
#define inline
Definition: image.h:2490
#define Q_SIGNALS
Definition: qobjectdefs.h:72
virtual bool isIndexHidden(const QModelIndex &index) const =0
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
void mouseMoveEvent(QMouseEvent *event)
Definition: qpoint.h:53
int y() const
Definition: qpoint.h:131
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
virtual void doItemsLayout()
virtual void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)=0
GLint * first
Definition: GLee.h:1362
virtual QRect visualRect(const QModelIndex &index) const =0
virtual QModelIndex indexAt(const QPoint &point) const =0
GLenum GLint x
Definition: GLee.h:876
GLuint GLuint GLsizei count
Definition: GLee.h:872
Orientation
Definition: qnamespace.h:174
GLuint GLsizei GLsizei * length
Definition: GLee.h:1713
#define Q_OBJECT
Definition: qobjectdefs.h:157
QSize sizeHint() const
GLuint GLuint end
Definition: GLee.h:872
Definition: qrect.h:58
virtual int horizontalOffset() const =0
GLfloat GLfloat p
Definition: GLee.h:5416
Definition: qsize.h:53
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
int x() const
Definition: qpoint.h:128
int int int * dx
Definition: GLee.h:10535
bool event(QEvent *event)
void showSection(int logicalIndex)
Definition: qheaderview.h:241
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const =0
virtual void scrollContentsBy(int dx, int dy)
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
#define QT_END_HEADER
Definition: qglobal.h:142
void paintEvent(QPaintEvent *)
virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)=0
void mouseDoubleClickEvent(QMouseEvent *event)
GLsizeiptr size
Definition: GLee.h:1561
virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)=0
GLuint index
Definition: GLee.h:1704
SortOrder
Definition: qnamespace.h:189