From fa7dfa37102fe2b0cf7518c329c3ba0273e39ab9 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 12 Sep 2020 23:31:46 +0200 Subject: [PATCH] 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 --- desktop-widgets/CMakeLists.txt | 3 ++ desktop-widgets/tab-widgets/TabBase.cpp | 1 - .../tab-widgets/TabDiveComputer.cpp | 32 +++++++++++++++++++ desktop-widgets/tab-widgets/TabDiveComputer.h | 23 +++++++++++++ .../tab-widgets/TabDiveComputer.ui | 29 +++++++++++++++++ desktop-widgets/tab-widgets/maintab.cpp | 10 ++++-- qt-models/divecomputermodel.cpp | 8 +++++ qt-models/divecomputermodel.h | 1 + 8 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 desktop-widgets/tab-widgets/TabDiveComputer.cpp create mode 100644 desktop-widgets/tab-widgets/TabDiveComputer.h create mode 100644 desktop-widgets/tab-widgets/TabDiveComputer.ui 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 @@ + + + TabDiveComputer + + + + 0 + 0 + 400 + 300 + + + + + + + + + + + TableView + QWidget +
desktop-widgets/tableview.h
+ 1 +
+
+ + +
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 #include @@ -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 diff --git a/qt-models/divecomputermodel.cpp b/qt-models/divecomputermodel.cpp index d0b9f7637..356e24ef8 100644 --- a/qt-models/divecomputermodel.cpp +++ b/qt-models/divecomputermodel.cpp @@ -113,3 +113,11 @@ bool DiveComputerSortedModel::lessThan(const QModelIndex &i1, const QModelIndex return sortHelper(i1, i2, DiveComputerModel::MODEL, DiveComputerModel::ID); } } + +void DiveComputerSortedModel::remove(const QModelIndex &index) +{ + int row = mapToSource(index).row(); + if (row < 0 || row >= (int)device_table.devices.size()) + return; + device_table.devices.erase(device_table.devices.begin() + row); +} diff --git a/qt-models/divecomputermodel.h b/qt-models/divecomputermodel.h index b21eadcc9..7f3d4171f 100644 --- a/qt-models/divecomputermodel.h +++ b/qt-models/divecomputermodel.h @@ -33,6 +33,7 @@ private: class DiveComputerSortedModel : public QSortFilterProxyModel { public: using QSortFilterProxyModel::QSortFilterProxyModel; + void remove(const QModelIndex &index); private: bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const; };