23 |
23 |
24 def __init__(self, sourceModel, parent=None): |
24 def __init__(self, sourceModel, parent=None): |
25 """ |
25 """ |
26 Constructor |
26 Constructor |
27 |
27 |
28 @param sourceModel reference to the source model (QAbstractItemModel) |
28 @param sourceModel reference to the source model |
29 @param parent reference to the parent object (QObject) |
29 @type QAbstractItemModel |
|
30 @param parent reference to the parent object |
|
31 @type QObject |
30 """ |
32 """ |
31 super().__init__(parent) |
33 super().__init__(parent) |
32 |
34 |
33 self.__sourceRowCache = [] |
35 self.__sourceRowCache = [] |
34 self.__removingDown = False |
36 self.__removingDown = False |
37 |
39 |
38 def headerData(self, section, orientation, role=Qt.ItemDataRole.DisplayRole): |
40 def headerData(self, section, orientation, role=Qt.ItemDataRole.DisplayRole): |
39 """ |
41 """ |
40 Public method to get the header data. |
42 Public method to get the header data. |
41 |
43 |
42 @param section section number (integer) |
44 @param section section number |
43 @param orientation header orientation (Qt.Orientation) |
45 @type int |
44 @param role data role (Qt.ItemDataRole) |
46 @param orientation header orientation |
|
47 @type Qt.Orientation |
|
48 @param role data role |
|
49 @type Qt.ItemDataRole |
45 @return header data |
50 @return header data |
|
51 @rtype Any |
46 """ |
52 """ |
47 return self.sourceModel().headerData(section, orientation, role) |
53 return self.sourceModel().headerData(section, orientation, role) |
48 |
54 |
49 def data(self, index, role=Qt.ItemDataRole.DisplayRole): |
55 def data(self, index, role=Qt.ItemDataRole.DisplayRole): |
50 """ |
56 """ |
51 Public method to get data from the model. |
57 Public method to get data from the model. |
52 |
58 |
53 @param index index of history entry to get data for (QModelIndex) |
59 @param index index of history entry to get data for |
54 @param role data role (integer) |
60 @type QModelIndex |
|
61 @param role data role |
|
62 @type int |
55 @return history entry data |
63 @return history entry data |
|
64 @rtype Any |
56 """ |
65 """ |
57 if role in [Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole]: |
66 if role in [Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole]: |
58 start = index.internalId() |
67 start = index.internalId() |
59 if start == 0: |
68 if start == 0: |
60 offset = self.__sourceDateRow(index.row()) |
69 offset = self.__sourceDateRow(index.row()) |
89 |
98 |
90 def columnCount(self, parent=None): |
99 def columnCount(self, parent=None): |
91 """ |
100 """ |
92 Public method to get the number of columns. |
101 Public method to get the number of columns. |
93 |
102 |
94 @param parent index of parent (QModelIndex) |
103 @param parent index of parent |
95 @return number of columns (integer) |
104 @type QModelIndex |
|
105 @return number of columns |
|
106 @rtype int |
96 """ |
107 """ |
97 if parent is None: |
108 if parent is None: |
98 parent = QModelIndex() |
109 parent = QModelIndex() |
99 |
110 |
100 return self.sourceModel().columnCount(self.mapToSource(parent)) |
111 return self.sourceModel().columnCount(self.mapToSource(parent)) |
101 |
112 |
102 def rowCount(self, parent=None): |
113 def rowCount(self, parent=None): |
103 """ |
114 """ |
104 Public method to determine the number of rows. |
115 Public method to determine the number of rows. |
105 |
116 |
106 @param parent index of parent (QModelIndex) |
117 @param parent index of parent |
107 @return number of rows (integer) |
118 @type QModelIndex |
|
119 @return number of rows |
|
120 @rtype int |
108 """ |
121 """ |
109 if parent is None: |
122 if parent is None: |
110 parent = QModelIndex() |
123 parent = QModelIndex() |
111 |
124 |
112 if ( |
125 if ( |
141 def __sourceDateRow(self, row): |
154 def __sourceDateRow(self, row): |
142 """ |
155 """ |
143 Private method to translate the top level date row into the offset |
156 Private method to translate the top level date row into the offset |
144 where that date starts. |
157 where that date starts. |
145 |
158 |
146 @param row row number of the date (integer) |
159 @param row row number of the date |
147 @return offset where that date starts (integer) |
160 @type int |
|
161 @return offset where that date starts |
|
162 @rtype int |
148 """ |
163 """ |
149 if row <= 0: |
164 if row <= 0: |
150 return 0 |
165 return 0 |
151 |
166 |
152 if len(self.__sourceRowCache) == 0: |
167 if len(self.__sourceRowCache) == 0: |
161 |
176 |
162 def mapToSource(self, proxyIndex): |
177 def mapToSource(self, proxyIndex): |
163 """ |
178 """ |
164 Public method to map an index to the source model index. |
179 Public method to map an index to the source model index. |
165 |
180 |
166 @param proxyIndex reference to a proxy model index (QModelIndex) |
181 @param proxyIndex reference to a proxy model index |
167 @return source model index (QModelIndex) |
182 @type QModelIndex |
|
183 @return source model index |
|
184 @rtype QModelIndex |
168 """ |
185 """ |
169 offset = proxyIndex.internalId() |
186 offset = proxyIndex.internalId() |
170 if offset == 0: |
187 if offset == 0: |
171 return QModelIndex() |
188 return QModelIndex() |
172 startDateRow = self.__sourceDateRow(offset - 1) |
189 startDateRow = self.__sourceDateRow(offset - 1) |
176 |
193 |
177 def index(self, row, column, parent=None): |
194 def index(self, row, column, parent=None): |
178 """ |
195 """ |
179 Public method to create an index. |
196 Public method to create an index. |
180 |
197 |
181 @param row row number for the index (integer) |
198 @param row row number for the index |
182 @param column column number for the index (integer) |
199 @type int |
183 @param parent index of the parent item (QModelIndex) |
200 @param column column number for the index |
184 @return requested index (QModelIndex) |
201 @type int |
|
202 @param parent index of the parent item |
|
203 @type QModelIndex |
|
204 @return requested index |
|
205 @rtype QModelIndex |
185 """ |
206 """ |
186 if parent is None: |
207 if parent is None: |
187 parent = QModelIndex() |
208 parent = QModelIndex() |
188 |
209 |
189 if ( |
210 if ( |
200 |
221 |
201 def parent(self, index): |
222 def parent(self, index): |
202 """ |
223 """ |
203 Public method to get the parent index. |
224 Public method to get the parent index. |
204 |
225 |
205 @param index index of item to get parent (QModelIndex) |
226 @param index index of item to get parent |
206 @return index of parent (QModelIndex) |
227 @type QModelIndex |
|
228 @return index of parent |
|
229 @rtype QModelIndex |
207 """ |
230 """ |
208 offset = index.internalId() |
231 offset = index.internalId() |
209 if offset == 0 or not index.isValid(): |
232 if offset == 0 or not index.isValid(): |
210 return QModelIndex() |
233 return QModelIndex() |
211 return self.createIndex(offset - 1, 0, 0) |
234 return self.createIndex(offset - 1, 0, 0) |
212 |
235 |
213 def hasChildren(self, parent=None): |
236 def hasChildren(self, parent=None): |
214 """ |
237 """ |
215 Public method to check, if an entry has some children. |
238 Public method to check, if an entry has some children. |
216 |
239 |
217 @param parent index of the entry to check (QModelIndex) |
240 @param parent index of the entry to check |
218 @return flag indicating the presence of children (boolean) |
241 @type QModelIndex |
|
242 @return flag indicating the presence of children |
|
243 @rtype bool |
219 """ |
244 """ |
220 if parent is None: |
245 if parent is None: |
221 parent = QModelIndex() |
246 parent = QModelIndex() |
222 |
247 |
223 grandparent = parent.parent() |
248 grandparent = parent.parent() |
227 |
252 |
228 def flags(self, index): |
253 def flags(self, index): |
229 """ |
254 """ |
230 Public method to get the item flags. |
255 Public method to get the item flags. |
231 |
256 |
232 @param index index of the item (QModelIndex) |
257 @param index index of the item |
233 @return flags (Qt.ItemFlags) |
258 @type QModelIndex |
|
259 @return flags |
|
260 @rtype Qt.ItemFlags |
234 """ |
261 """ |
235 return ( |
262 return ( |
236 Qt.ItemFlag.NoItemFlags |
263 Qt.ItemFlag.NoItemFlags |
237 if not index.isValid() |
264 if not index.isValid() |
238 else ( |
265 else ( |
244 |
271 |
245 def setSourceModel(self, sourceModel): |
272 def setSourceModel(self, sourceModel): |
246 """ |
273 """ |
247 Public method to set the source model. |
274 Public method to set the source model. |
248 |
275 |
249 @param sourceModel reference to the source model (QAbstractItemModel) |
276 @param sourceModel reference to the source model |
|
277 @type QAbstractItemModel |
250 """ |
278 """ |
251 if self.sourceModel() is not None: |
279 if self.sourceModel() is not None: |
252 self.sourceModel().modelReset.disconnect(self.__sourceReset) |
280 self.sourceModel().modelReset.disconnect(self.__sourceReset) |
253 self.sourceModel().layoutChanged.disconnect(self.__sourceReset) |
281 self.sourceModel().layoutChanged.disconnect(self.__sourceReset) |
254 self.sourceModel().rowsInserted.disconnect(self.__sourceRowsInserted) |
282 self.sourceModel().rowsInserted.disconnect(self.__sourceRowsInserted) |
276 |
304 |
277 def __sourceRowsInserted(self, parent, start, end): |
305 def __sourceRowsInserted(self, parent, start, end): |
278 """ |
306 """ |
279 Private slot to handle the insertion of data in the source model. |
307 Private slot to handle the insertion of data in the source model. |
280 |
308 |
281 @param parent reference to the parent index (QModelIndex) |
309 @param parent reference to the parent index |
282 @param start start row (integer) |
310 @type QModelIndex |
283 @param end end row (integer) |
311 @param start start row |
|
312 @type int |
|
313 @param end end row |
|
314 @type int |
284 """ |
315 """ |
285 if not parent.isValid(): |
316 if not parent.isValid(): |
286 if start != 0 or start != end: |
317 if start != 0 or start != end: |
287 self.beginResetModel() |
318 self.beginResetModel() |
288 self.__sourceRowCache = [] |
319 self.__sourceRowCache = [] |
301 |
332 |
302 def mapFromSource(self, sourceIndex): |
333 def mapFromSource(self, sourceIndex): |
303 """ |
334 """ |
304 Public method to map an index to the proxy model index. |
335 Public method to map an index to the proxy model index. |
305 |
336 |
306 @param sourceIndex reference to a source model index (QModelIndex) |
337 @param sourceIndex reference to a source model index |
307 @return proxy model index (QModelIndex) |
338 @type QModelIndex |
|
339 @return proxy model index |
|
340 @rtype QModelIndex |
308 """ |
341 """ |
309 if not sourceIndex.isValid(): |
342 if not sourceIndex.isValid(): |
310 return QModelIndex() |
343 return QModelIndex() |
311 |
344 |
312 if len(self.__sourceRowCache) == 0: |
345 if len(self.__sourceRowCache) == 0: |
327 |
360 |
328 def removeRows(self, row, count, parent=None): |
361 def removeRows(self, row, count, parent=None): |
329 """ |
362 """ |
330 Public method to remove entries from the model. |
363 Public method to remove entries from the model. |
331 |
364 |
332 @param row row of the first entry to remove (integer) |
365 @param row row of the first entry to remove |
333 @param count number of entries to remove (integer) |
366 @type int |
334 @param parent index of the parent entry (QModelIndex) |
367 @param count number of entries to remove |
335 @return flag indicating successful removal (boolean) |
368 @type int |
|
369 @param parent index of the parent entry |
|
370 @type QModelIndex |
|
371 @return flag indicating successful removal |
|
372 @rtype bool |
336 """ |
373 """ |
337 if parent is None: |
374 if parent is None: |
338 parent = QModelIndex() |
375 parent = QModelIndex() |
339 |
376 |
340 if row < 0 or count <= 0 or row + count > self.rowCount(parent): |
377 if row < 0 or count <= 0 or row + count > self.rowCount(parent): |
360 |
397 |
361 def __sourceRowsRemoved(self, parent, start, end): |
398 def __sourceRowsRemoved(self, parent, start, end): |
362 """ |
399 """ |
363 Private slot to handle the removal of data in the source model. |
400 Private slot to handle the removal of data in the source model. |
364 |
401 |
365 @param parent reference to the parent index (QModelIndex) |
402 @param parent reference to the parent index |
366 @param start start row (integer) |
403 @type QModelIndex |
367 @param end end row (integer) |
404 @param start start row |
|
405 @type int |
|
406 @param end end row |
|
407 @type int |
368 """ |
408 """ |
369 if not self.__removingDown: |
409 if not self.__removingDown: |
370 self.beginResetModel() |
410 self.beginResetModel() |
371 self.__sourceRowCache = [] |
411 self.__sourceRowCache = [] |
372 self.endResetModel() |
412 self.endResetModel() |