{
Q_UNUSED (widget)
Q_UNUSED (option)
if(!isVisible()) return;
painter
->setPen
(QPen(Qt
::white, .7, Qt
::SolidLine, Qt
::RoundCap, Qt
::MiterJoin));
QRectF visibleRectL
= visibleRect
();
// a pixmap is created on which all the points will draw
// visibleRectL is the rect of the visible area(Means whole graph should not be painted only concentrate on visible part)
QScopedPointer<QPixmap> pix
(new QPixmap(visibleRectL.
width(), visibleRectL.
height()));
paint.begin(pix.data());
paint.
setBrush(QBrush(Qt
::black));
paint.drawRect(0, 0, visibleRectL.width(), visibleRectL.height());
paint.end();
qreal horizontalPP = horizontalPaddingPixel();
qreal verticalPP = verticalPaddingPixel();
qreal zoomFactorInverse = 1 / zoomFactor();
qreal frontL = front();
QVector<PlotData*> plotDataVector = plotData();
qreal gridY0 = 0, gridY1 = visibleRectL.height();
foreach (PlotData* plotDataValue, plotDataVector) {
KAxisRange yRange = plotDataValue->yRange();
double height = (this->boundingRect().height() - (2* verticalPP));
int startPoint = (frontL * zoomFactorInverse) - (horizontalPP * zoomFactorInverse);
if(startPoint < 0)
startPoint = 0;
int endPoint = startPoint + (visibleRectL.width() * zoomFactorInverse) + 5;
if(endPoint > plotDataValue->totalPixel())
endPoint = plotDataValue->totalPixel();
qreal j = 0;
double xFactor = zoomFactor();
double yFactor = 1.f / (double(yRange.max() - yRange.min()) / height);
std::vector<Plot_Aggregation_Element> plotAggregationElement = plotDataValue->plotData();
// Each vector contains the data of one day
std::vector<Date_Element> dateElement = plotAggregationElement.at(0).ID[0].ID_vector;
foreach (Date_Element dateData, dateElement) {
std::vector<Time_Element> timeElement = dateData.Time_Vector;
QVector<QLineF> gridLines;
// each time element contains 330 points and each data element have 30-60 minimum time element
// that means we have atleast 330x60 points in one array and we will have 2-10 arrays
foreach (Time_Element timeData, timeElement) {
if(j >= startPoint &&
j <= endPoint) {
qreal x = j;
x = (x * xFactor) + horizontalPP - ::qCeil(frontL);
// value contains some data in it
if(timeData.Value.max_size() > 0) {
qreal data = timeData.Value[0];
qreal y = data - yRange.min();
y = height - (y * yFactor) + verticalPP;
}
{
// Draw Grid
if(QTime::fromString(QString::number(timeData.
Time),
"hhmm").
minute() == 0) }
} else if(j > endPoint) {
break;
}
j++;
}
painter->setClipRect(0, 0, visibleRect().width(), visibleRect().height());
if(!LineToDraw.isEmpty()) {
/// Draw graph on pixmap
paint.setPen(plotDataValue->plotColor());
paint.drawPolyline(LineToDraw);
paint.setOpacity(0.25);
paint.drawLines(gridLines);
paint.end();
/// Drawing finished
///
}
}
}
/// Draw pixmap with graph
painter->drawPixmap(0, 0, *pix.data());
}