void GraphDraw::paintGL()
{
if (points.count()>2 || pointsx.count()>2) {
float maxXp;
float minXp;
float maxYp;
float minYp;
float maxXt;
float minXt;
float maxYt;
float minYt;
float stepX;
float stepY;
painter.translate(0, float(height())/2);
if (!zoom) {
maxXt = maxX;
minXt = minX;
maxYt = maxY;
minYt = minY;
}
else {
maxXt = zoomListMax[zoom-1].first;
minXt = zoomListMin[zoom-1].first;
maxYt = zoomListMax[zoom-1].second;
minYt = zoomListMin[zoom-1].second;
}
stepX = qAbs(maxXt - minXt)/10;
stepY = qAbs(maxYt - minYt)/10;
maxXp = maxXt + 0.4*stepX;
minXp = minXt - 0.4*stepX;
maxYp = maxYt + 0.4*stepY;
minYp = minYt - 0.4*stepY; //
wsx = float(width()) / qAbs(maxXp - minXp);
wsy = float(height()) / qAbs(maxYp - minYp);
wdx = float(width())/2 - (maxXp*wsx + minXp*wsx)/2;
wdy = - (maxYp*wsy + minYp*wsy)/2;
for (float i=minXt;i<maxXt+stepX;i+=stepX) {
painter.setPen(palette().dark().color());
painter.
drawLine(QPointF(i
*wsx
+ wdx,
-float(height
())/2),
QPointF(i
*wsx
+ wdx,
float(height
())/2));
painter.
setPen(QPen(Qt
::darkGreen));
painter.
drawText(QPointF(i
*wsx
+ wdx
-float(fm
->width
(QString::number(i,
'f',
1))/2),
float(25)/2),
QString::number(i,
'f',
1));
}
for (float i=minYt;i<=maxYt+stepY;i+=stepY) {
painter.setPen(palette().dark().color());
painter.
drawLine(QPointF(0,
-(i
*wsy
+ wdy
)),
QPointF(width
(),
-(i
*wsy
+ wdy
)));
painter.
setPen(QPen(Qt
::darkGreen));
painter.
drawText(QPointF(5,
-(i
*wsy
+ wdy
+4)),
QString::number(i,
'f',
4));
}
painter.
setRenderHint(QPainter::Antialiasing, antialiasing
);
//Ñглаживание painter.
setPen(QPen(Qt
::red,
2, Qt
::SolidLine, Qt
::RoundCap, Qt
::RoundJoin));
if (sorting) {
QList<float> pointsk(points.keys());
for (int m = 0; m<points.count(); m++)
mpoints
[m
]=QPointF(pointsk
[m
]*wsx
+ wdx,
-(points.
value(pointsk
[m
])*wsy
+ wdy
));
painter.drawPolyline(mpoints, points.count());
delete []mpoints;
}
else {
for (int m = 0; m<pointsx.count(); m++)
mpoints
[m
]=QPointF(pointsx
[m
]*wsx
+ wdx,
-(pointsy
[m
]*wsy
+ wdy
));
painter.drawPolyline(mpoints, pointsx.count());
delete []mpoints;
}
painter.translate(0, -float(height())/2);
painter.
setPen(QPen(Qt
::black,
2, Qt
::SolidLine, Qt
::RoundCap, Qt
::RoundJoin));
painter.
drawRect(QRect(0,
0, width
(), height
()));
// font.setStyleStrategy(QFont::OpenGLCompatible);
// font.setStyleStrategy(QFont::PreferAntialias);
painter.drawText(float(width())-fm->width("<--- " + xlegend)-10, 15, "<--- " + xlegend);
painter.rotate(90);
painter.drawText(30, -width()+20, ylegend + " --->");
painter.rotate(-90);
if (mouseState)
painter.
drawRect(QRectF(clickPoint, currPoint
));
}
}
void GraphDraw::paintGL()
{
QPainter painter(this);
if (points.count()>2 || pointsx.count()>2) {
float maxXp;
float minXp;
float maxYp;
float minYp;
float maxXt;
float minXt;
float maxYt;
float minYt;
float stepX;
float stepY;
painter.translate(0, float(height())/2);
if (!zoom) {
maxXt = maxX;
minXt = minX;
maxYt = maxY;
minYt = minY;
}
else {
maxXt = zoomListMax[zoom-1].first;
minXt = zoomListMin[zoom-1].first;
maxYt = zoomListMax[zoom-1].second;
minYt = zoomListMin[zoom-1].second;
}
stepX = qAbs(maxXt - minXt)/10;
stepY = qAbs(maxYt - minYt)/10;
maxXp = maxXt + 0.4*stepX;
minXp = minXt - 0.4*stepX;
maxYp = maxYt + 0.4*stepY;
minYp = minYt - 0.4*stepY; //
wsx = float(width()) / qAbs(maxXp - minXp);
wsy = float(height()) / qAbs(maxYp - minYp);
wdx = float(width())/2 - (maxXp*wsx + minXp*wsx)/2;
wdy = - (maxYp*wsy + minYp*wsy)/2;
for (float i=minXt;i<maxXt+stepX;i+=stepX) {
painter.setPen(palette().dark().color());
painter.drawLine(QPointF(i*wsx + wdx, -float(height())/2), QPointF(i*wsx + wdx, float(height())/2));
painter.setPen(QPen(Qt::darkGreen));
painter.drawText(QPointF(i*wsx + wdx -float(fm->width(QString::number(i,'f',1))/2), float(25)/2), QString::number(i,'f',1));
}
for (float i=minYt;i<=maxYt+stepY;i+=stepY) {
painter.setPen(palette().dark().color());
painter.drawLine(QPointF(0, -(i*wsy + wdy)), QPointF(width(), -(i*wsy + wdy)));
painter.setPen(QPen(Qt::darkGreen));
painter.drawText(QPointF(5, -(i*wsy + wdy+4)),QString::number(i,'f',4));
}
painter.setRenderHint(QPainter::Antialiasing, antialiasing);//Ñглаживание
painter.setPen(QPen(Qt::red, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
if (sorting) {
QPointF *mpoints = new QPointF[points.count()];
QList<float> pointsk(points.keys());
for (int m = 0; m<points.count(); m++)
mpoints[m]=QPointF(pointsk[m]*wsx + wdx, -(points.value(pointsk[m])*wsy + wdy));
painter.drawPolyline(mpoints, points.count());
delete []mpoints;
}
else {
QPointF *mpoints = new QPointF[pointsx.count()];
for (int m = 0; m<pointsx.count(); m++)
mpoints[m]=QPointF(pointsx[m]*wsx + wdx, -(pointsy[m]*wsy + wdy));
painter.drawPolyline(mpoints, pointsx.count());
delete []mpoints;
}
painter.translate(0, -float(height())/2);
painter.setPen(QPen(Qt::black, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter.drawRect(QRect(0, 0, width(), height()));
// font.setStyleStrategy(QFont::OpenGLCompatible);
// font.setStyleStrategy(QFont::PreferAntialias);
painter.drawText(float(width())-fm->width("<--- " + xlegend)-10, 15, "<--- " + xlegend);
painter.rotate(90);
painter.drawText(30, -width()+20, ylegend + " --->");
painter.rotate(-90);
if (mouseState)
painter.drawRect(QRectF(clickPoint, currPoint));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks