diff options
| author | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
| commit | ffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch) | |
| tree | 1269efa852935b183daae4bb33a58d1b4d2ffb53 /widgets/AbstractLogWindow.cpp | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'widgets/AbstractLogWindow.cpp')
| -rw-r--r-- | widgets/AbstractLogWindow.cpp | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/widgets/AbstractLogWindow.cpp b/widgets/AbstractLogWindow.cpp index 667573ce..284fc34f 100644 --- a/widgets/AbstractLogWindow.cpp +++ b/widgets/AbstractLogWindow.cpp @@ -11,6 +11,8 @@ #include <QItemSelectionModel> #include <QItemSelection> #include <QTimer> +#include <QSet> +#include <QVector> #include "Configuration.hpp" #include "SettingsGroup.hpp" #include "MessageBox.hpp" @@ -46,46 +48,55 @@ public: #include "moc_AbstractLogWindow.cpp" #include "AbstractLogWindow.moc" -namespace -{ - bool row_is_higher (QModelIndex const& lhs, QModelIndex const& rhs) - { - return lhs.row () > rhs.row (); - } -} - void AbstractLogWindow::impl::delete_QSOs () { auto selection_model = log_view_->selectionModel (); selection_model->select (selection_model->selection (), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); auto row_indexes = selection_model->selectedRows (); + QSet<qlonglong> record_ids; + record_ids.reserve (row_indexes.size ()); + for (auto const& row_index : row_indexes) + { + record_ids.insert (row_index.sibling (row_index.row (), 0) + .data (Qt::EditRole).toLongLong ()); + } - if (row_indexes.size () + if (record_ids.size () && MessageBox::Yes == MessageBox::query_message (self_ , tr ("Confirm Delete") , tr ("Are you sure you want to delete the %n " "selected QSO(s) from the log?", "" - , row_indexes.size ()) + , record_ids.size ()) , QString {} , MessageBox::Yes | MessageBox::No , MessageBox::No)) { - // We must work with source model indexes because we don't want row - // removes to invalidate model indexes we haven't yet processed. We - // achieve that by processing them in descending row order. - for (auto& row_index : row_indexes) + // Logging can refresh the model and reset its fetched rows during confirmation. + auto source_model = model_.sourceModel (); + while (source_model->canFetchMore (QModelIndex {})) { - row_index = model_.mapToSource (row_index); + source_model->fetchMore (QModelIndex {}); } - - // reverse sort by row - std::sort (row_indexes.begin (), row_indexes.end (), row_is_higher); - - for (auto index : row_indexes) + QVector<int> rows; + for (auto row = 0; row < model_.rowCount (); ++row) + { + auto const id = model_.index (row, 0).data (Qt::EditRole).toLongLong (); + if (record_ids.contains (id)) + { + rows.push_back (row); + } + } + std::sort (rows.begin (), rows.end (), [] (int lhs, int rhs) { + return lhs > rhs; + }); + bool removed = false; + for (auto row : rows) + { + removed = model_.removeRow (row) || removed; + } + if (removed) { - auto row = model_.mapFromSource(index).row(); - model_.removeRow(row); - self_->log_model_changed(); + self_->log_model_changed (); } } } |
