diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-01 23:54:38 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-01 23:54:38 -0300 |
commit | e5ad47e459af1d937d26782ce8308dbd67ecec4b (patch) | |
tree | 0340be89b69de619623db519c7f8287636646ee0 /qt-ui/models.cpp | |
parent | 764a863082f9337156fc4bcf5c0ecc6ae3d149d6 (diff) | |
parent | 00d85313827af88ae5f35b2391ffa6964e81da49 (diff) | |
download | subsurface-e5ad47e459af1d937d26782ce8308dbd67ecec4b.tar.gz |
Merge branch 'Qt' into RenderStarsOnTable
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 97 |
1 files changed, 69 insertions, 28 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 7b9d8dc16..6d9bbad39 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -60,9 +60,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const if (!index.isValid() || index.row() >= MAX_CYLINDERS) { return ret; } - - struct dive *d = get_dive(selected_dive); - cylinder_t& cyl = d->cylinder[index.row()]; + cylinder_t& cyl = current_dive->cylinder[index.row()]; if (role == Qt::DisplayRole) { switch(index.column()) { @@ -94,67 +92,93 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const int CylindersModel::rowCount(const QModelIndex& parent) const { - return usedRows[currentDive]; + return usedRows[current_dive]; } void CylindersModel::add(cylinder_t* cyl) { - if (usedRows[currentDive] >= MAX_CYLINDERS) { + if (usedRows[current_dive] >= MAX_CYLINDERS) { free(cyl); + return; } - int row = usedRows[currentDive]; + int row = usedRows[current_dive]; - cylinder_t& cylinder = currentDive->cylinder[row]; + cylinder_t& cylinder = current_dive->cylinder[row]; cylinder.end.mbar = cyl->end.mbar; cylinder.start.mbar = cyl->start.mbar; beginInsertRows(QModelIndex(), row, row); - usedRows[currentDive]++; + usedRows[current_dive]++; endInsertRows(); } void CylindersModel::update() { - if (usedRows[currentDive] > 0) { - beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1); + if (usedRows[current_dive] > 0) { + beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1); endRemoveRows(); } - - currentDive = get_dive(selected_dive); - if (usedRows[currentDive] > 0) { - beginInsertRows(QModelIndex(), 0, usedRows[currentDive]-1); + if (usedRows[current_dive] > 0) { + beginInsertRows(QModelIndex(), 0, usedRows[current_dive]-1); endInsertRows(); } } void CylindersModel::clear() { - if (usedRows[currentDive] > 0) { - beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1); - usedRows[currentDive] = 0; + if (usedRows[current_dive] > 0) { + beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1); + usedRows[current_dive] = 0; endRemoveRows(); } } void WeightModel::clear() { + if (usedRows[current_dive] > 0) { + beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1); + usedRows[current_dive] = 0; + endRemoveRows(); + } } int WeightModel::columnCount(const QModelIndex& parent) const { - return 0; + return 2; } 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 { - return rows; + return usedRows[current_dive]; } QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -164,19 +188,36 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r return ret; } - switch(section) { - case TYPE: - ret = tr("Type"); - break; - case WEIGHT: - ret = tr("Weight"); - break; + if (role == Qt::DisplayRole) { + switch(section) { + case TYPE: + ret = tr("Type"); + break; + case WEIGHT: + ret = tr("Weight"); + break; + } } return ret; } -void WeightModel::add(weight_t* weight) +void WeightModel::add(weightsystem_t* weight) { + if (usedRows[current_dive] >= MAX_WEIGHTSYSTEMS) { + free(weight); + return; + } + + 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() |