changeset 2450:c8fe74afb77d

Merge from branch csv-export-dialog
author Chris Cannam
date Tue, 14 Jan 2020 15:59:17 +0000
parents 119588c42772 (current diff) 729b96803ab1 (diff)
children 22af3b429679
files repoint-lock.json repoint-project.json
diffstat 2 files changed, 79 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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"