From: Steinar H. Gunderson Date: Mon, 1 May 2023 12:50:09 +0000 (+0200) Subject: Add some offense events, now working-ish. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=47bc388b460b87ed7cd8be285f26dfe99c0f3c6a;p=pkanalytics Add some offense events, now working-ish. --- diff --git a/events.cpp b/events.cpp index a08f1c7..414c157 100644 --- a/events.cpp +++ b/events.cpp @@ -138,3 +138,11 @@ int EventsModel::insert_event(uint64_t t, int player_id) return pos; } + +void EventsModel::set_event_type(unsigned pos, const string &type) +{ + events[pos].type = type; + emit dataChanged(createIndex(pos, 0), createIndex(pos, 2)); + + // FIXME sqlite +} diff --git a/events.h b/events.h index 66398d1..e86d02b 100644 --- a/events.h +++ b/events.h @@ -26,6 +26,7 @@ public: QVariant data(const QModelIndex &index, int role) const override; int insert_event(uint64_t t, int player_id); + void set_event_type(unsigned row, const std::string &type); private: struct Player { diff --git a/mainwindow.h b/mainwindow.h index 430b88d..4e7095f 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -17,6 +17,7 @@ public: private: void seek(int64_t delta_ms); + void set_current_event_type(const std::string &type); Ui::MainWindow *ui; EventsModel *model; diff --git a/mainwindow.ui b/mainwindow.ui index b544286..91ef5e5 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -233,6 +233,9 @@ Pull (&p) + + P, Return + @@ -240,6 +243,9 @@ Catch/take (&c) + + C + @@ -257,17 +263,23 @@ - + Soft plus (&+) + + - + - + Soft minus (&-) + + + + @@ -275,6 +287,9 @@ Drop (&x) + + X + @@ -282,6 +297,9 @@ Goal (&g) + + G + diff --git a/stats.cpp b/stats.cpp index c8f0be5..9d62124 100644 --- a/stats.cpp +++ b/stats.cpp @@ -99,6 +99,16 @@ MainWindow::MainWindow() connect(ui->player_7, &QPushButton::clicked, [this]() { ui->event_view->selectRow(model->insert_event(player->position(), 7)); }); + + // TODO: disable if nothing is selected + connect(ui->catch_, &QPushButton::clicked, [this]() { set_current_event_type("catch"); }); + connect(ui->throwaway, &QPushButton::clicked, [this]() { set_current_event_type("throwaway"); }); + connect(ui->drop, &QPushButton::clicked, [this]() { set_current_event_type("drop"); }); + connect(ui->goal, &QPushButton::clicked, [this]() { set_current_event_type("goal"); }); + connect(ui->offensive_soft_plus, &QPushButton::clicked, [this]() { set_current_event_type("offensive_soft_plus"); }); + connect(ui->offensive_soft_minus, &QPushButton::clicked, [this]() { set_current_event_type("offensive_soft_minus"); }); + connect(ui->pull, &QPushButton::clicked, [this]() { set_current_event_type("pull"); }); + connect(ui->pull_landed, &QPushButton::clicked, [this]() { set_current_event_type("pull_landed"); }); } void MainWindow::setModel(EventsModel *model) @@ -118,6 +128,16 @@ void MainWindow::seek(int64_t delta_ms) } } +void MainWindow::set_current_event_type(const string &type) +{ + QItemSelectionModel *select = ui->event_view->selectionModel(); + if (!select->hasSelection()) { + return; + } + int row = select->selectedRows().front().row(); // Should only be one, due to our selection behavior. + model->set_event_type(row, type); +} + sqlite3 *open_db(const char *filename) { sqlite3 *db;