2020-09-12 05:07:15 +08:00
# include "preferences.h"
2021-10-21 19:00:34 +08:00
2020-09-12 05:07:15 +08:00
# include "ui_preferencesdialog.h"
2021-10-21 19:00:34 +08:00
# include "CustomWidgets/informationbox.h"
2022-03-03 19:28:59 +08:00
# include "appwindow.h"
2022-08-06 00:29:31 +08:00
# include "Device/compounddeviceeditdialog.h"
2021-10-21 19:00:34 +08:00
2020-09-12 05:07:15 +08:00
# include <QSettings>
# include <QPushButton>
# include <QMessageBox>
2020-11-12 02:13:53 +08:00
# include <QDebug>
2022-01-16 00:00:57 +08:00
# include <QFileDialog>
# include <map>
# include <fstream>
# include <iomanip>
2020-09-12 05:07:15 +08:00
using namespace std ;
2020-10-23 03:12:33 +08:00
Preferences Preferences : : instance ;
2020-09-12 05:07:15 +08:00
PreferencesDialog : : PreferencesDialog ( Preferences * pref , QWidget * parent ) :
QDialog ( parent ) ,
ui ( new Ui : : PreferencesDialog ) ,
p ( pref )
{
ui - > setupUi ( this ) ;
2021-07-10 04:26:44 +08:00
auto setDefaultSettingsEnabled = [ = ] ( bool en ) {
ui - > StartupSweepType - > setEnabled ( en ) ;
ui - > StartupSweepStart - > setEnabled ( en ) ;
ui - > StartupSweepStop - > setEnabled ( en ) ;
ui - > StartupSweepPoints - > setEnabled ( en ) ;
ui - > StartupSweepPowerStart - > setEnabled ( en ) ;
ui - > StartupSweepPowerStop - > setEnabled ( en ) ;
ui - > StartupSweepPowerFrequency - > setEnabled ( en ) ;
ui - > StartupSweepLevel - > setEnabled ( en ) ;
ui - > StartupSweepBandwidth - > setEnabled ( en ) ;
ui - > StartupSweepAveraging - > setEnabled ( en ) ;
ui - > StartupGeneratorFrequency - > setEnabled ( en ) ;
ui - > StartupGeneratorLevel - > setEnabled ( en ) ;
ui - > StartupSAStart - > setEnabled ( en ) ;
ui - > StartupSAStop - > setEnabled ( en ) ;
ui - > StartupSARBW - > setEnabled ( en ) ;
ui - > StartupSAWindow - > setEnabled ( en ) ;
ui - > StartupSADetector - > setEnabled ( en ) ;
ui - > StartupSAAveraging - > setEnabled ( en ) ;
ui - > StartupSASignalID - > setEnabled ( en ) ;
} ;
2020-09-12 05:07:15 +08:00
// Setup GUI connections and adjustments
// Startup page
connect ( ui - > StartupSweepLastUsed , & QPushButton : : clicked , [ = ] ( ) {
2021-07-10 04:26:44 +08:00
setDefaultSettingsEnabled ( false ) ;
2022-01-30 06:31:58 +08:00
ui - > StartupSetupFile - > setEnabled ( false ) ;
ui - > StartupBrowse - > setEnabled ( false ) ;
2022-01-31 01:09:47 +08:00
ui - > StartupStack - > setCurrentWidget ( ui - > StartupPageLastUsed ) ;
2020-09-12 05:07:15 +08:00
} ) ;
connect ( ui - > StartupSweepDefault , & QPushButton : : clicked , [ = ] ( ) {
2021-07-10 04:26:44 +08:00
setDefaultSettingsEnabled ( true ) ;
2022-01-30 06:31:58 +08:00
ui - > StartupSetupFile - > setEnabled ( false ) ;
ui - > StartupBrowse - > setEnabled ( false ) ;
2022-01-31 01:09:47 +08:00
ui - > StartupStack - > setCurrentWidget ( ui - > StartupPageDefaultValues ) ;
2022-01-30 06:31:58 +08:00
} ) ;
connect ( ui - > StartupUseSetupFile , & QPushButton : : clicked , [ = ] ( ) {
setDefaultSettingsEnabled ( false ) ;
ui - > StartupSetupFile - > setEnabled ( true ) ;
ui - > StartupBrowse - > setEnabled ( true ) ;
2022-01-31 01:09:47 +08:00
ui - > StartupStack - > setCurrentWidget ( ui - > StartupPageSetupFile ) ;
2022-01-30 06:31:58 +08:00
} ) ;
connect ( ui - > StartupBrowse , & QPushButton : : clicked , [ = ] ( ) {
ui - > StartupSetupFile - > setText ( QFileDialog : : getOpenFileName ( nullptr , " Select startup setup file " , " " , " Setup files (*.setup) " , nullptr , QFileDialog : : DontUseNativeDialog ) ) ;
2020-09-12 05:07:15 +08:00
} ) ;
ui - > StartupSweepStart - > setUnit ( " Hz " ) ;
ui - > StartupSweepStart - > setPrefixes ( " kMG " ) ;
ui - > StartupSweepStop - > setUnit ( " Hz " ) ;
ui - > StartupSweepStop - > setPrefixes ( " kMG " ) ;
2021-07-10 04:26:44 +08:00
ui - > StartupSweepPowerFrequency - > setUnit ( " Hz " ) ;
ui - > StartupSweepPowerFrequency - > setPrefixes ( " kMG " ) ;
2020-09-12 05:07:15 +08:00
ui - > StartupSweepBandwidth - > setUnit ( " Hz " ) ;
ui - > StartupSweepBandwidth - > setPrefixes ( " k " ) ;
2020-10-22 23:13:36 +08:00
ui - > StartupGeneratorFrequency - > setUnit ( " Hz " ) ;
ui - > StartupGeneratorFrequency - > setPrefixes ( " kMG " ) ;
ui - > StartupSAStart - > setUnit ( " Hz " ) ;
ui - > StartupSAStart - > setPrefixes ( " kMG " ) ;
ui - > StartupSAStop - > setUnit ( " Hz " ) ;
ui - > StartupSAStop - > setPrefixes ( " kMG " ) ;
ui - > StartupSARBW - > setUnit ( " Hz " ) ;
ui - > StartupSARBW - > setPrefixes ( " k " ) ;
2020-09-12 05:07:15 +08:00
2020-11-07 20:22:10 +08:00
// Acquisition page
ui - > AcquisitionDFTlimitRBW - > setUnit ( " Hz " ) ;
ui - > AcquisitionDFTlimitRBW - > setPrefixes ( " k " ) ;
connect ( ui - > AcquisitionUseDFT , & QCheckBox : : toggled , [ = ] ( bool enabled ) {
ui - > AcquisitionDFTlimitRBW - > setEnabled ( enabled ) ;
} ) ;
2022-01-15 23:11:33 +08:00
ui - > AcquisitionIF1 - > setUnit ( " Hz " ) ;
ui - > AcquisitionIF1 - > setPrefixes ( " kM " ) ;
ui - > AcquisitionIF1 - > setPrecision ( 6 ) ;
ui - > AcquisitionADCRate - > setUnit ( " Hz " ) ;
ui - > AcquisitionADCRate - > setPrefixes ( " kM " ) ;
ui - > AcquisitionADCRate - > setPrecision ( 6 ) ;
ui - > AcquisitionIF2 - > setUnit ( " Hz " ) ;
ui - > AcquisitionIF2 - > setPrefixes ( " kM " ) ;
ui - > AcquisitionIF2 - > setPrecision ( 6 ) ;
auto updateADCRate = [ = ] ( ) {
// update ADC rate, see FPGA protocol for calculation
ui - > AcquisitionADCRate - > setValue ( 102400000.0 / ui - > AcquisitionADCpresc - > value ( ) ) ;
} ;
auto updateIF2 = [ = ] ( ) {
auto ADCrate = ui - > AcquisitionADCRate - > value ( ) ;
ui - > AcquisitionIF2 - > setValue ( ADCrate * ui - > AcquisitionADCphaseInc - > value ( ) / 4096 ) ;
} ;
connect ( ui - > AcquisitionADCpresc , qOverload < int > ( & QSpinBox : : valueChanged ) , updateADCRate ) ;
connect ( ui - > AcquisitionADCpresc , qOverload < int > ( & QSpinBox : : valueChanged ) , updateIF2 ) ;
connect ( ui - > AcquisitionADCphaseInc , qOverload < int > ( & QSpinBox : : valueChanged ) , updateIF2 ) ;
2020-11-07 20:22:10 +08:00
2021-04-11 18:33:37 +08:00
// General page
if ( p - > TCPoverride ) {
2021-07-10 19:12:30 +08:00
ui - > SCPIServerPort - > setEnabled ( false ) ;
ui - > SCPIServerEnabled - > setEnabled ( false ) ;
2021-04-11 18:33:37 +08:00
}
2022-01-07 19:37:47 +08:00
connect ( ui - > MarkerShowMarkerData , & QCheckBox : : toggled , [ = ] ( bool enabled ) {
ui - > MarkerShowAllMarkerData - > setEnabled ( enabled ) ;
2021-05-15 02:34:23 +08:00
} ) ;
2022-08-06 00:29:31 +08:00
// Compound device page
connect ( ui - > compoundList , & QListWidget : : currentRowChanged , [ = ] ( ) {
if ( VirtualDevice : : getConnected ( ) & & VirtualDevice : : getConnected ( ) - > getCompoundDevice ( ) = = p - > compoundDevices [ ui - > compoundList - > currentRow ( ) ] ) {
// can't remove the device we are connected to
ui - > compoundDelete - > setEnabled ( false ) ;
} else {
ui - > compoundDelete - > setEnabled ( true ) ;
}
} ) ;
connect ( ui - > compoundList , & QListWidget : : doubleClicked , [ = ] ( ) {
auto index = ui - > compoundList - > currentRow ( ) ;
if ( index > = 0 & & index < p - > compoundDevices . size ( ) ) {
auto d = new CompoundDeviceEditDialog ( p - > compoundDevices [ index ] ) ;
d - > show ( ) ;
}
} ) ;
connect ( ui - > compoundAdd , & QPushButton : : clicked , [ = ] ( ) {
auto cd = new CompoundDevice ;
auto d = new CompoundDeviceEditDialog ( cd ) ;
connect ( d , & QDialog : : accepted , [ = ] ( ) {
p - > compoundDevices . push_back ( cd ) ;
ui - > compoundList - > addItem ( cd - > getDesription ( ) ) ;
p - > nonTrivialWriting ( ) ;
} ) ;
connect ( d , & QDialog : : rejected , [ = ] ( ) {
delete cd ;
} ) ;
d - > show ( ) ;
} ) ;
connect ( ui - > compoundDelete , & QPushButton : : clicked , [ = ] ( ) {
auto index = ui - > compoundList - > currentRow ( ) ;
if ( index > = 0 & & index < p - > compoundDevices . size ( ) ) {
// delete the actual compound device
if ( VirtualDevice : : getConnected ( ) & & VirtualDevice : : getConnected ( ) - > getCompoundDevice ( ) = = p - > compoundDevices [ index ] ) {
// can't remove the device we are currently connected to
return ;
}
delete p - > compoundDevices [ index ] ;
// delete the line in the GUI list
delete ui - > compoundList - > takeItem ( index ) ;
// remove compound device from list
p - > compoundDevices . erase ( p - > compoundDevices . begin ( ) + index ) ;
p - > nonTrivialWriting ( ) ;
}
} ) ;
2020-09-12 05:07:15 +08:00
// Page selection
connect ( ui - > treeWidget , & QTreeWidget : : currentItemChanged , [ = ] ( QTreeWidgetItem * current , QTreeWidgetItem * ) {
auto name = current - > text ( 0 ) ;
2021-07-10 19:12:30 +08:00
// remove any potential white space in name (can't have whitespace in page names)
name . replace ( " " , " " ) ;
2020-09-12 05:07:15 +08:00
for ( int i = 0 ; i < ui - > pageWidget - > count ( ) ; i + + ) {
auto w = ui - > pageWidget - > widget ( i ) ;
if ( name = = w - > objectName ( ) ) {
// found the correct page, set to front
ui - > pageWidget - > setCurrentWidget ( w ) ;
break ;
}
}
} ) ;
// Reset and OK action
connect ( ui - > buttonBox - > button ( QDialogButtonBox : : RestoreDefaults ) , & QPushButton : : clicked , [ = ] ( ) {
2021-10-13 03:58:44 +08:00
if ( InformationBox : : AskQuestion ( " Restore defaults? " , " Do you really want to set all preferences to their default values? " , true ) ) {
2020-09-12 05:07:15 +08:00
p - > setDefault ( ) ;
setInitialGUIState ( ) ;
}
} ) ;
connect ( ui - > buttonBox - > button ( QDialogButtonBox : : Ok ) , & QPushButton : : clicked , [ = ] ( ) {
// apply GUI state to settings
2022-01-16 00:00:57 +08:00
updateFromGUI ( ) ;
2020-09-12 05:07:15 +08:00
accept ( ) ;
} ) ;
2022-01-16 00:00:57 +08:00
connect ( ui - > buttonBox - > button ( QDialogButtonBox : : Save ) , & QPushButton : : clicked , [ = ] ( ) {
auto filename = QFileDialog : : getSaveFileName ( this , " Save preferences " , " " , " LibreVNA preferences files (*.vnapref) " , nullptr , QFileDialog : : DontUseNativeDialog ) ;
if ( filename . length ( ) > 0 ) {
if ( ! filename . toLower ( ) . endsWith ( " .vnapref " ) ) {
filename . append ( " .vnapref " ) ;
}
ofstream file ;
file . open ( filename . toStdString ( ) ) ;
updateFromGUI ( ) ;
file < < setw ( 1 ) < < p - > toJSON ( ) ;
file . close ( ) ;
}
} ) ;
connect ( ui - > buttonBox - > button ( QDialogButtonBox : : Open ) , & QPushButton : : clicked , [ = ] ( ) {
auto filename = QFileDialog : : getOpenFileName ( this , " Load preferences " , " " , " LibreVNA preferences files (*.vnapref) " , nullptr , QFileDialog : : DontUseNativeDialog ) ;
if ( filename . length ( ) > 0 ) {
ifstream file ;
file . open ( filename . toStdString ( ) ) ;
nlohmann : : json j ;
file > > j ;
file . close ( ) ;
p - > fromJSON ( j ) ;
setInitialGUIState ( ) ;
}
} ) ;
2020-09-12 05:07:15 +08:00
setInitialGUIState ( ) ;
2022-01-15 23:11:33 +08:00
updateADCRate ( ) ;
updateIF2 ( ) ;
2020-12-18 22:03:01 +08:00
connect ( ui - > AcquisitionUseHarmonic , & QCheckBox : : toggled , [ = ] ( bool enabled ) {
if ( enabled ) {
2020-12-19 01:52:38 +08:00
InformationBox : : ShowMessage ( " Harmonic Mixing " , " When harmonic mixing is enabled, the frequency range of the VNA is (theoretically) extended up to 18GHz "
2020-12-18 22:03:01 +08:00
" by using higher harmonics of the source signal as well as the 1.LO. The fundamental frequency is still present "
" in the output signal and might disturb the measurement if the DUT is not linear. Performance above 6GHz is not "
2020-12-19 01:52:38 +08:00
" specified and generally not very good. However, this mode might be useful if the signal of interest is just above "
" 6GHz (typically useful values up to 7-8GHz). Performance below 6GHz is not affected by this setting " ) ;
2020-12-18 22:03:01 +08:00
}
} ) ;
2020-09-12 05:07:15 +08:00
}
PreferencesDialog : : ~ PreferencesDialog ( )
{
delete ui ;
}
void PreferencesDialog : : setInitialGUIState ( )
{
ui - > StartupAutoconnect - > setChecked ( p - > Startup . ConnectToFirstDevice ) ;
if ( p - > Startup . RememberSweepSettings ) {
ui - > StartupSweepLastUsed - > click ( ) ;
2022-01-30 06:31:58 +08:00
} if ( p - > Startup . UseSetupFile ) {
ui - > StartupUseSetupFile - > click ( ) ;
2020-09-12 05:07:15 +08:00
} else {
ui - > StartupSweepDefault - > click ( ) ;
}
2022-01-31 01:09:47 +08:00
ui - > StartupAutosaveSetupFile - > setChecked ( p - > Startup . AutosaveSetupFile ) ;
2022-01-30 06:31:58 +08:00
ui - > StartupSetupFile - > setText ( p - > Startup . SetupFile ) ;
2021-07-10 04:26:44 +08:00
ui - > StartupSweepType - > setCurrentText ( p - > Startup . DefaultSweep . type ) ;
ui - > StartupSweepStart - > setValueQuiet ( p - > Startup . DefaultSweep . f_start ) ;
ui - > StartupSweepStop - > setValueQuiet ( p - > Startup . DefaultSweep . f_stop ) ;
ui - > StartupSweepLevel - > setValue ( p - > Startup . DefaultSweep . f_excitation ) ;
ui - > StartupSweepPowerStart - > setValue ( p - > Startup . DefaultSweep . dbm_start ) ;
ui - > StartupSweepPowerStop - > setValue ( p - > Startup . DefaultSweep . dbm_stop ) ;
ui - > StartupSweepPowerFrequency - > setValueQuiet ( p - > Startup . DefaultSweep . dbm_freq ) ;
2020-09-12 05:07:15 +08:00
ui - > StartupSweepBandwidth - > setValueQuiet ( p - > Startup . DefaultSweep . bandwidth ) ;
ui - > StartupSweepPoints - > setValue ( p - > Startup . DefaultSweep . points ) ;
2020-10-22 23:13:36 +08:00
ui - > StartupGeneratorFrequency - > setValue ( p - > Startup . Generator . frequency ) ;
ui - > StartupGeneratorLevel - > setValue ( p - > Startup . Generator . level ) ;
2020-10-23 17:39:07 +08:00
ui - > StartupSweepAveraging - > setValue ( p - > Startup . DefaultSweep . averaging ) ;
2020-10-22 23:13:36 +08:00
ui - > StartupSAStart - > setValue ( p - > Startup . SA . start ) ;
ui - > StartupSAStop - > setValue ( p - > Startup . SA . stop ) ;
ui - > StartupSARBW - > setValue ( p - > Startup . SA . RBW ) ;
ui - > StartupSAWindow - > setCurrentIndex ( p - > Startup . SA . window ) ;
ui - > StartupSADetector - > setCurrentIndex ( p - > Startup . SA . detector ) ;
2020-10-23 17:39:07 +08:00
ui - > StartupSAAveraging - > setValue ( p - > Startup . SA . averaging ) ;
2020-10-22 23:13:36 +08:00
ui - > StartupSASignalID - > setChecked ( p - > Startup . SA . signalID ) ;
2020-09-16 05:22:08 +08:00
ui - > AcquisitionAlwaysExciteBoth - > setChecked ( p - > Acquisition . alwaysExciteBothPorts ) ;
2020-09-20 16:13:06 +08:00
ui - > AcquisitionSuppressPeaks - > setChecked ( p - > Acquisition . suppressPeaks ) ;
2021-07-10 04:26:44 +08:00
ui - > AcquisitionAdjustPowerLevel - > setChecked ( p - > Acquisition . adjustPowerLevel ) ;
2020-12-18 22:03:01 +08:00
ui - > AcquisitionUseHarmonic - > setChecked ( p - > Acquisition . harmonicMixing ) ;
2022-03-07 06:01:11 +08:00
ui - > AcquisitionAllowSegmentedSweep - > setChecked ( p - > Acquisition . allowSegmentedSweep ) ;
2020-11-07 20:22:10 +08:00
ui - > AcquisitionUseDFT - > setChecked ( p - > Acquisition . useDFTinSAmode ) ;
ui - > AcquisitionDFTlimitRBW - > setValue ( p - > Acquisition . RBWLimitForDFT ) ;
2021-12-02 05:11:50 +08:00
ui - > AcquisitionAveragingMode - > setCurrentIndex ( p - > Acquisition . useMedianAveraging ? 1 : 0 ) ;
2022-01-15 23:11:33 +08:00
ui - > AcquisitionIF1 - > setValue ( p - > Acquisition . IF1 ) ;
ui - > AcquisitionADCpresc - > setValue ( p - > Acquisition . ADCprescaler ) ;
ui - > AcquisitionADCphaseInc - > setValue ( p - > Acquisition . DFTPhaseInc ) ;
2020-10-23 03:12:33 +08:00
2021-12-27 23:13:03 +08:00
ui - > GraphsShowUnit - > setChecked ( p - > Graphs . showUnits ) ;
2021-07-10 19:12:30 +08:00
ui - > GraphsColorBackground - > setColor ( p - > Graphs . Color . background ) ;
ui - > GraphsColorAxis - > setColor ( p - > Graphs . Color . axis ) ;
2021-10-18 06:37:40 +08:00
ui - > GraphsColorTicksDivisions - > setColor ( p - > Graphs . Color . Ticks . divisions ) ;
ui - > GraphsColorTicksBackgroundEnabled - > setChecked ( p - > Graphs . Color . Ticks . Background . enabled ) ;
ui - > GraphsColorTicksBackground - > setColor ( p - > Graphs . Color . Ticks . Background . background ) ;
2021-07-10 19:12:30 +08:00
ui - > GraphsDomainChangeBehavior - > setCurrentIndex ( ( int ) p - > Graphs . domainChangeBehavior ) ;
2022-04-22 19:46:46 +08:00
ui - > GraphsLimitIndication - > setCurrentIndex ( ( int ) p - > Graphs . limitIndication ) ;
2021-12-06 01:26:32 +08:00
ui - > GraphsLineWidth - > setValue ( p - > Graphs . lineWidth ) ;
2022-04-20 21:19:58 +08:00
ui - > GraphsFontSizeAxis - > setValue ( p - > Graphs . fontSizeAxis ) ;
ui - > GraphsFontSizeCursorOverlay - > setValue ( p - > Graphs . fontSizeCursorOverlay ) ;
ui - > GraphsFontSizeMarkerData - > setValue ( p - > Graphs . fontSizeMarkerData ) ;
ui - > GraphsFontSizeTraceNames - > setValue ( p - > Graphs . fontSizeTraceNames ) ;
2021-12-06 01:26:32 +08:00
2022-01-07 19:37:47 +08:00
ui - > MarkerShowMarkerData - > setChecked ( p - > Marker . defaultBehavior . showDataOnGraphs ) ;
ui - > MarkerShowAllMarkerData - > setChecked ( p - > Marker . defaultBehavior . showAllData ) ;
ui - > MarkerInterpolate - > setCurrentIndex ( p - > Marker . interpolatePoints ? 1 : 0 ) ;
2022-07-09 21:02:36 +08:00
ui - > MarkerSortOrder - > setCurrentIndex ( ( int ) p - > Marker . sortOrder ) ;
2022-01-07 19:37:47 +08:00
2021-07-10 19:12:30 +08:00
ui - > SCPIServerEnabled - > setChecked ( p - > SCPIServer . enabled ) ;
ui - > SCPIServerPort - > setValue ( p - > SCPIServer . port ) ;
2020-12-01 05:27:38 +08:00
2022-08-06 00:29:31 +08:00
for ( auto cd : p - > compoundDevices ) {
ui - > compoundList - > addItem ( cd - > getDesription ( ) ) ;
}
2020-12-01 05:27:38 +08:00
QTreeWidgetItem * item = ui - > treeWidget - > topLevelItem ( 0 ) ;
if ( item ! = nullptr ) {
ui - > treeWidget - > setCurrentItem ( item ) ; // visually select first item
}
2020-09-12 05:07:15 +08:00
}
2022-01-16 00:00:57 +08:00
void PreferencesDialog : : updateFromGUI ( )
{
p - > Startup . ConnectToFirstDevice = ui - > StartupAutoconnect - > isChecked ( ) ;
p - > Startup . RememberSweepSettings = ui - > StartupSweepLastUsed - > isChecked ( ) ;
2022-01-30 06:31:58 +08:00
p - > Startup . UseSetupFile = ui - > StartupUseSetupFile - > isChecked ( ) ;
p - > Startup . SetupFile = ui - > StartupSetupFile - > text ( ) ;
2022-01-31 01:09:47 +08:00
p - > Startup . AutosaveSetupFile = ui - > StartupAutosaveSetupFile - > isChecked ( ) ;
2022-01-16 00:00:57 +08:00
p - > Startup . DefaultSweep . type = ui - > StartupSweepType - > currentText ( ) ;
p - > Startup . DefaultSweep . f_start = ui - > StartupSweepStart - > value ( ) ;
p - > Startup . DefaultSweep . f_stop = ui - > StartupSweepStop - > value ( ) ;
p - > Startup . DefaultSweep . f_excitation = ui - > StartupSweepLevel - > value ( ) ;
p - > Startup . DefaultSweep . dbm_start = ui - > StartupSweepPowerStart - > value ( ) ;
p - > Startup . DefaultSweep . dbm_stop = ui - > StartupSweepPowerStop - > value ( ) ;
p - > Startup . DefaultSweep . dbm_freq = ui - > StartupSweepPowerFrequency - > value ( ) ;
p - > Startup . DefaultSweep . bandwidth = ui - > StartupSweepBandwidth - > value ( ) ;
p - > Startup . DefaultSweep . points = ui - > StartupSweepPoints - > value ( ) ;
p - > Startup . DefaultSweep . averaging = ui - > StartupSweepAveraging - > value ( ) ;
p - > Startup . Generator . frequency = ui - > StartupGeneratorFrequency - > value ( ) ;
p - > Startup . Generator . level = ui - > StartupGeneratorLevel - > value ( ) ;
p - > Startup . SA . start = ui - > StartupSAStart - > value ( ) ;
p - > Startup . SA . stop = ui - > StartupSAStop - > value ( ) ;
p - > Startup . SA . RBW = ui - > StartupSARBW - > value ( ) ;
p - > Startup . SA . window = ui - > StartupSAWindow - > currentIndex ( ) ;
p - > Startup . SA . detector = ui - > StartupSADetector - > currentIndex ( ) ;
p - > Startup . SA . signalID = ui - > StartupSASignalID - > isChecked ( ) ;
p - > Acquisition . alwaysExciteBothPorts = ui - > AcquisitionAlwaysExciteBoth - > isChecked ( ) ;
p - > Acquisition . suppressPeaks = ui - > AcquisitionSuppressPeaks - > isChecked ( ) ;
p - > Acquisition . adjustPowerLevel = ui - > AcquisitionAdjustPowerLevel - > isChecked ( ) ;
p - > Acquisition . harmonicMixing = ui - > AcquisitionUseHarmonic - > isChecked ( ) ;
2022-03-07 06:01:11 +08:00
p - > Acquisition . allowSegmentedSweep = ui - > AcquisitionAllowSegmentedSweep - > isChecked ( ) ;
2022-01-16 00:00:57 +08:00
p - > Acquisition . useDFTinSAmode = ui - > AcquisitionUseDFT - > isChecked ( ) ;
p - > Acquisition . RBWLimitForDFT = ui - > AcquisitionDFTlimitRBW - > value ( ) ;
p - > Acquisition . useMedianAveraging = ui - > AcquisitionAveragingMode - > currentIndex ( ) = = 1 ;
p - > Acquisition . IF1 = ui - > AcquisitionIF1 - > value ( ) ;
p - > Acquisition . ADCprescaler = ui - > AcquisitionADCpresc - > value ( ) ;
p - > Acquisition . DFTPhaseInc = ui - > AcquisitionADCphaseInc - > value ( ) ;
p - > Graphs . showUnits = ui - > GraphsShowUnit - > isChecked ( ) ;
p - > Graphs . Color . background = ui - > GraphsColorBackground - > getColor ( ) ;
p - > Graphs . Color . axis = ui - > GraphsColorAxis - > getColor ( ) ;
p - > Graphs . Color . Ticks . Background . enabled = ui - > GraphsColorTicksBackgroundEnabled - > isChecked ( ) ;
p - > Graphs . Color . Ticks . Background . background = ui - > GraphsColorTicksBackground - > getColor ( ) ;
p - > Graphs . Color . Ticks . divisions = ui - > GraphsColorTicksDivisions - > getColor ( ) ;
p - > Graphs . domainChangeBehavior = ( GraphDomainChangeBehavior ) ui - > GraphsDomainChangeBehavior - > currentIndex ( ) ;
2022-04-22 19:46:46 +08:00
p - > Graphs . limitIndication = ( GraphLimitIndication ) ui - > GraphsLimitIndication - > currentIndex ( ) ;
2022-01-16 00:00:57 +08:00
p - > Graphs . lineWidth = ui - > GraphsLineWidth - > value ( ) ;
2022-04-20 21:19:58 +08:00
p - > Graphs . fontSizeAxis = ui - > GraphsFontSizeAxis - > value ( ) ;
p - > Graphs . fontSizeCursorOverlay = ui - > GraphsFontSizeCursorOverlay - > value ( ) ;
p - > Graphs . fontSizeMarkerData = ui - > GraphsFontSizeMarkerData - > value ( ) ;
p - > Graphs . fontSizeTraceNames = ui - > GraphsFontSizeTraceNames - > value ( ) ;
2022-01-16 00:00:57 +08:00
p - > Marker . defaultBehavior . showDataOnGraphs = ui - > MarkerShowMarkerData - > isChecked ( ) ;
p - > Marker . defaultBehavior . showAllData = ui - > MarkerShowAllMarkerData - > isChecked ( ) ;
p - > Marker . interpolatePoints = ui - > MarkerInterpolate - > currentIndex ( ) = = 1 ;
2022-07-09 21:02:36 +08:00
p - > Marker . sortOrder = ( MarkerSortOrder ) ui - > MarkerSortOrder - > currentIndex ( ) ;
2022-01-16 00:00:57 +08:00
p - > SCPIServer . enabled = ui - > SCPIServerEnabled - > isChecked ( ) ;
p - > SCPIServer . port = ui - > SCPIServerPort - > value ( ) ;
}
2020-09-12 05:07:15 +08:00
void Preferences : : load ( )
{
QSettings settings ;
// load settings, using default values if not present
2020-11-12 02:13:53 +08:00
qInfo ( ) < < " Loading preferences " ;
2020-09-12 05:07:15 +08:00
for ( auto d : descr ) {
try {
d . var . setValue ( settings . value ( d . name , d . def ) ) ;
2020-11-12 02:13:53 +08:00
qDebug ( ) < < " Setting " < < d . name < < " is set to " < < d . var . value ( ) ;
2020-09-12 05:07:15 +08:00
} catch ( const exception & e ) {
d . var . setValue ( d . def ) ;
2020-11-12 02:13:53 +08:00
qDebug ( ) < < " Setting " < < d . name < < " reset to default: " < < d . def ;
2020-09-12 05:07:15 +08:00
}
}
2022-08-06 00:29:31 +08:00
nonTrivialParsing ( ) ;
2020-09-12 05:07:15 +08:00
}
void Preferences : : store ( )
{
2022-08-06 00:29:31 +08:00
nonTrivialWriting ( ) ;
2020-09-12 05:07:15 +08:00
QSettings settings ;
// store settings
for ( auto d : descr ) {
settings . setValue ( d . name , d . var . value ( ) ) ;
}
}
void Preferences : : edit ( )
{
auto dialog = new PreferencesDialog ( this ) ;
2022-03-03 19:28:59 +08:00
if ( AppWindow : : showGUI ( ) ) {
dialog - > exec ( ) ;
}
2020-09-12 05:07:15 +08:00
}
void Preferences : : setDefault ( )
{
for ( auto d : descr ) {
d . var . setValue ( d . def ) ;
}
}
2022-01-16 00:00:57 +08:00
void Preferences : : fromJSON ( nlohmann : : json j )
{
parseJSON ( j , descr ) ;
2022-08-06 00:29:31 +08:00
nonTrivialParsing ( ) ;
2022-01-16 00:00:57 +08:00
}
nlohmann : : json Preferences : : toJSON ( )
{
2022-08-06 00:29:31 +08:00
nonTrivialWriting ( ) ;
2022-01-16 00:00:57 +08:00
return createJSON ( descr ) ;
}
2022-08-06 00:29:31 +08:00
void Preferences : : nonTrivialParsing ( )
{
try {
compoundDevices . clear ( ) ;
nlohmann : : json jc = nlohmann : : json : : parse ( compoundDeviceJSON . toStdString ( ) ) ;
for ( auto j : jc ) {
auto cd = new CompoundDevice ( ) ;
cd - > fromJSON ( j ) ;
compoundDevices . push_back ( cd ) ;
}
} catch ( const exception & e ) {
qDebug ( ) < < " Failed to parse compound device string: " < < e . what ( ) ;
}
}
void Preferences : : nonTrivialWriting ( )
{
if ( compoundDevices . size ( ) > 0 ) {
nlohmann : : json j ;
for ( auto cd : compoundDevices ) {
j . push_back ( cd - > toJSON ( ) ) ;
}
compoundDeviceJSON = QString : : fromStdString ( j . dump ( ) ) ;
} else {
compoundDeviceJSON = " [] " ;
}
}