7 #include "CmdMediator.h" 8 #include "DocumentModelExportFormat.h" 9 #include "DocumentSerialize.h" 13 #include <QTextStream> 14 #include <QXmlStreamWriter> 18 const QStringList DEFAULT_CURVE_NAMES_NOT_EXPORTED;
19 const double DEFAULT_POINTS_INTERVAL_FUNCTIONS = 10;
20 const double DEFAULT_POINTS_INTERVAL_RELATIONS = 10;
21 const QString DEFAULT_X_LABEL (
"x");
22 const ExportPointsIntervalUnits DEFAULT_POINTS_INTERVAL_UNITS_FUNCTIONS = EXPORT_POINTS_INTERVAL_UNITS_SCREEN;
23 const ExportPointsIntervalUnits DEFAULT_POINTS_INTERVAL_UNITS_RELATIONS = EXPORT_POINTS_INTERVAL_UNITS_SCREEN;
24 const bool DEFAULT_EXPORT_DELIMITER_OVERRIDE =
false;
25 const bool DEFAULT_EXTRAPOLATE =
true;
29 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
30 settings.beginGroup (SETTINGS_GROUP_EXPORT);
34 m_curveNamesNotExported = settings.value (SETTINGS_EXPORT_CURVE_NAMES_NOT_EXPORTED,
35 QVariant (DEFAULT_CURVE_NAMES_NOT_EXPORTED)).toStringList();
36 m_delimiter = static_cast<ExportDelimiter> (settings.value (SETTINGS_EXPORT_DELIMITER,
37 QVariant (EXPORT_DELIMITER_COMMA)).toInt());
38 m_extrapolateOutsideEndpoints = settings.value (SETTINGS_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS,
39 QVariant (DEFAULT_EXTRAPOLATE)).toBool();
40 m_overrideCsvTsv = settings.value (SETTINGS_EXPORT_DELIMITER_OVERRIDE_CSV_TSV,
41 QVariant (DEFAULT_EXPORT_DELIMITER_OVERRIDE)).toBool();
42 m_header = static_cast<ExportHeader> (settings.value (SETTINGS_EXPORT_HEADER,
43 QVariant (EXPORT_HEADER_SIMPLE)).toInt());
44 m_layoutFunctions = static_cast<ExportLayoutFunctions> (settings.value (SETTINGS_EXPORT_LAYOUT_FUNCTIONS,
45 QVariant (EXPORT_LAYOUT_ALL_PER_LINE)).toInt());
46 m_pointsIntervalFunctions = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_FUNCTIONS,
47 QVariant (DEFAULT_POINTS_INTERVAL_FUNCTIONS)).toDouble();
48 m_pointsIntervalRelations = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_RELATIONS,
49 QVariant (DEFAULT_POINTS_INTERVAL_RELATIONS)).toDouble();
50 m_pointsIntervalUnitsFunctions = static_cast<ExportPointsIntervalUnits> (settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS,
51 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_FUNCTIONS)).toInt());
52 m_pointsIntervalUnitsRelations = static_cast<ExportPointsIntervalUnits> (settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS,
53 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_RELATIONS)).toInt());
54 m_pointsSelectionFunctions = static_cast<ExportPointsSelectionFunctions> (settings.value (SETTINGS_EXPORT_POINTS_SELECTION_FUNCTIONS,
55 QVariant (EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES)).toInt());
56 m_pointsSelectionRelations = static_cast<ExportPointsSelectionRelations> (settings.value (SETTINGS_EXPORT_POINTS_SELECTION_RELATIONS,
57 QVariant (EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE)).toInt());
58 m_xLabel = settings.value (SETTINGS_EXPORT_X_LABEL,
59 QVariant (DEFAULT_X_LABEL)).toString();
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())
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 ())
109 m_header = other.
header();
110 m_xLabel = other.
xLabel();
117 return m_curveNamesNotExported;
127 return m_extrapolateOutsideEndpoints;
137 return m_layoutFunctions;
142 LOG4CPP_INFO_S ((*mainCat)) <<
"DocumentModelExportFormat::loadXml";
146 QXmlStreamAttributes attributes = reader.attributes();
149 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS) &&
150 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS) &&
151 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS) &&
152 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS) &&
153 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS) &&
154 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS) &&
155 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS) &&
156 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER) &&
157 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER) &&
158 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL)) {
160 setPointsSelectionFunctions (static_cast<ExportPointsSelectionFunctions> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS).toInt()));
162 setPointsIntervalUnitsFunctions (static_cast<ExportPointsIntervalUnits> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS).toInt()));
163 setPointsSelectionRelations (static_cast<ExportPointsSelectionRelations> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS).toInt()));
165 setPointsIntervalUnitsRelations (static_cast<ExportPointsIntervalUnits> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS).toInt()));
166 setLayoutFunctions (static_cast<ExportLayoutFunctions> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS).toInt()));
167 setDelimiter (static_cast<ExportDelimiter> (attributes.value (DOCUMENT_SERIALIZE_EXPORT_DELIMITER).toInt()));
168 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV)) {
171 QString stringOverrideCsvTsv = attributes.value (DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV).toString();
175 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS)) {
178 QString stringExtrapolate = attributes.value (DOCUMENT_SERIALIZE_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS).toString();
183 setHeader (static_cast<ExportHeader> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_HEADER).toInt()));
184 setXLabel (attributes.value(DOCUMENT_SERIALIZE_EXPORT_X_LABEL).toString());
187 while ((loadNextFromReader (reader) != QXmlStreamReader::StartElement) ||
188 (reader.name() != DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED)) {
190 if (reader.atEnd()) {
200 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
201 while (tokenType == QXmlStreamReader::StartElement) {
203 if (reader.name() == DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED) {
206 tokenType = loadNextFromReader(reader);
213 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
214 (reader.name() != DOCUMENT_SERIALIZE_EXPORT)){
215 loadNextFromReader(reader);
216 if (reader.atEnd()) {
225 reader.raiseError (QObject::tr (
"Cannot read export data"));
231 return m_overrideCsvTsv;
236 return m_pointsIntervalFunctions;
241 return m_pointsIntervalRelations;
246 return m_pointsIntervalUnitsFunctions;
251 return m_pointsIntervalUnitsRelations;
256 return m_pointsSelectionFunctions;
261 return m_pointsSelectionRelations;
265 QTextStream &str)
const 267 str << indentation <<
"DocumentModelExportFormat\n";
269 indentation += INDENTATION_DELTA;
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 <<
" ";
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";
299 LOG4CPP_INFO_S ((*mainCat)) <<
"DocumentModelExportFormat::saveXml";
301 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT);
302 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS, QString::number (m_pointsSelectionFunctions));
303 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS_STRING, exportPointsSelectionFunctionsToString (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));
307 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS_STRING, exportPointsSelectionRelationsToString (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));
311 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS_STRING, exportLayoutFunctionsToString (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 ?
314 DOCUMENT_SERIALIZE_BOOL_TRUE :
315 DOCUMENT_SERIALIZE_BOOL_FALSE);
316 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_STRING, exportDelimiterToString (m_delimiter));
317 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS, m_extrapolateOutsideEndpoints ?
318 DOCUMENT_SERIALIZE_BOOL_TRUE :
319 DOCUMENT_SERIALIZE_BOOL_FALSE);
320 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER, QString::number (m_header));
321 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER_STRING, exportHeaderToString (m_header));
322 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL, m_xLabel);
325 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED);
326 QStringList::const_iterator itr;
327 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end (); itr++) {
328 QString curveNameNotExported = *itr;
329 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED);
330 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED_NAME, curveNameNotExported);
331 writer.writeEndElement();
333 writer.writeEndElement();
335 writer.writeEndElement();
Storage of one imported image and the data attached to that image.