Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jankae/LibreVNA
Browse files Browse the repository at this point in the history
  • Loading branch information
jankae committed Jul 17, 2022
2 parents d516d1a + 32164dd commit 787f0d0
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Edit line</string>
</property>
<property name="modal">
<bool>true</bool>
Expand Down
83 changes: 76 additions & 7 deletions Software/PC_Application/Traces/xyplotaxisdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
#include "ui_xyplotaxisdialog.h"
#include "traceaxis.h"

#include <QFileDialog>
#include <QStandardItemModel>
#include <fstream>
#include <iomanip>

#include <CustomWidgets/informationbox.h>

using namespace std;

Expand Down Expand Up @@ -183,16 +188,68 @@ XYplotAxisDialog::XYplotAxisDialog(TraceXYPlot *plot) :
ui->removeLine->setEnabled(true);
editLine(line);
connect(line, &XYPlotConstantLine::editingFinished, [=](){
item->setText(line->getDescription());
if(line->getPoints().size() < 2) { // must have 2 points to be a line
int index = ui->lineList->currentRow();
removeLine(index);
} else {
item->setText(line->getDescription());
}
});
});
connect(ui->removeLine, &QPushButton::clicked, [=](){
auto index = ui->lineList->currentRow();
delete ui->lineList->takeItem(index);
delete plot->constantLines[index];
plot->constantLines.erase(plot->constantLines.begin() + index);
if(plot->constantLines.size() == 0) {
ui->removeLine->setEnabled(false);
int index = ui->lineList->currentRow();
removeLine(index);
});
connect(ui->exportLines, &QPushButton::clicked, [=](){
QString filename = QFileDialog::getSaveFileName(nullptr, "Save limit lines", "", "Limit files (*.limits)", nullptr, QFileDialog::DontUseNativeDialog);
if(filename.isEmpty()) {
// aborted selection
return;
}
if(!filename.endsWith(".limits")) {
filename.append(".limits");
}

nlohmann::json jlines;
for(auto l : plot->constantLines ) {
jlines.push_back(l->toJSON());
}
nlohmann::json j;
j["limitLines"] = jlines;

ofstream file;
file.open(filename.toStdString());
file << setw(4) << j << endl;
file.close();

});
connect(ui->importLines, &QPushButton::clicked, [=](){
QString filename = QFileDialog::getOpenFileName(nullptr, "Load limit lines", "", "Limit files (*.limits)", nullptr, QFileDialog::DontUseNativeDialog);
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 file (" + QString(e.what()) + ")");
qWarning() << "Parsing of limits file failed: " << e.what();
file.close();
return;
}
file.close();
if(j.contains("limitLines")) {
for(auto jline : j["limitLines"]) {
auto line = new XYPlotConstantLine;
line->fromJSON(jline);
plot->constantLines.push_back(line);
auto item = new QListWidgetItem(line->getDescription());
ui->lineList->addItem(item);

}
}
});

Expand Down Expand Up @@ -276,3 +333,15 @@ bool XYplotAxisDialog::isSupported(XAxis::Type type)
{
return XAxis::isSupported(type, plot->getModel().getSource());
}

void XYplotAxisDialog::removeLine(int index) {
if (index < 0) {
return;
}
delete ui->lineList->takeItem(index);
delete plot->constantLines[index];
plot->constantLines.erase(plot->constantLines.begin() + index);
if(plot->constantLines.size() == 0) {
ui->removeLine->setEnabled(false);
}
}
1 change: 1 addition & 0 deletions Software/PC_Application/Traces/xyplotaxisdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private slots:
bool isSupported(XAxis::Type type);
Ui::XYplotAxisDialog *ui;
TraceXYPlot *plot;
void removeLine(int index);
};

#endif // XYPLOTAXISDIALOG_H
30 changes: 29 additions & 1 deletion Software/PC_Application/Traces/xyplotaxisdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,34 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="exportLines">
<property name="toolTip">
<string>Export</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/export.png</normaloff>:/icons/export.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="importLines">
<property name="toolTip">
<string>Import</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/import.png</normaloff>:/icons/import.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -564,8 +592,8 @@
</connection>
</connections>
<buttongroups>
<buttongroup name="Y2group"/>
<buttongroup name="Y1group"/>
<buttongroup name="Xgroup"/>
<buttongroup name="Y2group"/>
</buttongroups>
</ui>
106 changes: 55 additions & 51 deletions Software/PC_Application/appwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,58 @@ AppWindow::AppWindow(QWidget *parent)

connect(modeHandler, &ModeHandler::StatusBarMessageChanged, setModeStatusbar);

SetupMenu();

