CSVFileWriter.cpp

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #include "CSVFileWriter.h"
00017 
00018 #include "model/Model.h"
00019 #include "model/SparseOneDimensionalModel.h"
00020 #include "model/SparseTimeValueModel.h"
00021 #include "model/NoteModel.h"
00022 #include "model/TextModel.h"
00023 
00024 #include <QFile>
00025 #include <QTextStream>
00026 
00027 CSVFileWriter::CSVFileWriter(QString path, Model *model, QString delimiter) :
00028     m_path(path),
00029     m_model(model),
00030     m_error(""),
00031     m_delimiter(delimiter)
00032 {
00033 }
00034 
00035 CSVFileWriter::~CSVFileWriter()
00036 {
00037 }
00038 
00039 bool
00040 CSVFileWriter::isOK() const
00041 {
00042     return m_error == "";
00043 }
00044 
00045 QString
00046 CSVFileWriter::getError() const
00047 {
00048     return m_error;
00049 }
00050 
00051 void
00052 CSVFileWriter::write()
00053 {
00054     QFile file(m_path);
00055     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
00056         m_error = tr("Failed to open file %1 for writing").arg(m_path);
00057         return;
00058     }
00059     
00060     QTextStream out(&file);
00061     out << m_model->toDelimitedDataString(m_delimiter);
00062 
00063     file.close();
00064 }
00065 
00066 

Generated on Wed Feb 20 15:45:25 2008 for SonicVisualiser by  doxygen 1.5.1