| 
									
										
										
										
											2019-01-25 18:27:31 +01: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_EDIT_H
 | 
					
						
							|  |  |  | #define COMMAND_EDIT_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "command_base.h"
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:33:06 +01:00
										 |  |  | #include "core/subsurface-qt/divelistnotifier.h"
 | 
					
						
							| 
									
										
										
										
											2019-01-25 18:27:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QVector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // These are commands that edit individual fields of a set of dives.
 | 
					
						
							|  |  |  | // The implementation is very OO-style. Out-of-fashion and certainly
 | 
					
						
							|  |  |  | // not elegant, but in line with Qt's OO-based design.
 | 
					
						
							|  |  |  | // The actual code is in a common base class "Command::EditBase". To
 | 
					
						
							|  |  |  | // read and set the fields, the base class calls virtual functions of
 | 
					
						
							|  |  |  | // the derived classes.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // To deal with different data types, the base class is implemented
 | 
					
						
							|  |  |  | // as a template. The template parameter is the type to be read or
 | 
					
						
							|  |  |  | // set. Thus, switch-cascades and union trickery can be avoided.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // We put everything in a namespace, so that we can shorten names without polluting the global namespace
 | 
					
						
							|  |  |  | namespace Command { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-23 20:27:19 +02:00
										 |  |  | // Base class for commands that have a list of dives.
 | 
					
						
							|  |  |  | // This is used for extracting the number of dives and show a
 | 
					
						
							|  |  |  | // warning message when multiple dives are edited.
 | 
					
						
							|  |  |  | class EditDivesBase : public Base { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	EditDivesBase(bool currentDiveOnly); | 
					
						
							| 
									
										
										
										
											2019-07-17 15:49:45 +02:00
										 |  |  | 	EditDivesBase(dive *d); | 
					
						
							| 
									
										
										
										
											2019-05-23 20:27:19 +02:00
										 |  |  | 	std::vector<dive *> dives; // Dives to be edited.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// On undo, we set the selection and current dive at the time of the operation.
 | 
					
						
							|  |  |  | 	std::vector<dive *> selectedDives; | 
					
						
							|  |  |  | 	struct dive *current; | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	int numDives() const; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-25 18:27:31 +01:00
										 |  |  | template <typename T> | 
					
						
							| 
									
										
										
										
											2019-05-23 20:27:19 +02:00
										 |  |  | class EditBase : public EditDivesBase { | 
					
						
							| 
									
										
										
										
											2019-03-20 21:46:58 +01:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2019-01-25 18:27:31 +01:00
										 |  |  | 	T value; // Value to be set
 | 
					
						
							|  |  |  | 	T old; // Previous value
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-02-14 23:07:12 +01:00
										 |  |  | 	EditBase(T newValue, bool currentDiveOnly); | 
					
						
							| 
									
										
										
										
											2019-07-17 15:49:45 +02:00
										 |  |  | 	EditBase(T newValue, dive *d); | 
					
						
							| 
									
										
										
										
											2019-01-25 18:27:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	// Get and set functions to be overriden by sub-classes.
 | 
					
						
							|  |  |  | 	virtual void set(struct dive *d, T) const = 0; | 
					
						
							|  |  |  | 	virtual T data(struct dive *d) const = 0; | 
					
						
							|  |  |  | 	virtual QString fieldName() const = 0;	// Name of the field, used to create the undo menu-entry
 | 
					
						
							| 
									
										
										
										
											2019-01-27 22:08:13 +01:00
										 |  |  | 	virtual DiveField fieldId() const = 0; | 
					
						
							| 
									
										
										
										
											2019-01-25 18:27:31 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | // The individual Edit-commands define a virtual function that return the field-id.
 | 
					
						
							|  |  |  | // For reasons, which I don't fully understand, the C++ makers are strictly opposed
 | 
					
						
							|  |  |  | // to "virtual member constants" so we have to define these functions. To make
 | 
					
						
							|  |  |  | // things a bit more compact we do this automatically with the following template.
 | 
					
						
							|  |  |  | // Of course, we could directly encode the value in the EditBase-template, but
 | 
					
						
							|  |  |  | // that would lead to a multiplication of the created code.
 | 
					
						
							|  |  |  | template <typename T, DiveField::Flags ID> | 
					
						
							|  |  |  | class EditTemplate : public EditBase<T> { | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	using EditBase<T>::EditBase;	// Use constructor of base class.
 | 
					
						
							|  |  |  | 	DiveField fieldId() const override final;	// final prevents further overriding - then just don't use this template
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | // Automatically generate getter and setter in the case of simple assignments.
 | 
					
						
							|  |  |  | // The third parameter is a pointer to a member of the dive structure.
 | 
					
						
							|  |  |  | template <typename T, DiveField::Flags ID, T dive::*PTR> | 
					
						
							|  |  |  | class EditDefaultSetter : public EditTemplate<T, ID> { | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	using EditTemplate<T, ID>::EditTemplate; | 
					
						
							|  |  |  | 	void set(struct dive *d, T) const override final;	// final prevents further overriding - then just don't use this template
 | 
					
						
							|  |  |  | 	T data(struct dive *d) const override final;	// final prevents further overriding - then just don't use this template
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 18:30:49 +01:00
										 |  |  | // Automatically generate getter and setter in the case for string assignments.
 | 
					
						
							|  |  |  | // The third parameter is a pointer to a C-style string in the dive structure.
 | 
					
						
							|  |  |  | template <DiveField::Flags ID, char *dive::*PTR> | 
					
						
							|  |  |  | class EditStringSetter : public EditTemplate<QString, ID> { | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	using EditTemplate<QString, ID>::EditTemplate; | 
					
						
							|  |  |  | 	void set(struct dive *d, QString) const override final;	// final prevents further overriding - then just don't use this template
 | 
					
						
							|  |  |  | 	QString data(struct dive *d) const override final;	// final prevents further overriding - then just don't use this template
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class EditNotes : public EditStringSetter<DiveField::NOTES, &dive::notes> { | 
					
						
							| 
									
										
										
										
											2019-01-25 18:27:31 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 18:30:49 +01:00
										 |  |  | 	using EditStringSetter::EditStringSetter;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-01-25 18:27:31 +01:00
										 |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 18:30:49 +01:00
										 |  |  | class EditSuit : public EditStringSetter<DiveField::SUIT, &dive::suit> { | 
					
						
							| 
									
										
										
										
											2019-01-28 21:42:59 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 18:30:49 +01:00
										 |  |  | 	using EditStringSetter::EditStringSetter;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-01-28 21:42:59 +01:00
										 |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | class EditRating : public EditDefaultSetter<int, DiveField::RATING, &dive::rating> { | 
					
						
							| 
									
										
										
										
											2019-01-28 22:35:07 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | 	using EditDefaultSetter::EditDefaultSetter;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-01-28 22:35:07 +01:00
										 |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | class EditVisibility : public EditDefaultSetter<int, DiveField::VISIBILITY, &dive::visibility> { | 
					
						
							| 
									
										
										
										
											2019-01-28 22:35:07 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | 	using EditDefaultSetter::EditDefaultSetter;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-01-28 22:35:07 +01:00
										 |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | class EditWaveSize : public EditDefaultSetter<int, DiveField::WAVESIZE, &dive::wavesize> { | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | 	using EditDefaultSetter::EditDefaultSetter;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | class EditCurrent : public EditDefaultSetter<int, DiveField::CURRENT, &dive::current> { | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | 	using EditDefaultSetter::EditDefaultSetter;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | class EditSurge : public EditDefaultSetter<int, DiveField::SURGE, &dive::surge> { | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | 	using EditDefaultSetter::EditDefaultSetter;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | class EditChill : public EditDefaultSetter<int, DiveField::CHILL, &dive::chill> { | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | 	using EditDefaultSetter::EditDefaultSetter;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | class EditAirTemp : public EditTemplate<int, DiveField::AIR_TEMP> { | 
					
						
							| 
									
										
										
										
											2019-01-30 22:13:24 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | 	using EditTemplate::EditTemplate;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-01-30 22:13:24 +01:00
										 |  |  | 	void set(struct dive *d, int value) const override; | 
					
						
							|  |  |  | 	int data(struct dive *d) const override; | 
					
						
							|  |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | class EditWaterTemp : public EditTemplate<int, DiveField::WATER_TEMP> { | 
					
						
							| 
									
										
										
										
											2019-01-30 22:13:24 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | 	using EditTemplate::EditTemplate;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-01-30 22:13:24 +01:00
										 |  |  | 	void set(struct dive *d, int value) const override; | 
					
						
							|  |  |  | 	int data(struct dive *d) const override; | 
					
						
							|  |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | class EditAtmPress : public EditTemplate<int, DiveField::ATM_PRESS> { | 
					
						
							| 
									
										
										
										
											2019-11-19 19:16:45 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | 	using EditTemplate::EditTemplate;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-11-19 19:16:45 +02:00
										 |  |  | 	void set(struct dive *d, int value) const override; | 
					
						
							|  |  |  | 	int data(struct dive *d) const override; | 
					
						
							|  |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | class EditWaterTypeUser : public EditTemplate<int, DiveField::SALINITY> { | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | 	using EditTemplate::EditTemplate;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-04-30 12:42:33 +02:00
										 |  |  | 	void set(struct dive *d, int value) const override; | 
					
						
							|  |  |  | 	int data(struct dive *d) const override; | 
					
						
							|  |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | class EditDuration : public EditTemplate<int, DiveField::DURATION> { | 
					
						
							| 
									
										
										
										
											2019-02-10 17:37:06 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | 	using EditTemplate::EditTemplate;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-02-10 17:37:06 +01:00
										 |  |  | 	void set(struct dive *d, int value) const override; | 
					
						
							|  |  |  | 	int data(struct dive *d) const override; | 
					
						
							|  |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | class EditDepth : public EditTemplate<int, DiveField::DEPTH> { | 
					
						
							| 
									
										
										
										
											2019-02-10 17:37:06 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | 	using EditTemplate::EditTemplate;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-02-10 17:37:06 +01:00
										 |  |  | 	void set(struct dive *d, int value) const override; | 
					
						
							|  |  |  | 	int data(struct dive *d) const override; | 
					
						
							|  |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | class EditDiveSite : public EditTemplate<struct dive_site *, DiveField::DIVESITE> { | 
					
						
							| 
									
										
										
										
											2019-03-20 21:46:58 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | 	using EditTemplate::EditTemplate;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-03-20 21:46:58 +01:00
										 |  |  | 	void set(struct dive *d, struct dive_site *value) const override; | 
					
						
							|  |  |  | 	struct dive_site *data(struct dive *d) const override; | 
					
						
							|  |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// We specialize these so that we can send dive-site changed signals.
 | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Edit dive site, but add a new dive site first. Reuses the code of EditDiveSite by
 | 
					
						
							|  |  |  | // deriving from it and hooks into undo() and redo() to add / remove the dive site.
 | 
					
						
							|  |  |  | class EditDiveSiteNew : public EditDiveSite { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	OwningDiveSitePtr diveSiteToAdd; | 
					
						
							|  |  |  | 	struct dive_site *diveSiteToRemove; | 
					
						
							| 
									
										
										
										
											2019-02-14 23:07:12 +01:00
										 |  |  | 	EditDiveSiteNew(const QString &newName, bool currentDiveOnly); | 
					
						
							| 
									
										
										
										
											2019-03-20 21:46:58 +01:00
										 |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | class EditMode : public EditTemplate<int, DiveField::MODE> { | 
					
						
							| 
									
										
										
										
											2019-01-28 18:35:27 +01:00
										 |  |  | 	int index; | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-02-14 23:07:12 +01:00
										 |  |  | 	EditMode(int indexIn, int newValue, bool currentDiveOnly); | 
					
						
							| 
									
										
										
										
											2019-01-28 18:35:27 +01:00
										 |  |  | 	void set(struct dive *d, int i) const override; | 
					
						
							|  |  |  | 	int data(struct dive *d) const override; | 
					
						
							|  |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | class EditInvalid : public EditDefaultSetter<bool, DiveField::INVALID, &dive::invalid> { | 
					
						
							| 
									
										
										
										
											2019-12-12 23:07:17 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 18:10:54 +01:00
										 |  |  | 	using EditDefaultSetter::EditDefaultSetter;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-12-12 23:07:17 +01:00
										 |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-07 19:59:34 +01:00
										 |  |  | // Fields that work with tag-lists (tags, buddies, divemasters) work differently and therefore
 | 
					
						
							|  |  |  | // have their own base class. In this case, it's not a template, as all these lists are base
 | 
					
						
							|  |  |  | // on strings.
 | 
					
						
							| 
									
										
										
										
											2019-05-23 20:27:19 +02:00
										 |  |  | class EditTagsBase : public EditDivesBase { | 
					
						
							| 
									
										
										
										
											2019-02-07 19:59:34 +01:00
										 |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QStringList newList;	// Temporary until initialized
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-02-14 23:07:12 +01:00
										 |  |  | 	EditTagsBase(const QStringList &newList, bool currentDiveOnly); | 
					
						
							| 
									
										
										
										
											2019-02-07 19:59:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	QStringList tagsToAdd; | 
					
						
							|  |  |  | 	QStringList tagsToRemove; | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Getters, setters and parsers to be overriden by sub-classes.
 | 
					
						
							|  |  |  | 	virtual QStringList data(struct dive *d) const = 0; | 
					
						
							|  |  |  | 	virtual void set(struct dive *d, const QStringList &v) const = 0; | 
					
						
							|  |  |  | 	virtual QString fieldName() const = 0;	// Name of the field, used to create the undo menu-entry
 | 
					
						
							|  |  |  | 	virtual DiveField fieldId() const = 0; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | // See comments for EditTemplate
 | 
					
						
							|  |  |  | template <DiveField::Flags ID> | 
					
						
							|  |  |  | class EditTagsTemplate : public EditTagsBase { | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	using EditTagsBase::EditTagsBase;		// Use constructor of base class.
 | 
					
						
							|  |  |  | 	DiveField fieldId() const override final;	// final prevents further overriding - then just don't use this template
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class EditTags : public EditTagsTemplate<DiveField::TAGS> { | 
					
						
							| 
									
										
										
										
											2019-02-07 19:59:34 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | 	using EditTagsTemplate::EditTagsTemplate;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-02-07 19:59:34 +01:00
										 |  |  | 	QStringList data(struct dive *d) const override; | 
					
						
							|  |  |  | 	void set(struct dive *d, const QStringList &v) const override; | 
					
						
							|  |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | class EditBuddies : public EditTagsTemplate<DiveField::BUDDY> { | 
					
						
							| 
									
										
										
										
											2019-02-07 21:00:09 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | 	using EditTagsTemplate::EditTagsTemplate;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-02-07 21:00:09 +01:00
										 |  |  | 	QStringList data(struct dive *d) const override; | 
					
						
							|  |  |  | 	void set(struct dive *d, const QStringList &v) const override; | 
					
						
							|  |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | class EditDiveMaster : public EditTagsTemplate<DiveField::DIVEMASTER> { | 
					
						
							| 
									
										
										
										
											2019-02-07 21:23:00 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-03-21 17:36:58 +01:00
										 |  |  | 	using EditTagsTemplate::EditTagsTemplate;	// Use constructor of base class.
 | 
					
						
							| 
									
										
										
										
											2019-02-07 21:23:00 +01:00
										 |  |  | 	QStringList data(struct dive *d) const override; | 
					
						
							|  |  |  | 	void set(struct dive *d, const QStringList &v) const override; | 
					
						
							|  |  |  | 	QString fieldName() const override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 18:17:20 +01:00
										 |  |  | // Fields we have to remember to undo paste
 | 
					
						
							|  |  |  | struct PasteState { | 
					
						
							|  |  |  | 	dive *d; | 
					
						
							|  |  |  | 	dive_site *divesite; | 
					
						
							|  |  |  | 	QString notes; | 
					
						
							|  |  |  | 	QString divemaster; | 
					
						
							|  |  |  | 	QString buddy; | 
					
						
							|  |  |  | 	QString suit; | 
					
						
							|  |  |  | 	int rating; | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  | 	int wavesize; | 
					
						
							| 
									
										
										
										
											2019-02-23 18:17:20 +01:00
										 |  |  | 	int visibility; | 
					
						
							| 
									
										
										
										
											2019-11-28 21:04:52 +02:00
										 |  |  | 	int current; | 
					
						
							|  |  |  | 	int surge; | 
					
						
							|  |  |  | 	int chill; | 
					
						
							| 
									
										
										
										
											2019-02-23 18:17:20 +01:00
										 |  |  | 	tag_entry *tags; | 
					
						
							| 
									
										
										
										
											2019-08-04 18:44:57 +02:00
										 |  |  | 	struct cylinder_table cylinders; | 
					
						
							| 
									
										
										
										
											2019-06-26 17:21:03 +02:00
										 |  |  | 	struct weightsystem_table weightsystems; | 
					
						
							| 
									
										
										
										
											2019-02-23 18:17:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	PasteState(dive *d, const dive *data, dive_components what); // Read data from dive data for dive d
 | 
					
						
							|  |  |  | 	~PasteState(); | 
					
						
							|  |  |  | 	void swap(dive_components what); // Exchange values here and in dive
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 20:54:25 +02:00
										 |  |  | class PasteDives : public Base { | 
					
						
							| 
									
										
										
										
											2019-02-23 18:17:20 +01:00
										 |  |  | 	dive_components what; | 
					
						
							|  |  |  | 	std::vector<PasteState> dives; | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	PasteDives(const dive *d, dive_components what); | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 20:54:25 +02:00
										 |  |  | class ReplanDive : public Base { | 
					
						
							|  |  |  | 	dive *d; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Exchange these data with current dive
 | 
					
						
							|  |  |  | 	timestamp_t when; | 
					
						
							|  |  |  | 	depth_t maxdepth, meandepth; | 
					
						
							| 
									
										
										
										
											2019-08-04 18:44:57 +02:00
										 |  |  | 	struct cylinder_table cylinders; | 
					
						
							| 
									
										
										
										
											2019-10-06 20:54:25 +02:00
										 |  |  | 	struct divecomputer dc; | 
					
						
							|  |  |  | 	char *notes; | 
					
						
							|  |  |  | 	pressure_t surface_pressure; | 
					
						
							|  |  |  | 	duration_t duration; | 
					
						
							|  |  |  | 	int salinity; | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-11-30 15:51:34 +01:00
										 |  |  | 	// Dive computer(s) and cylinders(s) of the source dive will be reset!
 | 
					
						
							|  |  |  | 	// If edit_profile is true, the text will be changed from "replan dive" to "edit profile".
 | 
					
						
							|  |  |  | 	ReplanDive(dive *source, bool edit_profile); | 
					
						
							| 
									
										
										
										
											2019-10-06 20:54:25 +02:00
										 |  |  | 	~ReplanDive(); | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-02 21:19:29 +01:00
										 |  |  | class AddWeight : public EditDivesBase { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	AddWeight(bool currentDiveOnly); | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-08 22:47:38 +01:00
										 |  |  | class EditWeightBase : public EditDivesBase { | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	EditWeightBase(int index, bool currentDiveOnly); | 
					
						
							|  |  |  | 	~EditWeightBase(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	weightsystem_t ws; | 
					
						
							| 
									
										
										
										
											2020-03-11 11:30:51 +01:00
										 |  |  | 	std::vector<int> indices; // An index for each dive in the dives vector.
 | 
					
						
							| 
									
										
										
										
											2019-11-08 22:47:38 +01:00
										 |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class RemoveWeight : public EditWeightBase { | 
					
						
							| 
									
										
										
										
											2019-11-03 15:04:48 +01:00
										 |  |  | public: | 
					
						
							|  |  |  | 	RemoveWeight(int index, bool currentDiveOnly); | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							| 
									
										
										
										
											2019-11-08 22:47:38 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class EditWeight : public EditWeightBase { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	EditWeight(int index, weightsystem_t ws, bool currentDiveOnly); // Clones ws
 | 
					
						
							|  |  |  | 	~EditWeight(); | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	weightsystem_t new_ws; | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							| 
									
										
										
										
											2019-11-03 15:04:48 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-23 11:43:50 +01:00
										 |  |  | class AddCylinder : public EditDivesBase { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	AddCylinder(bool currentDiveOnly); | 
					
						
							|  |  |  | 	~AddCylinder(); | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	cylinder_t cyl; | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class EditCylinderBase : public EditDivesBase { | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2020-02-24 10:57:36 +01:00
										 |  |  | 	EditCylinderBase(int index, bool currentDiveOnly, bool nonProtectedOnly); | 
					
						
							| 
									
										
										
										
											2020-02-23 11:43:50 +01:00
										 |  |  | 	~EditCylinderBase(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cylinder_t cyl; | 
					
						
							|  |  |  | 	std::vector<int> indexes; // An index for each dive in the dives vector.
 | 
					
						
							|  |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class RemoveCylinder : public EditCylinderBase { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	RemoveCylinder(int index, bool currentDiveOnly); | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class EditCylinder : public EditCylinderBase { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	EditCylinder(int index, cylinder_t cyl, bool currentDiveOnly); // Clones cylinder
 | 
					
						
							|  |  |  | 	~EditCylinder(); | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	cylinder_t new_cyl; | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 08:25:37 +08:00
										 |  |  | #ifdef SUBSURFACE_MOBILE
 | 
					
						
							|  |  |  | // Edit a full dive. This is used on mobile where we don't have per-field granularity.
 | 
					
						
							|  |  |  | // It may add or edit a dive site.
 | 
					
						
							|  |  |  | class EditDive : public Base { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	EditDive(dive *oldDive, dive *newDive, dive_site *createDs, dive_site *editDs, location_t dsLocation); // Takes ownership of newDive
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	dive *oldDive; // Dive that is going to be overwritten
 | 
					
						
							|  |  |  | 	OwningDivePtr newDive; // New data
 | 
					
						
							| 
									
										
										
										
											2020-04-04 16:35:24 +02:00
										 |  |  | 	dive_site *newDiveSite; | 
					
						
							| 
									
										
										
										
											2020-01-10 08:25:37 +08:00
										 |  |  | 	int changedFields; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dive_site *siteToRemove; | 
					
						
							|  |  |  | 	OwningDiveSitePtr siteToAdd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dive_site *siteToEdit; | 
					
						
							|  |  |  | 	location_t dsLocation; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | 	bool workToBeDone() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void exchangeDives(); | 
					
						
							|  |  |  | 	void editDs(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // SUBSURFACE_MOBILE
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-25 18:27:31 +01:00
										 |  |  | } // namespace Command
 | 
					
						
							|  |  |  | #endif
 |