setWindowTitle(qlibrevnaApp->applicationName() + " v" + getAppVersion());

setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);

{
QSettings settings;
restoreGeometry(settings.value("geometry").toByteArray());
}

SetupSCPI();

auto pref = Preferences::getInstance();
if(pref.Startup.UseSetupFile) {
LoadSetup(pref.Startup.SetupFile);
}
// List available devices
UpdateDeviceList();
if(pref.Startup.ConnectToFirstDevice) {
// at least one device available
ConnectToDevice();
}

if(parser.isSet("setup")) {
LoadSetup(parser.value("setup"));
}
if(parser.isSet("cal")) {
VNA* mode = static_cast<VNA*>(modeHandler->findFirstOfType(Mode::Type::VNA));
mode->LoadCalibration(parser.value("cal"));
}
if(!parser.isSet("no-gui")) {
InformationBox::setGUI(true);
resize(1280, 800);
show();
} else {
InformationBox::setGUI(false);
noGUIset = true;
}
}

AppWindow::~AppWindow()
{
StopTCPServer();
delete ui;
}

void AppWindow::SetupMenu()
{
// UI connections
connect(ui->actionUpdate_Device_List, &QAction::triggered, this, &AppWindow::UpdateDeviceList);
connect(ui->actionDisconnect, &QAction::triggered, this, &AppWindow::DisconnectDevice);
Expand Down Expand Up @@ -329,53 +381,6 @@ AppWindow::AppWindow(QWidget *parent)
auto &a = About::getInstance();
a.about();
});

setWindowTitle(qlibrevnaApp->applicationName() + " v" + getAppVersion());

setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);

{
QSettings settings;
restoreGeometry(settings.value("geometry").toByteArray());
}

SetupSCPI();

auto pref = Preferences::getInstance();
if(pref.Startup.UseSetupFile) {
LoadSetup(pref.Startup.SetupFile);
}
// List available devices
UpdateDeviceList();
if(pref.Startup.ConnectToFirstDevice) {
// at least one device available
ConnectToDevice();
}

if(parser.isSet("setup")) {
LoadSetup(parser.value("setup"));
}
if(parser.isSet("cal")) {
VNA* mode = static_cast<VNA*>(modeHandler->findFirstOfType(Mode::Type::VNA));
mode->LoadCalibration(parser.value("cal"));
}
if(!parser.isSet("no-gui")) {
InformationBox::setGUI(true);
resize(1280, 800);
show();
} else {
InformationBox::setGUI(false);
noGUIset = true;
}
}

AppWindow::~AppWindow()
{
StopTCPServer();
delete ui;
}

void AppWindow::closeEvent(QCloseEvent *event)
Expand Down Expand Up @@ -937,6 +942,7 @@ int AppWindow::UpdateDeviceList()
devices.insert(device->serial());
}
int available = 0;
bool found = false;
if(devices.size()) {
for(auto d : devices) {
if(!parser.value("device").isEmpty() && parser.value("device") != d) {
Expand All @@ -952,13 +958,11 @@ int AppWindow::UpdateDeviceList()
connect(connectAction, &QAction::triggered, [this, d]() {
ConnectToDevice(d);
});
ui->menuConnect_to->setEnabled(true);
found = true;
available++;
}
} else {
// no devices available, disable connection option
ui->menuConnect_to->setEnabled(false);
}
ui->menuConnect_to->setEnabled(found);
qDebug() << "Updated device list, found" << available;
return available;
}
Expand Down
1 change: 1 addition & 0 deletions Software/PC_Application/appwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private slots:

void DeviceConnectionLost();

void SetupMenu();
void SetupStatusBar();
void UpdateStatusBar(DeviceStatusBar status);
void CreateToolbars();
Expand Down
5 changes: 2 additions & 3 deletions Software/PC_Application/modewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
#include <QMenuBar>

ModeWindow::ModeWindow(ModeHandler* handler, AppWindow* aw):
QWidget(aw),
QWidget(nullptr),
handler(handler),
aw(aw)
{

SetupUi();

connect(handler, &ModeHandler::ModeCreated, this, &ModeWindow::ModeCreated);
Expand Down Expand Up @@ -63,7 +62,7 @@ void ModeWindow::SetupUi()
mAdd->addAction(action);
connect(action, &QAction::triggered, [=](){
bool ok;
QString text = QInputDialog::getText(this,
QString text = QInputDialog::getText(aw,
"Create new "+Mode::TypeToName(type)+" tab",
"Name:", QLineEdit::Normal,
Mode::TypeToName(type), &ok);
Expand Down

0 comments on commit 787f0d0

Please sign in to comment.