| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #ifndef GRADSTABLEMODEL_H
- #define GRADSTABLEMODEL_H
- #include <QAbstractTableModel>
- #include <QObject>
- class GradsTableModel : public QAbstractTableModel
- {
- Q_OBJECT
- public:
- explicit GradsTableModel(QObject *parent = nullptr);
- enum columnRole {
- NAME, // 姓名
- SWID, // SW_ID
- EXAMINEENUMBER, // 考试编号
- EXAMNAME, // 考试内容
- CHECKINNUMBER, // 签到号
- GROUPNAME, // 组别
- ANSWERTIME, // 完成时间
- ANSWERFILENAME, // 文件名
- SCHOOL, // 学校
- EXAM_ROOM, // 考试教师
- EXAM_SESSIONS, // 考试场次
- COLUMNSIZE
- };
- struct Student
- {
- QString name; // 姓名
- QString swID; // SW_ID
- QString examineeNumber; // 考试编号
- QString examName; // 考试内容
- QString checkinNumber; // 签到号
- QString groupName; // 组别
- int answerTime; // 完成时间
- QString answerFileName; // 文件名
- QString school; // 学校
- QString exam_room; // 考试教师
- QString exam_sessions; // 考试场次
- };
- // 加载 JSON 数据
- void loadJsonData(const QJsonArray &jsonArray);
- Student getCurrentStudent(const QModelIndex &index) const
- {
- if (index.isValid() && index.row() < students.size()) {
- return students.at(index.row());
- }
- return Student(); // 如果索引无效或者超出范围,返回一个空的 Exams 结构
- }
- protected:
- // 返回行数
- int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- // 返回列数
- int columnCount(const QModelIndex &parent = QModelIndex()) const override;
- // 返回数据
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
- // 设置表头
- QVariant headerData(int section,
- Qt::Orientation orientation,
- int role = Qt::DisplayRole) const override;
- Qt::ItemFlags flags(const QModelIndex &index) const override;
- private:
- QList<Student> students;
- };
- #endif // GRADSTABLEMODEL_H
|