#ifndef DIALOG_H
#define DIALOG_H
#include <QtGui>
class myDialog : public QDialog
{
Q_OBJECT
public:
myDialog(QWidget *parent = 0);
~myDialog();
protected:
void paintEvent(QPaintEvent *event);
private slots:
void flushBuff();
private:
enum { Margin = 20 };
int maxY;
int numYticks;
int minY;
int maxX;
int minX;
int numXticks;
unsigned int drawdata[750];
QTimer *timer;
};
#endif // DIALOG_H
#include "dialog.h"
myDialog::myDialog(QWidget *parent)
: QDialog(parent)
{
setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
setBackgroundRole(QPalette::Dark);
resize(320, 240);
setWindowTitle(tr("Paint Demo"));
minX=0;
minY=0;
maxX=500;
maxY=0xffffff;
numXticks=5;
numYticks=5;
QTimer *timer = new QTimer(this);
connect( timer, SIGNAL(timeout()), this, SLOT(flushBuff()));
timer->start( 20 );
unsigned int buffer[750];
QFile file(":/mydata.txt");
if(file.open(QIODevice::ReadOnly)){
int j=0;
QTextStream in(&file);
while(!in.atEnd()){
QString line=in.readLine();
QString rmstr("0x");
line=line.remove(rmstr);
//QStringList items=line.split(",",QString::SkipEmptyParts);
QStringList items=line.split(" ",QString::SkipEmptyParts);
qDebug()<<items.count()<<endl;
bool OK;
for(int i=0;i<items.count();i++)
{
buffer[i+j*15]=items[i].toUInt(&OK,16);
}
j++;
}
}
else
qDebug()<<"files open error!"<<endl;
for(int i=0;i<250;i++)
{
drawdata[i]=(buffer[3*i]<<16)+(buffer[3*i+1]<<8)+(buffer[3*i+2]);
}
}
myDialog::~myDialog()
{
}
void myDialog::flushBuff(){
unsigned int tmp = drawdata[0];
int i;
for( i=0; i<249; i++ ) {
drawdata[i] = drawdata[i+1];
}
drawdata[249] = tmp;
update();
}
void myDialog::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QRect rect(2*Margin, Margin,width() - 3 * Margin, height() - 4 * Margin);
if (!rect.isValid())
return;
QPen quiteDark = palette().dark().color().light();
QPen light = palette().light().color();
for (int i = 0; i <= numXticks; ++i) {
int x = rect.left() + (i * (rect.width() - 1)
/ numXticks);
painter.setPen(quiteDark);
painter.drawLine(x, rect.top(), x, rect.bottom());
painter.setPen(light);
painter.drawLine(x, rect.bottom(), x, rect.bottom() + 5);
painter.drawText(x, rect.bottom() + 5, Margin - 5, Margin,
Qt::AlignHCenter | Qt::AlignTop,
QString::number(i));
}
int y;
for (int j = 0; j <= numYticks; ++j) {
y = rect.bottom() - (j * (rect.height() - 1)
/ numYticks);
painter.setPen(quiteDark);
painter.drawLine(rect.left(), y, rect.right(), y);
painter.setPen(light);
painter.drawLine(rect.left() - 5, y, rect.left(), y);
painter.drawText(rect.left() - Margin, y - 10, Margin - 5, Margin,
Qt::AlignRight | Qt::AlignVCenter,
QString::number(j));
}
QPoint points[240];
for(int i=0;i<240;i++)
{
points[i].setX(i+rect.left());
points[i].setY(drawdata[i]*(rect.height())/maxY+rect.top()+y*2);
}
painter.setPen(Qt::blue);
painter.drawPoints(points, 240);
}
#include "dialog.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
myDialog w;
w.show();
return a.exec();
}
mydata.txt
33 33 33 34 7c 93 35 c5 bd 37 e 7e 38 56 9f
39 9d eb 3a e4 2d 3c 29 31 3d 6c c2 3e ae ac
3f ee bb 41 2c bb 42 68 78 43 a1 c0 44 d8 60
46 c 25 47 3c de 48 6a 5a 49 94 67 4a ba d7
4b dd 78 4c fc 1c 4e 16 96 4f 2c b6 50 3e 50
51 4b 38 52 53 43 53 56 45 54 54 15 55 4c 8a
56 3f 7b 57 2c c2 58 14 37 58 f5 b6 59 d1 1b
5a a6 40 5b 75 5 5c 3d 48 5c fe e8 5d b9 c6
5e 6d c4 5f 1a c4 5f c0 ab 60 5f 5e 60 f6 c4
61 86 c3 62 f 44 62 90 32 63 9 78 63 7b 1
63 e4 bc 64 46 98 64 a0 84 64 f2 72 65 3c 56
65 7e 22 65 b7 cc 65 e9 4c 66 12 98 66 33 ab
66 4c 7f 66 5d 10 66 65 5b 66 65 5f 66 5d 1b
66 4c 93 66 33 c7 66 12 bc 65 e9 77 65 b7 ff
65 7e 5c 65 3c 98 64 f2 bc 64 a0 d5 64 46 f0
63 e5 1c 63 7b 69 63 9 e6 62 90 a8 62 f c1
61 87 47 60 f7 4f 60 5f f1 5f c1 44 5f 1b 64
5e 6e 6a 5d ba 73 5c ff 9b 5c 3e 2 5b 75 c5
5a a7 7 59 d1 e7 58 f6 88 58 15 f 57 2d 9f
56 40 5e 55 4d 72 54 55 2 53 57 37 52 54 3a
51 4c 34 50 3f 50 4f 2d ba 4e 17 9e 4c fd 29
4b de 88 4a bb eb 49 95 7f 48 6b 75 47 3d fc
46 d 46 44 d9 83 43 a2 e6 42 69 a1 41 2d e6
3f ef e8 3e af db 3d 6d f3 3c 2a 63 3a e5 61
39 9f 1f 38 57 d4 37 f b4 35 c6 f4 34 7d c9
33 34 69 31 eb 9 30 a1 de 2f 59 1d 2e 10 fc
2c c9 af 2b 83 6b 2a 3e 66 28 fa d3 27 b8 e8
26 78 d7 25 3a d5 23 ff 16 22 c5 cc 21 8f 29
20 5b 61 1f 2a a5 1d fd 26 1c d3 15 1b ac a3
1a 89 fe 19 6b 55 18 50 d8 17 3a b4 16 29 15
15 1c 28 14 14 19 13 11 12 12 13 3d 11 1a c3
10 27 cd f 3a 81 e 53 6 d 71 81 c 96 17
b c0 eb a f2 20 a 29 d7 9 68 31 8 ad 4d
7 f9 48 7 4c 41 6 a6 53 6 7 99 5 70 2d
4 e0 27 4 57 9e 3 d6 a9 3 5d 5c 2 eb cc
2 82 9 2 20 26 1 c6 32 1 74 3c 1 2a 52
0 e8 7e 0 ae cb 0 7d 44 0 53 f0 0 32 d5
0 19 fa 0 9 61 0 1 e 0 1 3 0 9 3e
0 19 bf 0 32 83 0 53 87 0 7c c4 0 ae 34
0 e7 cf 1 29 8c 1 73 60 1 c5 3f 2 1f 1c
2 80 e9 2 ea 95 3 5c 10 3 d5 47 4 56 27
4 de 9a 5 6e 8b 6 5 e2 6 a4 88 7 4a 61
7 f7 55 8 ab 45 9 66 16 a 27 aa a ef e0
b be 99 c 93 b2 d 6f b e 50 7f f 37 e9
10 25 25 11 18 c 12 10 76 13 e 3c 14 11 35
15 19 36 16 26 15 17 37 a7 18 4d be 19 68 30
1a 86 cc 1b a9 66 1c cf cf 1d f9 d6 1f 27 4b
20 57 fe 21 8b be 22 c2 58 23 fb 9b 25 37 54
26 75 50 27 b5 5b 28 f7 41 2a 3a d0 2b 7f d1
2c c6 11 2e d 5c 2f 55 7b 30 9e 3b 31 e7 65