Simplify model handling and crashes fixes

So, there's only one crash left (that I put a big TODO: on the maintab.cpp
about) and I'll fix it tomorrow as it's quite late here and I'm almost
sleeping at the keyboard.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-06-01 23:13:51 -03:00 committed by Dirk Hohndel
parent ee9746c622
commit 6cd85d9b73
6 changed files with 41 additions and 13 deletions

View file

@ -39,16 +39,10 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
void LocationInformationModel::update()
{
if (rowCount()) {
beginRemoveRows(QModelIndex(), 0, rowCount()-1);
endRemoveRows();
}
if (dive_site_table.nr) {
beginInsertRows(QModelIndex(), 0, dive_site_table.nr);
internalRowCount = dive_site_table.nr;
std::sort(dive_site_table.dive_sites, dive_site_table.dive_sites + dive_site_table.nr, dive_site_less_than);
endInsertRows();
}
beginResetModel();
internalRowCount = dive_site_table.nr;
std::sort(dive_site_table.dive_sites, dive_site_table.dive_sites + dive_site_table.nr, dive_site_less_than);
endResetModel();
}
int32_t LocationInformationModel::addDiveSite(const QString& name, int lon, int lat)
@ -76,3 +70,14 @@ bool LocationInformationModel::setData(const QModelIndex &index, const QVariant
emit dataChanged(index, index);
return true;
}
bool LocationInformationModel::removeRows(int row, int count, const QModelIndex & parent) {
if(row >= rowCount())
return false;
beginRemoveRows(QModelIndex(), row, row);
struct dive_site *ds = get_dive_site(row);
delete_dive_site(ds->uuid);
endRemoveRows();
return true;
}