Implemented a text queue to solve text color bug

This commit is contained in:
Mark Watkins 2011-07-11 11:58:51 +10:00
parent bb80f4b296
commit bbaf680bba
8 changed files with 58 additions and 13 deletions

View File

@ -20,13 +20,11 @@ void gTitle::Plot(gGraphWindow & w,float scrx,float scry)
float width,height; float width,height;
GetTextExtent(m_title,width,height); GetTextExtent(m_title,width,height);
int xp=(height/2)+20; int xp=(height/2)+20;
//if (m_alignment==wxALIGN_RIGHT) xp=scrx-4-height; //if (m_alignment==wxALIGN_RIGHT) xp=scrx-4-height;
DrawText(w,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);
//glColor3ub(m_color.red(),m_color.green(),m_color.blue());
//w.renderText(xp,scry-(w.GetBottomMargin()+((scry-w.GetBottomMargin())/2.0)+(height/2)),0.35,m_title,m_font); //w.renderText(xp,scry-(w.GetBottomMargin()+((scry-w.GetBottomMargin())/2.0)+(height/2)),0.35,m_title,m_font);
} }

View File

@ -15,6 +15,7 @@ gYAxis::gYAxis(QColor col)
m_show_major_lines=true; m_show_major_lines=true;
m_show_minor_lines=true; m_show_minor_lines=true;
m_yaxis_scale=1;
} }
gYAxis::~gYAxis() gYAxis::~gYAxis()
{ {
@ -89,7 +90,7 @@ void gYAxis::Plot(gGraphWindow &w,float scrx,float scry)
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;
fd=Format(i); // Override this as a function. fd=Format(i*m_yaxis_scale); // Override this as a function.
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;

View File

@ -25,11 +25,15 @@ class gYAxis:public gLayer
bool ShowMajorTicks() { return m_show_major_ticks; }; bool ShowMajorTicks() { return m_show_major_ticks; };
virtual const QString & Format(double v) { static QString t; t.sprintf("%.1f",v); return t; }; virtual const QString & Format(double v) { static QString t; t.sprintf("%.1f",v); return t; };
static const int Margin=50; // Left margin space static const int Margin=50; // Left margin space
void SetScale(float f) { m_yaxis_scale=f; }; // Scale yaxis ticker values (only what's displayed)
float Scale() { return m_yaxis_scale; };
protected: protected:
bool m_show_major_lines; bool m_show_major_lines;
bool m_show_minor_lines; bool m_show_minor_lines;
bool m_show_minor_ticks; bool m_show_minor_ticks;
bool m_show_major_ticks; bool m_show_major_ticks;
float m_yaxis_scale;
}; };
#endif // GYAXIS_H #endif // GYAXIS_H

View File

@ -55,7 +55,7 @@ void GetTextExtent(QString text, float & width, float & height, QFont *font)
width=fm.width(text); //fm.width(text); width=fm.width(text); //fm.width(text);
height=fm.xHeight()+2; //fm.ascent(); height=fm.xHeight()+2; //fm.ascent();
} }
void DrawText(gGraphWindow & wid, QString text, int x, int y, float angle, QColor color,QFont *font) void RDrawText(gGraphWindow & wid, QString text, int x, int y, float angle, QColor color,QFont *font)
{ {
//QFontMetrics fm(*font); //QFontMetrics fm(*font);
float w,h; float w,h;
@ -69,11 +69,13 @@ void DrawText(gGraphWindow & wid, QString text, int x, int y, float angle, QCol
} }
// glEnable(GL_TEXTURE_2D); // glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST); // glDisable(GL_DEPTH_TEST);
glFlush(); glFinish();
QPainter painter(&wid); QPainter painter(&wid);
painter.setFont(*font); painter.setFont(*font);
color=Qt::black;
painter.setPen(color); painter.setPen(color);
painter.setBrush(QBrush(color));
painter.setOpacity(1); painter.setOpacity(1);
// painter.setCompositionMode(QPainter::CompositionMode_); // painter.setCompositionMode(QPainter::CompositionMode_);
if (angle==0) { if (angle==0) {
@ -93,6 +95,33 @@ void DrawText(gGraphWindow & wid, QString text, int x, int y, float angle, QCol
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
struct TextBuffer
{
gGraphWindow *wid;
QString text;
int x,y;
float angle;
QColor *color;
QFont *font;
TextBuffer(gGraphWindow * _wid, QString _text, int _x, int _y, float _angle, QColor *_color,QFont *_font) {
wid=_wid; text=_text; x=_x; y=_y; angle=_angle; color=_color; font=_font;
}
};
vector<TextBuffer *> TextQue;
void DrawTextQueue()
{
for (unsigned i=0;i<TextQue.size();i++) {
TextBuffer * t=TextQue[i];
RDrawText(*t->wid,t->text,t->x,t->y,t->angle,*t->color,t->font);
delete TextQue[i];
}
TextQue.clear();
}
void DrawText(gGraphWindow & wid, QString text, int x, int y, float angle, QColor color,QFont *font)
{
TextQue.push_back(new TextBuffer(&wid,text,x,y,angle,&color,font));
}
void RoundedRectangle(int x,int y,int w,int h,int radius,const QColor color) void RoundedRectangle(int x,int y,int w,int h,int radius,const QColor color)

View File

@ -27,6 +27,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(gGraphWindow & wid, 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=QColor("black"),QFont *font=defaultfont);
void DrawTextQueue();
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);
void RoundedRectangle(int x,int y,int w,int h,int radius,const QColor color); void RoundedRectangle(int x,int y,int w,int h,int radius,const QColor color);

View File

@ -733,6 +733,8 @@ void gGraphWindow::Render(float w, float h)
for (list<gLayer *>::iterator l=layers.begin();l!=layers.end();l++) { for (list<gLayer *>::iterator l=layers.begin();l!=layers.end();l++) {
(*l)->Plot(*this,w,h); (*l)->Plot(*this,w,h);
} }
glFinish();
DrawTextQueue();
} }
void gGraphWindow::paintGL() void gGraphWindow::paintGL()

View File

@ -184,7 +184,8 @@ bool PRS1Loader::ParseProperties(Machine *m,QString filename)
s=f.readLine(); s=f.readLine();
} }
bool ok; bool ok;
int i=prop["ProductType"].toInt(&ok); QString pt=prop["ProductType"];
int i=pt.toInt(&ok,0);
if (ok) { if (ok) {
if (ModelMap.find(i)!=ModelMap.end()) { if (ModelMap.find(i)!=ModelMap.end()) {
m->properties["SubModel"]=ModelMap[i]; m->properties["SubModel"]=ModelMap[i];
@ -1025,14 +1026,20 @@ bool PRS1Loader::OpenWaveforms(Session *session,QString filename)
for (int j=0;j<interleave[numsignals-1-s];j++) { for (int j=0;j<interleave[numsignals-1-s];j++) {
if (sampletype[numsignals-1-s]==0) if (sampletype[numsignals-1-s]==0)
c=buffer[k++]; c=buffer[k++];
else if (sampletype[numsignals-1-s]==1) else if (sampletype[numsignals-1-s]==1) {
c=ucbuffer[k++]; c=ucbuffer[k++];
if (c<40) {
c=min[s];
//int q=0;
}
}
if (first[s]) { if (first[s]) {
min[s]=max[s]=c; min[s]=max[s]=c;
first[s]=false; first[s]=false;
} else {
if (min[s]>c) min[s]=c;
if (max[s]<c) max[s]=c;
} }
if (min[s]>c) min[s]=c;
if (max[s]<c) max[s]=c;
data[s][pos[s]++]=c; data[s][pos[s]++]=c;
} }
} }
@ -1054,7 +1061,7 @@ void InitModelMap()
ModelMap[34]="RemStar Pro with C-Flex+"; ModelMap[34]="RemStar Pro with C-Flex+";
ModelMap[35]="RemStar Auto with A-Flex"; ModelMap[35]="RemStar Auto with A-Flex";
ModelMap[37]="RemStar BIPAP Auto with Bi-Flex"; ModelMap[37]="RemStar BIPAP Auto with Bi-Flex";
ModelMap[0x41]="RemStar Something ASV with Funky-Flex"; ModelMap[0x41]="BiPAP autoSV Advanced";
}; };

