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  {
33  NoHints,
34  SkipXML,
35  RestoreTracks
36  };
37  UndoHelper(MultitrackModel & model);
38 
39  void recordBeforeState();
40  void recordAfterState();
41  void undoChanges();
42  void setHints(OptimizationHints hints);
43 
44 private:
45  void debugPrintState();
46  void restoreAffectedTracks();
47  void fixTransitions(Mlt::Playlist playlist, int clipIndex, Mlt::Producer clip);
48 
49  enum ChangeFlags {
50  NoChange = 0x0,
51  ClipInfoModified = 0x1,
52  XMLModified = 0x2,
53  Moved = 0x4,
54  Removed = 0x8
55  };
56 
57  struct Info {
58  int oldTrackIndex;
59  int oldClipIndex;
60  int newTrackIndex;
61  int newClipIndex;
62  bool isBlank;
63  QString xml;
64  int frame_in;
65  int frame_out;
66  int in_delta;
67  int out_delta;
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  {}
82  };
83  QMap<QUuid,Info> m_state;
84  QList<QUuid> m_clipsAdded;
85  QList<QUuid> m_insertedOrder;
86  QSet<int> m_affectedTracks;
87  MultitrackModel & m_model;
88  OptimizationHints m_hints;
89 };
90 
91 #endif // UNDOHELPER_H