SoDaRadio-5.0.3-master:8901fb5
soda_spect.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2017 Matthew H. Reilly (kb1vc)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef SODASPECT_H
30 #define SODASPECT_H
31 
32 #include <iostream>
33 
34 #include <QWidget>
35 #include <qwt/qwt_plot.h>
36 #include <qwt/qwt_plot_curve.h>
37 #include <qwt/qwt_plot_picker.h>
38 #include <qwt/qwt_plot_grid.h>
39 #include <qwt/qwt_plot_marker.h>
40 #include <qwt/qwt_plot_shapeitem.h>
41 
42 #include <QMouseEvent>
43 #include <QPointF>
44 
45 #include "soda_plot_picker.hpp"
46 #include "soda_freq_scale_draw.hpp"
47 
48 namespace GUISoDa {
49 class Spect : public QwtPlot
50 {
51  Q_OBJECT
52 
53 public:
54  explicit Spect(QWidget *parent = 0);
55  ~Spect();
56 
57  double freqCenter() { return center_freq_disp; }
58 
59 public slots:
60  void updateData(double cfreq, float * y);
61  void pickPoint(const QPointF & pos);
62  void setDynamicRange(double drange);
63  void setRefLevel(int rlvl);
64  void setFreqCenter(double cf, bool check_boundary = false);
65  void setFreqSpan(double fs, bool check_boundary = false);
66  void setFreqSpanKHz(double fs) { setFreqSpan(1e3 * fs, true); }
67  void setFreqMarker(double f);
68 
69  void scrollRight(bool v) {
70  (void) v;
72  }
73  void scrollLeft(bool v) {
74  (void) v;
76  }
77 
78  void configureSpectrum(double cfreq, double span, long buckets);
79 
80  void setMarkerOffset(double lo, double hi);
81 
82 protected:
83 
84  void resetFreqAxis(double cfreq);
85 
86  void replotXAxis();
87  void replotYAxis();
88 
89  double correctCenterFreq(double cfreq);
90 
91 public:
92 signals:
93  void xClick(double x);
94 
95 protected:
96  // storage for data to be plotted.
97  double * freqs;
98  double * vals;
100 
101  // the input data covers a frequency range that
102  // is not necessarily related to the display range.
104  double freq_span_in;
105 
106  // This is the display range (x and y dimensions)
107  // x axis settings
110 
111  // y axis settings
112  double val_ref; // value for maximum point on the scale
113  double val_range;
114 
115  // marker offset
118 
119  // marked frequency
120  double marker_freq;
121 
123 
124  QwtPlotCurve * curve_p;
125 
127 
128  QwtPlotGrid * grid_p;
129 
130  QwtPlotShapeItem freq_marker;
131 
132 
133 private:
134  void initPlot();
135 
136 };
137 }
138 
139 #endif // XYPLOTWIDGET_H
void updateData(double cfreq, float *y)
Definition: soda_spect.cpp:102
QwtPlotShapeItem freq_marker
Definition: soda_spect.hpp:130
void setFreqSpanKHz(double fs)
Definition: soda_spect.hpp:66
double marker_freq
Definition: soda_spect.hpp:120
double freq_span_disp
Definition: soda_spect.hpp:109
void replotXAxis()
Definition: soda_spect.cpp:134
double center_freq_in
Definition: soda_spect.hpp:103
FreqScaleDraw * freq_draw_p
Definition: soda_spect.hpp:122
void setFreqCenter(double cf, bool check_boundary=false)
Definition: soda_spect.cpp:148
void setMarkerOffset(double lo, double hi)
Definition: soda_spect.cpp:187
void setFreqMarker(double f)
Definition: soda_spect.cpp:194
double * vals
Definition: soda_spect.hpp:98
Spect(QWidget *parent=0)
Definition: soda_spect.cpp:39
void setDynamicRange(double drange)
Definition: soda_spect.cpp:116
double marker_hi_offset
Definition: soda_spect.hpp:117
QwtPlotCurve * curve_p
Definition: soda_spect.hpp:124
void replotYAxis()
Definition: soda_spect.cpp:122
void scrollRight(bool v)
Definition: soda_spect.hpp:69
void setRefLevel(int rlvl)
Definition: soda_spect.cpp:110
PlotPicker * picker_p
Definition: soda_spect.hpp:126
void xClick(double x)
double marker_lo_offset
Definition: soda_spect.hpp:116
double center_freq_disp
Definition: soda_spect.hpp:108
double correctCenterFreq(double cfreq)
Definition: soda_spect.cpp:156
void setFreqSpan(double fs, bool check_boundary=false)
Definition: soda_spect.cpp:167
void configureSpectrum(double cfreq, double span, long buckets)
Definition: soda_spect.cpp:214
void scrollLeft(bool v)
Definition: soda_spect.hpp:73
void pickPoint(const QPointF &pos)
Definition: soda_spect.cpp:180
double freq_span_in
Definition: soda_spect.hpp:104
QwtPlotGrid * grid_p
Definition: soda_spect.hpp:128
void resetFreqAxis(double cfreq)
Definition: soda_spect.cpp:204
double * freqs
Definition: soda_spect.hpp:97
double freqCenter()
Definition: soda_spect.hpp:57