safetyInspectDialog.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include "SafetyInspectDialog.h"
  2. #include <QApplication>
  3. #include <QMessageBox>
  4. #include <QScreen>
  5. SafetyInspectDialog::SafetyInspectDialog(QWidget *parent, const QMap<QString, QString> &userNameById,
  6. const QString &dateStr)
  7. : QDialog(parent),
  8. m_dateLabel(nullptr),
  9. m_tableWidget(nullptr),
  10. m_closeButton(nullptr),
  11. m_currentDate(dateStr),
  12. m_userNameById(userNameById) {
  13. setupUI();
  14. }
  15. SafetyInspectDialog::~SafetyInspectDialog() {}
  16. void SafetyInspectDialog::setupUI() {
  17. setWindowTitle("安全检查记录");
  18. setModal(true);
  19. resize(600, 400);
  20. // Center the dialog
  21. QScreen *screen = QApplication::primaryScreen();
  22. if (screen) {
  23. QRect screenGeometry = screen->geometry();
  24. int x = (screenGeometry.width() - width()) / 2;
  25. int y = (screenGeometry.height() - height()) / 2;
  26. move(x, y);
  27. }
  28. // Main layout
  29. QVBoxLayout *mainLayout = new QVBoxLayout(this);
  30. mainLayout->setContentsMargins(20, 20, 20, 20);
  31. mainLayout->setSpacing(15);
  32. // Header section
  33. QHBoxLayout *headerLayout = new QHBoxLayout();
  34. QLabel *titleLabel = new QLabel("检查日期:");
  35. titleLabel->setStyleSheet("font-weight: bold; font-size: 14px; color: #333;");
  36. m_dateLabel = new QLabel("未设置");
  37. m_dateLabel->setStyleSheet("font-size: 14px; color: #666; padding: 5px;");
  38. headerLayout->addWidget(titleLabel);
  39. headerLayout->addWidget(m_dateLabel);
  40. headerLayout->addStretch();
  41. mainLayout->addLayout(headerLayout);
  42. // Table setup
  43. setupTable();
  44. mainLayout->addWidget(m_tableWidget);
  45. // Button section
  46. QHBoxLayout *buttonLayout = new QHBoxLayout();
  47. m_closeButton = new QPushButton("关闭");
  48. m_closeButton->setStyleSheet(
  49. "QPushButton { "
  50. "background-color: #007ACC; "
  51. "color: white; "
  52. "padding: 8px 20px; "
  53. "border-radius: 4px; "
  54. "border: none; "
  55. "font-size: 12px; "
  56. "} "
  57. "QPushButton:hover { "
  58. "background-color: #005a9e; "
  59. "} "
  60. "QPushButton:pressed { "
  61. "background-color: #004578; "
  62. "}");
  63. connect(m_closeButton, &QPushButton::clicked, this, &SafetyInspectDialog::onCloseButtonClicked);
  64. buttonLayout->addStretch();
  65. buttonLayout->addWidget(m_closeButton);
  66. mainLayout->addLayout(buttonLayout);
  67. }
  68. void SafetyInspectDialog::setupTable() {
  69. m_tableWidget = new QTableWidget(this);
  70. m_tableWidget->setColumnCount(3);
  71. QStringList headers;
  72. headers << "姓名" << "电话" << "检查状态";
  73. m_tableWidget->setHorizontalHeaderLabels(headers);
  74. // Configure table properties
  75. m_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
  76. m_tableWidget->setAlternatingRowColors(true);
  77. m_tableWidget->verticalHeader()->setVisible(false);
  78. // Set column widths
  79. m_tableWidget->horizontalHeader()->setStretchLastSection(true);
  80. m_tableWidget->setColumnWidth(0, 150); // Name column
  81. m_tableWidget->setColumnWidth(1, 180); // Phone column
  82. // Status column will stretch to fill remaining space
  83. }
  84. void SafetyInspectDialog::setDate(const QString &date) {
  85. m_currentDate = date;
  86. if (m_dateLabel) {
  87. m_dateLabel->setText(date);
  88. }
  89. }
  90. void SafetyInspectDialog::setInspectionRecords(const QList<InspectionRecord> &records) {
  91. m_inspectionRecords = records;
  92. populateTable();
  93. }
  94. void SafetyInspectDialog::populateTable() {
  95. if (!m_tableWidget) return;
  96. m_tableWidget->setRowCount(m_inspectionRecords.size());
  97. for (int i = 0; i < m_inspectionRecords.size(); ++i) {
  98. const InspectionRecord &record = m_inspectionRecords[i];
  99. m_tableWidget->setItem(i, 0, new QTableWidgetItem(record.name));
  100. m_tableWidget->setItem(i, 1, new QTableWidgetItem(record.phone));
  101. if (record.confirmTime != QString()) {
  102. QString formattedTime = record.confirmTime.left(16).replace('T', ' ');
  103. QTableWidgetItem *timeItem = new QTableWidgetItem(formattedTime);
  104. timeItem->setForeground(QColor(Qt::darkGreen));
  105. m_tableWidget->setItem(i, 2, timeItem);
  106. } else {
  107. m_tableWidget->setItem(i, 2, new QTableWidgetItem("未确认"));
  108. }
  109. }
  110. }
  111. void SafetyInspectDialog::onCloseButtonClicked() { accept(); }