mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-06 03:00:43 +00:00
Higher resolution graph snapshots in antialias mode
This commit is contained in:
parent
fb9e26aee3
commit
32bc6a97d0
@ -291,18 +291,17 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion)
|
|||||||
int fw, font_height;
|
int fw, font_height;
|
||||||
GetTextExtent("Wg@", fw, font_height);
|
GetTextExtent("Wg@", fw, font_height);
|
||||||
|
|
||||||
if (m_margintop > 0) { m_margintop = font_height + (8 * printScaleY()); }
|
if (m_margintop > 0) { m_margintop = font_height + (8); }
|
||||||
|
|
||||||
//m_marginbottom=5;
|
//m_marginbottom=5;
|
||||||
|
|
||||||
left = marginLeft(), right = marginRight(), top = marginTop(), bottom = marginBottom();
|
left = marginLeft()*printScaleX(), right = marginRight()*printScaleX(), top = marginTop(), bottom = marginBottom() * printScaleY();
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (m_showTitle) {
|
if (m_showTitle) {
|
||||||
int title_x, yh;
|
int title_x, yh;
|
||||||
|
|
||||||
|
painter.setFont(*mediumfont);
|
||||||
QFontMetrics fm(*mediumfont);
|
QFontMetrics fm(*mediumfont);
|
||||||
|
|
||||||
yh = fm.height();
|
yh = fm.height();
|
||||||
@ -310,14 +309,14 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion)
|
|||||||
y = yh;
|
y = yh;
|
||||||
x = fm.width(title());
|
x = fm.width(title());
|
||||||
//GetTextExtent(title(),x,y,mediumfont);
|
//GetTextExtent(title(),x,y,mediumfont);
|
||||||
title_x = float(yh) * 1.5;
|
title_x = float(yh) ;
|
||||||
|
|
||||||
QString & txt = title();
|
QString & txt = title();
|
||||||
if (!m_issnapshot) {
|
if (!m_issnapshot) {
|
||||||
graphView()->AddTextQue(txt, marginLeft() + title_x + 4, originY + height / 2 - y / 2, 90, Qt::black, mediumfont);
|
graphView()->AddTextQue(txt, marginLeft() + title_x + 8*printScaleX(), originY + height / 2 - y / 2, 90, Qt::black, mediumfont);
|
||||||
}
|
}
|
||||||
|
|
||||||
left += title_x;
|
left += graphView()->titleWidth*printScaleX();
|
||||||
} else { left = 0; }
|
} else { left = 0; }
|
||||||
|
|
||||||
|
|
||||||
@ -339,7 +338,6 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #define DEBUG_LAYOUT
|
|
||||||
#ifdef DEBUG_LAYOUT
|
#ifdef DEBUG_LAYOUT
|
||||||
QColor col = Qt::red;
|
QColor col = Qt::red;
|
||||||
painter.setPen(col);
|
painter.setPen(col);
|
||||||
@ -355,11 +353,10 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion)
|
|||||||
|
|
||||||
if (!ll->visible()) { continue; }
|
if (!ll->visible()) { continue; }
|
||||||
|
|
||||||
tmp = ll->Height() * m_graphview->printScaleY();
|
tmp = ll->Height();// * m_graphview->printScaleY();
|
||||||
|
|
||||||
if (ll->position() == LayerTop) { top += tmp; }
|
if (ll->position() == LayerTop) { top += tmp; }
|
||||||
|
if (ll->position() == LayerBottom) { bottom += tmp * printScaleY(); }
|
||||||
if (ll->position() == LayerBottom) { bottom += tmp; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -397,7 +394,7 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bottom = marginBottom();
|
bottom = marginBottom() * printScaleY();
|
||||||
top = marginTop();
|
top = marginTop();
|
||||||
|
|
||||||
for (int i = 0; i < m_layers.size(); i++) {
|
for (int i = 0; i < m_layers.size(); i++) {
|
||||||
@ -405,7 +402,7 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion)
|
|||||||
|
|
||||||
if (!ll->visible()) { continue; }
|
if (!ll->visible()) { continue; }
|
||||||
|
|
||||||
tmp = ll->Height() * m_graphview->printScaleY();
|
tmp = ll->Height();
|
||||||
|
|
||||||
if (ll->position() == LayerTop) {
|
if (ll->position() == LayerTop) {
|
||||||
QRect rect(originX + left, originY + top, width - left - right, tmp);
|
QRect rect(originX + left, originY + top, width - left - right, tmp);
|
||||||
@ -415,7 +412,7 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ll->position() == LayerBottom) {
|
if (ll->position() == LayerBottom) {
|
||||||
bottom += tmp;
|
bottom += tmp * printScaleY();
|
||||||
QRect rect(originX + left, originY + height - bottom, width - left - right, tmp);
|
QRect rect(originX + left, originY + height - bottom, width - left - right, tmp);
|
||||||
ll->m_rect = rect;
|
ll->m_rect = rect;
|
||||||
ll->paint(painter, *this, QRegion(rect));
|
ll->paint(painter, *this, QRegion(rect));
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
#ifndef graphs_ggraph_h
|
#ifndef graphs_ggraph_h
|
||||||
#define graphs_ggraph_h
|
#define graphs_ggraph_h
|
||||||
|
|
||||||
|
//#define DEBUG_LAYOUT
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
@ -2099,12 +2099,73 @@ void gGraphView::onSnapshotGraphToggle()
|
|||||||
|
|
||||||
bool pinned = graph->isPinned();
|
bool pinned = graph->isPinned();
|
||||||
graph->setPinned(false);
|
graph->setPinned(false);
|
||||||
QPixmap pm = graph->renderPixmap(width(), graph->m_rect.height(), false);
|
|
||||||
|
bool highres = p_profile->appearance->antiAliasing();
|
||||||
|
QPixmap pm;
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
if (highres) {
|
||||||
|
QFont *_defaultfont = defaultfont;
|
||||||
|
QFont *_mediumfont = mediumfont;
|
||||||
|
QFont *_bigfont = bigfont;
|
||||||
|
|
||||||
|
QFont fa = *defaultfont;
|
||||||
|
QFont fb = *mediumfont;
|
||||||
|
QFont fc = *bigfont;
|
||||||
|
|
||||||
|
|
||||||
|
fa.setPointSize(fa.pointSize()*2.0);
|
||||||
|
fb.setPointSize(fb.pointSize()*2.0);
|
||||||
|
fc.setPointSize(fc.pointSize()*2.0);
|
||||||
|
|
||||||
|
defaultfont = &fa;
|
||||||
|
mediumfont = &fb;
|
||||||
|
bigfont = &fc;
|
||||||
|
|
||||||
|
|
||||||
|
graph->m_printing = true;
|
||||||
|
|
||||||
|
bool pmc = p_profile->appearance->usePixmapCaching();
|
||||||
|
p_profile->appearance->setUsePixmapCaching(false);
|
||||||
|
setUsePixmapCache(false);
|
||||||
|
|
||||||
|
int w = graph->m_rect.width() * 2.0;
|
||||||
|
int h = graph->m_rect.height() * 2.0;
|
||||||
|
setPrintScaleX(2);
|
||||||
|
setPrintScaleY(2);
|
||||||
|
|
||||||
|
pm = QPixmap(w,h);
|
||||||
|
|
||||||
|
QPainter painter(&pm);
|
||||||
|
|
||||||
|
QRect rec(0,0,w,h);
|
||||||
|
painter.fillRect(rec,QBrush(QColor(Qt::white)));
|
||||||
|
|
||||||
|
float f = scaleY();
|
||||||
|
QRegion region(rec);
|
||||||
|
graph->paint(painter, region);
|
||||||
|
DrawTextQue(painter);
|
||||||
|
painter.end();
|
||||||
|
|
||||||
|
setUsePixmapCache(pmc);
|
||||||
|
p_profile->appearance->setUsePixmapCaching(pmc);
|
||||||
|
|
||||||
|
setPrintScaleX(1);
|
||||||
|
setPrintScaleY(1);
|
||||||
|
graph->m_printing = false;
|
||||||
|
defaultfont = _defaultfont;
|
||||||
|
mediumfont = _mediumfont;
|
||||||
|
bigfont = _bigfont;
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
} else {
|
||||||
|
pm = graph->renderPixmap(width(), graph->m_rect.height(), false);
|
||||||
|
}
|
||||||
graph->setPinned(pinned);
|
graph->setPinned(pinned);
|
||||||
|
|
||||||
|
|
||||||
gGraph * newgraph = new gGraph(newname, nullptr, graph->title(), graph->units(), graph->height(), graph->group());
|
gGraph * newgraph = new gGraph(newname, nullptr, graph->title(), graph->units(), graph->height(), graph->group());
|
||||||
newgraph->setSnapshot(pm);
|
newgraph->setSnapshot(pm);
|
||||||
newgraph->setBlockSelect(true);
|
newgraph->setBlockSelect(true);
|
||||||
newgraph->setHeight(pm.height());
|
newgraph->setHeight(pm.height()/(highres?2:1));
|
||||||
//newgraph->setMinHeight(pm.height());
|
//newgraph->setMinHeight(pm.height());
|
||||||
|
|
||||||
m_graphs.insert(m_graphs.indexOf(graph)+1, newgraph);
|
m_graphs.insert(m_graphs.indexOf(graph)+1, newgraph);
|
||||||
|
@ -52,7 +52,7 @@ void gXGrid::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
|||||||
static QString fd = "0";
|
static QString fd = "0";
|
||||||
GetTextExtent(fd, x, y);
|
GetTextExtent(fd, x, y);
|
||||||
|
|
||||||
double max_yticks = round(height / (y + 14.0)); // plus spacing between lines
|
double max_yticks = round(height / (y + 14.0*w.printScaleY())); // plus spacing between lines
|
||||||
//double yt=1/max_yticks;
|
//double yt=1/max_yticks;
|
||||||
|
|
||||||
double mxy = maxy; //MAX(fabs(maxy), fabs(miny));
|
double mxy = maxy; //MAX(fabs(maxy), fabs(miny));
|
||||||
@ -155,131 +155,11 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
|||||||
|
|
||||||
//Todo: clean this up as there is a lot of duplicate code between the sections
|
//Todo: clean this up as there is a lot of duplicate code between the sections
|
||||||
|
|
||||||
if (0) {//w.graphView()->usePixmapCache()) {
|
if (0) {
|
||||||
/* if (w.invalidate_yAxisImage) {
|
|
||||||
|
|
||||||
if (!m_image.isNull()) {
|
|
||||||
w.graphView()->deleteTexture(m_textureID);
|
|
||||||
m_image=QImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (height<0) return;
|
|
||||||
if (height>2000) return;
|
|
||||||
|
|
||||||
int labelW=0;
|
|
||||||
|
|
||||||
EventDataType miny=w.min_y;
|
|
||||||
EventDataType maxy=w.max_y;
|
|
||||||
|
|
||||||
if (miny<0) { // even it up if it's starts negative
|
|
||||||
miny=-MAX(fabs(miny),fabs(maxy));
|
|
||||||
}
|
|
||||||
|
|
||||||
w.roundY(miny,maxy);
|
|
||||||
|
|
||||||
EventDataType dy=maxy-miny;
|
|
||||||
static QString fd="0";
|
|
||||||
GetTextExtent(fd,x,y);
|
|
||||||
yh=y;
|
|
||||||
|
|
||||||
m_image=QImage(width,height+y+4,QImage::Format_ARGB32_Premultiplied);
|
|
||||||
|
|
||||||
m_image.fill(Qt::transparent);
|
|
||||||
QPainter paint(&m_image);
|
|
||||||
|
|
||||||
|
|
||||||
double max_yticks=round(height / (y+14.0)); // plus spacing between lines
|
|
||||||
|
|
||||||
double mxy=MAX(fabs(maxy),fabs(miny));
|
|
||||||
double mny=miny;
|
|
||||||
if (miny<0) {
|
|
||||||
mny=-mxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
double rxy=mxy-mny;
|
|
||||||
|
|
||||||
int myt;
|
|
||||||
bool fnd=false;
|
|
||||||
for (myt=max_yticks;myt>2;myt--) {
|
|
||||||
float v=rxy/float(myt);
|
|
||||||
if (v==int(v)) {
|
|
||||||
fnd=true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fnd) max_yticks=myt;
|
|
||||||
double yt=1/max_yticks;
|
|
||||||
|
|
||||||
double ymult=height/rxy;
|
|
||||||
|
|
||||||
double min_ytick=rxy*yt;
|
|
||||||
|
|
||||||
float ty,h;
|
|
||||||
|
|
||||||
if (min_ytick<=0) {
|
|
||||||
qDebug() << "min_ytick error in gYAxis::paint() in" << w.title();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (min_ytick>=1000000) {
|
|
||||||
min_ytick=100;
|
|
||||||
}
|
|
||||||
|
|
||||||
//lines=w.backlines();
|
|
||||||
|
|
||||||
for (double i=miny; i<=maxy+min_ytick-0.00001; i+=min_ytick) {
|
|
||||||
ty=(i - miny) * ymult;
|
|
||||||
if (dy<5) {
|
|
||||||
fd=Format(i*m_yaxis_scale,2);
|
|
||||||
} else {
|
|
||||||
fd=Format(i*m_yaxis_scale,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
GetTextExtent(fd,x,y);
|
|
||||||
|
|
||||||
if (x>labelW) labelW=x;
|
|
||||||
h=(height-2)-ty;
|
|
||||||
h+=yh;
|
|
||||||
#ifndef Q_OS_MAC
|
|
||||||
// stupid pixel alignment rubbish, I really should be using floats..
|
|
||||||
h+=1;
|
|
||||||
#endif
|
|
||||||
if (h<0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
paint.setBrush(Qt::black);
|
|
||||||
paint.drawText(width-8-x,h+y/2,fd);
|
|
||||||
|
|
||||||
paint.setPen(m_line_color);
|
|
||||||
paint.drawLine(width-4,h,width,h);
|
|
||||||
|
|
||||||
double z=(min_ytick/4)*ymult;
|
|
||||||
double g=h;
|
|
||||||
for (int i=0;i<3;i++) {
|
|
||||||
g+=z;
|
|
||||||
if (g>height+yh) break;
|
|
||||||
paint.drawLine(width-3,g,width,g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
paint.end();
|
|
||||||
m_image=QGLWidget::convertToGLFormat(m_image);
|
|
||||||
m_textureID=w.graphView()->bindTexture(m_image,GL_TEXTURE_2D,GL_RGBA,QGLContext::NoBindOption);
|
|
||||||
w.invalidate_yAxisImage=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_image.isNull()) {
|
|
||||||
glEnable(GL_BLEND);
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
w.graphView()->drawTexture(QPoint(left,(top+height)-m_image.height()+5),m_textureID);
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
glDisable(GL_BLEND);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
} else {
|
} else {
|
||||||
if (height < 0) { return; }
|
if (height < 0) { return; }
|
||||||
|
|
||||||
if (height > 2000) { return; }
|
if (height > 4000) { return; }
|
||||||
|
|
||||||
int labelW = 0;
|
int labelW = 0;
|
||||||
|
|
||||||
@ -294,7 +174,12 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
|||||||
static QString fd = "0";
|
static QString fd = "0";
|
||||||
GetTextExtent(fd, x, y);
|
GetTextExtent(fd, x, y);
|
||||||
|
|
||||||
double max_yticks = round(height / (y + 14.0)); // plus spacing between lines
|
#ifdef DEBUG_LAYOUT
|
||||||
|
painter.setPen(Qt::green);
|
||||||
|
painter.drawLine(0,top,100,top);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
double max_yticks = height / (y + 14.0); // plus spacing between lines
|
||||||
|
|
||||||
double mxy = maxy; // MAX(fabs(maxy), fabs(miny));
|
double mxy = maxy; // MAX(fabs(maxy), fabs(miny));
|
||||||
double mny = miny;
|
double mny = miny;
|
||||||
@ -311,7 +196,7 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
|||||||
for (myt = max_yticks; myt > 2; myt--) {
|
for (myt = max_yticks; myt > 2; myt--) {
|
||||||
float v = rxy / float(myt);
|
float v = rxy / float(myt);
|
||||||
|
|
||||||
if (v == int(v)) {
|
if (qAbs(v - int(v)) < 0.000001) {
|
||||||
fnd = true;
|
fnd = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -345,6 +230,7 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
|||||||
|
|
||||||
QVector<QLine> ticks;
|
QVector<QLine> ticks;
|
||||||
|
|
||||||
|
float shorttick = 4.0 * w.printScaleX();
|
||||||
for (double i = miny; i <= maxy + min_ytick - 0.00001; i += min_ytick) {
|
for (double i = miny; i <= maxy + min_ytick - 0.00001; i += min_ytick) {
|
||||||
ty = (i - miny) * ymult;
|
ty = (i - miny) * ymult;
|
||||||
|
|
||||||
@ -362,9 +248,9 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
|||||||
|
|
||||||
if (h < top) { continue; }
|
if (h < top) { continue; }
|
||||||
|
|
||||||
w.renderText(fd, left + width - 8 - x, (h + (y / 2.0)), 0, m_text_color, defaultfont);
|
w.renderText(fd, left + width - shorttick*2 - x, (h + (y / 2.0)), 0, m_text_color, defaultfont);
|
||||||
|
|
||||||
ticks.append(QLine(left + width - 4, h, left + width, h));
|
ticks.append(QLine(left + width - shorttick, h, left + width, h));
|
||||||
|
|
||||||
double z = (min_ytick / 4) * ymult;
|
double z = (min_ytick / 4) * ymult;
|
||||||
double g = h;
|
double g = h;
|
||||||
@ -374,7 +260,7 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
|||||||
|
|
||||||
if (g > top + height) { break; }
|
if (g > top + height) { break; }
|
||||||
|
|
||||||
ticks.append(QLine(left + width - 3, g, left + width, g));
|
ticks.append(QLine(left + width - shorttick/2, g, left + width, g));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
painter.setPen(m_line_color);
|
painter.setPen(m_line_color);
|
||||||
|
@ -415,6 +415,7 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
|
|||||||
if (!print_bookmarks) {
|
if (!print_bookmarks) {
|
||||||
for (int i = 0; i < gv->size(); i++) {
|
for (int i = 0; i < gv->size(); i++) {
|
||||||
g = (*gv)[i];
|
g = (*gv)[i];
|
||||||
|
if (g->isSnapshot()) continue;
|
||||||
|
|
||||||
if (g->isEmpty()) { continue; }
|
if (g->isEmpty()) { continue; }
|
||||||
|
|
||||||
@ -508,6 +509,7 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
|
|||||||
|
|
||||||
for (int i = 0; i < gv->size(); i++) {
|
for (int i = 0; i < gv->size(); i++) {
|
||||||
gGraph *g = (*gv)[i];
|
gGraph *g = (*gv)[i];
|
||||||
|
if (g->isSnapshot()) continue;
|
||||||
|
|
||||||
if (g->isEmpty()) { continue; }
|
if (g->isEmpty()) { continue; }
|
||||||
|
|
||||||
@ -529,6 +531,7 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
|
|||||||
if (g->isEmpty()) { continue; }
|
if (g->isEmpty()) { continue; }
|
||||||
|
|
||||||
if (!g->visible()) { continue; }
|
if (!g->visible()) { continue; }
|
||||||
|
if (g->isSnapshot()) continue;
|
||||||
|
|
||||||
start.push_back(st);
|
start.push_back(st);
|
||||||
end.push_back(et);
|
end.push_back(et);
|
||||||
|
Loading…
Reference in New Issue
Block a user