summaryrefslogtreecommitdiff
path: root/src/gui/undocommands.h
blob: 40f0a3b4f7205de2755c90f733810a7d997f4c2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
    TikZiT - a GUI diagram editor for TikZ
    Copyright (C) 2018 Aleks Kissinger

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

/*!
  * \file undocommands.h
  *
  * All changes to a TikzDocument are done via subclasses of QUndoCommand. When a controller
  * (e.g. TikzScene) gets input from the user to change the document, it will push one of
  * these commands onto the TikzDocument's undo stack, which automatically calls the redo()
  * method of the command.
  */

#ifndef UNDOCOMMANDS_H
#define UNDOCOMMANDS_H

#include "tikzscene.h"

#include <QUndoCommand>
#include <QSet>

class GraphUpdateCommand : public QUndoCommand {
public:
    explicit GraphUpdateCommand(TikzScene *scene,
                                QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
protected:
    TikzScene *_scene;
};

class MoveCommand : public GraphUpdateCommand
{
public:
    explicit MoveCommand(TikzScene *scene,
                         QMap<Node*,QPointF> oldNodePositions,
                         QMap<Node*,QPointF> newNodePositions,
                         QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    QMap<Node*,QPointF> _oldNodePositions;
    QMap<Node*,QPointF> _newNodePositions;
};

class EdgeBendCommand : public GraphUpdateCommand
{
public:
    explicit EdgeBendCommand(TikzScene *scene, Edge *edge,
                             qreal oldWeight, int oldBend,
                             int oldInAngle, int oldOutAngle,
                             QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    Edge *_edge;
    qreal _oldWeight;
    int _oldBend;
    int _oldInAngle;
    int _oldOutAngle;
    qreal _newWeight;
    int _newBend;
    int _newInAngle;
    int _newOutAngle;
};

class ReverseEdgesCommand : public GraphUpdateCommand
{
public:
    explicit ReverseEdgesCommand(TikzScene *scene, QSet<Edge*> edgeSet,
                                 QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    QSet<Edge*> _edgeSet;
};

class DeleteCommand : public GraphUpdateCommand
{
public:
    explicit DeleteCommand(TikzScene *scene,
                           QMap<int,Node*> deleteNodes,
                           QMap<int,Edge*> deleteEdges,
                           QSet<Node*> selNodes,
                           QSet<Edge*> selEdges,
                           QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    QMap<int,Node*> _deleteNodes;
    QMap<int,Edge*> _deleteEdges;
    QSet<Node*> _selNodes;
    QSet<Edge*> _selEdges;
};

class AddNodeCommand : public GraphUpdateCommand
{
public:
    explicit AddNodeCommand(TikzScene *scene, Node *node, QRectF newBounds,
                            QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    Node *_node;
    QRectF _oldBounds;
    QRectF _newBounds;
};

class AddEdgeCommand : public GraphUpdateCommand
{
public:
    explicit AddEdgeCommand(TikzScene *scene, Edge *edge,
                            bool selectEdge=false,
                            QSet<Node *> selNodes=QSet<Node*>(),
                            QSet<Edge *> selEdges=QSet<Edge*>(),
                            QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    Edge *_edge;
    bool _selectEdge;
    QSet<Node*> _selNodes;
    QSet<Edge*> _selEdges;
};

class ChangeEdgeModeCommand : public GraphUpdateCommand
{
public:
    explicit ChangeEdgeModeCommand(TikzScene *scene, Edge *edge, QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    Edge *_edge;
};

class ApplyStyleToNodesCommand : public GraphUpdateCommand
{
public:
    explicit ApplyStyleToNodesCommand(TikzScene *scene, QString style, QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    QString _style;
    QMap<Node*,QString> _oldStyles;
};

class ApplyStyleToEdgesCommand : public GraphUpdateCommand
{
public:
	explicit ApplyStyleToEdgesCommand(TikzScene *scene, QString style, QUndoCommand *parent = nullptr);
	void undo() override;
	void redo() override;
private:
	QString _style;
	QMap<Edge*, QString> _oldStyles;
};

class PasteCommand : public GraphUpdateCommand
{
public:
    explicit PasteCommand(TikzScene *scene, Graph *graph, QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    Graph *_graph;
    QSet<Node*> _oldSelectedNodes;
	QSet<Edge*> _oldSelectedEdges;
};

class ChangeLabelCommand : public GraphUpdateCommand
{
public:
    explicit ChangeLabelCommand(TikzScene *scene,
                                QMap<Node*,QString> oldLabels,
                                QString newLabel,
                                QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    QMap<Node*,QString> _oldLabels;
    QString _newLabel;
};

class ReplaceGraphCommand : public GraphUpdateCommand
{
public:
    explicit ReplaceGraphCommand(TikzScene *scene,
                                 Graph *oldGraph,
                                 Graph *newGraph,
                                 QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    Graph *_oldGraph;
    Graph *_newGraph;
};

class ReflectNodesCommand : public GraphUpdateCommand
{
public:
    explicit ReflectNodesCommand(TikzScene *scene,
                                 QSet<Node*> nodes,
                                 bool horizontal,
                                 QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    QSet<Node*> _nodes;
    bool _horizontal;
};

class RotateNodesCommand : public GraphUpdateCommand
{
public:
    explicit RotateNodesCommand(TikzScene *scene,
                                QSet<Node*> nodes,
                                bool clockwise,
                                QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    QSet<Node*> _nodes;
    bool _clockwise;
};

class ReorderCommand : public GraphUpdateCommand
{
public:
    explicit ReorderCommand(TikzScene *scene,
                            const QVector<Node*> &oldNodeOrder,
                            const QVector<Node*> &newNodeOrder,
                            const QVector<Edge*> &oldEdgeOrder,
                            const QVector<Edge*> &newEdgeOrder,
                            QUndoCommand *parent = nullptr);
    void undo() override;
    void redo() override;
private:
    QVector<Node*> _oldNodeOrder;
    QVector<Node*> _newNodeOrder;
    QVector<Edge*> _oldEdgeOrder;
    QVector<Edge*> _newEdgeOrder;
};

#endif // UNDOCOMMANDS_H