improve autostart from setup file

This commit is contained in:
Jan Käberich 2022-01-30 18:09:47 +01:00
parent 0c782fc009
commit cb5f472c47
5 changed files with 514 additions and 404 deletions

View File

@ -144,15 +144,7 @@ AppWindow::AppWindow(QWidget *parent)
// aborted selection
return;
}
if(!filename.endsWith(".setup")) {
filename.append(".setup");
}
ofstream file;
file.open(filename.toStdString());
file << setw(4) << SaveSetup() << endl;
file.close();
QFileInfo fi(filename);
lSetupName.setText("Setup: "+fi.fileName());
SaveSetup(filename);
});
connect(ui->actionLoad_setup, &QAction::triggered, [=](){
auto filename = QFileDialog::getOpenFileName(nullptr, "Load setup data", "", "Setup files (*.setup)", nullptr, QFileDialog::DontUseNativeDialog);
@ -243,9 +235,12 @@ AppWindow::AppWindow(QWidget *parent)
qRegisterMetaType<Protocol::SpectrumAnalyzerResult>("SpectrumAnalyzerResult");
qRegisterMetaType<Protocol::AmplitudeCorrectionPoint>("AmplitudeCorrection");
auto pref = Preferences::getInstance();
if(pref.Startup.UseSetupFile) {
LoadSetup(pref.Startup.SetupFile);
}
// List available devices
UpdateDeviceList();
auto pref = Preferences::getInstance();
if(pref.Startup.ConnectToFirstDevice) {
// at least one device available
ConnectToDevice();
@ -257,9 +252,6 @@ AppWindow::AppWindow(QWidget *parent)
} else {
InformationBox::setGUI(false);
}
if(pref.Startup.UseSetupFile) {
LoadSetup(pref.Startup.SetupFile);
}
}
AppWindow::~AppWindow()
@ -270,6 +262,10 @@ AppWindow::~AppWindow()
void AppWindow::closeEvent(QCloseEvent *event)
{
auto pref = Preferences::getInstance();
if(pref.Startup.UseSetupFile && pref.Startup.AutosaveSetupFile) {
SaveSetup(pref.Startup.SetupFile);
}
vna->shutdown();
generator->shutdown();
spectrumAnalyzer->shutdown();
@ -280,7 +276,7 @@ void AppWindow::closeEvent(QCloseEvent *event)
if(Mode::getActiveMode()) {
Mode::getActiveMode()->deactivate();
}
Preferences::getInstance().store();
pref.store();
QMainWindow::closeEvent(event);
}
@ -926,6 +922,19 @@ void AppWindow::FrequencyCalibrationDialog()
d->exec();
}
void AppWindow::SaveSetup(QString filename)
{
if(!filename.endsWith(".setup")) {
filename.append(".setup");
}
ofstream file;
file.open(filename.toStdString());
file << setw(4) << SaveSetup() << endl;
file.close();
QFileInfo fi(filename);
lSetupName.setText("Setup: "+fi.fileName());
}
nlohmann::json AppWindow::SaveSetup()
{
nlohmann::json j;

View File

@ -61,6 +61,7 @@ private slots:
void ReceiverCalibrationDialog();
void FrequencyCalibrationDialog();
nlohmann::json SaveSetup();
void SaveSetup(QString filename);
void LoadSetup(QString filename);
void LoadSetup(nlohmann::json j);
private:

View File

@ -52,16 +52,19 @@ PreferencesDialog::PreferencesDialog(Preferences *pref, QWidget *parent) :
setDefaultSettingsEnabled(false);
ui->StartupSetupFile->setEnabled(false);
ui->StartupBrowse->setEnabled(false);
ui->StartupStack->setCurrentWidget(ui->StartupPageLastUsed);
});
connect(ui->StartupSweepDefault, &QPushButton::clicked, [=](){
setDefaultSettingsEnabled(true);
ui->StartupSetupFile->setEnabled(false);
ui->StartupBrowse->setEnabled(false);
ui->StartupStack->setCurrentWidget(ui->StartupPageDefaultValues);
});
connect(ui->StartupUseSetupFile, &QPushButton::clicked, [=](){
setDefaultSettingsEnabled(false);
ui->StartupSetupFile->setEnabled(true);
ui->StartupBrowse->setEnabled(true);
ui->StartupStack->setCurrentWidget(ui->StartupPageSetupFile);
});
connect(ui->StartupBrowse, &QPushButton::clicked, [=](){
ui->StartupSetupFile->setText(QFileDialog::getOpenFileName(nullptr, "Select startup setup file", "", "Setup files (*.setup)", nullptr, QFileDialog::DontUseNativeDialog));
@ -203,6 +206,7 @@ void PreferencesDialog::setInitialGUIState()
} else {
ui->StartupSweepDefault->click();
}
ui->StartupAutosaveSetupFile->setChecked(p->Startup.AutosaveSetupFile);
ui->StartupSetupFile->setText(p->Startup.SetupFile);
ui->StartupSweepType->setCurrentText(p->Startup.DefaultSweep.type);
ui->StartupSweepStart->setValueQuiet(p->Startup.DefaultSweep.f_start);
@ -263,6 +267,7 @@ void PreferencesDialog::updateFromGUI()
p->Startup.RememberSweepSettings = ui->StartupSweepLastUsed->isChecked();
p->Startup.UseSetupFile = ui->StartupUseSetupFile->isChecked();
p->Startup.SetupFile = ui->StartupSetupFile->text();
p->Startup.AutosaveSetupFile = ui->StartupAutosaveSetupFile->isChecked();
p->Startup.DefaultSweep.type = ui->StartupSweepType->currentText();
p->Startup.DefaultSweep.f_start = ui->StartupSweepStart->value();
p->Startup.DefaultSweep.f_stop = ui->StartupSweepStop->value();

View File

@ -33,6 +33,7 @@ public:
bool ConnectToFirstDevice;
bool RememberSweepSettings;
bool UseSetupFile;
bool AutosaveSetupFile;
QString SetupFile;
struct {
QString type;
@ -121,6 +122,7 @@ private:
{&Startup.RememberSweepSettings, "Startup.RememberSweepSettings", false},
{&Startup.UseSetupFile, "Startup.UseSetupFile", false},
{&Startup.SetupFile, "Startup.SetupFile", ""},
{&Startup.AutosaveSetupFile, "Startup.AutosaveSetupFile", false},
{&Startup.DefaultSweep.type, "Startup.DefaultSweep.type", "Frequency"},
{&Startup.DefaultSweep.f_start, "Startup.DefaultSweep.start", 1000000.0},
{&Startup.DefaultSweep.f_stop, "Startup.DefaultSweep.stop", 6000000000.0},

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>957</width>
<height>891</height>
<width>936</width>
<height>951</height>
</rect>
</property>
<property name="windowTitle">
@ -112,7 +112,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,0,0,0,0">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,0,0">
<item>
<widget class="QRadioButton" name="StartupSweepLastUsed">
<property name="text">
@ -136,13 +136,83 @@
<item>
<widget class="QRadioButton" name="StartupUseSetupFile">
<property name="text">
<string>Use setup file:</string>
<string>Setup file</string>
</property>
<attribute name="buttonGroup">
<string notr="true">StartupSweepGroup</string>
</attribute>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QStackedWidget" name="StartupStack">
<property name="currentIndex">
<number>2</number>
</property>
<widget class="QWidget" name="StartupPageLastUsed">
<layout class="QVBoxLayout" name="verticalLayout_18">
<item>
<widget class="QLabel" name="label_36">
<property name="text">
<string>The last used sweep settings (e.g. span, bandwidth,...) will be remembered. The graphs, traces and markers will not be remembered and the default configuration for them is used on startup.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="StartupPageSetupFile">
<layout class="QVBoxLayout" name="verticalLayout_17">
<item>
<widget class="QLabel" name="label_38">
<property name="text">
<string>All settings (sweep settings as well as graphs, markers and traces) will be taken from the specified file. If the autosave option is checked, the current state of the GUI is stored in this file during shutdown as well.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="label_35">
<property name="text">
<string>File location:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="StartupSetupFile"/>
</item>
@ -165,22 +235,41 @@
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<widget class="QCheckBox" name="StartupAutosaveSetupFile">
<property name="text">
<string>Autosave to this file on shutdown</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
<width>20</width>
<height>545</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="StartupPageDefaultValues">
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<widget class="QLabel" name="label_37">
<property name="text">
<string>These default values for the sweep settings will be used. The graphs, traces and markers will not be remembered and the default configuration for them is used on startup.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
@ -569,6 +658,10 @@
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">