1 /* This file is part of the KDE project
2    Copyright 2009 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public
6    License as published by the Free Software Foundation; either
7    version 2 of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13 
14    You should have received a copy of the GNU Library General Public License
15    along with this library; see the file COPYING.LIB.  If not, write to
16    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17    Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef CALLIGRA_SHEETS_PASTE_COMMAND
21 #define CALLIGRA_SHEETS_PASTE_COMMAND
22 
23 #include "AbstractRegionCommand.h"
24 
25 #include <KoXmlReader.h>
26 
27 #include "Global.h"
28 
29 #include "sheets_common_export.h"
30 
31 class QMimeData;
32 class KoXmlDocument;
33 
34 namespace Calligra
35 {
36 namespace Sheets
37 {
38 
39 /**
40  * \ingroup Commands
41  * \brief Command to paste cell data.
42  */
43 class CALLIGRA_SHEETS_COMMON_TEST_EXPORT PasteCommand : public AbstractRegionCommand
44 {
45 public:
46     PasteCommand(KUndo2Command *parent = 0);
47     ~PasteCommand() override;
48 
49     /**
50      * Modes used for paste with insertion.
51      */
52     enum InsertionMode {
53         NoInsertion,     ///< No cell insertion.
54         ShiftCells,      ///< Shift cells; determine the direction from the data.
55         ShiftCellsRight, ///< Shift cells to the right.
56         ShiftCellsDown   ///< Shift cells to the bottom.
57     };
58 
59     const QMimeData* mimeData() const;
60     bool setMimeData(const QMimeData *mimeData);
61     void setInsertionMode(InsertionMode mode);
62     void setMode(Paste::Mode mode);
63     void setOperation(Paste::Operation operation);
64     void setPasteFC(bool force);
65 
66     virtual bool isApproved() const;
67 
68     /**
69      * \param mimeData the MIME data to check
70      * \return \c true , if the MIME type is supported.
71      */
72     static bool supports(const QMimeData *mimeData);
73 
74     /**
75      * Checks whether the clipboard data contains columns or rows.
76      * Used to decide whether the paste with insertion dialog, where
77      * you can choose between shifting cells down or to the right,
78      * has to be shown.
79      * \param mimeData the MIME data to check
80      * \return \c true if the shifting direction is not defined
81      * \return \c false if the clipboard data contains a column or a row
82      */
83     static bool unknownShiftDirection(const QMimeData *mimeData);
84 
85 protected:
86     bool preProcessing() override;
87     bool mainProcessing() override;
88     bool postProcessing() override;
89 
90     /**
91      * Creates sub-commands for the region \p element by parsing XML \p data.
92      */
93     bool processXmlData(Element *element, KoXmlDocument *data);
94 
95     /**
96      * Creates sub-commands for the region \p element by parsing plain text.
97      */
98     bool processTextPlain(Element *element);
99 
100 private:
101     const QMimeData *   m_mimeData;
102     KoXmlDocument *     m_xmlDocument;
103     InsertionMode       m_insertMode;
104     Paste::Mode         m_pasteMode;
105     Paste::Operation    m_operation;
106     bool                m_pasteFC;
107 };
108 
109 } // namespace Sheets
110 } // namespace Calligra
111 
112 #endif // CALLIGRA_SHEETS_PASTE_COMMAND
113