summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-models/diveimportedmodel.cpp28
-rw-r--r--qt-models/diveimportedmodel.h1
2 files changed, 20 insertions, 9 deletions
diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp
index 504931b85..34c247c0c 100644
--- a/qt-models/diveimportedmodel.cpp
+++ b/qt-models/diveimportedmodel.cpp
@@ -155,22 +155,32 @@ void DiveImportedModel::repopulate(dive_table_t *table, struct dive_site_table *
endResetModel();
}
-// Note: this function is only used from mobile - perhaps move it there or unify.
-void DiveImportedModel::recordDives()
+// Delete non-selected dives
+void DiveImportedModel::deleteDeselected()
{
- if (diveTable->nr == 0)
- // nothing to do, just exit
- return;
-
- // delete non-selected dives
int total = diveTable->nr;
int j = 0;
for (int i = 0; i < total; i++) {
- if (checkStates[i])
+ if (checkStates[i]) {
j++;
- else
+ } else {
+ beginRemoveRows(QModelIndex(), j, j);
delete_dive_from_table(diveTable, j);
+ endRemoveRows();
+ }
}
+ checkStates.resize(diveTable->nr);
+ std::fill(checkStates.begin(), checkStates.end(), true);
+}
+
+// Note: this function is only used from mobile - perhaps move it there or unify.
+void DiveImportedModel::recordDives()
+{
+ if (diveTable->nr == 0)
+ // nothing to do, just exit
+ return;
+
+ deleteDeselected();
// TODO: Might want to let the user select IMPORT_ADD_TO_NEW_TRIP
add_imported_dives(diveTable, nullptr, sitesTable, IMPORT_PREFER_IMPORTED | IMPORT_IS_DOWNLOADED);
diff --git a/qt-models/diveimportedmodel.h b/qt-models/diveimportedmodel.h
index 49cbdf10c..5f2575bce 100644
--- a/qt-models/diveimportedmodel.h
+++ b/qt-models/diveimportedmodel.h
@@ -21,6 +21,7 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const;
Q_INVOKABLE void clearTable();
QHash<int, QByteArray> roleNames() const;
+ void deleteDeselected();
Q_INVOKABLE void recordDives();
Q_INVOKABLE void startDownload();