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 #include <QUndoCommand>
23 
24 namespace Markers {
25 
26 enum {
27  UndoIdUpdate = 200,
28 };
29 
30 class DeleteCommand : public QUndoCommand
31 {
32 public:
33  DeleteCommand(MarkersModel &model, const Marker &delMarker, int index);
34  void redo();
35  void undo();
36 private:
37  MarkersModel &m_model;
38  Marker m_delMarker;
39  int m_index;
40 };
41 
42 class AppendCommand : public QUndoCommand
43 {
44 public:
45  AppendCommand(MarkersModel &model, const Marker &newMarker, int index);
46  void redo();
47  void undo();
48 private:
49  MarkersModel &m_model;
50  Marker m_newMarker;
51  int m_index;
52 };
53 
54 class UpdateCommand : public QUndoCommand
55 {
56 public:
57  UpdateCommand(MarkersModel &model, const Marker &newMarker, const Marker &oldMarker, int index);
58  void redo();
59  void undo();
60 protected:
61  int id() const
62  {
63  return UndoIdUpdate;
64  }
65  bool mergeWith(const QUndoCommand *other);
66 private:
67  MarkersModel &m_model;
68  Marker m_newMarker;
69  Marker m_oldMarker;
70  int m_index;
71 };
72 
73 class ClearCommand : public QUndoCommand
74 {
75 public:
76  ClearCommand(MarkersModel &model, QList<Marker> &clearMarkers);
77  void redo();
78  void undo();
79 private:
80  MarkersModel &m_model;
81  QList<Marker> m_clearMarkers;
82 };
83 
84 }
85 
86 #endif // MARKERCOMMANDS_H