Engauge Digitizer 2
Loading...
Searching...
No Matches
DocumentModelExportFormat.cpp
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 "CmdMediator.h"
8#include "DocumentModelExportFormat.h"
9#include "DocumentSerialize.h"
10#include "Logger.h"
11#include <QObject>
12#include <QSettings>
13#include <QTextStream>
14#include <QXmlStreamWriter>
15#include "Settings.h"
16#include "Xml.h"
17
18const QStringList DEFAULT_CURVE_NAMES_NOT_EXPORTED;
19const double DEFAULT_POINTS_INTERVAL_FUNCTIONS = 10; // Consistent with DEFAULT_POINTS_INTERVAL_UNITS_FUNCTIONS
20const double DEFAULT_POINTS_INTERVAL_RELATIONS = 10; // Consistent with DEFAULT_POINTS_INTERVAL_UNITS_RELATIONS
21const QString DEFAULT_X_LABEL ("x");
22const ExportPointsIntervalUnits DEFAULT_POINTS_INTERVAL_UNITS_FUNCTIONS = EXPORT_POINTS_INTERVAL_UNITS_SCREEN; // Consistent with DEFAULT_POINTS_INTERVAL_FUNCTIONS
23const ExportPointsIntervalUnits DEFAULT_POINTS_INTERVAL_UNITS_RELATIONS = EXPORT_POINTS_INTERVAL_UNITS_SCREEN; // Consistent with DEFAULT_POINTS_INTERVAL_RELATIONS
24
26{
27 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
28 settings.beginGroup (SETTINGS_GROUP_EXPORT);
29
30 m_curveNamesNotExported = settings.value (SETTINGS_EXPORT_CURVE_NAMES_NOT_EXPORTED,
31 QVariant (DEFAULT_CURVE_NAMES_NOT_EXPORTED)).toStringList();
32 m_delimiter = (ExportDelimiter) settings.value (SETTINGS_EXPORT_DELIMITER,
33 QVariant (EXPORT_DELIMITER_COMMA)).toInt();
34 m_header = (ExportHeader) settings.value (SETTINGS_EXPORT_HEADER,
35 QVariant (EXPORT_HEADER_SIMPLE)).toInt();
36 m_layoutFunctions = (ExportLayoutFunctions) settings.value (SETTINGS_EXPORT_LAYOUT_FUNCTIONS,
37 QVariant (EXPORT_LAYOUT_ALL_PER_LINE)).toInt();
38 m_pointsIntervalFunctions = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_FUNCTIONS,
39 QVariant (DEFAULT_POINTS_INTERVAL_FUNCTIONS)).toDouble();
40 m_pointsIntervalRelations = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_RELATIONS,
41 QVariant (DEFAULT_POINTS_INTERVAL_RELATIONS)).toDouble();
42 m_pointsIntervalUnitsFunctions = (ExportPointsIntervalUnits) settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS,
43 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_FUNCTIONS)).toInt();
44 m_pointsIntervalUnitsRelations = (ExportPointsIntervalUnits) settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS,
45 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_RELATIONS)).toInt();
46 m_pointsSelectionFunctions = (ExportPointsSelectionFunctions) settings.value (SETTINGS_EXPORT_POINTS_SELECTION_FUNCTIONS,
47 QVariant (EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES)).toInt();
48 m_pointsSelectionRelations = (ExportPointsSelectionRelations) settings.value (SETTINGS_EXPORT_POINTS_SELECTION_RELATIONS,
49 QVariant (EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE)).toInt();
50 m_xLabel = settings.value (SETTINGS_EXPORT_X_LABEL,
51 QVariant (DEFAULT_X_LABEL)).toString();
52}
53
55 m_curveNamesNotExported (document.modelExport().curveNamesNotExported()),
56 m_pointsSelectionFunctions (document.modelExport().pointsSelectionFunctions()),
57 m_pointsIntervalFunctions (document.modelExport().pointsIntervalFunctions()),
58 m_pointsIntervalUnitsFunctions (document.modelExport().pointsIntervalUnitsFunctions()),
59 m_pointsSelectionRelations (document.modelExport().pointsSelectionRelations()),
60 m_pointsIntervalRelations (document.modelExport().pointsIntervalRelations()),
61 m_pointsIntervalUnitsRelations (document.modelExport().pointsIntervalUnitsRelations()),
62 m_layoutFunctions (document.modelExport().layoutFunctions()),
63 m_delimiter (document.modelExport().delimiter()),
64 m_header (document.modelExport().header()),
65 m_xLabel (document.modelExport().xLabel())
66{
67}
68
70 m_curveNamesNotExported (other.curveNamesNotExported()),
71 m_pointsSelectionFunctions (other.pointsSelectionFunctions()),
72 m_pointsIntervalFunctions (other.pointsIntervalFunctions()),
73 m_pointsIntervalUnitsFunctions (other.pointsIntervalUnitsFunctions()),
74 m_pointsSelectionRelations (other.pointsSelectionRelations()),
75 m_pointsIntervalRelations (other.pointsIntervalRelations()),
76 m_pointsIntervalUnitsRelations (other.pointsIntervalUnitsRelations()),
77 m_layoutFunctions (other.layoutFunctions()),
78 m_delimiter (other.delimiter()),
79 m_header (other.header()),
80 m_xLabel (other.xLabel ())
81{
82
83}
84
86{
87 m_curveNamesNotExported = other.curveNamesNotExported();
88 m_pointsSelectionFunctions = other.pointsSelectionFunctions();
89 m_pointsIntervalFunctions = other.pointsIntervalFunctions();
90 m_pointsIntervalUnitsFunctions = other.pointsIntervalUnitsFunctions();
91 m_pointsSelectionRelations = other.pointsSelectionRelations();
92 m_pointsIntervalRelations = other.pointsIntervalRelations();
93 m_pointsIntervalUnitsRelations = other.pointsIntervalUnitsRelations();
94 m_layoutFunctions = other.layoutFunctions();
95 m_delimiter = other.delimiter();
96 m_header = other.header();
97 m_xLabel = other.xLabel();
98
99 return *this;
100}
101
103{
104 return m_curveNamesNotExported;
105}
106
108{
109 return m_delimiter;
110}
111
113{
114 return m_header;
115}
116
118{
119 return m_layoutFunctions;
120}
121
122void DocumentModelExportFormat::loadXml(QXmlStreamReader &reader)
123{
124 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelExportFormat::loadXml";
125
126 bool success = true;
127
128 QXmlStreamAttributes attributes = reader.attributes();
129
130 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS) &&
131 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS) &&
132 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS) &&
133 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS) &&
134 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS) &&
135 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS) &&
136 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS) &&
137 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER) &&
138 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER) &&
139 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL)) {
140
141 setPointsSelectionFunctions ((ExportPointsSelectionFunctions) attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS).toInt());
142 setPointsIntervalFunctions (attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS).toDouble());
143 setPointsIntervalUnitsFunctions ((ExportPointsIntervalUnits) attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS).toInt());
144 setPointsSelectionRelations ((ExportPointsSelectionRelations) attributes.value(DOCUMENT_SERIALIZE_COORDS_SCALE_Y_RADIUS).toInt());
145 setPointsIntervalRelations (attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS).toDouble());
146 setPointsIntervalUnitsRelations ((ExportPointsIntervalUnits) attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS).toInt());
147 setLayoutFunctions ((ExportLayoutFunctions) attributes.value(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS).toInt());
148 setDelimiter ((ExportDelimiter) attributes.value (DOCUMENT_SERIALIZE_EXPORT_DELIMITER).toInt());
149 setHeader ((ExportHeader) attributes.value(DOCUMENT_SERIALIZE_EXPORT_HEADER).toInt());
150 setXLabel (attributes.value(DOCUMENT_SERIALIZE_EXPORT_X_LABEL).toString());
151
152 // Read element containing excluded curve names
153 while ((loadNextFromReader (reader) != QXmlStreamReader::StartElement) ||
154 (reader.name() != DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED)) {
155
156 if (reader.atEnd()) {
157 success = false;
158 break;
159 }
160 }
161
162 if (success) {
163
164 QStringList curveNamesNotExported;
165
166 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
167 while (tokenType == QXmlStreamReader::StartElement) {
168
169 if (reader.name() == DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED) {
170 curveNamesNotExported << reader.text().toString();
171 }
172 tokenType = loadNextFromReader(reader);
173 }
174
175 // Save curve names
177
178 // Read until end of this subtree
179 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
180 (reader.name() != DOCUMENT_SERIALIZE_EXPORT)){
181 loadNextFromReader(reader);
182 if (reader.atEnd()) {
183 success = false;
184 break;
185 }
186 }
187 }
188 }
189
190 if (!success) {
191 reader.raiseError (QObject::tr ("Cannot read export data"));
192 }
193}
194
196{
197 return m_pointsIntervalFunctions;
198}
199
201{
202 return m_pointsIntervalRelations;
203}
204
206{
207 return m_pointsIntervalUnitsFunctions;
208}
209
211{
212 return m_pointsIntervalUnitsRelations;
213}
214
215ExportPointsSelectionFunctions DocumentModelExportFormat::pointsSelectionFunctions() const
216{
217 return m_pointsSelectionFunctions;
218}
219
220ExportPointsSelectionRelations DocumentModelExportFormat::pointsSelectionRelations() const
221{
222 return m_pointsSelectionRelations;
223}
224
226 QTextStream &str) const
227{
228 str << indentation << "DocumentModelExportFormat\n";
229
230 indentation += INDENTATION_DELTA;
231
232 str << indentation << "curveNamesNotExported=";
233 QStringList::const_iterator itr;
234 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end(); itr++) {
235 QString curveName = *itr;
236 str << indentation << curveName << " ";
237 }
238 str << "\n";
239
240 str << indentation << "exportPointsSelectionFunctions="
241 << exportPointsSelectionFunctionsToString (m_pointsSelectionFunctions) << "\n";
242 str << indentation << "pointsIntervalFunctions=" << m_pointsIntervalFunctions << "\n";
243 str << indentation << "pointsIntervalUnitsFunctions="
244 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsFunctions) << "\n";
245 str << indentation << "exportPointsSelectionRelations="
246 << exportPointsSelectionRelationsToString (m_pointsSelectionRelations) << "\n";
247 str << indentation << "pointsIntervalRelations=" << m_pointsIntervalRelations << "\n";
248 str << indentation << "pointsIntervalUnitsRelations="
249 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsRelations) << "\n";
250 str << indentation << "exportLayoutFunctions=" << exportLayoutFunctionsToString (m_layoutFunctions) << "\n";
251 str << indentation << "exportDelimiter=" << exportDelimiterToString (m_delimiter) << "\n";
252 str << indentation << "exportHeader=" << exportHeaderToString (m_header) << "\n";
253 str << indentation << "xLabel=" << m_xLabel << "\n";
254}
255
256void DocumentModelExportFormat::saveXml(QXmlStreamWriter &writer) const
257{
258 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelExportFormat::saveXml";
259
260 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT);
261 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS, QString::number (m_pointsSelectionFunctions));
262 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS_STRING, exportPointsSelectionFunctionsToString (m_pointsSelectionFunctions));
263 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS, QString::number (m_pointsIntervalFunctions));
264 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS, QString::number (m_pointsIntervalUnitsFunctions));
265 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS, QString::number (m_pointsSelectionRelations));
266 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS_STRING, exportPointsSelectionRelationsToString (m_pointsSelectionRelations));
267 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS, QString::number (m_pointsIntervalUnitsRelations));
268 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS, QString::number (m_pointsIntervalRelations));
269 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS, QString::number (m_layoutFunctions));
270 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS_STRING, exportLayoutFunctionsToString (m_layoutFunctions));
271 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER, QString::number (m_delimiter));
272 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_STRING, exportDelimiterToString (m_delimiter));
273 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER, QString::number (m_header));
274 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER_STRING, exportHeaderToString (m_header));
275 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL, m_xLabel);
276
277 // Loop through curve names that are not to be exported
278 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED);
279 QStringList::const_iterator itr;
280 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end (); itr++) {
281 QString curveNameNotExported = *itr;
282 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED);
283 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED_NAME, curveNameNotExported);
284 writer.writeEndElement();
285 }
286 writer.writeEndElement();
287
288 writer.writeEndElement();
289}
290
291void DocumentModelExportFormat::setCurveNamesNotExported(const QStringList &curveNamesNotExported)
292{
293 m_curveNamesNotExported = curveNamesNotExported;
294}
295
296void DocumentModelExportFormat::setDelimiter(ExportDelimiter delimiter)
297{
298 m_delimiter = delimiter;
299}
300
302{
303 m_header = header;
304}
305
306void DocumentModelExportFormat::setLayoutFunctions(ExportLayoutFunctions layoutFunctions)
307{
308 m_layoutFunctions = layoutFunctions;
309}
310
312{
313 m_pointsIntervalFunctions = pointsIntervalFunctions;
314}
315
317{
318 m_pointsIntervalRelations = pointsIntervalRelations;
319}
320
321void DocumentModelExportFormat::setPointsIntervalUnitsFunctions(ExportPointsIntervalUnits pointsIntervalUnitsFunctions)
322{
323 m_pointsIntervalUnitsFunctions = pointsIntervalUnitsFunctions;
324}
325
326void DocumentModelExportFormat::setPointsIntervalUnitsRelations(ExportPointsIntervalUnits pointsIntervalUnitsRelations)
327{
328 m_pointsIntervalUnitsRelations = pointsIntervalUnitsRelations;
329}
330
331void DocumentModelExportFormat::setPointsSelectionFunctions(ExportPointsSelectionFunctions pointsSelectionFunctions)
332{
333 m_pointsSelectionFunctions = pointsSelectionFunctions;
334}
335
336void DocumentModelExportFormat::setPointsSelectionRelations(ExportPointsSelectionRelations pointsSelectionRelations)
337{
338 m_pointsSelectionRelations = pointsSelectionRelations;
339}
340
341void DocumentModelExportFormat::setXLabel (const QString &xLabel)
342{
343 m_xLabel = xLabel;
344}
345
347{
348 return m_xLabel;
349}
Model for DlgSettingsExportFormat and CmdSettingsExportFormat.
ExportHeader header() const
Get method for header.
ExportPointsSelectionRelations pointsSelectionRelations() const
Get method for point selection for relations.
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
void setPointsIntervalFunctions(double pointsIntervalFunctions)
Set method for points interval for functions.
QStringList curveNamesNotExported() const
Get method for curve names not exported.
void setPointsIntervalRelations(double pointsIntervalRelations)
Set method for relations interval for relations.
double pointsIntervalRelations() const
Get method for relations interval for relations.
void setLayoutFunctions(ExportLayoutFunctions exportLayoutFunctions)
Set method for functions layout.
void setXLabel(const QString &xLabel)
Set method for x label.
void setHeader(ExportHeader exportHeader)
Set method for header.
DocumentModelExportFormat()
Default constructor.
QString xLabel() const
Get method for x label.
ExportPointsSelectionFunctions pointsSelectionFunctions() const
Get method for point selection for functions.
void setDelimiter(ExportDelimiter exportDelimiter)
Set method for delimiter.
double pointsIntervalFunctions() const
Get method for points interval for functions.
ExportPointsIntervalUnits pointsIntervalUnitsRelations() const
Get method for points interval units for relations.
void setCurveNamesNotExported(const QStringList &curveNamesNotExported)
Set method for curve names not exported.
void setPointsSelectionRelations(ExportPointsSelectionRelations exportPointsSelectionRelations)
Set method for point selection for relations.
ExportDelimiter delimiter() const
Get method for delimiter.
void setPointsSelectionFunctions(ExportPointsSelectionFunctions exportPointsSelectionFunctions)
Set method for point selection for functions.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setPointsIntervalUnitsFunctions(ExportPointsIntervalUnits pointsIntervalUnitsFunctions)
Set method for points interval units for functions.
ExportLayoutFunctions layoutFunctions() const
Get method for functions layout.
DocumentModelExportFormat & operator=(const DocumentModelExportFormat &other)
Assignment constructor.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
void setPointsIntervalUnitsRelations(ExportPointsIntervalUnits pointsIntervalUnitsRelations)
Set method for points interval units for relations.
ExportPointsIntervalUnits pointsIntervalUnitsFunctions() const
Get method for points interval units for functions.
Storage of one imported image and the data attached to that image.
Definition Document.h:41