//class MPlotWaveCurve inherit from QwtPlotCurve
void MPlotWaveCurve
::drawCurve(QPainter * painter,
int style,
const QRectF & canvasRect,
int from,
int to
) const {
switch (style)
{
case Lines:
if (testCurveAttribute(Fitted))
{
// we always need the complete
// curve for fitting
from = 0;
to = dataSize() - 1;
}
/*
below 10 lines code achieved my effect,
variable m_iEaserCount represents the erased width,
variable m_iCurrentPoint represents the latest data index
*/
if ((from < m_iCurrentPoint) && (m_iCurrentPoint < to - m_iEaserCount))
{
drawLines(painter, xMap, yMap, canvasRect, from, m_iCurrentPoint);
drawLines(painter, xMap, yMap, canvasRect, m_iCurrentPoint + m_iEaserCount, to);
}
else
{
drawLines(painter, xMap, yMap, canvasRect, from, m_iCurrentPoint);
}
break;
case Sticks:
drawSticks(painter, xMap, yMap, canvasRect, from, to);
break;
case Steps:
drawSteps(painter, xMap, yMap, canvasRect, from, to);
break;
case Dots:
drawDots(painter, xMap, yMap, canvasRect, from, to);
break;
case NoCurve:
default:
break;
}
}
//class MPlotWaveCurve inherit from QwtPlotCurve
void MPlotWaveCurve::drawCurve(QPainter * painter, int style,
const QwtScaleMap & xMap, const QwtScaleMap & yMap,
const QRectF & canvasRect, int from, int to) const
{
switch (style)
{
case Lines:
if (testCurveAttribute(Fitted))
{
// we always need the complete
// curve for fitting
from = 0;
to = dataSize() - 1;
}
/*
below 10 lines code achieved my effect,
variable m_iEaserCount represents the erased width,
variable m_iCurrentPoint represents the latest data index
*/
if ((from < m_iCurrentPoint) && (m_iCurrentPoint < to - m_iEaserCount))
{
drawLines(painter, xMap, yMap, canvasRect, from, m_iCurrentPoint);
drawLines(painter, xMap, yMap, canvasRect, m_iCurrentPoint + m_iEaserCount, to);
}
else
{
drawLines(painter, xMap, yMap, canvasRect, from, m_iCurrentPoint);
}
break;
case Sticks:
drawSticks(painter, xMap, yMap, canvasRect, from, to);
break;
case Steps:
drawSteps(painter, xMap, yMap, canvasRect, from, to);
break;
case Dots:
drawDots(painter, xMap, yMap, canvasRect, from, to);
break;
case NoCurve:
default:
break;
}
}
To copy to clipboard, switch view to plain text mode
void Plot::updateCurve(int index)
{
CurveData *curveData = static_cast<CurveData *>( d_curve[index]->data() );
curveData->lock();
int iCurrentPoint = curveData->getCurrentPointIndex();//Get the index number of the latest data in the container, starting from 0
int iMaxPointCount = curveData->getMaxPointCount();//Get the capacity of a container
int size = curveData->size();//Get the current size of the container
if(iCurrentPoint == m_iLastPaintedPoint)
{
curveData->unlock();
return;
}
QRect canvasRect
= canvas
()->contentsRect
();
QRegion region;
//Save the area to be redrawn const QwtScaleMap xMap
= canvasMap
( d_curve
[index
]->xAxis
() );
const QwtScaleMap yMap
= canvasMap
( d_curve
[index
]->yAxis
() );
//Get the last starting X coordinate
int calc_start = (m_iLastPaintedPoint > 0)?m_iLastPaintedPoint -1:m_iLastPaintedPoint;
double start_x = xMap.transform( d_curve[index]->sample(calc_start).x() );
if ( iCurrentPoint > m_iLastPaintedPoint )//The data does not appear to flip, new data is added from the back
{
/*
Depending on the platform setting a clip might be an important
performance issue. F.e. for Qt Embedded this reduces the
part of the backing store that has to be copied out - maybe
to an unaccelerated frame buffer device.
*/
if(size < iMaxPointCount)//The initial container is not full
{
double stop_x = xMap.transform( d_curve[index]->sample(iCurrentPoint).x());
br
= QRect( start_x, canvasRect.
top(), stop_x
- start_x, canvasRect.
height());
}
else//After the container is full
{
if(iCurrentPoint + d_iEaserCount <= iMaxPointCount - 1)//If the erased point does not exceed the boundary
{
double stop_x = xMap.transform( d_curve[index]->sample(iCurrentPoint + d_iEaserCount).x());
br
= QRect( start_x, canvasRect.
top(), stop_x
- start_x, canvasRect.
height());
}
else//If the boundary is exceeded, only the remaining part is erased
{
br
= QRect( start_x, canvasRect.
top(), canvasRect.
right() - start_x, canvasRect.
height());
}
}
region += br;
}
else //Data flipped
{
//Tail
double stop_x = xMap.transform( d_curve[index]->sample(iCurrentPoint + d_iEaserCount).x());
double stop2_x = xMap.transform( d_curve[index]->sample(iMaxPointCount - 1).x());
QRect r1
( start_x , canvasRect.
top(), stop2_x
- start_x , canvasRect.
height());
region += r1;
//Head
double start2_x = xMap.transform( d_curve[index]->sample(0).x());
QRect r2
( start2_x, canvasRect.
top(), stop_x
- start2_x, canvasRect.
height());
region += r2;
}
//Set the latest data index of 12 curves
for(int i = 0;i < 12;i++)
{
d_curve[i]->SetCurrentPoint(iCurrentPoint);
}
m_iLastPaintedPoint = iCurrentPoint;
curveData->unlock();
//Partial refresh,replot 12 curves
canvas()->update(region);
}
void Plot::updateCurve(int index)
{
CurveData *curveData = static_cast<CurveData *>( d_curve[index]->data() );
curveData->lock();
int iCurrentPoint = curveData->getCurrentPointIndex();//Get the index number of the latest data in the container, starting from 0
int iMaxPointCount = curveData->getMaxPointCount();//Get the capacity of a container
int size = curveData->size();//Get the current size of the container
if(iCurrentPoint == m_iLastPaintedPoint)
{
curveData->unlock();
return;
}
QRect canvasRect = canvas()->contentsRect();
QRegion region;//Save the area to be redrawn
const QwtScaleMap xMap = canvasMap( d_curve[index]->xAxis() );
const QwtScaleMap yMap = canvasMap( d_curve[index]->yAxis() );
//Get the last starting X coordinate
int calc_start = (m_iLastPaintedPoint > 0)?m_iLastPaintedPoint -1:m_iLastPaintedPoint;
double start_x = xMap.transform( d_curve[index]->sample(calc_start).x() );
if ( iCurrentPoint > m_iLastPaintedPoint )//The data does not appear to flip, new data is added from the back
{
/*
Depending on the platform setting a clip might be an important
performance issue. F.e. for Qt Embedded this reduces the
part of the backing store that has to be copied out - maybe
to an unaccelerated frame buffer device.
*/
QRect br;
if(size < iMaxPointCount)//The initial container is not full
{
double stop_x = xMap.transform( d_curve[index]->sample(iCurrentPoint).x());
br = QRect( start_x, canvasRect.top(), stop_x - start_x, canvasRect.height());
}
else//After the container is full
{
if(iCurrentPoint + d_iEaserCount <= iMaxPointCount - 1)//If the erased point does not exceed the boundary
{
double stop_x = xMap.transform( d_curve[index]->sample(iCurrentPoint + d_iEaserCount).x());
br = QRect( start_x, canvasRect.top(), stop_x - start_x, canvasRect.height());
}
else//If the boundary is exceeded, only the remaining part is erased
{
br = QRect( start_x, canvasRect.top(), canvasRect.right() - start_x, canvasRect.height());
}
}
region += br;
}
else //Data flipped
{
//Tail
double stop_x = xMap.transform( d_curve[index]->sample(iCurrentPoint + d_iEaserCount).x());
double stop2_x = xMap.transform( d_curve[index]->sample(iMaxPointCount - 1).x());
QRect r1( start_x , canvasRect.top(), stop2_x - start_x , canvasRect.height());
region += r1;
//Head
double start2_x = xMap.transform( d_curve[index]->sample(0).x());
QRect r2( start2_x, canvasRect.top(), stop_x - start2_x, canvasRect.height());
region += r2;
}
//Set the latest data index of 12 curves
for(int i = 0;i < 12;i++)
{
d_curve[i]->SetCurrentPoint(iCurrentPoint);
}
m_iLastPaintedPoint = iCurrentPoint;
curveData->unlock();
//Partial refresh,replot 12 curves
canvas()->update(region);
}
To copy to clipboard, switch view to plain text mode
Bookmarks