mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-01-05 08:10:06 +01:00
add optional title to graphs
This commit is contained in:
parent
c808c6d4e4
commit
8a56b36166
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -295,6 +295,7 @@ void PreferencesDialog::setInitialGUIState()
|
|||
ui->GraphsLimitIndication->setCurrentIndex((int) p->Graphs.limitIndication);
|
||||
ui->GraphsLimitNaNpasses->setCurrentIndex(p->Graphs.limitNaNpasses ? 1 : 0);
|
||||
ui->GraphsLineWidth->setValue(p->Graphs.lineWidth);
|
||||
ui->GraphsFontSizeTitle->setValue(p->Graphs.fontSizeTitle);
|
||||
ui->GraphsFontSizeAxis->setValue(p->Graphs.fontSizeAxis);
|
||||
ui->GraphsFontSizeCursorOverlay->setValue(p->Graphs.fontSizeCursorOverlay);
|
||||
ui->GraphsFontSizeMarkerData->setValue(p->Graphs.fontSizeMarkerData);
|
||||
|
|
@ -416,6 +417,7 @@ void PreferencesDialog::updateFromGUI()
|
|||
p->Graphs.limitIndication = (GraphLimitIndication) ui->GraphsLimitIndication->currentIndex();
|
||||
p->Graphs.limitNaNpasses = ui->GraphsLimitNaNpasses->currentIndex() == 1;
|
||||
p->Graphs.lineWidth = ui->GraphsLineWidth->value();
|
||||
p->Graphs.fontSizeTitle = ui->GraphsFontSizeTitle->value();
|
||||
p->Graphs.fontSizeAxis = ui->GraphsFontSizeAxis->value();
|
||||
p->Graphs.fontSizeCursorOverlay = ui->GraphsFontSizeCursorOverlay->value();
|
||||
p->Graphs.fontSizeMarkerData = ui->GraphsFontSizeMarkerData->value();
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ public:
|
|||
bool limitNaNpasses;
|
||||
|
||||
double lineWidth;
|
||||
int fontSizeTitle;
|
||||
int fontSizeAxis;
|
||||
int fontSizeMarkerData;
|
||||
int fontSizeTraceNames;
|
||||
|
|
@ -274,6 +275,7 @@ private:
|
|||
{&Graphs.limitIndication, "Graphs.limitIndication", GraphLimitIndication::PassFailText},
|
||||
{&Graphs.limitNaNpasses, "Graphs.limitNaNpasses", false},
|
||||
{&Graphs.lineWidth, "Graphs.lineWidth", 1.0},
|
||||
{&Graphs.fontSizeTitle, "Graphs.fontSizeTitle", 18},
|
||||
{&Graphs.fontSizeAxis, "Graphs.fontSizeAxis", 10},
|
||||
{&Graphs.fontSizeCursorOverlay, "Graphs.fontSizeCursorOverlay", 12},
|
||||
{&Graphs.fontSizeMarkerData, "Graphs.fontSizeMarkerData", 12},
|
||||
|
|
|
|||
|
|
@ -953,9 +953,9 @@
|
|||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>-622</y>
|
||||
<y>0</y>
|
||||
<width>683</width>
|
||||
<height>1185</height>
|
||||
<height>1217</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_22">
|
||||
|
|
@ -1066,62 +1066,76 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_39">
|
||||
<property name="text">
|
||||
<string>Font (axes):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="GraphsFontSizeAxis">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="GraphsFontSizeTraceNames">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QSpinBox" name="GraphsFontSizeMarkerData">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<item row="5" column="1">
|
||||
<widget class="QSpinBox" name="GraphsFontSizeCursorOverlay">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_40">
|
||||
<property name="text">
|
||||
<string>Font (trace names):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_41">
|
||||
<property name="text">
|
||||
<string>Font (marker data):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_42">
|
||||
<property name="text">
|
||||
<string>Font (cursor overlay):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_68">
|
||||
<property name="text">
|
||||
<string>Font (title):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="GraphsFontSizeTitle">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
|||
Loading…
Reference in a new issue