mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Import: keep model state consistent when deleting unselected dives
In DiveImportedModel::deleteDeselected(), unselected dives were deleted from the dive-table. But this left the model in an inconsistent state and the frontend was not informed of the missing dives. Fix this by invoking the appropriate beginRemoveRows()/ endRemoveRows() pairs. Move the functionality into its own function so that it can be reused by the desktop version. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
ad7ffa0af0
commit
30b384cebd
2 changed files with 20 additions and 9 deletions
|
@ -155,6 +155,24 @@ void DiveImportedModel::repopulate(dive_table_t *table, struct dive_site_table *
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete non-selected dives
|
||||||
|
void DiveImportedModel::deleteDeselected()
|
||||||
|
{
|
||||||
|
int total = diveTable->nr;
|
||||||
|
int j = 0;
|
||||||
|
for (int i = 0; i < total; i++) {
|
||||||
|
if (checkStates[i]) {
|
||||||
|
j++;
|
||||||
|
} 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.
|
// Note: this function is only used from mobile - perhaps move it there or unify.
|
||||||
void DiveImportedModel::recordDives()
|
void DiveImportedModel::recordDives()
|
||||||
{
|
{
|
||||||
|
@ -162,15 +180,7 @@ void DiveImportedModel::recordDives()
|
||||||
// nothing to do, just exit
|
// nothing to do, just exit
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// delete non-selected dives
|
deleteDeselected();
|
||||||
int total = diveTable->nr;
|
|
||||||
int j = 0;
|
|
||||||
for (int i = 0; i < total; i++) {
|
|
||||||
if (checkStates[i])
|
|
||||||
j++;
|
|
||||||
else
|
|
||||||
delete_dive_from_table(diveTable, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Might want to let the user select IMPORT_ADD_TO_NEW_TRIP
|
// 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);
|
add_imported_dives(diveTable, nullptr, sitesTable, IMPORT_PREFER_IMPORTED | IMPORT_IS_DOWNLOADED);
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
Q_INVOKABLE void clearTable();
|
Q_INVOKABLE void clearTable();
|
||||||
QHash<int, QByteArray> roleNames() const;
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
void deleteDeselected();
|
||||||
Q_INVOKABLE void recordDives();
|
Q_INVOKABLE void recordDives();
|
||||||
Q_INVOKABLE void startDownload();
|
Q_INVOKABLE void startDownload();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue