#include <optional>
#include <sqlite3.h>
#include "mainwindow.h"
+#include "edit_player_dialog.h"
#include "ui_mainwindow.h"
#include "events.h"
#include "players.h"
if (s.attack_state == EventsModel::Status::DEFENSE && s.pull_state == EventsModel::Status::PULL_IN_AIR) {
insert_noplayer_event("pull_oob");
} else {
- set_current_event_type("throwaway");
+ insert_throwaway();
}
});
connect(ui->drop, &QPushButton::clicked, [this] { set_current_event_type("drop"); });
connect(ui->clear_player_list, &QPushButton::clicked, [this] {
ui->player_view->selectionModel()->clear();
});
+ connect(ui->player_view, &QTableView::doubleClicked, [this](const QModelIndex &index) {
+ open_edit_player_dialog(index.row());
+ });
connect(ui->player_view->selectionModel(), &QItemSelectionModel::selectionChanged, [this] {
update_gender_ratio(ui->video->get_position());
});
update_ui_from_time(ui->video->get_position());
}
+void MainWindow::insert_throwaway()
+{
+ uint64_t t = ui->video->get_position();
+
+ QItemSelectionModel *select = ui->event_view->selectionModel();
+ if (select->hasSelection()) {
+ int row = select->selectedRows().front().row(); // Should only be one, due to our selection behavior.
+ // We could want to modify this catch event into a throwaway. See if that is the case.
+ int last_catching_player = events->get_status_at(events->get_time(row) - 1).last_catching_player;
+ if (last_catching_player != -1 && last_catching_player == events->get_player_id(row)) {
+ // Last event was that this player caught the disc, so yes, make this a throwaway.
+ events->set_event_type(row, "throwaway");
+ update_ui_from_time(t);
+ return;
+ }
+ // It doesn't make sense that the player throws it away without holding the disc first,
+ // so we insert a new event where the person holding the disc throws it away.
+ // (In other words, fall back to inserting a new one based on time.)
+ }
+
+ int last_catching_player = events->get_status_at(t - 1).last_catching_player;
+ if (last_catching_player == -1) {
+ return;
+ }
+
+ ui->event_view->selectionModel()->blockSignals(true);
+ ui->event_view->selectRow(events->insert_event(t, last_catching_player, nullopt, "throwaway"));
+ ui->event_view->selectionModel()->blockSignals(false);
+}
+
// Formation buttons either modify the existing formation (if we've selected
// a formation change event), or insert a new one (if not).
void MainWindow::insert_or_change_formation(bool offense)
ui->pull_or_was_d->setEnabled(true);
ui->catch_->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player);
- ui->throwaway->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player);
+ ui->throwaway->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && s.last_catching_player != -1);
ui->drop->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player);
ui->goal->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player);
ui->stallout->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player);
EventType type = events->get_event_type(row);
if (type == EventType::GOAL || type == EventType::THEIR_GOAL) {
historical_gender_counts.push_back(current_gender_count);
- } else if (type == EventType::IN) {
+ } else if (type == EventType::SWAP_IN) {
string gender = players->get_player_gender_by_id(*events->get_player_id(row));
++current_gender_count[gender];
- } else if (type == EventType::OUT) {
+ } else if (type == EventType::SWAP_OUT) {
string gender = players->get_player_gender_by_id(*events->get_player_id(row));
--current_gender_count[gender];
}
update_ui_from_time(ui->video->get_position());
}
+void MainWindow::open_edit_player_dialog(unsigned row)
+{
+ int player_id = players->get_player_id(row);
+ string number = players->get_player_number(row);
+ string gender = players->get_player_gender(row);
+ string name = players->get_player_name(row);
+
+ EditPlayerDialog *dialog = new EditPlayerDialog(number, gender, name);
+ connect(dialog, &QDialog::finished, [this, dialog, player_id](int result) {
+ if (result == QDialog::Accepted) {
+ players->edit_player(player_id, dialog->number(), dialog->gender(), dialog->name());
+ update_ui_from_time(ui->video->get_position());
+ }
+ });
+ dialog->show();
+}