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
26class QTreeWidget;
27
28namespace Playlist {
29
30enum {
31 UndoIdTrimClipIn = 0,
32 UndoIdTrimClipOut,
33 UndoIdUpdate
34};
35
36class AppendCommand : public QUndoCommand
37{
38public:
39 AppendCommand(PlaylistModel &model, const QString &xml, bool emitModified = true,
40 QUndoCommand *parent = 0);
41 void redo();
42 void undo();
43private:
44 PlaylistModel &m_model;
45 QString m_xml;
46 bool m_emitModified;
47 QUuid m_uuid;
48};
49
50class InsertCommand : public QUndoCommand
51{
52public:
53 InsertCommand(PlaylistModel &model, const QString &xml, int row, QUndoCommand *parent = 0);
54 void redo();
55 void undo();
56private:
57 PlaylistModel &m_model;
58 QString m_xml;
59 int m_row;
60 QUuid m_uuid;
61};
62
63class UpdateCommand : public QUndoCommand
64{
65public:
66 UpdateCommand(PlaylistModel &model, const QString &xml, int row, QUndoCommand *parent = 0);
67 void redo();
68 void undo();
69protected:
70 int id() const
71 {
72 return UndoIdUpdate;
73 }
74 bool mergeWith(const QUndoCommand *other);
75private:
76 PlaylistModel &m_model;
77 QString m_newXml;
78 QString m_oldXml;
79 int m_row;
80 QUuid m_uuid;
81};
82
83class RemoveCommand : public QUndoCommand
84{
85public:
86 RemoveCommand(PlaylistModel &model, int row, QUndoCommand *parent = 0);
87 void redo();
88 void undo();
89private:
90 PlaylistModel &m_model;
91 QString m_xml;
92 int m_row;
93 QUuid m_uuid;
94};
95
96class MoveCommand : public QUndoCommand
97{
98public:
99 MoveCommand(PlaylistModel &model, int from, int to, QUndoCommand *parent = 0);
100 void redo();
101 void undo();
102private:
103 PlaylistModel &m_model;
104 int m_from;
105 int m_to;
106};
107
108class ClearCommand : public QUndoCommand
109{
110public:
111 ClearCommand(PlaylistModel &model, QUndoCommand *parent = 0);
112 void redo();
113 void undo();
114private:
115 PlaylistModel &m_model;
116 QString m_xml;
117 QVector<QUuid> m_uuids;
118};
119
120class SortCommand : public QUndoCommand
121{
122public:
123 SortCommand(PlaylistModel &model, int column, Qt::SortOrder order, QUndoCommand *parent = 0);
124 void redo();
125 void undo();
126private:
127 PlaylistModel &m_model;
128 int m_column;
129 Qt::SortOrder m_order;
130 QString m_xml;
131 QVector<QUuid> m_uuids;
132};
133
134class TrimClipInCommand : public QUndoCommand
135{
136public:
137 TrimClipInCommand(PlaylistModel &model, int row, int in, QUndoCommand *parent = nullptr);
138 void redo();
139 void undo();
140protected:
141 int id() const
142 {
143 return UndoIdTrimClipIn;
144 }
145 bool mergeWith(const QUndoCommand *other);
146private:
147 PlaylistModel &m_model;
148 int m_row;
149 int m_oldIn;
150 int m_newIn;
151 int m_out;
152};
153
154class TrimClipOutCommand : public QUndoCommand
155{
156public:
157 TrimClipOutCommand(PlaylistModel &model, int row, int out, QUndoCommand *parent = nullptr);
158 void redo();
159 void undo();
160protected:
161 int id() const
162 {
163 return UndoIdTrimClipOut;
164 }
165 bool mergeWith(const QUndoCommand *other);
166private:
167 PlaylistModel &m_model;
168 int m_row;
169 int m_in;
170 int m_oldOut;
171 int m_newOut;
172};
173
174class ReplaceCommand : public QUndoCommand
175{
176public:
177 ReplaceCommand(PlaylistModel &model, const QString &xml, int row, QUndoCommand *parent = 0);
178 void redo();
179 void undo();
180private:
181 PlaylistModel &m_model;
182 QString m_newXml;
183 QString m_oldXml;
184 int m_row;
185 QUuid m_uuid;
186};
187
188class NewBinCommand : public QUndoCommand
189{
190public:
191 NewBinCommand(PlaylistModel &model, QTreeWidget *tree, const QString &bin,
192 QUndoCommand *parent = 0);
193 void redo();
194 void undo();
195private:
196 PlaylistModel &m_model;
197 QTreeWidget *m_binTree;
198 QString m_bin;
199 Mlt::Properties m_oldBins;
200};
201
202class MoveToBinCommand : public QUndoCommand
203{
204public:
205 MoveToBinCommand(PlaylistModel &model, QTreeWidget *tree, const QString &bin,
206 const QList<int> &rows, QUndoCommand *parent = 0);
207 void redo();
208 void undo();
209
210private:
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
222class RenameBinCommand : public QUndoCommand
223{
224public:
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
231private:
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