summaryrefslogtreecommitdiff
path: root/src/gui/undocommands.h
blob: 354e455f741289ec5855c94fa0d56c3e3418aae5 (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
/*!
  * \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>

class GraphUpdateCommand : public QUndoCommand {
public:
    explicit GraphUpdateCommand(TikzScene *scene,
                                QUndoCommand *parent = 0);
    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 = 0);
    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,
                             float oldWeight, int oldBend,
                             int oldInAngle, int oldOutAngle,
                             QUndoCommand *parent = 0);
    void undo() override;
    void redo() override;
private:
    Edge *_edge;
    float _oldWeight;
    int _oldBend;
    int _oldInAngle;
    int _oldOutAngle;
    float _newWeight;
    int _newBend;
    int _newInAngle;
    int _newOutAngle;
};

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

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

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

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

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

class PasteCommand : public GraphUpdateCommand
{
public:
    explicit PasteCommand(TikzScene *scene, Graph *graph, QUndoCommand *parent = 0);
    void undo() override;
    void redo() override;
private:
    Graph *_graph;
    QList<QGraphicsItem*> _oldSelection;
};

#endif // UNDOCOMMANDS_H