Warning, file /office/calligra/libs/text/KoTextCommandBase.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007 Thomas Zander <zander@kde.org> 0003 * Copyright (C) 2011 Boudewijn Rempt <boud@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 #ifndef KO_TEXT_COMMAND_BASE_H 0021 #define KO_TEXT_COMMAND_BASE_H 0022 0023 #include <kundo2command.h> 0024 0025 #include "kotext_export.h" 0026 0027 class KOTEXT_EXPORT KoUndoableTool { 0028 public: 0029 virtual ~KoUndoableTool(){} 0030 virtual void setAddUndoCommandAllowed(bool allowed) = 0; 0031 }; 0032 0033 /** 0034 * Base class for all commands that work together with a tool that needs to handle undo/redo 0035 * in a tricky way. 0036 * Due to the fact that QTextDocument has its own undo queue we need to do some trickery 0037 * to integrate that into the apps. 0038 * If your command in some way changes the document, it will create unwanted undo commands in the undoStack 0039 * unless you inherit from this class and simply implement your undo and redo like this: 0040 @code 0041 void MyCommand::redo() { 0042 TextCommandBase::redo(); 0043 UndoRedoFinalizer finalizer(m_tool); 0044 // rest code 0045 } 0046 0047 void MyCommand::undo() { 0048 TextCommandBase::undo(); 0049 UndoRedoFinalizer finalizer(m_tool); 0050 // rest code 0051 } 0052 @endcode 0053 * @see TextTool::addCommand() 0054 */ 0055 class KOTEXT_EXPORT KoTextCommandBase : public KUndo2Command 0056 { 0057 public: 0058 0059 /// constructor 0060 explicit KoTextCommandBase(KUndo2Command *parent); 0061 ~KoTextCommandBase() override; 0062 0063 /// method called by the tool. 0064 void setTool(KoUndoableTool *tool); 0065 0066 // reimplemented from KUndo2Command 0067 void redo() override; 0068 // reimplemented from KUndo2Command 0069 void undo() override; 0070 0071 /// Sets the m_allowAddUndoCommand of the associated tool 0072 void setAllow(bool set); 0073 0074 protected: 0075 0076 class KOTEXT_EXPORT UndoRedoFinalizer 0077 { 0078 public: 0079 explicit UndoRedoFinalizer(KoTextCommandBase* parent) : m_parent(parent) {} 0080 ~UndoRedoFinalizer(); 0081 private: 0082 KoTextCommandBase* m_parent; 0083 }; 0084 0085 KoUndoableTool *m_tool; 0086 }; 0087 0088 #endif