2019-03-12 21:35:43 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
// Note: this header file is used by the undo-machinery and should not be included elsewhere.
|
|
|
|
|
|
|
|
#ifndef COMMAND_DIVESITE_H
|
|
|
|
#define COMMAND_DIVESITE_H
|
|
|
|
|
|
|
|
#include "command_base.h"
|
|
|
|
|
|
|
|
#include <QVector>
|
|
|
|
|
2021-09-11 21:45:35 +00:00
|
|
|
struct DiveAndLocation {
|
|
|
|
struct dive *d;
|
|
|
|
location_t location;
|
|
|
|
QString name;
|
|
|
|
};
|
|
|
|
|
2019-03-12 21:35:43 +00:00
|
|
|
// We put everything in a namespace, so that we can shorten names without polluting the global namespace
|
|
|
|
namespace Command {
|
|
|
|
|
2019-03-13 19:58:25 +00:00
|
|
|
class AddDiveSite : public Base {
|
|
|
|
public:
|
|
|
|
AddDiveSite(const QString &name);
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
|
|
|
|
// Note: we only add one dive site. Nevertheless, we use vectors so that we
|
|
|
|
// can reuse the dive site deletion code.
|
2019-05-05 03:40:27 +00:00
|
|
|
// For undo
|
2019-03-13 19:58:25 +00:00
|
|
|
std::vector<dive_site *> sitesToRemove;
|
|
|
|
|
2019-05-05 03:40:27 +00:00
|
|
|
// For redo
|
2024-05-04 11:39:04 +00:00
|
|
|
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
2019-05-05 03:40:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ImportDiveSites : public Base {
|
|
|
|
public:
|
2024-05-11 09:47:45 +00:00
|
|
|
// Note: Takes ownership of dive site table
|
|
|
|
ImportDiveSites(dive_site_table sites, const QString &source);
|
2019-05-05 03:40:27 +00:00
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
|
2019-03-13 19:58:25 +00:00
|
|
|
// For undo
|
2019-05-05 03:40:27 +00:00
|
|
|
std::vector<dive_site *> sitesToRemove;
|
|
|
|
|
|
|
|
// For redo
|
2024-05-04 11:39:04 +00:00
|
|
|
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
2019-03-13 19:58:25 +00:00
|
|
|
};
|
|
|
|
|
2019-03-12 21:35:43 +00:00
|
|
|
class DeleteDiveSites : public Base {
|
|
|
|
public:
|
|
|
|
DeleteDiveSites(const QVector<dive_site *> &sites);
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
2019-03-12 22:51:39 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2019-03-12 21:35:43 +00:00
|
|
|
|
|
|
|
// For redo
|
|
|
|
std::vector<dive_site *> sitesToRemove;
|
2019-03-19 18:52:54 +00:00
|
|
|
|
|
|
|
// For undo
|
2024-05-04 11:39:04 +00:00
|
|
|
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
2019-03-19 18:52:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PurgeUnusedDiveSites : public Base {
|
|
|
|
public:
|
|
|
|
PurgeUnusedDiveSites();
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
|
|
|
|
// For redo
|
|
|
|
std::vector<dive_site *> sitesToRemove;
|
2019-03-12 21:35:43 +00:00
|
|
|
|
|
|
|
// For undo
|
2024-05-04 11:39:04 +00:00
|
|
|
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
2019-03-12 22:51:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class EditDiveSiteName : public Base {
|
|
|
|
public:
|
|
|
|
EditDiveSiteName(dive_site *ds, const QString &name);
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
2019-03-12 21:35:43 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2019-03-12 22:51:39 +00:00
|
|
|
|
|
|
|
dive_site *ds;
|
2024-05-04 15:18:08 +00:00
|
|
|
std::string value; // Value to be set
|
2019-03-12 21:35:43 +00:00
|
|
|
};
|
|
|
|
|
2019-03-13 19:10:22 +00:00
|
|
|
class EditDiveSiteDescription : public Base {
|
|
|
|
public:
|
|
|
|
EditDiveSiteDescription(dive_site *ds, const QString &description);
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
|
|
|
|
dive_site *ds;
|
2024-05-04 15:18:08 +00:00
|
|
|
std::string value; // Value to be set
|
2019-03-13 19:10:22 +00:00
|
|
|
};
|
|
|
|
|
2019-03-13 23:00:54 +00:00
|
|
|
class EditDiveSiteNotes : public Base {
|
|
|
|
public:
|
|
|
|
EditDiveSiteNotes(dive_site *ds, const QString ¬es);
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
|
|
|
|
dive_site *ds;
|
2024-05-04 15:18:08 +00:00
|
|
|
std::string value; // Value to be set
|
2019-03-13 23:00:54 +00:00
|
|
|
};
|
|
|
|
|
2019-03-14 07:26:50 +00:00
|
|
|
class EditDiveSiteCountry : public Base {
|
|
|
|
public:
|
|
|
|
EditDiveSiteCountry(dive_site *ds, const QString &country);
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
|
|
|
|
dive_site *ds;
|
2024-05-04 11:39:04 +00:00
|
|
|
std::string value; // Value to be set
|
2019-03-14 07:26:50 +00:00
|
|
|
};
|
|
|
|
|
2019-03-14 21:07:48 +00:00
|
|
|
class EditDiveSiteLocation : public Base {
|
|
|
|
public:
|
2019-03-14 22:28:45 +00:00
|
|
|
EditDiveSiteLocation(dive_site *ds, location_t location);
|
2019-03-14 21:07:48 +00:00
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
|
|
|
|
dive_site *ds;
|
|
|
|
location_t value; // Value to be set
|
|
|
|
};
|
|
|
|
|
2019-03-15 13:32:55 +00:00
|
|
|
class EditDiveSiteTaxonomy : public Base {
|
|
|
|
public:
|
|
|
|
EditDiveSiteTaxonomy(dive_site *ds, taxonomy_data &taxonomy);
|
|
|
|
~EditDiveSiteTaxonomy(); // free taxonomy
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
|
|
|
|
dive_site *ds;
|
|
|
|
taxonomy_data value; // Value to be set
|
|
|
|
};
|
|
|
|
|
2019-03-15 16:41:31 +00:00
|
|
|
class MergeDiveSites : public Base {
|
|
|
|
public:
|
|
|
|
MergeDiveSites(dive_site *ds, const QVector<dive_site *> &sites);
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
|
|
|
|
dive_site *ds;
|
|
|
|
|
|
|
|
// For redo
|
|
|
|
std::vector<dive_site *> sitesToRemove;
|
|
|
|
|
|
|
|
// For undo
|
2024-05-04 11:39:04 +00:00
|
|
|
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
2019-03-15 16:41:31 +00:00
|
|
|
};
|
|
|
|
|
2019-11-16 20:35:26 +00:00
|
|
|
class ApplyGPSFixes : public Base {
|
|
|
|
public:
|
|
|
|
// Note: the dive site table is consumed after the call it will be empty.
|
|
|
|
ApplyGPSFixes(const std::vector<DiveAndLocation> &fixes);
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
|
|
|
|
// For undo
|
|
|
|
std::vector<dive_site *> sitesToRemove;
|
|
|
|
|
|
|
|
// For redo
|
2024-05-04 11:39:04 +00:00
|
|
|
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
2019-11-16 20:35:26 +00:00
|
|
|
|
|
|
|
// For redo and undo
|
|
|
|
struct SiteAndLocation {
|
|
|
|
dive_site *ds;
|
|
|
|
location_t location;
|
|
|
|
};
|
|
|
|
std::vector<SiteAndLocation> siteLocations;
|
|
|
|
void editDiveSites();
|
|
|
|
};
|
|
|
|
|
2019-03-12 21:35:43 +00:00
|
|
|
} // namespace Command
|
|
|
|
|
|
|
|
#endif // COMMAND_DIVESITE_H
|