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 <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-01-08 11:52:12 -02:00 committed by Dirk Hohndel
parent 25323c2717
commit f5f0938d8c
2 changed files with 19 additions and 0 deletions

View file

@ -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;
}

View file

@ -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;