-
-
Save jp9000/807bc8a65a937e5a2362e65cde7d4086 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <json11/json11.hpp> | |
#include <QString> | |
#include <functional> | |
#include <vector> | |
#include <string> | |
#include <deque> | |
typedef std::function<void(const json11::Json &s)> undo_redo_cb; | |
struct undo_item { | |
QString name; | |
json11::Json undo_data; | |
json11::Json redo_data; | |
undo_redo_cb undo; | |
undo_redo_cb redo; | |
}; | |
class undo_stack { | |
std::deque<undo_item> items; | |
size_t index = 0; | |
public: | |
void add_action(const QString &name, | |
undo_redo_cb undo, | |
undo_redo_cb redo, | |
json11::Json undo_data, | |
json11::Json redo_data); | |
void undo(QString &undo_name, QString &redo_name); | |
void redo(QString &undo_name, QString &redo_name); | |
inline void clear() | |
{ | |
items.clear(); | |
index = 0; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment