Helpviewer/AdBlock/AdBlockModel.py

changeset 7
c679fb30c8f3
parent 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
6:52e8c820d0dd 7:c679fb30c8f3
78 Public method to get the header data. 78 Public method to get the header data.
79 79
80 @param section section number (integer) 80 @param section section number (integer)
81 @param orientation header orientation (Qt.Orientation) 81 @param orientation header orientation (Qt.Orientation)
82 @param role data role (integer) 82 @param role data role (integer)
83 @return header data (QVariant) 83 @return header data
84 """ 84 """
85 if orientation == Qt.Horizontal and role == Qt.DisplayRole: 85 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
86 if section == 0: 86 if section == 0:
87 return QVariant(self.trUtf8("Rule")) 87 return self.trUtf8("Rule")
88 return QAbstractItemModel.headerData(self, section, orientation, role) 88 return QAbstractItemModel.headerData(self, section, orientation, role)
89 89
90 def data(self, index, role = Qt.DisplayRole): 90 def data(self, index, role = Qt.DisplayRole):
91 """ 91 """
92 Public method to get data from the model. 92 Public method to get data from the model.
93 93
94 @param index index of bookmark to get data for (QModelIndex) 94 @param index index of bookmark to get data for (QModelIndex)
95 @param role data role (integer) 95 @param role data role (integer)
96 @return bookmark data (QVariant) 96 @return bookmark data
97 """ 97 """
98 if not index.isValid() or index.model() != self or index.column() != 0: 98 if not index.isValid() or index.model() != self or index.column() != 0:
99 return QVariant() 99 return None
100 100
101 if role in [Qt.EditRole, Qt.DisplayRole]: 101 if role in [Qt.EditRole, Qt.DisplayRole]:
102 if index.parent().isValid(): 102 if index.parent().isValid():
103 r = self.rule(index) 103 r = self.rule(index)
104 return QVariant(r.filter()) 104 return r.filter()
105 else: 105 else:
106 sub = self.subscription(index) 106 sub = self.subscription(index)
107 if sub is not None: 107 if sub is not None:
108 return QVariant(sub.title()) 108 return sub.title()
109 109
110 elif role == Qt.CheckStateRole: 110 elif role == Qt.CheckStateRole:
111 if index.parent().isValid(): 111 if index.parent().isValid():
112 r = self.rule(index) 112 r = self.rule(index)
113 if r.isEnabled(): 113 if r.isEnabled():
114 return QVariant(Qt.Checked) 114 return Qt.Checked
115 else: 115 else:
116 return QVariant(Qt.Unchecked) 116 return Qt.Unchecked
117 else: 117 else:
118 sub = self.subscription(index) 118 sub = self.subscription(index)
119 if sub is not None: 119 if sub is not None:
120 if sub.isEnabled(): 120 if sub.isEnabled():
121 return QVariant(Qt.Checked) 121 return Qt.Checked
122 else: 122 else:
123 return QVariant(Qt.Unchecked) 123 return Qt.Unchecked
124 124
125 return QVariant() 125 return None
126 126
127 def columnCount(self, parent = QModelIndex()): 127 def columnCount(self, parent = QModelIndex()):
128 """ 128 """
129 Public method to get the number of columns. 129 Public method to get the number of columns.
130 130
257 def setData(self, index, value, role = Qt.EditRole): 257 def setData(self, index, value, role = Qt.EditRole):
258 """ 258 """
259 Public method to set the data of a node cell. 259 Public method to set the data of a node cell.
260 260
261 @param index index of the node cell (QModelIndex) 261 @param index index of the node cell (QModelIndex)
262 @param value value to be set (QVariant) 262 @param value value to be set
263 @param role role of the data (integer) 263 @param role role of the data (integer)
264 @return flag indicating success (boolean) 264 @return flag indicating success (boolean)
265 """ 265 """
266 if not index.isValid() or \ 266 if not index.isValid() or \
267 index.model() != self or \ 267 index.model() != self or \
275 if role in [Qt.EditRole, Qt.DisplayRole]: 275 if role in [Qt.EditRole, Qt.DisplayRole]:
276 if index.parent().isValid(): 276 if index.parent().isValid():
277 sub = self.subscription(index.parent()) 277 sub = self.subscription(index.parent())
278 if sub is not None: 278 if sub is not None:
279 r = self.rule(index) 279 r = self.rule(index)
280 r.setFilter(value.toString()) 280 r.setFilter(value)
281 sub.replaceRule(r, index.row()) 281 sub.replaceRule(r, index.row())
282 self.emit(SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"), 282 self.emit(SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"),
283 index, index) 283 index, index)
284 changed = True 284 changed = True
285 else: 285 else:
286 sub = self.subscription(index) 286 sub = self.subscription(index)
287 if sub is not None: 287 if sub is not None:
288 sub.setTitle(value.toString()) 288 sub.setTitle(value)
289 self.emit(SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"), 289 self.emit(SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"),
290 index, index) 290 index, index)
291 changed = True 291 changed = True
292 292
293 elif role == Qt.CheckStateRole: 293 elif role == Qt.CheckStateRole:

eric ide

mercurial