101 @return number of rows (integer) |
101 @return number of rows (integer) |
102 """ |
102 """ |
103 if parent is None: |
103 if parent is None: |
104 parent = QModelIndex() |
104 parent = QModelIndex() |
105 |
105 |
106 if parent.internalId() != 0 or \ |
106 if ( |
107 parent.column() > 0 or \ |
107 parent.internalId() != 0 or |
108 self.sourceModel() is None: |
108 parent.column() > 0 or |
|
109 self.sourceModel() is None |
|
110 ): |
109 return 0 |
111 return 0 |
110 |
112 |
111 # row count OF dates |
113 # row count OF dates |
112 if not parent.isValid(): |
114 if not parent.isValid(): |
113 if self.__sourceRowCache: |
115 if self.__sourceRowCache: |
116 currentDate = QDate() |
118 currentDate = QDate() |
117 rows = 0 |
119 rows = 0 |
118 totalRows = self.sourceModel().rowCount() |
120 totalRows = self.sourceModel().rowCount() |
119 |
121 |
120 for row in range(totalRows): |
122 for row in range(totalRows): |
121 rowDate = self.sourceModel().index(row, 0)\ |
123 rowDate = self.sourceModel().index(row, 0).data( |
122 .data(HistoryModel.DateRole) |
124 HistoryModel.DateRole) |
123 if rowDate != currentDate: |
125 if rowDate != currentDate: |
124 self.__sourceRowCache.append(row) |
126 self.__sourceRowCache.append(row) |
125 currentDate = rowDate |
127 currentDate = rowDate |
126 rows += 1 |
128 rows += 1 |
127 return rows |
129 return rows |
176 @return requested index (QModelIndex) |
178 @return requested index (QModelIndex) |
177 """ |
179 """ |
178 if parent is None: |
180 if parent is None: |
179 parent = QModelIndex() |
181 parent = QModelIndex() |
180 |
182 |
181 if row < 0 or \ |
183 if ( |
182 column < 0 or \ |
184 row < 0 or |
183 column >= self.columnCount(parent) or \ |
185 column < 0 or |
184 parent.column() > 0: |
186 column >= self.columnCount(parent) or |
|
187 parent.column() > 0 |
|
188 ): |
185 return QModelIndex() |
189 return QModelIndex() |
186 |
190 |
187 if not parent.isValid(): |
191 if not parent.isValid(): |
188 return self.createIndex(row, column, 0) |
192 return self.createIndex(row, column, 0) |
189 return self.createIndex(row, column, parent.row() + 1) |
193 return self.createIndex(row, column, parent.row() + 1) |
301 |
305 |
302 try: |
306 try: |
303 row = self.__sourceRowCache.index(sourceIndex.row()) |
307 row = self.__sourceRowCache.index(sourceIndex.row()) |
304 except ValueError: |
308 except ValueError: |
305 row = bisect.bisect_left(self.__sourceRowCache, sourceIndex.row()) |
309 row = bisect.bisect_left(self.__sourceRowCache, sourceIndex.row()) |
306 if row == len(self.__sourceRowCache) or \ |
310 if ( |
307 self.__sourceRowCache[row] != sourceIndex.row(): |
311 row == len(self.__sourceRowCache) or |
|
312 self.__sourceRowCache[row] != sourceIndex.row() |
|
313 ): |
308 row -= 1 |
314 row -= 1 |
309 dateRow = max(0, row) |
315 dateRow = max(0, row) |
310 row = sourceIndex.row() - self.__sourceRowCache[dateRow] |
316 row = sourceIndex.row() - self.__sourceRowCache[dateRow] |
311 return self.createIndex(row, sourceIndex.column(), dateRow + 1) |
317 return self.createIndex(row, sourceIndex.column(), dateRow + 1) |
312 |
318 |
320 @return flag indicating successful removal (boolean) |
326 @return flag indicating successful removal (boolean) |
321 """ |
327 """ |
322 if parent is None: |
328 if parent is None: |
323 parent = QModelIndex() |
329 parent = QModelIndex() |
324 |
330 |
325 if row < 0 or \ |
331 if ( |
326 count <= 0 or \ |
332 row < 0 or |
327 row + count > self.rowCount(parent): |
333 count <= 0 or |
|
334 row + count > self.rowCount(parent) |
|
335 ): |
328 return False |
336 return False |
329 |
337 |
330 self.__removingDown = True |
338 self.__removingDown = True |
331 if parent.isValid() and self.rowCount(parent) == count - row: |
339 if parent.isValid() and self.rowCount(parent) == count - row: |
332 self.beginRemoveRows(QModelIndex(), parent.row(), parent.row()) |
340 self.beginRemoveRows(QModelIndex(), parent.row(), parent.row()) |
366 while i >= start: |
374 while i >= start: |
367 try: |
375 try: |
368 ind = self.__sourceRowCache.index(i) |
376 ind = self.__sourceRowCache.index(i) |
369 except ValueError: |
377 except ValueError: |
370 ind = bisect.bisect_left(self.__sourceRowCache, i) |
378 ind = bisect.bisect_left(self.__sourceRowCache, i) |
371 if ind == len(self.__sourceRowCache) or \ |
379 if ( |
372 self.__sourceRowCache[ind] != i: |
380 ind == len(self.__sourceRowCache) or |
|
381 self.__sourceRowCache[ind] != i |
|
382 ): |
373 ind -= 1 |
383 ind -= 1 |
374 row = max(0, ind) |
384 row = max(0, ind) |
375 offset = self.__sourceRowCache[row] |
385 offset = self.__sourceRowCache[row] |
376 dateParent = self.index(row, 0) |
386 dateParent = self.index(row, 0) |
377 # If we can remove all the rows in the date do that |
387 # If we can remove all the rows in the date do that |