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 QTREEWIDGET_P_H
|
|
43 |
#define QTREEWIDGET_P_H
|
|
44 |
|
|
45 |
//
|
|
46 |
// W A R N I N G
|
|
47 |
// -------------
|
|
48 |
//
|
|
49 |
// This file is not part of the Qt API. This header file may change
|
|
50 |
// from version to version without notice, or even be removed.
|
|
51 |
//
|
|
52 |
// We mean it.
|
|
53 |
//
|
|
54 |
|
|
55 |
#include <QtCore/qabstractitemmodel.h>
|
|
56 |
#include <private/qabstractitemmodel_p.h>
|
|
57 |
#include <QtCore/qpair.h>
|
|
58 |
#include <QtCore/qbasictimer.h>
|
|
59 |
#include <QtGui/qtreewidget.h>
|
|
60 |
#include <private/qtreeview_p.h>
|
|
61 |
#include <QtGui/qheaderview.h>
|
|
62 |
|
|
63 |
#ifndef QT_NO_TREEWIDGET
|
|
64 |
|
|
65 |
QT_BEGIN_NAMESPACE
|
|
66 |
|
|
67 |
class QTreeWidgetItem;
|
|
68 |
class QTreeWidgetItemIterator;
|
|
69 |
class QTreeModelPrivate;
|
|
70 |
|
|
71 |
class QTreeModel : public QAbstractItemModel
|
|
72 |
{
|
|
73 |
Q_OBJECT
|
|
74 |
friend class QTreeWidget;
|
|
75 |
friend class QTreeWidgetPrivate;
|
|
76 |
friend class QTreeWidgetItem;
|
|
77 |
friend class QTreeWidgetItemPrivate;
|
|
78 |
friend class QTreeWidgetItemIterator;
|
|
79 |
friend class QTreeWidgetItemIteratorPrivate;
|
|
80 |
|
|
81 |
public:
|
|
82 |
explicit QTreeModel(int columns = 0, QTreeWidget *parent = 0);
|
|
83 |
~QTreeModel();
|
|
84 |
|
|
85 |
inline QTreeWidget *view() const
|
|
86 |
{ return qobject_cast<QTreeWidget*>(QObject::parent()); }
|
|
87 |
|
|
88 |
void clear();
|
|
89 |
void setColumnCount(int columns);
|
|
90 |
|
|
91 |
QTreeWidgetItem *item(const QModelIndex &index) const;
|
|
92 |
void itemChanged(QTreeWidgetItem *item);
|
|
93 |
|
|
94 |
QModelIndex index(const QTreeWidgetItem *item, int column) const;
|
|
95 |
QModelIndex index(int row, int column, const QModelIndex &parent) const;
|
|
96 |
QModelIndex parent(const QModelIndex &child) const;
|
|
97 |
int rowCount(const QModelIndex &parent) const;
|
|
98 |
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|
99 |
bool hasChildren(const QModelIndex &parent) const;
|
|
100 |
|
|
101 |
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
102 |
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
|
103 |
|
|
104 |
QMap<int, QVariant> itemData(const QModelIndex &index) const;
|
|
105 |
|
|
106 |
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|
107 |
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
|
|
108 |
int role);
|
|
109 |
|
|
110 |
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
111 |
|
|
112 |
void sort(int column, Qt::SortOrder order);
|
|
113 |
void ensureSorted(int column, Qt::SortOrder order,
|
|
114 |
int start, int end, const QModelIndex &parent);
|
|
115 |
static bool itemLessThan(const QPair<QTreeWidgetItem*,int> &left,
|
|
116 |
const QPair<QTreeWidgetItem*,int> &right);
|
|
117 |
static bool itemGreaterThan(const QPair<QTreeWidgetItem*,int> &left,
|
|
118 |
const QPair<QTreeWidgetItem*,int> &right);
|
|
119 |
static QList<QTreeWidgetItem*>::iterator sortedInsertionIterator(
|
|
120 |
const QList<QTreeWidgetItem*>::iterator &begin,
|
|
121 |
const QList<QTreeWidgetItem*>::iterator &end,
|
|
122 |
Qt::SortOrder order, QTreeWidgetItem *item);
|
|
123 |
|
|
124 |
bool insertRows(int row, int count, const QModelIndex &);
|
|
125 |
bool insertColumns(int column, int count, const QModelIndex &);
|
|
126 |
|
|
127 |
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
|
128 |
|
|
129 |
// dnd
|
|
130 |
QStringList mimeTypes() const;
|
|
131 |
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
|
132 |
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
|
|
133 |
int row, int column, const QModelIndex &parent);
|
|
134 |
Qt::DropActions supportedDropActions() const;
|
|
135 |
|
|
136 |
QMimeData *internalMimeData() const;
|
|
137 |
|
|
138 |
inline QModelIndex createIndexFromItem(int row, int col, QTreeWidgetItem *item) const
|
|
139 |
{ return createIndex(row, col, item); }
|
|
140 |
|
|
141 |
protected:
|
|
142 |
QTreeModel(QTreeModelPrivate &, QTreeWidget *parent = 0);
|
|
143 |
void emitDataChanged(QTreeWidgetItem *item, int column);
|
|
144 |
void beginInsertItems(QTreeWidgetItem *parent, int row, int count);
|
|
145 |
void endInsertItems();
|
|
146 |
void beginRemoveItems(QTreeWidgetItem *parent, int row, int count);
|
|
147 |
void endRemoveItems();
|
|
148 |
void sortItems(QList<QTreeWidgetItem*> *items, int column, Qt::SortOrder order);
|
|
149 |
void timerEvent(QTimerEvent *);
|
|
150 |
|
|
151 |
private:
|
|
152 |
QTreeWidgetItem *rootItem;
|
|
153 |
QTreeWidgetItem *headerItem;
|
|
154 |
|
|
155 |
mutable QModelIndexList cachedIndexes;
|
|
156 |
QList<QTreeWidgetItemIterator*> iterators;
|
|
157 |
|
|
158 |
mutable QBasicTimer sortPendingTimer;
|
|
159 |
mutable bool skipPendingSort; //while doing internal operation we don't care about sorting
|
|
160 |
bool inline executePendingSort() const;
|
|
161 |
|
|
162 |
bool isChanging() const;
|
|
163 |
|
|
164 |
private:
|
|
165 |
Q_DECLARE_PRIVATE(QTreeModel)
|
|
166 |
public:
|
|
167 |
struct SkipSorting
|
|
168 |
{
|
|
169 |
const QTreeModel * const model;
|
|
170 |
const bool previous;
|
|
171 |
SkipSorting(const QTreeModel *m) : model(m), previous(model->skipPendingSort)
|
|
172 |
{ model->skipPendingSort = true; }
|
|
173 |
~SkipSorting() { model->skipPendingSort = previous; }
|
|
174 |
};
|
|
175 |
friend struct SkipSorting;
|
|
176 |
};
|
|
177 |
|
|
178 |
QT_BEGIN_INCLUDE_NAMESPACE
|
|
179 |
#include "private/qabstractitemmodel_p.h"
|
|
180 |
QT_END_INCLUDE_NAMESPACE
|
|
181 |
|
|
182 |
class QTreeModelPrivate : public QAbstractItemModelPrivate
|
|
183 |
{
|
|
184 |
Q_DECLARE_PUBLIC(QTreeModel)
|
|
185 |
};
|
|
186 |
|
|
187 |
class QTreeWidgetItemPrivate
|
|
188 |
{
|
|
189 |
public:
|
|
190 |
QTreeWidgetItemPrivate(QTreeWidgetItem *item)
|
|
191 |
: q(item), disabled(false), selected(false), rowGuess(-1), policy(QTreeWidgetItem::DontShowIndicatorWhenChildless) {}
|
|
192 |
void propagateDisabled(QTreeWidgetItem *item);
|
|
193 |
void sortChildren(int column, Qt::SortOrder order, bool climb);
|
|
194 |
QTreeWidgetItem *q;
|
|
195 |
QVariantList display;
|
|
196 |
uint disabled : 1;
|
|
197 |
uint selected : 1;
|
|
198 |
int rowGuess;
|
|
199 |
QTreeWidgetItem::ChildIndicatorPolicy policy;
|
|
200 |
};
|
|
201 |
|
|
202 |
|
|
203 |
inline bool QTreeModel::executePendingSort() const
|
|
204 |
{
|
|
205 |
if (!skipPendingSort && sortPendingTimer.isActive() && !isChanging()) {
|
|
206 |
sortPendingTimer.stop();
|
|
207 |
int column = view()->header()->sortIndicatorSection();
|
|
208 |
Qt::SortOrder order = view()->header()->sortIndicatorOrder();
|
|
209 |
QTreeModel *that = const_cast<QTreeModel*>(this);
|
|
210 |
that->sort(column, order);
|
|
211 |
return true;
|
|
212 |
}
|
|
213 |
return false;
|
|
214 |
}
|
|
215 |
|
|
216 |
class QTreeWidgetPrivate : public QTreeViewPrivate
|
|
217 |
{
|
|
218 |
friend class QTreeModel;
|
|
219 |
Q_DECLARE_PUBLIC(QTreeWidget)
|
|
220 |
public:
|
|
221 |
QTreeWidgetPrivate() : QTreeViewPrivate(), explicitSortColumn(-1) {}
|
|
222 |
inline QTreeModel *treeModel() const { return qobject_cast<QTreeModel*>(model); }
|
|
223 |
inline QModelIndex index(const QTreeWidgetItem *item, int column = 0) const
|
|
224 |
{ return treeModel()->index(item, column); }
|
|
225 |
inline QTreeWidgetItem *item(const QModelIndex &index) const
|
|
226 |
{ return treeModel()->item(index); }
|
|
227 |
void _q_emitItemPressed(const QModelIndex &index);
|
|
228 |
void _q_emitItemClicked(const QModelIndex &index);
|
|
229 |
void _q_emitItemDoubleClicked(const QModelIndex &index);
|
|
230 |
void _q_emitItemActivated(const QModelIndex &index);
|
|
231 |
void _q_emitItemEntered(const QModelIndex &index);
|
|
232 |
void _q_emitItemChanged(const QModelIndex &index);
|
|
233 |
void _q_emitItemExpanded(const QModelIndex &index);
|
|
234 |
void _q_emitItemCollapsed(const QModelIndex &index);
|
|
235 |
void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex &index);
|
|
236 |
void _q_sort();
|
|
237 |
void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
|
238 |
void _q_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
|
239 |
|
|
240 |
// used by QTreeWidgetItem::sortChildren to make sure the column argument is used
|
|
241 |
int explicitSortColumn;
|
|
242 |
};
|
|
243 |
|
|
244 |
QT_END_NAMESPACE
|
|
245 |
|
|
246 |
#endif // QT_NO_TREEWIDGET
|
|
247 |
|
|
248 |
#endif // QTREEWIDGET_P_H
|