Helpviewer/History/HistoryFilterModel.py

changeset 488
4174c2707dba
parent 13
1af94a91f439
child 791
9ec2ac20e54e
equal deleted inserted replaced
487:4d41d03d3d00 488:4174c2707dba
114 Public method to set the source model. 114 Public method to set the source model.
115 115
116 @param sourceModel reference to the source model (QAbstractItemModel) 116 @param sourceModel reference to the source model (QAbstractItemModel)
117 """ 117 """
118 if self.sourceModel() is not None: 118 if self.sourceModel() is not None:
119 self.disconnect(self.sourceModel(), 119 self.sourceModel().modelReset.disconnect(self.__sourceReset)
120 SIGNAL("modelReset()"), 120 self.sourceModel().dataChanged.disconnect(self.__sourceDataChanged)
121 self.__sourceReset) 121 self.sourceModel().rowsInserted.disconnect(self.__sourceRowsInserted)
122 self.disconnect(self.sourceModel(), 122 self.sourceModel().rowsRemoved.disconnect(self.__sourceRowsRemoved)
123 SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"),
124 self.__sourceDataChanged)
125 self.disconnect(self.sourceModel(),
126 SIGNAL("rowsInserted(const QModelIndex &, int, int)"),
127 self.__sourceRowsInserted)
128 self.disconnect(self.sourceModel(),
129 SIGNAL("rowsRemoved(const QModelIndex &, int, int)"),
130 self.__sourceRowsRemoved)
131 123
132 QAbstractProxyModel.setSourceModel(self, sourceModel) 124 QAbstractProxyModel.setSourceModel(self, sourceModel)
133 125
134 if self.sourceModel() is not None: 126 if self.sourceModel() is not None:
135 self.__loaded = False 127 self.__loaded = False
136 self.connect(self.sourceModel(), 128 self.sourceModel().modelReset.connect(self.__sourceReset)
137 SIGNAL("modelReset()"), 129 self.sourceModel().dataChanged.connect(self.__sourceDataChanged)
138 self.__sourceReset) 130 self.sourceModel().rowsInserted.connect(self.__sourceRowsInserted)
139 self.connect(self.sourceModel(), 131 self.sourceModel().rowsRemoved.connect(self.__sourceRowsRemoved)
140 SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"),
141 self.__sourceDataChanged)
142 self.connect(self.sourceModel(),
143 SIGNAL("rowsInserted(const QModelIndex &, int, int)"),
144 self.__sourceRowsInserted)
145 self.connect(self.sourceModel(),
146 SIGNAL("rowsRemoved(const QModelIndex &, int, int)"),
147 self.__sourceRowsRemoved)
148 132
149 def __sourceDataChanged(self, topLeft, bottomRight): 133 def __sourceDataChanged(self, topLeft, bottomRight):
150 """ 134 """
151 Private slot to handle the change of data of the source model. 135 Private slot to handle the change of data of the source model.
152 136
153 @param topLeft index of top left data element (QModelIndex) 137 @param topLeft index of top left data element (QModelIndex)
154 @param bottomRight index of bottom right data element (QModelIndex) 138 @param bottomRight index of bottom right data element (QModelIndex)
155 """ 139 """
156 self.emit(SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"), 140 self.dataChanged.emit(
157 self.mapFromSource(topLeft), self.mapFromSource(bottomRight)) 141 self.mapFromSource(topLeft), self.mapFromSource(bottomRight))
158 142
159 def headerData(self, section, orientation, role = Qt.DisplayRole): 143 def headerData(self, section, orientation, role = Qt.DisplayRole):
160 """ 144 """
161 Public method to get the header data. 145 Public method to get the header data.
162 146
337 row + count > self.rowCount(parent) or \ 321 row + count > self.rowCount(parent) or \
338 parent.isValid(): 322 parent.isValid():
339 return False 323 return False
340 324
341 lastRow = row + count - 1 325 lastRow = row + count - 1
342 self.disconnect(self.sourceModel(), 326 self.sourceModel().rowsRemoved.disconnect(self.__sourceRowsRemoved)
343 SIGNAL("rowsRemoved(const QModelIndex &, int, int)"),
344 self.__sourceRowsRemoved)
345 self.beginRemoveRows(parent, row, lastRow) 327 self.beginRemoveRows(parent, row, lastRow)
346 oldCount = self.rowCount() 328 oldCount = self.rowCount()
347 start = self.sourceModel().rowCount() - self.__filteredRows[row].tailOffset 329 start = self.sourceModel().rowCount() - self.__filteredRows[row].tailOffset
348 end = self.sourceModel().rowCount() - self.__filteredRows[lastRow].tailOffset 330 end = self.sourceModel().rowCount() - self.__filteredRows[lastRow].tailOffset
349 self.sourceModel().removeRows(start, end - start + 1) 331 self.sourceModel().removeRows(start, end - start + 1)
350 self.endRemoveRows() 332 self.endRemoveRows()
351 self.connect(self.sourceModel(), 333 self.sourceModel().rowsRemoved.connect(self.__sourceRowsRemoved)
352 SIGNAL("rowsRemoved(const QModelIndex &, int, int)"),
353 self.__sourceRowsRemoved)
354 self.__loaded = False 334 self.__loaded = False
355 if oldCount - count != self.rowCount(): 335 if oldCount - count != self.rowCount():
356 self.reset() 336 self.reset()
357 return True 337 return True
358 338

eric ide

mercurial