]> git.sesse.net Git - pkanalytics/blobdiff - formations.h
Add a menu.
[pkanalytics] / formations.h
index 5eda723964d268bc35a1ea3eedb90a61f23f0b3c..efc87feaa34bfc3b520b7c9d73327d43c6967947 100644 (file)
@@ -18,6 +18,8 @@ public:
        QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
        QVariant data(const QModelIndex &index, int role) const override;
 
+       unsigned insert_new(const std::string &name);  // Returns the new ID.
+
        int get_formation_id(unsigned row) const {
                if (row == 0) {
                        return 0;
@@ -27,7 +29,22 @@ public:
                }
                return formations[row - 1].formation_id;
        }
-       std::string get_formation_name_by_id(unsigned formation_id);
+       std::string get_formation_name_by_id(unsigned formation_id) {
+               for (unsigned i = 0; i < formations.size(); ++i) {
+                       if (formations[i].formation_id == int(formation_id)) {
+                               return formations[i].name;
+                       }
+               }
+               abort();
+       }
+       unsigned get_row_from_id(unsigned formation_id) {
+               for (unsigned i = 0; i < formations.size(); ++i) {
+                       if (formations[i].formation_id == int(formation_id)) {
+                               return i + 1;
+                       }
+               }
+               abort();
+       }
 
 private:
        struct Formation {