diff options
author | Henrik Brautaset Aronsen <subsurface@henrik.synth.no> | 2013-04-25 09:50:01 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-04-25 06:39:02 -0700 |
commit | 5d4d40df910b7be15c58f46768b8fe54b0b429f0 (patch) | |
tree | b688685c21ccba5df00900875bc7861b8e5420df /qt-ui | |
parent | fde0f49df899a3c591e8def6dda93a4d83bbc962 (diff) | |
download | subsurface-5d4d40df910b7be15c58f46768b8fe54b0b429f0.tar.gz |
Simplify DiveItem
The DiveItem constructor had 13 variables. By passing it the full
dive we reduce that to 2.
[Dirk Hohndel: changed to use "struct dive *" instead of just "dive *"]
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/models.cpp | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index cf6490051..a725d0d61 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -63,7 +63,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const return ret; } - dive *d = get_dive(selected_dive); + struct dive *d = get_dive(selected_dive); cylinder_t& cyl = d->cylinder[index.row()]; if (role == Qt::DisplayRole) { @@ -297,8 +297,9 @@ public: explicit DiveItem(): number(0), when(), duration(), maxdepth(), rating(0), temperature(), totalweight(), suit(QString()), sac(0), otu(0), maxcns(0), location(QString()) { parentItem = 0; } - explicit DiveItem(int, timestamp_t, duration_t, depth_t, int, temperature_t, - weight_t, QString, int, int, int, QString, DiveItem *parent = 0); + + explicit DiveItem(struct dive *d, DiveItem *parent = 0); + ~DiveItem() { qDeleteAll(childlist); } int diveNumber() const { return number; } @@ -341,15 +342,24 @@ private: QList <DiveItem*> childlist; }; -DiveItem::DiveItem(int num, timestamp_t when, duration_t duration, depth_t maxdepth, int rating, temperature_t temp, - weight_t weight, QString su, int sac, int otu, int maxcns, QString loc, DiveItem *p): - number(num), rating(rating), suit(su), sac(sac), otu(otu), maxcns(maxcns), location(loc), parentItem(p) +DiveItem::DiveItem(struct dive *d, DiveItem *p): + number(d->number), + rating(d->rating), + suit(d->suit), + sac(d->sac), + otu(d->otu), + maxcns(d->maxcns), + location(d->location), + parentItem(p) { - this->when = when; - this->duration = duration; - this->maxdepth = maxdepth; - this->temperature = temp; - this->totalweight = weight; + this->when = d->when; + this->duration = d->duration; + this->maxdepth = d->maxdepth; + this->temperature = d->watertemp; + + weight_t tw = { total_weight(d) }; + this->totalweight = tw; + if (parentItem) parentItem->addChild(this); } @@ -431,20 +441,7 @@ DiveTripModel::DiveTripModel(QObject *parent) : QAbstractItemModel(parent) struct dive *d; for_each_dive(i, d) { - weight_t tw = {.grams = total_weight(d)}; - new DiveItem(d->number, - d->when, - d->duration, - d->maxdepth, - d->rating, - d->watertemp, - tw, - d->suit, - d->sac, - d->otu, - d->maxcns, - d->location, - rootItem); + new DiveItem(d, rootItem); } } |