#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "events.h"
+#include "players.h"
using namespace std;
return buf;
}
-MainWindow::MainWindow(EventsModel *events) : events(events)
+MainWindow::MainWindow(EventsModel *events, PlayersModel *players) : events(events), players(players)
{
player = new QMediaPlayer;
//player->setSource(QUrl::fromLocalFile("/home/sesse/dev/stats/ultimate.mkv"));
player->setPosition(events->get_time(current.row()));
});
+ ui->player_view->setModel(players);
+
connect(player, &QMediaPlayer::positionChanged, [this](uint64_t pos) {
position_changed(pos);
});
QApplication app(argc, argv);
sqlite3 *db = open_db("ultimate.db");
- MainWindow mainWindow(new EventsModel(db));
+ MainWindow mainWindow(new EventsModel(db), new PlayersModel(db));
mainWindow.resize(QSize(1280, 720));
mainWindow.show();
#include "ui_mainwindow.h"
class EventsModel;
+class PlayersModel;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
- MainWindow(EventsModel *events);
+ MainWindow(EventsModel *events, PlayersModel *players);
private:
void position_changed(uint64_t pos);
Ui::MainWindow *ui;
EventsModel *events;
+ PlayersModel *players;
bool seeking = false;
bool playing = true;
std::optional<uint64_t> buffered_seek;
<x>0</x>
<y>0</y>
<width>1031</width>
- <height>713</height>
+ <height>754</height>
</rect>
</property>
<property name="windowTitle">
</widget>
</item>
<item row="0" column="1">
- <layout class="QVBoxLayout" name="buttons">
- <item>
- <spacer name="verticalSpacer_2">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
+ <layout class="QVBoxLayout" name="buttons" stretch="0,0,0,0,0,0,0,0">
<item>
<layout class="QGridLayout" name="player_grid">
<item row="3" column="0" colspan="2">
</layout>
</item>
<item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
+ <widget class="QTableView" name="player_view">
+ <property name="selectionMode">
+ <enum>QAbstractItemView::MultiSelection</enum>
</property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectRows</enum>
</property>
- </spacer>
+ </widget>
</item>
</layout>
</item>
ui_files: ['mainwindow.ui'],
dependencies: qt6deps)
-executable('stats', ['main.cpp', 'events.cpp'], qt_files, dependencies: [qt6deps, sqlite3dep])
+executable('stats', ['main.cpp', 'events.cpp', 'players.cpp'], qt_files, dependencies: [qt6deps, sqlite3dep])
--- /dev/null
+#include <algorithm>
+#include <string>
+#include <vector>
+#include <sqlite3.h>
+#include "players.h"
+
+using namespace std;
+
+string format_timestamp(uint64_t pos);
+
+PlayersModel::PlayersModel(sqlite3 *db) : db(db)
+{
+ load_data();
+}
+
+QVariant PlayersModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role != Qt::DisplayRole) {
+ return QVariant();
+ }
+ if (orientation == Qt::Horizontal) {
+ if (section == 0) {
+ return "#";
+ } else if (section == 1) {
+ return "Name";
+ } else {
+ return QVariant();
+ }
+ } else {
+ return "";
+ }
+}
+
+QVariant PlayersModel::data(const QModelIndex &index, int role) const
+{
+ if (role != Qt::DisplayRole) {
+ return QVariant();
+ }
+ if (index.column() == 0) {
+ return QString::fromUtf8(players[index.row()].number);
+ } else if (index.column() == 1) {
+ return QString::fromUtf8(players[index.row()].name);
+ }
+ return QVariant();
+}
+
+void PlayersModel::load_data()
+{
+ players.clear();
+
+ // Read the players.
+ sqlite3_stmt *stmt;
+ int ret = sqlite3_prepare_v2(db, "SELECT player, number, name FROM player ORDER BY (number+0), number", -1, &stmt, 0);
+ if (ret != SQLITE_OK) {
+ fprintf(stderr, "SELECT prepare: %s\n", sqlite3_errmsg(db));
+ abort();
+ }
+ for ( ;; ) {
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ROW) {
+ Player p;
+ p.player_id = sqlite3_column_int(stmt, 0);
+ p.number = (const char *)sqlite3_column_text(stmt, 1);
+ p.name = (const char *) sqlite3_column_text(stmt, 2);
+ players.push_back(p);
+ } else if (ret == SQLITE_DONE) {
+ break;
+ } else {
+ fprintf(stderr, "SELECT step: %s\n", sqlite3_errmsg(db));
+ abort();
+ }
+ }
+ ret = sqlite3_finalize(stmt);
+ if (ret != SQLITE_OK) {
+ fprintf(stderr, "SELECT finalize: %s\n", sqlite3_errmsg(db));
+ abort();
+ }
+}
--- /dev/null
+#ifndef _PLAYERS_H
+#define _PLAYERS_H 1
+
+#include <sqlite3.h>
+#include <QAbstractTableModel>
+#include <string>
+#include <vector>
+
+class PlayersModel : public QAbstractTableModel
+{
+public:
+ PlayersModel(sqlite3 *db);
+
+ int rowCount(const QModelIndex &parent) const override
+ {
+ return players.size();
+ }
+ int columnCount(const QModelIndex &column) const override
+ {
+ return 2;
+ }
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+
+// Player get_player(int player_id) const;
+
+private:
+ struct Player {
+ int player_id;
+ std::string number;
+ std::string name;
+ };
+ std::vector<Player> players;
+
+ sqlite3 *db;
+
+ void load_data();
+};
+
+#endif // !defined(_PLAYERS_H)