summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/CMakeLists.txt3
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.cpp24
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.h18
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.ui32
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp5
-rw-r--r--qt-models/cylindermodel.cpp1
-rw-r--r--qt-models/divelocationmodel.cpp69
-rw-r--r--qt-models/divelocationmodel.h5
8 files changed, 143 insertions, 14 deletions
diff --git a/desktop-widgets/CMakeLists.txt b/desktop-widgets/CMakeLists.txt
index 6227eaac1..efccfcc26 100644
--- a/desktop-widgets/CMakeLists.txt
+++ b/desktop-widgets/CMakeLists.txt
@@ -48,6 +48,7 @@ set (SUBSURFACE_UI
tab-widgets/TabDiveInformation.ui
tab-widgets/TabDivePhotos.ui
tab-widgets/TabDiveExtraInfo.ui
+ tab-widgets/TabDiveSite.ui
)
# the interface, in C++
@@ -115,6 +116,8 @@ set(SUBSURFACE_INTERFACE
tab-widgets/TabDivePhotos.h
tab-widgets/TabDiveStatistics.cpp
tab-widgets/TabDiveStatistics.h
+ tab-widgets/TabDiveSite.cpp
+ tab-widgets/TabDiveSite.h
tab-widgets/maintab.cpp
tab-widgets/maintab.h
tableview.cpp
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.cpp b/desktop-widgets/tab-widgets/TabDiveSite.cpp
new file mode 100644
index 000000000..81736bc77
--- /dev/null
+++ b/desktop-widgets/tab-widgets/TabDiveSite.cpp
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "TabDiveSite.h"
+#include "qt-models/divelocationmodel.h"
+
+#include <qt-models/divecomputerextradatamodel.h>
+
+TabDiveSite::TabDiveSite(QWidget *parent) : TabBase(parent)
+{
+ ui.setupUi(this);
+ ui.diveSites->setTitle(tr("Dive sites"));
+ ui.diveSites->setModel(LocationInformationModel::instance());
+
+ // Show only the first few columns
+ for (int i = LocationInformationModel::COORDS; i < LocationInformationModel::COLUMNS; ++i)
+ ui.diveSites->view()->setColumnHidden(i, true);
+}
+
+void TabDiveSite::updateData()
+{
+}
+
+void TabDiveSite::clear()
+{
+}
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.h b/desktop-widgets/tab-widgets/TabDiveSite.h
new file mode 100644
index 000000000..60b3abd76
--- /dev/null
+++ b/desktop-widgets/tab-widgets/TabDiveSite.h
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef TAB_DIVE_SITE_H
+#define TAB_DIVE_SITE_H
+
+#include "TabBase.h"
+#include "ui_TabDiveSite.h"
+
+class TabDiveSite : public TabBase {
+ Q_OBJECT
+public:
+ TabDiveSite(QWidget *parent = 0);
+ void updateData() override;
+ void clear() override;
+private:
+ Ui::TabDiveSite ui;
+};
+
+#endif
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.ui b/desktop-widgets/tab-widgets/TabDiveSite.ui
new file mode 100644
index 000000000..1d52555e3
--- /dev/null
+++ b/desktop-widgets/tab-widgets/TabDiveSite.ui
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TabDiveSite</class>
+ <widget class="QWidget" name="TabDiveSite">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dive sites</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="TableView" name="diveSites" native="true"/>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>TableView</class>
+ <extends>QWidget</extends>
+ <header>desktop-widgets/tableview.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index d0e131f1e..a8dd87cb4 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -33,6 +33,7 @@
#include "TabDiveInformation.h"
#include "TabDivePhotos.h"
#include "TabDiveStatistics.h"
+#include "TabDiveSite.h"
#include <QCompleter>
#include <QSettings>
@@ -62,6 +63,8 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui.tabWidget->addTab(extraWidgets.last(), tr("Media"));
extraWidgets << new TabDiveExtraInfo();
ui.tabWidget->addTab(extraWidgets.last(), tr("Extra Info"));
+ extraWidgets << new TabDiveSite();
+ ui.tabWidget->addTab(extraWidgets.last(), tr("Dive sites"));
ui.dateEdit->setDisplayFormat(prefs.date_format);
ui.timeEdit->setDisplayFormat(prefs.time_format);
@@ -205,8 +208,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
acceptingEdit = false;
ui.diveTripLocation->hide();
-
-
}
MainTab::~MainTab()
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 129f25a6c..9796907cf 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -29,7 +29,6 @@ QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, in
CylindersModel *CylindersModel::instance()
{
-
static CylindersModel self;
return &self;
}
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
}
diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h
index 407031590..4840bff21 100644
--- a/qt-models/divelocationmodel.h
+++ b/qt-models/divelocationmodel.h
@@ -5,7 +5,6 @@
#include <QAbstractTableModel>
#include <QStringListModel>
#include <QSortFilterProxyModel>
-#include <stdint.h>
#include "core/units.h"
#define RECENTLY_ADDED_DIVESITE ((struct dive_site *)~0)
@@ -15,7 +14,7 @@ Q_OBJECT
public:
// Common columns, roles and accessor function for all dive-site models.
// Thus, different views can connect to different models.
- enum Columns { DIVESITE, NAME, LATITUDE, LONGITUDE, COORDS, DESCRIPTION, NOTES, TAXONOMY_1, TAXONOMY_2, TAXONOMY_3, COLUMNS};
+ enum Columns { REMOVE, NAME, DESCRIPTION, NUM_DIVES, COORDS, NOTES, LATITUDE, LONGITUDE, DIVESITE, TAXONOMY_1, TAXONOMY_2, TAXONOMY_3, COLUMNS};
enum Roles { DIVESITE_ROLE = Qt::UserRole + 1 };
static QVariant getDiveSiteData(const struct dive_site *ds, int column, int role);
@@ -25,6 +24,8 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index = QModelIndex(), int role = Qt::DisplayRole) const;
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
+ Qt::ItemFlags flags(const QModelIndex &index) const override;
public slots:
void update();