From f5f0938d8cd2193621f0d20d64eb0259c06788bf Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 8 Jan 2015 11:52:12 -0200 Subject: Dive d/l selection UI: Add method to remove unused dives This tries to relete from the dive list the dives that shouldn't be imported. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/downloadfromdivecomputer.cpp | 18 ++++++++++++++++++ qt-ui/downloadfromdivecomputer.h | 1 + 2 files changed, 19 insertions(+) diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index abc6fff91..465d19a42 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -405,6 +405,9 @@ void DownloadFromDCWidget::onDownloadThreadFinished() void DownloadFromDCWidget::on_ok_clicked() { + // remove all unselected dives from the dive-list. + diveImportedModel->removeUnused(); + int uniqId, idx; // remember the last downloaded dive (on most dive computers this will be the chronologically // first new dive) and select it again after processing all the dives @@ -573,3 +576,18 @@ void DiveImportedModel::setImportedDivesIndexes(int first, int last) memset(checkStates, true, last-first); endInsertRows(); } + +void DiveImportedModel::removeUnused() { + beginRemoveRows(QModelIndex(), 0, rowCount()-1); + endRemoveRows(); + + for(int i = lastIndex; i >= firstIndex; i-- ){ + if(!checkStates[firstIndex - i]) { + delete_single_dive(i); + } + } + + lastIndex = 0; + firstIndex = 0; + delete[] checkStates; +} diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h index b567dfe0e..ea272599e 100644 --- a/qt-ui/downloadfromdivecomputer.h +++ b/qt-ui/downloadfromdivecomputer.h @@ -36,6 +36,7 @@ public: bool setData(const QModelIndex &index, const QVariant &value, int role); void setImportedDivesIndexes(int first, int last); Qt::ItemFlags flags(const QModelIndex &index) const; + void removeUnused(); private: int firstIndex; int lastIndex; -- cgit v1.2.3-70-g09d2