View File

@ -118,11 +118,14 @@ Daily::Daily(QWidget *parent,QGLContext *context) :
AddCPAPData(mpw=new WaveData(CPAP_MaskPressure,1000000)); //FlowRate AddCPAPData(mpw=new WaveData(CPAP_MaskPressure,1000000)); //FlowRate
MP=new gGraphWindow(gSplitter,tr("Mask Pressure"),SF); MP=new gGraphWindow(gSplitter,tr("Mask Pressure"),SF);
MP->AddLayer(new gYAxis()); gYAxis *y=new gYAxis();
y->SetScale(.1);
MP->AddLayer(y);
MP->AddLayer(new gXAxis()); MP->AddLayer(new gXAxis());
gLineChart *g=new gLineChart(mpw,Qt::black,4000,true); gLineChart *g=new gLineChart(mpw,Qt::black,4000,true);
g->ReportEmpty(true); g->ReportEmpty(true);
MP->AddLayer(g); MP->AddLayer(g);
MP->setMinimumHeight(120);
AddCPAPData(frw=new WaveData(CPAP_FlowRate,1000000)); //FlowRate AddCPAPData(frw=new WaveData(CPAP_FlowRate,1000000)); //FlowRate
@ -634,7 +637,7 @@ void Daily::Load(QDate date)
if (mode==MODE_BIPAP) { if (mode==MODE_BIPAP) {
html+="<tr><td colspan=4 align='center'><i>"+tr("90%&nbsp;EPAP ")+QString().sprintf("%.2f",eap90)+tr("cmH2O")+"</td></tr>\n" html+="<tr><td colspan=4 align='center'><i>"+tr("90%&nbsp;EPAP ")+QString().sprintf("%.2f",eap90)+tr("cmH2O")+"</td></tr>\n"
"<tr><td colspan=4 align='center'><i>"+tr("90%&nbsp;IPAP ")+QString().sprintf("%.2f",iap90)+"</td></tr>\n"; "<tr><td colspan=4 align='center'><i>"+tr("90%&nbsp;IPAP ")+QString().sprintf("%.2f",iap90)+tr("cmH2O")+"</td></tr>\n";
} else if (mode==MODE_APAP) { } else if (mode==MODE_APAP) {
html+=("<tr><td colspan=4 align='center'><i>")+tr("90%&nbsp;Pressure ")+QString().sprintf("%.2f",cpap->summary_weighted_avg(CPAP_PressurePercentValue))+("</i></td></tr>\n"); html+=("<tr><td colspan=4 align='center'><i>")+tr("90%&nbsp;Pressure ")+QString().sprintf("%.2f",cpap->summary_weighted_avg(CPAP_PressurePercentValue))+("</i></td></tr>\n");
} else if (mode==MODE_CPAP) { } else if (mode==MODE_CPAP) {