eric6/WebBrowser/History/HistoryFilterModel.py

changeset 7268
a28338eaf694
parent 7229
53054eb5b15a
child 7360
9190402e4505
equal deleted inserted replaced
7267:aedc309827c7 7268:a28338eaf694
32 Special method implementing equality. 32 Special method implementing equality.
33 33
34 @param other reference to the object to check against (HistoryData) 34 @param other reference to the object to check against (HistoryData)
35 @return flag indicating equality (boolean) 35 @return flag indicating equality (boolean)
36 """ 36 """
37 return self.tailOffset == other.tailOffset and \ 37 return (
38 self.tailOffset == other.tailOffset and
38 (self.frequency == -1 or other.frequency == -1 or 39 (self.frequency == -1 or other.frequency == -1 or
39 self.frequency == other.frequency) 40 self.frequency == other.frequency)
41 )
40 42
41 def __lt__(self, other): 43 def __lt__(self, other):
42 """ 44 """
43 Special method determining less relation. 45 Special method determining less relation.
44 46
238 """ 240 """
239 if parent is None: 241 if parent is None:
240 parent = QModelIndex() 242 parent = QModelIndex()
241 243
242 self.__load() 244 self.__load()
243 if row < 0 or row >= self.rowCount(parent) or \ 245 if (
244 column < 0 or column >= self.columnCount(parent): 246 row < 0 or
247 row >= self.rowCount(parent) or
248 column < 0 or
249 column >= self.columnCount(parent)
250 ):
245 return QModelIndex() 251 return QModelIndex()
246 252
247 return self.createIndex(row, column, 253 return self.createIndex(row, column,
248 self.__filteredRows[row].tailOffset) 254 self.__filteredRows[row].tailOffset)
249 255
277 self.__historyDict[url] = sourceOffset 283 self.__historyDict[url] = sourceOffset
278 else: 284 else:
279 # the url is known already, so just update the frequency score 285 # the url is known already, so just update the frequency score
280 row = self.__filteredRows.index( 286 row = self.__filteredRows.index(
281 HistoryData(self.__historyDict[url], -1)) 287 HistoryData(self.__historyDict[url], -1))
282 self.__filteredRows[row].frequency += \ 288 self.__filteredRows[row].frequency += self.__frequencyScore(
283 self.__frequencyScore(idx) 289 idx)
284 290
285 self.__loaded = True 291 self.__loaded = True
286 292
287 def __sourceRowsInserted(self, parent, start, end): 293 def __sourceRowsInserted(self, parent, start, end):
288 """ 294 """
336 @return flag indicating successful removal (boolean) 342 @return flag indicating successful removal (boolean)
337 """ 343 """
338 if parent is None: 344 if parent is None:
339 parent = QModelIndex() 345 parent = QModelIndex()
340 346
341 if row < 0 or \ 347 if (
342 count <= 0 or \ 348 row < 0 or
343 row + count > self.rowCount(parent) or \ 349 count <= 0 or
344 parent.isValid(): 350 row + count > self.rowCount(parent) or
351 parent.isValid()
352 ):
345 return False 353 return False
346 354
347 lastRow = row + count - 1 355 lastRow = row + count - 1
348 self.sourceModel().rowsRemoved.disconnect(self.__sourceRowsRemoved) 356 self.sourceModel().rowsRemoved.disconnect(self.__sourceRowsRemoved)
349 self.beginRemoveRows(parent, row, lastRow) 357 self.beginRemoveRows(parent, row, lastRow)
350 oldCount = self.rowCount() 358 oldCount = self.rowCount()
351 start = self.sourceModel().rowCount() - \ 359 start = (
360 self.sourceModel().rowCount() -
352 self.__filteredRows[row].tailOffset 361 self.__filteredRows[row].tailOffset
353 end = self.sourceModel().rowCount() - \ 362 )
363 end = (
364 self.sourceModel().rowCount() -
354 self.__filteredRows[lastRow].tailOffset 365 self.__filteredRows[lastRow].tailOffset
366 )
355 self.sourceModel().removeRows(start, end - start + 1) 367 self.sourceModel().removeRows(start, end - start + 1)
356 self.endRemoveRows() 368 self.endRemoveRows()
357 self.sourceModel().rowsRemoved.connect(self.__sourceRowsRemoved) 369 self.sourceModel().rowsRemoved.connect(self.__sourceRowsRemoved)
358 self.__loaded = False 370 self.__loaded = False
359 if oldCount - count != self.rowCount(): 371 if oldCount - count != self.rowCount():
366 Private method to calculate the frequency score. 378 Private method to calculate the frequency score.
367 379
368 @param sourceIndex index of the source model (QModelIndex) 380 @param sourceIndex index of the source model (QModelIndex)
369 @return frequency score (integer) 381 @return frequency score (integer)
370 """ 382 """
371 loadTime = \ 383 loadTime = self.sourceModel().data(
372 self.sourceModel().data(sourceIndex, HistoryModel.DateTimeRole) 384 sourceIndex, HistoryModel.DateTimeRole)
373 days = loadTime.daysTo(self.__scaleTime) 385 days = loadTime.daysTo(self.__scaleTime)
374 386
375 if days <= 1: 387 if days <= 1:
376 return 100 388 return 100
377 elif days < 8: # within the last week 389 elif days < 8: # within the last week

eric ide

mercurial