LibreVNA/Software/PC_Application/Traces/tracexyplot.h

123 lines
3.2 KiB
C
Raw Normal View History

2020-10-28 05:07:14 +08:00
#ifndef TRACEXYPLOT_H
#define TRACEXYPLOT_H
#include "traceplot.h"
#include <set>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_series_data.h>
#include <qwt_plot_marker.h>
2020-10-23 03:12:33 +08:00
#include <qwt_plot_grid.h>
#include <qwt_plot_picker.h>
// Derived plotpicker, exposing transformation functions
2020-10-28 05:07:14 +08:00
class XYplotPicker : public QwtPlotPicker {
Q_OBJECT
public:
2020-10-28 05:07:14 +08:00
XYplotPicker(int xAxis, int yAxis, RubberBand rubberBand, DisplayMode trackerMode, QWidget *w)
: QwtPlotPicker(xAxis, yAxis, rubberBand, trackerMode, w) {};
QPoint plotToPixel(const QPointF &pos) {
return transform(pos);
}
QPointF pixelToPlot(const QPoint &pos) {
return invTransform(pos);
}
};
2020-10-28 05:07:14 +08:00
class TraceXYPlot : public TracePlot
{
2020-10-28 05:07:14 +08:00
friend class XYplotAxisDialog;
Q_OBJECT
public:
2020-10-28 05:07:14 +08:00
TraceXYPlot(TraceModel &model, QWidget *parent = nullptr);
~TraceXYPlot();
enum class YAxisType {
Disabled = 0,
2020-10-28 05:07:14 +08:00
// S parameter options
Magnitude = 1,
Phase = 2,
VSWR = 3,
2020-10-28 05:07:14 +08:00
// TDR options
Impulse = 4,
Step = 5,
Impedance = 6,
Last,
};
2020-10-28 05:07:14 +08:00
static const std::set<YAxisType> YAxisTypes;
enum class XAxisType {
Frequency,
Time,
Distance,
};
virtual void setXAxis(double min, double max) override;
void setYAxis(int axis, YAxisType type, bool log, bool autorange, double min, double max, double div);
2020-10-28 05:07:14 +08:00
void setXAxis(XAxisType type, bool autorange, double min, double max, double div);
void enableTrace(Trace *t, bool enabled) override;
2020-10-28 05:07:14 +08:00
// Applies potentially changed colors to all XY-plots
2020-10-23 03:12:33 +08:00
static void updateGraphColors();
2020-10-28 05:07:14 +08:00
bool isTDRtype(YAxisType type);
protected:
2020-10-28 05:07:14 +08:00
virtual void updateContextMenu() override;
virtual bool supported(Trace *t) override;
void replot() override;
private slots:
void traceColorChanged(Trace *t);
void markerAdded(TraceMarker *m) override;
void markerRemoved(TraceMarker *m) override;
void markerDataChanged(TraceMarker *m);
2020-10-20 23:03:49 +08:00
void markerSymbolChanged(TraceMarker *m);
void clicked(const QPointF pos);
void moved(const QPointF pos);
private:
2020-10-23 03:12:33 +08:00
void setColorFromPreferences();
QString AxisTypeToName(YAxisType type);
void enableTraceAxis(Trace *t, int axis, bool enabled);
bool supported(Trace *t, YAxisType type);
void updateXAxis();
QwtSeriesData<QPointF> *createQwtSeriesData(Trace &t, int axis);
std::set<Trace*> tracesAxis[2];
class Axis {
public:
2020-10-28 05:07:14 +08:00
union {
YAxisType Ytype;
XAxisType Xtype;
};
bool log;
bool autorange;
double rangeMin;
double rangeMax;
double rangeDiv;
};
Axis YAxis[2];
Axis XAxis;
double sweep_fmin, sweep_fmax;
using CurveData = struct {
QwtPlotCurve *curve;
QwtSeriesData<QPointF> *data;
};
std::map<Trace*, CurveData> curves[2];
std::map<TraceMarker*, QwtPlotMarker*> markers;
QwtPlot *plot;
2020-10-23 03:12:33 +08:00
QwtPlotGrid *grid;
TraceMarker *selectedMarker;
QwtPlotCurve *selectedCurve;
2020-10-28 05:07:14 +08:00
XYplotPicker *drawPicker;
2020-10-23 03:12:33 +08:00
// keep track of all created plots for changing colors
2020-10-28 05:07:14 +08:00
static std::set<TraceXYPlot*> allPlots;
};
2020-10-28 05:07:14 +08:00
#endif // TRACEXYPLOT_H