source: trunk/src/gui/itemviews/qtreewidget_p.h@ 112

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

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
65QT_BEGIN_NAMESPACE
66
67class QTreeWidgetItem;
68class QTreeWidgetItemIterator;
69class QTreeModelPrivate;
70
71class 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
81public:
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
141protected:
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
151private:
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
164private:
165 Q_DECLARE_PRIVATE(QTreeModel)
166public:
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
178QT_BEGIN_INCLUDE_NAMESPACE
179#include "private/qabstractitemmodel_p.h"
180QT_END_INCLUDE_NAMESPACE
181
182class QTreeModelPrivate : public QAbstractItemModelPrivate
183{
184 Q_DECLARE_PUBLIC(QTreeModel)
185};
186
187class QTreeWidgetItemPrivate
188{
189public:
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
203inline 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
216class QTreeWidgetPrivate : public QTreeViewPrivate
217{
218 friend class QTreeModel;
219 Q_DECLARE_PUBLIC(QTreeWidget)
220public:
221 QTreeWidgetPrivate() : QTreeViewPrivate(), explicitSortColumn(-1) {}
222 inline QTreeModel *model() const
223 { return qobject_cast<QTreeModel*>(q_func()->model()); }
224 inline QModelIndex index(const QTreeWidgetItem *item, int column = 0) const
225 { return model()->index(item, column); }
226 inline QTreeWidgetItem *item(const QModelIndex &index) const
227 { return model()->item(index); }
228 void _q_emitItemPressed(const QModelIndex &index);
229 void _q_emitItemClicked(const QModelIndex &index);
230 void _q_emitItemDoubleClicked(const QModelIndex &index);
231 void _q_emitItemActivated(const QModelIndex &index);
232 void _q_emitItemEntered(const QModelIndex &index);
233 void _q_emitItemChanged(const QModelIndex &index);
234 void _q_emitItemExpanded(const QModelIndex &index);
235 void _q_emitItemCollapsed(const QModelIndex &index);
236 void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex &index);
237 void _q_sort();
238 void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
239 void _q_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
240
241 // used by QTreeWidgetItem::sortChildren to make sure the column argument is used
242 int explicitSortColumn;
243};
244
245QT_END_NAMESPACE
246
247#endif // QT_NO_TREEWIDGET
248
249#endif // QTREEWIDGET_P_H
Note: See TracBrowser for help on using the repository browser.