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;
28 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
29 settings.beginGroup (SETTINGS_GROUP_EXPORT);
31 m_curveNamesNotExported = settings.value (SETTINGS_EXPORT_CURVE_NAMES_NOT_EXPORTED,
32 QVariant (DEFAULT_CURVE_NAMES_NOT_EXPORTED)).toStringList();
33 m_delimiter = (ExportDelimiter) settings.value (SETTINGS_EXPORT_DELIMITER,
34 QVariant (EXPORT_DELIMITER_COMMA)).toInt();
35 m_overrideCsvTsv = settings.value (SETTINGS_EXPORT_DELIMITER_OVERRIDE_CSV_TSV,
36 QVariant (DEFAULT_EXPORT_DELIMITER_OVERRIDE)).toBool();
37 m_header = (ExportHeader) settings.value (SETTINGS_EXPORT_HEADER,
38 QVariant (EXPORT_HEADER_SIMPLE)).toInt();
39 m_layoutFunctions = (ExportLayoutFunctions) settings.value (SETTINGS_EXPORT_LAYOUT_FUNCTIONS,
40 QVariant (EXPORT_LAYOUT_ALL_PER_LINE)).toInt();
41 m_pointsIntervalFunctions = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_FUNCTIONS,
42 QVariant (DEFAULT_POINTS_INTERVAL_FUNCTIONS)).toDouble();
43 m_pointsIntervalRelations = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_RELATIONS,
44 QVariant (DEFAULT_POINTS_INTERVAL_RELATIONS)).toDouble();
45 m_pointsIntervalUnitsFunctions = (ExportPointsIntervalUnits) settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS,
46 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_FUNCTIONS)).toInt();
47 m_pointsIntervalUnitsRelations = (ExportPointsIntervalUnits) settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS,
48 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_RELATIONS)).toInt();
49 m_pointsSelectionFunctions = (ExportPointsSelectionFunctions) settings.value (SETTINGS_EXPORT_POINTS_SELECTION_FUNCTIONS,
50 QVariant (EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES)).toInt();
51 m_pointsSelectionRelations = (ExportPointsSelectionRelations) settings.value (SETTINGS_EXPORT_POINTS_SELECTION_RELATIONS,
52 QVariant (EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE)).toInt();
53 m_xLabel = settings.value (SETTINGS_EXPORT_X_LABEL,
54 QVariant (DEFAULT_X_LABEL)).toString();
66 m_delimiter (document.modelExport().
delimiter()),
68 m_header (document.modelExport().
header()),
69 m_xLabel (document.modelExport().
xLabel())
101 m_header = other.
header();
102 m_xLabel = other.
xLabel();
109 return m_curveNamesNotExported;
124 return m_layoutFunctions;
129 LOG4CPP_INFO_S ((*mainCat)) <<
"DocumentModelExportFormat::loadXml";
133 QXmlStreamAttributes attributes = reader.attributes();
135 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS) &&
136 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS) &&
137 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS) &&
138 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS) &&
139 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS) &&
140 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS) &&
141 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS) &&
142 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER) &&
143 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER) &&
144 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL)) {
146 setPointsSelectionFunctions ((ExportPointsSelectionFunctions) attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS).toInt());
149 setPointsSelectionRelations ((ExportPointsSelectionRelations) attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS).toInt());
152 setLayoutFunctions ((ExportLayoutFunctions) attributes.value(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS).toInt());
153 setDelimiter ((ExportDelimiter) attributes.value (DOCUMENT_SERIALIZE_EXPORT_DELIMITER).toInt());
154 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV)) {
157 QString stringOverrideCsvTsv = attributes.value (DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV).toString();
161 setHeader ((ExportHeader) attributes.value(DOCUMENT_SERIALIZE_EXPORT_HEADER).toInt());
162 setXLabel (attributes.value(DOCUMENT_SERIALIZE_EXPORT_X_LABEL).toString());
165 while ((loadNextFromReader (reader) != QXmlStreamReader::StartElement) ||
166 (reader.name() != DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED)) {
168 if (reader.atEnd()) {
178 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
179 while (tokenType == QXmlStreamReader::StartElement) {
181 if (reader.name() == DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED) {
182 curveNamesNotExported << reader.text().toString();
184 tokenType = loadNextFromReader(reader);
191 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
192 (reader.name() != DOCUMENT_SERIALIZE_EXPORT)){
193 loadNextFromReader(reader);
194 if (reader.atEnd()) {
203 reader.raiseError (QObject::tr (
"Cannot read export data"));
209 return m_overrideCsvTsv;
214 return m_pointsIntervalFunctions;
219 return m_pointsIntervalRelations;
224 return m_pointsIntervalUnitsFunctions;
229 return m_pointsIntervalUnitsRelations;
234 return m_pointsSelectionFunctions;
239 return m_pointsSelectionRelations;
243 QTextStream &str)
const 245 str << indentation <<
"DocumentModelExportFormat\n";
247 indentation += INDENTATION_DELTA;
249 str << indentation <<
"curveNamesNotExported=";
250 QStringList::const_iterator itr;
251 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end(); itr++) {
252 QString curveName = *itr;
253 str << indentation << curveName <<
" ";
257 str << indentation <<
"exportPointsSelectionFunctions=" 258 << exportPointsSelectionFunctionsToString (m_pointsSelectionFunctions) <<
"\n";
259 str << indentation <<
"pointsIntervalFunctions=" << m_pointsIntervalFunctions <<
"\n";
260 str << indentation <<
"pointsIntervalUnitsFunctions=" 261 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsFunctions) <<
"\n";
262 str << indentation <<
"exportPointsSelectionRelations=" 263 << exportPointsSelectionRelationsToString (m_pointsSelectionRelations) <<
"\n";
264 str << indentation <<
"pointsIntervalRelations=" << m_pointsIntervalRelations <<
"\n";
265 str << indentation <<
"pointsIntervalUnitsRelations=" 266 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsRelations) <<
"\n";
267 str << indentation <<
"exportLayoutFunctions=" << exportLayoutFunctionsToString (m_layoutFunctions) <<
"\n";
268 str << indentation <<
"exportDelimiter=" << exportDelimiterToString (m_delimiter) <<
"\n";
269 str << indentation <<
"overrideCsvTsv=" << (m_overrideCsvTsv ?
"true" :
"false") <<
"\n";
270 str << indentation <<
"exportHeader=" << exportHeaderToString (m_header) <<
"\n";
271 str << indentation <<
"xLabel=" << m_xLabel <<
"\n";
276 LOG4CPP_INFO_S ((*mainCat)) <<
"DocumentModelExportFormat::saveXml";
278 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT);
279 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS, QString::number (m_pointsSelectionFunctions));
280 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS_STRING, exportPointsSelectionFunctionsToString (m_pointsSelectionFunctions));
281 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS, QString::number (m_pointsIntervalFunctions));
282 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS, QString::number (m_pointsIntervalUnitsFunctions));
283 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS, QString::number (m_pointsSelectionRelations));
284 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS_STRING, exportPointsSelectionRelationsToString (m_pointsSelectionRelations));
285 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS, QString::number (m_pointsIntervalUnitsRelations));
286 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS, QString::number (m_pointsIntervalRelations));
287 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS, QString::number (m_layoutFunctions));
288 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS_STRING, exportLayoutFunctionsToString (m_layoutFunctions));
289 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER, QString::number (m_delimiter));
290 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV, m_overrideCsvTsv ?
291 DOCUMENT_SERIALIZE_BOOL_TRUE :
292 DOCUMENT_SERIALIZE_BOOL_FALSE);
293 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_STRING, exportDelimiterToString (m_delimiter));
294 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER, QString::number (m_header));
295 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER_STRING, exportHeaderToString (m_header));
296 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL, m_xLabel);
299 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED);
300 QStringList::const_iterator itr;
301 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end (); itr++) {
302 QString curveNameNotExported = *itr;
303 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED);
304 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED_NAME, curveNameNotExported);
305 writer.writeEndElement();
307 writer.writeEndElement();
309 writer.writeEndElement();
Storage of one imported image and the data attached to that image.