]> git.sesse.net Git - pkanalytics/blob - formations.h
5eda723964d268bc35a1ea3eedb90a61f23f0b3c
[pkanalytics] / formations.h
1 #ifndef _FORMATIONS_H
2 #define _FORMATIONS_H 1
3
4 #include <sqlite3.h>
5 #include <QAbstractListModel>
6 #include <string>
7 #include <vector>
8
9 class FormationsModel : public QAbstractListModel
10 {
11 public:
12         FormationsModel(sqlite3 *db, bool offense);
13
14         int rowCount(const QModelIndex &parent) const override
15         {
16                 return formations.size() + 2;
17         }
18         QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
19         QVariant data(const QModelIndex &index, int role) const override;
20
21         int get_formation_id(unsigned row) const {
22                 if (row == 0) {
23                         return 0;
24                 }
25                 if (row == formations.size() + 1) {
26                         return -1;
27                 }
28                 return formations[row - 1].formation_id;
29         }
30         std::string get_formation_name_by_id(unsigned formation_id);
31
32 private:
33         struct Formation {
34                 int formation_id;
35                 std::string name;
36         };
37         std::vector<Formation> formations;
38
39         sqlite3 *db;
40         bool offense;
41
42         void load_data();
43 };
44
45 #endif  // !defined(_FORMATIONS_H)