src/edithistory.h

Wed, 22 Sep 2021 00:25:31 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 22 Sep 2021 00:25:31 +0300
changeset 135
d384df40c8e7
parent 133
e39326ee48dc
child 136
e8444e0d7f1a
permissions
-rw-r--r--

Merge commit

#pragma once
#include "main.h"
#include "model.h"
#include "modeleditcontext.h"

class AbstractHistoryEntry
{
public:
	virtual void undo(Model::EditContext& editContext) = 0;
	virtual void redo(Model::EditContext& editContext) = 0;
};

class InsertHistoryEntry : public AbstractHistoryEntry
{
public:
	InsertHistoryEntry(int position, const QString& code) :
		position{position},
		code{code} {}
	void undo(Model::EditContext& editContext) override;
	void redo(Model::EditContext& editContext) override;
protected:
	int position;
	QString code;
};

class DeleteHistoryEntry : public InsertHistoryEntry
{
public:
	void undo(Model::EditContext& editContext) override;
	void redo(Model::EditContext& editContext) override;
};

class EditHistoryEntry : public AbstractHistoryEntry
{
public:
	EditHistoryEntry(int position, const QString& codeBefore, const QString& codeAfter) :
		position{position},
		codeBefore{codeBefore},
		codeAfter{codeAfter} {}
	void undo(Model::EditContext& editContext) override;
	void redo(Model::EditContext& editContext) override;
private:
	int position;
	QString codeBefore;
	QString codeAfter;
};

class EditHistory
{
public:
	using Changeset = QVector<std::unique_ptr<AbstractHistoryEntry>>;
	EditHistory();
};

mercurial