2017-04-27 18:26:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/divecomputermanagementdialog.h"
|
|
|
|
#include "desktop-widgets/mainwindow.h"
|
2018-06-03 20:15:19 +00:00
|
|
|
#include "core/qthelper.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/divecomputermodel.h"
|
2013-06-07 18:34:27 +00:00
|
|
|
#include <QMessageBox>
|
2014-04-25 18:32:02 +00:00
|
|
|
#include <QShortcut>
|
2013-06-07 14:43:45 +00:00
|
|
|
|
2018-06-15 19:30:49 +00:00
|
|
|
DiveComputerManagementDialog::DiveComputerManagementDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
2013-06-07 14:43:45 +00:00
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.setupUi(this);
|
2013-06-17 22:58:26 +00:00
|
|
|
init();
|
2013-10-03 18:54:25 +00:00
|
|
|
connect(ui.tableView, SIGNAL(clicked(QModelIndex)), this, SLOT(tryRemove(QModelIndex)));
|
2014-04-25 18:32:02 +00:00
|
|
|
QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
|
|
|
|
connect(close, SIGNAL(activated()), this, SLOT(close()));
|
|
|
|
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
|
|
|
|
connect(quit, SIGNAL(activated()), parent, SLOT(close()));
|
2013-06-07 14:43:45 +00:00
|
|
|
}
|
|
|
|
|
2013-06-17 22:58:26 +00:00
|
|
|
void DiveComputerManagementDialog::init()
|
|
|
|
{
|
2018-06-15 19:30:49 +00:00
|
|
|
model.reset(new DiveComputerModel(dcList.dcMap));
|
|
|
|
ui.tableView->setModel(model.data());
|
2013-06-17 22:58:26 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
DiveComputerManagementDialog *DiveComputerManagementDialog::instance()
|
2013-06-07 14:43:45 +00:00
|
|
|
{
|
2014-02-12 14:22:54 +00:00
|
|
|
static DiveComputerManagementDialog *self = new DiveComputerManagementDialog(MainWindow::instance());
|
2013-06-07 14:43:45 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiveComputerManagementDialog::update()
|
|
|
|
{
|
|
|
|
model->update();
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.tableView->resizeColumnsToContents();
|
|
|
|
ui.tableView->setColumnWidth(DiveComputerModel::REMOVE, 22);
|
2013-06-17 19:42:52 +00:00
|
|
|
layout()->activate();
|
2013-06-07 14:43:45 +00:00
|
|
|
}
|
2013-06-07 18:34:27 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveComputerManagementDialog::tryRemove(const QModelIndex &index)
|
2013-06-07 18:34:27 +00:00
|
|
|
{
|
2013-10-11 13:21:04 +00:00
|
|
|
if (index.column() != DiveComputerModel::REMOVE)
|
2013-06-07 18:34:27 +00:00
|
|
|
return;
|
2013-06-17 19:42:52 +00:00
|
|
|
|
2013-06-07 18:34:27 +00:00
|
|
|
QMessageBox::StandardButton response = QMessageBox::question(
|
2014-02-28 04:09:57 +00:00
|
|
|
this, TITLE_OR_TEXT(
|
2014-07-11 08:21:38 +00:00
|
|
|
tr("Remove the selected dive computer?"),
|
2014-02-28 04:09:57 +00:00
|
|
|
tr("Are you sure that you want to \n remove the selected dive computer?")),
|
|
|
|
QMessageBox::Ok | QMessageBox::Cancel);
|
2013-06-17 19:42:52 +00:00
|
|
|
|
2013-10-11 13:21:04 +00:00
|
|
|
if (response == QMessageBox::Ok)
|
2013-06-07 18:34:27 +00:00
|
|
|
model->remove(index);
|
|
|
|
}
|
2013-06-17 22:58:26 +00:00
|
|
|
|
|
|
|
void DiveComputerManagementDialog::accept()
|
|
|
|
{
|
|
|
|
model->keepWorkingList();
|
|
|
|
hide();
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiveComputerManagementDialog::reject()
|
|
|
|
{
|
|
|
|
model->dropWorkingList();
|
|
|
|
hide();
|
|
|
|
close();
|
|
|
|
}
|