mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
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>
This commit is contained in:
parent
faebb53909
commit
fa7dfa3710
8 changed files with 103 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -4,4 +4,3 @@
|
|||
TabBase::TabBase(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
32
desktop-widgets/tab-widgets/TabDiveComputer.cpp
Normal file
32
desktop-widgets/tab-widgets/TabDiveComputer.cpp
Normal file
|
@ -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);
|
||||
}
|
23
desktop-widgets/tab-widgets/TabDiveComputer.h
Normal file
23
desktop-widgets/tab-widgets/TabDiveComputer.h
Normal file
|
@ -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
|
29
desktop-widgets/tab-widgets/TabDiveComputer.ui
Normal file
29
desktop-widgets/tab-widgets/TabDiveComputer.ui
Normal file
|
@ -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>
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue