From 62a89fcf22e405e01a50a64242d45a22bdf201e9 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 16 Jan 2025 12:04:15 +0000 Subject: [PATCH] Quote newline entries for matrix CSV exports. Closes #3520 --- qrenderdoc/Windows/BufferViewer.cpp | 57 ++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/qrenderdoc/Windows/BufferViewer.cpp b/qrenderdoc/Windows/BufferViewer.cpp index 3231b0ac9e..2cd48071c6 100644 --- a/qrenderdoc/Windows/BufferViewer.cpp +++ b/qrenderdoc/Windows/BufferViewer.cpp @@ -6467,7 +6467,19 @@ void BufferViewer::exportData(const BufferExport ¶ms) { for(int col = 0; col < model->columnCount(); col++) { - s << model->data(model->index(row, col), Qt::DisplayRole).toString(); + QList lines = + model->data(model->index(row, col), Qt::DisplayRole).toString().split(lit("\n")); + bool quote = (lines.count() > 1); + if(quote) + s << "\""; + for(int l = 0; l < lines.count(); l++) + { + s << lines[l].trimmed(); + if(l + 1 < lines.size()) + s << "\n"; + } + if(quote) + s << "\""; if(col + 1 < model->columnCount()) s << ", "; @@ -6487,13 +6499,13 @@ void BufferViewer::exportData(const BufferExport ¶ms) // it's fine to block invoke, because this is on the export thread m_Ctx.Replay().BlockInvoke( - [buff, &s, &config, byteOffset, chunkSize](IReplayController *r) { + [buff, &s, &config, byteOffset, chunkSize](IReplayController *controller) { // cache column data for the inner loop QVector cache; BufferData bufferData; - bufferData.storage = r->GetBufferData(buff, byteOffset, chunkSize); + bufferData.storage = controller->GetBufferData(buff, byteOffset, chunkSize); bufferData.stride = config.buffers[0]->stride; size_t numRows = @@ -6526,15 +6538,30 @@ void BufferViewer::exportData(const BufferExport ¶ms) // since some formats are packed and can't be read individually QVariantList list = GetVariants(prop->format, *el, data, end); - for(int v = 0; v < list.count(); v++) + if(el->type.rows > 1) { - s << interpretVariant(list[v], *el, *prop); - - if(v + 1 < list.count()) - s << ", "; + for(int c = 0; c < el->type.columns; c++) + { + s << "\""; + for(int r = 0; r < el->type.rows; r++) + { + if(list.empty()) + { + s << "---"; + } + else + { + int el_idx = r * el->type.columns + c; + s << interpretVariant(list[el_idx], *el, *prop).trimmed(); + } + + if(r + 1 < el->type.rows) + s << "\n"; + } + s << "\", "; + } } - - if(list.empty()) + else if(list.empty()) { for(int v = 0; v < d.numColumns; v++) { @@ -6544,6 +6571,16 @@ void BufferViewer::exportData(const BufferExport ¶ms) s << ", "; } } + else + { + for(int v = 0; v < list.count(); v++) + { + s << interpretVariant(list[v], *el, *prop); + + if(v + 1 < list.count()) + s << ", "; + } + } if(col + 1 < cache.count()) s << ", ";