Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdCopy.cpp
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "CmdCopy.h"
8#include "DataKey.h"
9#include "Document.h"
10#include "DocumentSerialize.h"
11#include "EngaugeAssert.h"
12#include "ExportToClipboard.h"
13#include "GraphicsItemType.h"
14#include "GraphicsView.h"
15#include "Logger.h"
16#include "MainWindow.h"
17#include "MimePoints.h"
18#include <QApplication>
19#include <QClipboard>
20#include <QTextStream>
21#include "QtToString.h"
22#include <QXmlStreamReader>
23#include "Xml.h"
24
25const QString CMD_DESCRIPTION ("Copy");
26
28 Document &document,
29 const QStringList &selectedPointIdentifiers) :
30 CmdAbstract(mainWindow,
31 document,
32 CMD_DESCRIPTION),
33 m_transformIsDefined (mainWindow.transformIsDefined())
34{
35 LOG4CPP_INFO_S ((*mainCat)) << "CmdCopy::CmdCopy"
36 << " selected=" << selectedPointIdentifiers.join (", ").toLatin1 ().data () << ")";
37
38 ExportToClipboard exportStrategy;
39 QTextStream strCsv (&m_csv), strHtml (&m_html);
40 exportStrategy.exportToClipboard (selectedPointIdentifiers,
42 strCsv,
43 strHtml,
46 m_curvesGraphs);
47}
48
50 Document &document,
51 const QString &cmdDescription,
52 QXmlStreamReader &reader) :
53 CmdAbstract (mainWindow,
54 document,
55 cmdDescription)
56{
57 LOG4CPP_INFO_S ((*mainCat)) << "CmdCopy::CmdCopy";
58
59 QXmlStreamAttributes attributes = reader.attributes();
60
61 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_TRANSFORM_DEFINED) ||
62 !attributes.hasAttribute(DOCUMENT_SERIALIZE_CSV) ||
63 !attributes.hasAttribute(DOCUMENT_SERIALIZE_HTML)) {
64 xmlExitWithError (reader,
65 QString ("%1 %2, %3 %4 %5")
66 .arg (QObject::tr ("Missing attribute(s)"))
67 .arg (DOCUMENT_SERIALIZE_TRANSFORM_DEFINED)
68 .arg (DOCUMENT_SERIALIZE_CSV)
69 .arg (QObject::tr ("and/or"))
70 .arg (DOCUMENT_SERIALIZE_HTML));
71 }
72
73 QString defined = attributes.value(DOCUMENT_SERIALIZE_TRANSFORM_DEFINED).toString();
74
75 m_transformIsDefined = (defined == DOCUMENT_SERIALIZE_BOOL_TRUE);
76 m_csv = attributes.value(DOCUMENT_SERIALIZE_CSV).toString();
77 m_html = attributes.value(DOCUMENT_SERIALIZE_HTML).toString();
78 m_curvesGraphs.loadXml(reader);
79}
80
81CmdCopy::~CmdCopy ()
82{
83}
84
86{
87 LOG4CPP_INFO_S ((*mainCat)) << "CmdCopy::cmdRedo";
88
89 MimePoints *mimePoints;
90 if (m_transformIsDefined) {
91 mimePoints = new MimePoints (m_csv,
92 m_html);
93 } else {
94 mimePoints = new MimePoints (m_csv);
95 }
96
97 QClipboard *clipboard = QApplication::clipboard();
98 clipboard->setMimeData (mimePoints, QClipboard::Clipboard);
99
100 document().updatePointOrdinals (mainWindow().transformation());
102}
103
105{
106 LOG4CPP_INFO_S ((*mainCat)) << "CmdCopy::cmdUndo";
107
108 document().updatePointOrdinals (mainWindow().transformation());
110}
111
112void CmdCopy::saveXml (QXmlStreamWriter &writer) const
113{
114 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
115 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_COPY);
116 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
117 writer.writeAttribute(DOCUMENT_SERIALIZE_TRANSFORM_DEFINED,
118 m_transformIsDefined ? DOCUMENT_SERIALIZE_BOOL_TRUE : DOCUMENT_SERIALIZE_BOOL_FALSE);
119 writer.writeAttribute(DOCUMENT_SERIALIZE_CSV, m_csv);
120 writer.writeAttribute(DOCUMENT_SERIALIZE_HTML, m_html);
121 m_curvesGraphs.saveXml(writer);
122 writer.writeEndElement();
123}
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition CmdAbstract.h:19
Document & document()
Return the Document that this command will modify during redo and undo.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
Definition CmdCopy.cpp:85
CmdCopy(MainWindow &mainWindow, Document &document, const QStringList &selectedPointIdentifiers)
Constructor for normal creation.
Definition CmdCopy.cpp:27
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
Definition CmdCopy.cpp:112
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
Definition CmdCopy.cpp:104
void saveXml(QXmlStreamWriter &writer) const
Serialize curves.
void loadXml(QXmlStreamReader &reader)
Load from serialized xml post-version 5 file.
Storage of one imported image and the data attached to that image.
Definition Document.h:41
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
Definition Document.cpp:903
const Curve & curveAxes() const
Get method for axis curve.
Definition Document.cpp:284
const CurvesGraphs & curvesGraphs() const
Make all Curves available, read only, for CmdAbstract classes only.
Definition Document.cpp:305
Strategy class for exporting to the clipboard. This strategy is external to the Document class so tha...
void exportToClipboard(const QStringList &selected, const Transformation &transformation, QTextStream &strCsv, QTextStream &strHtml, const Curve &curveAxis, const CurvesGraphs &curvesGraphsAll, CurvesGraphs &curvesGraphsSelected) const
Export, curve-by-curve, raw data points to a string that will be copied to the clipboard.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:78
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
Transformation transformation() const
Return read-only copy of transformation.
Custom mime type for separate treatment of graph coordinates and, when there is no transform,...
Definition MimePoints.h:14