-
Notifications
You must be signed in to change notification settings - Fork 22
/
mainwindow.cpp
78 lines (63 loc) · 2.22 KB
/
mainwindow.cpp
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
#include "mainwindow.h"
#include "plot.h"
#include "knob.h"
#include "wheelbox.h"
#include <qwt_scale_engine.h>
#include <qlabel.h>
#include <qlayout.h>
MainWindow::MainWindow( QWidget *parent ):
QWidget( parent )
{
const double intervalLength = 1.0; // seconds
/* 实例化主窗口的各种控件 */
d_plot = new Plot( this );
d_plot->setIntervalLength( intervalLength );
d_amplitudeKnob = new Knob( "Amplitude", 0.0, 200.0, this );
d_amplitudeKnob->setValue( 100.0 );
d_frequencyKnob = new Knob( "Frequency [Hz]", 0.1, 20.0, this );
d_frequencyKnob->setValue( 10.0 );
d_intervalWheel = new WheelBox( "Displayed [s]", 1.0, 100.0, 1.0, this );
d_intervalWheel->setValue( intervalLength );
d_timerWheel = new WheelBox( "Sample Interval [ms]", 0.0, 20.0, 0.1, this );
d_timerWheel->setValue( 1.0 );
//主窗口布局
QVBoxLayout* vLayout1 = new QVBoxLayout();
vLayout1->addWidget( d_intervalWheel );
vLayout1->addWidget( d_timerWheel );
vLayout1->addStretch( 10 );
vLayout1->addWidget( d_amplitudeKnob );
vLayout1->addWidget( d_frequencyKnob );
//主窗口布局
QHBoxLayout *layout = new QHBoxLayout( this );
layout->addWidget( d_plot, 10 );
layout->addLayout( vLayout1 );
/* 一个信号可以连接到另一个信号,用来传递一个信号 */
connect( d_amplitudeKnob, SIGNAL( valueChanged( double ) ),
SIGNAL( amplitudeChanged( double ) ) );
connect( d_frequencyKnob, SIGNAL( valueChanged( double ) ),
SIGNAL( frequencyChanged( double ) ) );
connect( d_timerWheel, SIGNAL( valueChanged( double ) ),
SIGNAL( signalIntervalChanged( double ) ) );
/*
* 连接采样间隔调节齿轮箱的valueChanged信号与画波形控件
* d_plot的槽函数setIntervalLength用来设置采样间隔长度
*/
connect( d_intervalWheel, SIGNAL( valueChanged( double ) ),
d_plot, SLOT( setIntervalLength( double ) ) );
}
void MainWindow::start()
{
d_plot->start();
}
double MainWindow::frequency() const
{
return d_frequencyKnob->value();
}
double MainWindow::amplitude() const
{
return d_amplitudeKnob->value();
}
double MainWindow::signalInterval() const
{
return d_timerWheel->value();
}