Skip to content

Commit

Permalink
Oscilloscope: 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 b435f98 commit 3d4c582
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/oscilloscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]){
Expand Down

0 comments on commit 3d4c582

Please sign in to comment.