2018-07-23 21:41:23 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
#include "command.h"
|
|
|
|
#include "command_divelist.h"
|
2019-03-12 21:35:43 +00:00
|
|
|
#include "command_divesite.h"
|
2019-01-25 17:27:31 +00:00
|
|
|
#include "command_edit.h"
|
2019-02-24 20:22:33 +00:00
|
|
|
#include "command_edit_trip.h"
|
2020-03-03 21:34:50 +00:00
|
|
|
#include "command_event.h"
|
2020-05-27 07:31:26 +00:00
|
|
|
#include "command_filter.h"
|
2020-04-14 20:07:00 +00:00
|
|
|
#include "command_pictures.h"
|
2018-07-23 21:41:23 +00:00
|
|
|
|
|
|
|
namespace Command {
|
|
|
|
|
|
|
|
// Dive-list related commands
|
2019-03-28 16:23:35 +00:00
|
|
|
void addDive(dive *d, bool autogroup, bool newNumber)
|
2018-07-23 21:41:23 +00:00
|
|
|
{
|
2019-03-28 16:23:35 +00:00
|
|
|
execute(new AddDive(d, autogroup, newNumber));
|
2018-07-23 21:41:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-28 13:24:19 +00:00
|
|
|
void importDives(struct dive_table *dives, struct trip_table *trips, struct dive_site_table *sites,
|
2020-10-17 14:07:39 +00:00
|
|
|
struct device_table *devices, struct filter_preset_table *presets,
|
|
|
|
int flags, const QString &source)
|
2018-12-23 22:45:12 +00:00
|
|
|
{
|
2020-10-17 14:07:39 +00:00
|
|
|
execute(new ImportDives(dives, trips, sites, devices, presets, flags, source));
|
2018-12-23 22:45:12 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 21:41:23 +00:00
|
|
|
void deleteDive(const QVector<struct dive*> &divesToDelete)
|
|
|
|
{
|
|
|
|
execute(new DeleteDive(divesToDelete));
|
|
|
|
}
|
|
|
|
|
2020-01-03 15:04:54 +00:00
|
|
|
void shiftTime(const std::vector<dive *> &changedDives, int amount)
|
2018-07-23 21:41:23 +00:00
|
|
|
{
|
|
|
|
execute(new ShiftTime(changedDives, amount));
|
|
|
|
}
|
|
|
|
|
2018-07-30 13:55:29 +00:00
|
|
|
void renumberDives(const QVector<QPair<dive *, int>> &divesToRenumber)
|
2018-07-23 21:41:23 +00:00
|
|
|
{
|
|
|
|
execute(new RenumberDives(divesToRenumber));
|
|
|
|
}
|
|
|
|
|
|
|
|
void removeDivesFromTrip(const QVector<dive *> &divesToRemove)
|
|
|
|
{
|
|
|
|
execute(new RemoveDivesFromTrip(divesToRemove));
|
|
|
|
}
|
|
|
|
|
|
|
|
void removeAutogenTrips()
|
|
|
|
{
|
|
|
|
execute(new RemoveAutogenTrips);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addDivesToTrip(const QVector<dive *> &divesToAddIn, dive_trip *trip)
|
|
|
|
{
|
|
|
|
execute(new AddDivesToTrip(divesToAddIn, trip));
|
|
|
|
}
|
|
|
|
|
|
|
|
void createTrip(const QVector<dive *> &divesToAddIn)
|
|
|
|
{
|
|
|
|
execute(new CreateTrip(divesToAddIn));
|
|
|
|
}
|
|
|
|
|
|
|
|
void autogroupDives()
|
|
|
|
{
|
|
|
|
execute(new AutogroupDives);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mergeTrips(dive_trip *trip1, dive_trip *trip2)
|
|
|
|
{
|
|
|
|
execute(new MergeTrips(trip1, trip2));
|
|
|
|
}
|
|
|
|
|
|
|
|
void splitDives(dive *d, duration_t time)
|
|
|
|
{
|
|
|
|
execute(new SplitDives(d, time));
|
|
|
|
}
|
|
|
|
|
2019-03-31 08:20:13 +00:00
|
|
|
void splitDiveComputer(dive *d, int dc_num)
|
|
|
|
{
|
|
|
|
execute(new SplitDiveComputer(d, dc_num));
|
|
|
|
}
|
|
|
|
|
2019-05-17 20:22:55 +00:00
|
|
|
void moveDiveComputerToFront(dive *d, int dc_num)
|
|
|
|
{
|
|
|
|
execute(new MoveDiveComputerToFront(d, dc_num));
|
|
|
|
}
|
|
|
|
|
2019-05-19 12:27:10 +00:00
|
|
|
void deleteDiveComputer(dive *d, int dc_num)
|
|
|
|
{
|
|
|
|
execute(new DeleteDiveComputer(d, dc_num));
|
|
|
|
}
|
|
|
|
|
2018-07-23 21:41:23 +00:00
|
|
|
void mergeDives(const QVector <dive *> &dives)
|
|
|
|
{
|
|
|
|
execute(new MergeDives(dives));
|
|
|
|
}
|
|
|
|
|
2019-03-12 21:35:43 +00:00
|
|
|
// Dive site related commands
|
|
|
|
void deleteDiveSites(const QVector <dive_site *> &sites)
|
|
|
|
{
|
|
|
|
execute(new DeleteDiveSites(sites));
|
|
|
|
}
|
|
|
|
|
2019-03-12 22:51:39 +00:00
|
|
|
void editDiveSiteName(dive_site *ds, const QString &value)
|
|
|
|
{
|
|
|
|
execute(new EditDiveSiteName(ds, value));
|
|
|
|
}
|
|
|
|
|
2019-03-13 19:10:22 +00:00
|
|
|
void editDiveSiteDescription(dive_site *ds, const QString &value)
|
|
|
|
{
|
|
|
|
execute(new EditDiveSiteDescription(ds, value));
|
|
|
|
}
|
|
|
|
|
2019-03-13 23:00:54 +00:00
|
|
|
void editDiveSiteNotes(dive_site *ds, const QString &value)
|
|
|
|
{
|
|
|
|
execute(new EditDiveSiteNotes(ds, value));
|
|
|
|
}
|
|
|
|
|
2019-03-14 07:26:50 +00:00
|
|
|
void editDiveSiteCountry(dive_site *ds, const QString &value)
|
|
|
|
{
|
|
|
|
execute(new EditDiveSiteCountry(ds, value));
|
|
|
|
}
|
|
|
|
|
2019-03-14 22:28:45 +00:00
|
|
|
void editDiveSiteLocation(dive_site *ds, location_t value)
|
2019-03-14 21:07:48 +00:00
|
|
|
{
|
|
|
|
execute(new EditDiveSiteLocation(ds, value));
|
|
|
|
}
|
|
|
|
|
2019-03-15 13:32:55 +00:00
|
|
|
void editDiveSiteTaxonomy(dive_site *ds, taxonomy_data &value)
|
|
|
|
{
|
|
|
|
execute(new EditDiveSiteTaxonomy(ds, value));
|
|
|
|
}
|
|
|
|
|
2019-03-13 19:58:25 +00:00
|
|
|
void addDiveSite(const QString &name)
|
|
|
|
{
|
|
|
|
execute(new AddDiveSite(name));
|
|
|
|
}
|
|
|
|
|
2019-05-05 03:40:27 +00:00
|
|
|
void importDiveSites(struct dive_site_table *sites, const QString &source)
|
|
|
|
{
|
|
|
|
execute(new ImportDiveSites(sites, source));
|
|
|
|
}
|
|
|
|
|
2019-03-15 16:41:31 +00:00
|
|
|
void mergeDiveSites(dive_site *ds, const QVector<dive_site *> &sites)
|
|
|
|
{
|
|
|
|
execute(new MergeDiveSites(ds, sites));
|
|
|
|
}
|
|
|
|
|
2019-03-19 18:52:54 +00:00
|
|
|
void purgeUnusedDiveSites()
|
|
|
|
{
|
|
|
|
execute(new PurgeUnusedDiveSites);
|
|
|
|
}
|
|
|
|
|
2019-11-16 20:35:26 +00:00
|
|
|
void applyGPSFixes(const std::vector<DiveAndLocation> &fixes)
|
|
|
|
{
|
|
|
|
execute(new ApplyGPSFixes(fixes));
|
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
// Execute an edit-command and return number of edited dives
|
|
|
|
static int execute_edit(EditDivesBase *cmd)
|
|
|
|
{
|
2019-05-24 19:17:22 +00:00
|
|
|
int count = cmd->numDives();
|
|
|
|
return execute(cmd) ? count : 0;
|
2019-05-23 18:27:19 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 17:27:31 +00:00
|
|
|
// Dive editing related commands
|
2019-05-23 18:27:19 +00:00
|
|
|
int editNotes(const QString &newValue, bool currentDiveOnly)
|
2019-01-25 17:27:31 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditNotes(newValue, currentDiveOnly));
|
2019-01-25 17:27:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editMode(int index, int newValue, bool currentDiveOnly)
|
2019-01-28 17:35:27 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditMode(index, newValue, currentDiveOnly));
|
2019-07-17 13:49:45 +00:00
|
|
|
}
|
|
|
|
|
2019-12-12 22:07:17 +00:00
|
|
|
int editInvalid(int newValue, bool currentDiveOnly)
|
|
|
|
{
|
|
|
|
return execute_edit(new EditInvalid(newValue, currentDiveOnly));
|
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editSuit(const QString &newValue, bool currentDiveOnly)
|
2019-01-28 20:42:59 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditSuit(newValue, currentDiveOnly));
|
2019-01-28 20:42:59 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editRating(int newValue, bool currentDiveOnly)
|
2019-01-28 21:35:07 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditRating(newValue, currentDiveOnly));
|
2019-01-28 21:35:07 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editVisibility(int newValue, bool currentDiveOnly)
|
2019-01-28 21:35:07 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditVisibility(newValue, currentDiveOnly));
|
2019-01-28 21:35:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 19:04:52 +00:00
|
|
|
int editWaveSize(int newValue, bool currentDiveOnly)
|
|
|
|
{
|
|
|
|
return execute_edit(new EditWaveSize(newValue, currentDiveOnly));
|
|
|
|
}
|
|
|
|
|
|
|
|
int editCurrent(int newValue, bool currentDiveOnly)
|
|
|
|
{
|
|
|
|
return execute_edit(new EditCurrent(newValue, currentDiveOnly));
|
|
|
|
}
|
|
|
|
|
|
|
|
int editSurge(int newValue, bool currentDiveOnly)
|
|
|
|
{
|
|
|
|
return execute_edit(new EditSurge(newValue, currentDiveOnly));
|
|
|
|
}
|
|
|
|
|
|
|
|
int editChill(int newValue, bool currentDiveOnly)
|
|
|
|
{
|
|
|
|
return execute_edit(new EditChill(newValue, currentDiveOnly));
|
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editAirTemp(int newValue, bool currentDiveOnly)
|
2019-01-30 21:13:24 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditAirTemp(newValue, currentDiveOnly));
|
2019-01-30 21:13:24 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editWaterTemp(int newValue, bool currentDiveOnly)
|
2019-01-30 21:13:24 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditWaterTemp(newValue, currentDiveOnly));
|
2019-01-30 21:13:24 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editAtmPress(int newValue, bool currentDiveOnly)
|
2019-04-30 10:42:33 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditAtmPress(newValue, currentDiveOnly));
|
2019-04-30 10:42:33 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 17:16:45 +00:00
|
|
|
int editWaterTypeUser(int newValue, bool currentDiveOnly)
|
|
|
|
{
|
|
|
|
return execute_edit(new EditWaterTypeUser(newValue, currentDiveOnly));
|
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editDepth(int newValue, bool currentDiveOnly)
|
2019-02-10 16:37:06 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditDepth(newValue, currentDiveOnly));
|
2019-02-10 16:37:06 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editDuration(int newValue, bool currentDiveOnly)
|
2019-02-10 16:37:06 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditDuration(newValue, currentDiveOnly));
|
2019-02-10 16:37:06 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editDiveSite(struct dive_site *newValue, bool currentDiveOnly)
|
2019-03-20 20:46:58 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditDiveSite(newValue, currentDiveOnly));
|
2019-03-20 20:46:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editDiveSiteNew(const QString &newName, bool currentDiveOnly)
|
2019-03-20 20:46:58 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditDiveSiteNew(newName, currentDiveOnly));
|
2019-03-20 20:46:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editTags(const QStringList &newList, bool currentDiveOnly)
|
2019-02-07 18:59:34 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditTags(newList, currentDiveOnly));
|
2019-02-07 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editBuddies(const QStringList &newList, bool currentDiveOnly)
|
2019-02-07 20:00:09 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditBuddies(newList, currentDiveOnly));
|
2019-02-07 20:00:09 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:27:19 +00:00
|
|
|
int editDiveMaster(const QStringList &newList, bool currentDiveOnly)
|
2019-02-07 20:23:00 +00:00
|
|
|
{
|
2019-05-23 18:27:19 +00:00
|
|
|
return execute_edit(new EditDiveMaster(newList, currentDiveOnly));
|
2019-02-07 20:23:00 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 17:17:20 +00:00
|
|
|
void pasteDives(const dive *d, dive_components what)
|
|
|
|
{
|
|
|
|
execute(new PasteDives(d, what));
|
|
|
|
}
|
|
|
|
|
2019-10-06 18:54:25 +00:00
|
|
|
void replanDive(dive *d)
|
|
|
|
{
|
2019-11-30 14:51:34 +00:00
|
|
|
execute(new ReplanDive(d, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
void editProfile(dive *d)
|
|
|
|
{
|
|
|
|
execute(new ReplanDive(d, true));
|
2019-10-06 18:54:25 +00:00
|
|
|
}
|
|
|
|
|
2019-11-02 20:19:29 +00:00
|
|
|
int addWeight(bool currentDiveOnly)
|
|
|
|
{
|
|
|
|
return execute_edit(new AddWeight(currentDiveOnly));
|
|
|
|
}
|
|
|
|
|
2019-11-03 14:04:48 +00:00
|
|
|
int removeWeight(int index, bool currentDiveOnly)
|
|
|
|
{
|
|
|
|
return execute_edit(new RemoveWeight(index, currentDiveOnly));
|
|
|
|
}
|
|
|
|
|
2019-11-08 21:47:38 +00:00
|
|
|
int editWeight(int index, weightsystem_t ws, bool currentDiveOnly)
|
|
|
|
{
|
|
|
|
return execute_edit(new EditWeight(index, ws, currentDiveOnly));
|
|
|
|
}
|
|
|
|
|
2020-02-23 10:43:50 +00:00
|
|
|
int addCylinder(bool currentDiveOnly)
|
|
|
|
{
|
|
|
|
return execute_edit(new AddCylinder(currentDiveOnly));
|
|
|
|
}
|
|
|
|
|
|
|
|
int removeCylinder(int index, bool currentDiveOnly)
|
|
|
|
{
|
|
|
|
return execute_edit(new RemoveCylinder(index, currentDiveOnly));
|
|
|
|
}
|
|
|
|
|
2020-03-27 20:09:59 +00:00
|
|
|
int editCylinder(int index, cylinder_t cyl, EditCylinderType type, bool currentDiveOnly)
|
2020-02-23 10:43:50 +00:00
|
|
|
{
|
2020-03-27 20:09:59 +00:00
|
|
|
return execute_edit(new EditCylinder(index, cyl, type, currentDiveOnly));
|
2020-02-23 10:43:50 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 18:30:10 +00:00
|
|
|
// Trip editing related commands
|
2019-02-24 20:22:33 +00:00
|
|
|
void editTripLocation(dive_trip *trip, const QString &s)
|
|
|
|
{
|
|
|
|
execute(new EditTripLocation(trip, s));
|
|
|
|
}
|
|
|
|
|
|
|
|
void editTripNotes(dive_trip *trip, const QString &s)
|
|
|
|
{
|
|
|
|
execute(new EditTripNotes(trip, s));
|
|
|
|
}
|
|
|
|
|
2020-01-10 00:25:37 +00:00
|
|
|
#ifdef SUBSURFACE_MOBILE
|
|
|
|
void editDive(dive *oldDive, dive *newDive, dive_site *createDs, dive_site *changeDs, location_t dsLocation)
|
|
|
|
{
|
|
|
|
execute(new EditDive(oldDive, newDive, createDs, changeDs, dsLocation));
|
|
|
|
}
|
|
|
|
#endif // SUBSURFACE_MOBILE
|
|
|
|
|
2020-03-03 21:34:50 +00:00
|
|
|
// Event commands
|
|
|
|
|
|
|
|
void addEventBookmark(struct dive *d, int dcNr, int seconds)
|
|
|
|
{
|
|
|
|
execute(new AddEventBookmark(d, dcNr, seconds));
|
|
|
|
}
|
|
|
|
|
2020-03-03 21:54:54 +00:00
|
|
|
void addEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode)
|
|
|
|
{
|
|
|
|
execute(new AddEventDivemodeSwitch(d, dcNr, seconds, divemode));
|
|
|
|
}
|
|
|
|
|
2020-03-03 22:31:46 +00:00
|
|
|
void addEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2)
|
|
|
|
{
|
|
|
|
execute(new AddEventSetpointChange(d, dcNr, seconds, pO2));
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:13:02 +00:00
|
|
|
void renameEvent(struct dive *d, int dcNr, struct event *ev, const char *name)
|
|
|
|
{
|
|
|
|
execute(new RenameEvent(d, dcNr, ev, name));
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:25:47 +00:00
|
|
|
void removeEvent(struct dive *d, int dcNr, struct event *ev)
|
|
|
|
{
|
|
|
|
execute(new RemoveEvent(d, dcNr, ev));
|
|
|
|
}
|
|
|
|
|
2020-03-04 20:10:05 +00:00
|
|
|
void addGasSwitch(struct dive *d, int dcNr, int seconds, int tank)
|
|
|
|
{
|
|
|
|
execute(new AddGasSwitch(d, dcNr, seconds, tank));
|
|
|
|
}
|
|
|
|
|
2020-04-14 20:07:00 +00:00
|
|
|
// Picture (media) commands
|
|
|
|
|
|
|
|
void setPictureOffset(dive *d, const QString &filename, offset_t offset)
|
|
|
|
{
|
|
|
|
execute(new SetPictureOffset(d, filename, offset));
|
|
|
|
}
|
|
|
|
|
2020-04-17 21:18:58 +00:00
|
|
|
void removePictures(const std::vector<PictureListForDeletion> &pictures)
|
|
|
|
{
|
|
|
|
execute(new RemovePictures(pictures));
|
|
|
|
}
|
|
|
|
|
2020-04-19 16:48:23 +00:00
|
|
|
void addPictures(const std::vector<PictureListForAddition> &pictures)
|
|
|
|
{
|
|
|
|
execute(new AddPictures(pictures));
|
|
|
|
}
|
|
|
|
|
2020-05-27 07:31:26 +00:00
|
|
|
void createFilterPreset(const QString &name, const FilterData &data)
|
|
|
|
{
|
|
|
|
execute(new CreateFilterPreset(name, data));
|
|
|
|
}
|
|
|
|
|
|
|
|
void removeFilterPreset(int index)
|
|
|
|
{
|
|
|
|
execute(new RemoveFilterPreset(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
void editFilterPreset(int index, const FilterData &data)
|
|
|
|
{
|
|
|
|
execute(new EditFilterPreset(index, data));
|
|
|
|
}
|
|
|
|
|
2018-07-23 21:41:23 +00:00
|
|
|
} // namespace Command
|