File indexing completed on 2024-05-19 16:07:59
0001 /* This file is part of the KDE project 0002 Copyright 2005,2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef CALLIGRA_SHEETS_ABSTRACT_REGION_COMMAND 0021 #define CALLIGRA_SHEETS_ABSTRACT_REGION_COMMAND 0022 0023 #include <kundo2command.h> 0024 0025 #include "Region.h" 0026 0027 #include "sheets_common_export.h" 0028 0029 class KoCanvasBase; 0030 0031 namespace Calligra 0032 { 0033 namespace Sheets 0034 { 0035 class Sheet; 0036 0037 /** 0038 * \class AbstractRegionCommand 0039 * \ingroup Commands 0040 * \brief Abstract base class for all region related operations. 0041 */ 0042 class CALLIGRA_SHEETS_COMMON_EXPORT AbstractRegionCommand : public Region, public KUndo2Command 0043 { 0044 public: 0045 /** 0046 * Constructor. 0047 */ 0048 explicit AbstractRegionCommand(KUndo2Command *parent = 0); 0049 0050 /** 0051 * Destructor. 0052 */ 0053 ~AbstractRegionCommand() override; 0054 0055 /** 0056 * \return the Sheet this AbstractRegionCommand works on 0057 */ 0058 Sheet* sheet() const { 0059 return m_sheet; 0060 } 0061 0062 /** 0063 * Sets \p sheet to be the Sheet to work on. 0064 */ 0065 void setSheet(Sheet* sheet) { 0066 m_sheet = sheet; 0067 } 0068 0069 /** 0070 * Executes the actual operation and adds the manipulator to the undo history, if desired. 0071 * \return \c true if the command was executed successfully 0072 * \return \c false if the command fails, was already executed once or is not approved 0073 * \see setRegisterUndo, isApproved 0074 */ 0075 virtual bool execute(KoCanvasBase* canvas = 0); 0076 0077 /** 0078 * Executes the actual operation. 0079 */ 0080 void redo() override; 0081 0082 /** 0083 * Executes the actual operation in reverse order. 0084 */ 0085 void undo() override; 0086 0087 /** 0088 * Sets reverse mode to \b reverse . 0089 * \see redo 0090 * \see undo 0091 */ 0092 virtual void setReverse(bool reverse) { 0093 m_reverse = reverse; 0094 } 0095 0096 /** 0097 * If \p registerUndo is \c true , this manipulator registers an 0098 * undo operation for the document. 0099 */ 0100 void setRegisterUndo(bool registerUndo) { 0101 m_register = registerUndo; 0102 } 0103 0104 protected: 0105 /** 0106 * Processes \p element , a Region::Point or a Region::Range . 0107 * Invoked by mainProcessing() . 0108 */ 0109 virtual bool process(Element*) { 0110 return true; 0111 } 0112 0113 /** 0114 * Preprocessing of the region. 0115 */ 0116 virtual bool preProcessing() { 0117 return true; 0118 } 0119 0120 /** 0121 * Processes the region. Calls process(Element*). 0122 */ 0123 virtual bool mainProcessing(); 0124 0125 /** 0126 * Postprocessing of the region. 0127 */ 0128 virtual bool postProcessing() { 0129 return true; 0130 } 0131 0132 /** 0133 * Checks all cells, that should be processed, for protection and matrix locks. 0134 * \return \c true if execution is approved 0135 * \return \c false otherwise 0136 */ 0137 bool isApproved() const; 0138 0139 protected: 0140 Sheet* m_sheet; 0141 bool m_reverse : 1; 0142 bool m_firstrun : 1; 0143 bool m_register : 1; 0144 bool m_success : 1; 0145 bool m_checkLock : 1; 0146 }; 0147 0148 } // namespace Sheets 0149 } // namespace Calligra 0150 0151 #endif // CALLIGRA_SHEETS_ABSTRACT_REGION_COMMAND