Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 2449:729b96803ab1 csv-export-dialog
Add CSV export format dialog
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2020 15:43:31 +0000 |
parents | 0075f5b8f76c |
children | d2c37d83f78d |
comparison
equal
deleted
inserted
replaced
2447:d7b724db4bd0 | 2449:729b96803ab1 |
---|---|
81 #include "base/Profiler.h" | 81 #include "base/Profiler.h" |
82 #include "base/Clipboard.h" | 82 #include "base/Clipboard.h" |
83 #include "base/UnitDatabase.h" | 83 #include "base/UnitDatabase.h" |
84 #include "layer/ColourDatabase.h" | 84 #include "layer/ColourDatabase.h" |
85 #include "widgets/ModelDataTableDialog.h" | 85 #include "widgets/ModelDataTableDialog.h" |
86 #include "widgets/CSVExportDialog.h" | |
86 #include "rdf/PluginRDFIndexer.h" | 87 #include "rdf/PluginRDFIndexer.h" |
87 | 88 |
88 #include "Surveyer.h" | 89 #include "Surveyer.h" |
89 #include "NetworkPermissionTester.h" | 90 #include "NetworkPermissionTester.h" |
90 #include "framework/VersionTester.h" | 91 #include "framework/VersionTester.h" |
3021 if (path == "") return; | 3022 if (path == "") return; |
3022 | 3023 |
3023 QString suffix = QFileInfo(path).suffix().toLower(); | 3024 QString suffix = QFileInfo(path).suffix().toLower(); |
3024 if (suffix == "") suffix = "svl"; // this is what exportLayerTo defaults to | 3025 if (suffix == "") suffix = "svl"; // this is what exportLayerTo defaults to |
3025 | 3026 |
3026 bool canWriteSelection = ! (suffix == "xml" || | 3027 bool canWriteSelection = |
3027 suffix == "svl" || | 3028 ! (suffix == "xml" || suffix == "svl" || |
3028 suffix == "n3" || | 3029 suffix == "n3" || suffix == "ttl"); |
3029 suffix == "ttl"); | 3030 |
3031 bool useCSVDialog = | |
3032 ! (suffix == "xml" || suffix == "svl" || | |
3033 suffix == "mid" || suffix == "midi" || | |
3034 suffix == "n3" || suffix == "ttl"); | |
3030 | 3035 |
3031 MultiSelection ms = m_viewManager->getSelection(); | 3036 MultiSelection ms = m_viewManager->getSelection(); |
3037 bool haveSelection = !ms.getSelections().empty(); | |
3038 | |
3032 MultiSelection *selectionToWrite = nullptr; | 3039 MultiSelection *selectionToWrite = nullptr; |
3033 | 3040 LayerGeometryProvider *provider = pane; |
3034 if (canWriteSelection && !ms.getSelections().empty()) { | 3041 |
3042 DataExportOptions options = DataExportDefaults; | |
3043 QString delimiter = ","; | |
3044 | |
3045 if (useCSVDialog) { | |
3046 | |
3047 CSVExportDialog::Configuration config; | |
3048 config.layerName = layer->getLayerPresentationName(); | |
3049 config.fileExtension = suffix; | |
3050 config.isDense = false; | |
3051 if (auto m = ModelById::get(modelId)) { | |
3052 config.isDense = !m->isSparse(); | |
3053 } | |
3054 config.haveView = true; | |
3055 config.haveSelection = canWriteSelection && haveSelection; | |
3056 | |
3057 CSVExportDialog dialog(config, this); | |
3058 if (dialog.exec() != QDialog::Accepted) { | |
3059 return; | |
3060 } | |
3061 | |
3062 if (dialog.shouldConstrainToSelection()) { | |
3063 selectionToWrite = &ms; | |
3064 } | |
3065 | |
3066 if (!dialog.shouldConstrainToViewHeight()) { | |
3067 provider = nullptr; | |
3068 } | |
3069 | |
3070 delimiter = dialog.getDelimiter(); | |
3071 | |
3072 if (dialog.shouldIncludeHeader()) { | |
3073 options |= DataExportIncludeHeader; | |
3074 } | |
3075 | |
3076 if (dialog.shouldIncludeTimestamps()) { | |
3077 options |= DataExportAlwaysIncludeTimestamp; | |
3078 } | |
3079 | |
3080 if (dialog.shouldWriteTimeInFrames()) { | |
3081 options |= DataExportWriteTimeInFrames; | |
3082 } | |
3083 | |
3084 } else if (canWriteSelection && haveSelection) { | |
3035 | 3085 |
3036 QStringList items; | 3086 QStringList items; |
3037 items << tr("Export the content of the selected area") | 3087 items << tr("Export the content of the selected area") |
3038 << tr("Export the whole layer"); | 3088 << tr("Export the whole layer"); |
3039 | 3089 |
3041 QString item = ListInputDialog::getItem | 3091 QString item = ListInputDialog::getItem |
3042 (this, tr("Select region to export"), | 3092 (this, tr("Select region to export"), |
3043 tr("Which region of the layer do you want to export?"), | 3093 tr("Which region of the layer do you want to export?"), |
3044 items, 0, &ok); | 3094 items, 0, &ok); |
3045 | 3095 |
3046 if (!ok || item.isEmpty()) return; | 3096 if (!ok || item.isEmpty()) { |
3097 return; | |
3098 } | |
3047 | 3099 |
3048 if (item == items[0]) selectionToWrite = &ms; | 3100 if (item == items[0]) { |
3101 selectionToWrite = &ms; | |
3102 } | |
3049 } | 3103 } |
3050 | 3104 |
3051 QString error; | 3105 QString error; |
3052 | 3106 |
3053 if (!exportLayerTo(layer, pane, selectionToWrite, path, error)) { | 3107 bool result = false; |
3108 | |
3109 if (suffix == "xml" || suffix == "svl") { | |
3110 result = exportLayerToSVL(layer, path, error); | |
3111 } else if (suffix == "mid" || suffix == "midi") { | |
3112 result = exportLayerToMIDI(layer, selectionToWrite, path, error); | |
3113 } else if (suffix == "ttl" || suffix == "n3") { | |
3114 result = exportLayerToRDF(layer, path, error); | |
3115 } else { | |
3116 result = exportLayerToCSV(layer, provider, selectionToWrite, | |
3117 delimiter, options, path, error); | |
3118 } | |
3119 | |
3120 if (!result) { | |
3054 QMessageBox::critical(this, tr("Failed to write file"), error); | 3121 QMessageBox::critical(this, tr("Failed to write file"), error); |
3055 } else { | 3122 } else { |
3056 m_recentFiles.addFile(path); | 3123 m_recentFiles.addFile(path); |
3057 emit activity(tr("Export layer to \"%1\"").arg(path)); | 3124 emit activity(tr("Export layer to \"%1\"").arg(path)); |
3058 } | 3125 } |