mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Undo: make dive site removal undoable
Create a new undo-command for deleting dive sites. If there are dives associated with that site, the dives will be removed. The frontend is not yet updated in such a case, as that infrastructure is in a different PR. Connect the trashcan icon of the dive site table to the undo command. Currently, this code is in the dive site model, which makes little sense, but is how the TableView class works. We might want to change that when cylinder and weight editing are made undoable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
e99c4c9059
commit
8e1f736d2b
7 changed files with 153 additions and 1 deletions
|
|
@ -5,8 +5,12 @@
|
|||
#include "core/qthelper.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/metrics.h"
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
#include "cleanertablemodel.h" // for trashIcon();
|
||||
#include <QDebug>
|
||||
#include "desktop-widgets/mainwindow.h" // to place message box
|
||||
#include "desktop-widgets/command.h"
|
||||
#include <QMessageBox>
|
||||
#endif
|
||||
#include <QLineEdit>
|
||||
#include <QIcon>
|
||||
#include <core/gettextfromc.h>
|
||||
|
|
@ -219,6 +223,25 @@ QStringList DiveSiteSortedModel::allSiteNames() const
|
|||
return locationNames;
|
||||
}
|
||||
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
// TODO: Remove from model. It doesn't make sense to call the model here, which calls the undo command,
|
||||
// which in turn calls the model.
|
||||
void DiveSiteSortedModel::remove(const QModelIndex &index)
|
||||
{
|
||||
if (index.column() != LocationInformationModel::REMOVE)
|
||||
return;
|
||||
struct dive_site *ds = get_dive_site(mapToSource(index).row(), &dive_site_table);
|
||||
if (!ds)
|
||||
return;
|
||||
if (ds->dives.nr > 0 &&
|
||||
QMessageBox::warning(MainWindow::instance(), tr("Delete dive site?"),
|
||||
tr("This dive site has %n dive(s). Do you really want to delete it?\n", "", ds->dives.nr),
|
||||
QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
|
||||
return;
|
||||
Command::deleteDiveSites(QVector<dive_site *>{ds});
|
||||
}
|
||||
#endif
|
||||
|
||||
GeoReferencingOptionsModel *GeoReferencingOptionsModel::instance()
|
||||
{
|
||||
static GeoReferencingOptionsModel *self = new GeoReferencingOptionsModel();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue