diff options
author | Tomaz Canabrava <tomaz.canabrava@gmail.com> | 2015-06-01 23:13:51 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-06-01 21:36:48 -0700 |
commit | 6cd85d9b731ef646b605d483dbbcddbc70283338 (patch) | |
tree | acb08cd7f45fbcf375a7f41525fb102ebd9fdbd0 /qt-models | |
parent | ee9746c622e84ed8385c8bbd0e6ffa61f4c813a4 (diff) | |
download | subsurface-6cd85d9b731ef646b605d483dbbcddbc70283338.tar.gz |
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>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/divelocationmodel.cpp | 25 | ||||
-rw-r--r-- | qt-models/divelocationmodel.h | 2 |
2 files changed, 17 insertions, 10 deletions
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index 42f283f1e..edf15b707 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -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; +} diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h index 7ca0c926a..4e5adf104 100644 --- a/qt-models/divelocationmodel.h +++ b/qt-models/divelocationmodel.h @@ -13,6 +13,8 @@ public: QVariant data(const QModelIndex &index = QModelIndex(), int role = Qt::DisplayRole) const; int32_t addDiveSite(const QString& name, int lat = 0, int lon = 0); bool setData(const QModelIndex &index, const QVariant &value, int role); + bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); + public slots: void update(); private: |