Add helper to remove dive from model

I tried various things to do this from QML but it just doesn't seem to
work at all. So I gave up and instead added a trivial helper function.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-01-29 06:25:13 -08:00
parent 957f03f2a4
commit 9f7ecbb53e
4 changed files with 19 additions and 1 deletions

View file

@ -556,6 +556,11 @@ QString QMLManager::addDive()
return DiveListModel::instance()->startAddDive();
}
void QMLManager::addDiveAborted(int id)
{
DiveListModel::instance()->removeDiveById(id);
}
QString QMLManager::getCurrentPosition()
{
return locationProvider->currentPosition();

View file

@ -77,6 +77,7 @@ public slots:
void saveChanges();
QString addDive();
void addDiveAborted(int id);
void applyGpsData();
void sendGpsData();
void downloadGpsData();

View file

@ -52,6 +52,16 @@ void DiveListModel::removeDive(int i)
endRemoveRows();
}
void DiveListModel::removeDiveById(int id)
{
for (int i = 0; i < rowCount(); i++) {
if (m_dives.at(i)->id() == id) {
removeDive(i);
return;
}
}
}
void DiveListModel::updateDive(int i, dive *d)
{
DiveObjectHelper *newDive = new DiveObjectHelper(d);
@ -125,6 +135,7 @@ DiveListModel *DiveListModel::instance()
return m_instance;
}
DiveObjectHelper* DiveListModel::at(int i){
DiveObjectHelper* DiveListModel::at(int i)
{
return m_dives.at(i);
}

View file

@ -33,6 +33,7 @@ public:
void addDive(dive *d);
void insertDive(int i, DiveObjectHelper *newDive);
void removeDive(int i);
void removeDiveById(int id);
void updateDive(int i, dive *d);
void clear();
int rowCount(const QModelIndex &parent = QModelIndex()) const;