CuteLogger
Fast and simple logging solution for Qt based applications
undohelper.h
1/*
2 * Copyright (c) 2015-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 UNDOHELPER_H
19#define UNDOHELPER_H
20
21#include "models/multitrackmodel.h"
22
23#include <MltPlaylist.h>
24#include <QList>
25#include <QMap>
26#include <QSet>
27#include <QString>
28
29class UndoHelper
30{
31public:
32 enum OptimizationHints { NoHints, SkipXML, RestoreTracks };
33 UndoHelper(MultitrackModel &model);
34
35 void recordBeforeState();
36 void recordAfterState();
37 void undoChanges();
38 void setHints(OptimizationHints hints);
39 void storeXmlForClip(const QUuid &uid);
40 QSet<int> affectedTracks() const { return m_affectedTracks; }
41
42private:
43 void debugPrintState(const QString &title);
44 void restoreAffectedTracks();
45 void fixTransitions(Mlt::Playlist playlist, int clipIndex, Mlt::Producer clip);
46
47 enum ChangeFlags {
48 NoChange = 0x0,
49 ClipInfoModified = 0x1,
50 XMLModified = 0x2,
51 Moved = 0x4,
52 Removed = 0x8
53 };
54
55 struct Info
56 {
57 int oldTrackIndex;
58 int oldClipIndex;
59 int newTrackIndex;
60 int newClipIndex;
61 bool isBlank;
62 QString xml;
63 int frame_in;
64 int frame_out;
65 int in_delta;
66 int out_delta;
67 int group;
68
69 int changes;
70 Info()
71 : oldTrackIndex(-1)
72 , oldClipIndex(-1)
73 , newTrackIndex(-1)
74 , newClipIndex(-1)
75 , isBlank(false)
76 , frame_in(-1)
77 , frame_out(-1)
78 , in_delta(0)
79 , out_delta(0)
80 , changes(NoChange)
81 , group(-1)
82 {}
83 };
84 QMap<QUuid, Info> m_state;
85 QList<QUuid> m_clipsAdded;
86 QList<QUuid> m_insertedOrder;
87 QSet<int> m_affectedTracks;
88 QSet<QUuid> m_xmlClips;
89 MultitrackModel &m_model;
90 OptimizationHints m_hints;
91};
92
93#endif // UNDOHELPER_H