1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.gui.standarditemmodel;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.abstractitemmodel;
19 import qt.core.bytearray;
20 import qt.core.hash;
21 import qt.core.list;
22 import qt.core.map;
23 import qt.core.mimedata;
24 import qt.core.namespace;
25 import qt.core.object;
26 import qt.core.scopedpointer;
27 import qt.core.size;
28 import qt.core.string;
29 import qt.core.stringlist;
30 import qt.core.variant;
31 import qt.gui.brush;
32 import qt.gui.font;
33 import qt.gui.icon;
34 import qt.helpers;
35 version(QT_NO_DATASTREAM){}else
36     import qt.core.datastream;
37 
38 /+ #ifndef QT_NO_DATASTREAM
39 #endif
40 
41 QT_REQUIRE_CONFIG(standarditemmodel);
42 
43 
44 template <class T> class QList;
45 
46 class QStandardItemModel; +/
47 
48 extern(C++, class) struct QStandardItemPrivate;
49 class /+ Q_GUI_EXPORT +/ QStandardItem
50 {
51 public:
52     this();
53     /+ explicit +/this(ref const(QString) text);
54     this(ref const(QIcon) icon, ref const(QString) text);
55     /+ explicit +/this(int rows, int columns = 1);
56     /+ virtual +/~this();
57 
58     /+ virtual +/ QVariant data(int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.UserRole + 1) const;
59     /+ virtual +/ void setData(ref const(QVariant) value, int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.UserRole + 1);
60     /+ virtual +/ void setData(T)(T value, int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.UserRole + 1)
61     {
62         static if(is(const(T) == const(QVariant)))
63             QVariant v = value;
64         else
65             QVariant v = QVariant.fromValue(value);
66         setData(v, role);
67     }
68     final void clearData();
69 
70     pragma(inline, true) final QString text() const {
71         return qvariant_cast!(QString)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole));
72     }
73     pragma(inline, true) final void setText(ref const(QString) atext)
74     { setData(atext, /+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole); }
75     pragma(inline, true) final void setText(const(QString) atext)
76     { setText(atext); }
77 
78     pragma(inline, true) final QIcon icon() const {
79         return qvariant_cast!(QIcon)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.DecorationRole));
80     }
81     pragma(inline, true) final void setIcon(ref const(QIcon) aicon)
82     { setData(aicon, /+ Qt:: +/qt.core.namespace.ItemDataRole.DecorationRole); }
83 
84 /+ #ifndef QT_NO_TOOLTIP +/
85     version(QT_NO_TOOLTIP){}else
86     {
87         pragma(inline, true) final QString toolTip() const {
88             return qvariant_cast!(QString)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.ToolTipRole));
89         }
90         pragma(inline, true) final void setToolTip(ref const(QString) atoolTip)
91         { setData(atoolTip, /+ Qt:: +/qt.core.namespace.ItemDataRole.ToolTipRole); }
92     }
93 /+ #endif
94 
95 #ifndef QT_NO_STATUSTIP +/
96     version(QT_NO_STATUSTIP){}else
97     {
98         pragma(inline, true) final QString statusTip() const {
99             return qvariant_cast!(QString)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.StatusTipRole));
100         }
101         pragma(inline, true) final void setStatusTip(ref const(QString) astatusTip)
102         { setData(astatusTip, /+ Qt:: +/qt.core.namespace.ItemDataRole.StatusTipRole); }
103     }
104 /+ #endif
105 
106 #if QT_CONFIG(whatsthis) +/
107     pragma(inline, true) final QString whatsThis() const {
108         return qvariant_cast!(QString)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.WhatsThisRole));
109     }
110     pragma(inline, true) final void setWhatsThis(ref const(QString) awhatsThis)
111     { setData(awhatsThis, /+ Qt:: +/qt.core.namespace.ItemDataRole.WhatsThisRole); }
112 /+ #endif +/
113 
114     pragma(inline, true) final QSize sizeHint() const {
115         return qvariant_cast!(QSize)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.SizeHintRole));
116     }
117     pragma(inline, true) final void setSizeHint(ref const(QSize) asizeHint)
118     { setData(asizeHint, /+ Qt:: +/qt.core.namespace.ItemDataRole.SizeHintRole); }
119 
120     pragma(inline, true) final QFont font() const {
121         return qvariant_cast!(QFont)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.FontRole));
122     }
123     pragma(inline, true) final void setFont(ref const(QFont) afont)
124     { setData(afont, /+ Qt:: +/qt.core.namespace.ItemDataRole.FontRole); }
125 
126 /+    pragma(inline, true) final /+ Qt:: +/qt.core.namespace.Alignment textAlignment() const {
127         return /+ Qt:: +/qt.core.namespace.Alignment(qvariant_cast!(int)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.TextAlignmentRole)));
128     }
129     pragma(inline, true) final void setTextAlignment(/+ Qt:: +/qt.core.namespace.Alignment atextAlignment)
130     { auto tmp = const(QVariant)(cast(int)(atextAlignment)); setData(tmp, /+ Qt:: +/qt.core.namespace.ItemDataRole.TextAlignmentRole); }+/
131 
132     pragma(inline, true) final QBrush background() const {
133         return qvariant_cast!(QBrush)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.BackgroundRole));
134     }
135     pragma(inline, true) final void setBackground(ref const(QBrush) abrush)
136     { setData(abrush, /+ Qt:: +/qt.core.namespace.ItemDataRole.BackgroundRole); }
137 
138     pragma(inline, true) final QBrush foreground() const {
139         return qvariant_cast!(QBrush)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.ForegroundRole));
140     }
141     pragma(inline, true) final void setForeground(ref const(QBrush) abrush)
142     { setData(abrush, /+ Qt:: +/qt.core.namespace.ItemDataRole.ForegroundRole); }
143 
144 /+    pragma(inline, true) final /+ Qt:: +/qt.core.namespace.CheckState checkState() const {
145         return /+ Qt:: +/qt.core.namespace.CheckState(qvariant_cast!(int)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.CheckStateRole)));
146     }
147     pragma(inline, true) final void setCheckState(/+ Qt:: +/qt.core.namespace.CheckState acheckState)
148     { setData(acheckState, /+ Qt:: +/qt.core.namespace.ItemDataRole.CheckStateRole); }+/
149 
150     pragma(inline, true) final QString accessibleText() const {
151         return qvariant_cast!(QString)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.AccessibleTextRole));
152     }
153     pragma(inline, true) final void setAccessibleText(ref const(QString) aaccessibleText)
154     { setData(aaccessibleText, /+ Qt:: +/qt.core.namespace.ItemDataRole.AccessibleTextRole); }
155 
156     pragma(inline, true) final QString accessibleDescription() const {
157         return qvariant_cast!(QString)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.AccessibleDescriptionRole));
158     }
159     pragma(inline, true) final void setAccessibleDescription(ref const(QString) aaccessibleDescription)
160     { setData(aaccessibleDescription, /+ Qt:: +/qt.core.namespace.ItemDataRole.AccessibleDescriptionRole); }
161 
162     final /+ Qt:: +/qt.core.namespace.ItemFlags flags() const;
163     final void setFlags(/+ Qt:: +/qt.core.namespace.ItemFlags flags);
164 
165 /+    pragma(inline, true) final bool isEnabled() const {
166         return (flags() & /+ Qt:: +/qt.core.namespace.ItemFlag.ItemIsEnabled) != 0;
167     }
168     final void setEnabled(bool enabled);
169 
170     pragma(inline, true) final bool isEditable() const {
171         return (flags() & /+ Qt:: +/qt.core.namespace.ItemFlag.ItemIsEditable) != 0;
172     }
173     final void setEditable(bool editable);
174 
175     pragma(inline, true) final bool isSelectable() const {
176         return (flags() & /+ Qt:: +/qt.core.namespace.ItemFlag.ItemIsSelectable) != 0;
177     }
178     final void setSelectable(bool selectable);
179 
180     pragma(inline, true) final bool isCheckable() const {
181         return (flags() & /+ Qt:: +/qt.core.namespace.ItemFlag.ItemIsUserCheckable) != 0;
182     }
183     final void setCheckable(bool checkable);
184 
185     pragma(inline, true) final bool isAutoTristate() const {
186         return (flags() & /+ Qt:: +/qt.core.namespace.ItemFlag.ItemIsAutoTristate) != 0;
187     }
188     final void setAutoTristate(bool tristate);
189 
190     pragma(inline, true) final bool isUserTristate() const {
191         return (flags() & /+ Qt:: +/qt.core.namespace.ItemFlag.ItemIsUserTristate) != 0;
192     }
193     final void setUserTristate(bool tristate);
194 
195 /+ #if QT_DEPRECATED_SINCE(5, 6) +/
196     /+ QT_DEPRECATED +/ final bool isTristate() const { return isAutoTristate(); }
197     /+ QT_DEPRECATED +/ final void setTristate(bool tristate);
198 /+ #endif
199 
200 #if QT_CONFIG(draganddrop) +/
201     pragma(inline, true) final bool isDragEnabled() const {
202         return (flags() & /+ Qt:: +/qt.core.namespace.ItemFlag.ItemIsDragEnabled) != 0;
203     }
204     final void setDragEnabled(bool dragEnabled);
205 
206     pragma(inline, true) final bool isDropEnabled() const {
207         return (flags() & /+ Qt:: +/qt.core.namespace.ItemFlag.ItemIsDropEnabled) != 0;
208     }
209     final void setDropEnabled(bool dropEnabled);+/
210 /+ #endif +/ // QT_CONFIG(draganddrop)
211 
212     final QStandardItem parent() const;
213     final int row() const;
214     final int column() const;
215     final QModelIndex index() const;
216     final QStandardItemModel model() const;
217 
218     final int rowCount() const;
219     final void setRowCount(int rows);
220     final int columnCount() const;
221     final void setColumnCount(int columns);
222 
223     final bool hasChildren() const;
224     final QStandardItem child(int row, int column = 0) const;
225     final void setChild(int row, int column, QStandardItem item);
226     pragma(inline, true) final void setChild(int arow, QStandardItem aitem)
227     { setChild(arow, 0, aitem); }
228 
229     final void insertRow(int row, ref const(QList!(QStandardItem)) items);
230     final void insertColumn(int column, ref const(QList!(QStandardItem)) items);
231     final void insertRows(int row, ref const(QList!(QStandardItem)) items);
232     final void insertRows(int row, int count);
233     final void insertColumns(int column, int count);
234 
235     final void removeRow(int row);
236     final void removeColumn(int column);
237     final void removeRows(int row, int count);
238     final void removeColumns(int column, int count);
239 
240     pragma(inline, true) final void appendRow(ref const(QList!(QStandardItem)) aitems)
241     { insertRow(rowCount(), aitems); }
242     pragma(inline, true) final void appendRows(ref const(QList!(QStandardItem)) aitems)
243     { insertRows(rowCount(), aitems); }
244     pragma(inline, true) final void appendColumn(ref const(QList!(QStandardItem)) aitems)
245     { insertColumn(columnCount(), aitems); }
246 /+    pragma(inline, true) final void insertRow(int arow, QStandardItem aitem)
247     { insertRow(arow, cast(QStandardItem)(QList!(QStandardItem)() << aitem)); }
248     pragma(inline, true) final void appendRow(QStandardItem aitem)
249     { insertRow(rowCount(), aitem); }
250 +/
251 
252     final QStandardItem takeChild(int row, int column = 0);
253     final QList!(QStandardItem) takeRow(int row);
254     final QList!(QStandardItem) takeColumn(int column);
255 
256     final void sortChildren(int column, /+ Qt:: +/qt.core.namespace.SortOrder order = /+ Qt:: +/qt.core.namespace.SortOrder.AscendingOrder);
257 
258     /+ virtual +/ QStandardItem clone() const;
259 
260     enum ItemType { Type = 0, UserType = 1000 }
261     /+ virtual +/ int type() const;
262 
263     version(QT_NO_DATASTREAM){}else
264     {
265         /+ virtual +/ void read(ref QDataStream in_);
266         /+ virtual +/ void write(ref QDataStream out_) const;
267     }
268     pragma(mangle, mangleOpLess("QStandardItem"))
269     bool opLess(const QStandardItem other) const;
270 
271 protected:
272     /+ QStandardItem(const QStandardItem &other); +/
273     this(ref QStandardItemPrivate dd);
274     /+ QStandardItem &operator=(const QStandardItem &other); +/
275     QScopedPointer!(QStandardItemPrivate) d_ptr;
276 
277     final void emitDataChanged();
278 
279 private:
280     /+ Q_DECLARE_PRIVATE(QStandardItem) +/
281     /+ friend class QStandardItemModelPrivate; +/
282     /+ friend class QStandardItemModel; +/
283 }
284 
285 /+ #ifndef QT_NO_TOOLTIP
286 #endif
287 
288 #ifndef QT_NO_STATUSTIP
289 #endif
290 
291 #if QT_CONFIG(whatsthis)
292 #endif +/
293 
294 extern(C++, class) struct QStandardItemModelPrivate;
295 
296 class /+ Q_GUI_EXPORT +/ QStandardItemModel : QAbstractItemModel
297 {
298     mixin(Q_OBJECT);
299     /+ Q_PROPERTY(int sortRole READ sortRole WRITE setSortRole) +/
300 
301 public:
302     /+ explicit +/this(QObject parent = null);
303     this(int rows, int columns, QObject parent = null);
304     ~this();
305 
306     final void setItemRoleNames(ref const(QHash!(int,QByteArray)) roleNames);
307 
308     override QModelIndex index(int row, int column, ref const(QModelIndex) parent = globalInitVar!QModelIndex) const;
309     override QModelIndex parent(ref const(QModelIndex) child) const;
310 
311     override int rowCount(ref const(QModelIndex) parent = globalInitVar!QModelIndex) const;
312     override int columnCount(ref const(QModelIndex) parent = globalInitVar!QModelIndex) const;
313     override bool hasChildren(ref const(QModelIndex) parent = globalInitVar!QModelIndex) const;
314     // Qt 6: Remove
315     override QModelIndex sibling(int row, int column, ref const(QModelIndex) idx) const;
316 
317     override QVariant data(ref const(QModelIndex) index, int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole) const;
318     override bool setData(ref const(QModelIndex) index, ref const(QVariant) value, int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.EditRole);
319     // Qt 6: add override keyword
320     final bool clearItemData(ref const(QModelIndex) index);
321 
322     override QVariant headerData(int section, /+ Qt:: +/qt.core.namespace.Orientation orientation,
323                             int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole) const;
324     override bool setHeaderData(int section, /+ Qt:: +/qt.core.namespace.Orientation orientation, ref const(QVariant) value,
325                            int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.EditRole);
326 
327     override bool insertRows(int row, int count, ref const(QModelIndex) parent = globalInitVar!QModelIndex);
328     override bool insertColumns(int column, int count, ref const(QModelIndex) parent = globalInitVar!QModelIndex);
329     override bool removeRows(int row, int count, ref const(QModelIndex) parent = globalInitVar!QModelIndex);
330     override bool removeColumns(int column, int count, ref const(QModelIndex) parent = globalInitVar!QModelIndex);
331 
332     override /+ Qt:: +/qt.core.namespace.ItemFlags flags(ref const(QModelIndex) index) const;
333     override /+ Qt:: +/qt.core.namespace.DropActions supportedDropActions() const;
334 
335     override QMap!(int, QVariant) itemData(ref const(QModelIndex) index) const;
336     override bool setItemData(ref const(QModelIndex) index, ref const(QMap!(int, QVariant)) roles);
337 
338     final void clear();
339 
340     /+ using QObject::parent; +/
341 
342     override void sort(int column, /+ Qt:: +/qt.core.namespace.SortOrder order = /+ Qt:: +/qt.core.namespace.SortOrder.AscendingOrder);
343 
344     final QStandardItem itemFromIndex(ref const(QModelIndex) index) const;
345     final QModelIndex indexFromItem(const(QStandardItem) item) const;
346 
347     final QStandardItem item(int row, int column = 0) const;
348     final void setItem(int row, int column, QStandardItem item);
349     pragma(inline, true) final void setItem(int arow, QStandardItem aitem)
350     { setItem(arow, 0, aitem); }
351     final QStandardItem invisibleRootItem() const;
352 
353     final QStandardItem horizontalHeaderItem(int column) const;
354     final void setHorizontalHeaderItem(int column, QStandardItem item);
355     final QStandardItem verticalHeaderItem(int row) const;
356     final void setVerticalHeaderItem(int row, QStandardItem item);
357 
358     final void setHorizontalHeaderLabels(ref const(QStringList) labels);
359     final void setVerticalHeaderLabels(ref const(QStringList) labels);
360 
361     final void setRowCount(int rows);
362     final void setColumnCount(int columns);
363 
364     final void appendRow(ref const(QList!(QStandardItem)) items);
365     final void appendColumn(ref const(QList!(QStandardItem)) items);
366 /+    pragma(inline, true) final void appendRow(QStandardItem aitem)
367     { appendRow(cast(QStandardItem)(QList!(QStandardItem)() << aitem)); }
368 +/
369 
370     final void insertRow(int row, ref const(QList!(QStandardItem)) items);
371     final void insertColumn(int column, ref const(QList!(QStandardItem)) items);
372 /+    pragma(inline, true) final void insertRow(int arow, QStandardItem aitem)
373     { insertRow(arow, cast(QStandardItem)(QList!(QStandardItem)() << aitem)); }
374 +/
375 
376 /+    pragma(inline, true) final bool insertRow(int arow, ref const(QModelIndex) aparent = globalInitVar!QModelIndex)
377     { return QAbstractItemModel.insertRow(arow, aparent); }
378     pragma(inline, true) final bool insertColumn(int acolumn, ref const(QModelIndex) aparent = globalInitVar!QModelIndex)
379     { return QAbstractItemModel.insertColumn(acolumn, aparent); }+/
380 
381     final QStandardItem takeItem(int row, int column = 0);
382     final QList!(QStandardItem) takeRow(int row);
383     final QList!(QStandardItem) takeColumn(int column);
384 
385     final QStandardItem takeHorizontalHeaderItem(int column);
386     final QStandardItem takeVerticalHeaderItem(int row);
387 
388     final const(QStandardItem) itemPrototype() const;
389     final void setItemPrototype(const(QStandardItem) item);
390 
391     final QList!(QStandardItem) findItems(ref const(QString) text,
392                                         /+ Qt:: +/qt.core.namespace.MatchFlags flags = /+ Qt:: +/qt.core.namespace.MatchFlag.MatchExactly,
393                                         int column = 0) const;
394 
395     final int sortRole() const;
396     final void setSortRole(int role);
397 
398     override QStringList mimeTypes() const;
399     override QMimeData mimeData(ref const(QModelIndexList) indexes) const;
400     override bool dropMimeData (const(QMimeData) data, /+ Qt:: +/qt.core.namespace.DropAction action, int row, int column, ref const(QModelIndex) parent);
401 
402 /+ Q_SIGNALS +/public:
403     // ### Qt 6: add changed roles
404     @QSignal final void itemChanged(QStandardItem item);
405 
406 protected:
407     this(ref QStandardItemModelPrivate dd, QObject parent = null);
408 
409 private:
410     /+ friend class QStandardItemPrivate; +/
411     /+ friend class QStandardItem; +/
412     /+ Q_DISABLE_COPY(QStandardItemModel) +/
413     /+ Q_DECLARE_PRIVATE(QStandardItemModel) +/
414 
415     /+ Q_PRIVATE_SLOT(d_func(), void _q_emitItemChanged(const QModelIndex &topLeft,
416                                                      const QModelIndex &bottomRight)) +/
417 }
418 
419 /+ #ifndef QT_NO_DATASTREAM
420 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QStandardItem &item);
421 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &out, const QStandardItem &item);
422 #endif +/
423