From be31a53b0d7090083f8b3a2ed923d0ed8b61000f Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 21 May 2013 09:59:41 -0300 Subject: Added support for visualization the Weigthssystems on the Equipment Tab. This patch adds support showing and for editing weigthsystems in the equipment tab, so, now the two things that are missing are 'edit' and 'delete', wich are quite easy to do. Signed-off-by: Tomaz Canabrava --- qt-ui/maintab.cpp | 2 ++ qt-ui/models.cpp | 40 +++++++++++++++++++++++++++++----------- qt-ui/models.h | 6 ++++-- 3 files changed, 35 insertions(+), 13 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index bb5169e52..848f068a2 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -203,6 +203,7 @@ void MainTab::updateDiveInfo(int dive) ui->longestAllText->setText(get_time_string(stats_selection.longest_time.seconds, 0)); ui->shortestAllText->setText(get_time_string(stats_selection.shortest_time.seconds, 0)); cylindersModel->setDive(d); + weightModel->setDive(d); } else { /* make the fields read-only */ ui->location->setReadOnly(true); @@ -228,6 +229,7 @@ void MainTab::updateDiveInfo(int dive) ui->gasUsedText->clear(); ui->airPressureText->clear(); cylindersModel->clear(); + weightModel->clear(); } /* statisticsTab*/ /* we can access the stats_selection struct, but how do we ensure the relevant dives are selected diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index d20bf2323..04f7256e6 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -138,8 +138,7 @@ void CylindersModel::setDive(dive* d) int amount = 0; for(int i = 0; i < MAX_CYLINDERS; i++){ - cylinder_t& cylinder = current_dive->cylinder[i]; - qDebug() << QString(cylinder.type.description); + cylinder_t& cylinder = d->cylinder[i]; if (!cylinder.type.description){ amount = i; break; @@ -154,9 +153,8 @@ void CylindersModel::setDive(dive* d) void WeightModel::clear() { - if (usedRows[current_dive] > 0) { - beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1); - usedRows[current_dive] = 0; + if (rows > 0) { + beginRemoveRows(QModelIndex(), 0, rows-1); endRemoveRows(); } } @@ -195,7 +193,7 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const int WeightModel::rowCount(const QModelIndex& parent) const { - return usedRows[current_dive]; + return rows; } QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -219,25 +217,45 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r void WeightModel::add(weightsystem_t* weight) { - if (usedRows[current_dive] >= MAX_WEIGHTSYSTEMS) { - free(weight); + if (rows >= MAX_WEIGHTSYSTEMS) { return; } - int row = usedRows[current_dive]; + int row = rows; - weightsystem_t *ws = ¤t_dive->weightsystem[row]; + weightsystem_t *ws = ¤t->weightsystem[row]; ws->description = weight->description; ws->weight.grams = weight->weight.grams; beginInsertRows(QModelIndex(), row, row); - usedRows[current_dive]++; + rows++; endInsertRows(); } void WeightModel::update() { + setDive(current); +} + +void WeightModel::setDive(dive* d) +{ + if (current) + clear(); + + int amount = 0; + for(int i = 0; i < MAX_WEIGHTSYSTEMS; i++){ + weightsystem_t& weightsystem = d->weightsystem[i]; + if (!weightsystem.description){ + amount = i; + break; + } + } + + beginInsertRows(QModelIndex(), 0, amount-1); + rows = amount; + current = d; + endInsertRows(); } void TankInfoModel::add(const QString& description) diff --git a/qt-ui/models.h b/qt-ui/models.h index 41bd4f892..62ae3913c 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -70,9 +70,11 @@ public: void add(weightsystem_t *weight); void clear(); void update(); + void setDive(struct dive *d); + private: - /* Remember the number of rows in a dive */ - QMap usedRows; + struct dive *current; + int rows; }; /*! An AbstractItemModel for recording dive trip information such as a list of dives. -- cgit v1.2.3-70-g09d2