From 756289c7b37c3e77d79b8a26096e678dccc943fa Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 29 May 2023 15:13:43 +0200 Subject: [PATCH] =?utf8?q?Fix=20various=20issues=20with=20setting=20the=20?= =?utf8?q?special=20=E2=80=9Cnone/unknown=E2=80=9D=20formation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- events.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/events.cpp b/events.cpp index 3b072ec..92ca327 100644 --- a/events.cpp +++ b/events.cpp @@ -38,11 +38,12 @@ QVariant EventsModel::data(const QModelIndex &index, int role) const if (role != Qt::DisplayRole) { return QVariant(); } + const Event &e = events[index.row()]; if (index.column() == 0) { - return QString::fromUtf8(format_timestamp(events[index.row()].t)); + return QString::fromUtf8(format_timestamp(e.t)); } else if (index.column() == 1) { - optional player_id = events[index.row()].player_id; - optional formation_id = events[index.row()].formation_id; + optional player_id = e.player_id; + optional formation_id = e.formation_id; if (player_id) { auto p_it = players.find(*player_id); const Player &p = p_it->second; @@ -51,6 +52,8 @@ QVariant EventsModel::data(const QModelIndex &index, int role) const auto f_it = formations.find(*formation_id); const Formation &f = f_it->second; return QString::fromUtf8(f.name); + } else if (e.type == "formation_offense" || e.type == "formation_defense") { + return "(None/unknown)"; } else { return QVariant(); } @@ -166,6 +169,7 @@ unsigned EventsModel::insert_event(uint64_t t, optional player_id, optional Event e; e.t = t; e.player_id = player_id; + e.formation_id = formation_id; e.type = type; events.insert(events.begin() + pos, e); @@ -456,9 +460,9 @@ void EventsModel::set_formation_at(uint64_t t, bool offense, unsigned formation) t = backdate_point; } if (offense) { - insert_event(t, nullopt, formation, "formation_offense"); + insert_event(t, nullopt, formation == 0 ? nullopt : optional{formation}, "formation_offense"); } else { - insert_event(t, nullopt, formation, "formation_defense"); + insert_event(t, nullopt, formation == 0 ? nullopt : optional{formation}, "formation_defense"); } } -- 2.39.2