diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-05-01 10:11:46 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-05-01 10:11:46 -0700 |
commit | 5c2ce0ac200cbf4b37a9765148b78d3091b5cd9f (patch) | |
tree | d1ab8ce4f0579c29a1789396fd3db5a84689a226 /qt-ui | |
parent | 730e055e5aacd2f917be9d86140773853670e850 (diff) | |
download | subsurface-5c2ce0ac200cbf4b37a9765148b78d3091b5cd9f.tar.gz |
Add data and add functions for WeightModel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/models.cpp | 40 | ||||
-rw-r--r-- | qt-ui/models.h | 2 |
2 files changed, 39 insertions, 3 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index d26b52ec9..4583c36cd 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -149,7 +149,29 @@ int WeightModel::columnCount(const QModelIndex& parent) const QVariant WeightModel::data(const QModelIndex& index, int role) const { - return QVariant(); + QVariant ret; + if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS) { + return ret; + } + weightsystem_t *ws = ¤t_dive->weightsystem[index.row()]; + + if (role == Qt::DisplayRole) { + switch(index.column()) { + case TYPE: + ret = QString(ws->description); + break; + case WEIGHT: + if (get_units()->weight == units::KG) { + int gr = ws->weight.grams % 1000; + int kg = ws->weight.grams / 1000; + ret = QString("%1.%2").arg(kg).arg((unsigned)(gr + 500) / 100); + } else { + ret = QString("%1").arg((unsigned)(grams_to_lbs(ws->weight.grams) + 0.5)); + } + break; + } + } + return ret; } int WeightModel::rowCount(const QModelIndex& parent) const @@ -175,8 +197,22 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r return ret; } -void WeightModel::add(weight_t* weight) +void WeightModel::add(weightsystem_t* weight) { + if (usedRows[current_dive] >= MAX_WEIGHTSYSTEMS) { + free(weight); + } + + int row = usedRows[current_dive]; + + weightsystem_t *ws = ¤t_dive->weightsystem[row]; + + ws->description = weight->description; + ws->weight.grams = weight->weight.grams; + + beginInsertRows(QModelIndex(), row, row); + usedRows[current_dive]++; + endInsertRows(); } void WeightModel::update() diff --git a/qt-ui/models.h b/qt-ui/models.h index b6bcdec78..46da9e51b 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -62,7 +62,7 @@ class WeightModel : public QAbstractTableModel { /*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; /*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const; - void add(weight_t *weight); + void add(weightsystem_t *weight); void clear(); void update(); private: |