From b9be739e209c37b9e5396bb885e3c08429d42ce7 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 1 May 2023 13:43:53 +0200 Subject: [PATCH] Move some meaty member functions out-of-line from EventsModel. --- stats.cpp | 81 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/stats.cpp b/stats.cpp index 5124ca3..63676cb 100644 --- a/stats.cpp +++ b/stats.cpp @@ -43,45 +43,8 @@ public: { return 3; } - QVariant headerData(int section, Qt::Orientation orientation, int role) const override - { - if (role != Qt::DisplayRole) { - return QVariant(); - } - if (orientation == Qt::Horizontal) { - if (section == 0) { - return "Time"; - } else if (section == 1) { - return "Player"; - } else { - return "Type"; - } - } else { - return ""; - } - } - - QVariant data(const QModelIndex &index, int role) const override - { - if (role != Qt::DisplayRole) { - return QVariant(); - } - refresh_if_needed(); - if (index.column() == 0) { - return QString::fromUtf8(format_timestamp(events[index.row()].t)); - } else if (index.column() == 1) { - optional player_id = events[index.row()].player_id; - if (player_id) { - const Player &p = players[*player_id]; - return QString::fromUtf8(p.name + " (" + p.number + ")"); - } else { - return QVariant(); - } - } else if (index.column() == 2) { - return QString::fromUtf8(events[index.row()].type); - } - return QVariant(); - } + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + QVariant data(const QModelIndex &index, int role) const override; private: struct Player { @@ -104,6 +67,46 @@ private: void refresh_if_needed() const; }; +QVariant EventsModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) { + return QVariant(); + } + if (orientation == Qt::Horizontal) { + if (section == 0) { + return "Time"; + } else if (section == 1) { + return "Player"; + } else { + return "Type"; + } + } else { + return ""; + } +} + +QVariant EventsModel::data(const QModelIndex &index, int role) const +{ + if (role != Qt::DisplayRole) { + return QVariant(); + } + refresh_if_needed(); + if (index.column() == 0) { + return QString::fromUtf8(format_timestamp(events[index.row()].t)); + } else if (index.column() == 1) { + optional player_id = events[index.row()].player_id; + if (player_id) { + const Player &p = players[*player_id]; + return QString::fromUtf8(p.name + " (" + p.number + ")"); + } else { + return QVariant(); + } + } else if (index.column() == 2) { + return QString::fromUtf8(events[index.row()].type); + } + return QVariant(); +} + void EventsModel::refresh_if_needed() const { if (!stale) { -- 2.39.2