mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +00:00
29b242c703
This data structure was quite fragile and made 'undo' when editing rather hard to implement. So instead I decided to turn this into a QMultiMap which seemed like the ideal data structure for it. This map holds all the dive computer related data indexed by the model. As QMultiMap it allows multiple entries per key (model string) and disambiguates between them with the deviceId. This commit turned out much larger than I wanted. But I didn't manage to find a clean way to break it up and make the pieces make sense. So this brings back the Ok / Cancel button for the dive computer edit dialog. And it makes those two buttons actually do the right thing (which is what started this whole process). For this to work we simply copy the map to a working copy and do all edits on that one - and then copy that over the 'real' map when we accept the changes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
70 lines
1.6 KiB
C++
70 lines
1.6 KiB
C++
#include "divecomputermanagementdialog.h"
|
|
#include "models.h"
|
|
#include "ui_divecomputermanagementdialog.h"
|
|
#include "mainwindow.h"
|
|
#include <QMessageBox>
|
|
#include "../qthelper.h"
|
|
#include "../helpers.h"
|
|
|
|
DiveComputerManagementDialog::DiveComputerManagementDialog(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f),
|
|
ui( new Ui::DiveComputerManagementDialog()),
|
|
model(0)
|
|
{
|
|
ui->setupUi(this);
|
|
init();
|
|
connect(ui->tableView, SIGNAL(clicked(QModelIndex)), this, SLOT(tryRemove(QModelIndex)));
|
|
}
|
|
|
|
void DiveComputerManagementDialog::init()
|
|
{
|
|
if (model)
|
|
delete model;
|
|
model = new DiveComputerModel(dcList.dcMap);
|
|
ui->tableView->setModel(model);
|
|
}
|
|
|
|
DiveComputerManagementDialog* DiveComputerManagementDialog::instance()
|
|
{
|
|
static DiveComputerManagementDialog *self = new DiveComputerManagementDialog();
|
|
return self;
|
|
}
|
|
|
|
void DiveComputerManagementDialog::update()
|
|
{
|
|
model->update();
|
|
ui->tableView->resizeColumnsToContents();
|
|
ui->tableView->setColumnWidth(DiveComputerModel::REMOVE, 22);
|
|
layout()->activate();
|
|
}
|
|
|
|
void DiveComputerManagementDialog::tryRemove(const QModelIndex& index)
|
|
{
|
|
if (index.column() != DiveComputerModel::REMOVE){
|
|
return;
|
|
}
|
|
|
|
QMessageBox::StandardButton response = QMessageBox::question(
|
|
this,
|
|
tr("Remove the selected Dive Computer?"),
|
|
tr("Are you sure that you want to \n remove the selected dive computer?"),
|
|
QMessageBox::Ok | QMessageBox::Cancel
|
|
);
|
|
|
|
if (response == QMessageBox::Ok){
|
|
model->remove(index);
|
|
}
|
|
}
|
|
|
|
void DiveComputerManagementDialog::accept()
|
|
{
|
|
model->keepWorkingList();
|
|
hide();
|
|
close();
|
|
}
|
|
|
|
void DiveComputerManagementDialog::reject()
|
|
{
|
|
model->dropWorkingList();
|
|
hide();
|
|
close();
|
|
}
|