Engauge Digitizer 2
Loading...
Searching...
No Matches
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
22const QString ADDED_DELIMITER (",");
23const QString CMD_DESCRIPTION ("Delete");
24
27 const QStringList &deletedPointIdentifiers) :
31 m_deletedPointIdentifiers (deletedPointIdentifiers)
32{
33 LOG4CPP_INFO_S ((*mainCat)) << "CmdDelete::CmdDelete";
34
35 // Export to clipboard
36 ExportToClipboard exportStrategy;
37 QTextStream strCsv (&m_csv), strHtml (&m_html);
38 exportStrategy.exportToClipboard (deletedPointIdentifiers,
39 mainWindow.transformation(),
40 strCsv,
41 strHtml,
42 document.curveAxes(),
43 document.curvesGraphs(),
44 m_curvesGraphsRemoved);
45}
46
49 const QString &cmdDescription,
50 QXmlStreamReader &reader) :
53 cmdDescription)
54{
55 LOG4CPP_INFO_S ((*mainCat)) << "CmdDelete::CmdDelete";
56
57 QXmlStreamAttributes attributes = reader.attributes();
58
59 QStringList requiredAttributesLeaf;
60 requiredAttributesLeaf << DOCUMENT_SERIALIZE_TRANSFORM_DEFINED
64 leafAndBaseAttributes (attributes,
65 requiredAttributesLeaf,
66 reader);
67
68 // Boolean values
69 QString defined = attributes.value(DOCUMENT_SERIALIZE_TRANSFORM_DEFINED).toString();
70
71 m_transformIsDefined = (defined == DOCUMENT_SERIALIZE_BOOL_TRUE);
72 m_csv = attributes.value(DOCUMENT_SERIALIZE_CSV).toString();
73 m_html = attributes.value(DOCUMENT_SERIALIZE_HTML).toString();
74 m_deletedPointIdentifiers = attributes.value(DOCUMENT_SERIALIZE_CMD_DELETE_ADDED_POINTS).toString().split(ADDED_DELIMITER);
75 m_curvesGraphsRemoved.loadXml(reader);
76}
77
81
95
107
108void CmdDelete::saveXml (QXmlStreamWriter &writer) const
109{
110 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
112 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
113 writer.writeAttribute(DOCUMENT_SERIALIZE_TRANSFORM_DEFINED,
115 writer.writeAttribute(DOCUMENT_SERIALIZE_CSV, m_csv);
116 writer.writeAttribute(DOCUMENT_SERIALIZE_HTML, m_html);
117 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DELETE_ADDED_POINTS, m_deletedPointIdentifiers.join (ADDED_DELIMITER));
118 m_curvesGraphsRemoved.saveXml(writer);
119 baseAttributes (writer);
120 writer.writeEndElement();
121}
const QString CMD_DESCRIPTION("Add axis point")
const QString CMD_DESCRIPTION("Delete")
const QString ADDED_DELIMITER(",")
const QString DOCUMENT_SERIALIZE_TRANSFORM_DEFINED
const QString DOCUMENT_SERIALIZE_CMD
const QString DOCUMENT_SERIALIZE_CMD_TYPE
const QString DOCUMENT_SERIALIZE_CMD_DELETE
const QString DOCUMENT_SERIALIZE_CMD_DESCRIPTION
const QString DOCUMENT_SERIALIZE_HTML
const QString DOCUMENT_SERIALIZE_CSV
const QString DOCUMENT_SERIALIZE_CMD_DELETE_ADDED_POINTS
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
const QString DOCUMENT_SERIALIZE_BOOL_FALSE
log4cpp::Category * mainCat
Definition Logger.cpp:14
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.
void saveOrCheckPostCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
void restoreState()
Before any other operations associated with a Cmd class are performed, this method is called to resto...
void saveOrCheckPreCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
void leafAndBaseAttributes(const QXmlStreamAttributes &attributes, const QStringList &requiredAttributesLeaf, QXmlStreamReader &reader)
Before reading leaf class attributes, check all required attributes from leaf and this base class are...
void baseAttributes(QXmlStreamWriter &writer) const
After writing leaf class attributes, this writes the base class atributes.
void selectAddedPointsForMoving(const QStringList &pointsAdded)
Select points that were just added so they can be moved by the user next for convenience.
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
Definition CmdDelete.cpp:82
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
Definition CmdDelete.cpp:96
virtual ~CmdDelete()
Definition CmdDelete.cpp:78
CmdDelete(MainWindow &mainWindow, Document &document, const QStringList &selectedPointIdentifiers)
Constructor for normal creation.
Definition CmdDelete.cpp:25
void saveDocumentState(const Document &document)
Save the document state for restoration by restoreDocumentState.
void restoreDocumentState(Document &document) const
Restore the document previously saved by saveDocumentState.
CmdPointChangeBase(MainWindow &mainWindow, Document &document, const QString &cmdDescription)
Single constructor.
Storage of one imported image and the data attached to that image.
Definition Document.h:44
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
void removePointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Remove all points identified in the specified CurvesGraphs. See also addPointsInCurvesGraphs.
Definition Document.cpp:903
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:95
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18