src/eric7/Debugger/WatchPointModel.py

branch
eric7
changeset 9330
a5b42af40217
parent 9221
bf71ee032bb4
child 9653
e67609152c5e
equal deleted inserted replaced
9329:bd8e621c3c20 9330:a5b42af40217
7 Module implementing the Watch expression model. 7 Module implementing the Watch expression 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 WatchPointModel(QAbstractItemModel): 21 class WatchPointModel(QAbstractItemModel):
17 """ 22 """
18 Class implementing a custom model for watch expressions. 23 Class implementing a custom model for watch expressions.
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)
25 30
31 ConditionColumn = 0
32 SpecialColumn = 1
33 TemporaryColumn = 2
34 EnabledColumn = 3
35 IgnoreCountColumn = 4
36
37 Header = (
38 QCoreApplication.translate("WatchPointModel", "Condition"),
39 QCoreApplication.translate("WatchPointModel", "Special"),
40 QCoreApplication.translate("WatchPointModel", "Temporary"),
41 QCoreApplication.translate("WatchPointModel", "Enabled"),
42 QCoreApplication.translate("WatchPointModel", "Ignore Count"),
43 )
44
45 Alignments = (
46 Qt.AlignmentFlag.AlignLeft,
47 Qt.AlignmentFlag.AlignLeft,
48 Qt.AlignmentFlag.AlignHCenter,
49 Qt.AlignmentFlag.AlignHCenter,
50 Qt.AlignmentFlag.AlignRight,
51 )
52
26 def __init__(self, parent=None): 53 def __init__(self, parent=None):
27 """ 54 """
28 Constructor 55 Constructor
29 56
30 @param parent reference to the parent widget (QObject) 57 @param parent reference to the parent widget (QObject)
31 """ 58 """
32 super().__init__(parent) 59 super().__init__(parent)
33 60
34 self.watchpoints = [] 61 self.watchpoints = []
35 self.header = [
36 self.tr("Condition"),
37 self.tr("Special"),
38 self.tr("Temporary"),
39 self.tr("Enabled"),
40 self.tr("Ignore Count"),
41 ]
42 self.alignments = [
43 Qt.AlignmentFlag.AlignLeft,
44 Qt.AlignmentFlag.AlignLeft,
45 Qt.AlignmentFlag.AlignHCenter,
46 Qt.AlignmentFlag.AlignHCenter,
47 Qt.AlignmentFlag.AlignRight,
48 ]
49 62
50 def columnCount(self, parent=None): 63 def columnCount(self, parent=None):
51 """ 64 """
52 Public method to get the current column count. 65 Public method to get the current column count.
53 66
54 @param parent index of the parent item (QModelIndex) (Unused) 67 @param parent index of the parent item (QModelIndex) (Unused)
55 @return column count (integer) 68 @return column count (integer)
56 """ 69 """
57 return len(self.header) 70 return len(WatchPointModel.Header)
58 71
59 def rowCount(self, parent=None): 72 def rowCount(self, parent=None):
60 """ 73 """
61 Public method to get the current row count. 74 Public method to get the current row count.
62 75
78 @return the requested data 91 @return the requested data
79 """ 92 """
80 if not index.isValid(): 93 if not index.isValid():
81 return None 94 return None
82 95
83 if role == Qt.ItemDataRole.DisplayRole and index.column() in [0, 1, 4]: 96 if role == Qt.ItemDataRole.DisplayRole and index.column() in (
97 WatchPointModel.ConditionColumn,
98 WatchPointModel.SpecialColumn,
99 WatchPointModel.IgnoreCountColumn,
100 ):
84 return self.watchpoints[index.row()][index.column()] 101 return self.watchpoints[index.row()][index.column()]
85 102
86 if role == Qt.ItemDataRole.CheckStateRole and index.column() in [2, 3]: 103 if role == Qt.ItemDataRole.CheckStateRole and index.column() in (
104 WatchPointModel.TemporaryColumn,
105 WatchPointModel.EnabledColumn,
106 ):
87 if self.watchpoints[index.row()][index.column()]: 107 if self.watchpoints[index.row()][index.column()]:
88 return Qt.CheckState.Checked 108 return Qt.CheckState.Checked
89 else: 109 else:
90 return Qt.CheckState.Unchecked 110 return Qt.CheckState.Unchecked
91 111
92 if role == Qt.ItemDataRole.ToolTipRole and index.column() in [0, 1]: 112 if role == Qt.ItemDataRole.ToolTipRole and index.column() in (
113 WatchPointModel.ConditionColumn,
114 WatchPointModel.SpecialColumn,
115 ):
93 return self.watchpoints[index.row()][index.column()] 116 return self.watchpoints[index.row()][index.column()]
94 117
95 if role == Qt.ItemDataRole.TextAlignmentRole and index.column() < len( 118 if role == Qt.ItemDataRole.TextAlignmentRole and index.column() < len(
96 self.alignments 119 WatchPointModel.Alignments
97 ): 120 ):
98 return self.alignments[index.column()].value 121 return WatchPointModel.Alignments[index.column()].value
99 122
100 return None 123 return None
101 124
102 def flags(self, index): 125 def flags(self, index):
103 """ 126 """
122 """ 145 """
123 if ( 146 if (
124 orientation == Qt.Orientation.Horizontal 147 orientation == Qt.Orientation.Horizontal
125 and role == Qt.ItemDataRole.DisplayRole 148 and role == Qt.ItemDataRole.DisplayRole
126 ): 149 ):
127 if section >= len(self.header): 150 if section >= len(WatchPointModel.Header):
128 return "" 151 return ""
129 else: 152 else:
130 return self.header[section] 153 return WatchPointModel.Header[section]
131 154
132 return None 155 return None
133 156
134 def index(self, row, column, parent=None): 157 def index(self, row, column, parent=None):
135 """ 158 """
143 if ( 166 if (
144 (parent and parent.isValid()) 167 (parent and parent.isValid())
145 or row < 0 168 or row < 0
146 or row >= len(self.watchpoints) 169 or row >= len(self.watchpoints)
147 or column < 0 170 or column < 0
148 or column >= len(self.header) 171 or column >= len(WatchPointModel.Header)
149 ): 172 ):
150 return QModelIndex() 173 return QModelIndex()
151 174
152 return self.createIndex(row, column, self.watchpoints[row]) 175 return self.createIndex(row, column, self.watchpoints[row])
153 176

eric ide

mercurial