From 4cc04c1ca4b2e12d6f65a5b9636d6086e197c67e Mon Sep 17 00:00:00 2001 From: Eoin Mcloughlin Date: Sun, 18 Dec 2016 12:51:59 +0000 Subject: [PATCH] Remember state of "Open File" dialog --- spectrogramcontrols.cpp | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/spectrogramcontrols.cpp b/spectrogramcontrols.cpp index 859eee7..b51523c 100644 --- a/spectrogramcontrols.cpp +++ b/spectrogramcontrols.cpp @@ -139,14 +139,36 @@ void SpectrogramControls::fftOrZoomChanged(int value) void SpectrogramControls::fileOpenButtonClicked() { - QString fileName = QFileDialog::getOpenFileName( - this, tr("Open File"), "", - tr("All files (*);;" - "complex file (*.cfile *.cf32 *.fc32);;" - "complex HackRF file (*.cs8 *.sc8 *.c8);;" - "complex Fancy file (*.cs16 *.sc16 *.c16);;" - "complex RTL-SDR file (*.cu8 *.uc8)") - ); + QSettings settings; + QString fileName; + QFileDialog fileSelect(this); + fileSelect.setNameFilter(tr("All files (*)", + "complex file (*.cfile *.cf32 *.fc32);;" + "complex HackRF file (*.cs8 *.sc8 *.c8);;" + "complex Fancy file (*.cs16 *.sc16 *.c16);;" + "complex RTL-SDR file (*.cu8 *.uc8);;")); + + // Try and load a saved state + { + QByteArray savedState = settings.value("OpenFileState").toByteArray(); + fileSelect.restoreState(savedState); + + // Filter doesn't seem to be considered part of the saved state + QString lastUsedFilter = settings.value("OpenFileFilter").toString(); + if(lastUsedFilter.size()) + fileSelect.selectNameFilter(lastUsedFilter); + } + + if(fileSelect.exec()) + { + fileName = fileSelect.selectedFiles()[0]; + + // Remember the state of the dialog for the next time + QByteArray dialogState = fileSelect.saveState(); + settings.setValue("OpenFileState", dialogState); + settings.setValue("OpenFileFilter", fileSelect.selectedNameFilter()); + } + if (!fileName.isEmpty()) emit openFile(fileName); }