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 
23 #include <MltPlaylist.h>
24 #include <QList>
25 #include <QMap>
26 #include <QSet>
27 #include <QString>
28 
29 class UndoHelper
30 {
31 public:
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  QSet<int> affectedTracks() const { return m_affectedTracks; }
40 
41 private:
42  void debugPrintState(const QString &title);
43  void restoreAffectedTracks();
44  void fixTransitions(Mlt::Playlist playlist, int clipIndex, Mlt::Producer clip);
45 
46  enum ChangeFlags {
47  NoChange = 0x0,
48  ClipInfoModified = 0x1,
49  XMLModified = 0x2,
50  Moved = 0x4,
51  Removed = 0x8
52  };
53 
54  struct Info
55  {
56  int oldTrackIndex;
57  int oldClipIndex;
58  int newTrackIndex;
59  int newClipIndex;
60  bool isBlank;
61  QString xml;
62  int frame_in;
63  int frame_out;
64  int in_delta;
65  int out_delta;
66  int group;
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  , group(-1)
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