|
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 QSTANDARDITEMMODEL_P_H |
|
43 #define QSTANDARDITEMMODEL_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 for the convenience |
|
50 // of other Qt classes. 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/qabstractitemmodel_p.h" |
|
57 |
|
58 #ifndef QT_NO_STANDARDITEMMODEL |
|
59 |
|
60 #include <private/qwidgetitemdata_p.h> |
|
61 #include <QtCore/qlist.h> |
|
62 #include <QtCore/qpair.h> |
|
63 #include <QtCore/qstack.h> |
|
64 #include <QtCore/qvariant.h> |
|
65 #include <QtCore/qvector.h> |
|
66 |
|
67 QT_BEGIN_NAMESPACE |
|
68 |
|
69 class QStandardItemPrivate |
|
70 { |
|
71 Q_DECLARE_PUBLIC(QStandardItem) |
|
72 public: |
|
73 inline QStandardItemPrivate() |
|
74 : model(0), |
|
75 parent(0), |
|
76 rows(0), |
|
77 columns(0), |
|
78 q_ptr(0), |
|
79 lastIndexOf(2) |
|
80 { } |
|
81 virtual ~QStandardItemPrivate(); |
|
82 |
|
83 inline int childIndex(int row, int column) const { |
|
84 if ((row < 0) || (column < 0) |
|
85 || (row >= rowCount()) || (column >= columnCount())) { |
|
86 return -1; |
|
87 } |
|
88 return (row * columnCount()) + column; |
|
89 } |
|
90 inline int childIndex(const QStandardItem *child) { |
|
91 int start = qMax(0, lastIndexOf -2); |
|
92 lastIndexOf = children.indexOf(const_cast<QStandardItem*>(child), start); |
|
93 if (lastIndexOf == -1 && start != 0) |
|
94 lastIndexOf = children.lastIndexOf(const_cast<QStandardItem*>(child), start); |
|
95 return lastIndexOf; |
|
96 } |
|
97 QPair<int, int> position() const; |
|
98 void setChild(int row, int column, QStandardItem *item, |
|
99 bool emitChanged = false); |
|
100 inline int rowCount() const { |
|
101 return rows; |
|
102 } |
|
103 inline int columnCount() const { |
|
104 return columns; |
|
105 } |
|
106 void childDeleted(QStandardItem *child); |
|
107 |
|
108 void setModel(QStandardItemModel *mod); |
|
109 |
|
110 inline void setParentAndModel( |
|
111 QStandardItem *par, |
|
112 QStandardItemModel *mod) { |
|
113 setModel(mod); |
|
114 parent = par; |
|
115 } |
|
116 |
|
117 void changeFlags(bool enable, Qt::ItemFlags f); |
|
118 void setItemData(const QMap<int, QVariant> &roles); |
|
119 const QMap<int, QVariant> itemData() const; |
|
120 |
|
121 bool insertRows(int row, int count, const QList<QStandardItem*> &items); |
|
122 bool insertRows(int row, const QList<QStandardItem*> &items); |
|
123 bool insertColumns(int column, int count, const QList<QStandardItem*> &items); |
|
124 |
|
125 void sortChildren(int column, Qt::SortOrder order); |
|
126 |
|
127 QStandardItemModel *model; |
|
128 QStandardItem *parent; |
|
129 QVector<QWidgetItemData> values; |
|
130 QVector<QStandardItem*> children; |
|
131 int rows; |
|
132 int columns; |
|
133 |
|
134 QStandardItem *q_ptr; |
|
135 |
|
136 int lastIndexOf; |
|
137 }; |
|
138 |
|
139 class QStandardItemModelPrivate : public QAbstractItemModelPrivate |
|
140 { |
|
141 Q_DECLARE_PUBLIC(QStandardItemModel) |
|
142 |
|
143 public: |
|
144 QStandardItemModelPrivate(); |
|
145 virtual ~QStandardItemModelPrivate(); |
|
146 |
|
147 void init(); |
|
148 |
|
149 inline QStandardItem *createItem() const { |
|
150 return itemPrototype ? itemPrototype->clone() : new QStandardItem; |
|
151 } |
|
152 |
|
153 inline QStandardItem *itemFromIndex(const QModelIndex &index) const { |
|
154 Q_Q(const QStandardItemModel); |
|
155 if (!index.isValid()) |
|
156 return root.data(); |
|
157 if (index.model() != q) |
|
158 return 0; |
|
159 QStandardItem *parent = static_cast<QStandardItem*>(index.internalPointer()); |
|
160 if (parent == 0) |
|
161 return 0; |
|
162 return parent->child(index.row(), index.column()); |
|
163 } |
|
164 |
|
165 void sort(QStandardItem *parent, int column, Qt::SortOrder order); |
|
166 void itemChanged(QStandardItem *item); |
|
167 void rowsAboutToBeInserted(QStandardItem *parent, int start, int end); |
|
168 void columnsAboutToBeInserted(QStandardItem *parent, int start, int end); |
|
169 void rowsAboutToBeRemoved(QStandardItem *parent, int start, int end); |
|
170 void columnsAboutToBeRemoved(QStandardItem *parent, int start, int end); |
|
171 void rowsInserted(QStandardItem *parent, int row, int count); |
|
172 void columnsInserted(QStandardItem *parent, int column, int count); |
|
173 void rowsRemoved(QStandardItem *parent, int row, int count); |
|
174 void columnsRemoved(QStandardItem *parent, int column, int count); |
|
175 |
|
176 void _q_emitItemChanged(const QModelIndex &topLeft, |
|
177 const QModelIndex &bottomRight); |
|
178 |
|
179 void decodeDataRecursive(QDataStream &stream, QStandardItem *item); |
|
180 |
|
181 QVector<QStandardItem*> columnHeaderItems; |
|
182 QVector<QStandardItem*> rowHeaderItems; |
|
183 QScopedPointer<QStandardItem> root; |
|
184 const QStandardItem *itemPrototype; |
|
185 int sortRole; |
|
186 }; |
|
187 |
|
188 QT_END_NAMESPACE |
|
189 |
|
190 #endif // QT_NO_STANDARDITEMMODEL |
|
191 |
|
192 #endif // QSTANDARDITEMMODEL_P_H |