Engauge Digitizer  2
CmdDelete.cpp
1 #include "CmdDelete.h"
2 #include "DataKey.h"
3 #include "Document.h"
4 #include "DocumentSerialize.h"
5 #include "EngaugeAssert.h"
6 #include "ExportToClipboard.h"
7 #include "GraphicsItemType.h"
8 #include "GraphicsView.h"
9 #include "Logger.h"
10 #include "MainWindow.h"
11 #include <QTextStream>
12 #include <QtToString.h>
13 #include <QXmlStreamReader>
14 
15 const QString CMD_DESCRIPTION ("Delete");
16 
18  Document &document,
19  const QStringList &selectedPointIdentifiers) :
20  CmdAbstract(mainWindow,
21  document,
22  CMD_DESCRIPTION)
23 {
24  LOG4CPP_INFO_S ((*mainCat)) << "CmdDelete::CmdDelete"
25  << " selected=(" << selectedPointIdentifiers.join (", ").toLatin1 ().data () << ")";
26 
27  // Export to clipboard
28  ExportToClipboard exportStrategy;
29  QTextStream strCsv (&m_csv), strHtml (&m_html);
30  exportStrategy.exportToClipboard (selectedPointIdentifiers,
31  mainWindow.transformation(),
32  strCsv,
33  strHtml,
34  document.curveAxes(),
35  document.curvesGraphs(),
36  m_curvesGraphsRemoved);
37 }
38 
40  Document &document,
41  const QString &cmdDescription,
42  QXmlStreamReader &reader) :
43  CmdAbstract (mainWindow,
44  document,
45  cmdDescription)
46 {
47  LOG4CPP_INFO_S ((*mainCat)) << "CmdDelete::CmdDelete";
48 
49  QXmlStreamAttributes attributes = reader.attributes();
50 
51  if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_TRANSFORM_DEFINED) ||
52  !attributes.hasAttribute(DOCUMENT_SERIALIZE_CSV) ||
53  !attributes.hasAttribute(DOCUMENT_SERIALIZE_HTML)) {
54  ENGAUGE_ASSERT (false);
55  }
56 
57  QString defined = attributes.value(DOCUMENT_SERIALIZE_TRANSFORM_DEFINED).toString();
58 
59  m_transformIsDefined = (defined == DOCUMENT_SERIALIZE_BOOL_TRUE);
60  m_csv = attributes.value(DOCUMENT_SERIALIZE_CSV).toString();
61  m_html = attributes.value(DOCUMENT_SERIALIZE_HTML).toString();
62  m_curvesGraphsRemoved.loadXml(reader);
63 }
64 
65 CmdDelete::~CmdDelete ()
66 {
67 }
68 
70 {
71  LOG4CPP_INFO_S ((*mainCat)) << "CmdDelete::cmdRedo";
72 
73  document().removePointsInCurvesGraphs (m_curvesGraphsRemoved);
74 
75  document().updatePointOrdinals (mainWindow().transformation());
77 }
78 
80 {
81  LOG4CPP_INFO_S ((*mainCat)) << "CmdDelete::cmdUndo";
82 
83  document().addPointsInCurvesGraphs (m_curvesGraphsRemoved);
84 
85  document().updatePointOrdinals (mainWindow().transformation());
87 }
88 
89 void CmdDelete::saveXml (QXmlStreamWriter &writer) const
90 {
91  writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
92  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_DELETE);
93  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
94  writer.writeAttribute(DOCUMENT_SERIALIZE_TRANSFORM_DEFINED,
95  m_transformIsDefined ? DOCUMENT_SERIALIZE_BOOL_TRUE : DOCUMENT_SERIALIZE_BOOL_FALSE);
96  writer.writeAttribute(DOCUMENT_SERIALIZE_CSV, m_csv);
97  writer.writeAttribute(DOCUMENT_SERIALIZE_HTML, m_html);
98  m_curvesGraphsRemoved.saveXml(writer);
99  writer.writeEndElement();
100 }
void saveXml(QXmlStreamWriter &writer) const
Serialize curves.
void loadXml(QXmlStreamReader &reader)
Load from serialized xml post-version 5 file.
Transformation transformation() const
Return read-only copy of transformation.
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
Definition: CmdDelete.cpp:79
CmdDelete(MainWindow &mainWindow, Document &document, const QStringList &selectedPointIdentifiers)
Constructor for normal creation.
Definition: CmdDelete.cpp:17
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition: CmdAbstract.h:11
const Curve & curveAxes() const
Get method for axis curve.
Definition: Document.cpp:214
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
Definition: CmdDelete.cpp:89
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.
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
Definition: CmdDelete.cpp:69
void removePointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Remove all points identified in the specified CurvesGraphs. See also addPointsInCurvesGraphs.
Definition: Document.cpp:780
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:32
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
Storage of one imported image and the data attached to that image.
Definition: Document.h:28
const CurvesGraphs & curvesGraphs() const
Make all Curves available, read only, for CmdAbstract classes only.
Definition: Document.cpp:247
Strategy class for exporting to the clipboard. This strategy is external to the Document class so tha...
void addPointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Add all points identified in the specified CurvesGraphs. See also removePointsInCurvesGraphs.
Definition: Document.cpp:161
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:22
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:60
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
Definition: Document.cpp:906