Add setup file as default startup configuration

This commit is contained in:
Jan Käberich 2022-01-29 23:31:58 +01:00
parent 3afbf42791
commit b2ed124240
5 changed files with 85 additions and 22 deletions

View File

@ -160,23 +160,7 @@ AppWindow::AppWindow(QWidget *parent)
// aborted selection
return;
}
ifstream file;
file.open(filename.toStdString());
if(!file.is_open()) {
qWarning() << "Unable to open file:" << filename;
return;
}
nlohmann::json j;
try {
file >> j;
} catch (exception &e) {
InformationBox::ShowError("Error", "Failed to parse the setup file (" + QString(e.what()) + ")");
qWarning() << "Parsing of setup file failed: " << e.what();
}
file.close();
LoadSetup(j);
QFileInfo fi(filename);
lSetupName.setText("Setup: "+fi.fileName());
LoadSetup(filename);
});
connect(ui->actionSave_image, &QAction::triggered, [=](){
Mode::getActiveMode()->saveSreenshot();
@ -261,7 +245,8 @@ AppWindow::AppWindow(QWidget *parent)
// List available devices
UpdateDeviceList();
if(Preferences::getInstance().Startup.ConnectToFirstDevice) {
auto pref = Preferences::getInstance();
if(pref.Startup.ConnectToFirstDevice) {
// at least one device available
ConnectToDevice();
}
@ -272,6 +257,9 @@ AppWindow::AppWindow(QWidget *parent)
} else {
InformationBox::setGUI(false);
}
if(pref.Startup.UseSetupFile) {
LoadSetup(pref.Startup.SetupFile);
}
}
AppWindow::~AppWindow()
@ -948,6 +936,27 @@ nlohmann::json AppWindow::SaveSetup()
return j;
}
void AppWindow::LoadSetup(QString filename)
{
ifstream file;
file.open(filename.toStdString());
if(!file.is_open()) {
qWarning() << "Unable to open file:" << filename;
return;
}
nlohmann::json j;
try {
file >> j;
} catch (exception &e) {
InformationBox::ShowError("Error", "Failed to parse the setup file (" + QString(e.what()) + ")");
qWarning() << "Parsing of setup file failed: " << e.what();
}
file.close();
LoadSetup(j);
QFileInfo fi(filename);
lSetupName.setText("Setup: "+fi.fileName());
}
void AppWindow::LoadSetup(nlohmann::json j)
{
// auto d = new JSONPickerDialog(j);

View File

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

View File

@ -50,9 +50,21 @@ PreferencesDialog::PreferencesDialog(Preferences *pref, QWidget *parent) :
// Startup page
connect(ui->StartupSweepLastUsed, &QPushButton::clicked, [=](){
setDefaultSettingsEnabled(false);
ui->StartupSetupFile->setEnabled(false);
ui->StartupBrowse->setEnabled(false);
});
connect(ui->StartupSweepDefault, &QPushButton::clicked, [=](){
setDefaultSettingsEnabled(true);
ui->StartupSetupFile->setEnabled(false);
ui->StartupBrowse->setEnabled(false);
});
connect(ui->StartupUseSetupFile, &QPushButton::clicked, [=](){
setDefaultSettingsEnabled(false);
ui->StartupSetupFile->setEnabled(true);
ui->StartupBrowse->setEnabled(true);
});
connect(ui->StartupBrowse, &QPushButton::clicked, [=](){
ui->StartupSetupFile->setText(QFileDialog::getOpenFileName(nullptr, "Select startup setup file", "", "Setup files (*.setup)", nullptr, QFileDialog::DontUseNativeDialog));
});
ui->StartupSweepStart->setUnit("Hz");
ui->StartupSweepStart->setPrefixes(" kMG");
@ -186,9 +198,12 @@ void PreferencesDialog::setInitialGUIState()
ui->StartupAutoconnect->setChecked(p->Startup.ConnectToFirstDevice);
if(p->Startup.RememberSweepSettings) {
ui->StartupSweepLastUsed->click();
} if(p->Startup.UseSetupFile) {
ui->StartupUseSetupFile->click();
} else {
ui->StartupSweepDefault->click();
}
ui->StartupSetupFile->setText(p->Startup.SetupFile);
ui->StartupSweepType->setCurrentText(p->Startup.DefaultSweep.type);
ui->StartupSweepStart->setValueQuiet(p->Startup.DefaultSweep.f_start);
ui->StartupSweepStop->setValueQuiet(p->Startup.DefaultSweep.f_stop);
@ -246,6 +261,8 @@ void PreferencesDialog::updateFromGUI()
{
p->Startup.ConnectToFirstDevice = ui->StartupAutoconnect->isChecked();
p->Startup.RememberSweepSettings = ui->StartupSweepLastUsed->isChecked();
p->Startup.UseSetupFile = ui->StartupUseSetupFile->isChecked();
p->Startup.SetupFile = ui->StartupSetupFile->text();
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

@ -32,6 +32,8 @@ public:
struct {
bool ConnectToFirstDevice;
bool RememberSweepSettings;
bool UseSetupFile;
QString SetupFile;
struct {
QString type;
double f_start;
@ -117,6 +119,8 @@ private:
const std::vector<Savable::SettingDescription> descr = {{
{&Startup.ConnectToFirstDevice, "Startup.ConnectToFirstDevice", true},
{&Startup.RememberSweepSettings, "Startup.RememberSweepSettings", false},
{&Startup.UseSetupFile, "Startup.UseSetupFile", false},
{&Startup.SetupFile, "Startup.SetupFile", ""},
{&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>919</width>
<height>876</height>
<width>957</width>
<height>891</height>
</rect>
</property>
<property name="windowTitle">
@ -83,7 +83,7 @@
</size>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="Startup">
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -112,7 +112,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,0,0,0,0">
<item>
<widget class="QRadioButton" name="StartupSweepLastUsed">
<property name="text">
@ -133,6 +133,38 @@
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="StartupUseSetupFile">
<property name="text">
<string>Use setup file:</string>
</property>
<attribute name="buttonGroup">
<string notr="true">StartupSweepGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QLineEdit" name="StartupSetupFile"/>
</item>
<item>
<widget class="QPushButton" name="StartupBrowse">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>20</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">