changeset 2449:729b96803ab1 csv-export-dialog

Add CSV export format dialog
author Chris Cannam
date Tue, 14 Jan 2020 15:43:31 +0000
parents d7b724db4bd0
children c8fe74afb77d
files main/MainWindow.cpp repoint-lock.json repoint-project.json
diffstat 3 files changed, 85 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/main/MainWindow.cpp	Fri Jan 10 15:06:09 2020 +0000
+++ b/main/MainWindow.cpp	Tue Jan 14 15:43:31 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	Fri Jan 10 15:06:09 2020 +0000
+++ b/repoint-lock.json	Tue Jan 14 15:43:31 2020 +0000
@@ -4,13 +4,13 @@
       "pin": "c42e50a5c297"
     },
     "svcore": {
-      "pin": "c546429d4c2f"
+      "pin": "fd5a87f3c5b4"
     },
     "svgui": {
-      "pin": "1f80a514ce29"
+      "pin": "3943553b95b0"
     },
     "svapp": {
-      "pin": "2dce002539a0"
+      "pin": "15da3ab3d416"
     },
     "checker": {
       "pin": "ef64b3f171d9"
--- a/repoint-project.json	Fri Jan 10 15:06:09 2020 +0000
+++ b/repoint-project.json	Tue Jan 14 15:43:31 2020 +0000
@@ -16,15 +16,18 @@
         },
         "svcore": {
             "vcs": "hg",
-            "service": "soundsoftware"
+            "service": "soundsoftware",
+            "branch": "csv-export-dialog"
         },
         "svgui": {
             "vcs": "hg",
-            "service": "soundsoftware"
+            "service": "soundsoftware",
+            "branch": "csv-export-dialog"
         },
         "svapp": {
             "vcs": "hg",
-	    "service": "soundsoftware"
+	    "service": "soundsoftware",
+            "branch": "csv-export-dialog"
         },
         "checker": {
             "vcs": "hg",