Add a file picker

This commit is contained in:
Mike Walters
2015-07-19 05:41:34 +01:00
parent ce821178a4
commit 8bebf255b1
5 changed files with 27 additions and 2 deletions

View File

@@ -2,16 +2,16 @@
#include <QDebug>
#include <QElapsedTimer>
#include <QFileDialog>
#include <QPainter>
#include <QPaintEvent>
#include <QRect>
Spectrogram::Spectrogram()
{
inputSource = new InputSource("/home/mike/Downloads/hubsan-chopped.cfile", 1024);
inputSource = nullptr;
powerMax = 0.0f;
powerMin = -50.0f;
resize(inputSource->GetWidth(), inputSource->GetHeight());
}
Spectrogram::~Spectrogram()
@@ -19,6 +19,24 @@ Spectrogram::~Spectrogram()
delete inputSource;
}
void Spectrogram::pickFile()
{
QString fileName = QFileDialog::getOpenFileName(
this, tr("Open File"), "", tr("Sample file (*.cfile *.bin);;All files (*.*)")
);
if (fileName != nullptr) {
try {
InputSource *newFile = new InputSource(fileName.toUtf8().constData(), (inputSource != nullptr) ? inputSource->GetWidth() : 1024);
delete inputSource;
inputSource = newFile;
resize(inputSource->GetWidth(), inputSource->GetHeight());
} catch (std::runtime_error e) {
// TODO: display error
return;
}
}
}
template <class T> const T& clamp (const T& value, const T& min, const T& max) {
return std::min(max, std::max(min, value));
}