00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef UNDO_H
00022 #define UNDO_H
00023
00026 #include <QList>
00027 #include <QStringList>
00028 #include "autodeletelist.h"
00029
00030 class KAEvent;
00031 class AlarmResource;
00032 class UndoItem;
00033
00034
00035 class Undo : public QObject
00036 {
00037 Q_OBJECT
00038 public:
00039 enum Type { NONE, UNDO, REDO };
00040
00041
00042
00043 struct Event
00044 {
00045 Event() {}
00046 Event(const KAEvent&, AlarmResource*);
00047 KAEvent event;
00048 AlarmResource* resource;
00049 QStringList dontShowErrors;
00050 };
00051 class EventList : public QList<Event>
00052 {
00053 public:
00054 void append(const KAEvent& e, AlarmResource* r) { QList<Event>::append(Event(e, r)); }
00055 };
00056
00057 static Undo* instance();
00058 static void saveAdd(const KAEvent&, AlarmResource*, const QString& name = QString());
00059 static void saveAdds(const EventList&, const QString& name = QString());
00060 static void saveEdit(const Event& oldEvent, const KAEvent& newEvent);
00061 static void saveDelete(const Event&, const QString& name = QString());
00062 static void saveDeletes(const EventList&, const QString& name = QString());
00063 static void saveReactivate(const KAEvent&, AlarmResource*, const QString& name = QString());
00064 static void saveReactivates(const EventList&, const QString& name = QString());
00065 static bool undo(QWidget* parent, const QString& action)
00066 { return undo(0, UNDO, parent, action); }
00067 static bool undo(int id, QWidget* parent, const QString& action)
00068 { return undo(findItem(id, UNDO), UNDO, parent, action); }
00069 static bool redo(QWidget* parent, const QString& action)
00070 { return undo(0, REDO, parent, action); }
00071 static bool redo(int id, QWidget* parent, const QString& action)
00072 { return undo(findItem(id, REDO), REDO, parent, action); }
00073 static void clear();
00074 static bool haveUndo() { return !mUndoList.isEmpty(); }
00075 static bool haveRedo() { return !mRedoList.isEmpty(); }
00076 static QString actionText(Type);
00077 static QString actionText(Type, int id);
00078 static QString description(Type, int id);
00079 static QList<int> ids(Type);
00080 static void emitChanged();
00081
00082
00083 typedef AutoDeleteList<UndoItem> List;
00084
00085 signals:
00086 void changed(const QString& undo, const QString& redo);
00087
00088 protected:
00089
00090 static void add(UndoItem*, bool undo);
00091 static void remove(UndoItem*, bool undo);
00092 static void replace(UndoItem* old, UndoItem* New);
00093
00094 private:
00095 Undo(QObject* parent) : QObject(parent) { }
00096 static void removeRedos(const QString& eventID);
00097 static bool undo(int index, Type, QWidget* parent, const QString& action);
00098 static UndoItem* getItem(int id, Type);
00099 static int findItem(int id, Type);
00100 void emitChanged(const QString& undo, const QString& redo)
00101 { emit changed(undo, redo); }
00102
00103 static Undo* mInstance;
00104 static List mUndoList;
00105 static List mRedoList;
00106
00107 friend class UndoItem;
00108 };
00109
00110 #endif // UNDO_H