void LinePlotter::run()
{
timeSpan.start();
forever {
const QRectF& visibleRectL = visibleRect();
qDebug() << "Timer Out : " << visibleRectL;
// *pix = pix->scaled(::max(visibleRectL.width(), 1.0), ::max(visibleRectL.height(), 1.0));
QImage image
(visibleRectL.
size().
toSize(),
QImage::Format_ARGB32);
paint.begin(&image);
paint.
setRenderHint(QPainter::SmoothPixmapTransform,
true);
paint.
setBrush(QBrush(Qt
::black));
paint.setClipRect(visibleRectL);
paint.drawRect(0, 0, visibleRectL.width(), visibleRectL.height());
const qreal& horizontalPP = horizontalPaddingPixel();
const qreal& verticalPP = verticalPaddingPixel();
const qreal& zoomFactorInverse = 1 / zoomFactor();
const qreal& frontL = front();
const qreal &gridY0 = 0, &gridY1 = visibleRectL.height();
const double& height = (this->boundingRect().height() - (2* verticalPP));
const double& xFactor = zoomFactor(), xPadding = + horizontalPP - ::qCeil(frontL);
int startPoint = (frontL * zoomFactorInverse) - (horizontalPP * zoomFactorInverse);
int xPos = mappingLine().x1();
uint mapperWidth = mapper()->size().width();
uint date = 00000000, time = 0000;
QVariantList points;
const QVector<PlotData*>& plotDataVector = plotData();
if(startPoint < 0)
startPoint = 0;
int endPoint = startPoint + (visibleRectL.width() * zoomFactorInverse) + 5;
foreach (PlotData* plotDataValue, plotDataVector) {
// Each vector contains the data of one day
const std::vector<ID_Element> &ID = plotDataValue->ID();
int IDIndex = 0;
foreach (const ID_Element& idElement, ID) {
int j = 0;
const KAxisRange& yRange = plotDataValue->yRange(IDIndex);
const double yFactor = 1.f / (double(yRange.max() - yRange.min()) / height);
if(endPoint > plotDataValue->totalPixel())
endPoint = plotDataValue->totalPixel();
const std::vector<Date_Element>& dateElement = idElement.ID_vector;
int timeSize = dateElement.front().Time_Vector.size();
qreal min = 0, max = 0;
bool init = true;
foreach (const Date_Element& dateData, dateElement) {
if((j + timeSize) < startPoint) {
j += timeSize;
} else {
const std::vector<Time_Element>& timeElement = dateData.Time_Vector;
QVector<QLineF> gridLines, halfGridLines;
foreach (const Time_Element& timeData, timeElement) {
if(j >= startPoint &&
j <= endPoint) {
// value contains some data in it
const std::vector<float>& value = timeData.Value;
qreal x = j;
x = (x * xFactor) + xPadding;
if(value.size() > 0) {
qreal y = value[0] - yRange.min();
y = height - (y * yFactor) + verticalPP;
if(j == xPos) {
// value contains some data in it
date = dateData.Date;
time = timeData.Time;
QVariantMap mapVal;
mapVal.insert("color", plotDataValue->IDColor(IDIndex));
mapVal.
insert("value",
QString::number(value
[0]));
points.append(mapVal);
}
if(init) {
init = false;
min = value[0];
max = min;
} else {
qreal range = value[0];
if(min > range)
min = range;
if(max < range)
max = range;
}
}
{
// Draw Grid
if(timeData.Time % 100 == 0)
else if((timeData.Time % 100) % 15 == 0)
}
} else if(j > endPoint) {
break;
}
++j;
}
/// Draw graph on pixmap
if(!LineToDraw.isEmpty()) {
paint.setPen(plotDataValue->IDColor(IDIndex));
paint.drawPolyline(LineToDraw);
}
{
paint.drawLines(gridLines);
}
{
paint.
setPen(QPen(QBrush(Qt
::gray),
1, Qt
::DotLine));
paint.drawLines(halfGridLines);
}
}
}
// Update the grapg again for new range series
if(yRange.min() != min ||
yRange.max() != max) {
plotDataValue->setYRange(KAxisRange(min, max), IDIndex);
emit rangeChanged(min, max, IDIndex);
// update();
}
++IDIndex; // increase the ID index number
}
}
// Draw pixmap with graph
// Draw mapper line and set mapper position
{
paint.setOpacity(1.0);
// insert date time
{
QVariantMap dateTimeMap;
dateTimeMap.insert("date", dateString);
dateTimeMap.insert("time", timeString);
points.append(dateTimeMap);
}
// Draw mapper line
{
xPos = (xPos * zoomFactor()) + xPadding;
xPos = xPos + 3;
if((xPos + mapperWidth) > visibleRectL.topRight().x()) { // out from right
xPos -= mapperWidth + 4;
}
// use setPos_ for animated positioning
mapper
()->setPos
(QPointF(xPos,
0));
mapper()->setDataValues(points);
paint.drawLine(lineToDraw);
}
}
paint.end();
}
emit image_changed(image);
}
void LinePlotter::run()
{
QTime timeSpan;
timeSpan.start();
forever {
const QRectF& visibleRectL = visibleRect();
qDebug() << "Timer Out : " << visibleRectL;
// *pix = pix->scaled(::max(visibleRectL.width(), 1.0), ::max(visibleRectL.height(), 1.0));
QImage image(visibleRectL.size().toSize(), QImage::Format_ARGB32);
QPainter paint;
paint.begin(&image);
paint.setRenderHint(QPainter::SmoothPixmapTransform, true);
paint.setBrush(QBrush(Qt::black));
paint.setClipRect(visibleRectL);
paint.drawRect(0, 0, visibleRectL.width(), visibleRectL.height());
const qreal& horizontalPP = horizontalPaddingPixel();
const qreal& verticalPP = verticalPaddingPixel();
const qreal& zoomFactorInverse = 1 / zoomFactor();
const qreal& frontL = front();
const qreal &gridY0 = 0, &gridY1 = visibleRectL.height();
const double& height = (this->boundingRect().height() - (2* verticalPP));
const double& xFactor = zoomFactor(), xPadding = + horizontalPP - ::qCeil(frontL);
int startPoint = (frontL * zoomFactorInverse) - (horizontalPP * zoomFactorInverse);
int xPos = mappingLine().x1();
uint mapperWidth = mapper()->size().width();
uint date = 00000000, time = 0000;
QVariantList points;
const QVector<PlotData*>& plotDataVector = plotData();
if(startPoint < 0)
startPoint = 0;
int endPoint = startPoint + (visibleRectL.width() * zoomFactorInverse) + 5;
foreach (PlotData* plotDataValue, plotDataVector) {
// Each vector contains the data of one day
const std::vector<ID_Element> &ID = plotDataValue->ID();
int IDIndex = 0;
foreach (const ID_Element& idElement, ID) {
int j = 0;
const KAxisRange& yRange = plotDataValue->yRange(IDIndex);
const double yFactor = 1.f / (double(yRange.max() - yRange.min()) / height);
if(endPoint > plotDataValue->totalPixel())
endPoint = plotDataValue->totalPixel();
const std::vector<Date_Element>& dateElement = idElement.ID_vector;
int timeSize = dateElement.front().Time_Vector.size();
qreal min = 0, max = 0;
bool init = true;
foreach (const Date_Element& dateData, dateElement) {
if((j + timeSize) < startPoint) {
j += timeSize;
} else {
const std::vector<Time_Element>& timeElement = dateData.Time_Vector;
QPolygonF LineToDraw;
QVector<QLineF> gridLines, halfGridLines;
foreach (const Time_Element& timeData, timeElement) {
if(j >= startPoint &&
j <= endPoint) {
// value contains some data in it
const std::vector<float>& value = timeData.Value;
qreal x = j;
x = (x * xFactor) + xPadding;
if(value.size() > 0) {
qreal y = value[0] - yRange.min();
y = height - (y * yFactor) + verticalPP;
LineToDraw << QPointF(x, y);
if(j == xPos) {
// value contains some data in it
date = dateData.Date;
time = timeData.Time;
QVariantMap mapVal;
mapVal.insert("color", plotDataValue->IDColor(IDIndex));
mapVal.insert("value", QString::number(value[0]));
points.append(mapVal);
}
if(init) {
init = false;
min = value[0];
max = min;
} else {
qreal range = value[0];
if(min > range)
min = range;
if(max < range)
max = range;
}
}
{
// Draw Grid
if(timeData.Time % 100 == 0)
gridLines << QLineF(QPointF(x, gridY0), QPointF(x, gridY1));
else if((timeData.Time % 100) % 15 == 0)
halfGridLines << QLineF(QPointF(x, gridY0), QPointF(x, gridY1));
}
} else if(j > endPoint) {
break;
}
++j;
}
/// Draw graph on pixmap
if(!LineToDraw.isEmpty()) {
paint.setPen(plotDataValue->IDColor(IDIndex));
paint.drawPolyline(LineToDraw);
}
{
paint.setPen(QPen(QBrush(Qt::red), 3));
paint.drawLines(gridLines);
}
{
paint.setPen(QPen(QBrush(Qt::gray), 1, Qt::DotLine));
paint.drawLines(halfGridLines);
}
}
}
// Update the grapg again for new range series
if(yRange.min() != min ||
yRange.max() != max) {
plotDataValue->setYRange(KAxisRange(min, max), IDIndex);
emit rangeChanged(min, max, IDIndex);
// update();
}
++IDIndex; // increase the ID index number
}
}
// Draw pixmap with graph
// Draw mapper line and set mapper position
{
paint.setPen(QPen(QBrush(Qt::green), 1));
paint.setOpacity(1.0);
// insert date time
{
QString dateString = QDateTime::fromString(QString::number(date), "yyyyMMdd").toString("yyyy-MM-dd");
QString timeString = QTime::fromString(QString::number(time), "hhmm").toString("hh:mm");
QVariantMap dateTimeMap;
dateTimeMap.insert("date", dateString);
dateTimeMap.insert("time", timeString);
points.append(dateTimeMap);
}
// Draw mapper line
{
xPos = (xPos * zoomFactor()) + xPadding;
const QLineF &lineToDraw = QLineF(QPointF(xPos, 0), QPointF(xPos, mappingLine().y2()));
xPos = xPos + 3;
if((xPos + mapperWidth) > visibleRectL.topRight().x()) { // out from right
xPos -= mapperWidth + 4;
}
// use setPos_ for animated positioning
mapper()->setPos(QPointF(xPos, 0));
mapper()->setDataValues(points);
paint.drawLine(lineToDraw);
}
}
paint.end();
}
emit image_changed(image);
}
To copy to clipboard, switch view to plain text mode
Bookmarks