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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-11-06 11:24:38 -08:00
parent 4ccddf95d7
commit 45251ec724
5 changed files with 149 additions and 8 deletions

View file

@ -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

View file

@ -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;

View file

@ -37,8 +37,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>662</width>
<height>642</height>
<width>668</width>
<height>658</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
@ -336,8 +336,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>662</width>
<height>642</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_5">
@ -416,8 +416,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>662</width>
<height>642</height>
<width>668</width>
<height>658</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_6">
@ -745,8 +745,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>662</width>
<height>642</height>
<width>342</width>
<height>167</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_7">
@ -953,6 +953,57 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Extra data</string>
</attribute>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>341</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Additional data from dive computer</string>
</property>
</widget>
<widget class="QScrollArea" name="scrollArea_5">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>661</width>
<height>641</height>
</rect>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_5">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>659</width>
<height>639</height>
</rect>
</property>
<widget class="QTableView" name="extraData">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>641</width>
<height>621</height>
</rect>
</property>
</widget>
</widget>
</widget>
</widget>
</widget>
<customwidgets>
<customwidget>

View file

@ -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();
}
}

View file

@ -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.
*
*/