studentmodel.h 2.0 KB

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