mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-05 06:25:16 +00:00
add optional title to graphs
This commit is contained in:
parent
c808c6d4e4
commit
8a56b36166
8 changed files with 75 additions and 16 deletions
|
|
@ -17,6 +17,7 @@
|
|||
#include <QMimeData>
|
||||
#include <QDebug>
|
||||
#include <QApplication>
|
||||
#include <QInputDialog>
|
||||
|
||||
std::set<TracePlot*> TracePlot::plots;
|
||||
|
||||
|
|
@ -233,13 +234,24 @@ void TracePlot::paintEvent(QPaintEvent *event)
|
|||
p.setBackground(QBrush(pref.Graphs.Color.background));
|
||||
p.fillRect(0, 0, width(), height(), QBrush(pref.Graphs.Color.background));
|
||||
|
||||
marginTop = 0;
|
||||
// draw title
|
||||
if(!title.isEmpty()) {
|
||||
QFont font = p.font();
|
||||
font.setPixelSize(pref.Graphs.fontSizeTitle);
|
||||
p.setFont(font);
|
||||
p.setPen(Util::getFontColorFromBackground(pref.Graphs.Color.background));
|
||||
p.drawText(QRect(0, 0, width(), pref.Graphs.fontSizeTitle), Qt::AlignCenter, title);
|
||||
marginTop += pref.Graphs.fontSizeTitle;
|
||||
}
|
||||
|
||||
// show names of active traces and marker data (if enabled)
|
||||
bool hasMarkerData = false;
|
||||
auto marginMarkerData = pref.Graphs.fontSizeMarkerData * 12.5;
|
||||
marginTop = pref.Graphs.fontSizeTraceNames + 8;
|
||||
auto traceNameTop = marginTop + 5;
|
||||
marginTop += pref.Graphs.fontSizeTraceNames + 8;
|
||||
int x = 1; // xcoordinate for the next trace name
|
||||
int y = marginTop; // ycoordinate for the next marker data
|
||||
auto areaTextTop = 5;
|
||||
auto labelMarginRight = 4;
|
||||
auto borderRadius = 5;
|
||||
for(auto t : traces) {
|
||||
|
|
@ -248,7 +260,7 @@ void TracePlot::paintEvent(QPaintEvent *event)
|
|||
}
|
||||
|
||||
// Trace name
|
||||
auto textArea = QRect(x, areaTextTop, width() - x, marginTop);
|
||||
auto textArea = QRect(x, traceNameTop, width() - x, pref.Graphs.fontSizeTraceNames + 8);
|
||||
QFont font = p.font();
|
||||
font.setPixelSize(pref.Graphs.fontSizeTraceNames);
|
||||
p.setFont(font);
|
||||
|
|
@ -384,6 +396,13 @@ void TracePlot::paintEvent(QPaintEvent *event)
|
|||
void TracePlot::finishContextMenu()
|
||||
{
|
||||
contextmenu->addSeparator();
|
||||
auto setTitle = new QAction("Set Title", contextmenu);
|
||||
contextmenu->addAction(setTitle);
|
||||
connect(setTitle, &QAction::triggered, [=](){
|
||||
title = QInputDialog::getText(contextmenu, "Set new graph title", "Enter new title:", QLineEdit::Normal, title);
|
||||
});
|
||||
contextmenu->addSeparator();
|
||||
|
||||
if(parentTile) {
|
||||
auto add = new QMenu("Add tile...", contextmenu);
|
||||
auto left = new QAction("to the left", contextmenu);
|
||||
|
|
@ -723,6 +742,18 @@ QRect TracePlot::getDropRect()
|
|||
return QRect(QPoint(w*dropBorders, h*dropBorders), QSize(w*(1.0-2*dropBorders), h*(1.0-2*dropBorders)));
|
||||
}
|
||||
|
||||
nlohmann::json TracePlot::getBaseJSON()
|
||||
{
|
||||
nlohmann::json j;
|
||||
j["title"] = title.toStdString();
|
||||
return j;
|
||||
}
|
||||
|
||||
void TracePlot::parseBaseJSON(nlohmann::json j)
|
||||
{
|
||||
title = QString::fromStdString(j.value("title", ""));
|
||||
}
|
||||
|
||||
std::set<TracePlot *> TracePlot::getPlots()
|
||||
{
|
||||
return plots;
|
||||
|
|
|
|||
|
|
@ -103,6 +103,10 @@ protected:
|
|||
virtual QString mouseText(QPoint pos) {Q_UNUSED(pos) return QString();}
|
||||
QRect getDropRect();
|
||||
|
||||
// save/load base class members. Should be called by derived classes in the toJSON/fromJSON functions
|
||||
nlohmann::json getBaseJSON();
|
||||
void parseBaseJSON(nlohmann::json j);
|
||||
|
||||
protected slots:
|
||||
void newTraceAvailable(Trace *t);
|
||||
void traceDeleted(Trace *t);
|
||||
|
|
@ -150,6 +154,9 @@ protected:
|
|||
unsigned int marginTop;
|
||||
|
||||
bool limitPassing;
|
||||
|
||||
private:
|
||||
QString title;
|
||||
};
|
||||
|
||||
#endif // TRACEPLOT_H
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ TracePolar::TracePolar(TraceModel &model, QWidget *parent)
|
|||
|
||||
nlohmann::json TracePolar::toJSON()
|
||||
{
|
||||
nlohmann::json j;
|
||||
nlohmann::json j = getBaseJSON();
|
||||
j["limit_to_span"] = limitToSpan;
|
||||
j["limit_to_edge"] = limitToEdge;
|
||||
j["edge_reflection"] = edgeReflection;
|
||||
|
|
@ -44,6 +44,7 @@ nlohmann::json TracePolar::toJSON()
|
|||
|
||||
void TracePolar::fromJSON(nlohmann::json j)
|
||||
{
|
||||
parseBaseJSON(j);
|
||||
limitToSpan = j.value("limit_to_span", true);
|
||||
limitToEdge = j.value("limit_to_edge", false);
|
||||
edgeReflection = j.value("edge_reflection", 1.0);
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ void TraceWaterfall::replot()
|
|||
|
||||
void TraceWaterfall::fromJSON(nlohmann::json j)
|
||||
{
|
||||
parseBaseJSON(j);
|
||||
resetWaterfall();
|
||||
pixelsPerLine = j.value("pixelsPerLine", pixelsPerLine);
|
||||
maxDataSweeps = j.value("maxLines", maxDataSweeps);
|
||||
|
|
@ -127,7 +128,7 @@ void TraceWaterfall::fromJSON(nlohmann::json j)
|
|||
|
||||
nlohmann::json TraceWaterfall::toJSON()
|
||||
{
|
||||
nlohmann::json j;
|
||||
nlohmann::json j = getBaseJSON();
|
||||
j["pixelsPerLine"] = pixelsPerLine;
|
||||
j["direction"] = dir == Direction::TopToBottom ? "TopToBottom" : "BottomToTop";
|
||||
j["keepDataBeyondPlot"] = keepDataBeyondPlotSize;
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ void TraceXYPlot::setAuto(bool horizontally, bool vertically)
|
|||
|
||||
nlohmann::json TraceXYPlot::toJSON()
|
||||
{
|
||||
nlohmann::json j;
|
||||
nlohmann::json j = getBaseJSON();
|
||||
nlohmann::json jX;
|
||||
jX["type"] = xAxis.TypeToName().toStdString();
|
||||
jX["mode"] = AxisModeToName(xAxisMode).toStdString();
|
||||
|
|
@ -198,6 +198,7 @@ nlohmann::json TraceXYPlot::toJSON()
|
|||
|
||||
void TraceXYPlot::fromJSON(nlohmann::json j)
|
||||
{
|
||||
parseBaseJSON(j);
|
||||
auto jX = j["XAxis"];
|
||||
// old format used enum value for type and mode, new format uses string encoding (more robust when additional enum values are added).
|
||||
// Check which format is used and parse accordingly
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue