aboutsummaryrefslogtreecommitdiffstats
path: root/commands/command_pictures.h
blob: 472a9256586d033f6ef26a96a567856d4bc9e944 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: GPL-2.0
// Note: this header file is used by the undo-machinery and should not be included elsewhere.

#ifndef COMMAND_PICTURES_H
#define COMMAND_PICTURES_H

#include "command_base.h"
#include "command.h" // for PictureListForDeletion/Addition

// We put everything in a namespace, so that we can shorten names without polluting the global namespace
namespace Command {

class SetPictureOffset final : public Base {
public:
	SetPictureOffset(dive *d, const QString &filename, offset_t offset); // Pictures are identified by the unique (dive,filename) pair
private:
	dive *d; // null means no work to be done
	QString filename;
	offset_t offset;

	void undo() override;
	void redo() override;
	bool workToBeDone() override;
};

class RemovePictures final : public Base {
public:
	RemovePictures(const std::vector<PictureListForDeletion> &pictures);
private:
	std::vector<PictureListForDeletion> picturesToRemove; // for redo
	std::vector<PictureListForAddition> picturesToAdd; // for undo

	void undo() override;
	void redo() override;
	bool workToBeDone() override;
};

class AddPictures final : public Base {
public:
	AddPictures(const std::vector<PictureListForAddition> &pictures);
private:
	struct DiveSiteEntry {
		dive *d;
		dive_site *ds;
	};
	struct DiveSiteEditEntry {
		dive_site *ds;
		location_t location;
	};
	std::vector<PictureListForAddition> picturesToAdd; // for redo
	std::vector<OwningDiveSitePtr> sitesToAdd; //for redo
	std::vector<PictureListForDeletion> picturesToRemove; // for undo
	std::vector<dive_site *> sitesToRemove; // for undo
	std::vector<DiveSiteEntry> sitesToSet; // for redo and undo
	std::vector<DiveSiteEditEntry> sitesToEdit; // for redo and undo

	void swapDiveSites();

	void undo() override;
	void redo() override;
	bool workToBeDone() override;
};

} // namespace Command
#endif