minor GUI fixes + preparation for spectrum analyzer export/import

This commit is contained in:
Jan Käberich 2020-11-24 18:08:00 +01:00
parent d63640d437
commit 37bd9a0435
11 changed files with 119 additions and 62 deletions

View File

@ -22,6 +22,7 @@ HEADERS += \
Generator/generator.h \
Generator/signalgenwidget.h \
SpectrumAnalyzer/spectrumanalyzer.h \
SpectrumAnalyzer/tracewidgetsa.h \
Tools/eseries.h \
Tools/impedancematchdialog.h \
Traces/fftcomplex.h \
@ -41,6 +42,7 @@ HEADERS += \
Util/qpointervariant.h \
Util/util.h \
VNA/portextension.h \
VNA/tracewidgetvna.h \
VNA/vna.h \
appwindow.h \
averaging.h \
@ -72,6 +74,7 @@ SOURCES += \
Generator/generator.cpp \
Generator/signalgenwidget.cpp \
SpectrumAnalyzer/spectrumanalyzer.cpp \
SpectrumAnalyzer/tracewidgetsa.cpp \
Tools/eseries.cpp \
Tools/impedancematchdialog.cpp \
Traces/fftcomplex.cpp \
@ -89,6 +92,7 @@ SOURCES += \
Traces/tracexyplot.cpp \
Traces/xyplotaxisdialog.cpp \
VNA/portextension.cpp \
VNA/tracewidgetvna.cpp \
VNA/vna.cpp \
appwindow.cpp \
averaging.cpp \

View File

@ -23,7 +23,7 @@
#include "CustomWidgets/toggleswitch.h"
#include "Device/manualcontroldialog.h"
#include "Traces/tracemodel.h"
#include "Traces/tracewidget.h"
#include "tracewidgetsa.h"
#include "Traces/tracesmithchart.h"
#include "Traces/tracexyplot.h"
#include "Traces/traceimportdialog.h"
@ -242,7 +242,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
markerModel = new TraceMarkerModel(traceModel, this);
auto tracesDock = new QDockWidget("Traces");
tracesDock->setWidget(new TraceWidget(traceModel, window, true));
tracesDock->setWidget(new TraceWidgetSA(traceModel, window));
window->addDockWidget(Qt::LeftDockWidgetArea, tracesDock);
docks.insert(tracesDock);

View File

@ -0,0 +1,7 @@
#include "tracewidgetsa.h"
TraceWidgetSA::TraceWidgetSA(TraceModel &model, QWidget *parent)
: TraceWidget(model, parent)
{
}

View File

@ -0,0 +1,18 @@
#ifndef TRACEWIDGETSA_H
#define TRACEWIDGETSA_H
#include "Traces/tracewidget.h"
class TraceWidgetSA : public TraceWidget
{
public:
TraceWidgetSA(TraceModel &model, QWidget *parent = nullptr);
protected slots:
virtual void exportDialog() override {};
virtual void importDialog() override {};
protected:
virtual Trace::LiveParameter defaultParameter() override {return Trace::LiveParameter::Port1;};
};
#endif // TRACEWIDGETSA_H

View File

@ -99,6 +99,7 @@ void TracePlot::contextMenuEvent(QContextMenuEvent *event)
void TracePlot::paintEvent(QPaintEvent *event)
{
auto pref = Preferences::getInstance();
QPainter p(this);
// p.setRenderHint(QPainter::Antialiasing);

View File

@ -10,16 +10,17 @@
#include <QMimeData>
#include <QDebug>
TraceWidget::TraceWidget(TraceModel &model, QWidget *parent, bool SA) :
TraceWidget::TraceWidget(TraceModel &model, QWidget *parent) :
QWidget(parent),
ui(new Ui::TraceWidget),
model(model),
SA(SA)
model(model)
{
ui->setupUi(this);
ui->view->setModel(&model);
ui->view->setAutoScroll(false);
ui->view->viewport()->installEventFilter(this);
connect(ui->bImport, &QPushButton::clicked, this, &TraceWidget::importDialog);
connect(ui->bExport, &QPushButton::clicked, this, &TraceWidget::exportDialog);
installEventFilter(this);
createCount = 0;
}
@ -32,8 +33,7 @@ TraceWidget::~TraceWidget()
void TraceWidget::on_add_clicked()
{
createCount++;
auto liveParam = SA ? Trace::LiveParameter::Port1 : Trace::LiveParameter::S11;
auto t = new Trace("Trace #"+QString::number(createCount), Qt::darkYellow, liveParam);
auto t = new Trace("Trace #"+QString::number(createCount), Qt::darkYellow, defaultParameter());
t->setColor(QColor::fromHsl((createCount * 50) % 360, 250, 128));
model.addTrace(t);
}
@ -123,46 +123,3 @@ void TraceWidget::on_view_clicked(const QModelIndex &index)
model.togglePause(index.row());
}
}
void TraceWidget::on_bImport_clicked()
{
auto filename = QFileDialog::getOpenFileName(nullptr, "Open measurement file", "", "Touchstone files (*.s1p *.s2p *.s3p *.s4p)", nullptr, QFileDialog::DontUseNativeDialog);
if (filename.length() > 0) {
auto t = Touchstone::fromFile(filename.toStdString());
std::vector<Trace*> traces;
for(unsigned int i=0;i<t.ports()*t.ports();i++) {
auto trace = new Trace();
trace->fillFromTouchstone(t, i, filename);
unsigned int sink = i / t.ports() + 1;
unsigned int source = i % t.ports() + 1;
trace->setName("S"+QString::number(sink)+QString::number(source));
traces.push_back(trace);
}
// contruct prefix from filename
// remove any directory names (keep only the filename itself)
int lastSlash = qMax(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));
if(lastSlash != -1) {
filename.remove(0, lastSlash + 1);
}
// remove file type
filename.truncate(filename.indexOf('.'));
auto i = new TraceImportDialog(model, traces, filename+"_");
i->show();
}
}
void TraceWidget::on_bExport_clicked()
{
auto e = new TraceExportDialog(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, i/2, traces[i]);
}
e->show();
}

