天天看點

Qt 實作脈搏檢測-1-心跳曲線部分

先實作畫心跳曲線

如下圖

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.藍牙

大緻需要實作以上三種模式的資料擷取,目前沒有,還沒有搞到硬體,資料隻能模拟。

#include "get_date.h"  
#include <windows.h>  
#include <QDebug>  
#include <QTimer>  
#include <QSerialPort>  
QTimer timer;  
QSerialPort port;  
Get_date::Get_date()  
{  
    qDebug()<<"Qthread is run";  
  
}  
  
void Get_date::run()  
{  
    connect(&timer,SIGNAL(timeout()),this,SLOT(timerout()));  
    timer.start(50);  
}  
  
Get_date::~Get_date()  
{  
    timer.stop();  
    qDebug()<<"Qthread is exit";  
}  
  
void Get_date::timerout()  
{  
    emit send_date(rand()%300);  
}        

這部分了,就是線程中模拟擷取資料的部分,采到資料後通過信号槽發送給GUI程序。

#include "palmus.h"  
#include "ui_palmus.h"  
#include <QPalette>  
#include <QDebug>  
#include <list>  
#include <windows.h>  
using namespace std;  
typedef list<int> LISTINT;  
static LISTINT listdate;  
static LISTINT::iterator i,j;  
Palmus::Palmus(QWidget *parent) :  
    QWidget(parent),  
    ui(new Ui::Palmus)  
{  
    ui->setupUi(this);  
    this->setWindowTitle("Palmus");  
    QPalette palette;  
    palette.setColor(QPalette::Background,QColor(0,0,0));  
    this->setPalette(palette);  
    connect(&Demodate,SIGNAL(send_date(int)),this,SLOT(slot_get_date(int)));  
    Demodate.run();  
  
}  
  
Palmus::~Palmus()  
{  
    Demodate.exit(1);  
    delete ui;  
}  
void Palmus::slot_get_date(int temp)  
{  
    listdate.push_front(temp);  
    qDebug()<<listdate.size();  
    update();  
    if(listdate.size()>1000)  
    {  
        listdate.pop_back();  
    }  
}  
static int temp1;  
static int temp2;  
void Palmus::paintEvent(QPaintEvent *)  
{  
  
    //Draw scale  
    QPainter painter_scale(this);  
    painter_scale.setPen(Qt::white);  
    painter_scale.setRenderHints(QPainter::Antialiasing,true);  
    int scale_x = this->width();  
    int scale_y = this->height();  
    painter_scale.drawLine(0,0,0,scale_y);  
    painter_scale.drawLine(0,scale_y,scale_x,scale_y);  
    while (scale_y>0)  
    {  
       painter_scale.drawLine(0,scale_y,5,scale_y);  
       scale_y = scale_y-10;  
    }  
    scale_x = 0;  
    scale_y = this->height();  
    while (scale_x<(this->width()))  
    {  
        painter_scale.drawLine(scale_x,scale_y,scale_x,scale_y-5);  
        scale_x= scale_x+10;  
    }  
  
  
  
  
    //Draw palmus  
    QPainter painter(this);  
    painter.setRenderHints(QPainter::Antialiasing,true);  
    painter.setPen(Qt::red);  
    int x = this->width();  
    i = listdate.begin();  
    temp1 = *i;  
    for(i=listdate.begin();i!=listdate.end();i=i.operator ++(1))  
    {  
        j=i.operator ++(1);  
  
        temp2 =  *j;  
        painter.drawLine(x,temp1,x-20,temp2);  
        temp1 = temp2;  
        x=x-20;  
    }  
}        

部分就是GUI住程序的函數了,主要還是等于重載了paintevent()函數

函數中第一份是畫刻度,現在還在想真麼畫好看

第二部分是畫心跳曲線

//Draw palmus  
    QPainter painter(this);  
    painter.setRenderHints(QPainter::Antialiasing,true);  
    painter.setPen(Qt::red);  
    int x = this->width();  
    i = listdate.begin();  
    temp1 = *i;  
    for(i=listdate.begin();i!=listdate.end();i=i.operator ++(1))  
    {  
        j=i.operator ++(1);  
  
        temp2 =  *j;  
        painter.drawLine(x,temp1,x-20,temp2);  
        temp1 = temp2;  
        x=x-20;  
    }        

心跳曲線部分代碼,其實主要就是畫線,每一段線連起來,就是曲線了,剩下的代碼在後面慢慢貼出來

繼續閱讀