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