Mercurial > hg > svcore
annotate data/fileio/CSVFileWriter.cpp @ 188:f86b74d1b143
* Simplify maker names in plugin menu
* Make sure derived models have a name (based on the transform)
* Don't start deriving a model from a derived model until the derived model is
  ready
* Tidy up completion management in writable wave file model
* Make writable models save/reload correctly from session file (i.e.
  regenerating from the original transform)
* Same for dense 3d models -- don't save the data, just the transform details
* Add a comment describing the SV file format
| author | Chris Cannam | 
|---|---|
| date | Fri, 13 Oct 2006 12:51:05 +0000 | 
| parents | 4b2ea82fd0ed | 
| children | 341e4e1a6ed3 | 
| rev | line source | 
|---|---|
| Chris@148 | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | 
| Chris@148 | 2 | 
| Chris@148 | 3 /* | 
| Chris@148 | 4 Sonic Visualiser | 
| Chris@148 | 5 An audio file viewer and annotation editor. | 
| Chris@148 | 6 Centre for Digital Music, Queen Mary, University of London. | 
| Chris@148 | 7 This file copyright 2006 Chris Cannam. | 
| Chris@148 | 8 | 
| Chris@148 | 9 This program is free software; you can redistribute it and/or | 
| Chris@148 | 10 modify it under the terms of the GNU General Public License as | 
| Chris@148 | 11 published by the Free Software Foundation; either version 2 of the | 
| Chris@148 | 12 License, or (at your option) any later version. See the file | 
| Chris@148 | 13 COPYING included with this distribution for more information. | 
| Chris@148 | 14 */ | 
| Chris@148 | 15 | 
| Chris@148 | 16 #include "CSVFileWriter.h" | 
| Chris@148 | 17 | 
| Chris@150 | 18 #include "model/Model.h" | 
| Chris@148 | 19 #include "model/SparseOneDimensionalModel.h" | 
| Chris@148 | 20 #include "model/SparseTimeValueModel.h" | 
| Chris@148 | 21 #include "model/NoteModel.h" | 
| Chris@148 | 22 #include "model/TextModel.h" | 
| Chris@148 | 23 | 
| Chris@148 | 24 #include <QFile> | 
| Chris@148 | 25 #include <QTextStream> | 
| Chris@148 | 26 | 
| Chris@148 | 27 CSVFileWriter::CSVFileWriter(QString path, Model *model, QString delimiter) : | 
| Chris@148 | 28 m_path(path), | 
| Chris@148 | 29 m_model(model), | 
| Chris@148 | 30 m_error(""), | 
| Chris@148 | 31 m_delimiter(delimiter) | 
| Chris@148 | 32 { | 
| Chris@148 | 33 } | 
| Chris@148 | 34 | 
| Chris@148 | 35 CSVFileWriter::~CSVFileWriter() | 
| Chris@148 | 36 { | 
| Chris@148 | 37 } | 
| Chris@148 | 38 | 
| Chris@148 | 39 bool | 
| Chris@148 | 40 CSVFileWriter::isOK() const | 
| Chris@148 | 41 { | 
| Chris@148 | 42 return m_error == ""; | 
| Chris@148 | 43 } | 
| Chris@148 | 44 | 
| Chris@148 | 45 QString | 
| Chris@148 | 46 CSVFileWriter::getError() const | 
| Chris@148 | 47 { | 
| Chris@148 | 48 return m_error; | 
| Chris@148 | 49 } | 
| Chris@148 | 50 | 
| Chris@148 | 51 void | 
| Chris@148 | 52 CSVFileWriter::write() | 
| Chris@148 | 53 { | 
| Chris@148 | 54 QFile file(m_path); | 
| Chris@148 | 55 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { | 
| Chris@148 | 56 m_error = tr("Failed to open file %1 for writing").arg(m_path); | 
| Chris@148 | 57 return; | 
| Chris@148 | 58 } | 
| Chris@148 | 59 | 
| Chris@148 | 60 QTextStream out(&file); | 
| Chris@148 | 61 out << m_model->toDelimitedDataString(m_delimiter); | 
| Chris@148 | 62 | 
| Chris@148 | 63 file.close(); | 
| Chris@148 | 64 } | 
| Chris@148 | 65 | 
| Chris@148 | 66 | 
