1 Star 0 Fork 3

星梦/dde-sys-monitor-plugin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
streamchart.cpp 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
juju 提交于 2020-07-21 20:46 . add chart mode;rebuid code structure
#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();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/manymobi/dde-sys-monitor-plugin.git
git@gitee.com:manymobi/dde-sys-monitor-plugin.git
manymobi
dde-sys-monitor-plugin
dde-sys-monitor-plugin
master

搜索帮助