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;
}
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 {