mirror of
https://github.com/jankae/LibreVNA.git
synced 2025-12-06 07:12:10 +01:00
WIP: save view configuration separately
This commit is contained in:
parent
b09ea7da44
commit
668f050988
|
|
@ -52,6 +52,7 @@
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
VNA::VNA(AppWindow *window, QString name)
|
VNA::VNA(AppWindow *window, QString name)
|
||||||
: Mode(window, name, "VNA"),
|
: Mode(window, name, "VNA"),
|
||||||
|
|
@ -1749,6 +1750,60 @@ void VNA::preset()
|
||||||
createDefaultTracesAndGraphs(DeviceDriver::getInfo(window->getDevice()).Limits.VNA.ports);
|
createDefaultTracesAndGraphs(DeviceDriver::getInfo(window->getDevice()).Limits.VNA.ports);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VNA::saveView()
|
||||||
|
{
|
||||||
|
auto filename = QFileDialog::getSaveFileName(nullptr, "Save VNA view data", "", "VNA view files (*.vnaview)", nullptr, QFileDialog::DontUseNativeDialog);
|
||||||
|
if(filename.isEmpty()) {
|
||||||
|
// aborted selection
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nlohmann::json j;
|
||||||
|
// only save data relevant to the view
|
||||||
|
// j["traces"] = traceModel.toJSON();
|
||||||
|
j["tiles"] = tiles->toJSON();
|
||||||
|
// j["markers"] = markerModel->toJSON();
|
||||||
|
|
||||||
|
if(filename.toLower().endsWith(".vnaview")) {
|
||||||
|
filename.chop(8);
|
||||||
|
}
|
||||||
|
filename.append(".vnaview");
|
||||||
|
ofstream file;
|
||||||
|
file.open(filename.toStdString());
|
||||||
|
file << setw(1) << toJSON();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VNA::loadView()
|
||||||
|
{
|
||||||
|
auto filename = QFileDialog::getOpenFileName(nullptr, "Load VNA view data", "", "VNA view files (*.vnaview)", nullptr, QFileDialog::DontUseNativeDialog);
|
||||||
|
if(filename.isEmpty()) {
|
||||||
|
// aborted selection
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ifstream file;
|
||||||
|
|
||||||
|
file.open(filename.toStdString());
|
||||||
|
if(!file.good()) {
|
||||||
|
QString msg = "Unable to open file: "+filename;
|
||||||
|
InformationBox::ShowError("Error", msg);
|
||||||
|
qWarning() << msg;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
nlohmann::json j;
|
||||||
|
file >> j;
|
||||||
|
if(j.contains("tiles")) {
|
||||||
|
tiles->fromJSON(j["tiles"]);
|
||||||
|
}
|
||||||
|
} catch(exception &e) {
|
||||||
|
InformationBox::ShowError("File parsing error", e.what());
|
||||||
|
qWarning() << "View file parsing failed: " << e.what();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
QString VNA::SweepTypeToString(VNA::SweepType sw)
|
QString VNA::SweepTypeToString(VNA::SweepType sw)
|
||||||
{
|
{
|
||||||
switch(sw) {
|
switch(sw) {
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ public:
|
||||||
void setAveragingMode(Averaging::Mode mode) override;
|
void setAveragingMode(Averaging::Mode mode) override;
|
||||||
|
|
||||||
void preset() override;
|
void preset() override;
|
||||||
|
void saveView() override;
|
||||||
|
void loadView() override;
|
||||||
|
|
||||||
enum class SweepType {
|
enum class SweepType {
|
||||||
Frequency = 0,
|
Frequency = 0,
|
||||||
|
|
|
||||||
|
|
@ -251,6 +251,14 @@ void AppWindow::SetupMenu()
|
||||||
modeHandler->getActiveMode()->preset();
|
modeHandler->getActiveMode()->preset();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(ui->actionSave, &QAction::triggered, [=](){
|
||||||
|
modeHandler->getActiveMode()->saveView();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(ui->actionLoad, &QAction::triggered, [=](){
|
||||||
|
modeHandler->getActiveMode()->loadView();
|
||||||
|
});
|
||||||
|
|
||||||
connect(ui->actionPreferences, &QAction::triggered, [=](){
|
connect(ui->actionPreferences, &QAction::triggered, [=](){
|
||||||
// save previous SCPI settings in case they change
|
// save previous SCPI settings in case they change
|
||||||
auto &p = Preferences::getInstance();
|
auto &p = Preferences::getInstance();
|
||||||
|
|
@ -392,7 +400,7 @@ bool AppWindow::ConnectToDevice(QString serial, DeviceDriver *driver)
|
||||||
// ui->actionReceiver_Calibration->setEnabled(true);
|
// ui->actionReceiver_Calibration->setEnabled(true);
|
||||||
// ui->actionFrequency_Calibration->setEnabled(true);
|
// ui->actionFrequency_Calibration->setEnabled(true);
|
||||||
// }
|
// }
|
||||||
ui->actionPreset->setEnabled(true);
|
// ui->actionPreset->setEnabled(true);
|
||||||
|
|
||||||
DeviceEntry e;
|
DeviceEntry e;
|
||||||
e.serial = device->getSerial();
|
e.serial = device->getSerial();
|
||||||
|
|
@ -438,7 +446,7 @@ void AppWindow::DisconnectDevice()
|
||||||
ui->actionSource_Calibration->setEnabled(false);
|
ui->actionSource_Calibration->setEnabled(false);
|
||||||
ui->actionReceiver_Calibration->setEnabled(false);
|
ui->actionReceiver_Calibration->setEnabled(false);
|
||||||
ui->actionFrequency_Calibration->setEnabled(false);
|
ui->actionFrequency_Calibration->setEnabled(false);
|
||||||
ui->actionPreset->setEnabled(false);
|
// ui->actionPreset->setEnabled(false);
|
||||||
for(auto a : deviceActionGroup->actions()) {
|
for(auto a : deviceActionGroup->actions()) {
|
||||||
a->setChecked(false);
|
a->setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,8 @@
|
||||||
<string>View</string>
|
<string>View</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionPreset"/>
|
<addaction name="actionPreset"/>
|
||||||
|
<addaction name="actionSave"/>
|
||||||
|
<addaction name="actionLoad"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
<addaction name="menuDevice"/>
|
<addaction name="menuDevice"/>
|
||||||
|
|
@ -213,7 +215,7 @@
|
||||||
</action>
|
</action>
|
||||||
<action name="actionPreset">
|
<action name="actionPreset">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Preset</string>
|
<string>Preset</string>
|
||||||
|
|
@ -232,6 +234,16 @@
|
||||||
<string>Create Debug Data</string>
|
<string>Create Debug Data</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionSave">
|
||||||
|
<property name="text">
|
||||||
|
<string>Save Graphs</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionLoad">
|
||||||
|
<property name="text">
|
||||||
|
<string>Load Graphs</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="icons.qrc"/>
|
<include location="icons.qrc"/>
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ public:
|
||||||
virtual void setAveragingMode(Averaging::Mode mode) = 0;
|
virtual void setAveragingMode(Averaging::Mode mode) = 0;
|
||||||
|
|
||||||
virtual void preset() = 0;
|
virtual void preset() = 0;
|
||||||
|
virtual void saveView() {};
|
||||||
|
virtual void loadView() {};
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void statusbarMessage(QString msg);
|
void statusbarMessage(QString msg);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue