Files
pyGUI/src/pygui/backend/models/data_model.py
T

85 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""QAbstractTableModel for displaying parsed wafer temperature data in QML."""
from __future__ import annotations
import logging
from typing import Any
from PySide6.QtCore import QAbstractTableModel, Qt
log = logging.getLogger(__name__)
# Column roles for the temperature data table
ROW_ROLE = Qt.ItemDataRole.UserRole + 1
COL_ROLE = Qt.ItemDataRole.UserRole + 2
class TemperatureTableModel(QAbstractTableModel):
"""Table model for parsed wafer temperature data.
Exposes a 2D list of temperature strings to QML TableView.
Column 0 = row index, remaining columns = Sensor1, Sensor2, ...
"""
def __init__(self, parent: Any = None) -> None:
super().__init__(parent)
self._data: list[list[str]] = [] # 2D array of temperature strings
self._col_count: int = 0 # Number of sensor columns (excludes row index)
def reset(self) -> None:
"""Clear all data."""
self.beginResetModel()
self._data = []
self._col_count = 0
self.endResetModel()
def load_data(self, data: list[list[str]], col_count: int) -> None:
"""Load parsed temperature data into the model.
Args:
data: 2D list of temperature strings (e.g. [["25.30", "24.80", ...], ...]).
col_count: Number of sensor columns (may differ from data[0] length).
"""
self.beginResetModel()
self._data = data
self._col_count = col_count
self.endResetModel()
log.info("Loaded %d rows × %d cols into model", len(data), col_count)
# ---- QAbstractTableModel interface ----
def rowCount(self, parent: Any = None) -> int:
return len(self._data)
def columnCount(self, parent: Any = None) -> int:
# Column 0 = row index, columns 1..N = sensor values
return self._col_count + 1
def data(self, index: Any, role: int = ...) -> Any:
if not index.isValid():
return None
row = index.row()
col = index.column()
if role == Qt.ItemDataRole.DisplayRole:
if col == 0:
return str(row + 1) # 1-based row index
sensor_col = col - 1
if row < len(self._data) and sensor_col < len(self._data[row]):
return self._data[row][sensor_col]
return "0"
return None
def headerData(
self, section: int, orientation: int, role: int = ...
) -> Any:
if role != Qt.ItemDataRole.DisplayRole:
return None
if orientation == Qt.Orientation.Horizontal:
if section == 0:
return "Row"
return f"Sensor{section}"
return str(section + 1)