1 module dqml.qabstractitemmodel;
2 
3 import dqml.global;
4 import dqml.dothersideinterface;
5 import dqml.qobject;
6 import dqml.qmodelindex;
7 import dqml.qvariant;
8 import dqml.qmetaobject;
9 import std.string;
10 import core.memory;
11 
12 abstract class QAbstractItemModel : QObject
13 {
14     shared static this()
15     {
16         m_staticMetaObject = new QMetaObject(dos_qabstractitemmodel_qmetaobject());
17     }
18     
19     public static QMetaObject staticMetaObject() 
20     {
21         return m_staticMetaObject;
22     }
23 
24     public override QMetaObject metaObject() 
25     {
26         return m_staticMetaObject;
27     }
28 
29     public abstract int rowCount(QModelIndex parentIndex);
30     
31     public abstract int columnCount(QModelIndex parentIndex);
32 
33     public abstract QVariant data(QModelIndex index, int role);
34 
35     public abstract QModelIndex parent(QModelIndex child);
36     
37     public abstract QModelIndex index(int row, int column, QModelIndex parent);
38     
39     public bool setData(QModelIndex index, QVariant value, int role)
40     {
41         return dos_qabstractitemmodel_setData(voidPointer(), index.voidPointer(), value.voidPointer(), role);
42     }
43 
44     public string[int] roleNames()
45     {
46         return null;
47     }
48 
49     public int flags(QModelIndex index)
50     {
51         return dos_qabstractitemmodel_flags(voidPointer(), index.voidPointer());
52     }
53 
54     public QVariant headerData(int section, int orientation, int role)
55     {
56         auto result = dos_qabstractitemmodel_headerData(voidPointer(), section, orientation, role);
57         return new QVariant(result, Ownership.Take);
58     }
59 
60   public bool hasChildren(QModelIndex parent)
61   {
62     return dos_qabstractitemmodel_hasChildren(voidPointer(), parent.voidPointer());
63   }
64 
65   public bool hasIndex(int row, int column, QModelIndex parent)
66   {
67     return dos_qabstractitemmodel_hasIndex(voidPointer(), row, column, parent.voidPointer());
68   }
69     
70   public bool canFetchMore(QModelIndex parent)
71   {
72     return dos_qabstractitemmodel_canFetchMore(voidPointer(), parent.voidPointer());
73   }
74 
75   public void fetchMore(QModelIndex parent)
76   {
77     dos_qabstractitemmodel_fetchMore(voidPointer(), parent.voidPointer());
78   }
79 
80   protected override void* createVoidPointer()
81     {
82         DosQAbstractItemModelCallbacks callbacks;
83         callbacks.rowCount = &rowCountCallback;
84 	callbacks.columnCount = &columnCountCallback;
85 	callbacks.data = &dataCallback;
86 	callbacks.setData = &setDataCallback;
87 	callbacks.headerData = &headerDataCallback;
88 	callbacks.roleNames = &roleNamesCallback;
89 	callbacks.flags = &flagsCallback;
90 	callbacks.index = &indexCallback;
91 	callbacks.parent = &parentCallback;
92 	callbacks.hasChildren = &hasChildrenCallback;
93 	callbacks.canFetchMore = &canFetchMoreCallback;
94 	callbacks.fetchMore = &fetchMoreCallback;
95 
96         return dos_qabstractitemmodel_create(cast(void*)this,
97                                              metaObject().voidPointer(),
98                                              &staticSlotCallback,
99 					     callbacks);
100     }
101 
102     protected final void beginInsertRows(QModelIndex parent, int first, int last)
103     {
104         dos_qabstractitemmodel_beginInsertRows(this.vptr, parent.voidPointer(), first, last);
105     }
106 
107     protected final void endInsertRows()
108     {
109         dos_qabstractitemmodel_endInsertRows(this.vptr);
110     }
111 
112     protected final void beginRemoveRows(QModelIndex parent, int first, int last)
113     {
114         dos_qabstractitemmodel_beginRemoveRows(this.vptr, parent.voidPointer(), first, last);
115     }
116 
117     protected final void endRemoveRows()
118     {
119         dos_qabstractitemmodel_endRemoveRows(this.vptr);
120     }
121     
122     protected final void beginInsertColumns(QModelIndex parent, int first, int last)
123     {
124         dos_qabstractitemmodel_beginInsertColumns(this.vptr, parent.voidPointer(), first, last);
125     }
126 
127     protected final void endInsertColumns()
128     {
129         dos_qabstractitemmodel_endInsertColumns(this.vptr);
130     }
131 
132     protected final void beginRemoveColumns(QModelIndex parent, int first, int last)
133     {
134         dos_qabstractitemmodel_beginRemoveColumns(this.vptr, parent.voidPointer(), first, last);
135     }
136 
137     protected final void endRemoveColumns()
138     {
139         dos_qabstractitemmodel_endRemoveColumns(this.vptr);
140     }
141 
142     protected final void beginResetModel()
143     {
144         dos_qabstractitemmodel_beginResetModel(this.vptr);
145     }
146 
147     protected final void endResetModel()
148     {
149         dos_qabstractitemmodel_endResetModel(this.vptr);
150     }
151     
152     protected final QModelIndex createIndex(int row, int column, void* data)
153     {
154         auto index = dos_qabstractitemmodel_createIndex(this.vptr, row, column, data);
155         return new QModelIndex(index, Ownership.Take);
156     }
157 
158     protected final void dataChanged(QModelIndex topLeft, QModelIndex bottomRight, int[] roles)
159     {
160         dos_qabstractitemmodel_dataChanged(this.vptr,
161                                            topLeft.voidPointer(),
162                                            bottomRight.voidPointer(),
163                                            roles.ptr,
164                                            cast(int)(roles.length));
165     }
166 
167     protected extern (C) static void rowCountCallback(void* modelPtr,
168                                                     void* indexPtr,
169                                                     ref int result)
170     {
171         auto model = cast(QAbstractItemModel)(modelPtr);
172         auto index = new QModelIndex(indexPtr, Ownership.Clone);
173         result = model.rowCount(index);
174     }
175 
176     protected extern (C) static void columnCountCallback(void* modelPtr,
177                                                        void* indexPtr,
178                                                        ref int result)
179     {
180         auto model = cast(QAbstractItemModel)(modelPtr);
181         auto index = new QModelIndex(indexPtr, Ownership.Clone);
182         result = model.columnCount(index);
183     }
184 
185     protected extern (C) static void dataCallback(void* modelPtr,
186                                                 void* indexPtr,
187                                                 int role,
188                                                 void* result)
189     {
190         auto model = cast(QAbstractItemModel)(modelPtr);
191         auto index = new QModelIndex(indexPtr, Ownership.Clone);
192         auto value = model.data(index, role);
193         if (value is null)
194             return;
195         dos_qvariant_assign(result, value.voidPointer());
196     }
197 
198     protected extern (C) static void setDataCallback(void* modelPtr,
199                                                    void* indexPtr,
200                                                    void* valuePtr,
201                                                    int role,
202                                                    ref bool result)
203     {
204         auto model = cast(QAbstractItemModel)(modelPtr);
205         auto index = new QModelIndex(indexPtr, Ownership.Clone);
206         auto value = new QVariant(valuePtr, Ownership.Clone);
207         result = model.setData(index, value, role);
208     }
209 
210     protected extern (C) static void roleNamesCallback(void* modelPtr,
211                                                      void* result)
212     {
213         auto model = cast(QAbstractItemModel)(modelPtr);
214         auto roles = model.roleNames();
215         foreach(int key; roles.keys) {
216             dos_qhash_int_qbytearray_insert(result, key, roles[key].toStringz());
217         }
218     }
219 
220     protected extern (C) static void flagsCallback(void* modelPtr,
221                                                  void* indexPtr,
222                                                  ref int result)
223     {
224         auto model = cast(QAbstractItemModel)(modelPtr);
225         auto index = new QModelIndex(indexPtr, Ownership.Clone);
226         result = model.flags(index);
227     }
228 
229     protected extern (C) static void headerDataCallback(void* modelPtr,
230                                                       int section,
231                                                       int orientation,
232                                                       int role,
233                                                       void* result)
234     {
235         auto model = cast(QAbstractItemModel)(modelPtr);
236         QVariant value = model.headerData(section, orientation, role);
237         if (value is null)
238             return;
239         dos_qvariant_assign(result, value.voidPointer());
240     }
241     
242     protected extern (C) static void indexCallback(void* modelPtr,
243                                                  int row,
244                                                  int column,
245                                                  void* parentIndex,
246                                                  void* result)
247     {
248         auto model = cast(QAbstractItemModel)(modelPtr);
249         QModelIndex value = model.index(row, column, new QModelIndex(parentIndex, Ownership.Clone));
250         dos_qmodelindex_assign(result, value.voidPointer());
251     }
252     
253     protected extern (C) static void parentCallback(void* modelPtr,
254                                                  void* childIndex,
255                                                  void* result)
256     {
257         auto model = cast(QAbstractItemModel)(modelPtr);
258         QModelIndex value = model.parent(new QModelIndex(childIndex, Ownership.Clone));
259         dos_qmodelindex_assign(result, value.voidPointer());
260     }
261 
262     protected extern (C) static void hasChildrenCallback(void* modelPtr,
263 							 void* parentIndex,
264 							 ref bool result)
265     {
266         auto model = cast(QAbstractItemModel)(modelPtr);
267 	result = model.hasChildren(new QModelIndex(parentIndex, Ownership.Clone));
268     }
269 
270     protected extern (C) static void canFetchMoreCallback(void* modelPtr,
271 							  void* parentIndex,
272 							  ref bool result)
273     {
274         auto model = cast(QAbstractItemModel)(modelPtr);
275 	result = model.canFetchMore(new QModelIndex(parentIndex, Ownership.Clone));
276     }
277 
278     protected extern (C) static void fetchMoreCallback(void* modelPtr,
279 						       void* parentIndex)
280 					
281     {
282         auto model = cast(QAbstractItemModel)(modelPtr);
283 	model.fetchMore(new QModelIndex(parentIndex, Ownership.Clone));
284     }
285 
286     private static QMetaObject m_staticMetaObject;
287 }