Engauge Digitizer  2
CmdDelete.cpp
Go to the documentation of this file.
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 "CmdDelete.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 <QTextStream>
18 #include <QtToString.h>
19 #include <QXmlStreamReader>
20 #include "Xml.h"
21 
22 const QString CMD_DESCRIPTION ("Delete");
23 
25  Document &document,
26  const QStringList &selectedPointIdentifiers) :
27  CmdPointChangeBase (mainWindow,
28  document,
30 {
31  LOG4CPP_INFO_S ((*mainCat)) << "CmdDelete::CmdDelete"
32  << " selected=" << selectedPointIdentifiers.count ();
33 
34  // Export to clipboard
35  ExportToClipboard exportStrategy;
36  QTextStream strCsv (&m_csv), strHtml (&m_html);
37  exportStrategy.exportToClipboard (selectedPointIdentifiers,
39  strCsv,
40  strHtml,
43  m_curvesGraphsRemoved);
44 }
45 
47  Document &document,
48  const QString &cmdDescription,
49  QXmlStreamReader &reader) :
50  CmdPointChangeBase (mainWindow,
51  document,
52  cmdDescription)
53 {
54  LOG4CPP_INFO_S ((*mainCat)) << "CmdDelete::CmdDelete";
55 
56  QXmlStreamAttributes attributes = reader.attributes();
57 
58  if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_TRANSFORM_DEFINED) ||
59  !attributes.hasAttribute(DOCUMENT_SERIALIZE_CSV) ||
60  !attributes.hasAttribute(DOCUMENT_SERIALIZE_HTML)) {
61  xmlExitWithError (reader,
62  QString ("%1 %2, %3 %4 %5")
63  .arg (QObject::tr ("Missing attribute(s)"))
66  .arg (QObject::tr ("and/or"))
68  }
69 
70  QString defined = attributes.value(DOCUMENT_SERIALIZE_TRANSFORM_DEFINED).toString();
71 
72  m_transformIsDefined = (defined == DOCUMENT_SERIALIZE_BOOL_TRUE);
73  m_csv = attributes.value(DOCUMENT_SERIALIZE_CSV).toString();
74  m_html = attributes.value(DOCUMENT_SERIALIZE_HTML).toString();
75  m_curvesGraphsRemoved.loadXml(reader);
76 }
77 
79 {
80 }
81 
83 {
84  LOG4CPP_INFO_S ((*mainCat)) << "CmdDelete::cmdRedo";
85 
88  document().removePointsInCurvesGraphs (m_curvesGraphsRemoved);
89 
90  document().updatePointOrdinals (mainWindow().transformation());
93 }
94 
96 {
97  LOG4CPP_INFO_S ((*mainCat)) << "CmdDelete::cmdUndo";
98 
103 }
104 
105 void CmdDelete::saveXml (QXmlStreamWriter &writer) const
106 {
107  writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
109  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
110  writer.writeAttribute(DOCUMENT_SERIALIZE_TRANSFORM_DEFINED,
112  writer.writeAttribute(DOCUMENT_SERIALIZE_CSV, m_csv);
113  writer.writeAttribute(DOCUMENT_SERIALIZE_HTML, m_html);
114  m_curvesGraphsRemoved.saveXml(writer);
115  writer.writeEndElement();
116 }
CmdDelete.h
CmdDelete::saveXml
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
Definition: CmdDelete.cpp:105
CmdDelete::CmdDelete
CmdDelete(MainWindow &mainWindow, Document &document, const QStringList &selectedPointIdentifiers)
Constructor for normal creation.
Definition: CmdDelete.cpp:24
Xml.h
CurvesGraphs::saveXml
void saveXml(QXmlStreamWriter &writer) const
Serialize curves.
Definition: CurvesGraphs.cpp:270
xmlExitWithError
void xmlExitWithError(QXmlStreamReader &reader, const QString &message)
Show specified message for an error while reading xml, then quit.
Definition: Xml.cpp:25
Document::curveAxes
const Curve & curveAxes() const
Get method for axis curve.
Definition: Document.cpp:321
CmdAbstract::document
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:35
DOCUMENT_SERIALIZE_BOOL_TRUE
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
GraphicsItemType.h
CurvesGraphs::loadXml
void loadXml(QXmlStreamReader &reader)
Load from serialized xml post-version 5 file.
Definition: CurvesGraphs.cpp:197
Document
Storage of one imported image and the data attached to that image.
Definition: Document.h:40
Document.h
EngaugeAssert.h
ExportToClipboard
Strategy class for exporting to the clipboard. This strategy is external to the Document class so tha...
Definition: ExportToClipboard.h:17
DocumentSerialize.h
DOCUMENT_SERIALIZE_TRANSFORM_DEFINED
const QString DOCUMENT_SERIALIZE_TRANSFORM_DEFINED
CmdPointChangeBase::saveDocumentState
void saveDocumentState(const Document &document)
Save the document state for restoration by restoreDocumentState.
Definition: CmdPointChangeBase.cpp:40
MainWindow::updateAfterCommand
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
Definition: MainWindow.cpp:3240
MainWindow
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:90
Logger.h
CMD_DESCRIPTION
const QString CMD_DESCRIPTION("Delete")
LOG4CPP_INFO_S
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
MainWindow::transformation
Transformation transformation() const
Return read-only copy of transformation.
Definition: MainWindow.cpp:3230
Document::removePointsInCurvesGraphs
void removePointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Remove all points identified in the specified CurvesGraphs. See also addPointsInCurvesGraphs.
Definition: Document.cpp:877
CmdPointChangeBase
Base class for CmdBase leaf subclasses that involve point additions, deletions and/or modifications.
Definition: CmdPointChangeBase.h:21
DOCUMENT_SERIALIZE_CMD_TYPE
const QString DOCUMENT_SERIALIZE_CMD_TYPE
DataKey.h
CmdAbstract::saveOrCheckPostCommandDocumentStateHash
void saveOrCheckPostCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
Definition: CmdAbstract.cpp:102
DOCUMENT_SERIALIZE_CSV
const QString DOCUMENT_SERIALIZE_CSV
CmdPointChangeBase::restoreDocumentState
void restoreDocumentState(Document &document) const
Restore the document previously saved by saveDocumentState.
Definition: CmdPointChangeBase.cpp:29
CmdDelete::cmdRedo
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
Definition: CmdDelete.cpp:82
CmdAbstract::saveOrCheckPreCommandDocumentStateHash
void saveOrCheckPreCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
Definition: CmdAbstract.cpp:125
mainCat
log4cpp::Category * mainCat
Definition: Logger.cpp:14
MainWindow.h
Document::updatePointOrdinals
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
Definition: Document.cpp:1066
DOCUMENT_SERIALIZE_CMD_DELETE
const QString DOCUMENT_SERIALIZE_CMD_DELETE
CmdAbstract::mainWindow
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:45
QtToString.h
ExportToClipboard::exportToClipboard
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.
Definition: ExportToClipboard.cpp:18
DOCUMENT_SERIALIZE_CMD_DESCRIPTION
const QString DOCUMENT_SERIALIZE_CMD_DESCRIPTION
DOCUMENT_SERIALIZE_CMD
const QString DOCUMENT_SERIALIZE_CMD
DOCUMENT_SERIALIZE_HTML
const QString DOCUMENT_SERIALIZE_HTML
DOCUMENT_SERIALIZE_BOOL_FALSE
const QString DOCUMENT_SERIALIZE_BOOL_FALSE
ExportToClipboard.h
Document::curvesGraphs
const CurvesGraphs & curvesGraphs() const
Make all Curves available, read only, for CmdAbstract classes only.
Definition: Document.cpp:342
CmdDelete::~CmdDelete
virtual ~CmdDelete()
Definition: CmdDelete.cpp:78
GraphicsView.h
CmdDelete::cmdUndo
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
Definition: CmdDelete.cpp:95