]> git.sesse.net Git - pkanalytics/blob - players.h
24c10b9843255890f604272bcf7d25cd69e9918b
[pkanalytics] / players.h
1 #ifndef _PLAYERS_H
2 #define _PLAYERS_H 1
3
4 #include <sqlite3.h>
5 #include <QAbstractTableModel>
6 #include <string>
7 #include <vector>
8
9 class PlayersModel : public QAbstractTableModel
10 {
11 public:
12         PlayersModel(sqlite3 *db);
13
14         int rowCount(const QModelIndex &parent) const override
15         {
16                 return players.size();
17         }
18         int columnCount(const QModelIndex &column) const override
19         {
20                 return 2;
21         }
22         QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
23         QVariant data(const QModelIndex &index, int role) const override;
24
25         int get_player_id(unsigned row) const {
26                 return players[row].player_id;
27         }
28
29 private:
30         struct Player {
31                 int player_id;
32                 std::string number;
33                 std::string name;
34         };
35         std::vector<Player> players;
36
37         sqlite3 *db;
38
39         void load_data();
40 };
41
42 #endif  // !defined(_PLAYERS_H)