File: undo_delete_node.h

package info (click to toggle)
antimony 0.9.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,476 kB
  • sloc: cpp: 42,596; ansic: 28,661; python: 1,093; yacc: 128; lex: 114; sh: 90; makefile: 10
file content (68 lines) | stat: -rw-r--r-- 1,664 bytes parent folder | download | duplicates (3)
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
#pragma once

#include <QList>
#include <QMap>
#include <QJsonObject>

#include "undo/undo_command.h"

class UndoDeleteMulti;

class UndoDeleteNode : public UndoCommand
{
public:
    /*
     *  UndoDeleteNode constructor can only be called with a parent
     *  UndoDeleteMulti object, as deleting nodes needs to be done
     *  along-side deleting their links.
     */
    UndoDeleteNode(Node* n, UndoDeleteMulti* parent);

    /*
     *  Actual commands to execute undo and redo
     */
    void redo() override;
    void undo() override;

    /*
     *  Node and graph pointer swap
     */
    void swapPointer(Node* a, Node* b) const override;
    void swapPointer(Graph* a, Graph* b) const override;

protected:
    /*
     *  Protected constructor used in UndoAddNode subclass
     */
    UndoDeleteNode(Node* n);

    struct ChildPointers
    {
        QList<Datum*> datums;
        QList<Node*> nodes;
        QList<Graph*> graphs;
    };

    /*
     *  Walk child datums and nodes in a deterministic order
     */
    ChildPointers walkChildren() const;

    /*
     *  Calls stack->swapPointer from every a to every b
     */
    template <class T>
    void pointerSwapList(QList<T*> as, QList<T*> bs);

    /*  Pointer to the target node and its parent graph */
    mutable Node* n;
    mutable Graph* g;

    /*  This object stores the serialized node  */
    QJsonObject data;

    /*  Pointers to datums and nodes (if this is a GraphNode) stored within   *
     *  the target node.  These lists are generated in a deterministic order  *
     *  and used for pointer swaps on undo / redo.                            */
    ChildPointers children;
};