From 3d4c582787bd1ae350596c89b57b3ddd23abbd72 Mon Sep 17 00:00:00 2001 From: Daniel Guramulta Date: Tue, 28 Jan 2020 10:52:07 +0200 Subject: [PATCH] Oscilloscope: fix file dialog not displaying correct file formats Signed-off-by: Daniel Guramulta --- src/oscilloscope.cpp | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/oscilloscope.cpp b/src/oscilloscope.cpp index d9c161b9b2..33ce76f480 100644 --- a/src/oscilloscope.cpp +++ b/src/oscilloscope.cpp @@ -1286,10 +1286,23 @@ void Oscilloscope::init_channel_settings() ChannelWidget *cw = channelWidgetAtId(current_ch_widget); if (current_ch_widget > 1 && cw->isReferenceChannel()) { // export + QStringList filter; + filter += QString(tr("Comma-separated values files (*.csv)")); + filter += QString(tr("Tab-delimited values files (*.txt)")); + filter += QString(tr("All Files(*)")); + + QString selectedFilter = filter[0]; + QString fileName = QFileDialog::getSaveFileName(this, - tr("Export"), "", tr("Comma-separated values files (*.csv)", - "Tab-delimited values files (*.txt)"), - nullptr, (m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog)); + tr("Export"), "", filter.join(";;"), + &selectedFilter, (m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog)); + + if (fileName.split(".").size() <= 1) { + // file name w/o extension. Let's append it + QString ext = selectedFilter.split(".")[1].split(")")[0]; + fileName += "." + ext; + } + if (!fileName.isEmpty()) { FileManager fm("Oscilloscope"); fm.open(fileName, FileManager::EXPORT); @@ -1744,10 +1757,22 @@ void Oscilloscope::btnExport_clicked(){ exportConfig = exportSettings->getExportConfig(); pause(true); + QStringList filter; + filter += QString(tr("Comma-separated values files (*.csv)")); + filter += QString(tr("Tab-delimited values files (*.txt)")); + filter += QString(tr("All Files(*)")); + + QString selectedFilter = filter[0]; + QString fileName = QFileDialog::getSaveFileName(this, - tr("Export"), "", tr("Comma-separated values files (*.csv)", - "Tab-delimited values files (*.txt)"), - nullptr, (m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog)); + tr("Export"), "", filter.join(";;"), + &selectedFilter, (m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog)); + + if (fileName.split(".").size() <= 1) { + // file name w/o extension. Let's append it + QString ext = selectedFilter.split(".")[1].split(")")[0]; + fileName += "." + ext; + } bool atleastOneChannelEnabled = false; for (auto x : exportConfig.keys()) if (exportConfig[x]){