summaryrefslogtreecommitdiffstats
path: root/qt-ui/models.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-04-15 15:04:35 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-04-15 17:34:44 -0700
commit115ee47bfc0aa8ca2b2bdaca047ccf595bbb7120 (patch)
treec729f128c39fcb71a751b0727ce5bf07a83d2db1 /qt-ui/models.cpp
parentdb180bf46e28aea3cc7dad2a695b1e0fa1b20e1e (diff)
downloadsubsurface-115ee47bfc0aa8ca2b2bdaca047ccf595bbb7120.tar.gz
Added the code that will load and populate the Tank Info
Added the code that will load and populate the Tank Info ComboBox that`s used by the user to select the Cylinder description. Code curerntly implements more than the GTK version since the GTK version of it was a plain-list, this one is a table based model that can be used in ListViews ( like we use now in the ComboBox ) but also in TableViews ( if there`s a need in the future to see everything that`s catalogued in the Tank Info struct. ) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r--qt-ui/models.cpp103
1 files changed, 102 insertions, 1 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 64fa6bac3..d1b8dc0a0 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -7,6 +7,8 @@
#include "models.h"
#include "../dive.h"
+extern struct tank_info tank_info[100];
+
CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent)
{
}
@@ -161,7 +163,7 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r
return ret;
}
- switch(section){
+ switch(section) {
case TYPE:
ret = tr("Type");
break;
@@ -179,3 +181,102 @@ void WeightModel::add(weight_t* weight)
void WeightModel::update()
{
}
+
+void TankInfoModel::add(const QString& description)
+{
+ // When the user `creates` a new one on the combobox.
+ // for now, empty till dirk cleans the GTK code.
+}
+
+void TankInfoModel::clear()
+{
+}
+
+int TankInfoModel::columnCount(const QModelIndex& parent) const
+{
+ return 3;
+}
+
+QVariant TankInfoModel::data(const QModelIndex& index, int role) const
+{
+ QVariant ret;
+ if (!index.isValid()) {
+ return ret;
+ }
+ struct tank_info *info = &tank_info[index.row()];
+
+ int ml = info->ml;
+
+ int bar = ((info->psi) ? psi_to_bar(info->psi) : info->bar) * 1000 + 0.5;
+
+ if (info->cuft) {
+ double airvolume = cuft_to_l(info->cuft) * 1000.0;
+ ml = airvolume / bar_to_atm(bar) + 0.5;
+ }
+ if (role == Qt::DisplayRole) {
+ switch(index.column()) {
+ case BAR: ret = bar;
+ break;
+ case ML: ret = ml;
+ break;
+ case DESCRIPTION:
+ ret = QString(info->name);
+ break;
+ }
+ }
+ return ret;
+}
+
+QVariant TankInfoModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ QVariant ret;
+
+ if (orientation != Qt::Horizontal)
+ return ret;
+
+ if (role == Qt::DisplayRole) {
+ switch(section) {
+ case BAR:
+ ret = tr("Bar");
+ break;
+ case ML:
+ ret = tr("Ml");
+ break;
+ case DESCRIPTION:
+ ret = tr("Description");
+ break;
+ }
+ }
+ return ret;
+}
+
+int TankInfoModel::rowCount(const QModelIndex& parent) const
+{
+ return rows+1;
+}
+
+TankInfoModel::TankInfoModel() : QAbstractTableModel(), rows(-1)
+{
+ struct tank_info *info = tank_info;
+ for (info = tank_info ; info->name; info++, rows++);
+
+ if (rows > -1) {
+ beginInsertRows(QModelIndex(), 0, rows);
+ endInsertRows();
+ }
+}
+
+void TankInfoModel::update()
+{
+ if(rows > -1) {
+ beginRemoveRows(QModelIndex(), 0, rows);
+ endRemoveRows();
+ }
+ struct tank_info *info = tank_info;
+ for (info = tank_info ; info->name; info++, rows++);
+
+ if (rows > -1) {
+ beginInsertRows(QModelIndex(), 0, rows);
+ endInsertRows();
+ }
+}