6 #include <QAbstractTableModel>
12 class EventsModel : public QAbstractTableModel
15 EventsModel(sqlite3 *db, int match_id);
17 int rowCount(const QModelIndex &parent) const override
21 int columnCount(const QModelIndex &column) const override
25 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
26 QVariant data(const QModelIndex &index, int role) const override;
28 unsigned insert_event(uint64_t t, std::optional<int> player_id, std::optional<int> formation_id, const std::string &type = "unknown"); // Returns the row.
29 void delete_event(unsigned row);
30 void set_event_type(unsigned row, const std::string &type);
31 uint64_t get_time(unsigned row) { return events[row].t; }
32 unsigned get_last_event_pos(uint64_t t) const; // Last event that happened at or before t.
33 QModelIndex get_last_event_qt(uint64_t t) const {
34 return createIndex(get_last_event_pos(t), 0);
36 std::optional<int> get_player_id(unsigned row) { return events[row].player_id; }
39 unsigned our_score, their_score;
40 enum { NOT_STARTED, OFFENSE, DEFENSE } attack_state;
41 unsigned offensive_formation, defensive_formation;
43 enum { NOT_PULLING, SHOULD_PULL, PULL_IN_AIR } pull_state;
45 unsigned possession_sec;
46 unsigned stoppage_sec;
48 Status get_status_at(uint64_t t);
49 std::set<int> get_team_at(uint64_t t);
50 void set_team_at(uint64_t, const std::set<int> &new_team);
51 std::vector<int> sort_team(const std::set<int> &team) const; // Ordered first by gender, then by number.
52 void set_formation_at(uint64_t t, bool offense, unsigned formation);
54 // Used to notify when we've inserted a new one into the database.
55 void inserted_new_formation(int formation_id, const std::string &name) {
56 formations[formation_id] = Formation{ formation_id, name };
65 std::map<int, Player> players;
66 std::map<int, int> player_ordering; // From id to position.
72 std::map<int, Formation> formations;
77 std::optional<int> player_id;
78 std::optional<int> formation_id;
81 std::vector<Event> events;
89 #endif // !defined(_EVENTS_H)