CuteLogger
Fast and simple logging solution for Qt based applications
markercommands.h
1 /*
2  * Copyright (c) 2021-2023 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MARKERCOMMANDS_H
19 #define MARKERCOMMANDS_H
20 
21 #include "models/markersmodel.h"
22 
23 #include <QUndoCommand>
24 
25 namespace Markers {
26 
27 enum {
28  UndoIdUpdate = 200,
29 };
30 
31 class DeleteCommand : public QUndoCommand
32 {
33 public:
34  DeleteCommand(MarkersModel &model, const Marker &delMarker, int index);
35  void redo();
36  void undo();
37 
38 private:
39  MarkersModel &m_model;
40  Marker m_delMarker;
41  int m_index;
42 };
43 
44 class AppendCommand : public QUndoCommand
45 {
46 public:
47  AppendCommand(MarkersModel &model, const Marker &newMarker, int index);
48  void redo();
49  void undo();
50 
51 private:
52  MarkersModel &m_model;
53  Marker m_newMarker;
54  int m_index;
55 };
56 
57 class UpdateCommand : public QUndoCommand
58 {
59 public:
60  UpdateCommand(MarkersModel &model, const Marker &newMarker, const Marker &oldMarker, int index);
61  void redo();
62  void undo();
63 
64 protected:
65  int id() const { return UndoIdUpdate; }
66  bool mergeWith(const QUndoCommand *other);
67 
68 private:
69  MarkersModel &m_model;
70  Marker m_newMarker;
71  Marker m_oldMarker;
72  int m_index;
73 };
74 
75 class ClearCommand : public QUndoCommand
76 {
77 public:
78  ClearCommand(MarkersModel &model, QList<Marker> &clearMarkers);
79  void redo();
80  void undo();
81 
82 private:
83  MarkersModel &m_model;
84  QList<Marker> m_clearMarkers;
85 };
86 
87 } // namespace Markers
88 
89 #endif // MARKERCOMMANDS_H