14 |
14 |
15 # TODO: change column numbers to class attributes |
15 # TODO: change column numbers to class attributes |
16 class BreakPointModel(QAbstractItemModel): |
16 class BreakPointModel(QAbstractItemModel): |
17 """ |
17 """ |
18 Class implementing a custom model for breakpoints. |
18 Class implementing a custom model for breakpoints. |
19 |
19 |
20 @signal dataAboutToBeChanged(QModelIndex, QModelIndex) emitted to indicate |
20 @signal dataAboutToBeChanged(QModelIndex, QModelIndex) emitted to indicate |
21 a change of the data |
21 a change of the data |
22 """ |
22 """ |
|
23 |
23 dataAboutToBeChanged = pyqtSignal(QModelIndex, QModelIndex) |
24 dataAboutToBeChanged = pyqtSignal(QModelIndex, QModelIndex) |
24 |
25 |
25 def __init__(self, project, parent=None): |
26 def __init__(self, project, parent=None): |
26 """ |
27 """ |
27 Constructor |
28 Constructor |
28 |
29 |
29 @param project reference to the project object |
30 @param project reference to the project object |
30 @type Project |
31 @type Project |
31 @param parent reference to the parent widget |
32 @param parent reference to the parent widget |
32 @type QObject |
33 @type QObject |
33 """ |
34 """ |
34 super().__init__(parent) |
35 super().__init__(parent) |
35 |
36 |
36 self.__project = project |
37 self.__project = project |
37 |
38 |
38 self.breakpoints = [] |
39 self.breakpoints = [] |
39 self.header = [ |
40 self.header = [ |
40 self.tr("Filename"), |
41 self.tr("Filename"), |
41 self.tr("Line"), |
42 self.tr("Line"), |
42 self.tr('Condition'), |
43 self.tr("Condition"), |
43 self.tr('Temporary'), |
44 self.tr("Temporary"), |
44 self.tr('Enabled'), |
45 self.tr("Enabled"), |
45 self.tr('Ignore Count'), |
46 self.tr("Ignore Count"), |
46 ] |
47 ] |
47 self.alignments = [Qt.AlignmentFlag.AlignLeft, |
48 self.alignments = [ |
48 Qt.AlignmentFlag.AlignRight, |
49 Qt.AlignmentFlag.AlignLeft, |
49 Qt.AlignmentFlag.AlignLeft, |
50 Qt.AlignmentFlag.AlignRight, |
50 Qt.AlignmentFlag.AlignHCenter, |
51 Qt.AlignmentFlag.AlignLeft, |
51 Qt.AlignmentFlag.AlignHCenter, |
52 Qt.AlignmentFlag.AlignHCenter, |
52 Qt.AlignmentFlag.AlignRight, |
53 Qt.AlignmentFlag.AlignHCenter, |
53 Qt.AlignmentFlag.AlignHCenter, |
54 Qt.AlignmentFlag.AlignRight, |
54 ] |
55 Qt.AlignmentFlag.AlignHCenter, |
|
56 ] |
55 |
57 |
56 def columnCount(self, parent=None): |
58 def columnCount(self, parent=None): |
57 """ |
59 """ |
58 Public method to get the current column count. |
60 Public method to get the current column count. |
59 |
61 |
60 @param parent reference to parent index (Unused) |
62 @param parent reference to parent index (Unused) |
61 @type QModelIndex |
63 @type QModelIndex |
62 @return column count |
64 @return column count |
63 @rtype int |
65 @rtype int |
64 """ |
66 """ |
65 return len(self.header) |
67 return len(self.header) |
66 |
68 |
67 def rowCount(self, parent=None): |
69 def rowCount(self, parent=None): |
68 """ |
70 """ |
69 Public method to get the current row count. |
71 Public method to get the current row count. |
70 |
72 |
71 @param parent reference to parent index |
73 @param parent reference to parent index |
72 @type QModelIndex |
74 @type QModelIndex |
73 @return row count |
75 @return row count |
74 @rtype int |
76 @rtype int |
75 """ |
77 """ |
76 # we do not have a tree, parent should always be invalid |
78 # we do not have a tree, parent should always be invalid |
77 if parent is None or not parent.isValid(): |
79 if parent is None or not parent.isValid(): |
78 return len(self.breakpoints) |
80 return len(self.breakpoints) |
79 else: |
81 else: |
80 return 0 |
82 return 0 |
81 |
83 |
82 def data(self, index, role=Qt.ItemDataRole.DisplayRole): |
84 def data(self, index, role=Qt.ItemDataRole.DisplayRole): |
83 """ |
85 """ |
84 Public method to get the requested data. |
86 Public method to get the requested data. |
85 |
87 |
86 @param index index of the requested data |
88 @param index index of the requested data |
87 @type QModelIndex |
89 @type QModelIndex |
88 @param role role of the requested data |
90 @param role role of the requested data |
89 @type Qt.ItemDataRole |
91 @type Qt.ItemDataRole |
90 @return the requested data |
92 @return the requested data |
91 @rtype any |
93 @rtype any |
92 """ |
94 """ |
93 if not index.isValid(): |
95 if not index.isValid(): |
94 return None |
96 return None |
95 |
97 |
96 if role == Qt.ItemDataRole.DisplayRole: |
98 if role == Qt.ItemDataRole.DisplayRole: |
97 if index.column() == 0: |
99 if index.column() == 0: |
98 filename = self.breakpoints[index.row()][0] |
100 filename = self.breakpoints[index.row()][0] |
99 if self.__project.isOpen(): |
101 if self.__project.isOpen(): |
100 return self.__project.getRelativePath(filename) |
102 return self.__project.getRelativePath(filename) |
101 else: |
103 else: |
102 return filename |
104 return filename |
103 elif index.column() in (1, 2, 5): |
105 elif index.column() in (1, 2, 5): |
104 return self.breakpoints[index.row()][index.column()] |
106 return self.breakpoints[index.row()][index.column()] |
105 |
107 |
106 if ( |
108 if role == Qt.ItemDataRole.CheckStateRole and index.column() in (3, 4): |
107 role == Qt.ItemDataRole.CheckStateRole and |
|
108 index.column() in (3, 4) |
|
109 ): |
|
110 if self.breakpoints[index.row()][index.column()]: |
109 if self.breakpoints[index.row()][index.column()]: |
111 return Qt.CheckState.Checked |
110 return Qt.CheckState.Checked |
112 else: |
111 else: |
113 return Qt.CheckState.Unchecked |
112 return Qt.CheckState.Unchecked |
114 |
113 |
115 if ( |
114 if role == Qt.ItemDataRole.ToolTipRole and index.column() in (0, 2): |
116 role == Qt.ItemDataRole.ToolTipRole and |
|
117 index.column() in (0, 2) |
|
118 ): |
|
119 return self.breakpoints[index.row()][index.column()] |
115 return self.breakpoints[index.row()][index.column()] |
120 |
116 |
121 if ( |
117 if role == Qt.ItemDataRole.TextAlignmentRole and index.column() < len( |
122 role == Qt.ItemDataRole.TextAlignmentRole and |
118 self.alignments |
123 index.column() < len(self.alignments) |
|
124 ): |
119 ): |
125 return self.alignments[index.column()].value |
120 return self.alignments[index.column()].value |
126 |
121 |
127 return None |
122 return None |
128 |
123 |
129 def setData(self, index, value, role=Qt.ItemDataRole.EditRole): |
124 def setData(self, index, value, role=Qt.ItemDataRole.EditRole): |
130 """ |
125 """ |
131 Public method to change data in the model. |
126 Public method to change data in the model. |
132 |
127 |
133 @param index index of the changed data |
128 @param index index of the changed data |
134 @type QModelIndex |
129 @type QModelIndex |
135 @param value value of the changed data |
130 @param value value of the changed data |
136 @type any |
131 @type any |
137 @param role role of the changed data |
132 @param role role of the changed data |
138 @type Qt.ItemDataRole |
133 @type Qt.ItemDataRole |
139 @return flag indicating success |
134 @return flag indicating success |
140 @rtype bool |
135 @rtype bool |
141 """ |
136 """ |
142 if (not index.isValid() or |
137 if ( |
143 index.column() >= len(self.header) or |
138 not index.isValid() |
144 index.row() >= len(self.breakpoints)): |
139 or index.column() >= len(self.header) |
|
140 or index.row() >= len(self.breakpoints) |
|
141 ): |
145 return False |
142 return False |
146 |
143 |
147 self.dataAboutToBeChanged.emit(index, index) |
144 self.dataAboutToBeChanged.emit(index, index) |
148 self.breakpoints[index.row()][index.column()] = value |
145 self.breakpoints[index.row()][index.column()] = value |
149 self.dataChanged.emit(index, index) |
146 self.dataChanged.emit(index, index) |
150 return True |
147 return True |
151 |
148 |
152 def flags(self, index): |
149 def flags(self, index): |
153 """ |
150 """ |
154 Public method to get item flags. |
151 Public method to get item flags. |
155 |
152 |
156 @param index index of the requested flags |
153 @param index index of the requested flags |
157 @type QModelIndex |
154 @type QModelIndex |
158 @return item flags for the given index |
155 @return item flags for the given index |
159 @rtype Qt.ItemFlags |
156 @rtype Qt.ItemFlags |
160 """ |
157 """ |
161 if not index.isValid(): |
158 if not index.isValid(): |
162 return Qt.ItemFlag.ItemIsEnabled |
159 return Qt.ItemFlag.ItemIsEnabled |
163 |
160 |
164 return Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsSelectable |
161 return Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsSelectable |
165 |
162 |
166 def headerData(self, section, orientation, |
163 def headerData(self, section, orientation, role=Qt.ItemDataRole.DisplayRole): |
167 role=Qt.ItemDataRole.DisplayRole): |
|
168 """ |
164 """ |
169 Public method to get header data. |
165 Public method to get header data. |
170 |
166 |
171 @param section section number of the requested header data |
167 @param section section number of the requested header data |
172 @type int |
168 @type int |
173 @param orientation orientation of the header |
169 @param orientation orientation of the header |
174 @type Qt.Orientation |
170 @type Qt.Orientation |
175 @param role role of the requested data |
171 @param role role of the requested data |
176 @type Qt.ItemDataRole |
172 @type Qt.ItemDataRole |
177 @return header data |
173 @return header data |
178 @rtype str |
174 @rtype str |
179 """ |
175 """ |
180 if ( |
176 if ( |
181 orientation == Qt.Orientation.Horizontal and |
177 orientation == Qt.Orientation.Horizontal |
182 role == Qt.ItemDataRole.DisplayRole |
178 and role == Qt.ItemDataRole.DisplayRole |
183 ): |
179 ): |
184 if section >= len(self.header): |
180 if section >= len(self.header): |
185 return "" |
181 return "" |
186 else: |
182 else: |
187 return self.header[section] |
183 return self.header[section] |
188 |
184 |
189 return None |
185 return None |
190 |
186 |
191 def index(self, row, column, parent=None): |
187 def index(self, row, column, parent=None): |
192 """ |
188 """ |
193 Public method to create an index. |
189 Public method to create an index. |
194 |
190 |
195 @param row row number for the index |
191 @param row row number for the index |
196 @type int |
192 @type int |
197 @param column column number for the index |
193 @param column column number for the index |
198 @type int |
194 @type int |
199 @param parent index of the parent item |
195 @param parent index of the parent item |
200 @type QModelIndex |
196 @type QModelIndex |
201 @return requested index |
197 @return requested index |
202 @rtype QModelIndex |
198 @rtype QModelIndex |
203 """ |
199 """ |
204 if ((parent and parent.isValid()) or |
200 if ( |
205 row < 0 or row >= len(self.breakpoints) or |
201 (parent and parent.isValid()) |
206 column < 0 or column >= len(self.header)): |
202 or row < 0 |
|
203 or row >= len(self.breakpoints) |
|
204 or column < 0 |
|
205 or column >= len(self.header) |
|
206 ): |
207 return QModelIndex() |
207 return QModelIndex() |
208 |
208 |
209 return self.createIndex(row, column, self.breakpoints[row]) |
209 return self.createIndex(row, column, self.breakpoints[row]) |
210 |
210 |
211 def parent(self, index): |
211 def parent(self, index): |
212 """ |
212 """ |
213 Public method to get the parent index. |
213 Public method to get the parent index. |
214 |
214 |
215 @param index index of item to get parent |
215 @param index index of item to get parent |
216 @type QModelIndex |
216 @type QModelIndex |
217 @return index of parent |
217 @return index of parent |
218 @rtype QModelIndex |
218 @rtype QModelIndex |
219 """ |
219 """ |
220 return QModelIndex() |
220 return QModelIndex() |
221 |
221 |
222 def hasChildren(self, parent=None): |
222 def hasChildren(self, parent=None): |
223 """ |
223 """ |
224 Public method to check for the presence of child items. |
224 Public method to check for the presence of child items. |
225 |
225 |
226 @param parent index of parent item |
226 @param parent index of parent item |
227 @type QModelIndex |
227 @type QModelIndex |
228 @return flag indicating the presence of child items |
228 @return flag indicating the presence of child items |
229 @rtype bool |
229 @rtype bool |
230 """ |
230 """ |
231 if parent is None or not parent.isValid(): |
231 if parent is None or not parent.isValid(): |
232 return len(self.breakpoints) > 0 |
232 return len(self.breakpoints) > 0 |
233 else: |
233 else: |
234 return False |
234 return False |
235 |
235 |
236 ########################################################################### |
236 ########################################################################### |
237 |
237 |
238 def addBreakPoint(self, fn, line, properties): |
238 def addBreakPoint(self, fn, line, properties): |
239 """ |
239 """ |
240 Public method to add a new breakpoint to the list. |
240 Public method to add a new breakpoint to the list. |
241 |
241 |
242 @param fn filename of the breakpoint |
242 @param fn filename of the breakpoint |
243 @type str |
243 @type str |
244 @param line line number of the breakpoint |
244 @param line line number of the breakpoint |
245 @type int |
245 @type int |
246 @param properties properties of the breakpoint |
246 @param properties properties of the breakpoint |
250 bp = [fn, line] + list(properties) |
250 bp = [fn, line] + list(properties) |
251 cnt = len(self.breakpoints) |
251 cnt = len(self.breakpoints) |
252 self.beginInsertRows(QModelIndex(), cnt, cnt) |
252 self.beginInsertRows(QModelIndex(), cnt, cnt) |
253 self.breakpoints.append(bp) |
253 self.breakpoints.append(bp) |
254 self.endInsertRows() |
254 self.endInsertRows() |
255 |
255 |
256 def addBreakPoints(self, breakpoints): |
256 def addBreakPoints(self, breakpoints): |
257 """ |
257 """ |
258 Public method to add multiple breakpoints to the list. |
258 Public method to add multiple breakpoints to the list. |
259 |
259 |
260 @param breakpoints list of breakpoints with file name, line number, |
260 @param breakpoints list of breakpoints with file name, line number, |
261 condition, temporary flag, enabled flag and ignore count each |
261 condition, temporary flag, enabled flag and ignore count each |
262 @type list of (str, int, str, bool, bool, int) |
262 @type list of (str, int, str, bool, bool, int) |
263 """ |
263 """ |
264 cnt = len(self.breakpoints) |
264 cnt = len(self.breakpoints) |
265 self.beginInsertRows(QModelIndex(), cnt, cnt + len(breakpoints) - 1) |
265 self.beginInsertRows(QModelIndex(), cnt, cnt + len(breakpoints) - 1) |
266 self.breakpoints += breakpoints |
266 self.breakpoints += breakpoints |
267 self.endInsertRows() |
267 self.endInsertRows() |
268 |
268 |
269 def setBreakPointByIndex(self, index, fn, line, properties): |
269 def setBreakPointByIndex(self, index, fn, line, properties): |
270 """ |
270 """ |
271 Public method to set the values of a breakpoint given by index. |
271 Public method to set the values of a breakpoint given by index. |
272 |
272 |
273 @param index index of the breakpoint |
273 @param index index of the breakpoint |
274 @type QModelIndex |
274 @type QModelIndex |
275 @param fn filename of the breakpoint |
275 @param fn filename of the breakpoint |
276 @type str |
276 @type str |
277 @param line line number of the breakpoint |
277 @param line line number of the breakpoint |