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  QSet<int> affectedTracks() const
43  {
44  return m_affectedTracks;
45  }
46 
47 private:
48  void debugPrintState(const QString &title);
49  void restoreAffectedTracks();
50  void fixTransitions(Mlt::Playlist playlist, int clipIndex, Mlt::Producer clip);
51 
52  enum ChangeFlags {
53  NoChange = 0x0,
54  ClipInfoModified = 0x1,
55  XMLModified = 0x2,
56  Moved = 0x4,
57  Removed = 0x8
58  };
59 
60  struct Info {
61  int oldTrackIndex;
62  int oldClipIndex;
63  int newTrackIndex;
64  int newClipIndex;
65  bool isBlank;
66  QString xml;
67  int frame_in;
68  int frame_out;
69  int in_delta;
70  int out_delta;
71  int group;
72 
73  int changes;
74  Info()
75  : oldTrackIndex(-1)
76  , oldClipIndex(-1)
77  , newTrackIndex(-1)
78  , newClipIndex(-1)
79  , isBlank(false)
80  , frame_in(-1)
81  , frame_out(-1)
82  , in_delta(0)
83  , out_delta(0)
84  , changes(NoChange)
85  , group(-1)
86  {}
87  };
88  QMap<QUuid, Info> m_state;
89  QList<QUuid> m_clipsAdded;
90  QList<QUuid> m_insertedOrder;
91  QSet<int> m_affectedTracks;
92  MultitrackModel &m_model;
93  OptimizationHints m_hints;
94 };
95 
96 #endif // UNDOHELPER_H