comparison data/model/DenseTimeValueModel.cpp @ 1833:21c792334c2e sensible-delimited-data-strings

Rewrite all the DelimitedDataString stuff so as to return vectors of individual cell strings rather than having the classes add the delimiters themselves. Rename accordingly to names based on StringExport. Take advantage of this in the CSV writer code so as to properly quote cells that contain delimiter characters.
author Chris Cannam
date Fri, 03 Apr 2020 17:11:05 +0100
parents c546429d4c2f
children
comparison
equal deleted inserted replaced
1832:7c92c644db20 1833:21c792334c2e
15 15
16 #include "DenseTimeValueModel.h" 16 #include "DenseTimeValueModel.h"
17 17
18 #include <QStringList> 18 #include <QStringList>
19 19
20 QString 20 using namespace std;
21 DenseTimeValueModel::getDelimitedDataHeaderLine(QString delimiter, 21
22 DataExportOptions) const 22 QVector<QString>
23 DenseTimeValueModel::getStringExportHeaders(DataExportOptions) const
23 { 24 {
24 int ch = getChannelCount(); 25 int ch = getChannelCount();
25 QStringList list; 26 QVector<QString> sv;
26 for (int i = 0; i < ch; ++i) { 27 for (int i = 0; i < ch; ++i) {
27 list << QString("Channel%1").arg(i+1); 28 sv.push_back(QString("Channel%1").arg(i+1));
28 } 29 }
29 return list.join(delimiter); 30 return sv;
30 } 31 }
31 32
32 QString 33 QVector<QVector<QString>>
33 DenseTimeValueModel::toDelimitedDataString(QString delimiter, 34 DenseTimeValueModel::toStringExportRows(DataExportOptions,
34 DataExportOptions, 35 sv_frame_t startFrame,
35 sv_frame_t startFrame, 36 sv_frame_t duration) const
36 sv_frame_t duration) const
37 { 37 {
38 int ch = getChannelCount(); 38 int ch = getChannelCount();
39 39
40 if (duration <= 0) return ""; 40 if (duration <= 0) return {};
41 41
42 auto data = getMultiChannelData(0, ch - 1, startFrame, duration); 42 auto data = getMultiChannelData(0, ch - 1, startFrame, duration);
43 43
44 if (data.empty() || data[0].empty()) return ""; 44 if (data.empty() || data[0].empty()) return {};
45 45
46 QStringList list; 46 QVector<QVector<QString>> rows;
47
47 for (sv_frame_t i = 0; in_range_for(data[0], i); ++i) { 48 for (sv_frame_t i = 0; in_range_for(data[0], i); ++i) {
48 QStringList parts; 49 QVector<QString> row;
49 parts << QString("%1").arg(startFrame + i); 50 row.push_back(QString("%1").arg(startFrame + i));
50 for (int c = 0; in_range_for(data, c); ++c) { 51 for (int c = 0; in_range_for(data, c); ++c) {
51 parts << QString("%1").arg(data[c][i]); 52 row.push_back(QString("%1").arg(data[c][i]));
52 } 53 }
53 list << parts.join(delimiter); 54 rows.push_back(row);
54 } 55 }
55 56
56 return list.join("\n"); 57 return rows;
57 } 58 }