Stopped a huge text drawing related memory leak

This commit is contained in:
Mark Watkins 2011-07-27 20:11:22 +10:00
parent a4287d0f64
commit e8c7222143
8 changed files with 25 additions and 21 deletions

View File

@ -137,7 +137,7 @@ void gFlagsLine::Plot(gGraphWindow & w,float scrx,float scry)
// Draw text label // Draw text label
float x,y; float x,y;
GetTextExtent(label,x,y); GetTextExtent(label,x,y);
DrawText(label,start_px-x-10,(scry-line_top)-(line_h/2)+(y/2)); DrawText(w,label,start_px-x-10,(scry-line_top)-(line_h/2)+(y/2));
float x1,x2; float x1,x2;
QColor & col=color[0]; QColor & col=color[0];

View File

@ -27,7 +27,7 @@ gLineChart::~gLineChart()
void gLineChart::Plot(gGraphWindow & w,float scrx,float scry) void gLineChart::Plot(gGraphWindow & w,float scrx,float scry)
{ {
const int max_drawlist_size=4096; const int max_drawlist_size=4096;
static QPoint m_drawlist[max_drawlist_size]; QPoint m_drawlist[max_drawlist_size];
if (!m_visible) if (!m_visible)
return; return;
@ -407,7 +407,7 @@ void gLineChart::Plot(gGraphWindow & w,float scrx,float scry)
QString msg="No Waveform Available"; QString msg="No Waveform Available";
float x,y; float x,y;
GetTextExtent(msg,x,y,bigfont); GetTextExtent(msg,x,y,bigfont);
DrawText(msg,start_px+(width/2.0)-(x/2.0),scry-w.GetBottomMargin()-height/2.0+y/2.0,0,Qt::gray,bigfont); DrawText(w,msg,start_px+(width/2.0)-(x/2.0),scry-w.GetBottomMargin()-height/2.0+y/2.0,0,Qt::gray,bigfont);
} }
} else { } else {

View File

@ -118,7 +118,7 @@ void gLineOverlayBar::Plot(gGraphWindow & w,float scrx,float scry)
} }
if (xx<(1800000)) { if (xx<(1800000)) {
GetTextExtent(label,x,y); GetTextExtent(label,x,y);
DrawText(label,x1-(x/2),scry-(start_py+height-30+y)); DrawText(w,label,x1-(x/2),scry-(start_py+height-30+y));
//w.renderText(x1-(x/2),scry-(start_py+height-30+y),label); //w.renderText(x1-(x/2),scry-(start_py+height-30+y),label);
} }

View File

@ -22,7 +22,7 @@ void gTitle::Plot(gGraphWindow & w,float scrx,float scry)
GetTextExtent(m_title,width,height); GetTextExtent(m_title,width,height);
int xp=(height/2)+15; int xp=(height/2)+15;
//if (m_alignment==wxALIGN_RIGHT) xp=scrx-4-height; //if (m_alignment==wxALIGN_RIGHT) xp=scrx-4-height;
DrawText(m_title,xp,scry-(w.GetBottomMargin()+((scry-w.GetBottomMargin())/2.0)),90.0,m_color,&m_font); DrawText(w,m_title,xp,scry-(w.GetBottomMargin()+((scry-w.GetBottomMargin())/2.0)),90.0,m_color,&m_font);
//DrawText(w,m_title,150,-40,45.0); //20+xp,scry-(w.GetBottomMargin()+((scry-w.GetBottomMargin())/2.0)+(height/2)),90.0,m_color,&m_font); //DrawText(w,m_title,150,-40,45.0); //20+xp,scry-(w.GetBottomMargin()+((scry-w.GetBottomMargin())/2.0)+(height/2)),90.0,m_color,&m_font);

View File

@ -179,9 +179,9 @@ void gXAxis::Plot(gGraphWindow & w,float scrx,float scry)
GetTextExtent(fd,x,y); GetTextExtent(fd,x,y);
if (!show_time) { if (!show_time) {
DrawText(fd, px+y, scry-(py-(x/2)-8), 90.0); DrawText(w,fd, px+y, scry-(py-(x/2)-8), 90.0);
} else { } else {
DrawText(fd, px-(x/2), scry-(py-8-y)); DrawText(w,fd, px-(x/2), scry-(py-8-y));
} }
} }

View File

