comparison data/fileio/CSVFileWriter.cpp @ 0:fc9323a41f5a

start base : Sonic Visualiser sv1-1.0rc1
author lbajardsilogic
date Fri, 11 May 2007 09:08:14 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:fc9323a41f5a
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #include "CSVFileWriter.h"
17
18 #include "model/Model.h"
19 #include "model/SparseOneDimensionalModel.h"
20 #include "model/SparseTimeValueModel.h"
21 #include "model/NoteModel.h"
22 #include "model/TextModel.h"
23
24 #include <QFile>
25 #include <QTextStream>
26
27 CSVFileWriter::CSVFileWriter(QString path, Model *model, QString delimiter) :
28 m_path(path),
29 m_model(model),
30 m_error(""),
31 m_delimiter(delimiter)
32 {
33 }
34
35 CSVFileWriter::~CSVFileWriter()
36 {
37 }
38
39 bool
40 CSVFileWriter::isOK() const
41 {
42 return m_error == "";
43 }
44
45 QString
46 CSVFileWriter::getError() const
47 {
48 return m_error;
49 }
50
51 void
52 CSVFileWriter::write()
53 {
54 QFile file(m_path);
55 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
56 m_error = tr("Failed to open file %1 for writing").arg(m_path);
57 return;
58 }
59
60 QTextStream out(&file);
61 out << m_model->toDelimitedDataString(m_delimiter);
62
63 file.close();
64 }
65
66