Skip to content

Commit

Permalink
LogicAnalyzer: fix file dialog not displaying correct file formats
Browse files Browse the repository at this point in the history
The file dialogs now display the correct formats that they support.

Signed-off-by: Daniel Guramulta <[email protected]>
  • Loading branch information
DanielGuramulta committed Jan 28, 2020
1 parent dcb6c19 commit db8e929
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions src/logic_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <QDateTime>
#include <QButtonGroup>
#include <QDateTime>
#include <QImageWriter>

/* Local includes */
#include "pulseview/pv/mainwindow.hpp"
Expand Down Expand Up @@ -473,11 +474,29 @@ LogicAnalyzer::LogicAnalyzer(struct iio_context *ctx,

QString date = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss");

QString fileNameHint = "Scopy-" + api->objectName() + "-" + date + ".png";
QString fileNameHint = "Scopy-" + api->objectName() + "-" + date;

QString fileName = QFileDialog::getSaveFileName(this,
tr("Export"), fileNameHint, tr({"(*.png);;"}),
nullptr, (m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));
const QList<QByteArray> imageFormats =
QImageWriter::supportedImageFormats();

QStringList filter;
if ( imageFormats.size() > 0 ) {
for ( int i = 0; i < imageFormats.size(); i++ ) {
filter += (imageFormats[i].toUpper() + " "
+ tr("Image") + " (*." + imageFormats[i] + ")");
}
}

QString selectedFilter = filter[0];
QString fileName = QFileDialog::getSaveFileName(this,
tr("Export"), fileNameHint, 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;
}

painter.end();
img.invertPixels(QImage::InvertRgb);
Expand Down Expand Up @@ -698,25 +717,34 @@ QString LogicAnalyzer::saveToFile()
if( noChannelEnabled )
return "";

QStringList filter;
filter += QString(tr("Comma-separated values files (*.csv)"));
filter += QString(tr("Tab-delimited values files (*.txt)"));
filter += QString(tr("Value Change Dump(*.vcd)"));
filter += QString(tr("All Files(*)"));

QString fileName = QFileDialog::getSaveFileName(this,
tr("Export"), "", tr("Comma-separated values files (*.csv)",
"Tab-delimited values files (*.txt)"),
tr("Export"), "", filter.join(";;"),
&selectedFilter, (m_useNativeDialogs ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog));


if(fileName.isEmpty()) {
return "";
}

// Check the selected file type
if(selectedFilter != "") {
if(selectedFilter.contains("comma", Qt::CaseInsensitive))
if(selectedFilter.contains("comma", Qt::CaseInsensitive)) {
fileName += ".csv";
separator = ",";
if(selectedFilter.contains("tab", Qt::CaseInsensitive))
}
if(selectedFilter.contains("tab", Qt::CaseInsensitive)) {
fileName += ".txt";
separator = "\t";
}
if(selectedFilter.contains("Change Dump", Qt::CaseInsensitive)) {
endRow = " $end\n";
startRow = "$";
fileName += ".vcd";
}
}

Expand Down

0 comments on commit db8e929

Please sign in to comment.