| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #ifndef EXAMSMODEL_H
- #define EXAMSMODEL_H
- #include <QAbstractTableModel >
- #include <QObject>
- class ExamsTableModel : public QAbstractTableModel
- {
- Q_OBJECT
- public:
- explicit ExamsTableModel(QObject *parent = nullptr);
- struct Exams
- {
- qint64 id;
- QString name;
- QString fileDir;
- bool select;
- int maxTime; // 最大完成时间
- };
- // 加载 JSON 数据
- void loadJsonData(const QJsonArray &jsonArray);
- Exams getCurrentExam(const QModelIndex &index) const
- {
- if (index.isValid() && index.row() < examsList.size()) {
- return examsList.at(index.row());
- }
- return Exams(); // 如果索引无效或者超出范围,返回一个空的 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;
- private:
- QList<Exams> examsList;
- };
- #endif // EXAMSMODEL_H
|