]> git.sesse.net Git - pkanalytics/blobdiff - stats.cpp
Make it possible to delete events.
[pkanalytics] / stats.cpp
index 6a96266a217806839237cd4ded48047266fd29c9..437e0eefad815100c8158a902b6752ea092b5a25 100644 (file)
--- a/stats.cpp
+++ b/stats.cpp
@@ -109,6 +109,10 @@ MainWindow::MainWindow()
        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"); });
+
+       QShortcut *key_delete = new QShortcut(QKeySequence(Qt::Key_Delete), this);
+       connect(key_delete, &QShortcut::activated, [this]() { ui->delete_->animateClick(); });
+       connect(ui->delete_, &QPushButton::clicked, [this]() { delete_current_event(); });
 }
 
 void MainWindow::setModel(EventsModel *model)
@@ -138,6 +142,16 @@ void MainWindow::set_current_event_type(const string &type)
        model->set_event_type(row, type);
 }
 
+void MainWindow::delete_current_event()
+{
+       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->delete_event(row);
+}
+
 sqlite3 *open_db(const char *filename)
 {
        sqlite3 *db;