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