Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
rectangularplotwidget.h
1/*
2 * Copyright (C) 2025 Andrés Martínez Mera - andresmmera@protonmail.com
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef RECTANGULARPLOTWIDGET_H
19#define RECTANGULARPLOTWIDGET_H
20
21#include "./QCustomPlot/qcustomplot.h"
22#include <QCheckBox>
23#include <QComboBox>
24#include <QDoubleSpinBox>
25#include <QGridLayout>
26#include <QLabel>
27#include <QMap>
28#include <QPen>
29#include <QVBoxLayout>
30#include <QWidget>
31#include <complex>
32#include <limits>
33
34class RectangularPlotWidget : public QWidget {
35 Q_OBJECT
36
37public:
38 struct Trace {
39 QList<double> trace;
40 QList<double> frequencies;
41 QString units;
42 QPen pen;
43 double Z0;
44 int y_axis;
45 QString y_axis_title;
46 };
47
48 struct Marker {
49 QString id;
50 double frequency;
51 QPen pen;
52 };
53
54 struct Limit {
55 double f1; // Start frequency
56 double f2; // End frequency
57 double y1; // Start y
58 double y2; // End y
59 int y_axis; // 0: Left y-axis; 1: Right y-axis
60 QPen pen;
61 };
62
63 // Struct to exchange the widget settings with the main program
64 struct AxisSettings {
65 double xAxisMin;
66 double xAxisMax;
67 double xAxisDiv;
68 QString xAxisUnits;
69
70 double yAxisMin;
71 double yAxisMax;
72 double yAxisDiv;
73
74 double y2AxisMin;
75 double y2AxisMax;
76 double y2AxisDiv;
77
78 bool showValues;
79 bool lockAxis;
80 };
81
82 explicit RectangularPlotWidget(QWidget* parent = nullptr);
84
85 void addTrace(const QString& name, const Trace& trace);
86 double calculateNiceStep(double range);
87 void removeTrace(const QString& name);
88 void clearTraces();
89 QPen getTracePen(const QString& traceName) const;
90 void setTracePen(const QString& traceName, const QPen& pen);
91 QMap<QString, QPen> getTracesInfo() const;
92
93 double getYmax();
94 double getYmin();
95 double getYdiv();
96 void setYdiv(double);
97 void setYmax(double);
98 void setYmin(double);
99
100 double getY2max();
101 double getY2min();
102 double getY2div();
103
104 double getXmax();
105 double getXmin();
106 double getXdiv();
107 double getXscale();
108 QString getXunits();
109 int getFreqIndex();
110
111 void updatePlot();
112 void set_y_autoscale(bool value);
113
114 bool areAxisSettingsLocked() const;
115
116 void setRightYAxisEnabled(bool enabled);
117 bool isRightYAxisEnabled() const;
118
119 void change_Y_axis_title(QString title);
120 void change_Y_axis_units(QString title);
121 void change_Y2_axis_title(QString title);
122 void change_Y2_axis_units(QString title);
123 void change_X_axis_title(QString title);
124 void change_X_axis_label(QString title);
125
126 QLabel* xAxisLabel;
127
128 bool addMarker(const QString& markerId, double frequency,
129 const QPen& pen = QPen(Qt::red, 2));
130 bool removeMarker(const QString& markerId);
131 bool updateMarkerFrequency(const QString& markerId, double newFrequency);
132 void clearMarkers();
133 QMap<QString, double> getMarkers() const;
134
135 bool addLimit(const QString& LimitId, const Limit& limit);
136 void removeLimit(const QString& LimitID);
137 void clearLimits();
138 QMap<QString, Limit> getLimits() const;
139 bool updateLimit(const QString& limitId, const Limit& limit);
140
141 QCustomPlot* customPlot() const { return plotWidget; }
142
143 // Exchange the settings with the main program
144 AxisSettings getSettings() const;
145 void setSettings(const AxisSettings& settings);
146
147private slots:
148 void updateXAxis();
149 void updateYAxis();
150 void updateY2Axis();
151 void changeFreqUnits();
152 void toggleShowValues(bool show);
153 void toggleLockAxisSettings(bool locked);
154
155private slots
156 : // To handle axis settings widgets when panning or zooming the plot
157 void onXAxisRangeChanged(const QCPRange& range);
158 void onYAxisRangeChanged(const QCPRange& range);
159 void onY2AxisRangeChanged(const QCPRange& range);
160
161private:
162 QCustomPlot* plotWidget;
163
164 QDoubleSpinBox* xAxisMin;
165 QDoubleSpinBox* xAxisMax;
166 QDoubleSpinBox* xAxisDiv;
167 QComboBox* xAxisUnits;
168
169 QDoubleSpinBox* yAxisMin;
170 QDoubleSpinBox* yAxisMax;
171 QDoubleSpinBox* yAxisDiv;
172 QLabel* yAxisUnits;
173
174 QDoubleSpinBox* y2AxisMin;
175 QDoubleSpinBox* y2AxisMax;
176 QDoubleSpinBox* y2AxisDiv;
177 QLabel* y2AxisUnits;
178 QLabel* y2AxisLabel;
179
180 QCheckBox* showValuesCheckbox;
181 bool showTraceValues;
182
183 QCheckBox* lockAxisCheckbox;
184 bool axisSettingsLocked;
185
186 QStringList frequencyUnits;
187 double fMin;
188 double fMax;
189
190 bool y_autoscale;
191
192 QMap<QString, Trace> traces;
193 QMap<QString, Marker> markers;
194 QMap<QString, Limit> limits;
195
196 // QCustomPlot specific members
197 QMap<QString, QCPGraph*> traceGraphs;
198 QMap<QString, QCPItemStraightLine*> markerLines;
199 QMap<QString, QCPItemText*> markerLabels;
200 QMap<QString, QCPItemTracer*> intersectionPoints;
201 QMap<QString, QCPItemText*> intersectionLabels;
202 QMap<QString, QCPGraph*> limitGraphs;
203
204 QGridLayout* setupAxisSettings();
205 void clearGraphicsItems();
206 void setupPlot();
207 void addMarkerIntersections(const QString& markerId, const Marker& marker);
208
209 int getYAxisTraceCount() const;
210 int getY2AxisTraceCount() const;
211};
212
213#endif // RECTANGULARPLOTWIDGET_H
Definition rectangularplotwidget.h:34
Definition rectangularplotwidget.h:64
Definition rectangularplotwidget.h:54
Definition rectangularplotwidget.h:48
Definition rectangularplotwidget.h:38