src/eric7/Debugger/BreakPointModel.py

branch
eric7
changeset 9330
a5b42af40217
parent 9221
bf71ee032bb4
child 9653
e67609152c5e
equal deleted inserted replaced
9329:bd8e621c3c20 9330:a5b42af40217
7 Module implementing the Breakpoint model. 7 Module implementing the Breakpoint model.
8 """ 8 """
9 9
10 import copy 10 import copy
11 11
12 from PyQt6.QtCore import pyqtSignal, Qt, QAbstractItemModel, QModelIndex 12 from PyQt6.QtCore import (
13 13 QAbstractItemModel,
14 14 QCoreApplication,
15 # TODO: change column numbers to class attributes 15 QModelIndex,
16 Qt,
17 pyqtSignal,
18 )
19
20
16 class BreakPointModel(QAbstractItemModel): 21 class BreakPointModel(QAbstractItemModel):
17 """ 22 """
18 Class implementing a custom model for breakpoints. 23 Class implementing a custom model for breakpoints.
19 24
20 @signal dataAboutToBeChanged(QModelIndex, QModelIndex) emitted to indicate 25 @signal dataAboutToBeChanged(QModelIndex, QModelIndex) emitted to indicate
21 a change of the data 26 a change of the data
22 """ 27 """
23 28
24 dataAboutToBeChanged = pyqtSignal(QModelIndex, QModelIndex) 29 dataAboutToBeChanged = pyqtSignal(QModelIndex, QModelIndex)
30
31 FilenameColumn = 0
32 LineNumberColumn = 1
33 ConditionColumn = 2
34 TemporaryColumn = 3
35 EnabledColumn = 4
36 IgnoreCountColumn = 5
37
38 Header = (
39 QCoreApplication.translate("BreakPointModel", "Filename"),
40 QCoreApplication.translate("BreakPointModel", "Line"),
41 QCoreApplication.translate("BreakPointModel", "Condition"),
42 QCoreApplication.translate("BreakPointModel", "Temporary"),
43 QCoreApplication.translate("BreakPointModel", "Enabled"),
44 QCoreApplication.translate("BreakPointModel", "Ignore Count"),
45 )
46
47 Alignments = (
48 Qt.AlignmentFlag.AlignLeft,
49 Qt.AlignmentFlag.AlignRight,
50 Qt.AlignmentFlag.AlignLeft,
51 Qt.AlignmentFlag.AlignHCenter,
52 Qt.AlignmentFlag.AlignHCenter,
53 Qt.AlignmentFlag.AlignRight,
54 Qt.AlignmentFlag.AlignHCenter,
55 )
25 56
26 def __init__(self, project, parent=None): 57 def __init__(self, project, parent=None):
27 """ 58 """
28 Constructor 59 Constructor
29 60
35 super().__init__(parent) 66 super().__init__(parent)
36 67
37 self.__project = project 68 self.__project = project
38 69
39 self.breakpoints = [] 70 self.breakpoints = []
40 self.header = [
41 self.tr("Filename"),
42 self.tr("Line"),
43 self.tr("Condition"),
44 self.tr("Temporary"),
45 self.tr("Enabled"),
46 self.tr("Ignore Count"),
47 ]
48 self.alignments = [
49 Qt.AlignmentFlag.AlignLeft,
50 Qt.AlignmentFlag.AlignRight,
51 Qt.AlignmentFlag.AlignLeft,
52 Qt.AlignmentFlag.AlignHCenter,
53 Qt.AlignmentFlag.AlignHCenter,
54 Qt.AlignmentFlag.AlignRight,
55 Qt.AlignmentFlag.AlignHCenter,
56 ]
57 71
58 def columnCount(self, parent=None): 72 def columnCount(self, parent=None):
59 """ 73 """
60 Public method to get the current column count. 74 Public method to get the current column count.
61 75
62 @param parent reference to parent index (Unused) 76 @param parent reference to parent index (Unused)
63 @type QModelIndex 77 @type QModelIndex
64 @return column count 78 @return column count
65 @rtype int 79 @rtype int
66 """ 80 """
67 return len(self.header) 81 return len(BreakPointModel.Header)
68 82
69 def rowCount(self, parent=None): 83 def rowCount(self, parent=None):
70 """ 84 """
71 Public method to get the current row count. 85 Public method to get the current row count.
72 86
94 """ 108 """
95 if not index.isValid(): 109 if not index.isValid():
96 return None 110 return None
97 111
98 if role == Qt.ItemDataRole.DisplayRole: 112 if role == Qt.ItemDataRole.DisplayRole:
99 if index.column() == 0: 113 if index.column() == BreakPointModel.FilenameColumn:
100 filename = self.breakpoints[index.row()][0] 114 filename = self.breakpoints[index.row()][0]
101 if self.__project.isOpen(): 115 if self.__project.isOpen():
102 return self.__project.getRelativePath(filename) 116 return self.__project.getRelativePath(filename)
103 else: 117 else:
104 return filename 118 return filename
105 elif index.column() in (1, 2, 5): 119 elif index.column() in (
120 BreakPointModel.LineNumberColumn,
121 BreakPointModel.ConditionColumn,
122 BreakPointModel.IgnoreCountColumn,
123 ):
106 return self.breakpoints[index.row()][index.column()] 124 return self.breakpoints[index.row()][index.column()]
107 125
108 if role == Qt.ItemDataRole.CheckStateRole and index.column() in (3, 4): 126 if role == Qt.ItemDataRole.CheckStateRole and index.column() in (
127 BreakPointModel.TemporaryColumn,
128 BreakPointModel.EnabledColumn,
129 ):
109 if self.breakpoints[index.row()][index.column()]: 130 if self.breakpoints[index.row()][index.column()]:
110 return Qt.CheckState.Checked 131 return Qt.CheckState.Checked
111 else: 132 else:
112 return Qt.CheckState.Unchecked 133 return Qt.CheckState.Unchecked
113 134
114 if role == Qt.ItemDataRole.ToolTipRole and index.column() in (0, 2): 135 if role == Qt.ItemDataRole.ToolTipRole and index.column() in (
136 BreakPointModel.FilenameColumn,
137 BreakPointModel.ConditionColumn,
138 ):
115 return self.breakpoints[index.row()][index.column()] 139 return self.breakpoints[index.row()][index.column()]
116 140
117 if role == Qt.ItemDataRole.TextAlignmentRole and index.column() < len( 141 if role == Qt.ItemDataRole.TextAlignmentRole and index.column() < len(
118 self.alignments 142 BreakPointModel.Alignments
119 ): 143 ):
120 return self.alignments[index.column()].value 144 return BreakPointModel.Alignments[index.column()].value
121 145
122 return None 146 return None
123 147
124 def setData(self, index, value, role=Qt.ItemDataRole.EditRole): 148 def setData(self, index, value, role=Qt.ItemDataRole.EditRole):
125 """ 149 """
134 @return flag indicating success 158 @return flag indicating success
135 @rtype bool 159 @rtype bool
136 """ 160 """
137 if ( 161 if (
138 not index.isValid() 162 not index.isValid()
139 or index.column() >= len(self.header) 163 or index.column() >= len(BreakPointModel.Header)
140 or index.row() >= len(self.breakpoints) 164 or index.row() >= len(self.breakpoints)
141 ): 165 ):
142 return False 166 return False
143 167
144 self.dataAboutToBeChanged.emit(index, index) 168 self.dataAboutToBeChanged.emit(index, index)
175 """ 199 """
176 if ( 200 if (
177 orientation == Qt.Orientation.Horizontal 201 orientation == Qt.Orientation.Horizontal
178 and role == Qt.ItemDataRole.DisplayRole 202 and role == Qt.ItemDataRole.DisplayRole
179 ): 203 ):
180 if section >= len(self.header): 204 if section >= len(BreakPointModel.Header):
181 return "" 205 return ""
182 else: 206 else:
183 return self.header[section] 207 return BreakPointModel.Header[section]
184 208
185 return None 209 return None
186 210
187 def index(self, row, column, parent=None): 211 def index(self, row, column, parent=None):
188 """ 212 """
200 if ( 224 if (
201 (parent and parent.isValid()) 225 (parent and parent.isValid())
202 or row < 0 226 or row < 0
203 or row >= len(self.breakpoints) 227 or row >= len(self.breakpoints)
204 or column < 0 228 or column < 0
205 or column >= len(self.header) 229 or column >= len(BreakPointModel.Header)
206 ): 230 ):
207 return QModelIndex() 231 return QModelIndex()
208 232
209 return self.createIndex(row, column, self.breakpoints[row]) 233 return self.createIndex(row, column, self.breakpoints[row])
210 234

eric ide

mercurial