Skip to content

Commit

Permalink
Remove UndoSystem::Observer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 1, 2017
1 parent b1953ec commit 6405397
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 66 deletions.
13 changes: 0 additions & 13 deletions include/iundo.h
Expand Up @@ -72,19 +72,6 @@ class UndoSystem :
virtual void redo() = 0;
virtual void clear() = 0;

class Observer {
public:
virtual ~Observer() {}
// Gets called after an undo operation is fully completed, allows objects to refresh their state
virtual void postUndo() = 0;
// Gets called after a redo operation is fully completed, allows objects to refresh their state
virtual void postRedo() = 0;
};

// Adds/removes an observer, which gets called on certain events
virtual void addObserver(Observer* observer) = 0;
virtual void removeObserver(Observer* observer) = 0;

// Emitted after an undo operation is fully completed, allows objects to refresh their state
virtual sigc::signal<void>& signal_postUndo() = 0;

Expand Down
69 changes: 16 additions & 53 deletions plugins/undo/UndoSystem.cpp
Expand Up @@ -40,11 +40,7 @@ namespace
class RadiantUndoSystem :
public UndoSystem
{
// The operation Observers which get notified on certain events
// This is not a set to retain the order of the observers
typedef std::list<Observer*> Observers;
Observers _observers;

private:
static const std::size_t MAX_UNDO_LEVELS = 16384;

// The undo and redo stacks
Expand Down Expand Up @@ -84,23 +80,23 @@ class RadiantUndoSystem :
return &_undoables[&undoable];
}

IUndoStateSaver* getStateSaver(IUndoable& undoable, IMapFileChangeTracker& tracker)
IUndoStateSaver* getStateSaver(IUndoable& undoable, IMapFileChangeTracker& tracker) override
{
auto result = _undoables.insert(std::make_pair(&undoable, UndoStackFiller(tracker)));
return &(result.first->second);
}

void releaseStateSaver(IUndoable& undoable)
void releaseStateSaver(IUndoable& undoable) override
{
_undoables.erase(&undoable);
}

std::size_t size() const
std::size_t size() const override
{
return _undoStack.size();
}

void start()
void start() override
{
_redoStack.clear();
if (_undoStack.size() == _undoLevels)
Expand All @@ -113,7 +109,7 @@ class RadiantUndoSystem :

// greebo: This finishes the current operation and
// removes it instantly from the stack
void cancel()
void cancel() override
{
// Try to add the last operation as "temp"
if (finishUndo("$TEMPORARY"))
Expand All @@ -123,13 +119,14 @@ class RadiantUndoSystem :
}
}

void finish(const std::string& command) {
void finish(const std::string& command) override
{
if (finishUndo(command)) {
rMessage() << command << std::endl;
}
}

void undo()
void undo() override
{
if (_undoStack.empty())
{
Expand All @@ -146,12 +143,6 @@ class RadiantUndoSystem :
finishRedo(operation->getName());
_undoStack.pop_back();

for (Observers::iterator i = _observers.begin(); i != _observers.end(); /* in-loop */)
{
Observer* observer = *(i++);
observer->postUndo();
}

_signalPostUndo.emit();

// Trigger the onPostUndo event on all scene nodes
Expand All @@ -164,7 +155,7 @@ class RadiantUndoSystem :
GlobalSceneGraph().sceneChanged();
}

void redo()
void redo() override
{
if (_redoStack.empty())
{
Expand All @@ -181,12 +172,6 @@ class RadiantUndoSystem :
finishUndo(operation->getName());
_redoStack.pop_back();

for (Observers::iterator i = _observers.begin(); i != _observers.end(); /* in-loop */)
{
Observer* observer = *(i++);
observer->postRedo();
}

_signalPostRedo.emit();

// Trigger the onPostRedo event on all scene nodes
Expand All @@ -199,7 +184,7 @@ class RadiantUndoSystem :
GlobalSceneGraph().sceneChanged();
}

void clear()
void clear() override
{
setActiveUndoStack(NULL);
_undoStack.clear();
Expand All @@ -210,28 +195,6 @@ class RadiantUndoSystem :
// there are some "persistent" observers like EntityInspector and ShaderClipboard
}

void addObserver(Observer* observer)
{
// Ensure no observer is added twice
assert(std::find(_observers.begin(), _observers.end(), observer) == _observers.end());

// Observers are added to the end of the list
_observers.push_back(observer);
}

void removeObserver(Observer* observer)
{
Observers::iterator i = std::find(_observers.begin(), _observers.end(), observer);

// Ensure that the observer is actually registered
assert(i != _observers.end());

if (i != _observers.end())
{
_observers.erase(i);
}
}

sigc::signal<void>& signal_postUndo() override
{
return _signalPostUndo;
Expand All @@ -243,26 +206,26 @@ class RadiantUndoSystem :
return _signalPostRedo;
}

void attachTracker(Tracker& tracker)
void attachTracker(Tracker& tracker) override
{
ASSERT_MESSAGE(_trackers.find(&tracker) == _trackers.end(), "undo tracker already attached");
_trackers.insert(&tracker);
}

void detachTracker(Tracker& tracker)
void detachTracker(Tracker& tracker) override
{
ASSERT_MESSAGE(_trackers.find(&tracker) != _trackers.end(), "undo tracker cannot be detached");
_trackers.erase(&tracker);
}

// RegisterableModule implementation
virtual const std::string& getName() const
virtual const std::string& getName() const override
{
static std::string _name(MODULE_UNDOSYSTEM);
return _name;
}

virtual const StringSet& getDependencies() const
virtual const StringSet& getDependencies() const override
{
static StringSet _dependencies;

Expand All @@ -279,7 +242,7 @@ class RadiantUndoSystem :
return _dependencies;
}

virtual void initialiseModule(const ApplicationContext& ctx)
virtual void initialiseModule(const ApplicationContext& ctx) override
{
rMessage() << "UndoSystem::initialiseModule called" << std::endl;

Expand Down

0 comments on commit 6405397

Please sign in to comment.