40 |
40 |
41 def __lt__(self, other): |
41 def __lt__(self, other): |
42 """ |
42 """ |
43 Special method determining less relation. |
43 Special method determining less relation. |
44 |
44 |
45 Note: Like the actual history entries the index mapping is sorted in reverse |
45 Note: Like the actual history entries the index mapping is sorted in |
46 order by offset |
46 reverse order by offset |
47 |
47 |
48 @param other reference to the history data object to compare against |
48 @param other reference to the history data object to compare against |
49 (HistoryEntry) |
49 (HistoryEntry) |
50 @return flag indicating less (boolean) |
50 @return flag indicating less (boolean) |
51 """ |
51 """ |
118 @param sourceModel reference to the source model (QAbstractItemModel) |
118 @param sourceModel reference to the source model (QAbstractItemModel) |
119 """ |
119 """ |
120 if self.sourceModel() is not None: |
120 if self.sourceModel() is not None: |
121 self.sourceModel().modelReset.disconnect(self.__sourceReset) |
121 self.sourceModel().modelReset.disconnect(self.__sourceReset) |
122 self.sourceModel().dataChanged.disconnect(self.__sourceDataChanged) |
122 self.sourceModel().dataChanged.disconnect(self.__sourceDataChanged) |
123 self.sourceModel().rowsInserted.disconnect(self.__sourceRowsInserted) |
123 self.sourceModel().rowsInserted.disconnect( |
|
124 self.__sourceRowsInserted) |
124 self.sourceModel().rowsRemoved.disconnect(self.__sourceRowsRemoved) |
125 self.sourceModel().rowsRemoved.disconnect(self.__sourceRowsRemoved) |
125 |
126 |
126 super().setSourceModel(sourceModel) |
127 super().setSourceModel(sourceModel) |
127 |
128 |
128 if self.sourceModel() is not None: |
129 if self.sourceModel() is not None: |
231 self.__load() |
232 self.__load() |
232 if row < 0 or row >= self.rowCount(parent) or \ |
233 if row < 0 or row >= self.rowCount(parent) or \ |
233 column < 0 or column >= self.columnCount(parent): |
234 column < 0 or column >= self.columnCount(parent): |
234 return QModelIndex() |
235 return QModelIndex() |
235 |
236 |
236 return self.createIndex(row, column, self.__filteredRows[row].tailOffset) |
237 return self.createIndex(row, column, |
|
238 self.__filteredRows[row].tailOffset) |
237 |
239 |
238 def parent(self, index): |
240 def parent(self, index): |
239 """ |
241 """ |
240 Public method to get the parent index. |
242 Public method to get the parent index. |
241 |
243 |
263 self.__filteredRows.append( |
265 self.__filteredRows.append( |
264 HistoryData(sourceOffset, self.__frequencyScore(idx))) |
266 HistoryData(sourceOffset, self.__frequencyScore(idx))) |
265 self.__historyDict[url] = sourceOffset |
267 self.__historyDict[url] = sourceOffset |
266 else: |
268 else: |
267 # the url is known already, so just update the frequency score |
269 # the url is known already, so just update the frequency score |
268 row = self.__filteredRows.index(HistoryData(self.__historyDict[url], -1)) |
270 row = self.__filteredRows.index( |
269 self.__filteredRows[row].frequency += self.__frequencyScore(idx) |
271 HistoryData(self.__historyDict[url], -1)) |
|
272 self.__filteredRows[row].frequency += \ |
|
273 self.__frequencyScore(idx) |
270 |
274 |
271 self.__loaded = True |
275 self.__loaded = True |
272 |
276 |
273 def __sourceRowsInserted(self, parent, start, end): |
277 def __sourceRowsInserted(self, parent, start, end): |
274 """ |
278 """ |
284 |
288 |
285 idx = self.sourceModel().index(start, 0, parent) |
289 idx = self.sourceModel().index(start, 0, parent) |
286 url = idx.data(HistoryModel.UrlStringRole) |
290 url = idx.data(HistoryModel.UrlStringRole) |
287 currentFrequency = 0 |
291 currentFrequency = 0 |
288 if url in self.__historyDict: |
292 if url in self.__historyDict: |
289 row = self.__filteredRows.index(HistoryData(self.__historyDict[url], -1)) |
293 row = self.__filteredRows.index( |
|
294 HistoryData(self.__historyDict[url], -1)) |
290 currentFrequency = self.__filteredRows[row].frequency |
295 currentFrequency = self.__filteredRows[row].frequency |
291 self.beginRemoveRows(QModelIndex(), row, row) |
296 self.beginRemoveRows(QModelIndex(), row, row) |
292 del self.__filteredRows[row] |
297 del self.__filteredRows[row] |
293 del self.__historyDict[url] |
298 del self.__historyDict[url] |
294 self.endRemoveRows() |
299 self.endRemoveRows() |
295 |
300 |
296 self.beginInsertRows(QModelIndex(), 0, 0) |
301 self.beginInsertRows(QModelIndex(), 0, 0) |
297 self.__filteredRows.insert(0, HistoryData(self.sourceModel().rowCount(), |
302 self.__filteredRows.insert( |
|
303 0, HistoryData(self.sourceModel().rowCount(), |
298 self.__frequencyScore(idx) + currentFrequency)) |
304 self.__frequencyScore(idx) + currentFrequency)) |
299 self.__historyDict[url] = self.sourceModel().rowCount() |
305 self.__historyDict[url] = self.sourceModel().rowCount() |
300 self.endInsertRows() |
306 self.endInsertRows() |
301 |
307 |
302 def __sourceRowsRemoved(self, parent, start, end): |
308 def __sourceRowsRemoved(self, parent, start, end): |
326 |
332 |
327 lastRow = row + count - 1 |
333 lastRow = row + count - 1 |
328 self.sourceModel().rowsRemoved.disconnect(self.__sourceRowsRemoved) |
334 self.sourceModel().rowsRemoved.disconnect(self.__sourceRowsRemoved) |
329 self.beginRemoveRows(parent, row, lastRow) |
335 self.beginRemoveRows(parent, row, lastRow) |
330 oldCount = self.rowCount() |
336 oldCount = self.rowCount() |
331 start = self.sourceModel().rowCount() - self.__filteredRows[row].tailOffset |
337 start = self.sourceModel().rowCount() - \ |
332 end = self.sourceModel().rowCount() - self.__filteredRows[lastRow].tailOffset |
338 self.__filteredRows[row].tailOffset |
|
339 end = self.sourceModel().rowCount() - \ |
|
340 self.__filteredRows[lastRow].tailOffset |
333 self.sourceModel().removeRows(start, end - start + 1) |
341 self.sourceModel().removeRows(start, end - start + 1) |
334 self.endRemoveRows() |
342 self.endRemoveRows() |
335 self.sourceModel().rowsRemoved.connect(self.__sourceRowsRemoved) |
343 self.sourceModel().rowsRemoved.connect(self.__sourceRowsRemoved) |
336 self.__loaded = False |
344 self.__loaded = False |
337 if oldCount - count != self.rowCount(): |
345 if oldCount - count != self.rowCount(): |