# HG changeset patch # User Chris Cannam # Date 1579017557 0 # Node ID c8fe74afb77d4f9977234c10dc4dd4dbd6d738a7 # Parent 119588c4277288313e0b3d9a0e9bfc63ff1b9a95# Parent 729b96803ab1cfc587723b76112a995fd46821ef Merge from branch csv-export-dialog diff -r 119588c42772 -r c8fe74afb77d main/MainWindow.cpp --- a/main/MainWindow.cpp Tue Jan 14 13:23:04 2020 +0000 +++ b/main/MainWindow.cpp Tue Jan 14 15:59:17 2020 +0000 @@ -83,6 +83,7 @@ #include "base/UnitDatabase.h" #include "layer/ColourDatabase.h" #include "widgets/ModelDataTableDialog.h" +#include "widgets/CSVExportDialog.h" #include "rdf/PluginRDFIndexer.h" #include "Surveyer.h" @@ -3023,15 +3024,64 @@ QString suffix = QFileInfo(path).suffix().toLower(); if (suffix == "") suffix = "svl"; // this is what exportLayerTo defaults to - bool canWriteSelection = ! (suffix == "xml" || - suffix == "svl" || - suffix == "n3" || - suffix == "ttl"); + bool canWriteSelection = + ! (suffix == "xml" || suffix == "svl" || + suffix == "n3" || suffix == "ttl"); + + bool useCSVDialog = + ! (suffix == "xml" || suffix == "svl" || + suffix == "mid" || suffix == "midi" || + suffix == "n3" || suffix == "ttl"); MultiSelection ms = m_viewManager->getSelection(); + bool haveSelection = !ms.getSelections().empty(); + MultiSelection *selectionToWrite = nullptr; - - if (canWriteSelection && !ms.getSelections().empty()) { + LayerGeometryProvider *provider = pane; + + DataExportOptions options = DataExportDefaults; + QString delimiter = ","; + + if (useCSVDialog) { + + CSVExportDialog::Configuration config; + config.layerName = layer->getLayerPresentationName(); + config.fileExtension = suffix; + config.isDense = false; + if (auto m = ModelById::get(modelId)) { + config.isDense = !m->isSparse(); + } + config.haveView = true; + config.haveSelection = canWriteSelection && haveSelection; + + CSVExportDialog dialog(config, this); + if (dialog.exec() != QDialog::Accepted) { + return; + } + + if (dialog.shouldConstrainToSelection()) { + selectionToWrite = &ms; + } + + if (!dialog.shouldConstrainToViewHeight()) { + provider = nullptr; + } + + delimiter = dialog.getDelimiter(); + + if (dialog.shouldIncludeHeader()) { + options |= DataExportIncludeHeader; + } + + if (dialog.shouldIncludeTimestamps()) { + options |= DataExportAlwaysIncludeTimestamp; + } + + if (dialog.shouldWriteTimeInFrames()) { + options |= DataExportWriteTimeInFrames; + } + + } else if (canWriteSelection && haveSelection) { QStringList items; items << tr("Export the content of the selected area") @@ -3043,14 +3093,31 @@ tr("Which region of the layer do you want to export?"), items, 0, &ok); - if (!ok || item.isEmpty()) return; + if (!ok || item.isEmpty()) { + return; + } - if (item == items[0]) selectionToWrite = &ms; + if (item == items[0]) { + selectionToWrite = &ms; + } } QString error; - if (!exportLayerTo(layer, pane, selectionToWrite, path, error)) { + bool result = false; + + if (suffix == "xml" || suffix == "svl") { + result = exportLayerToSVL(layer, path, error); + } else if (suffix == "mid" || suffix == "midi") { + result = exportLayerToMIDI(layer, selectionToWrite, path, error); + } else if (suffix == "ttl" || suffix == "n3") { + result = exportLayerToRDF(layer, path, error); + } else { + result = exportLayerToCSV(layer, provider, selectionToWrite, + delimiter, options, path, error); + } + + if (!result) { QMessageBox::critical(this, tr("Failed to write file"), error); } else { m_recentFiles.addFile(path); diff -r 119588c42772 -r c8fe74afb77d repoint-lock.json --- a/repoint-lock.json Tue Jan 14 13:23:04 2020 +0000 +++ b/repoint-lock.json Tue Jan 14 15:59:17 2020 +0000 @@ -4,13 +4,13 @@ "pin": "c42e50a5c297" }, "svcore": { - "pin": "c546429d4c2f" + "pin": "23d5cb3f9f38" }, "svgui": { - "pin": "1f80a514ce29" + "pin": "b33b0b06133e" }, "svapp": { - "pin": "2dce002539a0" + "pin": "8cf265f9b1b3" }, "checker": { "pin": "ef64b3f171d9"