mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
236f0512be
commit
89e0c3f464
7 changed files with 31 additions and 28 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue