Skip to content

Commit

Permalink
Import/export options in file menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jankae committed Sep 16, 2024
1 parent 009de1a commit b9e4117
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window, QString name)
window->addDockWidget(Qt::LeftDockWidgetArea, tracesDock);
docks.insert(tracesDock);

auto importAction = new QAction("CSV");
connect(importAction, &QAction::triggered, traceWidget, &TraceWidgetSA::importDialog);
importActions.push_back(importAction);

auto exportAction = new QAction("CSV");
connect(exportAction, &QAction::triggered, traceWidget, &TraceWidgetSA::exportDialog);
exportActions.push_back(exportAction);

auto markerWidget = new MarkerWidget(*markerModel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "mode.h"
#include "CustomWidgets/tilewidget.h"
#include "scpi.h"
#include "Traces/tracewidget.h"
#include "tracewidgetsa.h"

#include <QObject>
#include <QWidget>
Expand Down Expand Up @@ -36,6 +36,9 @@ class SpectrumAnalyzer : public Mode

void preset() override;

QList<QAction*> getImportOptions() override { return importActions;}
QList<QAction*> getExportOptions() override { return exportActions;}

virtual void deviceInfoUpdated() override;

public slots:
Expand Down Expand Up @@ -98,7 +101,7 @@ private slots:

double firstPointTime; // timestamp of the first point in the sweep, only use when zerospan is used
TraceModel traceModel;
TraceWidget *traceWidget;
TraceWidgetSA *traceWidget;
MarkerModel *markerModel;
Averaging average;

Expand All @@ -125,6 +128,10 @@ private slots:
QCheckBox *enable;
} normalize;

// import/export actions
QList<QAction*> importActions;
QList<QAction*> exportActions;

