Warning, file /pim/kalarm/src/undo.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * undo.h - undo/redo facility 0003 * Program: kalarm 0004 * SPDX-FileCopyrightText: 2005-2022 David Jarvie <djarvie@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 /** @file undo.h - undo/redo facility */ 0012 0013 #include "resources/resource.h" 0014 #include "lib/autodeletelist.h" 0015 #include "kalarmcalendar/kaevent.h" 0016 0017 #include <QStringList> 0018 0019 class UndoItem; 0020 using namespace KAlarmCal; 0021 0022 0023 class Undo : public QObject 0024 { 0025 Q_OBJECT 0026 public: 0027 enum Type { NONE, UNDO, REDO }; 0028 // N.B. The Event structure must be constructed before the action for 0029 // which the undo is being created is carried out, since the 0030 // don't-show-errors status is not contained within the KAEvent itself. 0031 struct Event 0032 { 0033 Event() = default; 0034 Event(const KAEvent&, const Resource&); 0035 KAEvent event; 0036 mutable Resource resource; 0037 QStringList dontShowErrors; 0038 }; 0039 class EventList : public QList<Event> 0040 { 0041 public: 0042 void append(const KAEvent& e, const Resource& res) { QList<Event>::append(Event(e, res)); } 0043 }; 0044 0045 static Undo* instance(); 0046 static void saveAdd(const KAEvent&, const Resource&, const QString& name = QString()); 0047 static void saveAdds(const EventList&, const QString& name = QString()); 0048 static void saveEdit(const Event& oldEvent, const KAEvent& newEvent); 0049 static void saveDelete(const Event&, const QString& name = QString()); 0050 static void saveDeletes(const EventList&, const QString& name = QString()); 0051 static void saveReactivate(const KAEvent&, const Resource&, const QString& name = QString()); 0052 static void saveReactivates(const EventList&, const QString& name = QString()); 0053 static bool undo(QWidget* parent, const QString& action) 0054 { return undo(0, UNDO, parent, action); } 0055 static bool undo(int id, QWidget* parent, const QString& action) 0056 { return undo(findItem(id, UNDO), UNDO, parent, action); } 0057 static bool redo(QWidget* parent, const QString& action) 0058 { return undo(0, REDO, parent, action); } 0059 static bool redo(int id, QWidget* parent, const QString& action) 0060 { return undo(findItem(id, REDO), REDO, parent, action); } 0061 static void clear(); 0062 static bool haveUndo() { return !mUndoList.isEmpty(); } 0063 static bool haveRedo() { return !mRedoList.isEmpty(); } 0064 static QString actionText(Type); 0065 static QString actionText(Type, int id); 0066 static QString description(Type, int id); 0067 static QList<int> ids(Type); 0068 static void emitChanged(); 0069 static void dumpDebug(Type, int count); 0070 0071 // Types for use by UndoItem class and its descendants 0072 using List = AutoDeleteList<UndoItem>; 0073 0074 Q_SIGNALS: 0075 void changed(const QString& undo, const QString& redo); 0076 0077 protected: 0078 // Methods for use by UndoItem class 0079 static void add(UndoItem*, bool undo); 0080 static void remove(UndoItem*, bool undo); 0081 static void replace(UndoItem* old, UndoItem* New); 0082 0083 private: 0084 explicit Undo(QObject* parent) : QObject(parent) {} 0085 static void removeRedos(const QString& eventID); 0086 static bool undo(int index, Type, QWidget* parent, const QString& action); 0087 static UndoItem* getItem(int id, Type); 0088 static int findItem(int id, Type); 0089 void emitChanged(const QString& undo, const QString& redo) 0090 { Q_EMIT changed(undo, redo); } 0091 0092 static Undo* mInstance; // the one and only Undo instance 0093 static List mUndoList; // edit history for undo, latest undo first 0094 static List mRedoList; // edit history for redo, latest redo first 0095 0096 friend class UndoItem; 0097 }; 0098 0099 // vim: et sw=4: