summaryrefslogtreecommitdiffstats
path: root/qt-models/divecomputerextradatamodel.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-05-28 17:29:58 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-29 14:11:26 -0700
commit257f8063c4437eced155ec5ad0b40791ca814dfb (patch)
tree318060630a47335ba84efff851d7222c53865068 /qt-models/divecomputerextradatamodel.cpp
parentd84ffa8fc3162692597c19c42e621f7d8ac58dca (diff)
downloadsubsurface-257f8063c4437eced155ec5ad0b40791ca814dfb.tar.gz
Move ExtraDataModel to qt-models
Another attempt to make it easyer to create the mobile version. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models/divecomputerextradatamodel.cpp')
-rw-r--r--qt-models/divecomputerextradatamodel.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/qt-models/divecomputerextradatamodel.cpp b/qt-models/divecomputerextradatamodel.cpp
new file mode 100644
index 000000000..8c0c828e3
--- /dev/null
+++ b/qt-models/divecomputerextradatamodel.cpp
@@ -0,0 +1,70 @@
+#include "divecomputerextradatamodel.h"
+#include "dive.h"
+#include "metrics.h"
+
+
+ExtraDataModel::ExtraDataModel(QObject *parent) : CleanerTableModel(parent),
+ rows(0)
+{
+ //enum Column {KEY, VALUE};
+ setHeaderDataStrings(QStringList() << tr("Key") << tr("Value"));
+}
+
+void ExtraDataModel::clear()
+{
+ if (rows > 0) {
+ beginRemoveRows(QModelIndex(), 0, rows - 1);
+ endRemoveRows();
+ }
+}
+
+QVariant ExtraDataModel::data(const QModelIndex &index, int role) const
+{
+ QVariant ret;
+ struct extra_data *ed = get_dive_dc(&displayed_dive, dc_number)->extra_data;
+ int i = -1;
+ while (ed && ++i < index.row())
+ ed = ed->next;
+ if (!ed)
+ return ret;
+
+ switch (role) {
+ case Qt::FontRole:
+ ret = defaultModelFont();
+ break;
+ case Qt::TextAlignmentRole:
+ ret = int(Qt::AlignLeft | Qt::AlignVCenter);
+ break;
+ case Qt::DisplayRole:
+ switch (index.column()) {
+ case KEY:
+ ret = QString(ed->key);
+ break;
+ case VALUE:
+ ret = QString(ed->value);
+ break;
+ }
+ break;
+ }
+ return ret;
+}
+
+int ExtraDataModel::rowCount(const QModelIndex &parent) const
+{
+ return rows;
+}
+
+void ExtraDataModel::updateDive()
+{
+ clear();
+ rows = 0;
+ struct extra_data *ed = get_dive_dc(&displayed_dive, dc_number)->extra_data;
+ while (ed) {
+ rows++;
+ ed = ed->next;
+ }
+ if (rows > 0) {
+ beginInsertRows(QModelIndex(), 0, rows - 1);
+ endInsertRows();
+ }
+}