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

Add writeSelection
author Chris Cannam
date Wed, 09 Oct 2013 14:51:46 +0100
parents 341e4e1a6ed3
children 59e7fe1b1003
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();
+    }
+}
+
+
+