Delete UndoCommands when the UndoHistory is destroyed

This commit is contained in:
David Capello 2015-05-20 16:51:07 -03:00
parent c04f4976fb
commit e730b90958
4 changed files with 19 additions and 2 deletions

View File

@ -17,6 +17,12 @@ CmdSequence::CmdSequence()
{
}
CmdSequence::~CmdSequence()
{
for (Cmd* cmd : m_cmds)
delete cmd;
}
void CmdSequence::add(Cmd* cmd)
{
m_cmds.push_back(cmd);

View File

@ -18,6 +18,7 @@ namespace app {
class CmdSequence : public Cmd {
public:
CmdSequence();
~CmdSequence();
void add(Cmd* cmd);

View File

@ -82,11 +82,10 @@ void UndoHistory::clearRedo()
void UndoHistory::add(UndoCommand* cmd)
{
UndoState* state = new UndoState;
UndoState* state = new UndoState(cmd);
state->m_prev = m_last;
state->m_next = nullptr;
state->m_parent = m_cur;
state->m_cmd = cmd;
if (!m_first)
m_first = state;

View File

@ -8,6 +8,8 @@
#define UNDO_UNDO_STATE_H_INCLUDED
#pragma once
#include "undo/undo_command.h"
namespace undo {
class UndoCommand;
@ -18,6 +20,15 @@ namespace undo {
class UndoState {
friend class UndoHistory;
public:
UndoState(UndoCommand* cmd)
: m_prev(nullptr)
, m_next(nullptr)
, m_parent(nullptr)
, m_cmd(cmd) {
}
~UndoState() {
delete m_cmd;
}
UndoState* prev() const { return m_prev; }
UndoState* next() const { return m_next; }
UndoCommand* cmd() const { return m_cmd; }