|
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_H |
|
43 #define QSTANDARDITEMMODEL_H |
|
44 |
|
45 #include <QtCore/qabstractitemmodel.h> |
|
46 #include <QtGui/qbrush.h> |
|
47 #include <QtGui/qfont.h> |
|
48 #include <QtGui/qicon.h> |
|
49 #ifndef QT_NO_DATASTREAM |
|
50 #include <QtCore/qdatastream.h> |
|
51 #endif |
|
52 |
|
53 QT_BEGIN_HEADER |
|
54 |
|
55 QT_BEGIN_NAMESPACE |
|
56 |
|
57 QT_MODULE(Gui) |
|
58 |
|
59 #ifndef QT_NO_STANDARDITEMMODEL |
|
60 |
|
61 template <class T> class QList; |
|
62 |
|
63 class QStandardItemModel; |
|
64 |
|
65 class QStandardItemPrivate; |
|
66 class Q_GUI_EXPORT QStandardItem |
|
67 { |
|
68 public: |
|
69 QStandardItem(); |
|
70 QStandardItem(const QString &text); |
|
71 QStandardItem(const QIcon &icon, const QString &text); |
|
72 explicit QStandardItem(int rows, int columns = 1); |
|
73 virtual ~QStandardItem(); |
|
74 |
|
75 virtual QVariant data(int role = Qt::UserRole + 1) const; |
|
76 virtual void setData(const QVariant &value, int role = Qt::UserRole + 1); |
|
77 |
|
78 inline QString text() const { |
|
79 return qvariant_cast<QString>(data(Qt::DisplayRole)); |
|
80 } |
|
81 inline void setText(const QString &text); |
|
82 |
|
83 inline QIcon icon() const { |
|
84 return qvariant_cast<QIcon>(data(Qt::DecorationRole)); |
|
85 } |
|
86 inline void setIcon(const QIcon &icon); |
|
87 |
|
88 #ifndef QT_NO_TOOLTIP |
|
89 inline QString toolTip() const { |
|
90 return qvariant_cast<QString>(data(Qt::ToolTipRole)); |
|
91 } |
|
92 inline void setToolTip(const QString &toolTip); |
|
93 #endif |
|
94 |
|
95 #ifndef QT_NO_STATUSTIP |
|
96 inline QString statusTip() const { |
|
97 return qvariant_cast<QString>(data(Qt::StatusTipRole)); |
|
98 } |
|
99 inline void setStatusTip(const QString &statusTip); |
|
100 #endif |
|
101 |
|
102 #ifndef QT_NO_WHATSTHIS |
|
103 inline QString whatsThis() const { |
|
104 return qvariant_cast<QString>(data(Qt::WhatsThisRole)); |
|
105 } |
|
106 inline void setWhatsThis(const QString &whatsThis); |
|
107 #endif |
|
108 |
|
109 inline QSize sizeHint() const { |
|
110 return qvariant_cast<QSize>(data(Qt::SizeHintRole)); |
|
111 } |
|
112 inline void setSizeHint(const QSize &sizeHint); |
|
113 |
|
114 inline QFont font() const { |
|
115 return qvariant_cast<QFont>(data(Qt::FontRole)); |
|
116 } |
|
117 inline void setFont(const QFont &font); |
|
118 |
|
119 inline Qt::Alignment textAlignment() const { |
|
120 return Qt::Alignment(qvariant_cast<int>(data(Qt::TextAlignmentRole))); |
|
121 } |
|
122 inline void setTextAlignment(Qt::Alignment textAlignment); |
|
123 |
|
124 inline QBrush background() const { |
|
125 return qvariant_cast<QBrush>(data(Qt::BackgroundRole)); |
|
126 } |
|
127 inline void setBackground(const QBrush &brush); |
|
128 |
|
129 inline QBrush foreground() const { |
|
130 return qvariant_cast<QBrush>(data(Qt::ForegroundRole)); |
|
131 } |
|
132 inline void setForeground(const QBrush &brush); |
|
133 |
|
134 inline Qt::CheckState checkState() const { |
|
135 return Qt::CheckState(qvariant_cast<int>(data(Qt::CheckStateRole))); |
|
136 } |
|
137 inline void setCheckState(Qt::CheckState checkState); |
|
138 |
|
139 inline QString accessibleText() const { |
|
140 return qvariant_cast<QString>(data(Qt::AccessibleTextRole)); |
|
141 } |
|
142 inline void setAccessibleText(const QString &accessibleText); |
|
143 |
|
144 inline QString accessibleDescription() const { |
|
145 return qvariant_cast<QString>(data(Qt::AccessibleDescriptionRole)); |
|
146 } |
|
147 inline void setAccessibleDescription(const QString &accessibleDescription); |
|
148 |
|
149 Qt::ItemFlags flags() const; |
|
150 void setFlags(Qt::ItemFlags flags); |
|
151 |
|
152 inline bool isEnabled() const { |
|
153 return (flags() & Qt::ItemIsEnabled) != 0; |
|
154 } |
|
155 void setEnabled(bool enabled); |
|
156 |
|
157 inline bool isEditable() const { |
|
158 return (flags() & Qt::ItemIsEditable) != 0; |
|
159 } |
|
160 void setEditable(bool editable); |
|
161 |
|
162 inline bool isSelectable() const { |
|
163 return (flags() & Qt::ItemIsSelectable) != 0; |
|
164 } |
|
165 void setSelectable(bool selectable); |
|
166 |
|
167 inline bool isCheckable() const { |
|
168 return (flags() & Qt::ItemIsUserCheckable) != 0; |
|
169 } |
|
170 void setCheckable(bool checkable); |
|
171 |
|
172 inline bool isTristate() const { |
|
173 return (flags() & Qt::ItemIsTristate) != 0; |
|
174 } |
|
175 void setTristate(bool tristate); |
|
176 |
|
177 #ifndef QT_NO_DRAGANDDROP |
|
178 inline bool isDragEnabled() const { |
|
179 return (flags() & Qt::ItemIsDragEnabled) != 0; |
|
180 } |
|
181 void setDragEnabled(bool dragEnabled); |
|
182 |
|
183 inline bool isDropEnabled() const { |
|
184 return (flags() & Qt::ItemIsDropEnabled) != 0; |
|
185 } |
|
186 void setDropEnabled(bool dropEnabled); |
|
187 #endif // QT_NO_DRAGANDDROP |
|
188 |
|
189 QStandardItem *parent() const; |
|
190 int row() const; |
|
191 int column() const; |
|
192 QModelIndex index() const; |
|
193 QStandardItemModel *model() const; |
|
194 |
|
195 int rowCount() const; |
|
196 void setRowCount(int rows); |
|
197 int columnCount() const; |
|
198 void setColumnCount(int columns); |
|
199 |
|
200 bool hasChildren() const; |
|
201 QStandardItem *child(int row, int column = 0) const; |
|
202 void setChild(int row, int column, QStandardItem *item); |
|
203 inline void setChild(int row, QStandardItem *item); |
|
204 |
|
205 void insertRow(int row, const QList<QStandardItem*> &items); |
|
206 void insertColumn(int column, const QList<QStandardItem*> &items); |
|
207 void insertRows(int row, const QList<QStandardItem*> &items); |
|
208 void insertRows(int row, int count); |
|
209 void insertColumns(int column, int count); |
|
210 |
|
211 void removeRow(int row); |
|
212 void removeColumn(int column); |
|
213 void removeRows(int row, int count); |
|
214 void removeColumns(int column, int count); |
|
215 |
|
216 inline void appendRow(const QList<QStandardItem*> &items); |
|
217 inline void appendRows(const QList<QStandardItem*> &items); |
|
218 inline void appendColumn(const QList<QStandardItem*> &items); |
|
219 inline void insertRow(int row, QStandardItem *item); |
|
220 inline void appendRow(QStandardItem *item); |
|
221 |
|
222 QStandardItem *takeChild(int row, int column = 0); |
|
223 QList<QStandardItem*> takeRow(int row); |
|
224 QList<QStandardItem*> takeColumn(int column); |
|
225 |
|
226 void sortChildren(int column, Qt::SortOrder order = Qt::AscendingOrder); |
|
227 |
|
228 virtual QStandardItem *clone() const; |
|
229 |
|
230 enum ItemType { Type = 0, UserType = 1000 }; |
|
231 virtual int type() const; |
|
232 |
|
233 #ifndef QT_NO_DATASTREAM |
|
234 virtual void read(QDataStream &in); |
|
235 virtual void write(QDataStream &out) const; |
|
236 #endif |
|
237 virtual bool operator<(const QStandardItem &other) const; |
|
238 |
|
239 protected: |
|
240 QStandardItem(const QStandardItem &other); |
|
241 QStandardItem(QStandardItemPrivate &dd); |
|
242 QStandardItem &operator=(const QStandardItem &other); |
|
243 QScopedPointer<QStandardItemPrivate> d_ptr; |
|
244 |
|
245 void emitDataChanged(); |
|
246 |
|
247 private: |
|
248 Q_DECLARE_PRIVATE(QStandardItem) |
|
249 friend class QStandardItemModelPrivate; |
|
250 friend class QStandardItemModel; |
|
251 }; |
|
252 |
|
253 inline void QStandardItem::setText(const QString &atext) |
|
254 { setData(atext, Qt::DisplayRole); } |
|
255 |
|
256 inline void QStandardItem::setIcon(const QIcon &aicon) |
|
257 { setData(aicon, Qt::DecorationRole); } |
|
258 |
|
259 #ifndef QT_NO_TOOLTIP |
|
260 inline void QStandardItem::setToolTip(const QString &atoolTip) |
|
261 { setData(atoolTip, Qt::ToolTipRole); } |
|
262 #endif |
|
263 |
|
264 #ifndef QT_NO_STATUSTIP |
|
265 inline void QStandardItem::setStatusTip(const QString &astatusTip) |
|
266 { setData(astatusTip, Qt::StatusTipRole); } |
|
267 #endif |
|
268 |
|
269 #ifndef QT_NO_WHATSTHIS |
|
270 inline void QStandardItem::setWhatsThis(const QString &awhatsThis) |
|
271 { setData(awhatsThis, Qt::WhatsThisRole); } |
|
272 #endif |
|
273 |
|
274 inline void QStandardItem::setSizeHint(const QSize &asizeHint) |
|
275 { setData(asizeHint, Qt::SizeHintRole); } |
|
276 |
|
277 inline void QStandardItem::setFont(const QFont &afont) |
|
278 { setData(afont, Qt::FontRole); } |
|
279 |
|
280 inline void QStandardItem::setTextAlignment(Qt::Alignment atextAlignment) |
|
281 { setData(int(atextAlignment), Qt::TextAlignmentRole); } |
|
282 |
|
283 inline void QStandardItem::setBackground(const QBrush &abrush) |
|
284 { setData(abrush, Qt::BackgroundRole); } |
|
285 |
|
286 inline void QStandardItem::setForeground(const QBrush &abrush) |
|
287 { setData(abrush, Qt::ForegroundRole); } |
|
288 |
|
289 inline void QStandardItem::setCheckState(Qt::CheckState acheckState) |
|
290 { setData(acheckState, Qt::CheckStateRole); } |
|
291 |
|
292 inline void QStandardItem::setAccessibleText(const QString &aaccessibleText) |
|
293 { setData(aaccessibleText, Qt::AccessibleTextRole); } |
|
294 |
|
295 inline void QStandardItem::setAccessibleDescription(const QString &aaccessibleDescription) |
|
296 { setData(aaccessibleDescription, Qt::AccessibleDescriptionRole); } |
|
297 |
|
298 inline void QStandardItem::setChild(int arow, QStandardItem *aitem) |
|
299 { setChild(arow, 0, aitem); } |
|
300 |
|
301 inline void QStandardItem::appendRow(const QList<QStandardItem*> &aitems) |
|
302 { insertRow(rowCount(), aitems); } |
|
303 |
|
304 inline void QStandardItem::appendRows(const QList<QStandardItem*> &aitems) |
|
305 { insertRows(rowCount(), aitems); } |
|
306 |
|
307 inline void QStandardItem::appendColumn(const QList<QStandardItem*> &aitems) |
|
308 { insertColumn(columnCount(), aitems); } |
|
309 |
|
310 inline void QStandardItem::insertRow(int arow, QStandardItem *aitem) |
|
311 { insertRow(arow, QList<QStandardItem*>() << aitem); } |
|
312 |
|
313 inline void QStandardItem::appendRow(QStandardItem *aitem) |
|
314 { insertRow(rowCount(), aitem); } |
|
315 |
|
316 class QStandardItemModelPrivate; |
|
317 |
|
318 class Q_GUI_EXPORT QStandardItemModel : public QAbstractItemModel |
|
319 { |
|
320 Q_OBJECT |
|
321 Q_PROPERTY(int sortRole READ sortRole WRITE setSortRole) |
|
322 |
|
323 public: |
|
324 explicit QStandardItemModel(QObject *parent = 0); |
|
325 QStandardItemModel(int rows, int columns, QObject *parent = 0); |
|
326 ~QStandardItemModel(); |
|
327 |
|
328 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; |
|
329 QModelIndex parent(const QModelIndex &child) const; |
|
330 |
|
331 int rowCount(const QModelIndex &parent = QModelIndex()) const; |
|
332 int columnCount(const QModelIndex &parent = QModelIndex()) const; |
|
333 bool hasChildren(const QModelIndex &parent = QModelIndex()) const; |
|
334 |
|
335 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
336 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); |
|
337 |
|
338 QVariant headerData(int section, Qt::Orientation orientation, |
|
339 int role = Qt::DisplayRole) const; |
|
340 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, |
|
341 int role = Qt::EditRole); |
|
342 |
|
343 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
344 bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()); |
|
345 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); |
|
346 bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()); |
|
347 |
|
348 Qt::ItemFlags flags(const QModelIndex &index) const; |
|
349 Qt::DropActions supportedDropActions() const; |
|
350 |
|
351 QMap<int, QVariant> itemData(const QModelIndex &index) const; |
|
352 bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles); |
|
353 |
|
354 void clear(); |
|
355 |
|
356 #ifdef Q_NO_USING_KEYWORD |
|
357 inline QObject *parent() const { return QObject::parent(); } |
|
358 #else |
|
359 using QObject::parent; |
|
360 #endif |
|
361 |
|
362 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); |
|
363 |
|
364 QStandardItem *itemFromIndex(const QModelIndex &index) const; |
|
365 QModelIndex indexFromItem(const QStandardItem *item) const; |
|
366 |
|
367 QStandardItem *item(int row, int column = 0) const; |
|
368 void setItem(int row, int column, QStandardItem *item); |
|
369 inline void setItem(int row, QStandardItem *item); |
|
370 QStandardItem *invisibleRootItem() const; |
|
371 |
|
372 QStandardItem *horizontalHeaderItem(int column) const; |
|
373 void setHorizontalHeaderItem(int column, QStandardItem *item); |
|
374 QStandardItem *verticalHeaderItem(int row) const; |
|
375 void setVerticalHeaderItem(int row, QStandardItem *item); |
|
376 |
|
377 void setHorizontalHeaderLabels(const QStringList &labels); |
|
378 void setVerticalHeaderLabels(const QStringList &labels); |
|
379 |
|
380 void setRowCount(int rows); |
|
381 void setColumnCount(int columns); |
|
382 |
|
383 void appendRow(const QList<QStandardItem*> &items); |
|
384 void appendColumn(const QList<QStandardItem*> &items); |
|
385 inline void appendRow(QStandardItem *item); |
|
386 |
|
387 void insertRow(int row, const QList<QStandardItem*> &items); |
|
388 void insertColumn(int column, const QList<QStandardItem*> &items); |
|
389 inline void insertRow(int row, QStandardItem *item); |
|
390 |
|
391 inline bool insertRow(int row, const QModelIndex &parent = QModelIndex()); |
|
392 inline bool insertColumn(int column, const QModelIndex &parent = QModelIndex()); |
|
393 |
|
394 QStandardItem *takeItem(int row, int column = 0); |
|
395 QList<QStandardItem*> takeRow(int row); |
|
396 QList<QStandardItem*> takeColumn(int column); |
|
397 |
|
398 QStandardItem *takeHorizontalHeaderItem(int column); |
|
399 QStandardItem *takeVerticalHeaderItem(int row); |
|
400 |
|
401 const QStandardItem *itemPrototype() const; |
|
402 void setItemPrototype(const QStandardItem *item); |
|
403 |
|
404 QList<QStandardItem*> findItems(const QString &text, |
|
405 Qt::MatchFlags flags = Qt::MatchExactly, |
|
406 int column = 0) const; |
|
407 |
|
408 int sortRole() const; |
|
409 void setSortRole(int role); |
|
410 |
|
411 QStringList mimeTypes() const; |
|
412 QMimeData *mimeData(const QModelIndexList &indexes) const; |
|
413 bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); |
|
414 |
|
415 Q_SIGNALS: |
|
416 void itemChanged(QStandardItem *item); |
|
417 |
|
418 protected: |
|
419 QStandardItemModel(QStandardItemModelPrivate &dd, QObject *parent = 0); |
|
420 |
|
421 private: |
|
422 friend class QStandardItemPrivate; |
|
423 friend class QStandardItem; |
|
424 Q_DISABLE_COPY(QStandardItemModel) |
|
425 Q_DECLARE_PRIVATE(QStandardItemModel) |
|
426 |
|
427 Q_PRIVATE_SLOT(d_func(), void _q_emitItemChanged(const QModelIndex &topLeft, |
|
428 const QModelIndex &bottomRight)) |
|
429 }; |
|
430 |
|
431 inline void QStandardItemModel::setItem(int arow, QStandardItem *aitem) |
|
432 { setItem(arow, 0, aitem); } |
|
433 |
|
434 inline void QStandardItemModel::appendRow(QStandardItem *aitem) |
|
435 { appendRow(QList<QStandardItem*>() << aitem); } |
|
436 |
|
437 inline void QStandardItemModel::insertRow(int arow, QStandardItem *aitem) |
|
438 { insertRow(arow, QList<QStandardItem*>() << aitem); } |
|
439 |
|
440 inline bool QStandardItemModel::insertRow(int arow, const QModelIndex &aparent) |
|
441 { return QAbstractItemModel::insertRow(arow, aparent); } |
|
442 inline bool QStandardItemModel::insertColumn(int acolumn, const QModelIndex &aparent) |
|
443 { return QAbstractItemModel::insertColumn(acolumn, aparent); } |
|
444 |
|
445 #ifndef QT_NO_DATASTREAM |
|
446 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QStandardItem &item); |
|
447 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &out, const QStandardItem &item); |
|
448 #endif |
|
449 |
|
450 #endif // QT_NO_STANDARDITEMMODEL |
|
451 |
|
452 QT_END_NAMESPACE |
|
453 |
|
454 QT_END_HEADER |
|
455 |
|
456 #endif //QSTANDARDITEMMODEL_H |