comparison data/fileio/CSVFileWriter.cpp @ 839:38bb7c8e415d

Add writeSelection
author Chris Cannam
date Wed, 09 Oct 2013 14:51:46 +0100
parents 341e4e1a6ed3
children 59e7fe1b1003
comparison
equal deleted inserted replaced
838:33fca917c800 839:38bb7c8e415d
21 #include "model/NoteModel.h" 21 #include "model/NoteModel.h"
22 #include "model/TextModel.h" 22 #include "model/TextModel.h"
23 23
24 #include "base/TempWriteFile.h" 24 #include "base/TempWriteFile.h"
25 #include "base/Exceptions.h" 25 #include "base/Exceptions.h"
26 #include "base/Selection.h"
26 27
27 #include <QFile> 28 #include <QFile>
28 #include <QTextStream> 29 #include <QTextStream>
29 30
30 CSVFileWriter::CSVFileWriter(QString path, Model *model, QString delimiter) : 31 CSVFileWriter::CSVFileWriter(QString path, Model *model, QString delimiter) :
73 } catch (FileOperationFailed &f) { 74 } catch (FileOperationFailed &f) {
74 m_error = f.what(); 75 m_error = f.what();
75 } 76 }
76 } 77 }
77 78
79 void
80 CSVFileWriter::writeSelection(MultiSelection *selection)
81 {
82 try {
83 TempWriteFile temp(m_path);
78 84
85 QFile file(temp.getTemporaryFilename());
86 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
87 m_error = tr("Failed to open file %1 for writing")
88 .arg(temp.getTemporaryFilename());
89 return;
90 }
91
92 QTextStream out(&file);
93
94 for (MultiSelection::SelectionList::iterator i =
95 selection->getSelections().begin();
96 i != selection->getSelections().end(); ++i) {
97
98 size_t f0(i->getStartFrame()), f1(i->getEndFrame());
99 out << m_model->toDelimitedDataString(m_delimiter, f0, f1);
100 }
101
102 file.close();
103 temp.moveToTarget();
104
105 } catch (FileOperationFailed &f) {
106 m_error = f.what();
107 }
108 }
109
110
111