1 /* 2 For general Scribus (>=1.3.2) copyright and licensing information please refer 3 to the COPYING file provided with the program. Following this notice may exist 4 a copyright and/or license notice that predates the release of Scribus 1.3.2 5 for which a new license (GPL+exception) is in place. 6 */ 7 /*************************************************************************** 8 * Copyright (C) 2005 by Riku Leino * 9 * riku@scribus.info * 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 * This program is distributed in the hope that it will be useful, * 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 19 * GNU General Public License for more details. * 20 * * 21 * You should have received a copy of the GNU General Public License * 22 * along with this program; if not, write to the * 23 * Free Software Foundation, Inc., * 24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 25 ***************************************************************************/ 26 27 #ifndef UNDOOBJECT_H 28 #define UNDOOBJECT_H 29 30 #include <QPixmap> 31 #include <QString> 32 33 #include "scribusapi.h" 34 #include "scguardedptr.h" 35 36 class UndoState; 37 38 /** 39 * @brief Superclass for all objects that are wanted to have undoable actions. 40 * 41 * The most important feature of UndoObject is the restore() method which must be 42 * implemented in the subclass. When an action that is wanted to be undoable 43 * happens UndoObject subclass must use UndoManager::action() method to store the 44 * action using UndoState object. Then when a user undos this action UndoManager 45 * will send the UndoState object back to this UndoObject by using the restore() 46 * method. 47 * 48 * What is needed for an undo/redo: 49 <ol> 50 <li>UndoObject creates an UndoState object describing the action</li> 51 <li>Sends it to the UndoManager</li> 52 <li>When an undo/redo is requested UndoManager will send this very same UndoState 53 object back to the UndoObject which then uses it to restore the state.</li> 54 </ol> 55 * 56 * @author Riku Leino riku@scribus.info 57 * @date December 2004 58 */ 59 class SCRIBUS_API UndoObject 60 { 61 public: 62 /** @brief Creates a new anonymous UndoObject instance */ 63 UndoObject(); 64 65 /** @brief Creates a copy of an UndoObject instance */ 66 UndoObject(const UndoObject& other); 67 68 /** 69 * @brief Creates a new UndoObject instance with the name <code>objectName</code> 70 * @param objectName Name of the UndoObject 71 */ 72 UndoObject(const QString &objectName, QPixmap *objectIcon = nullptr); 73 74 /** @brief Destroys the object. */ 75 virtual ~UndoObject(); 76 77 /** 78 * @brief Returns the name of the UndoObject. 79 * @return the name of the UndoObject 80 */ 81 virtual QString getUName() const; 82 83 /** 84 * @brief Set the name of the UndoObject 85 * @param newUName New name for the UndoObject 86 */ 87 virtual void setUName(const QString& newUName); 88 89 /** 90 * @brief Returns the pixmap connected to this object. 91 * @return pixmap connected to this object 92 */ 93 virtual QPixmap* getUPixmap() const; 94 95 /** 96 * @brief Set the pixmap for this object. 97 * @param newUPixmap pixmap for this object 98 */ 99 virtual void setUPixmap(QPixmap *newUPixmap); 100 101 /** 102 * @brief Returns an unique identifier number for the UndoObject 103 * @return unique identifier number for the UndoObjet 104 */ 105 ulong getUId() const; 106 107 /** 108 * @brief Returns a guarded pointer 109 */ 110 const ScGuardedPtr<UndoObject>& undoObjectPtr() const; 111 112 /** 113 * @brief Check if current object is owned by some undo state 114 */ 115 int undoStateCount() const; 116 117 /** 118 * @brief Method used when an undo/redo is requested. 119 * 120 * UndoObject must know how to handle the UndoState object given as a 121 * parameter. It is the same object that was send from the UndoObject to 122 * the UndoManager when the action happened. 123 * @param state State describing the action that is wanted to be undone/redone 124 * @param isUndo If true undo is wanted else if false redo. 125 */ 126 virtual void restore(UndoState* state, bool isUndo) = 0; 127 128 private: 129 /** @brief id number to be used with the next UndoObject */ 130 static ulong m_nextId; 131 132 /** @brief unique id number */ 133 ulong m_id; 134 135 /** 136 * @brief Name of the UndoObject 137 * 138 * This name will be used in UndoGui implementations 139 */ 140 QString m_uname; 141 142 /** 143 * @brief Icon presenting the object. 144 * 145 * When used together with an UndoAction that has an image is this image 146 * drawn first then the action image is drawn on top of this. 147 */ 148 QPixmap *m_upixmap {nullptr}; 149 150 /** 151 * @brief Guarded pointer 152 * 153 * Allows to warn undo system of an object deletion 154 */ 155 ScGuardedObject<UndoObject> m_objectPtr; 156 }; 157 typedef ScGuardedPtr<UndoObject> UndoObjectPtr; 158 159 class SCRIBUS_API DummyUndoObject : public UndoObject 160 { 161 public: DummyUndoObject()162 DummyUndoObject() {}; ~DummyUndoObject()163 virtual ~DummyUndoObject() {}; 164 //! \brief dummy implementation of the inherited one restore(UndoState *,bool)165 void restore(UndoState*, bool) {}; 166 }; 167 168 #endif 169