forked from embeddedmz/QwtWaterfallplot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
139 lines (112 loc) · 3.62 KB
/
main.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <vector>
#include <qapplication.h>
#include <qmainwindow.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qcombobox.h>
#include <qslider.h>
#include <qlabel.h>
#include <qcheckbox.h>
#include <qprinter.h>
#include <qprintdialog.h>
#include <QThread>
#include <QVBoxLayout>
#include <qwt_color_map.h>
#include <qwt_plot_renderer.h>
#include "Waterfallplot.h"
class MainWindow: public QMainWindow
{
public:
MainWindow(QWidget * = NULL);
public slots:
#ifndef QT_NO_PRINTER
void printPlot();
#endif
void playData();
private:
Waterfallplot* m_waterfall = nullptr;
};
MainWindow::MainWindow( QWidget *parent ):
QMainWindow( parent )
{
srand(time(nullptr));
QWidget *centralWidget = new QWidget(this);
QVBoxLayout* layout = new QVBoxLayout(centralWidget);
layout->setSpacing(6);
layout->setContentsMargins(11, 11, 11, 11);
m_waterfall = new Waterfallplot(0, 500, 64, 126, centralWidget);
layout->addWidget(m_waterfall);
setCentralWidget(centralWidget);
// Toolbar
QToolBar *toolBar = new QToolBar( this );
#ifndef QT_NO_PRINTER
QToolButton *btnPrint = new QToolButton( toolBar );
btnPrint->setText( "Print" );
btnPrint->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
toolBar->addWidget( btnPrint );
connect( btnPrint, SIGNAL( clicked() ), this, SLOT( printPlot() ) );
toolBar->addSeparator();
#endif
QToolButton* btnPlayData = new QToolButton(toolBar);
btnPlayData->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
btnPlayData->setToolButtonStyle(Qt::ToolButtonIconOnly);
btnPlayData->setToolTip("Play 32 random data (layers) on the waterfall view.");
toolBar->addWidget(btnPlayData);
QObject::connect(btnPlayData, &QToolButton::clicked, this, &MainWindow::playData);
addToolBar(toolBar);
}
int main( int argc, char **argv )
{
QApplication a( argc, argv );
a.setStyle( "Windows" );
MainWindow mainWindow;
mainWindow.resize( 600, 400 );
mainWindow.show();
return a.exec();
}
#ifndef QT_NO_PRINTER
void MainWindow::printPlot()
{
QPrinter printer( QPrinter::HighResolution );
printer.setOrientation( QPrinter::Landscape );
printer.setOutputFileName( "waterfall.pdf" );
QPrintDialog dialog( &printer );
if (dialog.exec())
{
QwtPlotRenderer renderer;
if ( printer.colorMode() == QPrinter::GrayScale )
{
renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground );
renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground );
renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame );
renderer.setLayoutFlag( QwtPlotRenderer::FrameWithScales );
}
// how to render curve + spectro in the same file ?
renderer.renderTo( m_waterfall->getSpectrogramPlot(), printer );
}
}
#endif
void MainWindow::playData()
{
for (auto i = 0u; i < 32; ++i)
{
std::vector<float> dummyData(126);
std::generate(dummyData.begin(), dummyData.end(), []{ return (std::rand() % 256); });
const bool bRet = m_waterfall->addData(dummyData.data(), dummyData.size());
assert(bRet);
// set the range only once (data range)
static bool s_setRangeOnlyOnce = true;
if (s_setRangeOnlyOnce)
{
double dataRng[2];
m_waterfall->getDataRange(dataRng[0], dataRng[1]);
m_waterfall->setRange(dataRng[0], dataRng[1]);
s_setRangeOnlyOnce = false;
}
m_waterfall->replot(true); // true: force repaint
QThread::msleep(10);
}
}