Helpviewer/History/HistoryFilterModel.py

changeset 7
c679fb30c8f3
parent 6
52e8c820d0dd
child 12
1d8dd9706f46
equal deleted inserted replaced
6:52e8c820d0dd 7:c679fb30c8f3
100 """ 100 """
101 Public method to get data from the model. 101 Public method to get data from the model.
102 102
103 @param index index of history entry to get data for (QModelIndex) 103 @param index index of history entry to get data for (QModelIndex)
104 @param role data role (integer) 104 @param role data role (integer)
105 @return history entry data (QVariant) 105 @return history entry data
106 """ 106 """
107 if role == self.FrequencyRole and index.isValid(): 107 if role == self.FrequencyRole and index.isValid():
108 return QVariant(self.__filteredRows[index.row()].frequency) 108 return self.__filteredRows[index.row()].frequency
109 109
110 return QAbstractProxyModel.data(self, index, role) 110 return QAbstractProxyModel.data(self, index, role)
111 111
112 def setSourceModel(self, sourceModel): 112 def setSourceModel(self, sourceModel):
113 """ 113 """
161 Public method to get the header data. 161 Public method to get the header data.
162 162
163 @param section section number (integer) 163 @param section section number (integer)
164 @param orientation header orientation (Qt.Orientation) 164 @param orientation header orientation (Qt.Orientation)
165 @param role data role (integer) 165 @param role data role (integer)
166 @return header data (QVariant) 166 @return header data
167 """ 167 """
168 return self.sourceModel().headerData(section, orientation, role) 168 return self.sourceModel().headerData(section, orientation, role)
169 169
170 def recalculateFrequencies(self): 170 def recalculateFrequencies(self):
171 """ 171 """
218 218
219 @param sourceIndex reference to a source model index (QModelIndex) 219 @param sourceIndex reference to a source model index (QModelIndex)
220 @return proxy model index (QModelIndex) 220 @return proxy model index (QModelIndex)
221 """ 221 """
222 self.__load() 222 self.__load()
223 url = sourceIndex.data(HistoryModel.UrlStringRole).toString() 223 url = sourceIndex.data(HistoryModel.UrlStringRole)
224 if url not in self.__historyDict: 224 if url not in self.__historyDict:
225 return QModelIndex() 225 return QModelIndex()
226 226
227 sourceOffset = self.sourceModel().rowCount() - sourceIndex.row() 227 sourceOffset = self.sourceModel().rowCount() - sourceIndex.row()
228 228
269 self.__historyDict = {} 269 self.__historyDict = {}
270 self.__scaleTime = QDateTime.currentDateTime() 270 self.__scaleTime = QDateTime.currentDateTime()
271 271
272 for sourceRow in range(self.sourceModel().rowCount()): 272 for sourceRow in range(self.sourceModel().rowCount()):
273 idx = self.sourceModel().index(sourceRow, 0) 273 idx = self.sourceModel().index(sourceRow, 0)
274 url = idx.data(HistoryModel.UrlStringRole).toString() 274 url = idx.data(HistoryModel.UrlStringRole)
275 if url not in self.__historyDict: 275 if url not in self.__historyDict:
276 sourceOffset = self.sourceModel().rowCount() - sourceRow 276 sourceOffset = self.sourceModel().rowCount() - sourceRow
277 self.__filteredRows.append( 277 self.__filteredRows.append(
278 HistoryData(sourceOffset, self.__frequencyScore(idx))) 278 HistoryData(sourceOffset, self.__frequencyScore(idx)))
279 self.__historyDict[url] = sourceOffset 279 self.__historyDict[url] = sourceOffset
295 if start == end and start == 0: 295 if start == end and start == 0:
296 if not self.__loaded: 296 if not self.__loaded:
297 return 297 return
298 298
299 idx = self.sourceModel().index(start, 0, parent) 299 idx = self.sourceModel().index(start, 0, parent)
300 url = idx.data(HistoryModel.UrlStringRole).toString() 300 url = idx.data(HistoryModel.UrlStringRole)
301 currentFrequency = 0 301 currentFrequency = 0
302 if url in self.__historyDict: 302 if url in self.__historyDict:
303 row = self.__filteredRows.index(HistoryData(self.__historyDict[url], -1)) 303 row = self.__filteredRows.index(HistoryData(self.__historyDict[url], -1))
304 currentFrequency = self.__filteredRows[row].frequency 304 currentFrequency = self.__filteredRows[row].frequency
305 self.beginRemoveRows(QModelIndex(), row, row) 305 self.beginRemoveRows(QModelIndex(), row, row)
362 362
363 @param sourceIndex index of the source model (QModelIndex) 363 @param sourceIndex index of the source model (QModelIndex)
364 @return frequency score (integer) 364 @return frequency score (integer)
365 """ 365 """
366 loadTime = \ 366 loadTime = \
367 self.sourceModel().data(sourceIndex, HistoryModel.DateTimeRole).toDateTime() 367 self.sourceModel().data(sourceIndex, HistoryModel.DateTimeRole)
368 days = loadTime.daysTo(self.__scaleTime) 368 days = loadTime.daysTo(self.__scaleTime)
369 369
370 if days <= 1: 370 if days <= 1:
371 return 100 371 return 100
372 elif days < 8: # within the last week 372 elif days < 8: # within the last week

eric ide

mercurial