Qt 4.8
qtreeview.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 QTREEVIEW_H
43 #define QTREEVIEW_H
44 
45 #include <QtGui/qabstractitemview.h>
46 
48 
50 
51 QT_MODULE(Gui)
52 
53 #ifndef QT_NO_TREEVIEW
54 
55 class QTreeViewPrivate;
56 class QHeaderView;
57 
59 {
60  Q_OBJECT
67  bool animated;
69  bool wordWrap;
72 
73 public:
74  explicit QTreeView(QWidget *parent = 0);
75  ~QTreeView();
76 
77  void setModel(QAbstractItemModel *model);
78  void setRootIndex(const QModelIndex &index);
79  void setSelectionModel(QItemSelectionModel *selectionModel);
80 
81  QHeaderView *header() const;
82  void setHeader(QHeaderView *header);
83 
84  int autoExpandDelay() const;
85  void setAutoExpandDelay(int delay);
86 
87  int indentation() const;
88  void setIndentation(int i);
89 
90  bool rootIsDecorated() const;
91  void setRootIsDecorated(bool show);
92 
93  bool uniformRowHeights() const;
94  void setUniformRowHeights(bool uniform);
95 
96  bool itemsExpandable() const;
97  void setItemsExpandable(bool enable);
98 
99  bool expandsOnDoubleClick() const;
100  void setExpandsOnDoubleClick(bool enable);
101 
102  int columnViewportPosition(int column) const;
103  int columnWidth(int column) const;
104  void setColumnWidth(int column, int width);
105  int columnAt(int x) const;
106 
107  bool isColumnHidden(int column) const;
108  void setColumnHidden(int column, bool hide);
109 
110  bool isHeaderHidden() const;
111  void setHeaderHidden(bool hide);
112 
113  bool isRowHidden(int row, const QModelIndex &parent) const;
114  void setRowHidden(int row, const QModelIndex &parent, bool hide);
115 
116  bool isFirstColumnSpanned(int row, const QModelIndex &parent) const;
117  void setFirstColumnSpanned(int row, const QModelIndex &parent, bool span);
118 
119  bool isExpanded(const QModelIndex &index) const;
120  void setExpanded(const QModelIndex &index, bool expand);
121 
122  void setSortingEnabled(bool enable);
123  bool isSortingEnabled() const;
124 
125  void setAnimated(bool enable);
126  bool isAnimated() const;
127 
128  void setAllColumnsShowFocus(bool enable);
129  bool allColumnsShowFocus() const;
130 
131  void setWordWrap(bool on);
132  bool wordWrap() const;
133 
134  void keyboardSearch(const QString &search);
135 
136  QRect visualRect(const QModelIndex &index) const;
137  void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
138  QModelIndex indexAt(const QPoint &p) const;
139  QModelIndex indexAbove(const QModelIndex &index) const;
140  QModelIndex indexBelow(const QModelIndex &index) const;
141 
142  void doItemsLayout();
143  void reset();
144 
145  void sortByColumn(int column, Qt::SortOrder order);
146 
147  void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
148  void selectAll();
149 
150 Q_SIGNALS:
151  void expanded(const QModelIndex &index);
152  void collapsed(const QModelIndex &index);
153 
154 public Q_SLOTS:
155  void hideColumn(int column);
156  void showColumn(int column);
157  void expand(const QModelIndex &index);
158  void collapse(const QModelIndex &index);
159  void resizeColumnToContents(int column);
160  void sortByColumn(int column);
161  void expandAll();
162  void collapseAll();
163  void expandToDepth(int depth);
164 
165 protected Q_SLOTS:
166  void columnResized(int column, int oldSize, int newSize);
167  void columnCountChanged(int oldCount, int newCount);
168  void columnMoved();
169  void reexpand();
170  void rowsRemoved(const QModelIndex &parent, int first, int last);
171 
172 protected:
173  QTreeView(QTreeViewPrivate &dd, QWidget *parent = 0);
174  void scrollContentsBy(int dx, int dy);
175  void rowsInserted(const QModelIndex &parent, int start, int end);
176  void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
177 
178  QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
179  int horizontalOffset() const;
180  int verticalOffset() const;
181 
182  void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command);
183  QRegion visualRegionForSelection(const QItemSelection &selection) const;
185 
188 
189  void drawTree(QPainter *painter, const QRegion &region) const;
190  virtual void drawRow(QPainter *painter,
191  const QStyleOptionViewItem &options,
192  const QModelIndex &index) const;
193  virtual void drawBranches(QPainter *painter,
194  const QRect &rect,
195  const QModelIndex &index) const;
196 
202 #ifndef QT_NO_DRAGANDDROP
204 #endif
205  bool viewportEvent(QEvent *event);
206 
207  void updateGeometries();
208 
209  int sizeHintForColumn(int column) const;
210  int indexRowSizeHint(const QModelIndex &index) const;
211  int rowHeight(const QModelIndex &index) const;
212 
213  void horizontalScrollbarAction(int action);
214 
215  bool isIndexHidden(const QModelIndex &index) const;
216  void selectionChanged(const QItemSelection &selected,
217  const QItemSelection &deselected);
218  void currentChanged(const QModelIndex &current, const QModelIndex &previous);
219 
220 private:
221  friend class QAccessibleItemView;
222  friend class QAccessibleTable2;
223  friend class QAccessibleTree;
224  friend class QAccessibleTable2Cell;
225  int visualIndex(const QModelIndex &index) const;
226 
229 #ifndef QT_NO_ANIMATION
230  Q_PRIVATE_SLOT(d_func(), void _q_endAnimatedOperation())
231 #endif //QT_NO_ANIMATION
232  Q_PRIVATE_SLOT(d_func(), void _q_modelAboutToBeReset())
233  Q_PRIVATE_SLOT(d_func(), void _q_sortIndicatorChanged(int column, Qt::SortOrder order))
234 };
235 
236 #endif // QT_NO_TREEVIEW
237 
239 
241 
242 #endif // QTREEVIEW_H
bool sortingEnabled
whether sorting is enabled
Definition: qtreeview.h:66
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
bool allColumnsShowFocus
whether items should show keyboard focus using all columns
Definition: qtreeview.h:68
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
This slot is called when rows are about to be removed.
The QKeyEvent class describes a key event.
Definition: qevent.h:224
The QItemSelectionModel class keeps track of a view&#39;s selected items.
bool wordWrap
the item text word-wrapping policy
Definition: qtreeview.h:69
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
Sets the current selection model to the given selectionModel.
#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...
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...
bool expandsOnDoubleClick
whether the items can be expanded by double-clicking.
Definition: qtreeview.h:71
#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
bool uniformRowHeights
whether all items in the treeview have the same height
Definition: qtreeview.h:64
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 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
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual void doItemsLayout()
This function is intended to lay out the items in the view.
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
bool headerHidden
whether the header is shown or not.
Definition: qtreeview.h:70
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
void dragMoveEvent(QDragMoveEvent *event)
This function is called continuously with the given event during a drag and drop operation over the w...
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
virtual void selectAll()
Selects all items in the view.
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.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
virtual void reset()
Reset the internal state of the view.
void keyPressEvent(QKeyEvent *event)
This function is called with the given event when a key event is sent to the widget.
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.
#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
bool animated
whether animations are enabled
Definition: qtreeview.h:67
bool itemsExpandable
whether the items are expandable by the user.
Definition: qtreeview.h:65
int autoExpandDelay
The delay time before items in a tree are opened during a drag and drop operation.
Definition: qtreeview.h:61
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This slot is called when the selection is changed.
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
bool rootIsDecorated
whether to show controls for expanding and collapsing top-level items
Definition: qtreeview.h:63
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
Definition: qnamespace.h:54
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.
#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)
int indentation
indentation of the items in the tree view.
Definition: qtreeview.h:62
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
static const KeyPair *const end
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
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.
virtual void keyboardSearch(const QString &search)
Moves to and selects the item best matching the string search.