-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathstreamchart.cpp
More file actions
65 lines (59 loc) · 1.5 KB
/
Copy pathstreamchart.cpp
File metadata and controls
65 lines (59 loc) · 1.5 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
#include "streamchart.h"
StreamChart::StreamChart(QWidget *parent) :
QWidget(parent)
{
penb=new QPen();
penb->setWidth(2);
pen1=new QPen();
pen1->setWidth(1);
pen2=new QPen();
pen2->setWidth(1);
queue=new QQueue<struct Data>();
}
StreamChart::~StreamChart()
{
delete penb;
delete pen1;
delete pen2;
delete queue;
}
void StreamChart::paintEvent(QPaintEvent *)
{
if(!queue->isEmpty())
{
QPainter pt(this);
//画背景
pt.fillRect(0,0,width,height,colorBackground);
int x,dy1,dy2;
//画线条
for(int i=0;i<queue->size();i++)
{
x=width-queue->size()+i;//+spacing;
dy1=queue->at(i).x*height/100;
dy1=(dy1==1?dy1+1:dy1);
dy2=queue->at(i).y*height/100;
//dy2=(dy2==1?dy2+1:dy2);
pen1->setColor(color1);
pt.setPen(*pen1);
pt.drawLine(x,height,x,height-dy1);
if(color2.alpha())
{
pen2->setColor(color2);
pt.setPen(*pen2);
pt.drawLine(x,height,x,height-dy2);
}
}
//最后画矩形
penb->setColor(colorBorder);
pt.setPen(*penb);
pt.drawRoundRect(0,0,width,height,borderRound,borderRound);
}
}
void StreamChart::updateChart(struct Data& data)
{
queue->enqueue(data);
setMinimumSize(width,height);
setMaximumSize(width,height);
if(queue->size()>width)queue->dequeue();
update();
}