E5Gui/E5TreeSortFilterProxyModel.py

changeset 55
b5c84934de9c
child 791
9ec2ac20e54e
equal deleted inserted replaced
54:31463df17fd5 55:b5c84934de9c
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 2010 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a modified QSortFilterProxyModel.
8 """
9
10 from PyQt4.QtCore import Qt, QModelIndex
11 from PyQt4.QtGui import QSortFilterProxyModel
12
13 class E5TreeSortFilterProxyModel(QSortFilterProxyModel):
14 """
15 Class implementing a modified QSortFilterProxyModel.
16
17 It always accepts the root nodes in the tree so filtering is only done
18 on the children.
19 """
20 def __init__(self, parent = None):
21 """
22 Constructor
23
24 @param parent reference to the parent object (QObject)
25 """
26 QSortFilterProxyModel.__init__(self, parent)
27
28 self.setFilterCaseSensitivity(Qt.CaseInsensitive)
29
30 def filterAcceptsRow(self, sourceRow, sourceParent):
31 """
32 Protected method to determine, if the row is acceptable.
33
34 @param sourceRow row number in the source model (integer)
35 @param sourceParent index of the source item (QModelIndex)
36 @return flag indicating acceptance (boolean)
37 """
38 idx = self.sourceModel().index(sourceRow, 0, sourceParent)
39 if self.sourceModel().hasChildren(idx):
40 return True
41
42 return QSortFilterProxyModel.filterAcceptsRow(self, sourceRow, sourceParent)
43
44 def hasChildren(self, parent = QModelIndex()):
45 """
46 Public method to check, if a parent node has some children.
47
48 @param parent index of the parent node (QModelIndex)
49 @return flag indicating the presence of children (boolean)
50 """
51 sindex = self.mapToSource(parent)
52 return self.sourceModel().hasChildren(sindex)

eric ide

mercurial