9 |
9 |
10 from PyQt4.QtCore import * |
10 from PyQt4.QtCore import * |
11 from PyQt4.QtGui import * |
11 from PyQt4.QtGui import * |
12 |
12 |
13 import Helpviewer.HelpWindow |
13 import Helpviewer.HelpWindow |
|
14 |
14 |
15 |
15 class AdBlockModel(QAbstractItemModel): |
16 class AdBlockModel(QAbstractItemModel): |
16 """ |
17 """ |
17 Class implementing a model for the AdBlock dialog. |
18 Class implementing a model for the AdBlock dialog. |
18 """ |
19 """ |
19 def __init__(self, parent = None): |
20 def __init__(self, parent=None): |
20 """ |
21 """ |
21 Constructor |
22 Constructor |
22 |
23 |
23 @param parent reference to the parent object (QObject) |
24 @param parent reference to the parent object (QObject) |
24 """ |
25 """ |
71 return QModelIndex() |
72 return QModelIndex() |
72 return self.createIndex(row, 0, 0) |
73 return self.createIndex(row, 0, 0) |
73 except ValueError: |
74 except ValueError: |
74 return QModelIndex() |
75 return QModelIndex() |
75 |
76 |
76 def headerData(self, section, orientation, role = Qt.DisplayRole): |
77 def headerData(self, section, orientation, role=Qt.DisplayRole): |
77 """ |
78 """ |
78 Public method to get the header data. |
79 Public method to get the header data. |
79 |
80 |
80 @param section section number (integer) |
81 @param section section number (integer) |
81 @param orientation header orientation (Qt.Orientation) |
82 @param orientation header orientation (Qt.Orientation) |
85 if orientation == Qt.Horizontal and role == Qt.DisplayRole: |
86 if orientation == Qt.Horizontal and role == Qt.DisplayRole: |
86 if section == 0: |
87 if section == 0: |
87 return self.trUtf8("Rule") |
88 return self.trUtf8("Rule") |
88 return QAbstractItemModel.headerData(self, section, orientation, role) |
89 return QAbstractItemModel.headerData(self, section, orientation, role) |
89 |
90 |
90 def data(self, index, role = Qt.DisplayRole): |
91 def data(self, index, role=Qt.DisplayRole): |
91 """ |
92 """ |
92 Public method to get data from the model. |
93 Public method to get data from the model. |
93 |
94 |
94 @param index index of bookmark to get data for (QModelIndex) |
95 @param index index of bookmark to get data for (QModelIndex) |
95 @param role data role (integer) |
96 @param role data role (integer) |
134 if parent.column() > 0: |
135 if parent.column() > 0: |
135 return 0 |
136 return 0 |
136 else: |
137 else: |
137 return 1 |
138 return 1 |
138 |
139 |
139 def rowCount(self, parent = QModelIndex()): |
140 def rowCount(self, parent=QModelIndex()): |
140 """ |
141 """ |
141 Public method to determine the number of rows. |
142 Public method to determine the number of rows. |
142 |
143 |
143 @param parent index of parent (QModelIndex) |
144 @param parent index of parent (QModelIndex) |
144 @return number of rows (integer) |
145 @return number of rows (integer) |
156 if parentNode is not None: |
157 if parentNode is not None: |
157 return len(parentNode.allRules()) |
158 return len(parentNode.allRules()) |
158 |
159 |
159 return 0 |
160 return 0 |
160 |
161 |
161 def index(self, row, column, parent = QModelIndex()): |
162 def index(self, row, column, parent=QModelIndex()): |
162 """ |
163 """ |
163 Public method to get a model index for a node cell. |
164 Public method to get a model index for a node cell. |
164 |
165 |
165 @param row row number (integer) |
166 @param row row number (integer) |
166 @param column column number (integer) |
167 @param column column number (integer) |
175 return self.createIndex(row, column, None) |
176 return self.createIndex(row, column, None) |
176 |
177 |
177 parentNode = self.subscription(parent) |
178 parentNode = self.subscription(parent) |
178 return self.createIndex(row, column, parentNode) |
179 return self.createIndex(row, column, parentNode) |
179 |
180 |
180 def parent(self, index = QModelIndex()): |
181 def parent(self, index=QModelIndex()): |
181 """ |
182 """ |
182 Public method to get the index of the parent node. |
183 Public method to get the index of the parent node. |
183 |
184 |
184 @param index index of the child node (QModelIndex) |
185 @param index index of the child node (QModelIndex) |
185 @return index of the parent node (QModelIndex) |
186 @return index of the parent node (QModelIndex) |
215 else: |
216 else: |
216 flags |= Qt.ItemIsUserCheckable | Qt.ItemIsEditable | Qt.ItemIsEnabled |
217 flags |= Qt.ItemIsUserCheckable | Qt.ItemIsEditable | Qt.ItemIsEnabled |
217 |
218 |
218 return flags |
219 return flags |
219 |
220 |
220 def removeRows(self, row, count, parent = QModelIndex()): |
221 def removeRows(self, row, count, parent=QModelIndex()): |
221 """ |
222 """ |
222 Public method to remove bookmarks from the model. |
223 Public method to remove bookmarks from the model. |
223 |
224 |
224 @param row row of the first bookmark to remove (integer) |
225 @param row row of the first bookmark to remove (integer) |
225 @param count number of bookmarks to remove (integer) |
226 @param count number of bookmarks to remove (integer) |
248 self.__manager.rulesChanged.connect(self.__rulesChanged) |
249 self.__manager.rulesChanged.connect(self.__rulesChanged) |
249 return True |
250 return True |
250 |
251 |
251 return False |
252 return False |
252 |
253 |
253 def setData(self, index, value, role = Qt.EditRole): |
254 def setData(self, index, value, role=Qt.EditRole): |
254 """ |
255 """ |
255 Public method to set the data of a node cell. |
256 Public method to set the data of a node cell. |
256 |
257 |
257 @param index index of the node cell (QModelIndex) |
258 @param index index of the node cell (QModelIndex) |
258 @param value value to be set |
259 @param value value to be set |
301 changed = True |
302 changed = True |
302 |
303 |
303 self.__manager.rulesChanged.connect(self.__rulesChanged) |
304 self.__manager.rulesChanged.connect(self.__rulesChanged) |
304 return changed |
305 return changed |
305 |
306 |
306 def hasChildren(self, parent = QModelIndex()): |
307 def hasChildren(self, parent=QModelIndex()): |
307 """ |
308 """ |
308 Public method to check, if a parent node has some children. |
309 Public method to check, if a parent node has some children. |
309 |
310 |
310 @param parent index of the parent node (QModelIndex) |
311 @param parent index of the parent node (QModelIndex) |
311 @return flag indicating the presence of children (boolean) |
312 @return flag indicating the presence of children (boolean) |