gradsmodel.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef GRADSTABLEMODEL_H
  2. #define GRADSTABLEMODEL_H
  3. #include <QAbstractTableModel>
  4. #include <QObject>
  5. class GradsTableModel : public QAbstractTableModel
  6. {
  7. Q_OBJECT
  8. public:
  9. explicit GradsTableModel(QObject *parent = nullptr);
  10. enum columnRole {
  11. NAME, // 姓名
  12. SWID, // SW_ID
  13. EXAMINEENUMBER, // 考试编号
  14. EXAMNAME, // 考试内容
  15. CHECKINNUMBER, // 签到号
  16. GROUPNAME, // 组别
  17. ANSWERTIME, // 完成时间
  18. ANSWERFILENAME, // 文件名
  19. SCHOOL, // 学校
  20. EXAM_ROOM, // 考试教师
  21. EXAM_SESSIONS, // 考试场次
  22. COLUMNSIZE
  23. };
  24. struct Student
  25. {
  26. QString name; // 姓名
  27. QString swID; // SW_ID
  28. QString examineeNumber; // 考试编号
  29. QString examName; // 考试内容
  30. QString checkinNumber; // 签到号
  31. QString groupName; // 组别
  32. int answerTime; // 完成时间
  33. QString answerFileName; // 文件名
  34. QString school; // 学校
  35. QString exam_room; // 考试教师
  36. QString exam_sessions; // 考试场次
  37. };
  38. // 加载 JSON 数据
  39. void loadJsonData(const QJsonArray &jsonArray);
  40. Student getCurrentStudent(const QModelIndex &index) const
  41. {
  42. if (index.isValid() && index.row() < students.size()) {
  43. return students.at(index.row());
  44. }
  45. return Student(); // 如果索引无效或者超出范围,返回一个空的 Exams 结构
  46. }
  47. protected:
  48. // 返回行数
  49. int rowCount(const QModelIndex &parent = QModelIndex()) const override;
  50. // 返回列数
  51. int columnCount(const QModelIndex &parent = QModelIndex()) const override;
  52. // 返回数据
  53. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
  54. // 设置表头
  55. QVariant headerData(int section,
  56. Qt::Orientation orientation,
  57. int role = Qt::DisplayRole) const override;
  58. Qt::ItemFlags flags(const QModelIndex &index) const override;
  59. private:
  60. QList<Student> students;
  61. };
  62. #endif // GRADSTABLEMODEL_H