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;
27 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
28 settings.beginGroup (SETTINGS_GROUP_EXPORT);
30 m_curveNamesNotExported = settings.value (SETTINGS_EXPORT_CURVE_NAMES_NOT_EXPORTED,
31 QVariant (DEFAULT_CURVE_NAMES_NOT_EXPORTED)).toStringList();
32 m_delimiter = (ExportDelimiter) settings.value (SETTINGS_EXPORT_DELIMITER,
33 QVariant (EXPORT_DELIMITER_COMMA)).toInt();
34 m_overrideCsvTsv = settings.value (SETTINGS_EXPORT_DELIMITER_OVERRIDE_CSV_TSV,
35 QVariant (
true)).toBool();
36 m_header = (ExportHeader) settings.value (SETTINGS_EXPORT_HEADER,
37 QVariant (EXPORT_HEADER_SIMPLE)).toInt();
38 m_layoutFunctions = (ExportLayoutFunctions) settings.value (SETTINGS_EXPORT_LAYOUT_FUNCTIONS,
39 QVariant (EXPORT_LAYOUT_ALL_PER_LINE)).toInt();
40 m_pointsIntervalFunctions = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_FUNCTIONS,
41 QVariant (DEFAULT_POINTS_INTERVAL_FUNCTIONS)).toDouble();
42 m_pointsIntervalRelations = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_RELATIONS,
43 QVariant (DEFAULT_POINTS_INTERVAL_RELATIONS)).toDouble();
44 m_pointsIntervalUnitsFunctions = (ExportPointsIntervalUnits) settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS,
45 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_FUNCTIONS)).toInt();
46 m_pointsIntervalUnitsRelations = (ExportPointsIntervalUnits) settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS,
47 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_RELATIONS)).toInt();
48 m_pointsSelectionFunctions = (ExportPointsSelectionFunctions) settings.value (SETTINGS_EXPORT_POINTS_SELECTION_FUNCTIONS,
49 QVariant (EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES)).toInt();
50 m_pointsSelectionRelations = (ExportPointsSelectionRelations) settings.value (SETTINGS_EXPORT_POINTS_SELECTION_RELATIONS,
51 QVariant (EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE)).toInt();
52 m_xLabel = settings.value (SETTINGS_EXPORT_X_LABEL,
53 QVariant (DEFAULT_X_LABEL)).toString();
65 m_delimiter (document.modelExport().
delimiter()),
67 m_header (document.modelExport().
header()),
68 m_xLabel (document.modelExport().
xLabel())
100 m_header = other.
header();
101 m_xLabel = other.
xLabel();
108 return m_curveNamesNotExported;
123 return m_layoutFunctions;
128 LOG4CPP_INFO_S ((*mainCat)) <<
"DocumentModelExportFormat::loadXml";
132 QXmlStreamAttributes attributes = reader.attributes();
134 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS) &&
135 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS) &&
136 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS) &&
137 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS) &&
138 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS) &&
139 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS) &&
140 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS) &&
141 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER) &&
142 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER) &&
143 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL)) {
145 setPointsSelectionFunctions ((ExportPointsSelectionFunctions) attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS).toInt());
151 setLayoutFunctions ((ExportLayoutFunctions) attributes.value(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS).toInt());
152 setDelimiter ((ExportDelimiter) attributes.value (DOCUMENT_SERIALIZE_EXPORT_DELIMITER).toInt());
153 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV)) {
156 QString stringOverrideCsvTsv = attributes.value (DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV).toString();
160 setHeader ((ExportHeader) attributes.value(DOCUMENT_SERIALIZE_EXPORT_HEADER).toInt());
161 setXLabel (attributes.value(DOCUMENT_SERIALIZE_EXPORT_X_LABEL).toString());
164 while ((loadNextFromReader (reader) != QXmlStreamReader::StartElement) ||
165 (reader.name() != DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED)) {
167 if (reader.atEnd()) {
177 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
178 while (tokenType == QXmlStreamReader::StartElement) {
180 if (reader.name() == DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED) {
181 curveNamesNotExported << reader.text().toString();
183 tokenType = loadNextFromReader(reader);
190 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
191 (reader.name() != DOCUMENT_SERIALIZE_EXPORT)){
192 loadNextFromReader(reader);
193 if (reader.atEnd()) {
202 reader.raiseError (QObject::tr (
"Cannot read export data"));
208 return m_overrideCsvTsv;
213 return m_pointsIntervalFunctions;
218 return m_pointsIntervalRelations;
223 return m_pointsIntervalUnitsFunctions;
228 return m_pointsIntervalUnitsRelations;
233 return m_pointsSelectionFunctions;
238 return m_pointsSelectionRelations;
242 QTextStream &str)
const 244 str << indentation <<
"DocumentModelExportFormat\n";
246 indentation += INDENTATION_DELTA;
248 str << indentation <<
"curveNamesNotExported=";
249 QStringList::const_iterator itr;
250 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end(); itr++) {
251 QString curveName = *itr;
252 str << indentation << curveName <<
" ";
256 str << indentation <<
"exportPointsSelectionFunctions=" 257 << exportPointsSelectionFunctionsToString (m_pointsSelectionFunctions) <<
"\n";
258 str << indentation <<
"pointsIntervalFunctions=" << m_pointsIntervalFunctions <<
"\n";
259 str << indentation <<
"pointsIntervalUnitsFunctions=" 260 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsFunctions) <<
"\n";
261 str << indentation <<
"exportPointsSelectionRelations=" 262 << exportPointsSelectionRelationsToString (m_pointsSelectionRelations) <<
"\n";
263 str << indentation <<
"pointsIntervalRelations=" << m_pointsIntervalRelations <<
"\n";
264 str << indentation <<
"pointsIntervalUnitsRelations=" 265 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsRelations) <<
"\n";
266 str << indentation <<
"exportLayoutFunctions=" << exportLayoutFunctionsToString (m_layoutFunctions) <<
"\n";
267 str << indentation <<
"exportDelimiter=" << exportDelimiterToString (m_delimiter) <<
"\n";
268 str << indentation <<
"overrideCsvTsv=" << (m_overrideCsvTsv ?
"true" :
"false") <<
"\n";
269 str << indentation <<
"exportHeader=" << exportHeaderToString (m_header) <<
"\n";
270 str << indentation <<
"xLabel=" << m_xLabel <<
"\n";
275 LOG4CPP_INFO_S ((*mainCat)) <<
"DocumentModelExportFormat::saveXml";
277 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT);
278 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS, QString::number (m_pointsSelectionFunctions));
279 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS_STRING, exportPointsSelectionFunctionsToString (m_pointsSelectionFunctions));
280 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS, QString::number (m_pointsIntervalFunctions));
281 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS, QString::number (m_pointsIntervalUnitsFunctions));
282 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS, QString::number (m_pointsSelectionRelations));
283 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS_STRING, exportPointsSelectionRelationsToString (m_pointsSelectionRelations));
284 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS, QString::number (m_pointsIntervalUnitsRelations));
285 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS, QString::number (m_pointsIntervalRelations));
286 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS, QString::number (m_layoutFunctions));
287 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS_STRING, exportLayoutFunctionsToString (m_layoutFunctions));
288 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER, QString::number (m_delimiter));
289 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CSV_TSV, m_overrideCsvTsv ?
290 DOCUMENT_SERIALIZE_BOOL_TRUE :
291 DOCUMENT_SERIALIZE_BOOL_FALSE);
292 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_STRING, exportDelimiterToString (m_delimiter));
293 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER, QString::number (m_header));
294 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER_STRING, exportHeaderToString (m_header));
295 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL, m_xLabel);
298 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED);
299 QStringList::const_iterator itr;
300 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end (); itr++) {
301 QString curveNameNotExported = *itr;
302 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED);
303 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED_NAME, curveNameNotExported);
304 writer.writeEndElement();
306 writer.writeEndElement();
308 writer.writeEndElement();
Storage of one imported image and the data attached to that image.