Project/ProjectBrowserSortFilterProxyModel.py

changeset 0
de9c2efb9d02
child 7
c679fb30c8f3
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2006 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the browser sort filter proxy model.
8 """
9
10 from PyQt4.QtCore import *
11 from PyQt4.QtGui import *
12
13 from UI.BrowserSortFilterProxyModel import BrowserSortFilterProxyModel
14 from ProjectBrowserModel import ProjectBrowserSourceType
15
16 import Preferences
17
18 class ProjectBrowserSortFilterProxyModel(BrowserSortFilterProxyModel):
19 """
20 Class implementing the browser sort filter proxy model.
21 """
22 def __init__(self, filterType, parent = None):
23 """
24 Constructor
25
26 @param filterType type of filter to apply
27 @param parent reference to the parent object (QObject)
28 """
29 BrowserSortFilterProxyModel.__init__(self, parent)
30 self.__filterType = filterType
31 self.setDynamicSortFilter(True)
32 self.hideGeneratedForms = Preferences.getProject("HideGeneratedForms")
33
34 def filterAcceptsRow(self, source_row, source_parent):
35 """
36 Protected method to filter rows.
37
38 It implements a filter to suppress the display of non public
39 classes, methods and attributes.
40
41 @param source_row row number (in the source model) of item (integer)
42 @param source_parent index of parent item (in the source model)
43 of item (QModelIndex)
44 @return flag indicating, if the item should be shown (boolean)
45 """
46 sindex = self.sourceModel().index(source_row, 0, source_parent)
47 if not sindex.isValid():
48 return False
49 sitem = self.sourceModel().item(sindex)
50 try:
51 if not self.__filterType in sitem.getProjectTypes():
52 return False
53 if self.hideGeneratedForms and \
54 self.__filterType == ProjectBrowserSourceType and \
55 sitem.data(0).toString().startswith("Ui_"):
56 return False
57 except AttributeError:
58 pass
59
60 if self.hideNonPublic:
61 return sitem.isPublic()
62 else:
63 return True
64
65 def preferencesChanged(self):
66 """
67 Public slot called to handle a change of the preferences settings.
68 """
69 BrowserSortFilterProxyModel.preferencesChanged(self)
70
71 hideGeneratedForms = Preferences.getProject("HideGeneratedForms")
72 if self.hideGeneratedForms != hideGeneratedForms:
73 self.hideGeneratedForms = hideGeneratedForms
74 self.filterChanged()

eric ide

mercurial