eric6/Debugger/BreakPointModel.py

branch
maintenance
changeset 8043
0acf98cd089a
parent 7924
8a96736d465e
parent 7923
91e843545d9a
child 8142
43248bafe9b2
equal deleted inserted replaced
7991:866adc8c315b 8043:0acf98cd089a
21 21
22 def __init__(self, parent=None): 22 def __init__(self, parent=None):
23 """ 23 """
24 Constructor 24 Constructor
25 25
26 @param parent reference to the parent widget (QObject) 26 @param parent reference to the parent widget
27 @type QObject
27 """ 28 """
28 super(BreakPointModel, self).__init__(parent) 29 super(BreakPointModel, self).__init__(parent)
29 30
30 self.breakpoints = [] 31 self.breakpoints = []
31 self.header = [ 32 self.header = [
47 48
48 def columnCount(self, parent=None): 49 def columnCount(self, parent=None):
49 """ 50 """
50 Public method to get the current column count. 51 Public method to get the current column count.
51 52
52 @param parent reference to parent index (QModelIndex) (Unused) 53 @param parent reference to parent index (Unused)
53 @return column count (integer) 54 @type QModelIndex
55 @return column count
56 @rtype int
54 """ 57 """
55 return len(self.header) 58 return len(self.header)
56 59
57 def rowCount(self, parent=None): 60 def rowCount(self, parent=None):
58 """ 61 """
59 Public method to get the current row count. 62 Public method to get the current row count.
60 63
61 @param parent reference to parent index (QModelIndex) 64 @param parent reference to parent index
62 @return row count (integer) 65 @type QModelIndex
66 @return row count
67 @rtype int
63 """ 68 """
64 # we do not have a tree, parent should always be invalid 69 # we do not have a tree, parent should always be invalid
65 if parent is None or not parent.isValid(): 70 if parent is None or not parent.isValid():
66 return len(self.breakpoints) 71 return len(self.breakpoints)
67 else: 72 else:
69 74
70 def data(self, index, role=Qt.DisplayRole): 75 def data(self, index, role=Qt.DisplayRole):
71 """ 76 """
72 Public method to get the requested data. 77 Public method to get the requested data.
73 78
74 @param index index of the requested data (QModelIndex) 79 @param index index of the requested data
75 @param role role of the requested data (Qt.ItemDataRole) 80 @type QModelIndex
81 @param role role of the requested data
82 @type Qt.ItemDataRole
76 @return the requested data 83 @return the requested data
84 @rtype any
77 """ 85 """
78 if not index.isValid(): 86 if not index.isValid():
79 return None 87 return None
80 88
81 if role == Qt.DisplayRole: 89 if role == Qt.DisplayRole:
98 106
99 def setData(self, index, value, role=Qt.EditRole): 107 def setData(self, index, value, role=Qt.EditRole):
100 """ 108 """
101 Public method to change data in the model. 109 Public method to change data in the model.
102 110
103 @param index index of the changed data (QModelIndex) 111 @param index index of the changed data
112 @type QModelIndex
104 @param value value of the changed data 113 @param value value of the changed data
105 @param role role of the changed data (Qt.ItemDataRole) 114 @type any
106 @return flag indicating success (boolean) 115 @param role role of the changed data
116 @type Qt.ItemDataRole
117 @return flag indicating success
118 @rtype bool
107 """ 119 """
108 if (not index.isValid() or 120 if (not index.isValid() or
109 index.column() >= len(self.header) or 121 index.column() >= len(self.header) or
110 index.row() >= len(self.breakpoints)): 122 index.row() >= len(self.breakpoints)):
111 return False 123 return False
117 129
118 def flags(self, index): 130 def flags(self, index):
119 """ 131 """
120 Public method to get item flags. 132 Public method to get item flags.
121 133
122 @param index index of the requested flags (QModelIndex) 134 @param index index of the requested flags
123 @return item flags for the given index (Qt.ItemFlags) 135 @type QModelIndex
136 @return item flags for the given index
137 @rtype Qt.ItemFlags
124 """ 138 """
125 if not index.isValid(): 139 if not index.isValid():
126 return Qt.ItemIsEnabled 140 return Qt.ItemIsEnabled
127 141
128 return Qt.ItemIsEnabled | Qt.ItemIsSelectable 142 return Qt.ItemIsEnabled | Qt.ItemIsSelectable
129 143
130 def headerData(self, section, orientation, role=Qt.DisplayRole): 144 def headerData(self, section, orientation, role=Qt.DisplayRole):
131 """ 145 """
132 Public method to get header data. 146 Public method to get header data.
133 147
134 @param section section number of the requested header data (integer) 148 @param section section number of the requested header data
135 @param orientation orientation of the header (Qt.Orientation) 149 @type int
136 @param role role of the requested data (Qt.ItemDataRole) 150 @param orientation orientation of the header
151 @type Qt.Orientation
152 @param role role of the requested data
153 @type Qt.ItemDataRole
137 @return header data 154 @return header data
155 @rtype str
138 """ 156 """
139 if orientation == Qt.Horizontal and role == Qt.DisplayRole: 157 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
140 if section >= len(self.header): 158 if section >= len(self.header):
141 return "" 159 return ""
142 else: 160 else:
146 164
147 def index(self, row, column, parent=None): 165 def index(self, row, column, parent=None):
148 """ 166 """
149 Public method to create an index. 167 Public method to create an index.
150 168
151 @param row row number for the index (integer) 169 @param row row number for the index
152 @param column column number for the index (integer) 170 @type int
153 @param parent index of the parent item (QModelIndex) 171 @param column column number for the index
154 @return requested index (QModelIndex) 172 @type int
173 @param parent index of the parent item
174 @type QModelIndex
175 @return requested index
176 @rtype QModelIndex
155 """ 177 """
156 if ((parent and parent.isValid()) or 178 if ((parent and parent.isValid()) or
157 row < 0 or row >= len(self.breakpoints) or 179 row < 0 or row >= len(self.breakpoints) or
158 column < 0 or column >= len(self.header)): 180 column < 0 or column >= len(self.header)):
159 return QModelIndex() 181 return QModelIndex()
162 184
163 def parent(self, index): 185 def parent(self, index):
164 """ 186 """
165 Public method to get the parent index. 187 Public method to get the parent index.
166 188
167 @param index index of item to get parent (QModelIndex) 189 @param index index of item to get parent
168 @return index of parent (QModelIndex) 190 @type QModelIndex
191 @return index of parent
192 @rtype QModelIndex
169 """ 193 """
170 return QModelIndex() 194 return QModelIndex()
171 195
172 def hasChildren(self, parent=None): 196 def hasChildren(self, parent=None):
173 """ 197 """
174 Public method to check for the presence of child items. 198 Public method to check for the presence of child items.
175 199
176 @param parent index of parent item (QModelIndex) 200 @param parent index of parent item
177 @return flag indicating the presence of child items (boolean) 201 @type QModelIndex
202 @return flag indicating the presence of child items
203 @rtype bool
178 """ 204 """
179 if parent is None or not parent.isValid(): 205 if parent is None or not parent.isValid():
180 return len(self.breakpoints) > 0 206 return len(self.breakpoints) > 0
181 else: 207 else:
182 return False 208 return False
185 211
186 def addBreakPoint(self, fn, line, properties): 212 def addBreakPoint(self, fn, line, properties):
187 """ 213 """
188 Public method to add a new breakpoint to the list. 214 Public method to add a new breakpoint to the list.
189 215
190 @param fn filename of the breakpoint (string) 216 @param fn filename of the breakpoint
191 @param line line number of the breakpoint (integer) 217 @type str
218 @param line line number of the breakpoint
219 @type int
192 @param properties properties of the breakpoint 220 @param properties properties of the breakpoint
193 (tuple of condition (string), temporary flag (bool), 221 (tuple of condition, temporary flag, enabled flag, ignore count)
194 enabled flag (bool), ignore count (integer)) 222 @type tuple of (str, bool, bool, int)
195 """ 223 """
196 bp = [fn, line] + list(properties) 224 bp = [fn, line] + list(properties)
197 cnt = len(self.breakpoints) 225 cnt = len(self.breakpoints)
198 self.beginInsertRows(QModelIndex(), cnt, cnt) 226 self.beginInsertRows(QModelIndex(), cnt, cnt)
199 self.breakpoints.append(bp) 227 self.breakpoints.append(bp)
201 229
202 def setBreakPointByIndex(self, index, fn, line, properties): 230 def setBreakPointByIndex(self, index, fn, line, properties):
203 """ 231 """
204 Public method to set the values of a breakpoint given by index. 232 Public method to set the values of a breakpoint given by index.
205 233
206 @param index index of the breakpoint (QModelIndex) 234 @param index index of the breakpoint
207 @param fn filename of the breakpoint (string) 235 @type QModelIndex
208 @param line line number of the breakpoint (integer) 236 @param fn filename of the breakpoint
237 @type str
238 @param line line number of the breakpoint
239 @type int
209 @param properties properties of the breakpoint 240 @param properties properties of the breakpoint
210 (tuple of condition (string), temporary flag (bool), 241 (tuple of condition, temporary flag, enabled flag, ignore count)
211 enabled flag (bool), ignore count (integer)) 242 @type tuple of (str, bool, bool, int)
212 """ 243 """
213 if index.isValid(): 244 if index.isValid():
214 row = index.row() 245 row = index.row()
215 index1 = self.createIndex(row, 0, self.breakpoints[row]) 246 index1 = self.createIndex(row, 0, self.breakpoints[row])
216 index2 = self.createIndex( 247 index2 = self.createIndex(
221 252
222 def setBreakPointEnabledByIndex(self, index, enabled): 253 def setBreakPointEnabledByIndex(self, index, enabled):
223 """ 254 """
224 Public method to set the enabled state of a breakpoint given by index. 255 Public method to set the enabled state of a breakpoint given by index.
225 256
226 @param index index of the breakpoint (QModelIndex) 257 @param index index of the breakpoint
227 @param enabled flag giving the enabled state (boolean) 258 @type QModelIndex
259 @param enabled flag giving the enabled state
260 @type bool
228 """ 261 """
229 if index.isValid(): 262 if index.isValid():
230 row = index.row() 263 row = index.row()
231 col = 4 264 col = 4
232 index1 = self.createIndex(row, col, self.breakpoints[row]) 265 index1 = self.createIndex(row, col, self.breakpoints[row])
236 269
237 def deleteBreakPointByIndex(self, index): 270 def deleteBreakPointByIndex(self, index):
238 """ 271 """
239 Public method to set the values of a breakpoint given by index. 272 Public method to set the values of a breakpoint given by index.
240 273
241 @param index index of the breakpoint (QModelIndex) 274 @param index index of the breakpoint
275 @type QModelIndex
242 """ 276 """
243 if index.isValid(): 277 if index.isValid():
244 row = index.row() 278 row = index.row()
245 self.beginRemoveRows(QModelIndex(), row, row) 279 self.beginRemoveRows(QModelIndex(), row, row)
246 del self.breakpoints[row] 280 del self.breakpoints[row]
248 282
249 def deleteBreakPoints(self, idxList): 283 def deleteBreakPoints(self, idxList):
250 """ 284 """
251 Public method to delete a list of breakpoints given by their indexes. 285 Public method to delete a list of breakpoints given by their indexes.
252 286
253 @param idxList list of breakpoint indexes (list of QModelIndex) 287 @param idxList list of breakpoint indexes
288 @type list of QModelIndex
254 """ 289 """
255 rows = [] 290 rows = []
256 for index in idxList: 291 for index in idxList:
257 if index.isValid(): 292 if index.isValid():
258 rows.append(index.row()) 293 rows.append(index.row())
274 309
275 def getBreakPointByIndex(self, index): 310 def getBreakPointByIndex(self, index):
276 """ 311 """
277 Public method to get the values of a breakpoint given by index. 312 Public method to get the values of a breakpoint given by index.
278 313
279 @param index index of the breakpoint (QModelIndex) 314 @param index index of the breakpoint
280 @return breakpoint (list of seven values (filename, line number, 315 @type QModelIndex
316 @return breakpoint (list of six values (filename, line number,
281 condition, temporary flag, enabled flag, ignore count)) 317 condition, temporary flag, enabled flag, ignore count))
318 @rtype list of (str, int, str, bool, bool, int)
282 """ 319 """
283 if index.isValid(): 320 if index.isValid():
284 return self.breakpoints[index.row()][:] # return a copy 321 return self.breakpoints[index.row()][:] # return a copy
285 else: 322 else:
286 return [] 323 return []
288 def getBreakPointIndex(self, fn, lineno): 325 def getBreakPointIndex(self, fn, lineno):
289 """ 326 """
290 Public method to get the index of a breakpoint given by filename and 327 Public method to get the index of a breakpoint given by filename and
291 line number. 328 line number.
292 329
293 @param fn filename of the breakpoint (string) 330 @param fn filename of the breakpoint
294 @param lineno line number of the breakpoint (integer) 331 @type str
295 @return index (QModelIndex) 332 @param lineno line number of the breakpoint
333 @type int
334 @return index
335 @rtype QModelIndex
296 """ 336 """
297 for row in range(len(self.breakpoints)): 337 for row in range(len(self.breakpoints)):
298 bp = self.breakpoints[row] 338 bp = self.breakpoints[row]
299 if bp[0] == fn and bp[1] == lineno: 339 if bp[0] == fn and bp[1] == lineno:
300 return self.createIndex(row, 0, self.breakpoints[row]) 340 return self.createIndex(row, 0, self.breakpoints[row])
303 343
304 def isBreakPointTemporaryByIndex(self, index): 344 def isBreakPointTemporaryByIndex(self, index):
305 """ 345 """
306 Public method to test, if a breakpoint given by its index is temporary. 346 Public method to test, if a breakpoint given by its index is temporary.
307 347
308 @param index index of the breakpoint to test (QModelIndex) 348 @param index index of the breakpoint to test
309 @return flag indicating a temporary breakpoint (boolean) 349 @type QModelIndex
350 @return flag indicating a temporary breakpoint
351 @rtype bool
310 """ 352 """
311 if index.isValid(): 353 if index.isValid():
312 return self.breakpoints[index.row()][3] 354 return self.breakpoints[index.row()][3]
313 else: 355 else:
314 return False 356 return False

eric ide

mercurial