signals:
void dataChanged();
void startFreqChanged(double freq);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TraceWidgetSA : public TraceWidget
{
public:
TraceWidgetSA(TraceModel &model, QWidget *parent = nullptr);
protected slots:
public slots:
virtual void exportDialog() override;
virtual void importDialog() override;

Expand Down
55 changes: 30 additions & 25 deletions Software/PC_Application/LibreVNA-GUI/VNA/tracewidgetvna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,41 @@ TraceWidgetVNA::TraceWidgetVNA(TraceModel &model, Calibration &cal, Deembedding
deembed(deembed)
{
auto exportMenu = new QMenu();
auto exportTouchstone = new QAction("Touchstone");
auto exportCSV = new QAction("CSV");
exportMenu->addAction(exportTouchstone);
exportMenu->addAction(exportCSV);
auto exportTouchstoneAction = new QAction("Touchstone");
auto exportCSVAction = new QAction("CSV");
exportMenu->addAction(exportTouchstoneAction);
exportMenu->addAction(exportCSVAction);

ui->bExport->setMenu(exportMenu);

connect(exportTouchstone, &QAction::triggered, [&]() {
auto e = new TraceTouchstoneExport(model);
// Attempt to set default traces (this will result in correctly populated
// 2 port export if the initial 4 traces have not been modified)
e->setPortNum(2);
auto traces = model.getTraces();
for(unsigned int i=0;i<4;i++) {
if(i >= traces.size()) {
break;
}
e->setTrace(i%2+1, i/2+1, traces[i]);
}
if(AppWindow::showGUI()) {
e->show();
}
});
connect(exportTouchstoneAction, &QAction::triggered, this, &TraceWidgetVNA::exportTouchstone);
connect(exportCSVAction, &QAction::triggered, this, &TraceWidgetVNA::exportCSV);
}

connect(exportCSV, &QAction::triggered, [&]() {
auto e = new TraceCSVExport(model);
if(AppWindow::showGUI()) {
e->show();
void TraceWidgetVNA::exportCSV()
{
auto e = new TraceCSVExport(model);
if(AppWindow::showGUI()) {
e->show();
}
}

void TraceWidgetVNA::exportTouchstone()
{
auto e = new TraceTouchstoneExport(model);
// Attempt to set default traces (this will result in correctly populated
// 2 port export if the initial 4 traces have not been modified)
e->setPortNum(2);
auto traces = model.getTraces();
for(unsigned int i=0;i<4;i++) {
if(i >= traces.size()) {
break;
}
});
e->setTrace(i%2+1, i/2+1, traces[i]);
}
if(AppWindow::showGUI()) {
e->show();
}
}

void TraceWidgetVNA::importDialog()
Expand Down
4 changes: 3 additions & 1 deletion Software/PC_Application/LibreVNA-GUI/VNA/tracewidgetvna.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class TraceWidgetVNA : public TraceWidget
{
public:
TraceWidgetVNA(TraceModel &model, Calibration &cal, Deembedding &deembed, QWidget *parent = nullptr);
protected slots:
public slots:
void exportCSV();
void exportTouchstone();
virtual void exportDialog() override {}
virtual void importDialog() override;

Expand Down
12 changes: 12 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,18 @@ VNA::VNA(AppWindow *window, QString name)
window->addDockWidget(Qt::LeftDockWidgetArea, tracesDock);
docks.insert(tracesDock);

auto importAction = new QAction("Touchstone/CSV");
connect(importAction, &QAction::triggered, traceWidget, &TraceWidgetVNA::importDialog);
importActions.push_back(importAction);

auto exportTouchstone = new QAction("Touchstone");
connect(exportTouchstone, &QAction::triggered, traceWidget, &TraceWidgetVNA::exportTouchstone);
exportActions.push_back(exportTouchstone);

auto exportCSV = new QAction("CSV");
connect(exportCSV, &QAction::triggered, traceWidget, &TraceWidgetVNA::exportCSV);
exportActions.push_back(exportCSV);


auto markerWidget = new MarkerWidget(*markerModel);

Expand Down
11 changes: 9 additions & 2 deletions Software/PC_Application/LibreVNA-GUI/VNA/vna.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "CustomWidgets/tilewidget.h"
#include "Deembedding/deembedding.h"
#include "scpi.h"
#include "Traces/tracewidget.h"
#include "tracewidgetvna.h"
#include "Calibration/calibration.h"

#include <QObject>
Expand Down Expand Up @@ -38,6 +38,9 @@ class VNA : public Mode

void preset() override;

QList<QAction*> getImportOptions() override { return importActions;}
QList<QAction*> getExportOptions() override { return exportActions;}

enum class SweepType {
Frequency = 0,
Power = 1,
Expand Down Expand Up @@ -140,7 +143,7 @@ private slots:
Settings settings;
unsigned int averages;
TraceModel traceModel;
TraceWidget *traceWidget;
TraceWidgetVNA *traceWidget;
MarkerModel *markerModel;
Averaging average;
bool singleSweep;
Expand Down Expand Up @@ -179,6 +182,10 @@ private slots:
TileWidget *tiles;
QScrollArea *central;

// import/export actions
QList<QAction*> importActions;
QList<QAction*> exportActions;

signals:
void deviceInitialized();
void dataChanged();
Expand Down
22 changes: 22 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/appwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ AppWindow::AppWindow(QWidget *parent)
};

connect(modeHandler, &ModeHandler::StatusBarMessageChanged, setModeStatusbar);
connect(modeHandler, &ModeHandler::CurrentModeChanged, this, &AppWindow::UpdateImportExportMenus);

SetupMenu();

Expand Down Expand Up @@ -1384,6 +1385,27 @@ bool AppWindow::LoadSetup(QString filename)
return true;
}

void AppWindow::UpdateImportExportMenus()
{
// clear menus of all actions first
ui->menuImport->clear();
ui->menuExport->clear();

// add action from currently active mode
auto active = modeHandler->getActiveMode();
if(active) {
for(auto a : active->getImportOptions()) {
ui->menuImport->addAction(a);
}
for(auto a : active->getExportOptions()) {
ui->menuExport->addAction(a);
}
}
// disable/enable menus
ui->menuImport->setEnabled(ui->menuImport->actions().size());
ui->menuExport->setEnabled(ui->menuExport->actions().size());
}

void AppWindow::LoadSetup(nlohmann::json j)
{
// auto d = new JSONPickerDialog(j);
Expand Down
1 change: 1 addition & 0 deletions Software/PC_Application/LibreVNA-GUI/appwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private slots:
void DeviceInfoUpdated();
void SaveSetup(QString filename);
bool LoadSetup(QString filename);
void UpdateImportExportMenus();
private:
nlohmann::json SaveSetup();
void LoadSetup(nlohmann::json j);
Expand Down
24 changes: 24 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,23 @@
<property name="title">
<string>File</string>
</property>
<widget class="QMenu" name="menuImport">
<property name="title">
<string>Import</string>
</property>
</widget>
<widget class="QMenu" name="menuExport">
<property name="title">
<string>Export</string>
</property>
</widget>
<addaction name="actionSave_setup"/>
<addaction name="actionLoad_setup"/>
<addaction name="actionSave_image"/>
<addaction name="separator"/>
<addaction name="menuImport"/>
<addaction name="menuExport"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuDevice">
Expand Down Expand Up @@ -232,6 +246,16 @@
<string>Create Debug Data</string>
</property>
</action>
<action name="actiondummy">
<property name="text">
<string>dummy</string>
</property>
</action>
<action name="actionDummy_4">
<property name="text">
<string>Dummy</string>
</property>
</action>
</widget>
<resources>
<include location="icons.qrc"/>
Expand Down
2 changes: 2 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class Mode : public QObject, public Savable, public SCPINode
virtual void setAveragingMode(Averaging::Mode mode) = 0;

virtual void preset() = 0;
virtual QList<QAction*> getImportOptions() { return {};}
virtual QList<QAction*> getExportOptions() { return {};}

signals:
void statusbarMessage(QString msg);
Expand Down

0 comments on commit b9e4117

Please sign in to comment.