diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-07-25 21:23:19 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-09-01 07:48:43 -0700 |
commit | 89e0c3f46498ba3e0844514b6709a07c200a68df (patch) | |
tree | 8609c84130cb04180d9db4bb43f2dfc11cf563c3 /qt-models/divetripmodel.cpp | |
parent | 236f0512bec2946b35052abf637c7c8df97f34bf (diff) | |
download | subsurface-89e0c3f46498ba3e0844514b6709a07c200a68df.tar.gz |
Cleanup: make DiveTripModel a global object
DiveTripModel (the model describing the dive-list) was destroyed
and recreated on every reset of the list. This seems excessive.
Instead - in analogy to most other models - make it a single
global object.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divetripmodel.cpp')
-rw-r--r-- | qt-models/divetripmodel.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 384da6b89..b94eaa985 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -437,6 +437,12 @@ int DiveItem::weight() const return tw.grams; } +DiveTripModel *DiveTripModel::instance() +{ + static DiveTripModel self; + return &self; +} + DiveTripModel::DiveTripModel(QObject *parent) : TreeModel(parent), currentLayout(TREE) @@ -586,9 +592,11 @@ void DiveTripModel::setupModelData() beginResetModel(); + clear(); if (autogroup) autogroup_dives(); dive_table.preexisting = dive_table.nr; + QMap<dive_trip_t *, TripItem *> trips; while (--i >= 0) { struct dive *dive = get_dive(i); update_cylinder_related_info(dive); @@ -598,7 +606,7 @@ void DiveTripModel::setupModelData() diveItem->diveId = dive->id; if (!trip || currentLayout == LIST) { - diveItem->parent = rootItem; + diveItem->parent = rootItem.get(); rootItem->children.push_back(diveItem); continue; } @@ -608,7 +616,7 @@ void DiveTripModel::setupModelData() if (!trips.keys().contains(trip)) { TripItem *tripItem = new TripItem(); tripItem->trip = trip; - tripItem->parent = rootItem; + tripItem->parent = rootItem.get(); tripItem->children.push_back(diveItem); trips[trip] = tripItem; rootItem->children.push_back(tripItem); |