summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-05-28 16:39:15 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-29 14:10:30 -0700
commit32b0afa3e7f4b0636b65119d63e9f398b9f4bfca (patch)
tree6283f64c8615b647dbb6e9602d705d22f316344d
parentf432b764e78ac3d66f5ab1bfc7c18fbdb75624e5 (diff)
downloadsubsurface-32b0afa3e7f4b0636b65119d63e9f398b9f4bfca.tar.gz
Move Tankinfomodel to its own file
Another change to make it easier to program the mobile ui. This was a fairly easy patch: just moved the contents of the file and fixed the includes. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--CMakeLists.txt1
-rw-r--r--qt-models/cylindermodel.cpp1
-rw-r--r--qt-models/models.cpp111
-rw-r--r--qt-models/models.h29
-rw-r--r--qt-models/tankinfomodel.cpp115
-rw-r--r--qt-models/tankinfomodel.h35
-rw-r--r--qt-ui/mainwindow.cpp1
-rw-r--r--qt-ui/modeldelegates.cpp1
8 files changed, 154 insertions, 140 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a599bb4d1..9f0309180 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -252,6 +252,7 @@ set(SUBSURFACE_MODELS_LIB_SRCS
qt-models/diveplannermodel.cpp
qt-models/models.cpp
qt-models/filtermodels.cpp
+ qt-models/tankinfomodel.cpp
qt-models/completionmodels.cpp
)
source_group("Subsurface Models" FILES ${SUBSURFACE_MODELS})
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 70b4f5f30..857381b71 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -1,4 +1,5 @@
#include "cylindermodel.h"
+#include "tankinfomodel.h"
#include "models.h"
#include "helpers.h"
#include "dive.h"
diff --git a/qt-models/models.cpp b/qt-models/models.cpp
index 3bc0f74a2..b2d317456 100644
--- a/qt-models/models.cpp
+++ b/qt-models/models.cpp
@@ -441,117 +441,6 @@ void WSInfoModel::update()
}
}
-TankInfoModel *TankInfoModel::instance()
-{
- static QScopedPointer<TankInfoModel> self(new TankInfoModel());
- return self.data();
-}
-
-const QString &TankInfoModel::biggerString() const
-{
- return biggerEntry;
-}
-
-bool TankInfoModel::insertRows(int row, int count, const QModelIndex &parent)
-{
- beginInsertRows(parent, rowCount(), rowCount());
- rows += count;
- endInsertRows();
- return true;
-}
-
-bool TankInfoModel::setData(const QModelIndex &index, const QVariant &value, int role)
-{
- struct tank_info_t *info = &tank_info[index.row()];
- switch (index.column()) {
- case DESCRIPTION:
- info->name = strdup(value.toByteArray().data());
- break;
- case ML:
- info->ml = value.toInt();
- break;
- case BAR:
- info->bar = value.toInt();
- break;
- }
- emit dataChanged(index, index);
- return true;
-}
-
-void TankInfoModel::clear()
-{
-}
-
-QVariant TankInfoModel::data(const QModelIndex &index, int role) const
-{
- QVariant ret;
- if (!index.isValid()) {
- return ret;
- }
- if (role == Qt::FontRole) {
- return defaultModelFont();
- }
- if (role == Qt::DisplayRole || role == Qt::EditRole) {
- struct tank_info_t *info = &tank_info[index.row()];
- int ml = info->ml;
- double bar = (info->psi) ? psi_to_bar(info->psi) : info->bar;
-
- if (info->cuft && info->psi)
- ml = cuft_to_l(info->cuft) * 1000 / bar_to_atm(bar);
-
- switch (index.column()) {
- case BAR:
- ret = bar * 1000;
- break;
- case ML:
- ret = ml;
- break;
- case DESCRIPTION:
- ret = QString(info->name);
- break;
- }
- }
- return ret;
-}
-
-int TankInfoModel::rowCount(const QModelIndex &parent) const
-{
- return rows + 1;
-}
-
-TankInfoModel::TankInfoModel() : rows(-1)
-{
- setHeaderDataStrings(QStringList() << tr("Description") << tr("ml") << tr("bar"));
- struct tank_info_t *info = tank_info;
- for (info = tank_info; info->name; info++, rows++) {
- QString infoName = gettextFromC::instance()->tr(info->name);
- if (infoName.count() > biggerEntry.count())
- biggerEntry = infoName;
- }
-
- if (rows > -1) {
- beginInsertRows(QModelIndex(), 0, rows);
- endInsertRows();
- }
-}
-
-void TankInfoModel::update()
-{
- if (rows > -1) {
- beginRemoveRows(QModelIndex(), 0, rows);
- endRemoveRows();
- rows = -1;
- }
- struct tank_info_t *info = tank_info;
- for (info = tank_info; info->name; info++, rows++)
- ;
-
- if (rows > -1) {
- beginInsertRows(QModelIndex(), 0, rows);
- endInsertRows();
- }
-}
-
//#################################################################################################
//#
//# Tree Model - a Basic Tree Model so I don't need to kill myself repeating this for every model.
diff --git a/qt-models/models.h b/qt-models/models.h
index 2edf89269..9e18ba26d 100644
--- a/qt-models/models.h
+++ b/qt-models/models.h
@@ -21,35 +21,6 @@
#include "../divecomputer.h"
#include "cleanertablemodel.h"
-/* Encapsulates the tank_info global variable
- * to show on Qt's Model View System.*/
-class TankInfoModel : public CleanerTableModel {
- Q_OBJECT
-public:
- static TankInfoModel *instance();
-
- enum Column {
- DESCRIPTION,
- ML,
- BAR
- };
- TankInfoModel();
-
- /*reimp*/ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- /*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
- /*reimp*/ bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
- /*reimp*/ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
- const QString &biggerString() const;
- void clear();
-public
-slots:
- void update();
-
-private:
- int rows;
- QString biggerEntry;
-};
-
/* Encapsulate ws_info */
class WSInfoModel : public CleanerTableModel {
Q_OBJECT
diff --git a/qt-models/tankinfomodel.cpp b/qt-models/tankinfomodel.cpp
new file mode 100644
index 000000000..0a06a3b08
--- /dev/null
+++ b/qt-models/tankinfomodel.cpp
@@ -0,0 +1,115 @@
+#include "tankinfomodel.h"
+#include "dive.h"
+#include "gettextfromc.h"
+#include "metrics.h"
+
+TankInfoModel *TankInfoModel::instance()
+{
+ static QScopedPointer<TankInfoModel> self(new TankInfoModel());
+ return self.data();
+}
+
+const QString &TankInfoModel::biggerString() const
+{
+ return biggerEntry;
+}
+
+bool TankInfoModel::insertRows(int row, int count, const QModelIndex &parent)
+{
+ beginInsertRows(parent, rowCount(), rowCount());
+ rows += count;
+ endInsertRows();
+ return true;
+}
+
+bool TankInfoModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ struct tank_info_t *info = &tank_info[index.row()];
+ switch (index.column()) {
+ case DESCRIPTION:
+ info->name = strdup(value.toByteArray().data());
+ break;
+ case ML:
+ info->ml = value.toInt();
+ break;
+ case BAR:
+ info->bar = value.toInt();
+ break;
+ }
+ emit dataChanged(index, index);
+ return true;
+}
+
+void TankInfoModel::clear()
+{
+}
+
+QVariant TankInfoModel::data(const QModelIndex &index, int role) const
+{
+ QVariant ret;
+ if (!index.isValid()) {
+ return ret;
+ }
+ if (role == Qt::FontRole) {
+ return defaultModelFont();
+ }
+ if (role == Qt::DisplayRole || role == Qt::EditRole) {
+ struct tank_info_t *info = &tank_info[index.row()];
+ int ml = info->ml;
+ double bar = (info->psi) ? psi_to_bar(info->psi) : info->bar;
+
+ if (info->cuft && info->psi)
+ ml = cuft_to_l(info->cuft) * 1000 / bar_to_atm(bar);
+
+ switch (index.column()) {
+ case BAR:
+ ret = bar * 1000;
+ break;
+ case ML:
+ ret = ml;
+ break;
+ case DESCRIPTION:
+ ret = QString(info->name);
+ break;
+ }
+ }
+ return ret;
+}
+
+int TankInfoModel::rowCount(const QModelIndex &parent) const
+{
+ return rows + 1;
+}
+
+TankInfoModel::TankInfoModel() : rows(-1)
+{
+ setHeaderDataStrings(QStringList() << tr("Description") << tr("ml") << tr("bar"));
+ struct tank_info_t *info = tank_info;
+ for (info = tank_info; info->name; info++, rows++) {
+ QString infoName = gettextFromC::instance()->tr(info->name);
+ if (infoName.count() > biggerEntry.count())
+ biggerEntry = infoName;
+ }
+
+ if (rows > -1) {
+ beginInsertRows(QModelIndex(), 0, rows);
+ endInsertRows();
+ }
+}
+
+void TankInfoModel::update()
+{
+ if (rows > -1) {
+ beginRemoveRows(QModelIndex(), 0, rows);
+ endRemoveRows();
+ rows = -1;
+ }
+ struct tank_info_t *info = tank_info;
+ for (info = tank_info; info->name; info++, rows++)
+ ;
+
+ if (rows > -1) {
+ beginInsertRows(QModelIndex(), 0, rows);
+ endInsertRows();
+ }
+}
diff --git a/qt-models/tankinfomodel.h b/qt-models/tankinfomodel.h
new file mode 100644
index 000000000..f1cf1ffc7
--- /dev/null
+++ b/qt-models/tankinfomodel.h
@@ -0,0 +1,35 @@
+#ifndef TANKINFOMODEL_H
+#define TANKINFOMODEL_H
+
+#include "cleanertablemodel.h"
+
+/* Encapsulates the tank_info global variable
+ * to show on Qt's Model View System.*/
+class TankInfoModel : public CleanerTableModel {
+ Q_OBJECT
+public:
+ static TankInfoModel *instance();
+
+ enum Column {
+ DESCRIPTION,
+ ML,
+ BAR
+ };
+ TankInfoModel();
+
+ /*reimp*/ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ /*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ /*reimp*/ bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
+ /*reimp*/ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+ const QString &biggerString() const;
+ void clear();
+public
+slots:
+ void update();
+
+private:
+ int rows;
+ QString biggerEntry;
+};
+
+#endif
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 9c36b6731..ffc813257 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -29,6 +29,7 @@
#include <QPrintDialog>
#include "printdialog.h"
#endif
+#include "tankinfomodel.h"
#include "diveplannermodel.h"
#include "divelogimportdialog.h"
#include "divelogexportdialog.h"
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 21d497562..b300c9a4a 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -6,6 +6,7 @@
#include "models.h"
#include "starwidget.h"
#include "profile/profilewidget2.h"
+#include "tankinfomodel.h"
#include <QCompleter>
#include <QKeyEvent>