| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- """
- Quality History Panel
- Panel for displaying recent quality test results in a table format.
- """
- from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QLabel,
- QPushButton, QSizePolicy, QTableWidget,
- QTableWidgetItem, QHeaderView, QScrollArea)
- from PyQt5.QtCore import Qt
- from PyQt5.QtGui import QFont, QColor
- from ui.widgets.panel_header import PanelHeader
- class QualityHistoryPanel(QWidget):
- """
- Panel for displaying recent quality test history.
- Shows table with test results and export functionality.
- """
- def __init__(self, parent=None):
- super().__init__(parent)
- self.test_history = []
- self.init_ui()
- def init_ui(self):
- """Initialize the panel UI."""
- # Set size policy
- self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
- layout = QVBoxLayout(self)
- layout.setContentsMargins(0, 0, 0, 0)
- layout.setSpacing(0)
- # Main panel container with card styling
- self.setStyleSheet("""
- QWidget {
- background-color: white;
- border: 1px solid #ddd;
- }
- """)
- # Header using the PanelHeader widget
- header = PanelHeader(
- title="Recent Quality Tests",
- color="#34495e" # Dark gray for history
- )
- layout.addWidget(header)
- # Content area
- content = QWidget()
- content.setStyleSheet("""
- background-color: #2c3e50;
- border: 1px solid #34495e;
- border-top: none;
- """)
- content_layout = QVBoxLayout(content)
- content_layout.setContentsMargins(10, 10, 10, 10)
- content_layout.setSpacing(10)
- # Create and populate the history table
- self._create_history_table(content_layout)
- # Export button
- self._create_export_button(content_layout)
- layout.addWidget(content, 1)
- def _create_history_table(self, parent_layout):
- """Create the history table widget."""
- # Table widget
- self.history_table = QTableWidget()
- self.history_table.setColumnCount(5)
- self.history_table.setHorizontalHeaderLabels(["Time", "ID", "Grade", "Score", "Defects"])
- # Configure table appearance
- self.history_table.setAlternatingRowColors(True)
- self.history_table.setSelectionBehavior(QTableWidget.SelectRows)
- self.history_table.setSelectionMode(QTableWidget.SingleSelection)
- self.history_table.setFocusPolicy(Qt.NoFocus)
- # Set column widths
- self.history_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.Fixed)
- self.history_table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Fixed)
- self.history_table.horizontalHeader().setSectionResizeMode(2, QHeaderView.Fixed)
- self.history_table.horizontalHeader().setSectionResizeMode(3, QHeaderView.Fixed)
- self.history_table.horizontalHeader().setSectionResizeMode(4, QHeaderView.Fixed)
- self.history_table.setColumnWidth(0, 80) # Time
- self.history_table.setColumnWidth(1, 70) # ID
- self.history_table.setColumnWidth(2, 50) # Grade
- self.history_table.setColumnWidth(3, 70) # Score
- self.history_table.setColumnWidth(4, 70) # Defects
- # Hide vertical header (row numbers)
- self.history_table.verticalHeader().setVisible(False)
- # Style the table
- self.history_table.setStyleSheet("""
- QTableWidget {
- background-color: #34495e;
- border: 1px solid #4a5f7a;
- border-radius: 5px;
- gridline-color: #4a5f7a;
- selection-background-color: #3498db;
- }
- QHeaderView::section {
- background-color: #2c3e50;
- color: #ecf0f1;
- padding: 8px;
- border: none;
- font-weight: bold;
- font-size: 10px;
- }
- QTableWidget::item {
- padding: 5px;
- color: #ecf0f1;
- border: none;
- }
- QTableWidget::item:selected {
- background-color: #3498db;
- color: white;
- }
- """)
- # Populate with sample data
- self._populate_sample_data()
- parent_layout.addWidget(self.history_table)
- def _populate_sample_data(self):
- """Populate table with sample history data."""
- # Sample test history data
- sample_data = [
- ("14:32:15", "Q-0032", "B", "78.5%", "2", "#f39c12"),
- ("14:28:10", "Q-0031", "A", "94.2%", "0", "#27ae60"),
- ("14:24:55", "Q-0030", "C", "52.8%", "5", "#e74c3c"),
- ("14:20:33", "Q-0029", "A", "91.7%", "1", "#27ae60"),
- ("14:16:12", "Q-0028", "B", "76.3%", "3", "#f39c12"),
- ("14:12:45", "Q-0027", "A", "89.4%", "0", "#27ae60"),
- ("14:08:22", "Q-0026", "B", "81.1%", "2", "#f39c12"),
- ("14:04:18", "Q-0025", "C", "45.9%", "7", "#e74c3c")
- ]
- self.history_table.setRowCount(len(sample_data))
- for row, (time, test_id, grade, score, defects, color) in enumerate(sample_data):
- # Time column
- time_item = QTableWidgetItem(time)
- time_item.setTextAlignment(Qt.AlignCenter)
- self.history_table.setItem(row, 0, time_item)
- # ID column
- id_item = QTableWidgetItem(test_id)
- id_item.setTextAlignment(Qt.AlignCenter)
- self.history_table.setItem(row, 1, id_item)
- # Grade column (color-coded widget)
- grade_item = QTableWidgetItem(grade)
- grade_item.setTextAlignment(Qt.AlignCenter)
- grade_item.setBackground(QColor(color))
- grade_item.setForeground(QColor("white"))
- self.history_table.setItem(row, 2, grade_item)
- # Score column
- score_item = QTableWidgetItem(score)
- score_item.setTextAlignment(Qt.AlignCenter)
- self.history_table.setItem(row, 3, score_item)
- # Defects column
- defects_item = QTableWidgetItem(defects)
- defects_item.setTextAlignment(Qt.AlignCenter)
- defects_item.setForeground(QColor(color))
- self.history_table.setItem(row, 4, defects_item)
- self.test_history = sample_data
- def _create_export_button(self, parent_layout):
- """Create the export results button."""
- self.export_btn = QPushButton("EXPORT RESULTS")
- self.export_btn.setFixedHeight(30)
- self.export_btn.setFont(QFont("Arial", 10, QFont.Bold))
- self.export_btn.setStyleSheet("""
- QPushButton {
- background-color: #9b59b6;
- color: white;
- border: 1px solid #8e44ad;
- border-radius: 3px;
- font-size: 10px;
- font-weight: bold;
- padding: 5px 15px;
- }
- QPushButton:hover {
- background-color: #8e44ad;
- border-color: #7d3c98;
- }
- QPushButton:pressed {
- background-color: #7d3c98;
- padding-top: 7px;
- }
- QPushButton:disabled {
- background-color: #7f8c8d;
- border-color: #95a5a6;
- color: #bdc3c7;
- }
- """)
- # For now, just show placeholder functionality
- self.export_btn.setToolTip("Export functionality - Coming soon")
- self.export_btn.clicked.connect(self._export_results)
- parent_layout.addWidget(self.export_btn)
- def _export_results(self):
- """Handle export button click (placeholder)."""
- # Placeholder for future export functionality
- print("Export functionality - Coming soon!")
- def add_test_result(self, time, test_id, grade, score, defects):
- """Add a new test result to the history."""
- # Add to beginning of list (most recent first)
- color = self._get_grade_color(grade)
- new_result = (time, test_id, grade, score, defects, color)
- self.test_history.insert(0, new_result)
- # Keep only last 50 results
- if len(self.test_history) > 50:
- self.test_history = self.test_history[:50]
- # Refresh table
- self._refresh_table()
- def _get_grade_color(self, grade):
- """Get color code for grade."""
- grade_colors = {
- 'A': '#27ae60',
- 'B': '#f39c12',
- 'C': '#e74c3c'
- }
- return grade_colors.get(grade, '#95a5a6')
- def _refresh_table(self):
- """Refresh the table display."""
- self.history_table.setRowCount(len(self.test_history))
- for row, (time, test_id, grade, score, defects, color) in enumerate(self.test_history):
- # Time column
- time_item = QTableWidgetItem(time)
- time_item.setTextAlignment(Qt.AlignCenter)
- self.history_table.setItem(row, 0, time_item)
- # ID column
- id_item = QTableWidgetItem(test_id)
- id_item.setTextAlignment(Qt.AlignCenter)
- self.history_table.setItem(row, 1, id_item)
- # Grade column (color-coded)
- grade_item = QTableWidgetItem(grade)
- grade_item.setTextAlignment(Qt.AlignCenter)
- grade_item.setBackground(QColor(color))
- grade_item.setForeground(QColor("white"))
- self.history_table.setItem(row, 2, grade_item)
- # Score column
- score_item = QTableWidgetItem(score)
- score_item.setTextAlignment(Qt.AlignCenter)
- self.history_table.setItem(row, 3, score_item)
- # Defects column
- defects_item = QTableWidgetItem(defects)
- defects_item.setTextAlignment(Qt.AlignCenter)
- defects_item.setForeground(QColor(color))
- self.history_table.setItem(row, 4, defects_item)
- def clear_history(self):
- """Clear all test history."""
- self.test_history = []
- self.history_table.setRowCount(0)
- def get_recent_tests(self, count=10):
- """Get the most recent test results."""
- return self.test_history[:count]
|