+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<int> 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();
+}
+