Qt 实现脉搏检测-1-心跳曲线部分

来源:互联网 发布:linux 改主机名 编辑:程序博客网 时间:2024/06/08 15:49

Qt 实现脉搏检测-1-心跳曲线部分

   

最新的想法就是写一个显示脉搏的东西,主要就是通过串口读取硬件(检测心跳的)传来的数据,在显示一下。

先实现画心跳曲线

如下图


先来电干货,

首先,在这个代码中,第一次用到了list这个东东


所以,关于list这个东东就得说道说道


上参考连接:http://blog.csdn.net/lskyne/article/details/10418823


大神写的很好,这里贴出关于list的部分函数。


assign() 给list赋值 
back() 返回最后一个元素 
begin() 返回指向第一个元素的迭代器 
clear() 删除所有元素 
empty() 如果list是空的则返回true 
end() 返回末尾的迭代器 
erase() 删除一个元素 
front() 返回第一个元素 
get_allocator() 返回list的配置器 
insert() 插入一个元素到list中 
max_size() 返回list能容纳的最大元素数量 
merge() 合并两个list 
pop_back() 删除最后一个元素 
pop_front() 删除第一个元素 
push_back() 在list的末尾添加一个元素 
push_front() 在list的头部添加一个元素 
rbegin() 返回指向第一个元素的逆向迭代器 
remove() 从list删除元素 
remove_if() 按指定条件删除元素 
rend() 指向list末尾的逆向迭代器 
resize() 改变list的大小 
reverse() 把list的元素倒转 
size() 返回list中的元素个数 
sort() 给list排序 
splice() 合并两个list 
swap() 交换两个list 
unique() 删除list中重复的元素


剩下的demo就需要到大神贴子下面去看了



第一部分:数据来源


单起一个线程专门来获取数据,现在数据来源应该来之

1.串口

2.无线网络

3.蓝牙

大致需要实现以上三种模式的数据获取,目前没有,还没有搞到硬件,数据只能模拟。

[cpp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. #include "get_date.h"    
  2. #include <windows.h>    
  3. #include <QDebug>    
  4. #include <QTimer>    
  5. #include <QSerialPort>    
  6. QTimer timer;    
  7. QSerialPort port;    
  8. Get_date::Get_date()    
  9. {    
  10.     qDebug()<<"Qthread is run";    
  11.     
  12. }    
  13.     
  14. void Get_date::run()    
  15. {    
  16.     connect(&timer,SIGNAL(timeout()),this,SLOT(timerout()));    
  17.     timer.start(50);    
  18. }    
  19.     
  20. Get_date::~Get_date()    
  21. {    
  22.     timer.stop();    
  23.     qDebug()<<"Qthread is exit";    
  24. }    
  25.     
  26. void Get_date::timerout()    
  27. {    
  28.     emit send_date(rand()%300);    
  29. }    

这部分了,就是线程中模拟获取数据的部分,采到数据后通过信号槽发送给GUI进程。

[cpp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. #include "palmus.h"    
  2. #include "ui_palmus.h"    
  3. #include <QPalette>    
  4. #include <QDebug>    
  5. #include <list>    
  6. #include <windows.h>    
  7. using namespace std;    
  8. typedef list<int> LISTINT;    
  9. static LISTINT listdate;    
  10. static LISTINT::iterator i,j;    
  11. Palmus::Palmus(QWidget *parent) :    
  12.     QWidget(parent),    
  13.     ui(new Ui::Palmus)    
  14. {    
  15.     ui->setupUi(this);    
  16.     this->setWindowTitle("Palmus");    
  17.     QPalette palette;    
  18.     palette.setColor(QPalette::Background,QColor(0,0,0));    
  19.     this->setPalette(palette);    
  20.     connect(&Demodate,SIGNAL(send_date(int)),this,SLOT(slot_get_date(int)));    
  21.     Demodate.run();    
  22.     
  23. }    
  24.     
  25. Palmus::~Palmus()    
  26. {    
  27.     Demodate.exit(1);    
  28.     delete ui;    
  29. }    
  30. void Palmus::slot_get_date(int temp)    
  31. {    
  32.     listdate.push_front(temp);    
  33.     qDebug()<<listdate.size();    
  34.     update();    
  35.     if(listdate.size()>1000)    
  36.     {    
  37.         listdate.pop_back();    
  38.     }    
  39. }    
  40. static int temp1;    
  41. static int temp2;    
  42. void Palmus::paintEvent(QPaintEvent *)    
  43. {    
  44.     
  45.     //Draw scale    
  46.     QPainter painter_scale(this);    
  47.     painter_scale.setPen(Qt::white);    
  48.     painter_scale.setRenderHints(QPainter::Antialiasing,true);    
  49.     int scale_x = this->width();    
  50.     int scale_y = this->height();    
  51.     painter_scale.drawLine(0,0,0,scale_y);    
  52.     painter_scale.drawLine(0,scale_y,scale_x,scale_y);    
  53.     while (scale_y>0)    
  54.     {    
  55.        painter_scale.drawLine(0,scale_y,5,scale_y);    
  56.        scale_y = scale_y-10;    
  57.     }    
  58.     scale_x = 0;    
  59.     scale_y = this->height();    
  60.     while (scale_x<(this->width()))    
  61.     {    
  62.         painter_scale.drawLine(scale_x,scale_y,scale_x,scale_y-5);    
  63.         scale_x= scale_x+10;    
  64.     }    
  65.     
  66.     
  67.     
  68.     
  69.     //Draw palmus    
  70.     QPainter painter(this);    
  71.     painter.setRenderHints(QPainter::Antialiasing,true);    
  72.     painter.setPen(Qt::red);    
  73.     int x = this->width();    
  74.     i = listdate.begin();    
  75.     temp1 = *i;    
  76.     for(i=listdate.begin();i!=listdate.end();i=i.operator ++(1))    
  77.     {    
  78.         j=i.operator ++(1);    
  79.     
  80.         temp2 =  *j;    
  81.         painter.drawLine(x,temp1,x-20,temp2);    
  82.         temp1 = temp2;    
  83.         x=x-20;    
  84.     }    
  85. }    

这部分就是GUI住进程的函数了,主要还是等于重载了paintevent()函数


函数中第一份是画刻度,现在还在想真么画好看

第二部分是画心跳曲线

[cpp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. //Draw palmus    
  2.     QPainter painter(this);    
  3.     painter.setRenderHints(QPainter::Antialiasing,true);    
  4.     painter.setPen(Qt::red);    
  5.     int x = this->width();    
  6.     i = listdate.begin();    
  7.     temp1 = *i;    
  8.     for(i=listdate.begin();i!=listdate.end();i=i.operator ++(1))    
  9.     {    
  10.         j=i.operator ++(1);    
  11.     
  12.         temp2 =  *j;    
  13.         painter.drawLine(x,temp1,x-20,temp2);    
  14.         temp1 = temp2;    
  15.         x=x-20;    
  16.     }    

心跳曲线部分代码,其实主要就是画线,每一段线连起来,就是曲线了,剩下的代码在后面慢慢贴出来

0 0
原创粉丝点击