Mercurial > hg > svcore
diff data/fileio/CSVFileWriter.cpp @ 1445:4437209348ef streaming-csv-writer
Introduce overload of writeInChunks taking a MultiSelection. Simplifies the progress reporting.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Tue, 17 Apr 2018 10:03:50 +0100 |
parents | cdb316c6a151 |
children | a12fd0456f0c |
line wrap: on
line diff
--- a/data/fileio/CSVFileWriter.cpp Tue Apr 17 10:03:50 2018 +0100 +++ b/data/fileio/CSVFileWriter.cpp Tue Apr 17 10:03:50 2018 +0100 @@ -29,7 +29,6 @@ #include <QFile> #include <QTextStream> #include <exception> -#include <numeric> CSVFileWriter::CSVFileWriter(QString path, Model *model, @@ -86,52 +85,15 @@ QTextStream out(&file); - bool completed = false; - - const auto nFramesToWrite = std::accumulate( - selection->getSelections().begin(), - selection->getSelections().end(), - 0, - [](sv_frame_t acc, const Selection& current) -> sv_frame_t { - return acc + (current.getEndFrame() - current.getStartFrame()); - } + bool completed = CSVStreamWriter::writeInChunks( + out, + *m_model, + *selection, + m_reporter, + m_delimiter, + m_options ); - sv_frame_t nFramesWritten = 0; - const auto createProgressCalculator = [ - &nFramesWritten, - &nFramesToWrite - ](sv_frame_t nFramesToWriteForSelection) { - const auto nFramesWrittenAtSelectionStart = nFramesWritten; - nFramesWritten += nFramesToWriteForSelection; - return [ - &nFramesWritten, - &nFramesToWrite, - nFramesWrittenAtSelectionStart - ] (sv_frame_t nFramesWrittenForSelection) { - const auto nFramesWrittenSoFar = ( - nFramesWrittenAtSelectionStart + nFramesWrittenForSelection - ); - return 100 * nFramesWrittenSoFar / nFramesToWrite; - }; - }; - - for (const auto& bounds : selection->getSelections()) { - completed = CSVStreamWriter::writeInChunks( - out, - *m_model, - bounds, - m_reporter, - m_delimiter, - m_options, - 16384, - createProgressCalculator - ); - if (!completed) { - break; - } - } - file.close(); if (completed) { temp.moveToTarget();