CuteLogger
Fast and simple logging solution for Qt based applications
playlistcommands.h
1 /*
2  * Copyright (c) 2013-2024 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 
23 #include <QString>
24 #include <QUndoCommand>
25 #include <QUuid>
26 
27 class QTreeWidget;
28 
29 namespace Playlist {
30 
31 enum { UndoIdTrimClipIn = 0, UndoIdTrimClipOut, UndoIdUpdate };
32 
33 class AppendCommand : public QUndoCommand
34 {
35 public:
36  AppendCommand(PlaylistModel &model,
37  const QString &xml,
38  bool emitModified = true,
39  QUndoCommand *parent = 0);
40  void redo();
41  void undo();
42 
43 private:
44  PlaylistModel &m_model;
45  QString m_xml;
46  bool m_emitModified;
47  QUuid m_uuid;
48 };
49 
50 class InsertCommand : public QUndoCommand
51 {
52 public:
53  InsertCommand(PlaylistModel &model, const QString &xml, int row, QUndoCommand *parent = 0);
54  void redo();
55  void undo();
56 
57 private:
58  PlaylistModel &m_model;
59  QString m_xml;
60  int m_row;
61  QUuid m_uuid;
62 };
63 
64 class UpdateCommand : public QUndoCommand
65 {
66 public:
67  UpdateCommand(PlaylistModel &model, const QString &xml, int row, QUndoCommand *parent = 0);
68  void redo();
69  void undo();
70 
71 protected:
72  int id() const { return UndoIdUpdate; }
73  bool mergeWith(const QUndoCommand *other);
74 
75 private:
76  PlaylistModel &m_model;
77  QString m_newXml;
78  QString m_oldXml;
79  int m_row;
80  QUuid m_uuid;
81 };
82 
83 class RemoveCommand : public QUndoCommand
84 {
85 public:
86  RemoveCommand(PlaylistModel &model, int row, QUndoCommand *parent = 0);
87  void redo();
88  void undo();
89 
90 private:
91  PlaylistModel &m_model;
92  QString m_xml;
93  int m_row;
94  QUuid m_uuid;
95 };
96 
97 class MoveCommand : public QUndoCommand
98 {
99 public:
100  MoveCommand(PlaylistModel &model, int from, int to, QUndoCommand *parent = 0);
101  void redo();
102  void undo();
103 
104 private:
105  PlaylistModel &m_model;
106  int m_from;
107  int m_to;
108 };
109 
110 class ClearCommand : public QUndoCommand
111 {
112 public:
113  ClearCommand(PlaylistModel &model, QUndoCommand *parent = 0);
114  void redo();
115  void undo();
116 
117 private:
118  PlaylistModel &m_model;
119  QString m_xml;
120  QVector<QUuid> m_uuids;
121 };
122 
123 class SortCommand : public QUndoCommand
124 {
125 public:
126  SortCommand(PlaylistModel &model, int column, Qt::SortOrder order, QUndoCommand *parent = 0);
127  void redo();
128  void undo();
129 
130 private:
131  PlaylistModel &m_model;
132  int m_column;
133  Qt::SortOrder m_order;
134  QString m_xml;
135  QVector<QUuid> m_uuids;
136 };
137 
138 class TrimClipInCommand : public QUndoCommand
139 {
140 public:
141  TrimClipInCommand(PlaylistModel &model, int row, int in, QUndoCommand *parent = nullptr);
142  void redo();
143  void undo();
144 
145 protected:
146  int id() const { return UndoIdTrimClipIn; }
147  bool mergeWith(const QUndoCommand *other);
148 
149 private:
150  PlaylistModel &m_model;
151  int m_row;
152  int m_oldIn;
153  int m_newIn;
154  int m_out;
155 };
156 
157 class TrimClipOutCommand : public QUndoCommand
158 {
159 public:
160  TrimClipOutCommand(PlaylistModel &model, int row, int out, QUndoCommand *parent = nullptr);
161  void redo();
162  void undo();
163 
164 protected:
165  int id() const { return UndoIdTrimClipOut; }
166  bool mergeWith(const QUndoCommand *other);
167 
168 private:
169  PlaylistModel &m_model;
170  int m_row;
171  int m_in;
172  int m_oldOut;
173  int m_newOut;
174 };
175 
176 class ReplaceCommand : public QUndoCommand
177 {
178 public:
179  ReplaceCommand(PlaylistModel &model, const QString &xml, int row, QUndoCommand *parent = 0);
180  void redo();
181  void undo();
182 
183 private:
184  PlaylistModel &m_model;
185  QString m_newXml;
186  QString m_oldXml;
187  int m_row;
188  QUuid m_uuid;
189 };
190 
191 class NewBinCommand : public QUndoCommand
192 {
193 public:
194  NewBinCommand(PlaylistModel &model,
195  QTreeWidget *tree,
196  const QString &bin,
197  QUndoCommand *parent = 0);
198  void redo();
199  void undo();
200 
201 private:
202  PlaylistModel &m_model;
203  QTreeWidget *m_binTree;
204  QString m_bin;
205  Mlt::Properties m_oldBins;
206 };
207 
208 class MoveToBinCommand : public QUndoCommand
209 {
210 public:
211  MoveToBinCommand(PlaylistModel &model,
212  QTreeWidget *tree,
213  const QString &bin,
214  const QList<int> &rows,
215  QUndoCommand *parent = 0);
216  void redo();
217  void undo();
218 
219 private:
220  PlaylistModel &m_model;
221  QTreeWidget *m_binTree;
222  QString m_bin;
223 
224  typedef struct
225  {
226  int row;
227  QString bin;
228  } oldData;
229  QList<oldData> m_oldData;
230 };
231 
232 class RenameBinCommand : public QUndoCommand
233 {
234 public:
235  RenameBinCommand(PlaylistModel &model,
236  QTreeWidget *tree,
237  const QString &bin,
238  const QString &newName = QString(),
239  QUndoCommand *parent = 0);
240  void redo();
241  void undo();
242  static void rebuildBinList(PlaylistModel &model, QTreeWidget *binTree);
243 
244 private:
245  PlaylistModel &m_model;
246  QTreeWidget *m_binTree;
247  QString m_bin;
248  QString m_newName;
249  QList<int> m_removedRows;
250 };
251 
252 } // namespace Playlist
253 
254 #endif // PLAYLISTCOMMANDS_H