Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
rectangularplotwidget.h
Go to the documentation of this file.
1
7
8#ifndef RECTANGULARPLOTWIDGET_H
9#define RECTANGULARPLOTWIDGET_H
10
11#include "./QCustomPlot/qcustomplot.h"
13#include <QCheckBox>
14#include <QComboBox>
15#include <QGridLayout>
16#include <QLabel>
17#include <QMap>
18#include <QPen>
19#include <QVBoxLayout>
20#include <QWidget>
21#include <complex>
22#include <limits>
23
30class RectangularPlotWidget : public QWidget {
31 Q_OBJECT
32
33public:
39 struct Trace {
40 QList<double> trace;
41 QList<double> frequencies;
42 QString units;
43 QPen pen;
44 double Z0;
45 int y_axis;
46 QString y_axis_title;
47 };
48
49
53 struct Marker {
54 QString id;
55 double frequency;
56 QPen pen;
57 };
58
61 struct Limit {
62 double f1;
63 double f2;
64 double y1;
65 double y2;
66 int y_axis;
67 QPen pen;
68 };
69
72 struct AxisSettings {
73 double xAxisMin;
74 double xAxisMax;
75 double xAxisDiv;
76 QString xAxisUnits;
77 double yAxisMin;
78 double yAxisMax;
79 double yAxisDiv;
80 double y2AxisMin;
81 double y2AxisMax;
82 double y2AxisDiv;
84 bool lockAxis;
85 bool lockPan;
86 };
87
90 explicit RectangularPlotWidget(QWidget* parent = nullptr);
91
94
98 void addTrace(const QString& name, const Trace& trace);
99
102 void removeTrace(const QString& name) {
103 traces.remove(name);
104 updatePlot();
105 }
106
108 void clearTraces() {
109 traces.clear();
110 updatePlot();
111 }
112
116 double calculateNiceStep(double range);
117
121 QPen getTracePen(const QString& traceName) const;
122
126 void setTracePen(const QString& traceName, const QPen& pen);
127
130 QMap<QString, QPen> getTracesInfo() const;
131
133 double getYmax() { return yAxisMax->value(); }
134
136 double getYmin() { return yAxisMin->value(); }
137
139 double getYdiv() { return yAxisDiv->value(); }
140
143 void setYdiv(double val) { yAxisDiv->setValue(val); }
144
147 void setYmax(double val) { yAxisMax->setValue(val); }
148
151 void setYmin(double val) { yAxisMin->setValue(val); }
152
154 double getY2max() { return y2AxisMax->value(); }
155
157 double getY2min() { return y2AxisMin->value(); }
158
160 double getY2div() { return y2AxisDiv->value(); }
161
163 double getXmax() { return xAxisMax->value(); }
164
166 double getXmin(){ return xAxisMin->value(); }
167
169 double getXdiv() { return xAxisDiv->value(); }
170
173 double getXscale();
174
177 QString getXunits() { return xAxisUnits->currentText(); }
178
181 int getFreqIndex() { return xAxisUnits->currentIndex(); }
182
184 void updatePlot();
185
188 void set_y_autoscale(bool value) { y_autoscale = value; }
189
193 return axisSettingsLocked;
194 }
195
198 void setRightYAxisEnabled(bool enabled);
199
202 bool isRightYAxisEnabled() const {
203 return plotWidget->yAxis2->visible();
204 }
205
208 void change_Y_axis_title(QString title) {
209 plotWidget->yAxis->setLabel(title);
210 plotWidget->replot();
211 }
212
215 void change_Y_axis_units(QString units){
216 yAxisUnits->setText(units);
217 }
218
221 void change_Y2_axis_title(QString title){
222 plotWidget->yAxis2->setLabel(title);
223 plotWidget->replot();
224 }
225
228 void change_Y2_axis_units(QString units) {
229 y2AxisUnits->setText(units);
230 }
231
234 void change_X_axis_title(QString title){
235 plotWidget->xAxis->setLabel(title);
236 plotWidget->replot();
237 }
238
239
240 QLabel* xAxisLabel;
241
247 bool addMarker(const QString& markerId, double frequency,
248 const QPen& pen = QPen(Qt::red, 2));
249
253 bool removeMarker(const QString& markerId);
254
259 bool updateMarkerFrequency(const QString& markerId, double newFrequency);
260
263 markers.clear();
264 updatePlot();
265 }
266
269 QMap<QString, double> getMarkers() const;
270
275 bool addLimit(const QString& LimitId, const Limit& limit);
276
279 void removeLimit(const QString& LimitID);
280
282 void clearLimits() {
283 limits.clear();
284 updatePlot();
285 }
286
289 QMap<QString, Limit> getLimits() const {
290 return limits;
291 }
292
297 bool updateLimit(const QString& limitId, const Limit& limit);
298
301 QCustomPlot* customPlot() const { return plotWidget; }
302
305 AxisSettings getSettings() const;
306
309 void setSettings(const AxisSettings& settings);
310
311private slots:
313 void updateXAxis();
314
316 void updateYAxis();
317
319 void updateY2Axis();
320
322 void changeFreqUnits();
323
327 void toggleShowValues(bool show);
328
331 void toggleLockAxisSettings(bool locked);
332
335 void toggleLockPan(bool locked);
336
337private slots:
339 void onXAxisRangeChanged(const QCPRange& range);
340
342 void onYAxisRangeChanged(const QCPRange& range);
343
345 void onY2AxisRangeChanged(const QCPRange& range);
346
347private:
348 QCustomPlot* plotWidget;
349
350 CustomDoubleSpinBox* xAxisMin;
351 CustomDoubleSpinBox* xAxisMax;
352 CustomDoubleSpinBox* xAxisDiv;
353 QComboBox* xAxisUnits;
354
355 CustomDoubleSpinBox* yAxisMin;
356 CustomDoubleSpinBox* yAxisMax;
357 CustomDoubleSpinBox* yAxisDiv;
358 QLabel* yAxisUnits;
359
360 CustomDoubleSpinBox* y2AxisMin;
361 CustomDoubleSpinBox* y2AxisMax;
362 CustomDoubleSpinBox* y2AxisDiv;
363 QLabel* y2AxisUnits;
364 QLabel* y2AxisLabel;
365
366 QCheckBox* showValuesCheckbox;
367 bool showTraceValues;
368
369 QCheckBox* lockAxisCheckbox;
370 bool axisSettingsLocked;
371
372 QCheckBox* lockPanCheckbox;
373
374 QStringList frequencyUnits;
375 double fMin;
376 double fMax;
377
378 bool y_autoscale;
379
380 QMap<QString, Trace> traces;
381 QMap<QString, Marker> markers;
382 QMap<QString, Limit> limits;
383
384 QMap<QString, QCPGraph*> traceGraphs;
385 QMap<QString, QCPItemStraightLine*> markerLines;
386 QMap<QString, QCPItemText*> markerLabels;
387 QMap<QString, QCPItemTracer*> intersectionPoints;
388 QMap<QString, QCPItemText*> intersectionLabels;
389 QMap<QString, QCPGraph*> limitGraphs;
390
393 QGridLayout* setupAxisSettings();
394
396 void clearGraphicsItems();
397
399 void setupPlot();
400
404 void addMarkerIntersections(const QString& markerId, const Marker& marker);
405
408 int getYAxisTraceCount() const;
409
412 int getY2AxisTraceCount() const;
413};
414
415#endif // RECTANGULARPLOTWIDGET_H
Custom QDoubleSpinBox. It includes a context menu (right-click) for setting the minimum,...
A QDoubleSpinBox subclass that provides a context menu for configuring range and step.
Definition CustomDoubleSpinBox.h:28
void setLabel(const QString &str)
Definition qcustomplot.cpp:9488
Represents the range an axis is encompassing.
Definition qcustomplot.h:986
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
Definition qcustomplot.h:4305
QCPAxis * xAxis
Definition qcustomplot.h:4514
Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint)
Definition qcustomplot.cpp:16135
QCPAxis * yAxis2
Definition qcustomplot.h:4514
QCPAxis * yAxis
Definition qcustomplot.h:4514
Widget for displaying rectangular (Cartesian) plots with dual y-axes It provides a rectangular plot v...
Definition rectangularplotwidget.h:30
double getY2min()
Get minimum right Y-axis value.
Definition rectangularplotwidget.h:157
bool areAxisSettingsLocked() const
Check if axis settings are locked.
Definition rectangularplotwidget.h:192
bool addMarker(const QString &markerId, double frequency, const QPen &pen=QPen(Qt::red, 2))
Add a vertical marker at a specific frequency.
Definition rectangularplotwidget.cpp:236
QMap< QString, double > getMarkers() const
Get all markers and their frequencies.
Definition rectangularplotwidget.cpp:277
double getYmin()
Get minimum left Y-axis value.
Definition rectangularplotwidget.h:136
QMap< QString, QPen > getTracesInfo() const
Get information about all traces.
Definition rectangularplotwidget.cpp:228
void clearLimits()
Remove all limit lines from the plot.
Definition rectangularplotwidget.h:282
void setSettings(const AxisSettings &settings)
Apply axis settings to the plot.
Definition rectangularplotwidget.cpp:987
bool addLimit(const QString &LimitId, const Limit &limit)
Add a limit line to the plot.
Definition rectangularplotwidget.cpp:873
void set_y_autoscale(bool value)
Enable or disable automatic Y-axis scaling.
Definition rectangularplotwidget.h:188
bool updateLimit(const QString &limitId, const Limit &limit)
Update an existing limit line.
Definition rectangularplotwidget.cpp:897
void change_Y_axis_units(QString units)
Set left Y-axis unit label.
Definition rectangularplotwidget.h:215
void addTrace(const QString &name, const Trace &trace)
Add or update a trace on the plot.
Definition rectangularplotwidget.cpp:85
AxisSettings getSettings() const
Get current axis settings.
Definition rectangularplotwidget.cpp:965
double getY2div()
Get right Y-axis division interval.
Definition rectangularplotwidget.h:160
double getYdiv()
Get left Y-axis division interval.
Definition rectangularplotwidget.h:139
void setYdiv(double val)
Set left Y-axis division interval.
Definition rectangularplotwidget.h:143
double getXdiv()
Get X-axis division interval.
Definition rectangularplotwidget.h:169
double getXmax()
Get maximum X-axis value.
Definition rectangularplotwidget.h:163
void change_Y2_axis_title(QString title)
Set right Y-axis title.
Definition rectangularplotwidget.h:221
double getY2max()
Get maximum right Y-axis value.
Definition rectangularplotwidget.h:154
void change_Y2_axis_units(QString units)
Set right Y-axis unit label.
Definition rectangularplotwidget.h:228
void clearTraces()
Remove all traces from the plot.
Definition rectangularplotwidget.h:108
QPen getTracePen(const QString &traceName) const
Get the pen style for a specific trace.
Definition rectangularplotwidget.cpp:208
bool isRightYAxisEnabled() const
Check if right Y-axis is enabled.
Definition rectangularplotwidget.h:202
void setRightYAxisEnabled(bool enabled)
Enable or disable the right Y-axis.
Definition rectangularplotwidget.cpp:913
void removeLimit(const QString &LimitID)
Remove a limit line from the plot.
Definition rectangularplotwidget.cpp:888
double calculateNiceStep(double range)
Calculate an aesthetically pleasing step size for axis divisions.
Definition rectangularplotwidget.cpp:182
void clearMarkers()
Remove all markers from the plot.
Definition rectangularplotwidget.h:262
double getYmax()
Get maximum left Y-axis value.
Definition rectangularplotwidget.h:133
bool updateMarkerFrequency(const QString &markerId, double newFrequency)
Update the frequency of an existing marker.
Definition rectangularplotwidget.cpp:800
QString getXunits()
Get current frequency unit string.
Definition rectangularplotwidget.h:177
void updatePlot()
Redraw the entire plot with current data.
Definition rectangularplotwidget.cpp:285
QCustomPlot * customPlot() const
Access the underlying QCustomPlot widget.
Definition rectangularplotwidget.h:301
QMap< QString, Limit > getLimits() const
Get all defined limits.
Definition rectangularplotwidget.h:289
~RectangularPlotWidget()
Destructor.
Definition rectangularplotwidget.cpp:34
double getXmin()
Get minimum X-axis value.
Definition rectangularplotwidget.h:166
void change_X_axis_title(QString title)
Set X-axis title.
Definition rectangularplotwidget.h:234
void change_Y_axis_title(QString title)
Set left Y-axis title.
Definition rectangularplotwidget.h:208
double getXscale()
Get frequency scale factor for current units.
Definition rectangularplotwidget.cpp:787
void setYmax(double val)
Set maximum left Y-axis value.
Definition rectangularplotwidget.h:147
QLabel * xAxisLabel
x-axis label
Definition rectangularplotwidget.h:240
int getFreqIndex()
Get frequency unit combo box index.
Definition rectangularplotwidget.h:181
void removeTrace(const QString &name)
Remove a trace from the plot.
Definition rectangularplotwidget.h:102
void setYmin(double val)
Set minimum left Y-axis value.
Definition rectangularplotwidget.h:151
bool removeMarker(const QString &markerId)
Remove a marker from the plot.
Definition rectangularplotwidget.cpp:267
void setTracePen(const QString &traceName, const QPen &pen)
Set the pen style for a specific trace.
Definition rectangularplotwidget.cpp:220
Settings for plot axes and display options.
Definition rectangularplotwidget.h:72
double yAxisMin
Minimum left Y-axis value.
Definition rectangularplotwidget.h:77
double xAxisMin
Minimum X-axis value.
Definition rectangularplotwidget.h:73
double xAxisMax
Maximum X-axis value.
Definition rectangularplotwidget.h:74
double xAxisDiv
X-axis tick interval.
Definition rectangularplotwidget.h:75
double y2AxisMin
Minimum right Y-axis value.
Definition rectangularplotwidget.h:80
QString xAxisUnits
Frequency units (Hz, kHz, MHz, GHz)
Definition rectangularplotwidget.h:76
double y2AxisDiv
Right Y-axis tick interval.
Definition rectangularplotwidget.h:82
bool lockPan
Lock pan mode to prevent dragging.
Definition rectangularplotwidget.h:85
double y2AxisMax
Maximum right Y-axis value.
Definition rectangularplotwidget.h:81
double yAxisMax
Maximum left Y-axis value.
Definition rectangularplotwidget.h:78
double yAxisDiv
Left Y-axis tick interval.
Definition rectangularplotwidget.h:79
bool lockAxis
Lock axis settings to prevent auto-adjustment.
Definition rectangularplotwidget.h:84
bool showValues
Show marker intersection values.
Definition rectangularplotwidget.h:83
Data structure representing a limit line segment.
Definition rectangularplotwidget.h:61
double f2
End frequency [Hz].
Definition rectangularplotwidget.h:63
double f1
Start frequency [Hz].
Definition rectangularplotwidget.h:62
double y2
Y-value at end frequency.
Definition rectangularplotwidget.h:65
double y1
Y-value at start frequency.
Definition rectangularplotwidget.h:64
QPen pen
Limit line style.
Definition rectangularplotwidget.h:67
int y_axis
Axis assignment: 0 for left, 1 for right.
Definition rectangularplotwidget.h:66
Data structure for the frequency marker.
Definition rectangularplotwidget.h:53
QPen pen
Marker pen style.
Definition rectangularplotwidget.h:56
QString id
Unique marker identifier.
Definition rectangularplotwidget.h:54
double frequency
Marker frequency [Hz].
Definition rectangularplotwidget.h:55
Data structure representing a trace on the plot.
Definition rectangularplotwidget.h:39
QList< double > trace
Y-axis values.
Definition rectangularplotwidget.h:40
QList< double > frequencies
X-axis frequency values in Hz.
Definition rectangularplotwidget.h:41
QPen pen
Visual style for the trace line.
Definition rectangularplotwidget.h:43
QString y_axis_title
Title for the y-axis.
Definition rectangularplotwidget.h:46
int y_axis
Axis assignment: 0 for left, 2 for right.
Definition rectangularplotwidget.h:45
QString units
Units for the trace values (e.g., "dB")
Definition rectangularplotwidget.h:42
double Z0
Reference impedance.
Definition rectangularplotwidget.h:44