38 const QString &cmdDescription,
39 QXmlStreamReader &reader) :
44 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointsGraph::CmdAddPointsGraph";
46 QXmlStreamAttributes attributes = reader.attributes();
48 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_CURVE_NAME)) {
49 xmlExitWithError (reader,
51 .arg (QObject::tr (
"Missing attribute"))
52 .arg (DOCUMENT_SERIALIZE_CURVE_NAME));
55 m_curveName = attributes.value(DOCUMENT_SERIALIZE_CURVE_NAME).toString();
58 while (loadNextFromReader (reader)) {
60 if (reader.atEnd() || reader.hasError ()) {
65 if ((reader.tokenType() == QXmlStreamReader::EndElement) &
66 (reader.name() == DOCUMENT_SERIALIZE_CMD)) {
71 if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
72 (reader.name() == DOCUMENT_SERIALIZE_POINT)) {
75 QXmlStreamAttributes attributes = reader.attributes ();
77 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER) &&
78 attributes.hasAttribute(DOCUMENT_SERIALIZE_ORDINAL) &&
79 attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_X) &&
80 attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_Y)) {
82 m_identifiersAdded << attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
83 m_ordinals << attributes.value(DOCUMENT_SERIALIZE_ORDINAL).toDouble();
85 QPoint point (attributes.value(DOCUMENT_SERIALIZE_SCREEN_X).toInt(),
86 attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y).toInt());
93 reader.raiseError (QObject::tr (
"Cannot read graph points"));
132 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
133 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_ADD_POINTS_GRAPH);
134 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
135 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
137 for (
int index = 0; index < m_points.count(); index++) {
139 writer.writeStartElement (DOCUMENT_SERIALIZE_POINT);
140 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X, QString::number (m_points.at (index).x()));
141 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y, QString::number (m_points.at (index).y()));
144 if (index < m_identifiersAdded.count()) {
145 identifier = m_identifiersAdded.at (index);
148 writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, identifier);
149 writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL, QString::number (m_ordinals.at (index)));
150 writer.writeEndElement();
152 writer.writeEndElement();
CmdAddPointsGraph(MainWindow &mainWindow, Document &document, const QString &curveName, const QList< QPoint > &points, const QList< double > &ordinals)
Constructor for normal creation.
void addPointGraphWithGeneratedIdentifier(const QString &curveName, const QPointF &posScreen, QString &generatedIentifier, double ordinal)
Add a single graph point with a generated point identifier.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.