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

Last change on this file since 619 was 561, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 8.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 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
59#ifndef QT_NO_TREEVIEW
60
61QT_BEGIN_NAMESPACE
62
63struct QTreeViewItem
64{
65 QTreeViewItem() : expanded(false), spanning(false), hasChildren(false),
66 hasMoreSiblings(false), total(0), level(0), height(0) {}
67 QModelIndex index; // we remove items whenever the indexes are invalidated
68 uint expanded : 1;
69 uint spanning : 1;
70 uint hasChildren : 1; // if the item has visible children (even if collapsed)
71 uint hasMoreSiblings : 1;
72 uint total : 28; // total number of children visible
73 uint level : 16; // indentation
74 int height : 16; // row height
75};
76
77class QTreeViewPrivate : public QAbstractItemViewPrivate
78{
79 Q_DECLARE_PUBLIC(QTreeView)
80public:
81
82 QTreeViewPrivate()
83 : QAbstractItemViewPrivate(),
84 header(0), indent(20), lastViewedItem(0), defaultItemHeight(-1),
85 uniformRowHeights(false), rootDecoration(true),
86 itemsExpandable(true), sortingEnabled(false),
87 expandsOnDoubleClick(true),
88 allColumnsShowFocus(false), current(0), spanning(false),
89 animationsEnabled(false), columnResizeTimerID(0),
90 autoExpandDelay(-1), hoverBranch(-1), geometryRecursionBlock(false) {}
91
92 ~QTreeViewPrivate() {}
93 void initialize();
94
95 QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const;
96
97#ifndef QT_NO_ANIMATION
98 struct AnimatedOperation : public QVariantAnimation
99 {
100 int item;
101 QPixmap before;
102 QPixmap after;
103 QWidget *viewport;
104 AnimatedOperation() : item(0) { setEasingCurve(QEasingCurve::InOutQuad); }
105 int top() const { return startValue().toInt(); }
106 QRect rect() const { QRect rect = viewport->rect(); rect.moveTop(top()); return rect; }
107 void updateCurrentValue(const QVariant &) { viewport->update(rect()); }
108 void updateState(State state, State) { if (state == Stopped) before = after = QPixmap(); }
109 } animatedOperation;
110 void prepareAnimatedOperation(int item, QVariantAnimation::Direction d);
111 void beginAnimatedOperation();
112 void drawAnimatedOperation(QPainter *painter) const;
113 QPixmap renderTreeToPixmapForAnimation(const QRect &rect) const;
114 void _q_endAnimatedOperation();
115#endif //QT_NO_ANIMATION
116
117 void expand(int item, bool emitSignal);
118 void collapse(int item, bool emitSignal);
119
120 void _q_columnsAboutToBeRemoved(const QModelIndex &, int, int);
121 void _q_columnsRemoved(const QModelIndex &, int, int);
122 void _q_modelAboutToBeReset();
123 void _q_sortIndicatorChanged(int column, Qt::SortOrder order);
124 void _q_modelDestroyed();
125
126 void layout(int item);
127
128 int pageUp(int item) const;
129 int pageDown(int item) const;
130
131 int itemHeight(int item) const;
132 int indentationForItem(int item) const;
133 int coordinateForItem(int item) const;
134 int itemAtCoordinate(int coordinate) const;
135
136 int viewIndex(const QModelIndex &index) const;
137 QModelIndex modelIndex(int i, int column = 0) const;
138
139 int firstVisibleItem(int *offset = 0) const;
140 int columnAt(int x) const;
141 bool hasVisibleChildren( const QModelIndex& parent) const;
142
143 void relayout(const QModelIndex &parent);
144 bool expandOrCollapseItemAtPos(const QPoint &pos);
145
146 void updateScrollBars();
147
148 int itemDecorationAt(const QPoint &pos) const;
149 QRect itemDecorationRect(const QModelIndex &index) const;
150
151
152 QList<QPair<int, int> > columnRanges(const QModelIndex &topIndex, const QModelIndex &bottomIndex) const;
153 void select(const QModelIndex &start, const QModelIndex &stop, QItemSelectionModel::SelectionFlags command);
154
155 QPair<int,int> startAndEndColumns(const QRect &rect) const;
156
157 void updateChildCount(const int parentItem, const int delta);
158 void rowsRemoved(const QModelIndex &parent,
159 int start, int end, bool before);
160
161 void paintAlternatingRowColors(QPainter *painter, QStyleOptionViewItemV4 *option, int y, int bottom) const;
162
163 QHeaderView *header;
164 int indent;
165
166 mutable QVector<QTreeViewItem> viewItems;
167 mutable int lastViewedItem;
168 int defaultItemHeight; // this is just a number; contentsHeight() / numItems
169 bool uniformRowHeights; // used when all rows have the same height
170 bool rootDecoration;
171 bool itemsExpandable;
172 bool sortingEnabled;
173 bool expandsOnDoubleClick;
174 bool allColumnsShowFocus;
175
176 // used for drawing
177 mutable QPair<int,int> leftAndRight;
178 mutable int current;
179 mutable bool spanning;
180
181 // used when expanding and collapsing items
182 QSet<QPersistentModelIndex> expandedIndexes;
183 bool animationsEnabled;
184
185 inline bool storeExpanded(const QPersistentModelIndex &idx) {
186 if (expandedIndexes.contains(idx))
187 return false;
188 expandedIndexes.insert(idx);
189 return true;
190 }
191
192 inline bool isIndexExpanded(const QModelIndex &idx) const {
193 //We first check if the idx is a QPersistentModelIndex, because creating QPersistentModelIndex is slow
194 return isPersistent(idx) && expandedIndexes.contains(idx);
195 }
196
197 // used when hiding and showing items
198 QSet<QPersistentModelIndex> hiddenIndexes;
199
200 inline bool isRowHidden(const QModelIndex &idx) const {
201 //We first check if the idx is a QPersistentModelIndex, because creating QPersistentModelIndex is slow
202 return isPersistent(idx) && hiddenIndexes.contains(idx);
203 }
204
205 inline bool isItemHiddenOrDisabled(int i) const {
206 if (i < 0 || i >= viewItems.count())
207 return false;
208 const QModelIndex index = viewItems.at(i).index;
209 return isRowHidden(index) || !isIndexEnabled(index);
210 }
211
212 inline int above(int item) const
213 { int i = item; while (isItemHiddenOrDisabled(--item)){} return item < 0 ? i : item; }
214 inline int below(int item) const
215 { int i = item; while (isItemHiddenOrDisabled(++item)){} return item >= viewItems.count() ? i : item; }
216 inline void invalidateHeightCache(int item) const
217 { viewItems[item].height = 0; }
218
219 // used for spanning rows
220 QVector<QPersistentModelIndex> spanningIndexes;
221
222 // used for updating resized columns
223 int columnResizeTimerID;
224 QList<int> columnsToUpdate;
225
226 // used for the automatic opening of nodes during DND
227 int autoExpandDelay;
228 QBasicTimer openTimer;
229
230 // used for drawing hilighted expand/collapse indicators
231 int hoverBranch;
232
233 // used for blocking recursion when calling setViewportMargins from updateGeometries
234 bool geometryRecursionBlock;
235};
236
237QT_END_NAMESPACE
238
239#endif // QT_NO_TREEVIEW
240
241#endif // QTREEVIEW_P_H
Note: See TracBrowser for help on using the repository browser.