64 if date == QDate.currentDate(): |
64 if date == QDate.currentDate(): |
65 return self.trUtf8("Earlier Today") |
65 return self.trUtf8("Earlier Today") |
66 return date.toString("yyyy-MM-dd") |
66 return date.toString("yyyy-MM-dd") |
67 if index.column() == 1: |
67 if index.column() == 1: |
68 return self.trUtf8( |
68 return self.trUtf8( |
69 "%n item(s)", "", self.rowCount(index.sibling(index.row(), 0))) |
69 "%n item(s)", "", |
|
70 self.rowCount(index.sibling(index.row(), 0))) |
70 |
71 |
71 elif role == Qt.DecorationRole: |
72 elif role == Qt.DecorationRole: |
72 if index.column() == 0 and not index.parent().isValid(): |
73 if index.column() == 0 and not index.parent().isValid(): |
73 return UI.PixmapCache.getIcon("history.png") |
74 return UI.PixmapCache.getIcon("history.png") |
74 |
75 |
109 currentDate = QDate() |
110 currentDate = QDate() |
110 rows = 0 |
111 rows = 0 |
111 totalRows = self.sourceModel().rowCount() |
112 totalRows = self.sourceModel().rowCount() |
112 |
113 |
113 for row in range(totalRows): |
114 for row in range(totalRows): |
114 rowDate = \ |
115 rowDate = self.sourceModel().index(row, 0)\ |
115 self.sourceModel().index(row, 0).data(HistoryModel.DateRole) |
116 .data(HistoryModel.DateRole) |
116 if rowDate != currentDate: |
117 if rowDate != currentDate: |
117 self.__sourceRowCache.append(row) |
118 self.__sourceRowCache.append(row) |
118 currentDate = rowDate |
119 currentDate = rowDate |
119 rows += 1 |
120 rows += 1 |
120 return rows |
121 return rows |
209 @param index index of the item (QModelIndex) |
210 @param index index of the item (QModelIndex) |
210 @return flags (Qt.ItemFlags) |
211 @return flags (Qt.ItemFlags) |
211 """ |
212 """ |
212 if not index.isValid(): |
213 if not index.isValid(): |
213 return Qt.ItemFlags(Qt.NoItemFlags) |
214 return Qt.ItemFlags(Qt.NoItemFlags) |
214 return Qt.ItemFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled) |
215 return Qt.ItemFlags( |
|
216 Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled) |
215 |
217 |
216 def setSourceModel(self, sourceModel): |
218 def setSourceModel(self, sourceModel): |
217 """ |
219 """ |
218 Public method to set the source model. |
220 Public method to set the source model. |
219 |
221 |
220 @param sourceModel reference to the source model (QAbstractItemModel) |
222 @param sourceModel reference to the source model (QAbstractItemModel) |
221 """ |
223 """ |
222 if self.sourceModel() is not None: |
224 if self.sourceModel() is not None: |
223 self.sourceModel().modelReset.disconnect(self.__sourceReset) |
225 self.sourceModel().modelReset.disconnect(self.__sourceReset) |
224 self.sourceModel().layoutChanged.disconnect(self.__sourceReset) |
226 self.sourceModel().layoutChanged.disconnect(self.__sourceReset) |
225 self.sourceModel().rowsInserted.disconnect(self.__sourceRowsInserted) |
227 self.sourceModel().rowsInserted.disconnect( |
|
228 self.__sourceRowsInserted) |
226 self.sourceModel().rowsRemoved.disconnect(self.__sourceRowsRemoved) |
229 self.sourceModel().rowsRemoved.disconnect(self.__sourceRowsRemoved) |
227 |
230 |
228 super().setSourceModel(sourceModel) |
231 super().setSourceModel(sourceModel) |
229 |
232 |
230 if self.sourceModel() is not None: |
233 if self.sourceModel() is not None: |
262 treeParent = treeIndex.parent() |
265 treeParent = treeIndex.parent() |
263 if self.rowCount(treeParent) == 1: |
266 if self.rowCount(treeParent) == 1: |
264 self.beginInsertRows(QModelIndex(), 0, 0) |
267 self.beginInsertRows(QModelIndex(), 0, 0) |
265 self.endInsertRows() |
268 self.endInsertRows() |
266 else: |
269 else: |
267 self.beginInsertRows(treeParent, treeIndex.row(), treeIndex.row()) |
270 self.beginInsertRows(treeParent, treeIndex.row(), |
|
271 treeIndex.row()) |
268 self.endInsertRows() |
272 self.endInsertRows() |
269 |
273 |
270 def mapFromSource(self, sourceIndex): |
274 def mapFromSource(self, sourceIndex): |
271 """ |
275 """ |
272 Public method to map an index to the proxy model index. |
276 Public method to map an index to the proxy model index. |
317 else: |
321 else: |
318 # removing whole dates |
322 # removing whole dates |
319 for i in range(row + count - 1, row - 1, -1): |
323 for i in range(row + count - 1, row - 1, -1): |
320 dateParent = self.index(i, 0) |
324 dateParent = self.index(i, 0) |
321 offset = self.__sourceDateRow(dateParent.row()) |
325 offset = self.__sourceDateRow(dateParent.row()) |
322 if not self.sourceModel().removeRows(offset, self.rowCount(dateParent)): |
326 if not self.sourceModel().removeRows( |
|
327 offset, self.rowCount(dateParent)): |
323 return False |
328 return False |
324 return True |
329 return True |
325 |
330 |
326 def __sourceRowsRemoved(self, parent, start, end): |
331 def __sourceRowsRemoved(self, parent, start, end): |
327 """ |
332 """ |