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