Engauge Digitizer 2
Loading...
Searching...
No Matches
DocumentModelExportFormat.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 "CmdMediator.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
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
24const bool DEFAULT_EXPORT_DELIMITER_OVERRIDE = false; // Target beginner users who expect simplest behavior. Issue #169
25const bool DEFAULT_EXTRAPOLATE = true; // Traditional behavior before version 11
26
28{
31
32 // Sync these settings with DlgSettingsExportFormat::slotLoadDefault()
33 // and DlgSettingsExportFormat::slotSaveDefault()
34 m_curveNamesNotExported = settings.value (SETTINGS_EXPORT_CURVE_NAMES_NOT_EXPORTED,
36 m_delimiter = static_cast<ExportDelimiter> (settings.value (SETTINGS_EXPORT_DELIMITER,
38 m_extrapolateOutsideEndpoints = settings.value (SETTINGS_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS,
42 m_header = static_cast<ExportHeader> (settings.value (SETTINGS_EXPORT_HEADER,
44 m_layoutFunctions = static_cast<ExportLayoutFunctions> (settings.value (SETTINGS_EXPORT_LAYOUT_FUNCTIONS,
46 m_pointsIntervalFunctions = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_FUNCTIONS,
48 m_pointsIntervalRelations = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_RELATIONS,
50 m_pointsIntervalUnitsFunctions = static_cast<ExportPointsIntervalUnits> (settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS,
52 m_pointsIntervalUnitsRelations = static_cast<ExportPointsIntervalUnits> (settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS,
54 m_pointsSelectionFunctions = static_cast<ExportPointsSelectionFunctions> (settings.value (SETTINGS_EXPORT_POINTS_SELECTION_FUNCTIONS,
56 m_pointsSelectionRelations = static_cast<ExportPointsSelectionRelations> (settings.value (SETTINGS_EXPORT_POINTS_SELECTION_RELATIONS,
58 m_xLabel = settings.value (SETTINGS_EXPORT_X_LABEL,
59 QVariant (DEFAULT_X_LABEL)).toString();
60}
61
63 m_curveNamesNotExported (document.modelExport().curveNamesNotExported()),
64 m_pointsSelectionFunctions (document.modelExport().pointsSelectionFunctions()),
65 m_pointsIntervalFunctions (document.modelExport().pointsIntervalFunctions()),
66 m_pointsIntervalUnitsFunctions (document.modelExport().pointsIntervalUnitsFunctions()),
67 m_pointsSelectionRelations (document.modelExport().pointsSelectionRelations()),
68 m_pointsIntervalRelations (document.modelExport().pointsIntervalRelations()),
69 m_pointsIntervalUnitsRelations (document.modelExport().pointsIntervalUnitsRelations()),
70 m_layoutFunctions (document.modelExport().layoutFunctions()),
71 m_delimiter (document.modelExport().delimiter()),
72 m_extrapolateOutsideEndpoints (document.modelExport().extrapolateOutsideEndpoints()),
73 m_overrideCsvTsv (document.modelExport().overrideCsvTsv()),
74 m_header (document.modelExport().header()),
75 m_xLabel (document.modelExport().xLabel())
76{
77}
78
80 m_curveNamesNotExported (other.curveNamesNotExported()),
81 m_pointsSelectionFunctions (other.pointsSelectionFunctions()),
82 m_pointsIntervalFunctions (other.pointsIntervalFunctions()),
83 m_pointsIntervalUnitsFunctions (other.pointsIntervalUnitsFunctions()),
84 m_pointsSelectionRelations (other.pointsSelectionRelations()),
85 m_pointsIntervalRelations (other.pointsIntervalRelations()),
86 m_pointsIntervalUnitsRelations (other.pointsIntervalUnitsRelations()),
87 m_layoutFunctions (other.layoutFunctions()),
88 m_delimiter (other.delimiter()),
89 m_extrapolateOutsideEndpoints (other.extrapolateOutsideEndpoints()),
90 m_overrideCsvTsv (other.overrideCsvTsv()),
91 m_header (other.header()),
92 m_xLabel (other.xLabel ())
93{
94}
95
97{
98 m_curveNamesNotExported = other.curveNamesNotExported();
99 m_pointsSelectionFunctions = other.pointsSelectionFunctions();
100 m_pointsIntervalFunctions = other.pointsIntervalFunctions();
101 m_pointsIntervalUnitsFunctions = other.pointsIntervalUnitsFunctions();
102 m_pointsSelectionRelations = other.pointsSelectionRelations();
103 m_pointsIntervalRelations = other.pointsIntervalRelations();
104 m_pointsIntervalUnitsRelations = other.pointsIntervalUnitsRelations();
105 m_layoutFunctions = other.layoutFunctions();
106 m_delimiter = other.delimiter();
107 m_extrapolateOutsideEndpoints = other.extrapolateOutsideEndpoints();
108 m_overrideCsvTsv = other.overrideCsvTsv();
109 m_header = other.header();
110 m_xLabel = other.xLabel();
111
112 return *this;
113}
114
116{
117 return m_curveNamesNotExported;
118}
119
121{
122 return m_delimiter;
123}
124
126{
127 return m_extrapolateOutsideEndpoints;
128}
129
131{
132 return m_header;
133}
134
136{
137 return m_layoutFunctions;
138}
139
141{
142 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelExportFormat::loadXml";
143
144 bool success = true;
145
147
148 // DOCUMENT_SERIALIZE_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS is specific to versions 11 and newer
159
169
170 // Boolean value
172
174 }
176
177 // Boolean value
179
181 }
182
185
186 // Read element containing excluded curve names
187 while ((loadNextFromReader (reader) != QXmlStreamReader::StartElement) ||
189
190 if (reader.atEnd()) {
191 success = false;
192 break;
193 }
194 }
195
196 if (success) {
197
199
200 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
201 while (tokenType == QXmlStreamReader::StartElement) {
202
204 curveNamesNotExported << reader.text().toString();
205 }
207 }
208
209 // Save curve names
211
212 // Read until end of this subtree
213 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
216 if (reader.atEnd()) {
217 success = false;
218 break;
219 }
220 }
221 }
222 }
223
224 if (!success) {
225 reader.raiseError (QObject::tr ("Cannot read export data"));
226 }
227}
228
230{
231 return m_overrideCsvTsv;
232}
233
235{
236 return m_pointsIntervalFunctions;
237}
238
240{
241 return m_pointsIntervalRelations;
242}
243
245{
246 return m_pointsIntervalUnitsFunctions;
247}
248
250{
251 return m_pointsIntervalUnitsRelations;
252}
253
255{
256 return m_pointsSelectionFunctions;
257}
258
260{
261 return m_pointsSelectionRelations;
262}
263
265 QTextStream &str) const
266{
267 str << indentation << "DocumentModelExportFormat\n";
268
270
271 str << indentation << "curveNamesNotExported=";
272 QStringList::const_iterator itr;
273 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end(); itr++) {
274 QString curveName = *itr;
275 str << indentation << curveName << " ";
276 }
277 str << "\n";
278
279 str << indentation << "exportPointsSelectionFunctions="
280 << exportPointsSelectionFunctionsToString (m_pointsSelectionFunctions) << "\n";
281 str << indentation << "pointsIntervalFunctions=" << m_pointsIntervalFunctions << "\n";
282 str << indentation << "pointsIntervalUnitsFunctions="
283 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsFunctions) << "\n";
284 str << indentation << "exportPointsSelectionRelations="
285 << exportPointsSelectionRelationsToString (m_pointsSelectionRelations) << "\n";
286 str << indentation << "pointsIntervalRelations=" << m_pointsIntervalRelations << "\n";
287 str << indentation << "pointsIntervalUnitsRelations="
288 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsRelations) << "\n";
289 str << indentation << "exportLayoutFunctions=" << exportLayoutFunctionsToString (m_layoutFunctions) << "\n";
290 str << indentation << "exportDelimiter=" << exportDelimiterToString (m_delimiter) << "\n";
291 str << indentation << "exportExtrapolateOutsideEndpoints=" << (m_extrapolateOutsideEndpoints ? "yes" : "no") << "\n";
292 str << indentation << "overrideCsvTsv=" << (m_overrideCsvTsv ? "true" : "false") << "\n";
293 str << indentation << "exportHeader=" << exportHeaderToString (m_header) << "\n";
294 str << indentation << "xLabel=" << m_xLabel << "\n";
295}
296
298{
299 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelExportFormat::saveXml";
300
301 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT);
302 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS, QString::number (m_pointsSelectionFunctions));
304 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS, QString::number (m_pointsIntervalFunctions));
305 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS, QString::number (m_pointsIntervalUnitsFunctions));
306 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS, QString::number (m_pointsSelectionRelations));
308 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS, QString::number (m_pointsIntervalUnitsRelations));
309 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS, QString::number (m_pointsIntervalRelations));
310 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS, QString::number (m_layoutFunctions));
312 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER, QString::number (m_delimiter));
313 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV, m_overrideCsvTsv ?
317 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS, m_extrapolateOutsideEndpoints ?
320 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER, QString::number (m_header));
322 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL, m_xLabel);
323
324 // Loop through curve names that are not to be exported
326 QStringList::const_iterator itr;
327 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end (); itr++) {
331 writer.writeEndElement();
332 }
333 writer.writeEndElement();
334
335 writer.writeEndElement();
336}
337
339{
340 m_curveNamesNotExported = curveNamesNotExported;
341}
342
344{
345 m_delimiter = delimiter;
346}
347
349{
350 m_extrapolateOutsideEndpoints = extrapolateOutsideEndpoints;
351}
352
354{
355 m_header = header;
356}
357
359{
360 m_layoutFunctions = layoutFunctions;
361}
362
364{
365 m_overrideCsvTsv = overrideCsvTsv;
366}
367
369{
370 m_pointsIntervalFunctions = pointsIntervalFunctions;
371}
372
374{
375 m_pointsIntervalRelations = pointsIntervalRelations;
376}
377
379{
380 m_pointsIntervalUnitsFunctions = pointsIntervalUnitsFunctions;
381}
382
384{
385 m_pointsIntervalUnitsRelations = pointsIntervalUnitsRelations;
386}
387
389{
390 m_pointsSelectionFunctions = pointsSelectionFunctions;
391}
392
394{
395 m_pointsSelectionRelations = pointsSelectionRelations;
396}
397
399{
400 m_xLabel = xLabel;
401}
402
404{
405 return m_xLabel;
406}
const int INNER_RADIUS_MIN
const QString DEFAULT_X_LABEL("x")
const ExportPointsIntervalUnits DEFAULT_POINTS_INTERVAL_UNITS_RELATIONS
const double DEFAULT_POINTS_INTERVAL_RELATIONS
const QStringList DEFAULT_CURVE_NAMES_NOT_EXPORTED
const double DEFAULT_POINTS_INTERVAL_FUNCTIONS
const bool DEFAULT_EXTRAPOLATE
const bool DEFAULT_EXPORT_DELIMITER_OVERRIDE
const ExportPointsIntervalUnits DEFAULT_POINTS_INTERVAL_UNITS_FUNCTIONS
const QString DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS
const QString DOCUMENT_SERIALIZE_EXPORT_X_LABEL
const QString DOCUMENT_SERIALIZE_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS
const QString DOCUMENT_SERIALIZE_EXPORT_DELIMITER
const QString DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED
const QString DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS
const QString DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED_NAME
const QString DOCUMENT_SERIALIZE_EXPORT
const QString DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS
const QString DOCUMENT_SERIALIZE_EXPORT_DELIMITER_STRING
const QString DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS
const QString DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED
const QString DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV
const QString DOCUMENT_SERIALIZE_EXPORT_HEADER
const QString DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS
const QString DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS_STRING
const QString DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS
const QString DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS_STRING
const QString DOCUMENT_SERIALIZE_EXPORT_HEADER_STRING
const QString DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
const QString DOCUMENT_SERIALIZE_BOOL_FALSE
const QString DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS_STRING
QString exportDelimiterToString(ExportDelimiter exportDelimiter)
ExportDelimiter
Delimiter values that may or may not be overridden by DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CS...
@ EXPORT_DELIMITER_COMMA
QString exportHeaderToString(ExportHeader exportHeader)
ExportHeader
@ EXPORT_HEADER_SIMPLE
QString exportLayoutFunctionsToString(ExportLayoutFunctions exportLayoutFunctions)
ExportLayoutFunctions
@ EXPORT_LAYOUT_ALL_PER_LINE
QString exportPointsIntervalUnitsToString(ExportPointsIntervalUnits exportPointsIntervalUnits)
@ EXPORT_POINTS_INTERVAL_UNITS_SCREEN
QString exportPointsSelectionFunctionsToString(ExportPointsSelectionFunctions exportPointsSelectionFunctions)
@ EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES
QString exportPointsSelectionRelationsToString(ExportPointsSelectionRelations exportPointsSelectionRelations)
@ EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE
log4cpp::Category * mainCat
Definition Logger.cpp:14
const QString INDENTATION_DELTA
const QString SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS
const QString SETTINGS_EXPORT_POINTS_SELECTION_FUNCTIONS
const QString SETTINGS_ENGAUGE
const QString SETTINGS_EXPORT_POINTS_INTERVAL_FUNCTIONS
const QString SETTINGS_EXPORT_X_LABEL
const QString SETTINGS_EXPORT_CURVE_NAMES_NOT_EXPORTED
const QString SETTINGS_EXPORT_DELIMITER
const QString SETTINGS_GROUP_EXPORT
const QString SETTINGS_EXPORT_POINTS_INTERVAL_RELATIONS
const QString SETTINGS_EXPORT_LAYOUT_FUNCTIONS
const QString SETTINGS_EXPORT_POINTS_SELECTION_RELATIONS
const QString SETTINGS_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS
const QString SETTINGS_EXPORT_HEADER
const QString SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS
const QString SETTINGS_EXPORT_DELIMITER_OVERRIDE_CSV_TSV
const QString SETTINGS_DIGITIZER
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition Xml.cpp:14
Model for DlgSettingsExportFormat and CmdSettingsExportFormat.
bool extrapolateOutsideEndpoints() const
Get methods for extrapolation.
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.
bool overrideCsvTsv() const
Get method for csv/tsv format override.
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 setOverrideCsvTsv(bool overrideCsvTsv)
Set method for csv/tsv format override.
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.
void setExtrapolateOutsideEndpoints(bool extrapolateOutsideEndpoints)
Set methods for extrapolation.
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:42
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18