Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdSettingsCurveList.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
8#include "CurveNameList.h"
9#include "Document.h"
10#include "DocumentSerialize.h"
11#include "Logger.h"
12#include "MainWindow.h"
13#include <QXmlStreamReader>
14#include "Xml.h"
15
16const QString CMD_DESCRIPTION ("Curve list");
17
20 const CurveNameList &modelCurves) :
24{
25 LOG4CPP_INFO_S ((*mainCat)) << "CmdSettingsCurveList::CmdSettingsCurveList";
26
27 m_curvesGraphsBefore = document.curvesGraphs ();
28
29 // Build the 'after' state
30 for (int row = 0; row < modelCurves.rowCount (); row++) {
31
32 QModelIndex idxCurrent = modelCurves.index (row, CURVE_NAME_LIST_COLUMN_CURRENT);
33
34 QString curveNameCurrent = modelCurves.data (idxCurrent).toString ();
35 QString curveNameOriginal = modelCurves.currentCurveToOriginalCurve (curveNameCurrent);
36 if (!curveNameOriginal.isEmpty ()) {
37
38 // There was an original Curve
39 const Document &documentConst = const_cast<Document&> (document);
40 const Curve *curveOriginal = documentConst.curveForCurveName (curveNameOriginal);
41 Curve curveCurrent (*curveOriginal);
42 curveCurrent.setCurveName (curveNameCurrent);
43
44 m_curvesGraphsAfter.addGraphCurveAtEnd (curveCurrent); // Save Curve
45
46 } else {
47
48 // There was no original Curve
49 Curve curveCurrent (curveNameCurrent,
51 CurveStyle (LineStyle::defaultGraphCurve(m_curvesGraphsAfter.numCurves()),
52 PointStyle::defaultGraphCurve(m_curvesGraphsAfter.numCurves())));
53
54 m_curvesGraphsAfter.addGraphCurveAtEnd (curveCurrent); // Save Curve
55 }
56 }
57}
58
61 const QString &cmdDescription,
62 QXmlStreamReader &reader) :
65 cmdDescription)
66{
67 LOG4CPP_INFO_S ((*mainCat)) << "CmdSettingsCurveList::CmdSettingsCurveList";
68
69 bool success = true;
70
71 // Read until end of this subtree
72 bool isBefore = true;
73 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
74 (reader.name() != DOCUMENT_SERIALIZE_CMD)){
75 loadNextFromReader(reader);
76 if (reader.atEnd()) {
77 xmlExitWithError (reader,
78 QString ("%1 %2")
79 .arg (QObject::tr ("Reached end of file before finding end element for"))
81 success = false;
82 break;
83 }
84
85 if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
86 (reader.name() == DOCUMENT_SERIALIZE_CURVES_GRAPHS)) {
87
88 if (isBefore) {
89
90 m_curvesGraphsBefore.loadXml (reader);
91 isBefore = false;
92
93 } else {
94
95 m_curvesGraphsAfter.loadXml (reader);
96
97 }
98 }
99 }
100
101 if (!success) {
102 reader.raiseError ("Cannot read curve add/remove settings");
103 }
104}
105
109
120
131
132void CmdSettingsCurveList::saveXml (QXmlStreamWriter &writer) const
133{
134 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
136 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
137 baseAttributes (writer);
138 m_curvesGraphsBefore.saveXml(writer);
139 m_curvesGraphsAfter.saveXml(writer);
140 writer.writeEndElement();
141}
const QString CMD_DESCRIPTION("Add axis point")
const QString CMD_DESCRIPTION("Curve list")
@ CURVE_NAME_LIST_COLUMN_CURRENT
const QString DOCUMENT_SERIALIZE_CURVES_GRAPHS
const QString DOCUMENT_SERIALIZE_CMD_SETTINGS_CURVE_LIST
const QString DOCUMENT_SERIALIZE_CMD
const QString DOCUMENT_SERIALIZE_CMD_TYPE
const QString DOCUMENT_SERIALIZE_CMD_DESCRIPTION
log4cpp::Category * mainCat
Definition Logger.cpp:14
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition Xml.cpp:14
void xmlExitWithError(QXmlStreamReader &reader, const QString &message)
Show specified message for an error while reading xml, then quit.
Definition Xml.cpp:25
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 baseAttributes(QXmlStreamWriter &writer) const
After writing leaf class attributes, this writes the base class atributes.
CmdAbstract(MainWindow &mainWindow, Document &document, const QString &cmdDescription)
Single constructor.
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
CmdSettingsCurveList(MainWindow &mainWindow, Document &document, const CurveNameList &modelCurves)
Constructor for normal creation.
static ColorFilterSettings defaultFilter()
Initial default for any Curve.
Model for DlgSettingsCurveList and CmdSettingsCurveList.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
One row per curve name.
QString currentCurveToOriginalCurve(const QString &currentCurve) const
Return the original curve for the specified current curve.
Container for LineStyle and PointStyle for one Curve.
Definition CurveStyle.h:19
Container for one set of digitized Points.
Definition Curve.h:34
void setCurveName(const QString &curveName)
Change the curve name.
Definition Curve.cpp:555
Storage of one imported image and the data attached to that image.
Definition Document.h:44
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
Definition Document.cpp:341
static LineStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
Definition LineStyle.cpp:84
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:95
void updateSettingsCurveList(const CurvesGraphs &curvesGraphs)
Update with new curves.
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
static PointStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18