Qt 4.8
qtreeview_p.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_P_H
43 #define QTREEVIEW_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "private/qabstractitemview_p.h"
57 #include <QtCore/qvariantanimation.h>
58 #include <QtCore/qabstractitemmodel.h>
59 
60 #ifndef QT_NO_TREEVIEW
61 
63 
65 {
66  QTreeViewItem() : parentItem(-1), expanded(false), spanning(false), hasChildren(false),
67  hasMoreSiblings(false), total(0), level(0), height(0) {}
68  QModelIndex index; // we remove items whenever the indexes are invalidated
69  int parentItem; // parent item index in viewItems
72  uint hasChildren : 1; // if the item has visible children (even if collapsed)
74  uint total : 28; // total number of children visible
75  uint level : 16; // indentation
76  int height : 16; // row height
77 };
78 
80 
82 {
84 public:
85 
88  header(0), indent(20), lastViewedItem(0), defaultItemHeight(-1),
89  uniformRowHeights(false), rootDecoration(true),
90  itemsExpandable(true), sortingEnabled(false),
91  expandsOnDoubleClick(true),
92  allColumnsShowFocus(false), current(0), spanning(false),
93  animationsEnabled(false), columnResizeTimerID(0),
94  autoExpandDelay(-1), hoverBranch(-1), geometryRecursionBlock(false), hasRemovedItems(false) {}
95 
97  void initialize();
98 
99  QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const;
100  void adjustViewOptionsForIndex(QStyleOptionViewItemV4 *option, const QModelIndex &current) const;
101 
102 #ifndef QT_NO_ANIMATION
104  {
105  int item;
109  AnimatedOperation() : item(0) { setEasingCurve(QEasingCurve::InOutQuad); }
110  int top() const { return startValue().toInt(); }
111  QRect rect() const { QRect rect = viewport->rect(); rect.moveTop(top()); return rect; }
112  void updateCurrentValue(const QVariant &) { viewport->update(rect()); }
113  void updateState(State state, State) { if (state == Stopped) before = after = QPixmap(); }
114  } animatedOperation;
115  void prepareAnimatedOperation(int item, QVariantAnimation::Direction d);
116  void beginAnimatedOperation();
117  void drawAnimatedOperation(QPainter *painter) const;
118  QPixmap renderTreeToPixmapForAnimation(const QRect &rect) const;
119  void _q_endAnimatedOperation();
120 #endif //QT_NO_ANIMATION
121 
122  void expand(int item, bool emitSignal);
123  void collapse(int item, bool emitSignal);
124 
125  void _q_columnsAboutToBeRemoved(const QModelIndex &, int, int);
126  void _q_columnsRemoved(const QModelIndex &, int, int);
127  void _q_modelAboutToBeReset();
128  void _q_sortIndicatorChanged(int column, Qt::SortOrder order);
129  void _q_modelDestroyed();
130 
131  void layout(int item, bool recusiveExpanding = false, bool afterIsUninitialized = false);
132 
133  int pageUp(int item) const;
134  int pageDown(int item) const;
135 
136  int itemHeight(int item) const;
137  int indentationForItem(int item) const;
138  int coordinateForItem(int item) const;
139  int itemAtCoordinate(int coordinate) const;
140 
141  int viewIndex(const QModelIndex &index) const;
142  QModelIndex modelIndex(int i, int column = 0) const;
143 
144  void insertViewItems(int pos, int count, const QTreeViewItem &viewItem);
145  void removeViewItems(int pos, int count);
146 #if 0
147  bool checkViewItems() const;
148 #endif
149 
150  int firstVisibleItem(int *offset = 0) const;
151  int columnAt(int x) const;
152  bool hasVisibleChildren( const QModelIndex& parent) const;
153 
154  bool expandOrCollapseItemAtPos(const QPoint &pos);
155 
156  void updateScrollBars();
157 
158  int itemDecorationAt(const QPoint &pos) const;
159  QRect itemDecorationRect(const QModelIndex &index) const;
160 
161 
162  QList<QPair<int, int> > columnRanges(const QModelIndex &topIndex, const QModelIndex &bottomIndex) const;
163  void select(const QModelIndex &start, const QModelIndex &stop, QItemSelectionModel::SelectionFlags command);
164 
165  QPair<int,int> startAndEndColumns(const QRect &rect) const;
166 
167  void updateChildCount(const int parentItem, const int delta);
168 
169  void paintAlternatingRowColors(QPainter *painter, QStyleOptionViewItemV4 *option, int y, int bottom) const;
170 
171  // logicalIndices: vector of currently visibly logical indices
172  // itemPositions: vector of view item positions (beginning/middle/end/onlyone)
173  void calcLogicalIndices(QVector<int> *logicalIndices, QVector<QStyleOptionViewItemV4::ViewItemPosition> *itemPositions, int left, int right) const;
174 
176  int indent;
177 
179  mutable int lastViewedItem;
180  int defaultItemHeight; // this is just a number; contentsHeight() / numItems
181  bool uniformRowHeights; // used when all rows have the same height
187 
188  // used for drawing
190  mutable int current;
191  mutable bool spanning;
192 
193  // used when expanding and collapsing items
196 
197  inline bool storeExpanded(const QPersistentModelIndex &idx) {
198  if (expandedIndexes.contains(idx))
199  return false;
200  expandedIndexes.insert(idx);
201  return true;
202  }
203 
204  inline bool isIndexExpanded(const QModelIndex &idx) const {
205  //We first check if the idx is a QPersistentModelIndex, because creating QPersistentModelIndex is slow
206  return isPersistent(idx) && expandedIndexes.contains(idx);
207  }
208 
209  // used when hiding and showing items
211 
212  inline bool isRowHidden(const QModelIndex &idx) const {
213  //We first check if the idx is a QPersistentModelIndex, because creating QPersistentModelIndex is slow
214  return isPersistent(idx) && hiddenIndexes.contains(idx);
215  }
216 
217  inline bool isItemHiddenOrDisabled(int i) const {
218  if (i < 0 || i >= viewItems.count())
219  return false;
220  const QModelIndex index = viewItems.at(i).index;
221  return isRowHidden(index) || !isIndexEnabled(index);
222  }
223 
224  inline int above(int item) const
225  { int i = item; while (isItemHiddenOrDisabled(--item)){} return item < 0 ? i : item; }
226  inline int below(int item) const
227  { int i = item; while (isItemHiddenOrDisabled(++item)){} return item >= viewItems.count() ? i : item; }
228  inline void invalidateHeightCache(int item) const
229  { viewItems[item].height = 0; }
230 
231  inline int accessibleTable2Index(const QModelIndex &index) const {
232  return (viewIndex(index) + (header ? 1 : 0)) * model->columnCount()+index.column() + 1;
233  }
234 
235  // used for spanning rows
237 
238  // used for updating resized columns
241 
242  // used for the automatic opening of nodes during DND
245 
246  // used for drawing hilighted expand/collapse indicators
247  mutable int hoverBranch;
248 
249  // used for blocking recursion when calling setViewportMargins from updateGeometries
251 
252  // If we should clean the set
254 };
255 
257 
258 #endif // QT_NO_TREEVIEW
259 
260 #endif // QTREEVIEW_P_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool isItemHiddenOrDisabled(int i) const
Definition: qtreeview_p.h:217
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QSet< QPersistentModelIndex > expandedIndexes
Definition: qtreeview_p.h:194
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
QVector< QPersistentModelIndex > spanningIndexes
Definition: qtreeview_p.h:236
void updateState(State state, State)
Definition: qtreeview_p.h:113
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
bool isIndexExpanded(const QModelIndex &idx) const
Definition: qtreeview_p.h:204
SortOrder
Definition: qnamespace.h:189
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Direction
This enum describes the direction of the animation when in Running state.
bool contains(const T &value) const
Definition: qset.h:91
The QVariantAnimation class provides an abstract base class for animations.
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
void updateCurrentValue(const QVariant &)
This pure virtual function is called every time the animation&#39;s current value changes.
Definition: qtreeview_p.h:112
const char * layout
const_iterator insert(const T &value)
Definition: qset.h:179
unsigned int uint
Definition: qglobal.h:996
QPair< int, int > leftAndRight
Definition: qtreeview_p.h:189
QList< int > columnsToUpdate
Definition: qtreeview_p.h:240
The State element defines configurations of objects and properties.
int above(int item) const
Definition: qtreeview_p.h:224
uint hasMoreSiblings
Definition: qtreeview_p.h:73
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void invalidateHeightCache(int item) const
Definition: qtreeview_p.h:228
bool isRowHidden(const QModelIndex &idx) const
Definition: qtreeview_p.h:212
QSet< QPersistentModelIndex > hiddenIndexes
Definition: qtreeview_p.h:210
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
The QPersistentModelIndex class is used to locate data in a data model.
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
uint hasChildren
Definition: qtreeview_p.h:72
bool storeExpanded(const QPersistentModelIndex &idx)
Definition: qtreeview_p.h:197
QModelIndex index
Definition: qtreeview_p.h:68
QVector< QTreeViewItem > viewItems
Definition: qtreeview_p.h:178
bool expandsOnDoubleClick
Definition: qtreeview_p.h:185
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QBasicTimer class provides timer events for objects.
Definition: qbasictimer.h:55
int accessibleTable2Index(const QModelIndex &index) const
Definition: qtreeview_p.h:231
QBasicTimer openTimer
Definition: qtreeview_p.h:244
int below(int item) const
Definition: qtreeview_p.h:226
Q_DECLARE_TYPEINFO(QTreeViewItem, Q_MOVABLE_TYPE)
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top edge at the given y coordinate.
Definition: qrect.h:353
bool allColumnsShowFocus
Definition: qtreeview_p.h:186
QHeaderView * header
Definition: qtreeview_p.h:175
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
int column() const
Returns the column this model index refers to.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
bool geometryRecursionBlock
Definition: qtreeview_p.h:250