资源简介
通过串口读取外部设备上的温度,显示到QT界面上,还有曲线图。
代码片段和文件信息
#include “linegraphwidget.h“
LineGraphWidget::LineGraphWidget(int mix int max QWidget *parent) :
QWidget(parent)
rangeMin(mix)
rangeMax(max)
singleUnitX(20)
timer(NULL)
{
connect(thisSIGNAL(newDataCome())thisSLOT(update()));
}
void LineGraphWidget::paintEvent(QPaintEvent *)
{
int i;
int abcd;
Counter = 0;
QPixmap pix(widgetXwidgetY);
QPainter painter(&pix);
pix.fill(Qt::white);
QPen pen;
pen.setBrush(Qt::darkGreen);
painter.setPen(pen);
QPen pen1;
pen1.setBrush(Qt::black);
painter.setRenderHint(QPainter::Antialiasing);
for(i = 0;i < sumUnitX; ++i) {
a = basePoint.x + i*singleUnitX;
b = basePoint.y;
c= a;
d = yAxisEndPoint.y;
painter.drawLine(abcd);
}
for(i = 0; i < sumUnitY+1; ++i) {
a = basePoint.x;
b = basePoint.y - singleUnitY*i;
c = xAxisEndPoint.x;
d = b;
painter.drawLine(abcd);
}
painter.setPen(pen1);
for (i = 0;i < (sumUnitY/2+1);++i) {
QRectF rectF(0basePoint.y - singleUnitY*i*2 - 5basePoint.x(widgetY - basePoint.y)/3);
painter.drawText(rectFQt::AlignCenterQString::number(rangeMin+i*20));
}
for (i = 0;i < sumUnitX/5;++i) {
QRectF rectF(basePoint.x+singleUnitX*(5*i+3)basePoint.ysingleUnitX*4widgetY-basePoint.y);
painter.drawText(rectFQt::AlignCenterQString::number(0.5*(i+1)*singleUnitX));
}
int size = xList.size();
while(Counter < (size -1)) {
painter.drawLine(basePoint.x + xList.value(Counter)*singleUnitX
basePoint.y - ((yList.value(Counter) - rangeMin)/10.0)*singleUnitY
basePoint.x + xList.value(Counter + 1)*singleUnitX
basePoint.y - ((yList.value(Counter + 1) - rangeMin)/10.0)*singleUnitY);
Counter++;
}
painter.end();
painter.begin(this);
painter.drawPixmap(00pix);
painter.end();
Counter = 0;
}
void LineGraphWidget::resizeEvent(QResizeEvent * e)
{
if (e->oldSize() != size()) {
initGraph();
}
}
void LineGraphWidget::showData(const int &data)
{
//这里还要进行相关的数据正确性检测,不能超过图的范围
if (data > rangeMax || data < rangeMin) {
return;
}
int xsize = xList.size();
int yValue = data;
if (xsize == sumUnitX) {
xList.clear();
yList.clear();
xsize = xList.length();
}
if (xsize >= 1) {
xList.insert(xsizexsize);
yList.insert(xsizeyValue);
emit newDataCome();
}
else {
xList.insert(xsizexsize);
yList.insert(xsizeyValue);
}
}
void LineGraphWidget::getSumUnitX()
{
if ((static_cast(widgetX*0.85))%singleUnitX == 0){
sumUnitX = (static_cast(widgetX*0.85))/singleUnitX;
}
else {
sumUnitX = (static_cast(widgetX*0.85))/singleUnitX + 1;
}
}
void LineGraphWidget::getSingleUnitY()
{
int range = rangeMax - rangeMin;
if (range == 0) {
sumUnitY = range/10 + 1;
}
else {
sumUnitY = range/10 + 2;
}
singleUnitY = (static_cast(widgetY*0.85))/sumUnitY;
}
void LineGraphWidget::initGraph()
{
widgetX = size().width();
widgetY = size().height();
basePoint.x = static_cast(widgetX*0.1);
basePoint.y = sta
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3705 2013-03-22 15:40 qt_02\linegraphwidget.cpp
文件 1459 2013-03-21 16:18 qt_02\linegraphwidget.h
文件 10776 2013-03-22 15:40 qt_02\linegraphwidget.o
文件 179 2013-02-04 16:29 qt_02\main.cpp
文件 1592 2013-03-21 17:27 qt_02\main.o
文件 9368 2013-03-21 14:00 qt_02\Makefile
文件 3171 2013-03-21 17:27 qt_02\moc_linegraphwidget.cpp
文件 9104 2013-03-21 17:27 qt_02\moc_linegraphwidget.o
文件 3097 2013-03-21 17:27 qt_02\moc_qextserialba
文件 5568 2013-03-21 17:27 qt_02\moc_qextserialba
文件 2823 2013-03-21 17:27 qt_02\moc_widget.cpp
文件 6952 2013-03-21 17:27 qt_02\moc_widget.o
文件 38286 2013-02-21 21:22 qt_02\posix_qextserialport.cpp
文件 1934 2007-09-06 00:47 qt_02\posix_qextserialport.h
文件 18448 2013-03-21 17:27 qt_02\posix_qextserialport.o
文件 6528 2007-09-06 00:47 qt_02\qextserialba
文件 6873 2007-09-06 00:47 qt_02\qextserialba
文件 4912 2013-03-21 17:27 qt_02\qextserialba
文件 86158 2013-03-26 11:55 qt_02\qt
文件 522 2013-03-21 14:00 qt_02\qt.pro
文件 14079 2013-03-26 11:56 qt_02\qt.pro.user
文件 429 2013-03-04 14:35 qt_02\qt_new_interface.pro
文件 18360 2013-03-26 11:55 qt_02\ui_widget.h
文件 8333 2013-03-26 11:56 qt_02\wangning.xx
文件 3063 2013-03-26 11:50 qt_02\widget.cpp
文件 532 2013-03-21 16:59 qt_02\widget.h
文件 42864 2013-03-26 11:55 qt_02\widget.o
文件 33893 2013-03-26 11:55 qt_02\widget.ui
..AD... 0 2013-03-26 20:52 qt_02
----------- --------- ---------- ----- ----
............此处省略2个文件信息
- 上一篇:usb cdc 标准协议文档
- 下一篇:哈夫曼树与哈夫曼编码
评论
共有 条评论