Skip to content

Instantly share code, notes, and snippets.

@jp9000
Created April 15, 2020 16:30
Show Gist options
  • Save jp9000/807bc8a65a937e5a2362e65cde7d4086 to your computer and use it in GitHub Desktop.
Save jp9000/807bc8a65a937e5a2362e65cde7d4086 to your computer and use it in GitHub Desktop.
#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