2 #define _FORMATIONS_H 1
5 #include <QAbstractListModel>
9 class FormationsModel : public QAbstractListModel
12 FormationsModel(sqlite3 *db, bool offense);
14 int rowCount(const QModelIndex &parent) const override
16 return formations.size() + 2;
18 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
19 QVariant data(const QModelIndex &index, int role) const override;
21 unsigned insert_new(const std::string &name); // Returns the new ID.
23 int get_formation_id(unsigned row) const {
27 if (row == formations.size() + 1) {
30 return formations[row - 1].formation_id;
32 std::string get_formation_name_by_id(unsigned formation_id) {
33 for (unsigned i = 0; i < formations.size(); ++i) {
34 if (formations[i].formation_id == int(formation_id)) {
35 return formations[i].name;
40 unsigned get_row_from_id(unsigned formation_id) {
41 for (unsigned i = 0; i < formations.size(); ++i) {
42 if (formations[i].formation_id == int(formation_id)) {
54 std::vector<Formation> formations;
62 #endif // !defined(_FORMATIONS_H)