summaryrefslogtreecommitdiffstats
path: root/commands/command_edit_trip.h
blob: f1d633b4b0837554f42046536853af5f7eccff6d (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
// 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_TRIP_H
#define COMMAND_EDIT_TRIP_H

#include "command_base.h"
#include "core/subsurface-qt/divelistnotifier.h"

#include <QVector>

// These are commands that edit individual fields of a a trip.
// The implementation follows the (rather verbose) OO-style of the dive-edit commands.
// But here, no template is used as the two fields are both of string type.

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

class EditTripBase : public Base {
	bool workToBeDone() override;

	dive_trip *trip; // Trip to be edited.
public:
	EditTripBase(dive_trip *trip, const QString &newValue);

protected:
	QString value; // Value to be set
	void undo() override;
	void redo() override;

	// Get and set functions to be overriden by sub-classes.
	virtual void set(struct dive_trip *t, const QString &) const = 0;
	virtual QString data(struct dive_trip *t) const = 0;
	virtual QString fieldName() const = 0;	// Name of the field, used to create the undo menu-entry
	virtual TripField fieldId() const = 0;
};

class EditTripLocation : public EditTripBase {
public:
	using EditTripBase::EditTripBase;	// Use constructor of base class.
	void set(dive_trip *t, const QString &s) const override;
	QString data(dive_trip *t) const override;
	QString fieldName() const override;
	TripField fieldId() const override;
};

class EditTripNotes : public EditTripBase {
public:
	using EditTripBase::EditTripBase;	// Use constructor of base class.
	void set(dive_trip *t, const QString &s) const override;
	QString data(dive_trip *t) const override;
	QString fieldName() const override;
	TripField fieldId() const override;
};

} // namespace Command

#endif