From 0408d6ff8fb94467c25b6bde780807a32a77e6e6 Mon Sep 17 00:00:00 2001 From: Michael Morgan <84428382+aa5sh@users.noreply.github.com> Date: Sat, 18 Jul 2026 22:06:13 -0500 Subject: [PATCH] Add ability to clear selected alerts Add a new feature to clear individual selected alerts from the alert table. Changed selection mode from SingleSelection to ExtendedSelection to allow multiple row selection, added a new 'Clear Selected' action, and renamed existing 'Clear' actions to 'Clear All' for clarity. --- models/AlertTableModel.cpp | 21 +++++++++++++++++++++ models/AlertTableModel.h | 1 + ui/AlertWidget.cpp | 18 ++++++++++++++++++ ui/AlertWidget.h | 1 + ui/AlertWidget.ui | 26 ++++++++++++++++++++++++-- ui/MainWindow.ui | 2 +- 6 files changed, 66 insertions(+), 3 deletions(-) diff --git a/models/AlertTableModel.cpp b/models/AlertTableModel.cpp index 030548af..54892521 100644 --- a/models/AlertTableModel.cpp +++ b/models/AlertTableModel.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include "AlertTableModel.h" #include "data/Data.h" @@ -127,6 +129,25 @@ void AlertTableModel::clear() endResetModel(); } +void AlertTableModel::clearRows(const QList &rows) +{ + QList selectedRows = rows; + + std::sort(selectedRows.begin(), selectedRows.end(), std::greater()); + selectedRows.erase(std::unique(selectedRows.begin(), selectedRows.end()), selectedRows.end()); + + QMutexLocker locker(&alertListMutex); + for ( const int row : selectedRows ) + { + if ( row < 0 || row >= alertList.count() ) + continue; + + beginRemoveRows(QModelIndex(), row, row); + alertList.removeAt(row); + endRemoveRows(); + } +} + const AlertTableModel::AlertTableRecord AlertTableModel::getTableRecord(const QModelIndex &index) { QMutexLocker locker(&alertListMutex); diff --git a/models/AlertTableModel.h b/models/AlertTableModel.h index bab7a6fb..0bcbc083 100644 --- a/models/AlertTableModel.h +++ b/models/AlertTableModel.h @@ -44,6 +44,7 @@ class AlertTableModel : public QAbstractTableModel QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; void addAlert(const SpotAlert &entry); void clear(); + void clearRows(const QList &rows); const AlertTableRecord getTableRecord(const QModelIndex& index); void aging(const int clear_interval_sec); void resetDupe(); diff --git a/ui/AlertWidget.cpp b/ui/AlertWidget.cpp index 5b894872..f86080bd 100644 --- a/ui/AlertWidget.cpp +++ b/ui/AlertWidget.cpp @@ -29,6 +29,7 @@ AlertWidget::AlertWidget(QWidget *parent) : ui->alertTableView->addAction(ui->actionEditRules); ui->alertTableView->addAction(ui->actionColumnVisibility); + ui->alertTableView->addAction(ui->actionClearSelected); ui->alertTableView->addAction(ui->actionClear); restoreTableHeaderState(); @@ -69,6 +70,23 @@ void AlertWidget::clearAllAlerts() emit alertsCleared(); } +void AlertWidget::clearSelectedAlerts() +{ + FCT_IDENTIFICATION; + + const QModelIndexList selectedRows = ui->alertTableView->selectionModel()->selectedRows(); + QList sourceRows; + + for ( const QModelIndex &index : selectedRows ) + sourceRows << proxyModel->mapToSource(index).row(); + + if ( sourceRows.isEmpty() ) + return; + + alertTableModel->clearRows(sourceRows); + emit alertsCleared(); +} + void AlertWidget::entryDoubleClicked(QModelIndex index) { FCT_IDENTIFICATION; diff --git a/ui/AlertWidget.h b/ui/AlertWidget.h index d9a119b4..a29ec0a5 100644 --- a/ui/AlertWidget.h +++ b/ui/AlertWidget.h @@ -25,6 +25,7 @@ class AlertWidget : public QWidget, public ShutdownAwareWidget public slots: void addAlert(const SpotAlert &alert); void clearAllAlerts(); + void clearSelectedAlerts(); void entryDoubleClicked(QModelIndex index); void alertAgingChanged(int); void showEditRules(); diff --git a/ui/AlertWidget.ui b/ui/AlertWidget.ui index c9a67eee..df060e69 100644 --- a/ui/AlertWidget.ui +++ b/ui/AlertWidget.ui @@ -50,7 +50,7 @@ true - QAbstractItemView::SingleSelection + QAbstractItemView::ExtendedSelection QAbstractItemView::SelectRows @@ -129,9 +129,14 @@ Column Visibility... + + + Clear Selected + + - Clear + Clear All @@ -201,6 +206,22 @@ + + actionClearSelected + triggered() + AlertWidget + clearSelectedAlerts() + + + -1 + -1 + + + 386 + 162 + + + actionClear triggered() @@ -220,6 +241,7 @@ clearAllAlerts() + clearSelectedAlerts() entryDoubleClicked(QModelIndex) alertAgingChanged(int) showEditRules() diff --git a/ui/MainWindow.ui b/ui/MainWindow.ui index 59a69f2b..a135a475 100644 --- a/ui/MainWindow.ui +++ b/ui/MainWindow.ui @@ -928,7 +928,7 @@ - Clear + Clear All QAction::NoRole