changeset 839:38bb7c8e415d

Add writeSelection
author Chris Cannam
date Wed, 09 Oct 2013 14:51:46 +0100
parents 33fca917c800
children e50a8fee6752
files data/fileio/CSVFileWriter.cpp data/fileio/CSVFileWriter.h
diffstat 2 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CSVFileWriter.cpp	Wed Oct 09 14:47:19 2013 +0100
+++ b/data/fileio/CSVFileWriter.cpp	Wed Oct 09 14:51:46 2013 +0100
@@ -23,6 +23,7 @@
 
 #include "base/TempWriteFile.h"
 #include "base/Exceptions.h"
+#include "base/Selection.h"
 
 #include <QFile>
 #include <QTextStream>
@@ -75,4 +76,36 @@
     }
 }
 
+void
+CSVFileWriter::writeSelection(MultiSelection *selection)
+{
+    try {
+        TempWriteFile temp(m_path);
 
+        QFile file(temp.getTemporaryFilename());
+        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+            m_error = tr("Failed to open file %1 for writing")
+                .arg(temp.getTemporaryFilename());
+            return;
+        }
+    
+        QTextStream out(&file);
+
+        for (MultiSelection::SelectionList::iterator i =
+                 selection->getSelections().begin();
+             i != selection->getSelections().end(); ++i) {
+	
+            size_t f0(i->getStartFrame()), f1(i->getEndFrame());
+            out << m_model->toDelimitedDataString(m_delimiter, f0, f1);
+        }
+
+        file.close();
+        temp.moveToTarget();
+
+    } catch (FileOperationFailed &f) {
+        m_error = f.what();
+    }
+}
+
+
+
--- a/data/fileio/CSVFileWriter.h	Wed Oct 09 14:47:19 2013 +0100
+++ b/data/fileio/CSVFileWriter.h	Wed Oct 09 14:51:46 2013 +0100
@@ -20,6 +20,7 @@
 #include <QString>
 
 class Model;
+class MultiSelection;
 
 class CSVFileWriter : public QObject
 {
@@ -33,6 +34,7 @@
     virtual QString getError() const;
 
     virtual void write();
+    virtual void writeSelection(MultiSelection *selection);
 
 protected:
     QString m_path;