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_header = (ExportHeader) settings.value (SETTINGS_EXPORT_HEADER,
35 QVariant (EXPORT_HEADER_SIMPLE)).toInt();
36 m_layoutFunctions = (ExportLayoutFunctions) settings.value (SETTINGS_EXPORT_LAYOUT_FUNCTIONS,
37 QVariant (EXPORT_LAYOUT_ALL_PER_LINE)).toInt();
38 m_pointsIntervalFunctions = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_FUNCTIONS,
39 QVariant (DEFAULT_POINTS_INTERVAL_FUNCTIONS)).toDouble();
40 m_pointsIntervalRelations = settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_RELATIONS,
41 QVariant (DEFAULT_POINTS_INTERVAL_RELATIONS)).toDouble();
42 m_pointsIntervalUnitsFunctions = (ExportPointsIntervalUnits) settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS,
43 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_FUNCTIONS)).toInt();
44 m_pointsIntervalUnitsRelations = (ExportPointsIntervalUnits) settings.value (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS,
45 QVariant (DEFAULT_POINTS_INTERVAL_UNITS_RELATIONS)).toInt();
46 m_pointsSelectionFunctions = (ExportPointsSelectionFunctions) settings.value (SETTINGS_EXPORT_POINTS_SELECTION_FUNCTIONS,
47 QVariant (EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES)).toInt();
48 m_pointsSelectionRelations = (ExportPointsSelectionRelations) settings.value (SETTINGS_EXPORT_POINTS_SELECTION_RELATIONS,
49 QVariant (EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE)).toInt();
50 m_xLabel = settings.value (SETTINGS_EXPORT_X_LABEL,
51 QVariant (DEFAULT_X_LABEL)).toString();
55 m_curveNamesNotExported (document.modelExport().curveNamesNotExported()),
56 m_pointsSelectionFunctions (document.modelExport().pointsSelectionFunctions()),
57 m_pointsIntervalFunctions (document.modelExport().pointsIntervalFunctions()),
58 m_pointsIntervalUnitsFunctions (document.modelExport().pointsIntervalUnitsFunctions()),
59 m_pointsSelectionRelations (document.modelExport().pointsSelectionRelations()),
60 m_pointsIntervalRelations (document.modelExport().pointsIntervalRelations()),
61 m_pointsIntervalUnitsRelations (document.modelExport().pointsIntervalUnitsRelations()),
62 m_layoutFunctions (document.modelExport().layoutFunctions()),
63 m_delimiter (document.modelExport().delimiter()),
64 m_header (document.modelExport().header()),
65 m_xLabel (document.modelExport().xLabel())
70 m_curveNamesNotExported (other.curveNamesNotExported()),
71 m_pointsSelectionFunctions (other.pointsSelectionFunctions()),
72 m_pointsIntervalFunctions (other.pointsIntervalFunctions()),
73 m_pointsIntervalUnitsFunctions (other.pointsIntervalUnitsFunctions()),
74 m_pointsSelectionRelations (other.pointsSelectionRelations()),
75 m_pointsIntervalRelations (other.pointsIntervalRelations()),
76 m_pointsIntervalUnitsRelations (other.pointsIntervalUnitsRelations()),
77 m_layoutFunctions (other.layoutFunctions()),
78 m_delimiter (other.delimiter()),
79 m_header (other.header()),
80 m_xLabel (other.xLabel ())
104 return m_curveNamesNotExported;
119 return m_layoutFunctions;
124 LOG4CPP_INFO_S ((*mainCat)) <<
"DocumentModelExportFormat::loadXml";
128 QXmlStreamAttributes attributes = reader.attributes();
130 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS) &&
131 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS) &&
132 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS) &&
133 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS) &&
134 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS) &&
135 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS) &&
136 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS) &&
137 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER) &&
138 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER) &&
139 attributes.hasAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL)) {
141 setPointsSelectionFunctions ((ExportPointsSelectionFunctions) attributes.value(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS).toInt());
147 setLayoutFunctions ((ExportLayoutFunctions) attributes.value(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS).toInt());
148 setDelimiter ((ExportDelimiter) attributes.value (DOCUMENT_SERIALIZE_EXPORT_DELIMITER).toInt());
149 setHeader ((ExportHeader) attributes.value(DOCUMENT_SERIALIZE_EXPORT_HEADER).toInt());
150 setXLabel (attributes.value(DOCUMENT_SERIALIZE_EXPORT_X_LABEL).toString());
153 while ((loadNextFromReader (reader) != QXmlStreamReader::StartElement) ||
154 (reader.name() != DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED)) {
156 if (reader.atEnd()) {
166 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
167 while (tokenType == QXmlStreamReader::StartElement) {
169 if (reader.name() == DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED) {
170 curveNamesNotExported << reader.text().toString();
172 tokenType = loadNextFromReader(reader);
179 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
180 (reader.name() != DOCUMENT_SERIALIZE_EXPORT)){
181 loadNextFromReader(reader);
182 if (reader.atEnd()) {
191 reader.raiseError (QObject::tr (
"Cannot read export data"));
197 return m_pointsIntervalFunctions;
202 return m_pointsIntervalRelations;
207 return m_pointsIntervalUnitsFunctions;
212 return m_pointsIntervalUnitsRelations;
217 return m_pointsSelectionFunctions;
222 return m_pointsSelectionRelations;
226 QTextStream &str)
const
228 str << indentation <<
"DocumentModelExportFormat\n";
230 indentation += INDENTATION_DELTA;
232 str << indentation <<
"curveNamesNotExported=";
233 QStringList::const_iterator itr;
234 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end(); itr++) {
235 QString curveName = *itr;
236 str << indentation << curveName <<
" ";
240 str << indentation <<
"exportPointsSelectionFunctions="
241 << exportPointsSelectionFunctionsToString (m_pointsSelectionFunctions) <<
"\n";
242 str << indentation <<
"pointsIntervalFunctions=" << m_pointsIntervalFunctions <<
"\n";
243 str << indentation <<
"pointsIntervalUnitsFunctions="
244 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsFunctions) <<
"\n";
245 str << indentation <<
"exportPointsSelectionRelations="
246 << exportPointsSelectionRelationsToString (m_pointsSelectionRelations) <<
"\n";
247 str << indentation <<
"pointsIntervalRelations=" << m_pointsIntervalRelations <<
"\n";
248 str << indentation <<
"pointsIntervalUnitsRelations="
249 << exportPointsIntervalUnitsToString (m_pointsIntervalUnitsRelations) <<
"\n";
250 str << indentation <<
"exportLayoutFunctions=" << exportLayoutFunctionsToString (m_layoutFunctions) <<
"\n";
251 str << indentation <<
"exportDelimiter=" << exportDelimiterToString (m_delimiter) <<
"\n";
252 str << indentation <<
"exportHeader=" << exportHeaderToString (m_header) <<
"\n";
253 str << indentation <<
"xLabel=" << m_xLabel <<
"\n";
258 LOG4CPP_INFO_S ((*mainCat)) <<
"DocumentModelExportFormat::saveXml";
260 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT);
261 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS, QString::number (m_pointsSelectionFunctions));
262 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_FUNCTIONS_STRING, exportPointsSelectionFunctionsToString (m_pointsSelectionFunctions));
263 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_FUNCTIONS, QString::number (m_pointsIntervalFunctions));
264 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS, QString::number (m_pointsIntervalUnitsFunctions));
265 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS, QString::number (m_pointsSelectionRelations));
266 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_SELECTION_RELATIONS_STRING, exportPointsSelectionRelationsToString (m_pointsSelectionRelations));
267 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS, QString::number (m_pointsIntervalUnitsRelations));
268 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_POINTS_INTERVAL_RELATIONS, QString::number (m_pointsIntervalRelations));
269 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS, QString::number (m_layoutFunctions));
270 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_LAYOUT_FUNCTIONS_STRING, exportLayoutFunctionsToString (m_layoutFunctions));
271 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER, QString::number (m_delimiter));
272 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_DELIMITER_STRING, exportDelimiterToString (m_delimiter));
273 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER, QString::number (m_header));
274 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_HEADER_STRING, exportHeaderToString (m_header));
275 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_X_LABEL, m_xLabel);
278 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAMES_NOT_EXPORTED);
279 QStringList::const_iterator itr;
280 for (itr = m_curveNamesNotExported.begin (); itr != m_curveNamesNotExported.end (); itr++) {
281 QString curveNameNotExported = *itr;
282 writer.writeStartElement(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED);
283 writer.writeAttribute(DOCUMENT_SERIALIZE_EXPORT_CURVE_NAME_NOT_EXPORTED_NAME, curveNameNotExported);
284 writer.writeEndElement();
286 writer.writeEndElement();
288 writer.writeEndElement();
Storage of one imported image and the data attached to that image.