diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-03-09 22:32:16 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | dd12bdaf94c1ebc5d32598151aa96da12e61c146 (patch) | |
tree | ce03750531ebcabdda7c656c28b6c9e9e73032f7 /qt-models/divelocationmodel.cpp | |
parent | 992ad2fa2784d38c5dfe3cce4e35e00d27a5f533 (diff) | |
download | subsurface-dd12bdaf94c1ebc5d32598151aa96da12e61c146.tar.gz |
Dive site: add dive site list tab
Add a very simple tab-widget presenting the list of known dive sites.
The table is rendered using our custom "TableView".
The (mis)uses the "LocationInformationModel". It moves the items
to be displayed (delete, name, description, number of dives) to the
front and makes the others hidden.
Moreover, it was necessary to limit the geo-tag decoration role to
the name to avoid having the icon next to each column.
Make the trash-can icon active and the name and description editable.
This is modelled after the cylinders-table code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divelocationmodel.cpp')
-rw-r--r-- | qt-models/divelocationmodel.cpp | 69 |
1 files changed, 60 insertions, 9 deletions
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index 2ce2e0a3e..b9bf5702b 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -3,6 +3,8 @@ #include "qt-models/divelocationmodel.h" #include "core/qthelper.h" #include "core/divesite.h" +#include "core/metrics.h" +#include "cleanertablemodel.h" // for trashIcon(); #include <QDebug> #include <QLineEdit> #include <QIcon> @@ -23,16 +25,57 @@ LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractTabl { } -int LocationInformationModel::columnCount(const QModelIndex&) const +int LocationInformationModel::columnCount(const QModelIndex &) const { return COLUMNS; } -int LocationInformationModel::rowCount(const QModelIndex&) const +int LocationInformationModel::rowCount(const QModelIndex &) const { return dive_site_table.nr; } +QVariant LocationInformationModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Vertical) + return QVariant(); + + switch (role) { + case Qt::TextAlignmentRole: + return int(Qt::AlignLeft | Qt::AlignVCenter); + case Qt::FontRole: + return defaultModelFont(); + case Qt::InitialSortOrderRole: + // By default, sort number of dives descending, everything else ascending. + return section == NUM_DIVES ? Qt::DescendingOrder : Qt::AscendingOrder; + case Qt::DisplayRole: + case Qt::ToolTipRole: + switch (section) { + case NAME: + return tr("Name"); + case DESCRIPTION: + return tr("Description"); + case NUM_DIVES: + return tr("# of dives"); + } + break; + } + + return QVariant(); +} + +Qt::ItemFlags LocationInformationModel::flags(const QModelIndex &index) const +{ + switch (index.column()) { + case REMOVE: + return Qt::ItemIsEnabled; + case NAME: + case DESCRIPTION: + return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; + } + return QAbstractItemModel::flags(index); +} + QVariant LocationInformationModel::getDiveSiteData(const struct dive_site *ds, int column, int role) { if (!ds) @@ -40,10 +83,11 @@ QVariant LocationInformationModel::getDiveSiteData(const struct dive_site *ds, i switch(role) { case Qt::EditRole: - case Qt::DisplayRole : + case Qt::DisplayRole: switch(column) { case DIVESITE: return QVariant::fromValue<dive_site *>((dive_site *)ds); // Not nice: casting away const case NAME: return ds->name; + case NUM_DIVES: return ds->dives.nr; case LATITUDE: return ds->location.lat.udeg; case LONGITUDE: return ds->location.lon.udeg; case COORDS: return "TODO"; @@ -54,12 +98,19 @@ QVariant LocationInformationModel::getDiveSiteData(const struct dive_site *ds, i case TAXONOMY_3: return "TODO"; } break; - case Qt::DecorationRole : { - if (dive_site_has_gps_location(ds)) - return QIcon(":geotag-icon"); - else - return QVariant(); - } + case Qt::ToolTipRole: + switch(column) { + case REMOVE: return tr("Clicking here will remove this divesite."); + } + break; + case Qt::DecorationRole: + switch(column) { +#ifndef SUBSURFACE_MOBILE + case REMOVE: return trashIcon(); +#endif + case NAME: return dive_site_has_gps_location(ds) ? QIcon(":geotag-icon") : QVariant(); + } + break; case DIVESITE_ROLE: return QVariant::fromValue<dive_site *>((dive_site *)ds); // Not nice: casting away const } |