Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
| 1 | #include "signaldisplay.h" |
| 2 | #include <QtGui> |
| 3 | #include <QDebug> |
| 4 | |
| 5 | SignalDisplay::SignalDisplay(QWidget *&parent):QWidget(parent) |
| 6 | { |
| 7 | secsPerDiv = 1.0/600.0; |
| 8 | voltsPerDiv = 20; |
| 9 | numSig=2; |
| 10 | setPointsPerPlot(10); |
| 11 | } |
| 12 | |
| 13 | void SignalDisplay::setNumSig(int value) |
| 14 | { |
| 15 | numSig = value; |
| 16 | setPointsPerPlot(pointsPerPlot); |
| 17 | } |
| 18 | |
| 19 | void SignalDisplay::setPointsPerPlot(int value) |
| 20 | { |
| 21 | pointsPerPlot = value; |
| 22 | waves = new QPoint *[numSig]; |
| 23 | secsIdx=new int[numSig]; |
| 24 | colorTraces = new QColor[numSig]; |
| 25 | int numT=(255/(numSig+1)); |
| 26 | for(int i=0;i<numSig;i++) |
| 27 | { |
| 28 | waves[i] = new QPoint [pointsPerPlot]; |
| 29 | secsIdx[i]=0; |
| 30 | colorTraces[i]=qRgb(numT*(i%numSig),numT*(i%numSig),numT*(i%numSig)); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | void SignalDisplay::drawGrid(QPainter &p, QColor colorGrid, int x, int y, int w, int h, int nx, int ny){ |
| 35 | p.setPen(colorGrid); |
| 36 | for (int ix= 0; ix<nx; ix++){ |
| 37 | int x = ix*w/nx; |
| 38 | p.drawLine(x,0,x,h); |
| 39 | } |
| 40 | for (int iy = 0; iy < ny; iy++){ |
| 41 | int y = iy*h/ny; |
| 42 | p.drawLine(0,y,w,y); |
| 43 | } |
| 44 | } |
| 45 | void SignalDisplay::paintEvent(QPaintEvent *event){ |
| 46 | QPainter painter(this); |
| 47 | w = width(); |
| 48 | h = height(); |
| 49 | ox = w; |
| 50 | oy = h; |
| 51 | painter.fillRect(0,0,w,h,Qt::white); |
| 52 | drawGrid(painter, Qt::lightGray,0,0,w,h,5, 10); |
| 53 | for(int i=0; i<numSig; i++) |
| 54 | { |
| 55 | painter.setPen(colorTraces[i]); |
| 56 | painter.drawPolyline(waves[i],pointsPerPlot); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void SignalDisplay::addPoints(int idx, int value) |
| 61 | { |
| 62 | waves[idx][secsIdx[idx]] = QPoint(secsIdx[idx]*w/10/60.0/pointsPerPlot/secsPerDiv+w/(2*pointsPerPlot), \ |
| 63 | oy-value*h/voltsPerDiv/10); |
| 64 | secsIdx[idx] = (secsIdx[idx]+1) % pointsPerPlot; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | //EOF |
| 69 |
Branches:
master
