Mercurial > hg > svcore
comparison data/fileio/CSVFileWriter.cpp @ 675:341e4e1a6ed3
Use TempWriteFile for CSV export as well
author | Chris Cannam |
---|---|
date | Tue, 29 Mar 2011 17:55:31 +0100 |
parents | 4b2ea82fd0ed |
children | 38bb7c8e415d |
comparison
equal
deleted
inserted
replaced
674:920e3880f7b4 | 675:341e4e1a6ed3 |
---|---|
18 #include "model/Model.h" | 18 #include "model/Model.h" |
19 #include "model/SparseOneDimensionalModel.h" | 19 #include "model/SparseOneDimensionalModel.h" |
20 #include "model/SparseTimeValueModel.h" | 20 #include "model/SparseTimeValueModel.h" |
21 #include "model/NoteModel.h" | 21 #include "model/NoteModel.h" |
22 #include "model/TextModel.h" | 22 #include "model/TextModel.h" |
23 | |
24 #include "base/TempWriteFile.h" | |
25 #include "base/Exceptions.h" | |
23 | 26 |
24 #include <QFile> | 27 #include <QFile> |
25 #include <QTextStream> | 28 #include <QTextStream> |
26 | 29 |
27 CSVFileWriter::CSVFileWriter(QString path, Model *model, QString delimiter) : | 30 CSVFileWriter::CSVFileWriter(QString path, Model *model, QString delimiter) : |
49 } | 52 } |
50 | 53 |
51 void | 54 void |
52 CSVFileWriter::write() | 55 CSVFileWriter::write() |
53 { | 56 { |
54 QFile file(m_path); | 57 try { |
55 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { | 58 TempWriteFile temp(m_path); |
56 m_error = tr("Failed to open file %1 for writing").arg(m_path); | 59 |
57 return; | 60 QFile file(temp.getTemporaryFilename()); |
61 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { | |
62 m_error = tr("Failed to open file %1 for writing") | |
63 .arg(temp.getTemporaryFilename()); | |
64 return; | |
65 } | |
66 | |
67 QTextStream out(&file); | |
68 out << m_model->toDelimitedDataString(m_delimiter); | |
69 | |
70 file.close(); | |
71 temp.moveToTarget(); | |
72 | |
73 } catch (FileOperationFailed &f) { | |
74 m_error = f.what(); | |
58 } | 75 } |
59 | |
60 QTextStream out(&file); | |
61 out << m_model->toDelimitedDataString(m_delimiter); | |
62 | |
63 file.close(); | |
64 } | 76 } |
65 | 77 |
66 | 78 |