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