undo.h
Go to the documentation of this file.
00001 /* 00002 * undo.h - undo/redo facility 00003 * Program: kalarm 00004 * Copyright (C) 2005 by David Jarvie <software@astrojar.org.uk> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along 00017 * with this program; if not, write to the Free Software Foundation, Inc., 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef UNDO_H 00022 #define UNDO_H 00023 00026 #include <tqvaluelist.h> 00027 #include <tqstringlist.h> 00028 00029 class KAEvent; 00030 class UndoItem; 00031 00032 00033 class Undo : public TQObject 00034 { 00035 Q_OBJECT 00036 00037 public: 00038 enum Type { NONE, UNDO, REDO }; 00039 00040 static Undo* instance(); 00041 static void saveAdd(const KAEvent&); 00042 static void saveEdit(const KAEvent& oldEvent, const KAEvent& newEvent); 00043 static void saveDelete(const KAEvent&); 00044 static void saveDeletes(const TQValueList<KAEvent>&); 00045 static void saveReactivate(const KAEvent&); 00046 static void saveReactivates(const TQValueList<KAEvent>&); 00047 static bool undo(TQWidget* parent, const TQString& action) 00048 { return undo(mUndoList.begin(), UNDO, parent, action); } 00049 static bool undo(int id, TQWidget* parent, const TQString& action) 00050 { return undo(findItem(id, UNDO), UNDO, parent, action); } 00051 static bool redo(TQWidget* parent, const TQString& action) 00052 { return undo(mRedoList.begin(), REDO, parent, action); } 00053 static bool redo(int id, TQWidget* parent, const TQString& action) 00054 { return undo(findItem(id, REDO), REDO, parent, action); } 00055 static void clear(); 00056 static bool haveUndo() { return !mUndoList.isEmpty(); } 00057 static bool haveRedo() { return !mRedoList.isEmpty(); } 00058 static TQString actionText(Type); 00059 static TQString actionText(Type, int id); 00060 static TQString description(Type, int id); 00061 static TQValueList<int> ids(Type); 00062 static void emitChanged(); 00063 00064 // Types for use by UndoItem class and its descendants 00065 typedef TQValueList<UndoItem*> List; 00066 00067 signals: 00068 void changed(const TQString& undo, const TQString& redo); 00069 00070 protected: 00071 // Methods for use by UndoItem class 00072 static void add(UndoItem*, bool undo); 00073 static void remove(UndoItem*, bool undo); 00074 static void replace(UndoItem* old, UndoItem* New); 00075 00076 private: 00077 typedef TQValueList<UndoItem*>::Iterator Iterator; 00078 00079 Undo(TQObject* parent) : TQObject(parent) { } 00080 static void removeRedos(const TQString& eventID); 00081 static bool undo(Iterator, Type, TQWidget* parent, const TQString& action); 00082 static UndoItem* getItem(int id, Type); 00083 static Iterator findItem(int id, Type); 00084 void emitChanged(const TQString& undo, const TQString& redo) 00085 { emit changed(undo, redo); } 00086 00087 static Undo* mInstance; // the one and only Undo instance 00088 static List mUndoList; // edit history for undo, latest undo first 00089 static List mRedoList; // edit history for redo, latest redo first 00090 00091 friend class UndoItem; 00092 }; 00093 00094 #endif // UNDO_H