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