Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
polarplotwidget.h
Go to the documentation of this file.
1
7
8#ifndef POLARPLOTWIDGET_H
9#define POLARPLOTWIDGET_H
10
11#include "UI/PlotWidgets/QCustomPlot/qcustomplot.h"
13#include <QCheckBox>
14#include <QComboBox>
15#include <QGridLayout>
16#include <QLabel>
17#include <QMap>
18#include <QPen>
19#include <QWidget>
20#include <complex>
21#include <limits>
22
23
29class PolarPlotWidget : public QWidget {
30 Q_OBJECT
31
32public:
37 struct Trace {
38 QList<std::complex<double>> values;
39 QList<double> frequencies;
40 QPen pen;
42 };
43
47 struct Marker {
48 QString id;
49 double frequency;
50 QPen pen;
51 };
52
54 struct AxisSettings {
55 double freqMax;
56 double freqMin;
57 QString freqUnit;
58 double radius_min;
59 double radius_max;
60 double radius_div;
61 QString marker_format;
62 };
63
65 void setSettings(const AxisSettings& settings);
66
70
73 explicit PolarPlotWidget(QWidget* parent = nullptr);
74
77 clearGraphicsItems(); // Clean up any remaining graphics items
78 }
79
80 // Trace management functions
81
87 void addTrace(const QString& name, const Trace& trace);
88
91 void removeTrace(const QString& name);
92
94 void clearTraces();
95
99 QPen getTracePen(const QString& traceName) const;
100
104 void setTracePen(const QString& traceName, const QPen& pen);
105
108 QMap<QString, QPen> getTracesInfo() const;
109
110 // Axis value access functions
111
114 double getRmax() { return rAxisMax->value(); }
115
118 double getRmin() { return rAxisMin->value(); }
119
122 double getRdiv() { return rAxisDiv->value(); }
123
126 int getDisplayMode() const {
127 return displayModeCombo->currentIndex();
128 }
129
130
131 // Marker management functions
132
138 bool addMarker(const QString& markerId, double frequency,
139 const QPen& pen = QPen(Qt::red, 2));
140
144 bool removeMarker(const QString& markerId);
145
150 bool updateMarkerFrequency(const QString& markerId, double newFrequency);
151
154 markers.clear();
155 updatePlot();
156 }
157
160 QMap<QString, double> getMarkers() const;
161
164 QCustomPlot* customPlot() const { return plot; }
165
166private slots:
168 void updateRAxis();
169
171 void updateAngleAxis() {
172 updatePlot();
173 }
174
176 void toggleDisplayMode() { updatePlot(); }
177
180 void onFMinChanged(double value){
181 fMin = value * getFrequencyMultiplier();
182 updatePlot();
183 }
184
187 void onFMaxChanged(double value) {
188 fMax = value * getFrequencyMultiplier();
189 updatePlot();
190 }
191
194 void onFUnitChanged() {
195 fMin = fMinSpinBox->value() * getFrequencyMultiplier();
196 fMax = fMaxSpinBox->value() * getFrequencyMultiplier();
197 updatePlot();
198 }
199
200private slots: // Slot to update axis settings widget based on the user zoomming and panning
201
204 void checkAxisRanges();
205
209 void checkAxisRanges(QMouseEvent* event) {
210 // This overload handles mouse events - just call the main function
211 Q_UNUSED(event)
212 checkAxisRanges();
213 }
214
218 void onRadialRangeChanged(const QCPRange& newRange);
219
220private:
221 QCustomPlot* plot;
222 QCPPolarAxisAngular* angularAxis;
223 QCPPolarAxisRadial* radialAxis;
224
225 CustomDoubleSpinBox* rAxisMin;
226 CustomDoubleSpinBox* rAxisMax;
227 CustomDoubleSpinBox* rAxisDiv;
228 QComboBox* displayModeCombo;
229
230 CustomDoubleSpinBox* fMinSpinBox;
231 CustomDoubleSpinBox* fMaxSpinBox;
232 QComboBox* fUnitComboBox;
233 double fMin;
234 double fMax;
235 QStringList frequencyUnits;
236
237 QMap<QString, Trace> traces;
238 QMap<QString, Marker> markers;
239 QMap<QString, QList<QCPPolarGraph*>>
240 traceGraphs; // Each trace can have multiple graphs for phase wrapping
241
242 // Marker items for drawing
243 QList<QCPItemEllipse*> markerItems;
244 QList<QCPItemText*> markerLabels;
245
249 void updateFrequencyRange();
250
253 QGridLayout* setupAxisSettings();
254
258 void updatePlot();
259
262 void clearGraphicsItems();
263
267 void drawCustomMarkers();
268
271 double getFrequencyMultiplier() const;
272
278 std::complex<double> getComplexValueAtFrequency(const Trace& trace,
279 double frequency);
280};
281
282#endif // POLARPLOTWIDGET_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
Widget for displaying complex data in polar plot format with markers and traces.
Definition polarplotwidget.h:29
QMap< QString, QPen > getTracesInfo() const
Get all trace names and their pen styles.
Definition polarplotwidget.cpp:164
void clearMarkers()
Clear all markers from the plot.
Definition polarplotwidget.h:153
int getDisplayMode() const
Get current display mode.
Definition polarplotwidget.h:126
void clearTraces()
Clear all traces from the plot.
Definition polarplotwidget.cpp:136
~PolarPlotWidget()
Class destructor.
Definition polarplotwidget.h:76
bool updateMarkerFrequency(const QString &markerId, double newFrequency)
Update existing marker to new frequency.
Definition polarplotwidget.cpp:307
QMap< QString, double > getMarkers() const
Get all marker IDs and their frequencies.
Definition polarplotwidget.cpp:213
QCustomPlot * customPlot() const
Access underlying QCustomPlot instance.
Definition polarplotwidget.h:164
void addTrace(const QString &name, const Trace &trace)
Add trace to the widget.
Definition polarplotwidget.cpp:89
bool removeMarker(const QString &markerId)
Remove marker by ID.
Definition polarplotwidget.cpp:203
double getRdiv()
Get radial axis division spacing.
Definition polarplotwidget.h:122
QPen getTracePen(const QString &traceName) const
Get pen style for a specific trace.
Definition polarplotwidget.cpp:150
double getRmax()
Get current radial axis maximum value.
Definition polarplotwidget.h:114
void removeTrace(const QString &name)
Remove trace by name.
Definition polarplotwidget.cpp:123
PolarPlotWidget::AxisSettings getSettings() const
Get current axis settings.
Definition polarplotwidget.cpp:727
void setTracePen(const QString &traceName, const QPen &pen)
Set pen style for a specific trace.
Definition polarplotwidget.cpp:157
double getRmin()
Get current radial axis minimum value.
Definition polarplotwidget.h:118
void setSettings(const AxisSettings &settings)
Apply saved axis settings.
Definition polarplotwidget.cpp:743
bool addMarker(const QString &markerId, double frequency, const QPen &pen=QPen(Qt::red, 2))
Add marker at specified frequency.
Definition polarplotwidget.cpp:172
The main container for polar plots, representing the angular axis as a circle.
Definition qcustomplot.h:8291
The radial axis inside a radial plot.
Definition qcustomplot.h:8017
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
Settings for plot axes and display options.
Definition polarplotwidget.h:54
QString freqUnit
Frequency unit (Hz, kHz, MHz, GHz)
Definition polarplotwidget.h:57
double radius_min
Radial axis minimum.
Definition polarplotwidget.h:58
double radius_div
Radial axis division spacing.
Definition polarplotwidget.h:60
double freqMin
Minimum frequency value.
Definition polarplotwidget.h:56
QString marker_format
Marker display format string.
Definition polarplotwidget.h:61
double radius_max
Radial axis maximum.
Definition polarplotwidget.h:59
double freqMax
Maximum frequency value.
Definition polarplotwidget.h:55
Data structure for the frequency marker.
Definition polarplotwidget.h:47
double frequency
Frequency position in Hz.
Definition polarplotwidget.h:49
QString id
Marker identifier.
Definition polarplotwidget.h:48
QPen pen
Visual style for marker.
Definition polarplotwidget.h:50
Complex trace data structure with frequencies and display properties.
Definition polarplotwidget.h:37
int displayMode
0: Magnitude/Phase, 1: Real/Imaginary
Definition polarplotwidget.h:41
QPen pen
Line style for this trace.
Definition polarplotwidget.h:40
QList< std::complex< double > > values
Complex values for polar representation.
Definition polarplotwidget.h:38
QList< double > frequencies
Corresponding frequencies for each point.
Definition polarplotwidget.h:39