{
painter.setWindow( 0, 0, 800, 200 );
painter.
setRenderHint( QPainter::Antialiasing,
true);
painter.
setPen(QPen(Qt
::black,
1, Qt
::SolidLine, Qt
::RoundCap, Qt
::MiterJoin));
int nGridStep = 20;
for( int x = 0; x <= 800 / nGridStep; x ++ )
{
painter.drawLine( x * nGridStep, 0, x * nGridStep, 200 );
}
for( int y = 0; y <= 200 / nGridStep; y ++ )
{
painter.drawLine( 0, y * nGridStep, 800, y * nGridStep );
}
painter.
setPen(QPen(Qt
::red,
3, Qt
::SolidLine, Qt
::RoundCap, Qt
::MiterJoin));
int nSpace = 0;
int nSpace2 = 0;
for( int i = 0; i < 48; i ++ ) // size of linear buffer
{
nSpace += nGridStep;
painter.drawLine( nSpace2, 200 - m_GraphArray[ i ], nSpace, 200 - m_GraphArray[ i + 1 ] );
nSpace2 += nGridStep;
}
}
void PlotterView::paintEvent( QPaintEvent *event)
{
QPainter painter(this);
painter.setWindow( 0, 0, 800, 200 );
painter.setRenderHint( QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
int nGridStep = 20;
for( int x = 0; x <= 800 / nGridStep; x ++ )
{
painter.drawLine( x * nGridStep, 0, x * nGridStep, 200 );
}
for( int y = 0; y <= 200 / nGridStep; y ++ )
{
painter.drawLine( 0, y * nGridStep, 800, y * nGridStep );
}
painter.setPen(QPen(Qt::red, 3, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
int nSpace = 0;
int nSpace2 = 0;
for( int i = 0; i < 48; i ++ ) // size of linear buffer
{
nSpace += nGridStep;
painter.drawLine( nSpace2, 200 - m_GraphArray[ i ], nSpace, 200 - m_GraphArray[ i + 1 ] );
nSpace2 += nGridStep;
}
}
To copy to clipboard, switch view to plain text mode
{
memcpy( m_GraphArray, &m_GraphArray[1], 50 * sizeof(unsigned int) ); // move entire array left one
m_GraphArray[50] = qrand() % 200;
repaint();
}
void PlotterView::timerEvent(QTimerEvent *event)
{
memcpy( m_GraphArray, &m_GraphArray[1], 50 * sizeof(unsigned int) ); // move entire array left one
m_GraphArray[50] = qrand() % 200;
repaint();
}
To copy to clipboard, switch view to plain text mode
Bookmarks