From b435f985636c38626c4d2c4e6c940aba1be1f676 Mon Sep 17 00:00:00 2001 From: Daniel Guramulta Date: Tue, 28 Jan 2020 10:44:46 +0200 Subject: [PATCH] SpectrumAnalyzer: fix file dialog not displaying correct file formats Signed-off-by: Daniel Guramulta --- src/spectrum_analyzer.cpp | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/spectrum_analyzer.cpp b/src/spectrum_analyzer.cpp index 3b353cfb97..63cb1e86a0 100644 --- a/src/spectrum_analyzer.cpp +++ b/src/spectrum_analyzer.cpp @@ -446,10 +446,23 @@ SpectrumAnalyzer::SpectrumAnalyzer(struct iio_context *ctx, Filter *filt, } else { // 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("Spectrum Analyzer"); @@ -553,11 +566,22 @@ void SpectrumAnalyzer::readPreferences() { void SpectrumAnalyzer::btnExportClicked() { + 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("Spectrum Analyzer");