undo.cpp
00001
00002
00003
00004
00005
00006
00007 #include "undo.h"
00008
00010
00011
00012 void StackBase::push(Command *c)
00013 {
00014 mCommandStack.push(c);
00015 emit changed();
00016 }
00017
00018 bool StackBase::isEmpty()
00019 {
00020 return mCommandStack.isEmpty();
00021 }
00022
00023 Command *StackBase::top()
00024 {
00025 return mCommandStack.top();
00026 }
00027
00028 void StackBase::clear()
00029 {
00030 mCommandStack.clear();
00031 emit changed();
00032 }
00033
00034 Command *StackBase::pop()
00035 {
00036 Command *c = mCommandStack.pop();
00037 if (c)
00038 emit changed();
00039
00040 return c;
00041 }
00042
00044
00045
00046 UndoStack* UndoStack::instance_ = 0;
00047
00048 UndoStack::UndoStack()
00049 : StackBase()
00050 {
00051
00052 }
00053
00054 UndoStack* UndoStack::instance()
00055 {
00056 if (!instance_)
00057 instance_ = new UndoStack();
00058 return instance_;
00059 }
00060
00061 void UndoStack::undo()
00062 {
00063 if (isEmpty())
00064 return;
00065
00066 Command *command = pop();
00067 command->undo();
00068
00069 RedoStack::instance()->push( command );
00070 }
00071
00073
00074
00075 RedoStack* RedoStack::instance_ = 0;
00076
00077 RedoStack::RedoStack()
00078 {
00079 mCommandStack.setAutoDelete( true );
00080 }
00081
00082 RedoStack* RedoStack::instance()
00083 {
00084 if (!instance_)
00085 instance_ = new RedoStack();
00086 return instance_;
00087 }
00088
00089 void RedoStack::redo()
00090 {
00091 Command *command;
00092 if (isEmpty())
00093 return;
00094
00095 command = pop();
00096 command->redo();
00097 UndoStack::instance()->push( command );
00098 }
00099
00100 #include "undo.moc"
This file is part of the documentation for kdelibs Version 3.1.4.