-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyzerPlot.cpp
More file actions
129 lines (110 loc) · 3.52 KB
/
AnalyzerPlot.cpp
File metadata and controls
129 lines (110 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "AnalyzerPlot.h"
#include "frequencyplot.h"
#include <QWidget>
#include <qwt_scale_map.h>
#include <qwt_plot_grid.h>
#include <qwt_legend.h>
#include <qwt_math.h>
#include <qcolor.h>
#include <qpainter.h>
#include <qframe.h>
#include <qwt_plot_spectrogram.h>
#include <qwt_plot_canvas.h>
#include <QDebug>
#include <QTimer>
#include <QColorDialog>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
#include <qwt_curve_fitter.h>
#include <qwt_text.h>
AnalyzerPlotCurve::AnalyzerPlotCurve( const QString& name, FreqValues* pValues, QwtPlot* pPlot, const QColor& color )
: m_strName( name )
, m_pFreqValues( pValues )
{
m_pPlotCurve = new QwtPlotCurve( name );
m_pPlotCurve->attach( pPlot );
m_pPlotCurve->setPen(color);
m_pPlotCurve->setStyle(QwtPlotCurve::Lines);
}
AnalyzerPlotCurve::~AnalyzerPlotCurve(void)
{
delete m_pPlotCurve;
}
void AnalyzerPlotCurve::setColor( const QColor& color )
{
m_pPlotCurve->setPen(color);
}
void AnalyzerPlotCurve::Plot()
{
m_pPlotCurve->setSamples( m_pFreqValues->GetXValues(), m_pFreqValues->GetValues() );
}
QwtPlotCurve* AnalyzerPlotCurve::GetPlotCurve()
{
return m_pPlotCurve;
}
AnalyzerPlotBase::AnalyzerPlotBase( QWidget *parent, FrequencyPlot* pFreqencyPlot )
:QwtPlot( parent ),
m_pFrequencyPlot( pFreqencyPlot )
{
setAutoReplot();
canvas()->installEventFilter(parent);
setCanvasBackground(QColor(Qt::black));
QwtLegend* legend = new QwtLegend();
insertLegend( legend, QwtPlot::TopLegend);
//QObject::connect( this, SIGNAL(legendClicked(QwtPlotItem*) ), this, SLOT( legendClicked(QwtPlotItem *)) );
m_markerPeak1 = new QwtPlotMarker();
m_markerPeak1->setLineStyle( QwtPlotMarker::HLine );
m_markerPeak1->setLabelAlignment( Qt::AlignRight | Qt::AlignBottom );
m_markerPeak1->setLinePen( QColor( Qt::red ), 0, Qt::DashDotLine );
m_markerPeak1->attach( this );
m_markerPeak2 = new QwtPlotMarker();
m_markerPeak2->setLineStyle( QwtPlotMarker::HLine );
m_markerPeak2->setLabelAlignment( Qt::AlignRight | Qt::AlignBottom );
m_markerPeak2->setLinePen( QColor( Qt::red ), 0, Qt::DashDotLine );
m_markerPeak2->attach( this );
m_pTimer = new QTimer;
m_pTimer->setSingleShot(true);
}
void AnalyzerPlotBase::legendClicked(QwtPlotItem * plotItem)
{
QString name = plotItem->title().text();
QColorDialog dlgColor( plotItem->title().color() );
if( dlgColor.exec() == QDialog::Accepted )
{
m_pFrequencyPlot->ChangeCurveColor( dlgColor.currentColor(), name );
}
}
void AnalyzerPlotBase::showPeak( double freq1, double amplitude1, double freq2, double amplitude2 )
{
if( freq1 == 0 )
{
m_markerPeak1->setValue( 0.0, 0.0 );
m_markerPeak1->setLabel( QString("") );
}
else
{
QString label1;
label1.sprintf( "%.3f dB", amplitude1 );
QwtText text1( label1 );
text1.setFont( QFont( "Helvetica", 10, QFont::Bold ) );
text1.setColor( QColor( Qt::red ) );
m_markerPeak1->setValue( freq1, amplitude1 );
m_markerPeak1->setLabel( text1);
}
if( freq2 == 0 )
{
m_markerPeak2->setValue( 0.0, 0.0 );
m_markerPeak2->setLabel( QString("") );
}
else
{
QString label2;
label2.sprintf( "%.3f dB", amplitude2 );
QwtText text2( label2 );
text2.setFont( QFont( "Helvetica", 10, QFont::Bold ) );
text2.setColor( QColor( Qt::red ) );
m_markerPeak2->setValue( freq2, amplitude2 );
m_markerPeak2->setLabel( text2 );
}
}