diff --git a/Graphs/gFlagsLine.cpp b/Graphs/gFlagsLine.cpp index f2760776..30625349 100644 --- a/Graphs/gFlagsLine.cpp +++ b/Graphs/gFlagsLine.cpp @@ -104,7 +104,7 @@ gFlagsLine::gFlagsLine(ChannelID code,QColor flag_color,QString label,bool alway gFlagsLine::~gFlagsLine() { //delete lines; - delete quads; + //delete quads; } void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height) { diff --git a/Graphs/gGraphView.cpp b/Graphs/gGraphView.cpp index 0c28f9ac..18deafa5 100644 --- a/Graphs/gGraphView.cpp +++ b/Graphs/gGraphView.cpp @@ -69,7 +69,7 @@ GLBuffer::GLBuffer(QColor color,int max,int type) GLBuffer::~GLBuffer() { if (colors) delete [] colors; - delete [] buffer; + if (buffer) delete [] buffer; } void GLBuffer::add(GLshort s) { @@ -178,16 +178,21 @@ void GLBuffer::draw() if (antialias) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - if (m_type==GL_LINES) { + if (m_type==GL_LINES || m_type==GL_LINE_LOOP) { glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); size+=0.5; + } else if (m_type==GL_POLYGON) { + glEnable(GL_POLYGON_SMOOTH); + glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); } } - if (m_type==GL_LINES) { + if (m_type==GL_LINES || m_type==GL_LINE_LOOP) { glLineWidth(size); } else if (m_type==GL_POINTS) { glPointSize(size); + } else if (m_type==GL_POLYGON) { + glPolygonMode(GL_BACK,GL_FILL); } if (m_scissor) { glScissor(s1,s2,s3,s4); @@ -221,9 +226,14 @@ void GLBuffer::draw() glDisable(GL_SCISSOR_TEST); m_scissor=false; } + if (m_type==GL_POLYGON) { + glPolygonMode(GL_BACK,GL_FILL); + } if (antialias) { - if (m_type==GL_LINES) { + if (m_type==GL_LINES || m_type==GL_LINE_LOOP) { glDisable(GL_LINE_SMOOTH); + } else if (m_type==GL_POLYGON) { + glDisable(GL_POLYGON_SMOOTH); } glDisable(GL_BLEND); } @@ -347,6 +357,9 @@ Layer::Layer(ChannelID code) Layer::~Layer() { + for (int i=0;idraw(); DrawTextQue(); m_tooltip->paint(); - if (pref["ShowDebug"].toBool()) { + if (m_showsplitter && pref["ShowDebug"].toBool()) { QString ss; ss="PreDraw took "+QString::number(elapsed)+"ms"; AddTextQue(ss,width()-140,10,0,col,defaultfont); diff --git a/Graphs/gGraphView.h b/Graphs/gGraphView.h index 701b89ef..e3668d6d 100644 --- a/Graphs/gGraphView.h +++ b/Graphs/gGraphView.h @@ -283,6 +283,10 @@ public: void ToolTip(QString text, int x, int y, int timeout=2000); void redraw(); void timedRedraw(int ms); + void setMargins(short left,short right,short top,short bottom) { + m_marginleft=left; m_marginright=right; + m_margintop=top; m_marginbottom=bottom; + } GLBuffer * lines(); GLBuffer * backlines(); diff --git a/Graphs/gLineChart.cpp b/Graphs/gLineChart.cpp index 197d960a..424a9317 100644 --- a/Graphs/gLineChart.cpp +++ b/Graphs/gLineChart.cpp @@ -22,7 +22,7 @@ gLineChart::gLineChart(ChannelID code,QColor col,bool square_plot, bool disable_ } gLineChart::~gLineChart() { - delete lines; + //delete lines; //delete outlines; } diff --git a/Graphs/gLineOverlay.cpp b/Graphs/gLineOverlay.cpp index a400d399..3334e570 100644 --- a/Graphs/gLineOverlay.cpp +++ b/Graphs/gLineOverlay.cpp @@ -22,8 +22,8 @@ gLineOverlayBar::gLineOverlayBar(ChannelID code,QColor color,QString label,FlagT gLineOverlayBar::~gLineOverlayBar() { //delete lines; - delete quads; - delete points; + //delete quads; + //delete points; } void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int height) diff --git a/Graphs/gSegmentChart.cpp b/Graphs/gSegmentChart.cpp index f671cd1b..b9acbf30 100644 --- a/Graphs/gSegmentChart.cpp +++ b/Graphs/gSegmentChart.cpp @@ -9,10 +9,16 @@ gSegmentChart::gSegmentChart(GraphSegmentType type,QColor gradient_color,QColor outline_color) -:Layer(""),m_graph_type(type),m_gradient_color(gradient_color),m_outline_color(outline_color) +:Layer("EmptyChannel"),m_graph_type(type),m_gradient_color(gradient_color),m_outline_color(outline_color) { // m_gradient_color=QColor(200,200,200); m_empty=true; + addGLBuf(poly=new GLBuffer(gradient_color,2000,GL_POLYGON)); + addGLBuf(lines=new GLBuffer(outline_color,2000,GL_LINE_LOOP)); + lines->setSize(1); + poly->forceAntiAlias(false); + lines->forceAntiAlias(true); + lines->setAntiAlias(true); } gSegmentChart::~gSegmentChart() { @@ -56,7 +62,6 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height) { if (!m_visible) return; if (!m_day) return; - //if (!m_total) return; int start_px=left; int start_py=top; @@ -67,7 +72,7 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height) float j=0.0; float sum=0.0; - float step=1.0/45.0; + float step=1.0/180.0; float px,py; float q; @@ -88,24 +93,17 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height) return; } - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - glEnable(GL_LINE_SMOOTH); - glLineWidth(1.5); int data; unsigned size=m_values.size(); float line_step=float(width)/float(size-1); bool line_first=true; int line_last; - - if (m_graph_type==GST_Line) { - w.qglColor(m_outline_color); - glBegin(GL_LINES); - } - + GLBuffer *quads=w.quads(); + GLBuffer *lines2=w.lines(); for (unsigned m=0;madd(start_px+xoffset, start_py+height-yoffset,m_gradient_color); for (q=sum;qadd(px,py,col); } q=sum+j; px=start_px+xoffset+sin(q*2*M_PI)*radius; py=start_py+height-(yoffset+cos(q*2*M_PI)*radius); - glVertex2f(px,py); - glEnd(); + poly->add(px,py,col); - // Draw Outline - //m_outline_color=Qt::red; - w.qglColor(m_outline_color); if (m_total>data) { // Draw the center point first - //glPolygonMode(GL_BACK,GL_LINE); - glBegin(GL_LINE_LOOP); - glVertex2f(start_px+xoffset, start_py+height-yoffset); - } else { // Only one entry, so just draw the circle - glBegin(GL_LINE_LOOP); + lines->add(start_px+xoffset, start_py+height-yoffset,m_outline_color); } for (q=sum;qadd(px,py,m_outline_color); } double tpx=start_px+xoffset+sin((sum+(j/2.0))*2*M_PI)*(radius/1.7); double tpy=start_py+height-(yoffset+cos((sum+(j/2.0))*2*M_PI)*(radius/1.7)); q=sum+j; px=start_px+xoffset+sin(q*2*M_PI)*radius; py=start_py+height-(yoffset+cos(q*2*M_PI)*radius); - glVertex2f(px,py); - glEnd(); + lines->add(px,py,m_outline_color); if (j>.09) { - //glBegin(GL_POINTS); - //glVertex2f(tpx,tpy); - //glEnd(); QString a=m_names[m]; //QString::number(floor(100.0/m_total*data),'f',0)+"%"; int x,y; GetTextExtent(a,x,y); @@ -171,23 +153,11 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height) } else if (m_graph_type==GST_CandleStick) { float bw=xmult*float(data); - glBegin(GL_QUADS); - w.qglColor(m_gradient_color); - glVertex2f(xp,start_py); - glVertex2f(xp+bw,start_py); - w.qglColor(m_colors[m % m_colors.size()]); - glVertex2f(xp+bw,start_py+height); - glVertex2f(xp,start_py+height); - glEnd(); + quads->add(xp,start_py,xp+bw,start_py,m_gradient_color); + quads->add(xp+bw,start_py+height,xp,start_py+height,col); - w.qglColor(m_outline_color); - - glBegin(GL_LINE_LOOP); - glVertex2f(xp,start_py); - glVertex2f(xp+bw,start_py); - glVertex2f(xp+bw,start_py+height); - glVertex2f(xp,start_py+height); - glEnd(); + lines->add(xp,start_py,xp+bw,start_py,m_outline_color); + lines->add(xp+bw,start_py+height,xp,start_py+height,m_outline_color); if (!m_names[m].isEmpty()) { int px,py; @@ -203,19 +173,12 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height) if (line_first) { line_first=false; } else { - glVertex2f(xp,line_last); + lines->add(xp,line_last,xp+line_step,h,col); xp+=line_step; - glVertex2f(xp,h); } line_last=h; } } - if (m_graph_type==GST_Line) { - glEnd(); - } - glPolygonMode(GL_BACK,GL_FILL); - glDisable(GL_LINE_SMOOTH); - glDisable(GL_BLEND); } diff --git a/Graphs/gSegmentChart.h b/Graphs/gSegmentChart.h index bcec4df4..8f89482f 100644 --- a/Graphs/gSegmentChart.h +++ b/Graphs/gSegmentChart.h @@ -32,6 +32,7 @@ protected: QColor m_gradient_color; QColor m_outline_color; bool m_empty; + GLBuffer *poly,*lines; }; class gTAPGraph:public gSegmentChart diff --git a/SleepLib/loader_plugins/prs1_loader.cpp b/SleepLib/loader_plugins/prs1_loader.cpp index 802b1ef0..ddc42570 100644 --- a/SleepLib/loader_plugins/prs1_loader.cpp +++ b/SleepLib/loader_plugins/prs1_loader.cpp @@ -331,20 +331,20 @@ int PRS1Loader::OpenMachine(Machine *m,QString path,Profile *profile) //sess->p90(CPAP_EPAP); //sess->p90(CPAP_IPAP); } else { - sess->avg(CPAP_Pressure); - sess->wavg(CPAP_Pressure); - sess->p90(CPAP_Pressure); - sess->min(CPAP_Pressure); - sess->max(CPAP_Pressure); - sess->cph(CPAP_Pressure); + //sess->avg(CPAP_Pressure); + //sess->wavg(CPAP_Pressure); + //sess->p90(CPAP_Pressure); + //sess->min(CPAP_Pressure); + //sess->max(CPAP_Pressure); + //sess->cph(CPAP_Pressure); if (!sess->settings.contains(CPAP_PressureMin)) { sess->settings[CPAP_BrokenSummary]=true; //sess->set_last(sess->first()); if (sess->min(CPAP_Pressure)==sess->max(CPAP_Pressure)) { - sess->settings["PRS1Mode"]=MODE_CPAP; // no ramp + sess->settings[CPAP_Mode]=MODE_CPAP; // no ramp } else { - sess->settings["PRS1Mode"]=MODE_UNKNOWN; + sess->settings[CPAP_Mode]=MODE_UNKNOWN; } //sess->Set("FlexMode",PR_UNKNOWN); } @@ -368,6 +368,9 @@ int PRS1Loader::OpenMachine(Machine *m,QString path,Profile *profile) //qDebug() << "OpenMachine Done"; return true; } +//bool PRS1Loader::OpenMachine() +//{ +//} bool PRS1Loader::OpenSummary(Session *session,QString filename) { diff --git a/daily.cpp b/daily.cpp index 1156dda2..77ea2c7a 100644 --- a/daily.cpp +++ b/daily.cpp @@ -54,6 +54,10 @@ Daily::Daily(QWidget *parent,Profile * _profile,gGraphView * shared, MainWindow GraphView=new gGraphView(ui->graphMainArea,shared); GraphView->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); + snapGV=new gGraphView(ui->graphMainArea,shared); + snapGV->setMinimumSize(172,172); + snapGV->hideSplitter(); + snapGV->hide(); scrollbar=new MyScrollBar(ui->graphMainArea); scrollbar->setOrientation(Qt::Vertical); scrollbar->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Expanding); @@ -63,17 +67,6 @@ Daily::Daily(QWidget *parent,Profile * _profile,gGraphView * shared, MainWindow layout->addWidget(GraphView,1); layout->addWidget(scrollbar,0); - // GAHI=new gGraph(GraphView,"Event Breakdown",default_height); - /*gSegmentChart * seg=new gSegmentChart(GST_Pie); - seg->AddSlice(CPAP_Hypopnea,QColor(0x40,0x40,0xff,0xff),"H"); - seg->AddSlice(CPAP_Apnea,QColor(0x20,0x80,0x20,0xff),"A"); - seg->AddSlice(CPAP_Obstructive,QColor(0x40,0xaf,0xbf,0xff),"OA"); - seg->AddSlice(CPAP_ClearAirway,QColor(0xb2,0x54,0xcd,0xff),"CA"); - seg->AddSlice(CPAP_RERA,QColor(0xff,0xff,0x80,0xff),"RE"); - seg->AddSlice(CPAP_FlowLimit,QColor(0x40,0x40,0x40,0xff),"FL"); - - SF->AddLayer(AddCPAP(seg),LayerRight,100); */ - SF=new gGraph(GraphView,"Event Flags",default_height); FRW=new gGraph(GraphView,"Flow Rate",default_height); MP=new gGraph(GraphView,"Mask Pressure",default_height); @@ -95,6 +88,21 @@ Daily::Daily(QWidget *parent,Profile * _profile,gGraphView * shared, MainWindow SPO2=new gGraph(GraphView,"SPO2",default_height,1); PLETHY=new gGraph(GraphView,"Plethy",default_height,1); + // Event Pie Chart (for snapshot purposes) + // TODO: Convert snapGV to generic for snapshotting multiple graphs (like reports does) + GAHI=new gGraph(snapGV,"Breakdown",172); + gSegmentChart * evseg=new gSegmentChart(GST_Pie); + evseg->AddSlice(CPAP_Hypopnea,QColor(0x40,0x40,0xff,0xff),"H"); + evseg->AddSlice(CPAP_Apnea,QColor(0x20,0x80,0x20,0xff),"A"); + evseg->AddSlice(CPAP_Obstructive,QColor(0x40,0xaf,0xbf,0xff),"OA"); + evseg->AddSlice(CPAP_ClearAirway,QColor(0xb2,0x54,0xcd,0xff),"CA"); + evseg->AddSlice(CPAP_RERA,QColor(0xff,0xff,0x80,0xff),"RE"); + evseg->AddSlice(CPAP_FlowLimit,QColor(0x40,0x40,0x40,0xff),"FL"); + + GAHI->AddLayer(AddCPAP(evseg)); + GAHI->setMargins(0,0,0,0); + //SF->AddLayer(AddCPAP(evseg),LayerRight,100); + gFlagsGroup *fg=new gFlagsGroup(); fg->AddLayer((new gFlagsLine(CPAP_CSR,QColor("light green"),"CSR",false,FT_Span))); fg->AddLayer((new gFlagsLine(CPAP_ClearAirway,QColor("purple"),"CA",true))); @@ -389,9 +397,11 @@ void Daily::Load(QDate date) UpdateOXIGraphs(oxi); UpdateCPAPGraphs(cpap); UpdateEventsTree(ui->treeWidget,cpap); + snapGV->setDay(cpap); GraphView->ResetBounds(); + //snapGV->ResetBounds(); //GraphView->ResetBounds(1); //GraphView->setEmptyText(tr("No Data")); //tr("No data for ")+date.toString(Qt::SystemLocaleLongDate)); @@ -405,6 +415,7 @@ void Daily::Load(QDate date) scrollbar->show(); } GraphView->updateGL(); + snapGV->updateGL(); //RedrawGraphs(); @@ -490,18 +501,18 @@ void Daily::Load(QDate date) // ^^ Scratch that.. pie now includes text.. // if (pref["EnableGraphSnapshots"].toBool()) { // AHI Pie Chart -// if (ahi+rei+fli>0) { -// html+="\n"+tr("Event Breakdown")+"\n"; -// G_AHI->setFixedSize(gwwidth,120); -// QPixmap pixmap=G_AHI->renderPixmap(gwwidth,120,false); //gwwidth,gwheight,false); -// QByteArray byteArray; -// QBuffer buffer(&byteArray); // use buffer to store pixmap into byteArray -// buffer.open(QIODevice::WriteOnly); -// pixmap.save(&buffer, "PNG"); -// html += "\n"; -// } else { -// html += "\n"; -// } + if (ahi+rei+fli>0) { + html+="\n"; //"+tr("Event Breakdown")+"\n"; + //G_AHI->setFixedSize(gwwidth,120); + QPixmap pixmap=snapGV->renderPixmap(172,172,false); //gwwidth,gwheight,false); + QByteArray byteArray; + QBuffer buffer(&byteArray); // use buffer to store pixmap into byteArray + buffer.open(QIODevice::WriteOnly); + pixmap.save(&buffer, "PNG"); + html += "\n"; + } else { + html += "\n"; + } // } } html+=""; @@ -762,7 +773,7 @@ void Daily::UpdateCPAPGraphs(Day *day) for (QList::iterator g=CPAPData.begin();g!=CPAPData.end();g++) { (*g)->SetDay(day); } -}; +} void Daily::UpdateOXIGraphs(Day *day) { diff --git a/daily.h b/daily.h index 47ce2916..dad5ebbc 100644 --- a/daily.h +++ b/daily.h @@ -91,10 +91,9 @@ private: //QVBoxLayout *splitter; QMenu *show_graph_menu; - gGraphView *GraphView; + gGraphView *GraphView,*snapGV; MyScrollBar *scrollbar; QHBoxLayout *layout; - }; #endif // DAILY_H