CuteLogger
Fast and simple logging solution for Qt based applications
filtercommands.h
1/*
2 * Copyright (c) 2021-2026 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 FILTERCOMMANDS_H
19#define FILTERCOMMANDS_H
20
21#include "models/attachedfiltersmodel.h"
22
23#include <MltProducer.h>
24#include <MltProperties.h>
25#include <QString>
26#include <QUndoCommand>
27#include <QUuid>
28
29class QmlMetadata;
30class FilterController;
31
32namespace Filter {
33
34enum {
35 UndoIdAdd = 300,
36 UndoIdMove,
37 UndoIdDisable,
38 UndoIdChangeParameter,
39 UndoIdChangeAddKeyframe,
40 UndoIdChangeRemoveKeyframe,
41 UndoIdChangeKeyframe,
42};
43
44class AddCommand : public QUndoCommand
45{
46public:
47 typedef enum {
48 AddSingle,
49 AddSet,
50 AddSetLast,
51 } AddType;
52 AddCommand(AttachedFiltersModel &model,
53 const QString &name,
54 Mlt::Service &service,
55 int row,
56 AddCommand::AddType type = AddCommand::AddSingle,
57 QUndoCommand *parent = 0);
58 void redo();
59 void undo();
60
61protected:
62 int id() const { return UndoIdAdd; }
63 bool mergeWith(const QUndoCommand *other);
64
65private:
66 AttachedFiltersModel &m_model;
67 std::vector<int> m_rows;
68 std::vector<QString> m_serviceNames;
69 std::vector<Mlt::Properties> m_serviceProperties;
70 std::vector<mlt_service_type> m_serviceTypes;
71 Mlt::Producer m_producer;
72 QUuid m_producerUuid;
73 AddType m_type;
74};
75
76class RemoveCommand : public QUndoCommand
77{
78public:
79 RemoveCommand(AttachedFiltersModel &model,
80 const QString &name,
81 Mlt::Service &service,
82 int row,
83 QUndoCommand *parent = 0);
84 void redo();
85 void undo();
86
87private:
88 AttachedFiltersModel &m_model;
89 int m_index;
90 int m_row;
91 Mlt::Producer m_producer;
92 QUuid m_producerUuid;
93 Mlt::Service m_service;
94};
95
96class MoveCommand : public QUndoCommand
97{
98public:
99 MoveCommand(AttachedFiltersModel &model,
100 const QString &name,
101 int fromRow,
102 int toRow,
103 QUndoCommand *parent = 0);
104 void redo();
105 void undo();
106
107protected:
108 int id() const { return UndoIdMove; }
109
110private:
111 AttachedFiltersModel &m_model;
112 int m_fromRow;
113 int m_toRow;
114 Mlt::Producer m_producer;
115 QUuid m_producerUuid;
116};
117
118class DisableCommand : public QUndoCommand
119{
120public:
121 DisableCommand(AttachedFiltersModel &model,
122 const QString &name,
123 int row,
124 bool disabled,
125 QUndoCommand *parent = 0);
126 void redo();
127 void undo();
128
129protected:
130 int id() const { return UndoIdDisable; }
131 bool mergeWith(const QUndoCommand *other);
132
133private:
134 AttachedFiltersModel &m_model;
135 int m_row;
136 Mlt::Producer m_producer;
137 QUuid m_producerUuid;
138 bool m_disabled;
139};
140
141class PasteCommand : public QUndoCommand
142{
143public:
144 PasteCommand(AttachedFiltersModel &model,
145 const QString &filterProducerXml,
146 QUndoCommand *parent = 0);
147 void redo();
148 void undo();
149
150private:
151 AttachedFiltersModel &m_model;
152 QString m_xml;
153 QString m_beforeXml;
154 QUuid m_producerUuid;
155};
156
157class UndoParameterCommand : public QUndoCommand
158{
159public:
160 UndoParameterCommand(const QString &name,
161 FilterController *controller,
162 int row,
163 Mlt::Properties &before,
164 const QString &desc = QString(),
165 QUndoCommand *parent = 0);
166 void update(const QString &propertyName);
167 void redo();
168 void undo();
169
170protected:
171 int id() const { return UndoIdChangeParameter; }
172 bool mergeWith(const QUndoCommand *other);
173
174private:
175 int m_row;
176 QUuid m_producerUuid;
177 Mlt::Properties m_before;
178 Mlt::Properties m_after;
179 FilterController *m_filterController;
180 bool m_firstRedo;
181};
182
183class UndoAddKeyframeCommand : public UndoParameterCommand
184{
185public:
186 UndoAddKeyframeCommand(const QString &name,
187 FilterController *controller,
188 int row,
189 Mlt::Properties &before)
190 : UndoParameterCommand(name, controller, row, before, QObject::tr("add keyframe"))
191 {}
192
193protected:
194 int id() const { return UndoIdChangeAddKeyframe; }
195 bool mergeWith(const QUndoCommand *other) { return false; }
196};
197
198class UndoRemoveKeyframeCommand : public UndoParameterCommand
199{
200public:
201 UndoRemoveKeyframeCommand(const QString &name,
202 FilterController *controller,
203 int row,
204 Mlt::Properties &before)
205 : UndoParameterCommand(name, controller, row, before, QObject::tr("remove keyframe"))
206 {}
207
208protected:
209 int id() const { return UndoIdChangeRemoveKeyframe; }
210 bool mergeWith(const QUndoCommand *other) { return false; }
211};
212
213class UndoModifyKeyframeCommand : public UndoParameterCommand
214{
215public:
216 UndoModifyKeyframeCommand(const QString &name,
217 FilterController *controller,
218 int row,
219 Mlt::Properties &before,
220 int paramIndex,
221 int keyframeIndex)
222 : UndoParameterCommand(name, controller, row, before, QObject::tr("modify keyframe"))
223 , m_paramIndex(paramIndex)
224 , m_keyframeIndex(keyframeIndex)
225 {}
226
227protected:
228 int id() const { return UndoIdChangeRemoveKeyframe; }
229 bool mergeWith(const QUndoCommand *other)
230 {
231 auto *that = dynamic_cast<const UndoModifyKeyframeCommand *>(other);
232 if (!that || m_paramIndex != that->m_paramIndex || m_keyframeIndex != that->m_keyframeIndex)
233 return false;
234 else
235 return UndoParameterCommand::mergeWith(other);
236 }
237
238private:
239 int m_paramIndex;
240 int m_keyframeIndex;
241};
242
243} // namespace Filter
244
245#endif // FILTERCOMMANDS_H