CuteLogger
Fast and simple logging solution for Qt based applications
playlistcommands.h
1 /*
2  * Copyright (c) 2013-2019 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 PLAYLISTCOMMANDS_H
19 #define PLAYLISTCOMMANDS_H
20 
21 #include "models/playlistmodel.h"
22 #include <QUndoCommand>
23 #include <QString>
24 
25 namespace Playlist
26 {
27 
28 enum {
29  UndoIdTrimClipIn,
30  UndoIdTrimClipOut,
31  UndoIdUpdate
32 };
33 
34 class AppendCommand : public QUndoCommand
35 {
36 public:
37  AppendCommand(PlaylistModel& model, const QString& xml, bool emitModified = true, QUndoCommand * parent = 0);
38  void redo();
39  void undo();
40 private:
41  PlaylistModel& m_model;
42  QString m_xml;
43  bool m_emitModified;
44 };
45 
46 class InsertCommand : public QUndoCommand
47 {
48 public:
49  InsertCommand(PlaylistModel& model, const QString& xml, int row, QUndoCommand * parent = 0);
50  void redo();
51  void undo();
52 private:
53  PlaylistModel& m_model;
54  QString m_xml;
55  int m_row;
56 };
57 
58 class UpdateCommand : public QUndoCommand
59 {
60 public:
61  UpdateCommand(PlaylistModel& model, const QString& xml, int row, QUndoCommand * parent = 0);
62  void redo();
63  void undo();
64 protected:
65  int id() const { return UndoIdUpdate; }
66  bool mergeWith(const QUndoCommand *other);
67 private:
68  PlaylistModel& m_model;
69  QString m_newXml;
70  QString m_oldXml;
71  int m_row;
72 };
73 
74 class RemoveCommand : public QUndoCommand
75 {
76 public:
77  RemoveCommand(PlaylistModel& model, int row, QUndoCommand * parent = 0);
78  void redo();
79  void undo();
80 private:
81  PlaylistModel& m_model;
82  QString m_xml;
83  int m_row;
84 };
85 
86 class MoveCommand : public QUndoCommand
87 {
88 public:
89  MoveCommand(PlaylistModel& model, int from, int to, QUndoCommand * parent = 0);
90  void redo();
91  void undo();
92 private:
93  PlaylistModel& m_model;
94  int m_from;
95  int m_to;
96 };
97 
98 class ClearCommand : public QUndoCommand
99 {
100 public:
101  ClearCommand(PlaylistModel& model, QUndoCommand * parent = 0);
102  void redo();
103  void undo();
104 private:
105  PlaylistModel& m_model;
106  QString m_xml;
107 };
108 
109 class SortCommand : public QUndoCommand
110 {
111 public:
112  SortCommand(PlaylistModel& model, int column, Qt::SortOrder order, QUndoCommand * parent = 0);
113  void redo();
114  void undo();
115 private:
116  PlaylistModel& m_model;
117  int m_column;
118  Qt::SortOrder m_order;
119  QString m_xml;
120 };
121 
122 class TrimClipInCommand : public QUndoCommand
123 {
124 public:
125  TrimClipInCommand(PlaylistModel& model, int row, int in, QUndoCommand * parent = nullptr);
126  void redo();
127  void undo();
128 protected:
129  int id() const { return UndoIdTrimClipIn; }
130  bool mergeWith(const QUndoCommand *other);
131 private:
132  PlaylistModel& m_model;
133  int m_row;
134  int m_oldIn;
135  int m_newIn;
136  int m_out;
137 };
138 
139 class TrimClipOutCommand : public QUndoCommand
140 {
141 public:
142  TrimClipOutCommand(PlaylistModel& model, int row, int out, QUndoCommand * parent = nullptr);
143  void redo();
144  void undo();
145 protected:
146  int id() const { return UndoIdTrimClipOut; }
147  bool mergeWith(const QUndoCommand *other);
148 private:
149  PlaylistModel& m_model;
150  int m_row;
151  int m_in;
152  int m_oldOut;
153  int m_newOut;
154 };
155 
156 }
157 
158 #endif // PLAYLISTCOMMANDS_H