diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-11-06 11:24:38 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-11-07 13:00:58 -0800 |
commit | 45251ec7248a0300506af043b0a5c448051b2072 (patch) | |
tree | 5ade6357ec26c2412788844d48db76e9fdd3dcd7 /qt-ui/models.cpp | |
parent | 4ccddf95d7660b9c2c91da1d72f08bd45988c83e (diff) | |
download | subsurface-45251ec7248a0300506af043b0a5c448051b2072.tar.gz |
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>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
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(); + } +} |