/* 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 . */ /*! * \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 #include 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 oldNodePositions, QMap newNodePositions, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: QMap _oldNodePositions; QMap _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 edgeSet, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: QSet _edgeSet; }; class DeleteCommand : public GraphUpdateCommand { public: explicit DeleteCommand(TikzScene *scene, QMap deleteNodes, QMap deleteEdges, QSet selNodes, QSet selEdges, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: QMap _deleteNodes; QMap _deleteEdges; QSet _selNodes; QSet _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 selNodes=QSet(), QSet selEdges=QSet(), QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: Edge *_edge; bool _selectEdge; QSet _selNodes; QSet _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 _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 _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 _oldSelectedNodes; QSet _oldSelectedEdges; }; class ChangeLabelCommand : public GraphUpdateCommand { public: explicit ChangeLabelCommand(TikzScene *scene, QMap oldLabels, QString newLabel, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: QMap _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 nodes, bool horizontal, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: QSet _nodes; bool _horizontal; }; class RotateNodesCommand : public GraphUpdateCommand { public: explicit RotateNodesCommand(TikzScene *scene, QSet nodes, bool clockwise, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: QSet _nodes; bool _clockwise; }; class ReorderCommand : public GraphUpdateCommand { public: explicit ReorderCommand(TikzScene *scene, const QVector &oldNodeOrder, const QVector &newNodeOrder, const QVector &oldEdgeOrder, const QVector &newEdgeOrder, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: QVector _oldNodeOrder; QVector _newNodeOrder; QVector _oldEdgeOrder; QVector _newEdgeOrder; }; #endif // UNDOCOMMANDS_H