source: trunk/src/gui/itemviews/qtreeview_p.h@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 9.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
62QT_BEGIN_NAMESPACE
63
64struct QTreeViewItem
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
70 uint expanded : 1;
71 uint spanning : 1;
72 uint hasChildren : 1; // if the item has visible children (even if collapsed)
73 uint hasMoreSiblings : 1;
74 uint total : 28; // total number of children visible
75 uint level : 16; // indentation
76 int height : 16; // row height
77};
78
79Q_DECLARE_TYPEINFO(QTreeViewItem, Q_MOVABLE_TYPE);
80
81class QTreeViewPrivate : public QAbstractItemViewPrivate
82{
83 Q_DECLARE_PUBLIC(QTreeView)
84public:
85
86 QTreeViewPrivate()
87 : QAbstractItemViewPrivate(),
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
96 ~QTreeViewPrivate() {}
97 void initialize();
98
99 QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const;
100
101#ifndef QT_NO_ANIMATION
102 struct AnimatedOperation : public QVariantAnimation
103 {
104 int item;
105 QPixmap before;
106 QPixmap after;
107 QWidget *viewport;
108 AnimatedOperation() : item(0) { setEasingCurve(QEasingCurve::InOutQuad); }
109 int top() const { return startValue().toInt(); }
110 QRect rect() const { QRect rect = viewport->rect(); rect.moveTop(top()); return rect; }
111 void updateCurrentValue(const QVariant &) { viewport->update(rect()); }
112 void updateState(State state, State) { if (state == Stopped) before = after = QPixmap(); }
113 } animatedOperation;
114 void prepareAnimatedOperation(int item, QVariantAnimation::Direction d);
115 void beginAnimatedOperation();
116 void drawAnimatedOperation(QPainter *painter) const;
117 QPixmap renderTreeToPixmapForAnimation(const QRect &rect) const;
118 void _q_endAnimatedOperation();
119#endif //QT_NO_ANIMATION
120
121 void expand(int item, bool emitSignal);
122 void collapse(int item, bool emitSignal);
123
124 void _q_columnsAboutToBeRemoved(const QModelIndex &, int, int);
125 void _q_columnsRemoved(const QModelIndex &, int, int);
126 void _q_modelAboutToBeReset();
127 void _q_sortIndicatorChanged(int column, Qt::SortOrder order);
128 void _q_modelDestroyed();
129
130 void layout(int item, bool recusiveExpanding = false, bool afterIsUninitialized = false);
131
132 int pageUp(int item) const;
133 int pageDown(int item) const;
134
135 int itemHeight(int item) const;
136 int indentationForItem(int item) const;
137 int coordinateForItem(int item) const;
138 int itemAtCoordinate(int coordinate) const;
139
140 int viewIndex(const QModelIndex &index) const;
141 QModelIndex modelIndex(int i, int column = 0) const;
142
143 void insertViewItems(int pos, int count, const QTreeViewItem &viewItem);
144 void removeViewItems(int pos, int count);
145#if 0
146 bool checkViewItems() const;
147#endif
148
149 int firstVisibleItem(int *offset = 0) const;
150 int columnAt(int x) const;
151 bool hasVisibleChildren( const QModelIndex& parent) const;
152
153 bool expandOrCollapseItemAtPos(const QPoint &pos);
154
155 void updateScrollBars();
156
157 int itemDecorationAt(const QPoint &pos) const;
158 QRect itemDecorationRect(const QModelIndex &index) const;
159
160
161 QList<QPair<int, int> > columnRanges(const QModelIndex &topIndex, const QModelIndex &bottomIndex) const;
162 void select(const QModelIndex &start, const QModelIndex &stop, QItemSelectionModel::SelectionFlags command);
163
164 QPair<int,int> startAndEndColumns(const QRect &rect) const;
165
166 void updateChildCount(const int parentItem, const int delta);
167
168 void paintAlternatingRowColors(QPainter *painter, QStyleOptionViewItemV4 *option, int y, int bottom) const;
169
170 QHeaderView *header;
171 int indent;
172
173 mutable QVector<QTreeViewItem> viewItems;
174 mutable int lastViewedItem;
175 int defaultItemHeight; // this is just a number; contentsHeight() / numItems
176 bool uniformRowHeights; // used when all rows have the same height
177 bool rootDecoration;
178 bool itemsExpandable;
179 bool sortingEnabled;
180 bool expandsOnDoubleClick;
181 bool allColumnsShowFocus;
182
183 // used for drawing
184 mutable QPair<int,int> leftAndRight;
185 mutable int current;
186 mutable bool spanning;
187
188 // used when expanding and collapsing items
189 QSet<QPersistentModelIndex> expandedIndexes;
190 bool animationsEnabled;
191
192 inline bool storeExpanded(const QPersistentModelIndex &idx) {
193 if (expandedIndexes.contains(idx))
194 return false;
195 expandedIndexes.insert(idx);
196 return true;
197 }
198
199 inline bool isIndexExpanded(const QModelIndex &idx) const {
200 //We first check if the idx is a QPersistentModelIndex, because creating QPersistentModelIndex is slow
201 return isPersistent(idx) && expandedIndexes.contains(idx);
202 }
203
204 // used when hiding and showing items
205 QSet<QPersistentModelIndex> hiddenIndexes;
206
207 inline bool isRowHidden(const QModelIndex &idx) const {
208 //We first check if the idx is a QPersistentModelIndex, because creating QPersistentModelIndex is slow
209 return isPersistent(idx) && hiddenIndexes.contains(idx);
210 }
211
212 inline bool isItemHiddenOrDisabled(int i) const {
213 if (i < 0 || i >= viewItems.count())
214 return false;
215 const QModelIndex index = viewItems.at(i).index;
216 return isRowHidden(index) || !isIndexEnabled(index);
217 }
218
219 inline int above(int item) const
220 { int i = item; while (isItemHiddenOrDisabled(--item)){} return item < 0 ? i : item; }
221 inline int below(int item) const
222 { int i = item; while (isItemHiddenOrDisabled(++item)){} return item >= viewItems.count() ? i : item; }
223 inline void invalidateHeightCache(int item) const
224 { viewItems[item].height = 0; }
225
226 // used for spanning rows
227 QVector<QPersistentModelIndex> spanningIndexes;
228
229 // used for updating resized columns
230 int columnResizeTimerID;
231 QList<int> columnsToUpdate;
232
233 // used for the automatic opening of nodes during DND
234 int autoExpandDelay;
235 QBasicTimer openTimer;
236
237 // used for drawing hilighted expand/collapse indicators
238 int hoverBranch;
239
240 // used for blocking recursion when calling setViewportMargins from updateGeometries
241 bool geometryRecursionBlock;
242
243 // If we should clean the set
244 bool hasRemovedItems;
245};
246
247QT_END_NAMESPACE
248
249#endif // QT_NO_TREEVIEW
250
251#endif // QTREEVIEW_P_H
Note: See TracBrowser for help on using the repository browser.