SafetyInspectDialog.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef SAFETYINSPECT_H
  2. #define SAFETYINSPECT_H
  3. #include <QDialog>
  4. #include <QHBoxLayout>
  5. #include <QHeaderView>
  6. #include <QJsonArray>
  7. #include <QJsonDocument>
  8. #include <QJsonObject>
  9. #include <QLabel>
  10. #include <QNetworkAccessManager>
  11. #include <QNetworkReply>
  12. #include <QPushButton>
  13. #include <QTableWidget>
  14. #include <QVBoxLayout>
  15. /**
  16. * SafetyInspect Dialog Component
  17. *
  18. * Usage example:
  19. *
  20. * // Method 1: Set data manually
  21. * SafetyInspect *dialog = new SafetyInspect(this);
  22. * dialog->setDate("2025-07-30");
  23. *
  24. * QList<SafetyInspect::InspectionRecord> records;
  25. * SafetyInspect::InspectionRecord record1;
  26. * record1.name = "张三";
  27. * record1.phone = "13800138000";
  28. * record1.checkStatus = "检查通过";
  29. * records.append(record1);
  30. *
  31. * dialog->setInspectionRecords(records);
  32. * dialog->exec();
  33. *
  34. * // Method 2: Fetch data from HTTP
  35. * SafetyInspect *dialog = new SafetyInspect(this);
  36. * dialog->fetchDataFromHttp("https://api.example.com/safety-inspection");
  37. * dialog->exec();
  38. */
  39. class SafetyInspectDialog : public QDialog {
  40. Q_OBJECT
  41. public:
  42. struct InspectionRecord {
  43. QString name;
  44. QString phone;
  45. QString confirmTime;
  46. };
  47. explicit SafetyInspectDialog(QWidget *parent = nullptr,
  48. const QMap<QString, QString> &userNameById = QMap<QString, QString>(),
  49. const QString &dateStr = QString());
  50. ~SafetyInspectDialog();
  51. // Set the date to display in header
  52. void setDate(const QString &date);
  53. // Set the inspection records to display in table
  54. void setInspectionRecords(const QList<InspectionRecord> &records);
  55. void onCloseButtonClicked();
  56. private:
  57. void setupUI();
  58. void setupTable();
  59. void populateTable();
  60. QLabel *m_dateLabel;
  61. QTableWidget *m_tableWidget;
  62. QPushButton *m_closeButton;
  63. QString m_currentDate;
  64. QMap<QString, QString> m_userNameById;
  65. QList<InspectionRecord> m_inspectionRecords;
  66. };
  67. #endif // SAFETYINSPECT_H