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