2019-05-05 03:51:16 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include "desktop-widgets/divesiteimportdialog.h"
|
2019-11-13 14:08:40 +00:00
|
|
|
#include "commands/command.h"
|
2019-05-05 03:51:16 +00:00
|
|
|
#include "core/qthelper.h"
|
|
|
|
#include "core/metrics.h"
|
|
|
|
#include "core/subsurface-string.h"
|
|
|
|
#include "desktop-widgets/mainwindow.h"
|
|
|
|
#include "qt-models/divesiteimportmodel.h"
|
|
|
|
#include "qt-models/models.h"
|
|
|
|
|
|
|
|
#include <QShortcut>
|
|
|
|
|
2024-05-11 09:47:45 +00:00
|
|
|
DivesiteImportDialog::DivesiteImportDialog(dive_site_table imported, QString source, QWidget *parent) : QDialog(parent),
|
|
|
|
importedSites(std::move(imported)),
|
|
|
|
importedSource(std::move(source)),
|
2024-05-12 20:09:18 +00:00
|
|
|
divesiteImportedModel(std::make_unique<DivesiteImportedModel>(importedSites))
|
2019-05-05 03:51:16 +00:00
|
|
|
{
|
2022-02-08 19:24:53 +00:00
|
|
|
QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_W), this);
|
|
|
|
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this);
|
2019-05-05 03:51:16 +00:00
|
|
|
|
|
|
|
int startingWidth = defaultModelFont().pointSize();
|
|
|
|
|
|
|
|
ui.setupUi(this);
|
2024-05-11 09:47:45 +00:00
|
|
|
ui.importedDivesitesView->setModel(divesiteImportedModel.get());
|
2019-05-05 03:51:16 +00:00
|
|
|
ui.importedDivesitesView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
ui.importedDivesitesView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
ui.importedDivesitesView->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
ui.importedDivesitesView->verticalHeader()->setVisible(false);
|
|
|
|
ui.importedDivesitesView->setColumnWidth(0, startingWidth * 14);
|
|
|
|
ui.importedDivesitesView->setColumnWidth(1, startingWidth * 12);
|
|
|
|
ui.importedDivesitesView->setColumnWidth(2, startingWidth * 8);
|
|
|
|
ui.importedDivesitesView->setColumnWidth(3, startingWidth * 14);
|
|
|
|
ui.selectAllButton->setEnabled(true);
|
|
|
|
ui.unselectAllButton->setEnabled(true);
|
|
|
|
|
2024-05-11 09:47:45 +00:00
|
|
|
connect(ui.importedDivesitesView, &QTableView::clicked, divesiteImportedModel.get(), &DivesiteImportedModel::changeSelected);
|
|
|
|
connect(ui.selectAllButton, &QPushButton::clicked, divesiteImportedModel.get(), &DivesiteImportedModel::selectAll);
|
|
|
|
connect(ui.unselectAllButton, &QPushButton::clicked, divesiteImportedModel.get(), &DivesiteImportedModel::selectNone);
|
2019-05-05 03:51:16 +00:00
|
|
|
connect(close, SIGNAL(activated()), this, SLOT(close()));
|
|
|
|
connect(quit, SIGNAL(activated()), parent, SLOT(close()));
|
|
|
|
|
|
|
|
ui.ok->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
DivesiteImportDialog::~DivesiteImportDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivesiteImportDialog::on_cancel_clicked()
|
|
|
|
{
|
|
|
|
done(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivesiteImportDialog::on_ok_clicked()
|
|
|
|
{
|
|
|
|
// delete non-selected dive sites
|
2024-05-11 09:47:45 +00:00
|
|
|
dive_site_table selectedSites;
|
|
|
|
for (size_t i = 0; i < importedSites.size(); i++) {
|
|
|
|
if (divesiteImportedModel->data(divesiteImportedModel->index(i, 0), Qt::CheckStateRole) == Qt::Checked)
|
|
|
|
selectedSites.push_back(std::move(importedSites[i]));
|
|
|
|
}
|
|
|
|
importedSites.clear(); // Hopefully, the model is not used thereafter!
|
2019-05-05 03:51:16 +00:00
|
|
|
|
2024-05-11 09:47:45 +00:00
|
|
|
Command::importDiveSites(std::move(selectedSites), importedSource);
|
2019-05-05 03:51:16 +00:00
|
|
|
accept();
|
|
|
|
}
|