Helpviewer/History/HistoryFilterModel.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1112
8a7d1b9d18db
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
9 9
10 from PyQt4.QtCore import * 10 from PyQt4.QtCore import *
11 from PyQt4.QtGui import QAbstractProxyModel 11 from PyQt4.QtGui import QAbstractProxyModel
12 12
13 from .HistoryModel import HistoryModel 13 from .HistoryModel import HistoryModel
14
14 15
15 class HistoryData(object): 16 class HistoryData(object):
16 """ 17 """
17 Class storing some history data. 18 Class storing some history data.
18 """ 19 """
19 def __init__(self, offset, frequency = 0): 20 def __init__(self, offset, frequency=0):
20 """ 21 """
21 Constructor 22 Constructor
22 23
23 @param offset tail offset (integer) 24 @param offset tail offset (integer)
24 @param frequency frequency (integer) 25 @param frequency frequency (integer)
39 40
40 def __lt__(self, other): 41 def __lt__(self, other):
41 """ 42 """
42 Special method determining less relation. 43 Special method determining less relation.
43 44
44 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 reverse
45 order by offset 46 order by offset
46 47
47 @param other reference to the history data object to compare against 48 @param other reference to the history data object to compare against
48 (HistoryEntry) 49 (HistoryEntry)
49 @return flag indicating less (boolean) 50 @return flag indicating less (boolean)
50 """ 51 """
51 return self.tailOffset > other.tailOffset 52 return self.tailOffset > other.tailOffset
53
52 54
53 class HistoryFilterModel(QAbstractProxyModel): 55 class HistoryFilterModel(QAbstractProxyModel):
54 """ 56 """
55 Class implementing the history filter model. 57 Class implementing the history filter model.
56 """ 58 """
57 FrequencyRole = HistoryModel.MaxRole + 1 59 FrequencyRole = HistoryModel.MaxRole + 1
58 MaxRole = FrequencyRole 60 MaxRole = FrequencyRole
59 61
60 def __init__(self, sourceModel, parent = None): 62 def __init__(self, sourceModel, parent=None):
61 """ 63 """
62 Constructor 64 Constructor
63 65
64 @param sourceModel reference to the source model (QAbstractItemModel) 66 @param sourceModel reference to the source model (QAbstractItemModel)
65 @param parent reference to the parent object (QObject) 67 @param parent reference to the parent object (QObject)
94 if url not in self.__historyDict: 96 if url not in self.__historyDict:
95 return 0 97 return 0
96 98
97 return self.sourceModel().rowCount() - self.__historyDict[url] 99 return self.sourceModel().rowCount() - self.__historyDict[url]
98 100
99 def data(self, index, role = Qt.DisplayRole): 101 def data(self, index, role=Qt.DisplayRole):
100 """ 102 """
101 Public method to get data from the model. 103 Public method to get data from the model.
102 104
103 @param index index of history entry to get data for (QModelIndex) 105 @param index index of history entry to get data for (QModelIndex)
104 @param role data role (integer) 106 @param role data role (integer)
138 @param bottomRight index of bottom right data element (QModelIndex) 140 @param bottomRight index of bottom right data element (QModelIndex)
139 """ 141 """
140 self.dataChanged.emit( 142 self.dataChanged.emit(
141 self.mapFromSource(topLeft), self.mapFromSource(bottomRight)) 143 self.mapFromSource(topLeft), self.mapFromSource(bottomRight))
142 144
143 def headerData(self, section, orientation, role = Qt.DisplayRole): 145 def headerData(self, section, orientation, role=Qt.DisplayRole):
144 """ 146 """
145 Public method to get the header data. 147 Public method to get the header data.
146 148
147 @param section section number (integer) 149 @param section section number (integer)
148 @param orientation header orientation (Qt.Orientation) 150 @param orientation header orientation (Qt.Orientation)
162 Private slot to handle a reset of the source model. 164 Private slot to handle a reset of the source model.
163 """ 165 """
164 self.__loaded = False 166 self.__loaded = False
165 self.reset() 167 self.reset()
166 168
167 def rowCount(self, parent = QModelIndex()): 169 def rowCount(self, parent=QModelIndex()):
168 """ 170 """
169 Public method to determine the number of rows. 171 Public method to determine the number of rows.
170 172
171 @param parent index of parent (QModelIndex) 173 @param parent index of parent (QModelIndex)
172 @return number of rows (integer) 174 @return number of rows (integer)
174 self.__load() 176 self.__load()
175 if parent.isValid(): 177 if parent.isValid():
176 return 0 178 return 0
177 return len(self.__historyDict) 179 return len(self.__historyDict)
178 180
179 def columnCount(self, parent = QModelIndex()): 181 def columnCount(self, parent=QModelIndex()):
180 """ 182 """
181 Public method to get the number of columns. 183 Public method to get the number of columns.
182 184
183 @param parent index of parent (QModelIndex) 185 @param parent index of parent (QModelIndex)
184 @return number of columns (integer) 186 @return number of columns (integer)
215 except ValueError: 217 except ValueError:
216 return QModelIndex() 218 return QModelIndex()
217 219
218 return self.createIndex(row, sourceIndex.column(), sourceOffset) 220 return self.createIndex(row, sourceIndex.column(), sourceOffset)
219 221
220 def index(self, row, column, parent = QModelIndex()): 222 def index(self, row, column, parent=QModelIndex()):
221 """ 223 """
222 Public method to create an index. 224 Public method to create an index.
223 225
224 @param row row number for the index (integer) 226 @param row row number for the index (integer)
225 @param column column number for the index (integer) 227 @param column column number for the index (integer)
290 del self.__filteredRows[row] 292 del self.__filteredRows[row]
291 del self.__historyDict[url] 293 del self.__historyDict[url]
292 self.endRemoveRows() 294 self.endRemoveRows()
293 295
294 self.beginInsertRows(QModelIndex(), 0, 0) 296 self.beginInsertRows(QModelIndex(), 0, 0)
295 self.__filteredRows.insert(0, HistoryData(self.sourceModel().rowCount(), 297 self.__filteredRows.insert(0, HistoryData(self.sourceModel().rowCount(),
296 self.__frequencyScore(idx) + currentFrequency)) 298 self.__frequencyScore(idx) + currentFrequency))
297 self.__historyDict[url] = self.sourceModel().rowCount() 299 self.__historyDict[url] = self.sourceModel().rowCount()
298 self.endInsertRows() 300 self.endInsertRows()
299 301
300 def __sourceRowsRemoved(self, parent, start, end): 302 def __sourceRowsRemoved(self, parent, start, end):
305 @param start start row (integer) 307 @param start start row (integer)
306 @param end end row (integer) 308 @param end end row (integer)
307 """ 309 """
308 self.__sourceReset() 310 self.__sourceReset()
309 311
310 def removeRows(self, row, count, parent = QModelIndex()): 312 def removeRows(self, row, count, parent=QModelIndex()):
311 """ 313 """
312 Public method to remove entries from the model. 314 Public method to remove entries from the model.
313 315
314 @param row row of the first entry to remove (integer) 316 @param row row of the first entry to remove (integer)
315 @param count number of entries to remove (integer) 317 @param count number of entries to remove (integer)

eric ide

mercurial