summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-09-12 23:31:46 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-25 13:59:04 -0700
commitfa7dfa37102fe2b0cf7518c329c3ba0273e39ab9 (patch)
tree09562030ea022630bf1306d2e0d31ad6cb21083a /desktop-widgets
parentfaebb539091ca5550bb6b60280d692c50d547bc0 (diff)
downloadsubsurface-fa7dfa37102fe2b0cf7518c329c3ba0273e39ab9.tar.gz
desktop: add tab-widget for dive computer names
If we want to include dive computer names in the undo system, there should be visual feedback on undo/redo. This would mean opening the divecomputer dialog, which would appear quite strange. Therefore, add a tab. This is not ideal, but consistent with the dive site tab, which probably shouldn't be there either. In the future, the UI needs some rethinking. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/CMakeLists.txt3
-rw-r--r--desktop-widgets/tab-widgets/TabBase.cpp1
-rw-r--r--desktop-widgets/tab-widgets/TabDiveComputer.cpp32
-rw-r--r--desktop-widgets/tab-widgets/TabDiveComputer.h23
-rw-r--r--desktop-widgets/tab-widgets/TabDiveComputer.ui29
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp10
6 files changed, 94 insertions, 4 deletions
diff --git a/desktop-widgets/CMakeLists.txt b/desktop-widgets/CMakeLists.txt
index 53ac30faa..f86d89ad7 100644
--- a/desktop-widgets/CMakeLists.txt
+++ b/desktop-widgets/CMakeLists.txt
@@ -53,6 +53,7 @@ set (SUBSURFACE_UI
tab-widgets/TabDiveExtraInfo.ui
tab-widgets/TabDiveEquipment.ui
tab-widgets/TabDiveSite.ui
+ tab-widgets/TabDiveComputer.ui
)
# the interface, in C++
@@ -123,6 +124,8 @@ set(SUBSURFACE_INTERFACE
tab-widgets/TabDiveStatistics.h
tab-widgets/TabDiveSite.cpp
tab-widgets/TabDiveSite.h
+ tab-widgets/TabDiveComputer.cpp
+ tab-widgets/TabDiveComputer.h
tab-widgets/maintab.cpp
tab-widgets/maintab.h
tableview.cpp
diff --git a/desktop-widgets/tab-widgets/TabBase.cpp b/desktop-widgets/tab-widgets/TabBase.cpp
index 4252d8b2f..a0bfb2251 100644
--- a/desktop-widgets/tab-widgets/TabBase.cpp
+++ b/desktop-widgets/tab-widgets/TabBase.cpp
@@ -4,4 +4,3 @@
TabBase::TabBase(QWidget *parent) : QWidget(parent)
{
}
-
diff --git a/desktop-widgets/tab-widgets/TabDiveComputer.cpp b/desktop-widgets/tab-widgets/TabDiveComputer.cpp
new file mode 100644
index 000000000..b8cd32cf4
--- /dev/null
+++ b/desktop-widgets/tab-widgets/TabDiveComputer.cpp
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "TabDiveComputer.h"
+#include "ui_TabDiveExtraInfo.h"
+
+TabDiveComputer::TabDiveComputer(QWidget *parent) : TabBase(parent)
+{
+ ui.setupUi(this);
+ sortedModel.setSourceModel(&model);
+ ui.table->setModel(&sortedModel);
+ ui.table->view()->setSelectionBehavior(QAbstractItemView::SelectRows);
+ ui.table->view()->setSelectionMode(QAbstractItemView::SingleSelection);
+ ui.table->view()->setSortingEnabled(true);
+ ui.table->view()->sortByColumn(DiveComputerModel::MODEL, Qt::AscendingOrder);
+ connect(ui.table, &TableView::itemClicked, this, &TabDiveComputer::tableClicked);
+}
+
+void TabDiveComputer::updateData()
+{
+}
+
+void TabDiveComputer::clear()
+{
+}
+
+void TabDiveComputer::tableClicked(const QModelIndex &index)
+{
+ if (!index.isValid())
+ return;
+
+ if (index.column() == DiveComputerModel::REMOVE)
+ sortedModel.remove(index);
+}
diff --git a/desktop-widgets/tab-widgets/TabDiveComputer.h b/desktop-widgets/tab-widgets/TabDiveComputer.h
new file mode 100644
index 000000000..bdbb9097c
--- /dev/null
+++ b/desktop-widgets/tab-widgets/TabDiveComputer.h
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef TAB_DIVE_COMPUTER_H
+#define TAB_DIVE_COMPUTER_H
+
+#include "TabBase.h"
+#include "ui_TabDiveComputer.h"
+#include "qt-models/divecomputermodel.h"
+
+class TabDiveComputer : public TabBase {
+ Q_OBJECT
+public:
+ TabDiveComputer(QWidget *parent = 0);
+ void updateData() override;
+ void clear() override;
+public slots:
+ void tableClicked(const QModelIndex &index);
+private:
+ Ui::TabDiveComputer ui;
+ DiveComputerModel model;
+ DiveComputerSortedModel sortedModel;
+};
+
+#endif
diff --git a/desktop-widgets/tab-widgets/TabDiveComputer.ui b/desktop-widgets/tab-widgets/TabDiveComputer.ui
new file mode 100644
index 000000000..e14511fd7
--- /dev/null
+++ b/desktop-widgets/tab-widgets/TabDiveComputer.ui
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TabDiveComputer</class>
+ <widget class="QWidget" name="TabDiveComputer">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="TableView" name="table"/>
+ </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 978b22692..c322bb442 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -34,6 +34,7 @@
#include "TabDivePhotos.h"
#include "TabDiveStatistics.h"
#include "TabDiveSite.h"
+#include "TabDiveComputer.h"
#include <QCompleter>
#include <QSettings>
@@ -71,6 +72,8 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui.tabWidget->addTab(extraWidgets.last(), tr("Extra Info"));
extraWidgets << new TabDiveSite(this);
ui.tabWidget->addTab(extraWidgets.last(), tr("Dive sites"));
+ extraWidgets << new TabDiveComputer(this);
+ ui.tabWidget->addTab(extraWidgets.last(), tr("Device names"));
updateDateTimeFields();
@@ -348,11 +351,12 @@ void MainTab::updateDiveInfo()
if (editMode || MainWindow::instance()->graphics->isPlanner())
return;
- // If there is no current dive, disable all widgets except the last, which is the dive site tab.
- // TODO: Conceptually, the dive site tab shouldn't even be a tab here!
+ // If there is no current dive, disable all widgets except the last two,
+ // which are the dive site tab and the dive computer tabs.
+ // TODO: Conceptually, these two shouldn't even be a tabs here!
bool enabled = current_dive != nullptr;
ui.notesTab->setEnabled(enabled);
- for (int i = 0; i < extraWidgets.size() - 1; ++i)
+ for (int i = 0; i < extraWidgets.size() - 2; ++i)
extraWidgets[i]->setEnabled(enabled);
ignoreInput = true; // don't trigger on changes to the widgets