Skip to content

Commit

Permalink
SpectrumAnalyzer: fix file dialog not displaying correct file formats
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Guramulta <[email protected]>
  • Loading branch information
DanielGuramulta committed Jan 28, 2020
1 parent a92af08 commit b435f98
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions src/spectrum_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b435f98

Please sign in to comment.