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);
32 m_curveNamesNotExported = settings.value (SETTINGS_EXPORT_CURVE_NAMES_NOT_EXPORTED,
33 QVariant (DEFAULT_CURVE_NAMES_NOT_EXPORTED)).toStringList();
34 m_delimiter =
static_cast<ExportDelimiter
> (settings.value (SETTINGS_EXPORT_DELIMITER,
35 QVariant (EXPORT_DELIMITER_COMMA)).toInt());
36 m_extrapolateOutsideEndpoints = settings.value (SETTINGS_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS,
37 QVariant (DEFAULT_EXTRAPOLATE)).toBool();
38 m_overrideCsvTsv = settings.value (SETTINGS_EXPORT_DELIMITER_OVERRIDE_CSV_TSV,
39 QVariant (DEFAULT_EXPORT_DELIMITER_OVERRIDE)).toBool();
40 m_header =
static_cast<ExportHeader
> (settings.value (SETTINGS_EXPORT_HEADER,
41 QVariant (EXPORT_HEADER_SIMPLE)).toInt());
42 m_layoutFunctions =
static_cast<ExportLayoutFunctions
> (settings.value (SETTINGS_EXPORT_LAYOUT_FUNCTIONS,
43 QVariant (EXPORT_LAYOUT_ALL_PER_LINE)).toInt());
44 m_pointsIntervalFunctions = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_FUNCTIONS,
45 QVariant (DEFAULT_POINTS_INTERVAL_FUNCTIONS)).toDouble();
46 m_pointsIntervalRelations = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_RELATIONS,
47 QVariant (DEFAULT_POINTS_INTERVAL_RELATIONS)).toDouble();
48 m_pointsIntervalUnitsFunctions =
static_cast<ExportPointsIntervalUnits
> (settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS,
49 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_FUNCTIONS)).toInt());
50 m_pointsIntervalUnitsRelations =
static_cast<ExportPointsIntervalUnits
> (settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS,
51 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_RELATIONS)).toInt());
52 m_pointsSelectionFunctions =
static_cast<ExportPointsSelectionFunctions
> (settings.value (SETTINGS_EXPORT_POINTS_SELECTION_FUNCTIONS,
53 QVariant (EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES)).toInt());
54 m_pointsSelectionRelations =
static_cast<ExportPointsSelectionRelations
> (settings.value (SETTINGS_EXPORT_POINTS_SELECTION_RELATIONS,
55 QVariant (EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE)).toInt());
56 m_xLabel = settings.value (SETTINGS_EXPORT_X_LABEL,
57 QVariant (DEFAULT_X_LABEL)).toString();
61 m_curveNamesNotExported (document.modelExport().curveNamesNotExported()),
62 m_pointsSelectionFunctions (document.modelExport().pointsSelectionFunctions()),
63 m_pointsIntervalFunctions (document.modelExport().pointsIntervalFunctions()),
64 m_pointsIntervalUnitsFunctions (document.modelExport().pointsIntervalUnitsFunctions()),
65 m_pointsSelectionRelations (document.modelExport().pointsSelectionRelations()),
66 m_pointsIntervalRelations (document.modelExport().pointsIntervalRelations()),
67 m_pointsIntervalUnitsRelations (document.modelExport().pointsIntervalUnitsRelations()),
68 m_layoutFunctions (document.modelExport().layoutFunctions()),
69 m_delimiter (document.modelExport().delimiter()),
70 m_extrapolateOutsideEndpoints (document.modelExport().extrapolateOutsideEndpoints()),
71 m_overrideCsvTsv (document.modelExport().overrideCsvTsv()),
72 m_header (document.modelExport().header()),
73 m_xLabel (document.modelExport().xLabel())
78 m_curveNamesNotExported (other.curveNamesNotExported()),
79 m_pointsSelectionFunctions (other.pointsSelectionFunctions()),
80 m_pointsIntervalFunctions (other.pointsIntervalFunctions()),
81 m_pointsIntervalUnitsFunctions (other.pointsIntervalUnitsFunctions()),
82 m_pointsSelectionRelations (other.pointsSelectionRelations()),
83 m_pointsIntervalRelations (other.pointsIntervalRelations()),
84 m_pointsIntervalUnitsRelations (other.pointsIntervalUnitsRelations()),
85 m_layoutFunctions (other.layoutFunctions()),
86 m_delimiter (other.delimiter()),
87 m_extrapolateOutsideEndpoints (other.extrapolateOutsideEndpoints()),
88 m_overrideCsvTsv (other.overrideCsvTsv()),
89 m_header (other.header()),
90 m_xLabel (other.xLabel ())
107 m_header = other.
header();
108 m_xLabel = other.
xLabel();
115 return m_curveNamesNotExported;
125 return m_extrapolateOutsideEndpoints;
135 return m_layoutFunctions;
140 LOG4CPP_INFO_S ((*mainCat)) <<
"DocumentModelExportFormat::loadXml";
144 QXmlStreamAttributes attributes = reader.attributes();
147 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS) &&
148 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS) &&
149 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS) &&
150 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS) &&
151 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS) &&
152 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS) &&
153 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS) &&
154 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER) &&
155 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER) &&
156 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL)) {
158 setPointsSelectionFunctions (static_cast<ExportPointsSelectionFunctions> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS).toInt()));
160 setPointsIntervalUnitsFunctions (static_cast<ExportPointsIntervalUnits> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS).toInt()));
161 setPointsSelectionRelations (static_cast<ExportPointsSelectionRelations> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS).toInt()));
163 setPointsIntervalUnitsRelations (static_cast<ExportPointsIntervalUnits> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS).toInt()));
164 setLayoutFunctions (static_cast<ExportLayoutFunctions> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS).toInt()));
165 setDelimiter (static_cast<ExportDelimiter> (attributes.value (DOCUMENT_SERIALIZE_EXPORT_DELIMITER).toInt()));
166 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV)) {
169 QString stringOverrideCsvTsv = attributes.value (DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV).toString();
173 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS)) {
176 QString stringExtrapolate = attributes.value (DOCUMENT_SERIALIZE_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS).toString();
181 setHeader (static_cast<ExportHeader> (attributes.value(DOCUMENT_SERIALIZE_EXPORT_HEADER).toInt()));
182 setXLabel (attributes.value(DOCUMENT_SERIALIZE_EXPORT_X_LABEL).toString());
185 while ((loadNextFromReader (reader) != QXmlStreamReader::StartElement) ||
186 (reader.name() != DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED)) {
188 if (reader.atEnd()) {
198 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
199 while (tokenType == QXmlStreamReader::StartElement) {
201 if (reader.name() == DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED) {
202 curveNamesNotExported << reader.text().toString();
204 tokenType = loadNextFromReader(reader);
211 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
212 (reader.name() != DOCUMENT_SERIALIZE_EXPORT)){
213 loadNextFromReader(reader);
214 if (reader.atEnd()) {
223 reader.raiseError (QObject::tr (
"Cannot read export data"));
229 return m_overrideCsvTsv;
234 return m_pointsIntervalFunctions;
239 return m_pointsIntervalRelations;
244 return m_pointsIntervalUnitsFunctions;
249 return m_pointsIntervalUnitsRelations;
254 return m_pointsSelectionFunctions;
259 return m_pointsSelectionRelations;
263 QTextStream &str)
const
265 str << indentation <<
"DocumentModelExportFormat\n";
267 indentation += INDENTATION_DELTA;
269 str << indentation <<
"curveNamesNotExported=";
270 QStringList::const_iterator itr;
271 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end(); itr++) {
272 QString curveName = *itr;
273 str << indentation << curveName <<
" ";
277 str << indentation <<
"exportPointsSelectionFunctions="
278 << exportPointsSelectionFunctionsToString (m_pointsSelectionFunctions) <<
"\n";
279 str << indentation <<
"pointsIntervalFunctions=" << m_pointsIntervalFunctions <<
"\n";
280 str << indentation <<
"pointsIntervalUnitsFunctions="
281 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsFunctions) <<
"\n";
282 str << indentation <<
"exportPointsSelectionRelations="
283 << exportPointsSelectionRelationsToString (m_pointsSelectionRelations) <<
"\n";
284 str << indentation <<
"pointsIntervalRelations=" << m_pointsIntervalRelations <<
"\n";
285 str << indentation <<
"pointsIntervalUnitsRelations="
286 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsRelations) <<
"\n";
287 str << indentation <<
"exportLayoutFunctions=" << exportLayoutFunctionsToString (m_layoutFunctions) <<
"\n";
288 str << indentation <<
"exportDelimiter=" << exportDelimiterToString (m_delimiter) <<
"\n";
289 str << indentation <<
"exportExtrapolateOutsideEndpoints=" << (m_extrapolateOutsideEndpoints ?
"yes" :
"no") <<
"\n";
290 str << indentation <<
"overrideCsvTsv=" << (m_overrideCsvTsv ?
"true" :
"false") <<
"\n";
291 str << indentation <<
"exportHeader=" << exportHeaderToString (m_header) <<
"\n";
292 str << indentation <<
"xLabel=" << m_xLabel <<
"\n";
297 LOG4CPP_INFO_S ((*mainCat)) <<
"DocumentModelExportFormat::saveXml";
299 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT);
300 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS, QString::number (m_pointsSelectionFunctions));
301 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS_STRING, exportPointsSelectionFunctionsToString (m_pointsSelectionFunctions));
302 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS, QString::number (m_pointsIntervalFunctions));
303 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS, QString::number (m_pointsIntervalUnitsFunctions));
304 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS, QString::number (m_pointsSelectionRelations));
305 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS_STRING, exportPointsSelectionRelationsToString (m_pointsSelectionRelations));
306 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS, QString::number (m_pointsIntervalUnitsRelations));
307 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS, QString::number (m_pointsIntervalRelations));
308 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS, QString::number (m_layoutFunctions));
309 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS_STRING, exportLayoutFunctionsToString (m_layoutFunctions));
310 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER, QString::number (m_delimiter));
311 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV, m_overrideCsvTsv ?
312 DOCUMENT_SERIALIZE_BOOL_TRUE :
313 DOCUMENT_SERIALIZE_BOOL_FALSE);
314 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_STRING, exportDelimiterToString (m_delimiter));
315 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_EXTRAPOLATE_OUTSIDE_ENDPOINTS, m_extrapolateOutsideEndpoints ?
316 DOCUMENT_SERIALIZE_BOOL_TRUE :
317 DOCUMENT_SERIALIZE_BOOL_FALSE);
318 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER, QString::number (m_header));
319 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER_STRING, exportHeaderToString (m_header));
320 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL, m_xLabel);
323 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED);
324 QStringList::const_iterator itr;
325 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end (); itr++) {
326 QString curveNameNotExported = *itr;
327 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED);
328 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED_NAME, curveNameNotExported);
329 writer.writeEndElement();
331 writer.writeEndElement();
333 writer.writeEndElement();
Storage of one imported image and the data attached to that image.