From 45251ec7248a0300506af043b0a5c448051b2072 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 6 Nov 2014 11:24:38 -0800 Subject: Show extra data in separate tab on MainTab This way any extra data probided by the dive computer is visible to the user (without other processing). This data cannot be edited by the user as it reflects the information given by the dive computer. Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 4 ++++ qt-ui/maintab.h | 2 ++ qt-ui/maintab.ui | 67 ++++++++++++++++++++++++++++++++++++++++++++++++------- qt-ui/models.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qt-ui/models.h | 18 +++++++++++++++ 5 files changed, 149 insertions(+), 8 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 545632f75..ab712aeca 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -32,6 +32,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), weightModel(new WeightModel(this)), cylindersModel(CylindersModel::instance()), + extraDataModel(new ExtraDataModel(this)), editMode(NONE), divePictureModel(DivePictureModel::instance()), currentTrip(0), @@ -47,6 +48,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui.weights->setModel(weightModel); ui.photosView->setModel(divePictureModel); connect(ui.photosView, SIGNAL(photoDoubleClicked(QString)), this, SLOT(photoDoubleClicked(QString))); + ui.extraData->setModel(extraDataModel); closeMessage(); QAction *action = new QAction(tr("Save"), this); @@ -473,6 +475,7 @@ void MainTab::updateDiveInfo(bool clear) ui.equipmentTab->setEnabled(true); cylindersModel->updateDive(); weightModel->updateDive(); + extraDataModel->updateDive(); taglist_get_tagstring(displayed_dive.tag_list, buf, 1024); ui.tagWidget->setText(QString(buf)); } @@ -899,6 +902,7 @@ void MainTab::rejectChanges() weightModel->changed = false; cylindersModel->updateDive(); weightModel->updateDive(); + extraDataModel->updateDive(); } #undef EDIT_TEXT2 diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 541e3fb79..369dd1723 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -17,6 +17,7 @@ class WeightModel; class CylindersModel; +class ExtraDataModel; class QCompleter; struct Completers { @@ -94,6 +95,7 @@ private: Ui::MainTab ui; WeightModel *weightModel; CylindersModel *cylindersModel; + ExtraDataModel *extraDataModel; EditMode editMode; BuddyCompletionModel buddyModel; DiveMasterCompletionModel diveMasterModel; diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index a3b15418e..72c04acc3 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -37,8 +37,8 @@ 0 0 - 662 - 642 + 668 + 658 @@ -336,8 +336,8 @@ 0 0 - 662 - 642 + 100 + 30 @@ -416,8 +416,8 @@ 0 0 - 662 - 642 + 668 + 658 @@ -745,8 +745,8 @@ 0 0 - 662 - 642 + 342 + 167 @@ -953,6 +953,57 @@ + + + Extra data + + + + + 10 + 20 + 341 + 16 + + + + Additional data from dive computer + + + + + + 10 + 50 + 661 + 641 + + + + true + + + + + 0 + 0 + 659 + 639 + + + + + + 10 + 10 + 641 + 621 + + + + + + diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 64a5fd540..c48d1e4fc 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -2660,3 +2660,69 @@ void MultiFilterSortModel::removeFilterModel(MultiFilterInterface *model) models.removeAll(model); disconnect(itemModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(myInvalidate())); } + +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(); + } +} diff --git a/qt-ui/models.h b/qt-ui/models.h index a78c20be0..8750492a1 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -165,6 +165,24 @@ private: int rows; }; +/* extra data model for additional dive computer data */ +class ExtraDataModel : public CleanerTableModel { + Q_OBJECT +public: + enum Column { + KEY, + VALUE + }; + explicit ExtraDataModel(QObject *parent = 0); + /*reimp*/ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + /*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const; + + void clear(); + void updateDive(); +private: + int rows; +}; + /*! An AbstractItemModel for recording dive trip information such as a list of dives. * */ -- cgit v1.2.3-70-g09d2