| 13 | } |
| 14 | |
| 15 | QVariant SampleModel::data(const QModelIndex &index, int role) const |
| 16 | { |
| 17 | if (!index.isValid()) |
| 18 | return QVariant(); |
| 19 | if (index.row() < 0 || index.row() > _data.count() - 1) |
| 20 | return QVariant(); |
| 21 | |
| 22 | auto row = _data.at(index.row()); |
| 23 | |
| 24 | switch (role) { |
| 25 | case IdRole: |
| 26 | return index.row(); |
| 27 | |
| 28 | case NameRole: |
| 29 | return row.first; |
| 30 | |
| 31 | case GradeRole: |
| 32 | return row.second; |
| 33 | } |
| 34 | |
| 35 | return QVariant(); |
| 36 | } |
| 37 | |
| 38 | QHash<int, QByteArray> SampleModel::roleNames() const |
| 39 | { |