mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Add ability to undo removing of dives from trips
Add the functionality to undo/redo removing of dives from trips. The code calling remove_dive_from_trip has moved to the UndoCommands class. Signed-off-by: Grace Karanja <gracie.karanja89@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
8e32faa866
commit
193edd9f13
3 changed files with 44 additions and 1 deletions
|
@ -622,10 +622,14 @@ void DiveListView::removeFromTrip()
|
||||||
//TODO: move this to C-code.
|
//TODO: move this to C-code.
|
||||||
int i;
|
int i;
|
||||||
struct dive *d;
|
struct dive *d;
|
||||||
|
QMap<struct dive*, dive_trip*> divesToRemove;
|
||||||
for_each_dive (i, d) {
|
for_each_dive (i, d) {
|
||||||
if (d->selected)
|
if (d->selected)
|
||||||
remove_dive_from_trip(d, false);
|
divesToRemove.insert(d, d->divetrip);
|
||||||
}
|
}
|
||||||
|
UndoRemoveDivesFromTrip *undoCommand = new UndoRemoveDivesFromTrip(divesToRemove);
|
||||||
|
MainWindow::instance()->undoStack->push(undoCommand);
|
||||||
|
|
||||||
rememberSelection();
|
rememberSelection();
|
||||||
reload(currentLayout, false);
|
reload(currentLayout, false);
|
||||||
fixMessyQtModelBehaviour();
|
fixMessyQtModelBehaviour();
|
||||||
|
|
|
@ -92,3 +92,32 @@ void UndoRenumberDives::redo()
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
MainWindow::instance()->refreshDisplay();
|
MainWindow::instance()->refreshDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UndoRemoveDivesFromTrip::UndoRemoveDivesFromTrip(QMap<dive *, dive_trip *> removedDives)
|
||||||
|
{
|
||||||
|
divesToUndo = removedDives;
|
||||||
|
setText("remove dive(s) from trip");
|
||||||
|
}
|
||||||
|
|
||||||
|
void UndoRemoveDivesFromTrip::undo()
|
||||||
|
{
|
||||||
|
QMapIterator<dive*, dive_trip*> i(divesToUndo);
|
||||||
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
add_dive_to_trip(i.key (), i.value());
|
||||||
|
}
|
||||||
|
mark_divelist_changed(true);
|
||||||
|
MainWindow::instance()->refreshDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UndoRemoveDivesFromTrip::redo()
|
||||||
|
{
|
||||||
|
QMapIterator<dive*, dive_trip*> i(divesToUndo);
|
||||||
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
remove_dive_from_trip(i.key(), false);
|
||||||
|
}
|
||||||
|
mark_divelist_changed(true);
|
||||||
|
MainWindow::instance()->refreshDisplay();
|
||||||
|
}
|
||||||
|
|
|
@ -37,4 +37,14 @@ private:
|
||||||
int start;
|
int start;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UndoRemoveDivesFromTrip : public QUndoCommand {
|
||||||
|
public:
|
||||||
|
UndoRemoveDivesFromTrip(QMap<struct dive*, dive_trip*> removedDives);
|
||||||
|
virtual void undo();
|
||||||
|
virtual void redo();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMap<struct dive*, dive_trip*> divesToUndo;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // UNDOCOMMANDS_H
|
#endif // UNDOCOMMANDS_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue