File indexing completed on 2024-05-12 16:35:12
0001 /* This file is part of the KDE project 0002 Copyright 2009 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_PASTE_COMMAND 0021 #define CALLIGRA_SHEETS_PASTE_COMMAND 0022 0023 #include "AbstractRegionCommand.h" 0024 0025 #include <KoXmlReader.h> 0026 0027 #include "Global.h" 0028 0029 #include "sheets_common_export.h" 0030 0031 class QMimeData; 0032 class KoXmlDocument; 0033 0034 namespace Calligra 0035 { 0036 namespace Sheets 0037 { 0038 0039 /** 0040 * \ingroup Commands 0041 * \brief Command to paste cell data. 0042 */ 0043 class CALLIGRA_SHEETS_COMMON_TEST_EXPORT PasteCommand : public AbstractRegionCommand 0044 { 0045 public: 0046 PasteCommand(KUndo2Command *parent = 0); 0047 ~PasteCommand() override; 0048 0049 /** 0050 * Modes used for paste with insertion. 0051 */ 0052 enum InsertionMode { 0053 NoInsertion, ///< No cell insertion. 0054 ShiftCells, ///< Shift cells; determine the direction from the data. 0055 ShiftCellsRight, ///< Shift cells to the right. 0056 ShiftCellsDown ///< Shift cells to the bottom. 0057 }; 0058 0059 const QMimeData* mimeData() const; 0060 bool setMimeData(const QMimeData *mimeData); 0061 void setInsertionMode(InsertionMode mode); 0062 void setMode(Paste::Mode mode); 0063 void setOperation(Paste::Operation operation); 0064 void setPasteFC(bool force); 0065 0066 virtual bool isApproved() const; 0067 0068 /** 0069 * \param mimeData the MIME data to check 0070 * \return \c true , if the MIME type is supported. 0071 */ 0072 static bool supports(const QMimeData *mimeData); 0073 0074 /** 0075 * Checks whether the clipboard data contains columns or rows. 0076 * Used to decide whether the paste with insertion dialog, where 0077 * you can choose between shifting cells down or to the right, 0078 * has to be shown. 0079 * \param mimeData the MIME data to check 0080 * \return \c true if the shifting direction is not defined 0081 * \return \c false if the clipboard data contains a column or a row 0082 */ 0083 static bool unknownShiftDirection(const QMimeData *mimeData); 0084 0085 protected: 0086 bool preProcessing() override; 0087 bool mainProcessing() override; 0088 bool postProcessing() override; 0089 0090 /** 0091 * Creates sub-commands for the region \p element by parsing XML \p data. 0092 */ 0093 bool processXmlData(Element *element, KoXmlDocument *data); 0094 0095 /** 0096 * Creates sub-commands for the region \p element by parsing plain text. 0097 */ 0098 bool processTextPlain(Element *element); 0099 0100 private: 0101 const QMimeData * m_mimeData; 0102 KoXmlDocument * m_xmlDocument; 0103 InsertionMode m_insertMode; 0104 Paste::Mode m_pasteMode; 0105 Paste::Operation m_operation; 0106 bool m_pasteFC; 0107 }; 0108 0109 } // namespace Sheets 0110 } // namespace Calligra 0111 0112 #endif // CALLIGRA_SHEETS_PASTE_COMMAND