Helpviewer/History/HistoryTreeModel.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1112
8a7d1b9d18db
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
13 from PyQt4.QtGui import QAbstractProxyModel 13 from PyQt4.QtGui import QAbstractProxyModel
14 14
15 from .HistoryModel import HistoryModel 15 from .HistoryModel import HistoryModel
16 16
17 import UI.PixmapCache 17 import UI.PixmapCache
18
18 19
19 class HistoryTreeModel(QAbstractProxyModel): 20 class HistoryTreeModel(QAbstractProxyModel):
20 """ 21 """
21 Class implementing the history tree model. 22 Class implementing the history tree model.
22 """ 23 """
23 def __init__(self, sourceModel, parent = None): 24 def __init__(self, sourceModel, parent=None):
24 """ 25 """
25 Constructor 26 Constructor
26 27
27 @param sourceModel reference to the source model (QAbstractItemModel) 28 @param sourceModel reference to the source model (QAbstractItemModel)
28 @param parent reference to the parent object (QObject) 29 @param parent reference to the parent object (QObject)
32 self.__sourceRowCache = [] 33 self.__sourceRowCache = []
33 self.__removingDown = False 34 self.__removingDown = False
34 35
35 self.setSourceModel(sourceModel) 36 self.setSourceModel(sourceModel)
36 37
37 def headerData(self, section, orientation, role = Qt.DisplayRole): 38 def headerData(self, section, orientation, role=Qt.DisplayRole):
38 """ 39 """
39 Public method to get the header data. 40 Public method to get the header data.
40 41
41 @param section section number (integer) 42 @param section section number (integer)
42 @param orientation header orientation (Qt.Orientation) 43 @param orientation header orientation (Qt.Orientation)
43 @param role data role (integer) 44 @param role data role (integer)
44 @return header data 45 @return header data
45 """ 46 """
46 return self.sourceModel().headerData(section, orientation, role) 47 return self.sourceModel().headerData(section, orientation, role)
47 48
48 def data(self, index, role = Qt.DisplayRole): 49 def data(self, index, role=Qt.DisplayRole):
49 """ 50 """
50 Public method to get data from the model. 51 Public method to get data from the model.
51 52
52 @param index index of history entry to get data for (QModelIndex) 53 @param index index of history entry to get data for (QModelIndex)
53 @param role data role (integer) 54 @param role data role (integer)
77 idx = self.sourceModel().index(offset, 0) 78 idx = self.sourceModel().index(offset, 0)
78 return idx.data(HistoryModel.DateRole) 79 return idx.data(HistoryModel.DateRole)
79 80
80 return QAbstractProxyModel.data(self, index, role) 81 return QAbstractProxyModel.data(self, index, role)
81 82
82 def columnCount(self, parent = QModelIndex()): 83 def columnCount(self, parent=QModelIndex()):
83 """ 84 """
84 Public method to get the number of columns. 85 Public method to get the number of columns.
85 86
86 @param parent index of parent (QModelIndex) 87 @param parent index of parent (QModelIndex)
87 @return number of columns (integer) 88 @return number of columns (integer)
88 """ 89 """
89 return self.sourceModel().columnCount(self.mapToSource(parent)) 90 return self.sourceModel().columnCount(self.mapToSource(parent))
90 91
91 def rowCount(self, parent = QModelIndex()): 92 def rowCount(self, parent=QModelIndex()):
92 """ 93 """
93 Public method to determine the number of rows. 94 Public method to determine the number of rows.
94 95
95 @param parent index of parent (QModelIndex) 96 @param parent index of parent (QModelIndex)
96 @return number of rows (integer) 97 @return number of rows (integer)
123 end = self.__sourceDateRow(parent.row() + 1) 124 end = self.__sourceDateRow(parent.row() + 1)
124 return end - start 125 return end - start
125 126
126 def __sourceDateRow(self, row): 127 def __sourceDateRow(self, row):
127 """ 128 """
128 Private method to translate the top level date row into the offset 129 Private method to translate the top level date row into the offset
129 where that date starts. 130 where that date starts.
130 131
131 @param row row number of the date (integer) 132 @param row row number of the date (integer)
132 @return offset where that date starts (integer) 133 @return offset where that date starts (integer)
133 """ 134 """
156 return QModelIndex() 157 return QModelIndex()
157 startDateRow = self.__sourceDateRow(offset - 1) 158 startDateRow = self.__sourceDateRow(offset - 1)
158 return self.sourceModel().index( 159 return self.sourceModel().index(
159 startDateRow + proxyIndex.row(), proxyIndex.column()) 160 startDateRow + proxyIndex.row(), proxyIndex.column())
160 161
161 def index(self, row, column, parent = QModelIndex()): 162 def index(self, row, column, parent=QModelIndex()):
162 """ 163 """
163 Public method to create an index. 164 Public method to create an index.
164 165
165 @param row row number for the index (integer) 166 @param row row number for the index (integer)
166 @param column column number for the index (integer) 167 @param column column number for the index (integer)
187 offset = index.internalId() 188 offset = index.internalId()
188 if offset == 0 or not index.isValid(): 189 if offset == 0 or not index.isValid():
189 return QModelIndex() 190 return QModelIndex()
190 return self.createIndex(offset - 1, 0, 0) 191 return self.createIndex(offset - 1, 0, 0)
191 192
192 def hasChildren(self, parent = QModelIndex()): 193 def hasChildren(self, parent=QModelIndex()):
193 """ 194 """
194 Public method to check, if an entry has some children. 195 Public method to check, if an entry has some children.
195 196
196 @param parent index of the entry to check (QModelIndex) 197 @param parent index of the entry to check (QModelIndex)
197 @return flag indicating the presence of children (boolean) 198 @return flag indicating the presence of children (boolean)
288 row -= 1 289 row -= 1
289 dateRow = max(0, row) 290 dateRow = max(0, row)
290 row = sourceIndex.row() - self.__sourceRowCache[dateRow] 291 row = sourceIndex.row() - self.__sourceRowCache[dateRow]
291 return self.createIndex(row, sourceIndex.column(), dateRow + 1) 292 return self.createIndex(row, sourceIndex.column(), dateRow + 1)
292 293
293 def removeRows(self, row, count, parent = QModelIndex()): 294 def removeRows(self, row, count, parent=QModelIndex()):
294 """ 295 """
295 Public method to remove entries from the model. 296 Public method to remove entries from the model.
296 297
297 @param row row of the first entry to remove (integer) 298 @param row row of the first entry to remove (integer)
298 @param count number of entries to remove (integer) 299 @param count number of entries to remove (integer)

eric ide

mercurial