mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-05 22:45:23 +00:00
Save/load trace and graph setup
This commit is contained in:
parent
b91f431473
commit
9ad8def2ea
33 changed files with 605 additions and 28 deletions
|
|
@ -28,6 +28,73 @@ TileWidget::~TileWidget()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void TileWidget::clear()
|
||||
{
|
||||
if(hasContent) {
|
||||
delete content;
|
||||
hasContent = false;
|
||||
}
|
||||
if(isSplit) {
|
||||
delete child1;
|
||||
delete child2;
|
||||
isSplit = false;
|
||||
delete splitter;
|
||||
}
|
||||
}
|
||||
|
||||
nlohmann::json TileWidget::toJSON()
|
||||
{
|
||||
nlohmann::json j;
|
||||
j["split"] = isSplit;
|
||||
if(isSplit) {
|
||||
j["orientation"] = splitter->orientation() == Qt::Horizontal ? "horizontal" : "vertical";
|
||||
j["sizes"] = splitter->sizes();
|
||||
j["tile1"] = child1->toJSON();
|
||||
j["tile2"] = child2->toJSON();
|
||||
}
|
||||
if(hasContent) {
|
||||
std::string plotname;
|
||||
switch(content->getType()) {
|
||||
case TracePlot::Type::SmithChart:
|
||||
plotname = "smithchart";
|
||||
break;
|
||||
case TracePlot::Type::XYPlot:
|
||||
plotname = "XY-plot";
|
||||
break;
|
||||
}
|
||||
j["plot"] = plotname;
|
||||
j["plotsettings"] = content->toJSON();
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
void TileWidget::fromJSON(nlohmann::json j)
|
||||
{
|
||||
// delete all childs before parsing json
|
||||
clear();
|
||||
bool split = j.value("split", false);
|
||||
if(split) {
|
||||
if(j["orientation"] == "horizontal") {
|
||||
splitHorizontally();
|
||||
} else {
|
||||
splitVertically();
|
||||
}
|
||||
splitter->setSizes(j["sizes"]);
|
||||
child1->fromJSON(j["tile1"]);
|
||||
child2->fromJSON(j["tile2"]);
|
||||
} else if(j.contains("plot")) {
|
||||
// has a plot enabled
|
||||
auto plotname = j["plot"];
|
||||
if(plotname == "smithchart") {
|
||||
content = new TraceSmithChart(model);
|
||||
} else {
|
||||
content = new TraceXYPlot(model);
|
||||
}
|
||||
setContent(content);
|
||||
content->fromJSON(j["plotsettings"]);
|
||||
}
|
||||
}
|
||||
|
||||
void TileWidget::splitVertically()
|
||||
{
|
||||
if(isSplit) {
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@
|
|||
#include "Traces/traceplot.h"
|
||||
#include <QSplitter>
|
||||
#include "Traces/tracemodel.h"
|
||||
#include "savable.h"
|
||||
|
||||
namespace Ui {
|
||||
class TileWidget;
|
||||
}
|
||||
|
||||
class TileWidget : public QWidget
|
||||
class TileWidget : public QWidget, public Savable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
|
@ -20,6 +21,12 @@ public:
|
|||
|
||||
TileWidget *Child1() { return child1; };
|
||||
TileWidget *Child2() { return child2; };
|
||||
|
||||
// closes all plots/childs, leaving only the tilewidget at the top
|
||||
void clear();
|
||||
|
||||
virtual nlohmann::json toJSON() override;
|
||||
virtual void fromJSON(nlohmann::json j) override;
|
||||
public slots:
|
||||
void splitVertically();
|
||||
void splitHorizontally();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue