annotate 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
rev   line source
Chris@147 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@147 2
Chris@147 3 /*
Chris@147 4 Sonic Visualiser
Chris@147 5 An audio file viewer and annotation editor.
Chris@147 6 Centre for Digital Music, Queen Mary, University of London.
Chris@147 7 This file copyright 2006 Chris Cannam.
Chris@147 8
Chris@147 9 This program is free software; you can redistribute it and/or
Chris@147 10 modify it under the terms of the GNU General Public License as
Chris@147 11 published by the Free Software Foundation; either version 2 of the
Chris@147 12 License, or (at your option) any later version. See the file
Chris@147 13 COPYING included with this distribution for more information.
Chris@147 14 */
Chris@147 15
Chris@147 16 #include "DenseTimeValueModel.h"
Chris@147 17
Chris@838 18 #include <QStringList>
Chris@1815 19
Chris@1833 20 using namespace std;
Chris@1833 21
Chris@1833 22 QVector<QString>
Chris@1833 23 DenseTimeValueModel::getStringExportHeaders(DataExportOptions) const
Chris@1815 24 {
Chris@1815 25 int ch = getChannelCount();
Chris@1833 26 QVector<QString> sv;
Chris@1815 27 for (int i = 0; i < ch; ++i) {
Chris@1833 28 sv.push_back(QString("Channel%1").arg(i+1));
Chris@1815 29 }
Chris@1833 30 return sv;
Chris@1815 31 }
Chris@1815 32
Chris@1833 33 QVector<QVector<QString>>
Chris@1833 34 DenseTimeValueModel::toStringExportRows(DataExportOptions,
Chris@1833 35 sv_frame_t startFrame,
Chris@1833 36 sv_frame_t duration) const
Chris@838 37 {
Chris@929 38 int ch = getChannelCount();
Chris@838 39
Chris@1833 40 if (duration <= 0) return {};
Chris@838 41
Chris@1679 42 auto data = getMultiChannelData(0, ch - 1, startFrame, duration);
Chris@838 43
Chris@1833 44 if (data.empty() || data[0].empty()) return {};
Chris@1096 45
Chris@1833 46 QVector<QVector<QString>> rows;
Chris@1833 47
Chris@1096 48 for (sv_frame_t i = 0; in_range_for(data[0], i); ++i) {
Chris@1833 49 QVector<QString> row;
Chris@1833 50 row.push_back(QString("%1").arg(startFrame + i));
Chris@1096 51 for (int c = 0; in_range_for(data, c); ++c) {
Chris@1833 52 row.push_back(QString("%1").arg(data[c][i]));
Chris@838 53 }
Chris@1833 54 rows.push_back(row);
Chris@838 55 }
Chris@838 56
Chris@1833 57 return rows;
Chris@838 58 }