UI/BrowserModel.py

changeset 7
c679fb30c8f3
parent 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
6:52e8c820d0dd 7:c679fb30c8f3
40 40
41 @param parent reference to parent object (QObject) 41 @param parent reference to parent object (QObject)
42 """ 42 """
43 QAbstractItemModel.__init__(self, parent) 43 QAbstractItemModel.__init__(self, parent)
44 44
45 rootData = QVariant(QApplication.translate("BrowserModel", "Name")) 45 rootData = QApplication.translate("BrowserModel", "Name")
46 self.rootItem = BrowserItem(None, rootData) 46 self.rootItem = BrowserItem(None, rootData)
47 47
48 self.progDir = None 48 self.progDir = None
49 49
50 self.__populateModel() 50 self.__populateModel()
67 """ 67 """
68 Public method to get data of an item. 68 Public method to get data of an item.
69 69
70 @param index index of the data to retrieve (QModelIndex) 70 @param index index of the data to retrieve (QModelIndex)
71 @param role role of data (Qt.ItemDataRole) 71 @param role role of data (Qt.ItemDataRole)
72 @return requested data (QVariant) 72 @return requested data
73 """ 73 """
74 if not index.isValid(): 74 if not index.isValid():
75 return QVariant() 75 return None
76 76
77 if role == Qt.DisplayRole: 77 if role == Qt.DisplayRole:
78 item = index.internalPointer() 78 item = index.internalPointer()
79 if index.column() < item.columnCount(): 79 if index.column() < item.columnCount():
80 return QVariant(item.data(index.column())) 80 return item.data(index.column())
81 elif index.column() == item.columnCount() and \ 81 elif index.column() == item.columnCount() and \
82 index.column() < self.columnCount(self.parent(index)): 82 index.column() < self.columnCount(self.parent(index)):
83 # This is for the case where an item under a multi-column parent 83 # This is for the case where an item under a multi-column parent
84 # doesn't have a value for all the columns 84 # doesn't have a value for all the columns
85 return QVariant("") 85 return ""
86 elif role == Qt.DecorationRole: 86 elif role == Qt.DecorationRole:
87 if index.column() == 0: 87 if index.column() == 0:
88 return QVariant(index.internalPointer().getIcon()) 88 return index.internalPointer().getIcon()
89 89
90 return QVariant() 90 return None
91 91
92 def flags(self, index): 92 def flags(self, index):
93 """ 93 """
94 Public method to get the item flags. 94 Public method to get the item flags.
95 95
106 Public method to get the header data. 106 Public method to get the header data.
107 107
108 @param section number of section to get data for (integer) 108 @param section number of section to get data for (integer)
109 @param orientation header orientation (Qt.Orientation) 109 @param orientation header orientation (Qt.Orientation)
110 @param role role of data (Qt.ItemDataRole) 110 @param role role of data (Qt.ItemDataRole)
111 @return requested header data (QVariant) 111 @return requested header data
112 """ 112 """
113 if orientation == Qt.Horizontal and role == Qt.DisplayRole: 113 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
114 if section >= self.rootItem.columnCount(): 114 if section >= self.rootItem.columnCount():
115 return QVariant("") 115 return ""
116 else: 116 else:
117 return self.rootItem.data(section) 117 return self.rootItem.data(section)
118 118
119 return QVariant() 119 return None
120 120
121 def index(self, row, column, parent = QModelIndex()): 121 def index(self, row, column, parent = QModelIndex()):
122 """ 122 """
123 Public method to create an index. 123 Public method to create an index.
124 124
234 Private method to populate the browser model. 234 Private method to populate the browser model.
235 """ 235 """
236 self._addItem(BrowserSysPathItem(self.rootItem), self.rootItem) 236 self._addItem(BrowserSysPathItem(self.rootItem), self.rootItem)
237 237
238 self.toplevelDirs = [] 238 self.toplevelDirs = []
239 tdp = Preferences.Prefs.settings.value('BrowserModel/ToplevelDirs').toStringList() 239 tdp = Preferences.Prefs.settings.value('BrowserModel/ToplevelDirs')
240 if tdp: 240 if tdp:
241 self.toplevelDirs = tdp 241 self.toplevelDirs = tdp
242 else: 242 else:
243 self.toplevelDirs.append(Utilities.toNativeSeparators(QDir.homePath())) 243 self.toplevelDirs.append(Utilities.toNativeSeparators(QDir.homePath()))
244 for d in QDir.drives(): 244 for d in QDir.drives():
298 def saveToplevelDirs(self): 298 def saveToplevelDirs(self):
299 """ 299 """
300 Public slot to save the toplevel directories. 300 Public slot to save the toplevel directories.
301 """ 301 """
302 Preferences.Prefs.settings.setValue('BrowserModel/ToplevelDirs', 302 Preferences.Prefs.settings.setValue('BrowserModel/ToplevelDirs',
303 QVariant(self.toplevelDirs)) 303 self.toplevelDirs)
304 304
305 def _addItem(self, itm, parentItem): 305 def _addItem(self, itm, parentItem):
306 """ 306 """
307 Protected slot to add an item. 307 Protected slot to add an item.
308 308

eric ide

mercurial