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 // aborted selection
return; return;
} }
ifstream file; LoadSetup(filename);
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());
}); });
connect(ui->actionSave_image, &QAction::triggered, [=](){ connect(ui->actionSave_image, &QAction::triggered, [=](){
Mode::getActiveMode()->saveSreenshot(); Mode::getActiveMode()->saveSreenshot();
@ -261,7 +245,8 @@ AppWindow::AppWindow(QWidget *parent)
// List available devices // List available devices
UpdateDeviceList(); UpdateDeviceList();
if(Preferences::getInstance().Startup.ConnectToFirstDevice) { auto pref = Preferences::getInstance();
if(pref.Startup.ConnectToFirstDevice) {
// at least one device available // at least one device available
ConnectToDevice(); ConnectToDevice();
} }
@ -272,6 +257,9 @@ AppWindow::AppWindow(QWidget *parent)
} else { } else {
InformationBox::setGUI(false); InformationBox::setGUI(false);
} }
if(pref.Startup.UseSetupFile) {
LoadSetup(pref.Startup.SetupFile);
}
} }
AppWindow::~AppWindow() AppWindow::~AppWindow()
@ -948,6 +936,27 @@ nlohmann::json AppWindow::SaveSetup()
return j; 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) void AppWindow::LoadSetup(nlohmann::json j)
{ {
// auto d = new JSONPickerDialog(j); // auto d = new JSONPickerDialog(j);

View File

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

View File

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

View File

@ -32,6 +32,8 @@ public:
struct { struct {
bool ConnectToFirstDevice; bool ConnectToFirstDevice;
bool RememberSweepSettings; bool RememberSweepSettings;
bool UseSetupFile;
QString SetupFile;
struct { struct {
QString type; QString type;
double f_start; double f_start;
@ -117,6 +119,8 @@ private:
const std::vector<Savable::SettingDescription> descr = {{ const std::vector<Savable::SettingDescription> descr = {{
{&Startup.ConnectToFirstDevice, "Startup.ConnectToFirstDevice", true}, {&Startup.ConnectToFirstDevice, "Startup.ConnectToFirstDevice", true},
{&Startup.RememberSweepSettings, "Startup.RememberSweepSettings", false}, {&Startup.RememberSweepSettings, "Startup.RememberSweepSettings", false},
{&Startup.UseSetupFile, "Startup.UseSetupFile", false},
{&Startup.SetupFile, "Startup.SetupFile", ""},
{&Startup.DefaultSweep.type, "Startup.DefaultSweep.type", "Frequency"}, {&Startup.DefaultSweep.type, "Startup.DefaultSweep.type", "Frequency"},
{&Startup.DefaultSweep.f_start, "Startup.DefaultSweep.start", 1000000.0}, {&Startup.DefaultSweep.f_start, "Startup.DefaultSweep.start", 1000000.0},
{&Startup.DefaultSweep.f_stop, "Startup.DefaultSweep.stop", 6000000000.0}, {&Startup.DefaultSweep.f_stop, "Startup.DefaultSweep.stop", 6000000000.0},

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>919</width> <width>957</width>
<height>876</height> <height>891</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -83,7 +83,7 @@
</size> </size>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="Startup"> <widget class="QWidget" name="Startup">
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
@ -112,7 +112,7 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,0,0,0,0">
<item> <item>
<widget class="QRadioButton" name="StartupSweepLastUsed"> <widget class="QRadioButton" name="StartupSweepLastUsed">
<property name="text"> <property name="text">
@ -133,6 +133,38 @@
</attribute> </attribute>
</widget> </widget>
</item> </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> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">