comparison data/fileio/CSVFileWriter.cpp @ 148:1a42221a1522

* Reorganising code base. This revision will not compile.
author Chris Cannam
date Mon, 31 Jul 2006 11:49:58 +0000
parents
children 4b2ea82fd0ed
comparison
equal deleted inserted replaced
147:3a13b0d4934e 148:1a42221a1522
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 "base/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