src/eric7/Debugger/WatchPointModel.py

branch
eric7
changeset 9330
a5b42af40217
parent 9221
bf71ee032bb4
child 9653
e67609152c5e
--- a/src/eric7/Debugger/WatchPointModel.py	Thu Sep 15 11:51:21 2022 +0200
+++ b/src/eric7/Debugger/WatchPointModel.py	Thu Sep 15 13:19:51 2022 +0200
@@ -9,10 +9,15 @@
 
 import copy
 
-from PyQt6.QtCore import pyqtSignal, Qt, QAbstractItemModel, QModelIndex
+from PyQt6.QtCore import (
+    QAbstractItemModel,
+    QCoreApplication,
+    QModelIndex,
+    Qt,
+    pyqtSignal,
+)
 
 
-# TODO: change column numbers to class attributes
 class WatchPointModel(QAbstractItemModel):
     """
     Class implementing a custom model for watch expressions.
@@ -23,6 +28,28 @@
 
     dataAboutToBeChanged = pyqtSignal(QModelIndex, QModelIndex)
 
+    ConditionColumn = 0
+    SpecialColumn = 1
+    TemporaryColumn = 2
+    EnabledColumn = 3
+    IgnoreCountColumn = 4
+
+    Header = (
+        QCoreApplication.translate("WatchPointModel", "Condition"),
+        QCoreApplication.translate("WatchPointModel", "Special"),
+        QCoreApplication.translate("WatchPointModel", "Temporary"),
+        QCoreApplication.translate("WatchPointModel", "Enabled"),
+        QCoreApplication.translate("WatchPointModel", "Ignore Count"),
+    )
+
+    Alignments = (
+        Qt.AlignmentFlag.AlignLeft,
+        Qt.AlignmentFlag.AlignLeft,
+        Qt.AlignmentFlag.AlignHCenter,
+        Qt.AlignmentFlag.AlignHCenter,
+        Qt.AlignmentFlag.AlignRight,
+    )
+
     def __init__(self, parent=None):
         """
         Constructor
@@ -32,20 +59,6 @@
         super().__init__(parent)
 
         self.watchpoints = []
-        self.header = [
-            self.tr("Condition"),
-            self.tr("Special"),
-            self.tr("Temporary"),
-            self.tr("Enabled"),
-            self.tr("Ignore Count"),
-        ]
-        self.alignments = [
-            Qt.AlignmentFlag.AlignLeft,
-            Qt.AlignmentFlag.AlignLeft,
-            Qt.AlignmentFlag.AlignHCenter,
-            Qt.AlignmentFlag.AlignHCenter,
-            Qt.AlignmentFlag.AlignRight,
-        ]
 
     def columnCount(self, parent=None):
         """
@@ -54,7 +67,7 @@
         @param parent index of the parent item (QModelIndex) (Unused)
         @return column count (integer)
         """
-        return len(self.header)
+        return len(WatchPointModel.Header)
 
     def rowCount(self, parent=None):
         """
@@ -80,22 +93,32 @@
         if not index.isValid():
             return None
 
-        if role == Qt.ItemDataRole.DisplayRole and index.column() in [0, 1, 4]:
+        if role == Qt.ItemDataRole.DisplayRole and index.column() in (
+            WatchPointModel.ConditionColumn,
+            WatchPointModel.SpecialColumn,
+            WatchPointModel.IgnoreCountColumn,
+        ):
             return self.watchpoints[index.row()][index.column()]
 
-        if role == Qt.ItemDataRole.CheckStateRole and index.column() in [2, 3]:
+        if role == Qt.ItemDataRole.CheckStateRole and index.column() in (
+            WatchPointModel.TemporaryColumn,
+            WatchPointModel.EnabledColumn,
+        ):
             if self.watchpoints[index.row()][index.column()]:
                 return Qt.CheckState.Checked
             else:
                 return Qt.CheckState.Unchecked
 
-        if role == Qt.ItemDataRole.ToolTipRole and index.column() in [0, 1]:
+        if role == Qt.ItemDataRole.ToolTipRole and index.column() in (
+            WatchPointModel.ConditionColumn,
+            WatchPointModel.SpecialColumn,
+        ):
             return self.watchpoints[index.row()][index.column()]
 
         if role == Qt.ItemDataRole.TextAlignmentRole and index.column() < len(
-            self.alignments
+            WatchPointModel.Alignments
         ):
-            return self.alignments[index.column()].value
+            return WatchPointModel.Alignments[index.column()].value
 
         return None
 
@@ -124,10 +147,10 @@
             orientation == Qt.Orientation.Horizontal
             and role == Qt.ItemDataRole.DisplayRole
         ):
-            if section >= len(self.header):
+            if section >= len(WatchPointModel.Header):
                 return ""
             else:
-                return self.header[section]
+                return WatchPointModel.Header[section]
 
         return None
 
@@ -145,7 +168,7 @@
             or row < 0
             or row >= len(self.watchpoints)
             or column < 0
-            or column >= len(self.header)
+            or column >= len(WatchPointModel.Header)
         ):
             return QModelIndex()
 

eric ide

mercurial