Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions models/AlertTableModel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <QColor>
#include <QSqlRecord>
#include <algorithm>
#include <functional>

#include "AlertTableModel.h"
#include "data/Data.h"
Expand Down Expand Up @@ -127,6 +129,25 @@ void AlertTableModel::clear()
endResetModel();
}

void AlertTableModel::clearRows(const QList<int> &rows)
{
QList<int> selectedRows = rows;

std::sort(selectedRows.begin(), selectedRows.end(), std::greater<int>());
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);
Expand Down
1 change: 1 addition & 0 deletions models/AlertTableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> &rows);
const AlertTableRecord getTableRecord(const QModelIndex& index);
void aging(const int clear_interval_sec);
void resetDupe();
Expand Down
18 changes: 18 additions & 0 deletions ui/AlertWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -69,6 +70,23 @@ void AlertWidget::clearAllAlerts()
emit alertsCleared();
}

void AlertWidget::clearSelectedAlerts()
{
FCT_IDENTIFICATION;

const QModelIndexList selectedRows = ui->alertTableView->selectionModel()->selectedRows();
QList<int> 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;
Expand Down
1 change: 1 addition & 0 deletions ui/AlertWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 24 additions & 2 deletions ui/AlertWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
Expand Down Expand Up @@ -129,9 +129,14 @@
<string>Column Visibility...</string>
</property>
</action>
<action name="actionClearSelected">
<property name="text">
<string>Clear Selected</string>
</property>
</action>
<action name="actionClear">
<property name="text">
<string>Clear</string>
<string>Clear All</string>
</property>
</action>
</widget>
Expand Down Expand Up @@ -201,6 +206,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>actionClearSelected</sender>
<signal>triggered()</signal>
<receiver>AlertWidget</receiver>
<slot>clearSelectedAlerts()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>386</x>
<y>162</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionClear</sender>
<signal>triggered()</signal>
Expand All @@ -220,6 +241,7 @@
</connections>
<slots>
<slot>clearAllAlerts()</slot>
<slot>clearSelectedAlerts()</slot>
<slot>entryDoubleClicked(QModelIndex)</slot>
<slot>alertAgingChanged(int)</slot>
<slot>showEditRules()</slot>
Expand Down
2 changes: 1 addition & 1 deletion ui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@
</action>
<action name="actionClearAlerts">
<property name="text">
<string>Clear</string>
<string>Clear All</string>
</property>
<property name="menuRole">
<enum>QAction::NoRole</enum>
Expand Down