2019-03-09 21:32:16 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include "TabDiveSite.h"
|
2019-03-13 20:36:31 +00:00
|
|
|
#include "core/subsurface-qt/DiveListNotifier.h"
|
|
|
|
#include "core/divesite.h"
|
2019-03-09 21:32:16 +00:00
|
|
|
#include "qt-models/divelocationmodel.h"
|
2019-03-13 19:58:25 +00:00
|
|
|
#include "desktop-widgets/command.h"
|
2019-03-09 21:32:16 +00:00
|
|
|
|
|
|
|
#include <qt-models/divecomputerextradatamodel.h>
|
|
|
|
|
|
|
|
TabDiveSite::TabDiveSite(QWidget *parent) : TabBase(parent)
|
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
ui.diveSites->setTitle(tr("Dive sites"));
|
2019-03-12 16:28:43 +00:00
|
|
|
ui.diveSites->setModel(&model);
|
|
|
|
// Default: sort by name
|
|
|
|
ui.diveSites->view()->sortByColumn(LocationInformationModel::NAME, Qt::AscendingOrder);
|
|
|
|
ui.diveSites->view()->setSortingEnabled(true);
|
2019-03-16 11:09:58 +00:00
|
|
|
ui.diveSites->view()->horizontalHeader()->setSectionResizeMode(LocationInformationModel::NAME, QHeaderView::Stretch);
|
|
|
|
ui.diveSites->view()->horizontalHeader()->setSectionResizeMode(LocationInformationModel::DESCRIPTION, QHeaderView::Stretch);
|
2019-03-09 21:32:16 +00:00
|
|
|
|
|
|
|
// Show only the first few columns
|
2019-03-14 21:07:48 +00:00
|
|
|
for (int i = LocationInformationModel::LOCATION; i < LocationInformationModel::COLUMNS; ++i)
|
2019-03-09 21:32:16 +00:00
|
|
|
ui.diveSites->view()->setColumnHidden(i, true);
|
2019-03-13 19:58:25 +00:00
|
|
|
|
|
|
|
connect(ui.diveSites, &TableView::addButtonClicked, this, &TabDiveSite::add);
|
2019-03-13 20:56:41 +00:00
|
|
|
|
|
|
|
// Subtle: We depend on this slot being executed after the slot in the model.
|
|
|
|
// This is realized because the model was constructed as a member object and connects in the constructor.
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &TabDiveSite::diveSiteChanged);
|
2019-03-09 21:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabDiveSite::updateData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabDiveSite::clear()
|
|
|
|
{
|
|
|
|
}
|
2019-03-13 19:58:25 +00:00
|
|
|
|
|
|
|
void TabDiveSite::add()
|
|
|
|
{
|
2019-03-13 20:36:31 +00:00
|
|
|
// This is mighty dirty: We hook into the "dive site added" signal and
|
|
|
|
// select the name field of the added dive site when the command sends
|
|
|
|
// the signal. This works only because we know that the model added the
|
|
|
|
// connection first. Very subtle!
|
|
|
|
// After the command has finished, the signal is disconnected so that dive
|
|
|
|
// site names are not selected on regular redo / undo.
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::diveSiteAdded, this, &TabDiveSite::diveSiteAdded);
|
2019-03-13 19:58:25 +00:00
|
|
|
Command::addDiveSite(tr("New dive site"));
|
2019-03-13 20:36:31 +00:00
|
|
|
disconnect(&diveListNotifier, &DiveListNotifier::diveSiteAdded, this, &TabDiveSite::diveSiteAdded);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabDiveSite::diveSiteAdded(struct dive_site *, int idx)
|
|
|
|
{
|
|
|
|
if (idx < 0)
|
|
|
|
return;
|
|
|
|
QModelIndex globalIdx = LocationInformationModel::instance()->index(idx, LocationInformationModel::NAME);
|
|
|
|
QModelIndex localIdx = model.mapFromSource(globalIdx);
|
|
|
|
ui.diveSites->view()->setCurrentIndex(localIdx);
|
|
|
|
ui.diveSites->view()->edit(localIdx);
|
2019-03-13 19:58:25 +00:00
|
|
|
}
|
2019-03-13 20:56:41 +00:00
|
|
|
|
|
|
|
void TabDiveSite::diveSiteChanged(struct dive_site *ds, int field)
|
|
|
|
{
|
|
|
|
int idx = get_divesite_idx(ds, &dive_site_table);
|
|
|
|
if (idx < 0)
|
|
|
|
return;
|
|
|
|
QModelIndex globalIdx = LocationInformationModel::instance()->index(idx, field);
|
|
|
|
QModelIndex localIdx = model.mapFromSource(globalIdx);
|
|
|
|
ui.diveSites->view()->scrollTo(localIdx);
|
|
|
|
}
|
2019-03-19 18:52:54 +00:00
|
|
|
|
|
|
|
void TabDiveSite::on_purgeUnused_clicked()
|
|
|
|
{
|
|
|
|
Command::purgeUnusedDiveSites();
|
|
|
|
}
|
2019-03-24 16:11:29 +00:00
|
|
|
|
|
|
|
void TabDiveSite::on_filterText_textChanged(const QString &text)
|
|
|
|
{
|
|
|
|
model.setFilter(text);
|
|
|
|
}
|