Mercurial > hg > svcore
comparison data/fileio/CSVStreamWriter.h @ 1447:5bd240517c1a streaming-csv-writer
Fix multi-selection output line break issue, compare against end frame of last region.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Tue, 17 Apr 2018 10:03:50 +0100 |
parents | 4437209348ef |
children | deabf9fd3d28 |
comparison
equal
deleted
inserted
replaced
1446:0a743cd7b83d | 1447:5bd240517c1a |
---|---|
36 ProgressReporter* reporter = nullptr, | 36 ProgressReporter* reporter = nullptr, |
37 QString delimiter = ",", | 37 QString delimiter = ",", |
38 DataExportOptions options = DataExportDefaults, | 38 DataExportOptions options = DataExportDefaults, |
39 const sv_frame_t blockSize = 16384) | 39 const sv_frame_t blockSize = 16384) |
40 { | 40 { |
41 if (blockSize <= 0) return false; | 41 const auto selections = regions.getSelections(); |
42 if (blockSize <= 0 || selections.empty()) return false; | |
42 | 43 |
43 // TODO, some form of checking validity of selections? | 44 // TODO, some form of checking validity of selections? |
44 const auto nFramesToWrite = std::accumulate( | 45 const auto nFramesToWrite = std::accumulate( |
45 regions.getSelections().begin(), | 46 selections.begin(), |
46 regions.getSelections().end(), | 47 selections.end(), |
47 0, | 48 0, |
48 [](sv_frame_t acc, const Selection& current) -> sv_frame_t { | 49 [](sv_frame_t acc, const Selection& current) -> sv_frame_t { |
49 return acc + (current.getEndFrame() - current.getStartFrame()); | 50 return acc + (current.getEndFrame() - current.getStartFrame()); |
50 } | 51 } |
51 ); | 52 ); |
53 const auto finalFrameOfLastRegion = (*selections.crbegin()).getEndFrame(); | |
52 | 54 |
53 const auto wasCancelled = [&reporter]() { | 55 const auto wasCancelled = [&reporter]() { |
54 return reporter && reporter->wasCancelled(); | 56 return reporter && reporter->wasCancelled(); |
55 }; | 57 }; |
56 | 58 |
57 sv_frame_t nFramesWritten = 0; | 59 sv_frame_t nFramesWritten = 0; |
58 int previousProgress = 0; | 60 int previousProgress = 0; |
59 | 61 |
60 for (const auto& extents : regions.getSelections()) { | 62 for (const auto& extents : selections) { |
61 const auto startFrame = extents.getStartFrame(); | 63 const auto startFrame = extents.getStartFrame(); |
62 const auto endFrame = extents.getEndFrame(); | 64 const auto endFrame = extents.getEndFrame(); |
63 auto readPtr = startFrame; | 65 auto readPtr = startFrame; |
64 while (readPtr < endFrame) { | 66 while (readPtr < endFrame) { |
65 if (wasCancelled()) return false; | 67 if (wasCancelled()) return false; |
70 oss << model.toDelimitedDataStringSubsetWithOptions( | 72 oss << model.toDelimitedDataStringSubsetWithOptions( |
71 delimiter, | 73 delimiter, |
72 options, | 74 options, |
73 start, | 75 start, |
74 end | 76 end |
75 ) << (end < endFrame ? "\n" : ""); | 77 ) << (end < finalFrameOfLastRegion ? "\n" : ""); |
76 nFramesWritten += end - start; | 78 nFramesWritten += end - start; |
77 const auto currentProgress = 100 * nFramesWritten / nFramesToWrite; | 79 const auto currentProgress = 100 * nFramesWritten / nFramesToWrite; |
78 const bool hasIncreased = currentProgress > previousProgress; | 80 const bool hasIncreased = currentProgress > previousProgress; |
79 if (hasIncreased) { | 81 if (hasIncreased) { |
80 if (reporter) reporter->setProgress(currentProgress); | 82 if (reporter) reporter->setProgress(currentProgress); |