#include "SafetyInspectDialog.h" #include #include #include SafetyInspectDialog::SafetyInspectDialog(QWidget *parent, const QMap &userNameById, const QString &dateStr) : QDialog(parent), m_dateLabel(nullptr), m_tableWidget(nullptr), m_closeButton(nullptr), m_currentDate(dateStr), m_userNameById(userNameById) { setupUI(); } SafetyInspectDialog::~SafetyInspectDialog() {} void SafetyInspectDialog::setupUI() { setWindowTitle("安全检查记录"); setModal(true); resize(600, 400); // Center the dialog QScreen *screen = QApplication::primaryScreen(); if (screen) { QRect screenGeometry = screen->geometry(); int x = (screenGeometry.width() - width()) / 2; int y = (screenGeometry.height() - height()) / 2; move(x, y); } // Main layout QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(20, 20, 20, 20); mainLayout->setSpacing(15); // Header section QHBoxLayout *headerLayout = new QHBoxLayout(); QLabel *titleLabel = new QLabel("检查日期:"); titleLabel->setStyleSheet("font-weight: bold; font-size: 14px; color: #333;"); m_dateLabel = new QLabel("未设置"); m_dateLabel->setStyleSheet("font-size: 14px; color: #666; padding: 5px;"); headerLayout->addWidget(titleLabel); headerLayout->addWidget(m_dateLabel); headerLayout->addStretch(); mainLayout->addLayout(headerLayout); // Table setup setupTable(); mainLayout->addWidget(m_tableWidget); // Button section QHBoxLayout *buttonLayout = new QHBoxLayout(); m_closeButton = new QPushButton("关闭"); m_closeButton->setStyleSheet( "QPushButton { " "background-color: #007ACC; " "color: white; " "padding: 8px 20px; " "border-radius: 4px; " "border: none; " "font-size: 12px; " "} " "QPushButton:hover { " "background-color: #005a9e; " "} " "QPushButton:pressed { " "background-color: #004578; " "}"); connect(m_closeButton, &QPushButton::clicked, this, &SafetyInspectDialog::onCloseButtonClicked); buttonLayout->addStretch(); buttonLayout->addWidget(m_closeButton); mainLayout->addLayout(buttonLayout); } void SafetyInspectDialog::setupTable() { m_tableWidget = new QTableWidget(this); m_tableWidget->setColumnCount(3); QStringList headers; headers << "姓名" << "电话" << "检查状态"; m_tableWidget->setHorizontalHeaderLabels(headers); // Configure table properties m_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); m_tableWidget->setAlternatingRowColors(true); m_tableWidget->verticalHeader()->setVisible(false); // Set column widths m_tableWidget->horizontalHeader()->setStretchLastSection(true); m_tableWidget->setColumnWidth(0, 150); // Name column m_tableWidget->setColumnWidth(1, 180); // Phone column // Status column will stretch to fill remaining space } void SafetyInspectDialog::setDate(const QString &date) { m_currentDate = date; if (m_dateLabel) { m_dateLabel->setText(date); } } void SafetyInspectDialog::setInspectionRecords(const QList &records) { m_inspectionRecords = records; populateTable(); } void SafetyInspectDialog::populateTable() { if (!m_tableWidget) return; m_tableWidget->setRowCount(m_inspectionRecords.size()); for (int i = 0; i < m_inspectionRecords.size(); ++i) { const InspectionRecord &record = m_inspectionRecords[i]; m_tableWidget->setItem(i, 0, new QTableWidgetItem(record.name)); m_tableWidget->setItem(i, 1, new QTableWidgetItem(record.phone)); if (record.confirmTime != QString()) { QString formattedTime = record.confirmTime.left(16).replace('T', ' '); QTableWidgetItem *timeItem = new QTableWidgetItem(formattedTime); timeItem->setForeground(QColor(Qt::darkGreen)); m_tableWidget->setItem(i, 2, timeItem); } else { m_tableWidget->setItem(i, 2, new QTableWidgetItem("未确认")); } } } void SafetyInspectDialog::onCloseButtonClicked() { accept(); }