CuteLogger
Fast and simple logging solution for Qt based applications
playlistcommands.h
1 /*
2  * Copyright (c) 2013-2020 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 PLAYLISTCOMMANDS_H
19 #define PLAYLISTCOMMANDS_H
20 
21 #include "models/playlistmodel.h"
22 #include <QUndoCommand>
23 #include <QString>
24 
25 namespace Playlist {
26 
27 enum {
28  UndoIdTrimClipIn,
29  UndoIdTrimClipOut,
30  UndoIdUpdate
31 };
32 
33 class AppendCommand : public QUndoCommand
34 {
35 public:
36  AppendCommand(PlaylistModel &model, const QString &xml, bool emitModified = true,
37  QUndoCommand *parent = 0);
38  void redo();
39  void undo();
40 private:
41  PlaylistModel &m_model;
42  QString m_xml;
43  bool m_emitModified;
44 };
45 
46 class InsertCommand : public QUndoCommand
47 {
48 public:
49  InsertCommand(PlaylistModel &model, const QString &xml, int row, QUndoCommand *parent = 0);
50  void redo();
51  void undo();
52 private:
53  PlaylistModel &m_model;
54  QString m_xml;
55  int m_row;
56 };
57 
58 class UpdateCommand : public QUndoCommand
59 {
60 public:
61  UpdateCommand(PlaylistModel &model, const QString &xml, int row, QUndoCommand *parent = 0);
62  void redo();
63  void undo();
64 protected:
65  int id() const
66  {
67  return UndoIdUpdate;
68  }
69  bool mergeWith(const QUndoCommand *other);
70 private:
71  PlaylistModel &m_model;
72  QString m_newXml;
73  QString m_oldXml;
74  int m_row;
75 };
76 
77 class RemoveCommand : public QUndoCommand
78 {
79 public:
80  RemoveCommand(PlaylistModel &model, int row, QUndoCommand *parent = 0);
81  void redo();
82  void undo();
83 private:
84  PlaylistModel &m_model;
85  QString m_xml;
86  int m_row;
87 };
88 
89 class MoveCommand : public QUndoCommand
90 {
91 public:
92  MoveCommand(PlaylistModel &model, int from, int to, QUndoCommand *parent = 0);
93  void redo();
94  void undo();
95 private:
96  PlaylistModel &m_model;
97  int m_from;
98  int m_to;
99 };
100 
101 class ClearCommand : public QUndoCommand
102 {
103 public:
104  ClearCommand(PlaylistModel &model, QUndoCommand *parent = 0);
105  void redo();
106  void undo();
107 private:
108  PlaylistModel &m_model;
109  QString m_xml;
110 };
111 
112 class SortCommand : public QUndoCommand
113 {
114 public:
115  SortCommand(PlaylistModel &model, int column, Qt::SortOrder order, QUndoCommand *parent = 0);
116  void redo();
117  void undo();
118 private:
119  PlaylistModel &m_model;
120  int m_column;
121  Qt::SortOrder m_order;
122  QString m_xml;
123 };
124 
125 class TrimClipInCommand : public QUndoCommand
126 {
127 public:
128  TrimClipInCommand(PlaylistModel &model, int row, int in, QUndoCommand *parent = nullptr);
129  void redo();
130  void undo();
131 protected:
132  int id() const
133  {
134  return UndoIdTrimClipIn;
135  }
136  bool mergeWith(const QUndoCommand *other);
137 private:
138  PlaylistModel &m_model;
139  int m_row;
140  int m_oldIn;
141  int m_newIn;
142  int m_out;
143 };
144 
145 class TrimClipOutCommand : public QUndoCommand
146 {
147 public:
148  TrimClipOutCommand(PlaylistModel &model, int row, int out, QUndoCommand *parent = nullptr);
149  void redo();
150  void undo();
151 protected:
152  int id() const
153  {
154  return UndoIdTrimClipOut;
155  }
156  bool mergeWith(const QUndoCommand *other);
157 private:
158  PlaylistModel &m_model;
159  int m_row;
160  int m_in;
161  int m_oldOut;
162  int m_newOut;
163 };
164 
165 class ReplaceCommand : public QUndoCommand
166 {
167 public:
168  ReplaceCommand(PlaylistModel &model, const QString &xml, int row, QUndoCommand *parent = 0);
169  void redo();
170  void undo();
171 private:
172  PlaylistModel &m_model;
173  QString m_newXml;
174  QString m_oldXml;
175  int m_row;
176 };
177 
178 }
179 
180 #endif // PLAYLISTCOMMANDS_H