@ -144,7 +144,7 @@ void gYAxis::Plot(gGraphWindow &w,float scrx,float scry)
GetTextExtent(fd,x,y); GetTextExtent(fd,x,y);
if (x>labelW) labelW=x; if (x>labelW) labelW=x;
h=start_py+ty; h=start_py+ty;
DrawText(fd,start_px-12-x,scry-(h-(y/2.0)),0); DrawText(w,fd,start_px-12-x,scry-(h-(y/2.0)),0);
vertarray[vertcnt++]=start_px-4; vertarray[vertcnt++]=start_px-4;
vertarray[vertcnt++]=h; vertarray[vertcnt++]=h;

View File

@ -95,31 +95,32 @@ struct TextBuffer
float angle; float angle;
QColor color; QColor color;
QFont *font; QFont *font;
TextBuffer() { x=0; y=0; }
TextBuffer(QString _text, int _x, int _y, float _angle, QColor _color,QFont *_font) { TextBuffer(QString _text, int _x, int _y, float _angle, QColor _color,QFont *_font) {
text=_text; x=_x; y=_y; angle=_angle; color=_color; font=_font; text=_text; x=_x; y=_y; angle=_angle; color=_color; font=_font;
} }
}; };
vector<TextBuffer *> TextQue; vector<TextBuffer> TextQue;
vector<TextBuffer *> TextQueRot; vector<TextBuffer> TextQueRot;
void DrawTextQueue(gGraphWindow & wid) void DrawTextQueue(gGraphWindow & wid)
{ {
//glFlush(); //glFlush();
for (unsigned i=0;i<TextQue.size();i++) { for (unsigned i=0;i<TextQue.size();i++) {
TextBuffer & t=*TextQue[i]; TextBuffer & t=TextQue[i];
wid.qglColor(t.color); wid.qglColor(t.color);
wid.renderText(t.x,wid.GetScrY()-t.y,0,t.text,*t.font); wid.renderText(t.x,wid.GetScrY()-t.y,0,t.text,*t.font);
//RDrawText(painter,t.text,t.x,t.y,t.angle,t.color,t.font); //RDrawText(painter,t.text,t.x,t.y,t.angle,t.color,t.font);
delete TextQue[i]; //delete TextQue[i];
} }
if (wid.parentWidget()!=0) { if (wid.parentWidget()!=0) {
QPainter painter(&wid); QPainter painter(&wid);
// TODO.. Prerotate the 90degree stuff here and keep the matrix for all of these.. // TODO.. Prerotate the 90degree stuff here and keep the matrix for all of these..
for (unsigned i=0;i<TextQueRot.size();i++) { for (unsigned i=0;i<TextQueRot.size();i++) {
TextBuffer & t=*TextQueRot[i]; TextBuffer & t=TextQueRot[i];
RDrawText(painter,t.text,t.x,t.y,t.angle,t.color,t.font); RDrawText(painter,t.text,t.x,t.y,t.angle,t.color,t.font);
delete TextQueRot[i]; //delete TextQueRot[i];
} }
painter.end(); painter.end();
} }
@ -131,13 +132,16 @@ void DrawTextQueue(gGraphWindow & wid)
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
// I bet this slows things down craploads.. should probably skip the vector and use a preallocated textbuffer array. // I bet this slows things down craploads.. should probably skip the vector and use a preallocated textbuffer array.
void DrawText(QString text, int x, int y, float angle, QColor color,QFont *font) void DrawText(gGraphWindow &wid,QString text, int x, int y, float angle, QColor color,QFont *font)
{ {
TextBuffer *b=new TextBuffer(text,x,y,angle,color,font); if (angle==90) {
if (angle==90) //TextBuffer *b=new TextBuffer(text,x,y,angle,color,font);
TextQueRot.push_back(b); TextQueRot.push_back(TextBuffer(text,x,y,angle,color,font));
else } else {
TextQue.push_back(b); wid.qglColor(color);
wid.renderText(x,wid.GetScrY()-y,0,text,*font);
//TextQue.push_back(b);
}
} }

View File

@ -26,7 +26,7 @@ extern GLshort *vertex_array[num_vert_arrays];
class gGraphWindow; class gGraphWindow;
void GetTextExtent(QString text, float & width, float & height, QFont *font=defaultfont); void GetTextExtent(QString text, float & width, float & height, QFont *font=defaultfont);
void DrawText(QString text, int x, int y, float angle=0, QColor color=QColor("black"),QFont *font=defaultfont); void DrawText(gGraphWindow &wid, QString text, int x, int y, float angle=0, QColor color=Qt::black,QFont *font=defaultfont);
void DrawTextQueue(gGraphWindow & wid); void DrawTextQueue(gGraphWindow & wid);
void LinedRoundedRectangle(int x,int y,int w,int h,int radius,int lw,QColor color); void LinedRoundedRectangle(int x,int y,int w,int h,int radius,int lw,QColor color);