summaryrefslogtreecommitdiffstats
path: root/qt-models/diveplotdatamodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-06-29 10:31:49 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-09 19:19:04 +0100
commit3025e0630de2b9ced3d0aadd1513cb0e1c93b159 (patch)
tree7fac659c1c80f2b28550c36ed700508e7dcc6817 /qt-models/diveplotdatamodel.cpp
parent77e5dbac7309d6bc09d6ef2631857d41486f3ac8 (diff)
downloadsubsurface-3025e0630de2b9ced3d0aadd1513cb0e1c93b159.tar.gz
Cleanup: implement proper Qt-model semantics in DivePlotData model
User beginResetModel()/endResetModel() pairs to reset the model. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/diveplotdatamodel.cpp')
-rw-r--r--qt-models/diveplotdatamodel.cpp26
1 files changed, 11 insertions, 15 deletions
diff --git a/qt-models/diveplotdatamodel.cpp b/qt-models/diveplotdatamodel.cpp
index 6f718021f..6809ee952 100644
--- a/qt-models/diveplotdatamodel.cpp
+++ b/qt-models/diveplotdatamodel.cpp
@@ -164,29 +164,25 @@ QVariant DivePlotDataModel::headerData(int section, Qt::Orientation orientation,
void DivePlotDataModel::clear()
{
- if (rowCount() != 0) {
- beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
- pInfo.nr = 0;
- free(pInfo.entry);
- pInfo.entry = 0;
- diveId = -1;
- dcNr = -1;
- endRemoveRows();
- }
+ beginResetModel();
+ pInfo.nr = 0;
+ free(pInfo.entry);
+ pInfo.entry = 0;
+ diveId = -1;
+ dcNr = -1;
+ endResetModel();
}
void DivePlotDataModel::setDive(dive *d, const plot_info &info)
{
- clear();
- Q_ASSERT(d != NULL);
+ beginResetModel();
diveId = d->id;
dcNr = dc_number;
free(pInfo.entry);
pInfo = info;
pInfo.entry = (struct plot_data *)malloc(sizeof(struct plot_data) * pInfo.nr);
memcpy(pInfo.entry, info.entry, sizeof(plot_data) * pInfo.nr);
- beginInsertRows(QModelIndex(), 0, pInfo.nr - 1);
- endInsertRows();
+ endResetModel();
}
unsigned int DivePlotDataModel::dcShown() const
@@ -199,8 +195,8 @@ unsigned int DivePlotDataModel::dcShown() const
{ \
double ret = -1; \
for (int i = 0, count = rowCount(); i < count; i++) { \
- if (pInfo.entry[i].pressures.GAS > ret) \
- ret = pInfo.entry[i].pressures.GAS; \
+ if (pInfo.entry[i].pressures.GAS > ret) \
+ ret = pInfo.entry[i].pressures.GAS; \
} \
return ret; \
}