#include "history.h"
#include "qdebug.h"
history::history()
{
file1.setFileName("D:/QT5.5things/object/history1.txt");
file2.setFileName("D:/QT5.5things/object/history2.txt");
}
history::~history()
{
file1.close();
file2.close();
}
QVector<double> history::viewing_beginner1()
{
file1.close();
file2.close();
if(!file1.isOpen())
file1.open(QIODevice::ReadWrite| QIODevice::Text);
filedata1=file1.readAll();
//qDebug()<<filedata1.size();
//file1.close();
totalpage1=(filedata1.size()/8000)+1;
currentpage1=1;
historylistdata1.clear();
if(!movecounter1)
movecounter1=0;
int counter1=0;
QVector<double> historytopaint1; // 存储业务数据的 lis
while (counter1<1000)
{
historylistdata1<<filedata1.left(8).toFloat();
filedata1.remove(0,8);
counter1++;
}
for(movecounter1=0;movecounter1<1000;movecounter1++)
{ historytopaint1<<historylistdata1[movecounter1];
}
QVector<double> historytopaint=historytopaint1;
//qDebug()<<historytopaint.size();
return historytopaint;
}
QVector<double> history::viewing_beginner2()
{
file2.close();
if(!file2.isOpen())
file2.open(QIODevice::ReadWrite | QIODevice::Text);
filedata2=file2.readAll();
//file2.close();
totalpage2=(filedata2.size()/8000)+1;
currentpage2=1;
historylistdata2.clear();
if(!movecounter2)
movecounter2=0;
int counter2=0;
QVector<double> historytopaint2;//存储业务数据的 list
while (counter2<1000)
{
historylistdata2<<filedata2.left(8).toFloat();
filedata2.remove(0,8);
counter2++;
}
for(movecounter2=0;movecounter2<1000;movecounter2++)
{
historytopaint2<<historylistdata2[movecounter2];
}
QVector<double> historytopaint=historytopaint2;
return historytopaint;
}
void history::file_writer(int who, QByteArray dataTOfile)
{
if(who==1)
{
if(!file1.isOpen())
file1.open(QIODevice::WriteOnly | QIODevice::Text);
file1.write(dataTOfile);
//file1.close();
}
if(who==2)
{
if(!file2.isOpen())
file2.open(QIODevice::WriteOnly | QIODevice::Text);
file2.write(dataTOfile);
// file2.close();
}
}
void history::clearHistory()
{
file1.resize(0);
file2.resize(0);
}
QVector<double> history::nextPage1()
{
if(currentpage1==totalpage1)
{
qDebug() <<"当前已是通道1最新数据";
return next_container1;
}
else
{
if(currentpage1!=totalpage1)
currentpage1++;
int counter1=0;
int paintcounter1=0;
QVector<double> historytopaint1; // 存储业务数据的 list
while (counter1<1000)
{
historylistdata1<<filedata1.left(8).toFloat();
filedata1.remove(0,8);
counter1++;
if(filedata1.size()<8)
break;
}
for(;paintcounter1<1000&&movecounter1<=(historylistdata1.size()-1);movecounter1++)
{
historytopaint1<<historylistdata1.at(movecounter1);
paintcounter1++;
}
next_container1=historytopaint1;
return next_container1;
}
}
QVector<double> history::nextPage2()
{
if(currentpage2==totalpage2)
{
qDebug() <<"当前已是通道2最新数据";
return next_container2;
}
else
{
if(currentpage2!=totalpage2)
currentpage2++;
int counter2=0;
int paintcounter2=0;
QVector<double> historytopaint2; // 存储业务数据的 list
while (counter2<1000)
{
historylistdata2<<filedata2.left(8).toFloat();
filedata2.remove(0,8);
counter2++;
if(filedata2.size()<8)
break;
}
for(;paintcounter2<1000&&movecounter2<=(historylistdata2.size()-1);movecounter2++)
{
historytopaint2<<historylistdata2.at(movecounter2);
paintcounter2++;
}
next_container2=historytopaint2;
return next_container2;
}
}
QVector<double> history::lastPage1()
{
if(currentpage1==1)
{
qDebug() <<"当前已是通道1最早数据";
return last_container1;
}
else
{
if(currentpage1>1)
currentpage1--;
QVector<double> historytopaint1; // 存储业务数据的 list
int paintcounter1=0;
if(historylistdata1.size()%1000)
{
for( movecounter1=movecounter1-1-1000-(historylistdata1.size()-(historylistdata1.size()/1000)*1000);paintcounter1<1000;movecounter1++)
{
historytopaint1<<historylistdata1.at( movecounter1);
paintcounter1++;
}
}
else
{
for( movecounter1=movecounter1-2*1000+1;paintcounter1<1000;movecounter1++)
{
historytopaint1<<historylistdata1.at( movecounter1);
paintcounter1++;
}
}
last_container1=historytopaint1;
return last_container1;
}
}
QVector<double> history::lastPage2()
{
if(currentpage2==1)
{
qDebug() <<"当前已是通道2最早数据";
return last_container2;
}
else
{
if(currentpage2>1)
currentpage2--;
QVector<double> historytopaint2; // 存储业务数据的 list
int paintcounter2=0;
if(historylistdata2.size()%1000)
{
for( movecounter2=movecounter2-1-1000-(historylistdata2.size()-(historylistdata2.size()/1000)*1000);paintcounter2<1000;movecounter2++)
{
historytopaint2<<historylistdata2.at( movecounter2);
paintcounter2++;
}
}
else
{
for( movecounter2=movecounter2-2*1000+1;paintcounter2<1000;movecounter2++)
{
historytopaint2<<historylistdata2.at( movecounter2);
paintcounter2++;
}
}
last_container2=historytopaint2;
return last_container2;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
QT实时绘制串口数据
共21个文件
cpp:9个
h:8个
ui:2个
需积分: 50 180 下载量 152 浏览量
2018-07-20
22:22:04
上传
评论 22
收藏 14KB ZIP 举报
温馨提示
采用多线程方法,主线程解析数据和绘图,子线程接收数据,QWT绘图,有历史回顾功能
资源推荐
资源详情
资源评论
收起资源包目录
object.zip (21个子文件)
object
processdata.cpp 4KB
asker.cpp 410B
serialport.cpp 2KB
object.pro.user 18KB
processdata.h 792B
file.cpp 1KB
painter.cpp 946B
widget.ui 5KB
readportthread.cpp 310B
file.h 432B
history.h 972B
painter.h 703B
main.cpp 193B
serialport.h 717B
asker.h 414B
object.pro 864B
asker.ui 1KB
widget.cpp 6KB
widget.h 1KB
readportthread.h 456B
history.cpp 6KB
共 21 条
- 1
资源评论
birdexplore
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功