View File

@ -13,28 +13,26 @@ class TraceWidget : public QWidget
Q_OBJECT
public:
explicit TraceWidget(TraceModel &model, QWidget *parent = nullptr, bool SA = false);
explicit TraceWidget(TraceModel &model, QWidget *parent = nullptr);
~TraceWidget();
public slots:
protected slots:
void on_add_clicked();
private slots:
void on_remove_clicked();
void on_edit_clicked();
void on_view_doubleClicked(const QModelIndex &index);
void on_view_clicked(const QModelIndex &index);
void on_bImport_clicked();
void on_bExport_clicked();
virtual void exportDialog() = 0;
virtual void importDialog() = 0;
private:
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
virtual Trace::LiveParameter defaultParameter() = 0;
QPoint dragStartPosition;
Trace *dragTrace;
Ui::TraceWidget *ui;
TraceModel &model;
int createCount;
bool SA;
};
#endif // TRACEWIDGET_H

View File

@ -0,0 +1,54 @@
#include "tracewidgetvna.h"
#include <QFileDialog>
#include "Traces/traceimportdialog.h"
#include "Traces/traceexportdialog.h"
TraceWidgetVNA::TraceWidgetVNA(TraceModel &model, QWidget *parent)
: TraceWidget(model, parent)
{
}
void TraceWidgetVNA::exportDialog()
{
auto e = new TraceExportDialog(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, i/2, traces[i]);
}
e->show();
}
void TraceWidgetVNA::importDialog()
{
auto filename = QFileDialog::getOpenFileName(nullptr, "Open measurement file", "", "Touchstone files (*.s1p *.s2p *.s3p *.s4p)", nullptr, QFileDialog::DontUseNativeDialog);
if (filename.length() > 0) {
auto t = Touchstone::fromFile(filename.toStdString());
std::vector<Trace*> traces;
for(unsigned int i=0;i<t.ports()*t.ports();i++) {
auto trace = new Trace();
trace->fillFromTouchstone(t, i, filename);
unsigned int sink = i / t.ports() + 1;
unsigned int source = i % t.ports() + 1;
trace->setName("S"+QString::number(sink)+QString::number(source));
traces.push_back(trace);
}
// contruct prefix from filename
// remove any directory names (keep only the filename itself)
int lastSlash = qMax(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));
if(lastSlash != -1) {
filename.remove(0, lastSlash + 1);
}
// remove file type
filename.truncate(filename.indexOf('.'));
auto i = new TraceImportDialog(model, traces, filename+"_");
i->show();
}
}

View File

@ -0,0 +1,18 @@
#ifndef TRACEWIDGETVNA_H
#define TRACEWIDGETVNA_H
#include "Traces/tracewidget.h"
class TraceWidgetVNA : public TraceWidget
{
public:
TraceWidgetVNA(TraceModel &model, QWidget *parent = nullptr);
protected slots:
virtual void exportDialog() override;
virtual void importDialog() override;
protected:
virtual Trace::LiveParameter defaultParameter() override {return Trace::LiveParameter::S11;};
};
#endif // TRACEWIDGETVNA_H

View File

@ -24,7 +24,7 @@
#include "CustomWidgets/toggleswitch.h"
#include "Device/manualcontroldialog.h"
#include "Traces/tracemodel.h"
#include "Traces/tracewidget.h"
#include "tracewidgetvna.h"
#include "Traces/tracesmithchart.h"
#include "Traces/tracexyplot.h"
#include "Traces/traceimportdialog.h"
@ -352,7 +352,7 @@ VNA::VNA(AppWindow *window)
markerModel = new TraceMarkerModel(traceModel, this);
auto tracesDock = new QDockWidget("Traces");
tracesDock->setWidget(new TraceWidget(traceModel));
tracesDock->setWidget(new TraceWidgetVNA(traceModel));
window->addDockWidget(Qt::LeftDockWidgetArea, tracesDock);
docks.insert(tracesDock);

View File

@ -18,7 +18,7 @@ Mode::Mode(AppWindow *window, QString name)
// Create mode switch button
auto modeSwitch = new QPushButton(name);
modeSwitch->setCheckable(true);
modeSwitch->setMaximumHeight(window->getUi()->menubar->height());
modeSwitch->setMaximumHeight(window->menuBar()->height());
if(!cornerWidget) {
// this is the first created mode, initialize corner widget and set this mode as active
modeSwitch->setChecked(true);
@ -29,7 +29,7 @@ Mode::Mode(AppWindow *window, QString name)
cornerWidget->layout()->setContentsMargins(0,0,0,0);
window->menuBar()->setCornerWidget(cornerWidget);
modeButtonGroup = new QButtonGroup;
window->getUi()->menubar->setMaximumHeight(window->getUi()->menubar->height());
// window->menuBar()->setMaximumHeight(window->menuBar()->height());
}
cornerWidget->layout()->addWidget(modeSwitch);
modeButtonGroup->addButton(modeSwitch);