diff options
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/maintab.cpp | 3 | ||||
-rw-r--r-- | qt-ui/models.cpp | 53 | ||||
-rw-r--r-- | qt-ui/models.h | 8 |
3 files changed, 40 insertions, 24 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index e9a8cd1c4..bb5169e52 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -202,6 +202,7 @@ void MainTab::updateDiveInfo(int dive) ui->averageTimeAllText->setText(get_time_string(seconds, 0)); 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); } else { /* make the fields read-only */ ui->location->setReadOnly(true); @@ -226,6 +227,7 @@ void MainTab::updateDiveInfo(int dive) ui->airTemperatureText->clear(); ui->gasUsedText->clear(); ui->airPressureText->clear(); + cylindersModel->clear(); } /* statisticsTab*/ /* we can access the stats_selection struct, but how do we ensure the relevant dives are selected @@ -292,7 +294,6 @@ void MainTab::on_delWeight_clicked() void MainTab::reload() { - cylindersModel->update(); } void MainTab::on_editAccept_clicked(bool edit) diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 90c826331..d20bf2323 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -13,7 +13,7 @@ extern struct tank_info tank_info[100]; -CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent) +CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent), current(0), rows(0) { } @@ -62,7 +62,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const if (!index.isValid() || index.row() >= MAX_CYLINDERS) return ret; - cylinder_t& cyl = current_dive->cylinder[index.row()]; + cylinder_t& cyl = current->cylinder[index.row()]; if (role == Qt::DisplayRole) { switch(index.column()) { @@ -94,49 +94,64 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const int CylindersModel::rowCount(const QModelIndex& parent) const { - return usedRows[current_dive]; + return rows; } void CylindersModel::add(cylinder_t* cyl) { - if (usedRows[current_dive] >= MAX_CYLINDERS) { - free(cyl); + if (rows >= MAX_CYLINDERS) { return; } - int row = usedRows[current_dive]; + int row = rows; - cylinder_t& cylinder = current_dive->cylinder[row]; + cylinder_t& cylinder = current->cylinder[row]; cylinder.end.mbar = cyl->end.mbar; cylinder.start.mbar = cyl->start.mbar; + cylinder.type.description = strdup(cyl->type.description); + cylinder.type.size = cyl->type.size; + cylinder.type.workingpressure = cyl->type.workingpressure; beginInsertRows(QModelIndex(), row, row); - usedRows[current_dive]++; + rows++; endInsertRows(); } void CylindersModel::update() { - if (usedRows[current_dive] > 0) { - beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1); - endRemoveRows(); - } - if (usedRows[current_dive] > 0) { - beginInsertRows(QModelIndex(), 0, usedRows[current_dive]-1); - endInsertRows(); - } + setDive(current); } void CylindersModel::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(); } } +void CylindersModel::setDive(dive* d) +{ + if (current) + clear(); + + int amount = 0; + for(int i = 0; i < MAX_CYLINDERS; i++){ + cylinder_t& cylinder = current_dive->cylinder[i]; + qDebug() << QString(cylinder.type.description); + if (!cylinder.type.description){ + amount = i; + break; + } + } + + beginInsertRows(QModelIndex(), 0, amount-1); + rows = amount; + current = d; + endInsertRows(); +} + void WeightModel::clear() { if (usedRows[current_dive] > 0) { diff --git a/qt-ui/models.h b/qt-ui/models.h index ac533fd71..41bd4f892 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -49,11 +49,11 @@ public: void add(cylinder_t *cyl); void clear(); void update(); + void setDive(struct dive *d); + private: - /* Since the dive doesn't stores the number of cylinders that - * it has (max 8) and since I don't want to make a - * model-for-each-dive, let's hack this here instead. */ - QMap<struct dive *, int> usedRows; + struct dive *current; + int rows; }; /* Encapsulation of the Weight Model, that represents |