File: undo_stack.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 (42 lines) | stat: -rw-r--r-- 889 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
#pragma once

#include <QUndoStack>

#include "undo/undo_command.h"

class Node;
class Datum;
class Graph;
class UndoCommand;

class UndoStack : public QUndoStack
{
public:
    UndoStack(QObject* parent=NULL);

    /*
     *  Performs a pointer swap for all commands in the stack
     */
    template <class T>
    void swapPointer(T* a, T* b)
    {
        for (int i=0; i < count(); ++i)
            swapPointer(a, b, command(i));
    }

    void push(UndoCommand* c);

protected:
    /*
     *  Performs a pointer swap for a specific command.
     *  (and recursively on its children)
     */
    template <class T>
    static void swapPointer(T* a, T* b, const QUndoCommand* cmd)
    {
        if (auto u = dynamic_cast<const UndoCommand*>(cmd))
            u->swapPointer(a, b);
        for (int i=0; i < cmd->childCount(); ++i)
            swapPointer(a, b, cmd->child(i));
    }
};