diff --git a/Graphs/gGraphView.cpp b/Graphs/gGraphView.cpp index c6af7736..6bbace3d 100644 --- a/Graphs/gGraphView.cpp +++ b/Graphs/gGraphView.cpp @@ -948,7 +948,7 @@ void gGraphView::paintGL() glVertex2f(0, height()); glVertex2f(0, 0); - glColor4f(0.3,0.3,1.0,1.0); // Gradient End + glColor4f(0.6,0.6,1.0,1.0); // Gradient End glVertex2f(width(), 0); glVertex2f(width(), height()); diff --git a/Graphs/gLineChart.cpp b/Graphs/gLineChart.cpp index 72cd98c8..63c204f4 100644 --- a/Graphs/gLineChart.cpp +++ b/Graphs/gLineChart.cpp @@ -39,7 +39,15 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height) EventDataType miny,maxy; double minx,maxx; - miny=w.min_y, maxy=w.max_y, maxx=w.max_x, minx=w.min_x; + miny=w.min_y, maxy=w.max_y; + + if (w.blockZoom()) { + minx=w.rmin_x, maxx=w.rmax_x; + } else { + maxx=w.max_x, minx=w.min_x; + } + + if (miny<0) { miny=-MAX(fabs(miny),fabs(maxy)); } @@ -82,7 +90,7 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height) double xmult=double(width)/xx; EventDataType yy=maxy-miny; - EventDataType ymult=EventDataType(height-2)/yy; // time to pixel conversion multiplier + EventDataType ymult=EventDataType(height-3)/yy; // time to pixel conversion multiplier // Return on screwy min/max conditions if (xx<0) @@ -246,7 +254,7 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height) } int xst=left+1; - int yst=top+height-1; + int yst=top+height+1; double time; EventDataType data; diff --git a/Graphs/gSegmentChart.cpp b/Graphs/gSegmentChart.cpp index 9842998c..3e8229a2 100644 --- a/Graphs/gSegmentChart.cpp +++ b/Graphs/gSegmentChart.cpp @@ -9,7 +9,7 @@ gSegmentChart::gSegmentChart(GraphSegmentType type,QColor gradient_color,QColor outline_color) -:gLayer(EmptyChannel),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); } @@ -26,7 +26,7 @@ void gSegmentChart::AddSlice(ChannelID code,QColor color,QString name) } void gSegmentChart::SetDay(Day *d) { - gLayer::SetDay(d); + Layer::SetDay(d); m_total=0; if (!m_day) return; for (int c=0;ccount(m_codes[i])>0) { + res=false; + break; + } + } + return res; +} -void gSegmentChart::Plot(gGraphWindow & w,float scrx,float scry) +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=w.GetLeftMargin(); - int start_py=w.GetBottomMargin(); - int width=scrx-(w.GetLeftMargin()+w.GetRightMargin()); - int height=scry-(w.GetTopMargin()+w.GetBottomMargin()); + int start_px=left; + int start_py=top; + width--; float diameter=MIN(width,height); diameter-=8; @@ -63,23 +74,24 @@ void gSegmentChart::Plot(gGraphWindow & w,float scrx,float scry) float xmult=float(width)/float(m_total); float ymult=float(height)/float(m_total); - float xp=w.GetLeftMargin(); + float xp=left; int xoffset=width/2; int yoffset=height/2; if (m_total==0) { - w.qglColor(Qt::green); + QColor col=Qt::green; QString a=":-)"; float x,y; GetTextExtent(a,x,y,bigfont); - w.renderText(start_px+xoffset-x/2, scry-(start_py+yoffset-y/2),a,*bigfont); + + w.renderText(a,start_px+xoffset-x/2, (start_py+yoffset-y/2),0,col,bigfont); return; } + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); glLineWidth(1.5); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); int data; unsigned size=m_values.size(); float line_step=float(width)/float(size-1); @@ -102,41 +114,42 @@ void gSegmentChart::Plot(gGraphWindow & w,float scrx,float scry) j=float(data)/float(m_total); // ratio of this pie slice // Draw Filling - glPolygonMode(GL_BACK,GL_FILL); glBegin(GL_POLYGON); + glPolygonMode(GL_BACK,GL_FILL); w.qglColor(m_gradient_color); - glVertex2f(start_px+xoffset, start_py+yoffset); + glVertex2f(start_px+xoffset, start_py+height-yoffset); w.qglColor(m_colors[m % m_colors.size()]); for (q=sum;qdata) { // Draw the center point first - glPolygonMode(GL_BACK,GL_LINE); - glBegin(GL_POLYGON); - glVertex2f(start_px+xoffset, start_py+yoffset); + //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); } for (q=sum;q tap; diff --git a/Graphs/gSegmentChart.h b/Graphs/gSegmentChart.h index bc1a6087..af6f7b99 100644 --- a/Graphs/gSegmentChart.h +++ b/Graphs/gSegmentChart.h @@ -1,18 +1,19 @@ #ifndef GSEGMENTCHART_H #define GSEGMENTCHART_H -#include "graphlayer.h" +#include "gGraphView.h" enum GraphSegmentType { GST_Pie, GST_CandleStick, GST_Line }; -class gSegmentChart : public gLayer +class gSegmentChart : public Layer { public: gSegmentChart(GraphSegmentType gt=GST_Pie, QColor gradient_color=Qt::white,QColor outline_color=Qt::black); virtual ~gSegmentChart(); - virtual void Plot(gGraphWindow & w,float scrx,float scry); + virtual void paint(gGraph & w,int left, int top, int width, int height); virtual void SetDay(Day *d); + virtual bool isEmpty(); void AddSlice(ChannelID code,QColor col,QString name=""); void setGradientColor(QColor & color) { m_gradient_color=color; } diff --git a/daily.cpp b/daily.cpp index bf0146fe..2bf940aa 100644 --- a/daily.cpp +++ b/daily.cpp @@ -70,21 +70,37 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw) layout->addWidget(GraphView,1); layout->addWidget(scrollbar,0); - SF=new gGraph(GraphView,"Event Flags",180); - FRW=new gGraph(GraphView,"Flow Rate",180); - MP=new gGraph(GraphView,"Mask Pressure",180); - PRD=new gGraph(GraphView,"Pressure",180); - LEAK=new gGraph(GraphView,"Leak",180); - SNORE=new gGraph(GraphView,"Snore",180); - RR=new gGraph(GraphView,"Respiratory Rate",180); - TV=new gGraph(GraphView,"Tidal Volume",180); - MV=new gGraph(GraphView,"Minute Ventilation",180); - FLG=new gGraph(GraphView,"Flow Limitation",180); - PTB=new gGraph(GraphView,"Patient Trig. Breath",180); + const int default_height=150; + SF=new gGraph(GraphView,"Event Flags",default_height); - PULSE=new gGraph(GraphView,"Pulse",180,1); - SPO2=new gGraph(GraphView,"SPO2",180,1); - PLETHY=new gGraph(GraphView,"Plethy",180,1); + // 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); + + FRW=new gGraph(GraphView,"Flow Rate",default_height); + MP=new gGraph(GraphView,"Mask Pressure",default_height); + PRD=new gGraph(GraphView,"Pressure",default_height); + LEAK=new gGraph(GraphView,"Leak",default_height); + SNORE=new gGraph(GraphView,"Snore",default_height); + RR=new gGraph(GraphView,"Respiratory Rate",default_height); + TV=new gGraph(GraphView,"Tidal Volume",default_height); + MV=new gGraph(GraphView,"Minute Ventilation",default_height); + FLG=new gGraph(GraphView,"Flow Limitation",default_height); + PTB=new gGraph(GraphView,"Patient Trig. Breath",default_height); + RE=new gGraph(GraphView,"Respiratory Event",default_height); + IE=new gGraph(GraphView,"I:E",default_height); + TE=new gGraph(GraphView,"Te",default_height); + TI=new gGraph(GraphView,"Ti",default_height); + PULSE=new gGraph(GraphView,"Pulse",default_height,1); + SPO2=new gGraph(GraphView,"SPO2",default_height,1); + PLETHY=new gGraph(GraphView,"Plethy",default_height,1); gFlagsGroup *fg=new gFlagsGroup(); @@ -105,12 +121,6 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw) //SF->AddLayer(new gFooBar(),LayerBottom,0,1); SF->AddLayer(new gXAxis(Qt::black,false),LayerBottom,0,gXAxis::Margin); - PRD->AddLayer(new gXGrid()); - PRD->AddLayer(AddCPAP(new gLineChart(CPAP_Pressure,QColor("dark green"),true))); - PRD->AddLayer(AddCPAP(new gLineChart(CPAP_EPAP,Qt::blue,true))); - PRD->AddLayer(AddCPAP(new gLineChart(CPAP_IPAP,Qt::red,true))); - PRD->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - PRD->AddLayer(new gXAxis(),LayerBottom,0,20); gLineChart *l; l=new gLineChart(CPAP_FlowRate,Qt::black,false,false); @@ -134,74 +144,35 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw) FRW->AddLayer(AddCPAP(new gLineOverlayBar(CPAP_Obstructive,QColor("#40c0ff"),"OA"))); FRW->AddLayer(AddCPAP(new gLineOverlayBar(CPAP_ClearAirway,QColor("purple"),"CA"))); - LEAK->AddLayer(new gXGrid()); + + gGraph *graphs[]={ PRD, LEAK, SNORE, PTB, MP, RR, MV, TV, FLG, IE, TI, TE, SPO2, PLETHY, PULSE }; + int ng=sizeof(graphs)/sizeof(gGraph*); + for (int i=0;iAddLayer(new gXGrid()); + } + PRD->AddLayer(AddCPAP(new gLineChart(CPAP_Pressure,QColor("dark green"),true))); + PRD->AddLayer(AddCPAP(new gLineChart(CPAP_EPAP,Qt::blue,true))); + PRD->AddLayer(AddCPAP(new gLineChart(CPAP_IPAP,Qt::red,true))); LEAK->AddLayer(AddCPAP(new gLineChart(CPAP_Leak,Qt::darkYellow,true))); - LEAK->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - LEAK->AddLayer(new gXAxis(),LayerBottom,0,20); - - SNORE->AddLayer(new gXGrid()); SNORE->AddLayer(AddCPAP(new gLineChart(CPAP_Snore,Qt::darkGray,true))); - SNORE->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - SNORE->AddLayer(new gXAxis(),LayerBottom,0,20); - - PTB->AddLayer(new gXGrid()); PTB->AddLayer(AddCPAP(new gLineChart(CPAP_PatientTriggeredBreaths,Qt::gray,true))); - PTB->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - PTB->AddLayer(new gXAxis(),LayerBottom,0,20); - - MP->AddLayer(new gXGrid()); MP->AddLayer(AddCPAP(new gLineChart(CPAP_MaskPressure,Qt::blue,false))); - MP->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - MP->AddLayer(new gXAxis(),LayerBottom,0,20); - - RR->AddLayer(new gXGrid()); RR->AddLayer(AddCPAP(new gLineChart(CPAP_RespiratoryRate,Qt::darkMagenta,true))); - RR->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - RR->AddLayer(new gXAxis(),LayerBottom,0,20); - - MV->AddLayer(new gXGrid()); MV->AddLayer(AddCPAP(new gLineChart(CPAP_MinuteVentilation,Qt::darkCyan,true))); - MV->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - MV->AddLayer(new gXAxis(),LayerBottom,0,20); - - TV->AddLayer(new gXGrid()); TV->AddLayer(AddCPAP(new gLineChart(CPAP_TidalVolume,Qt::magenta,true))); - TV->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - TV->AddLayer(new gXAxis(),LayerBottom,0,20); - - FLG->AddLayer(new gXGrid()); FLG->AddLayer(AddCPAP(new gLineChart(CPAP_FlowLimitGraph,Qt::darkBlue,true))); - FLG->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - FLG->AddLayer(new gXAxis(),LayerBottom,0,20); - - - PULSE->AddLayer(new gXGrid()); + //RE->AddLayer(AddCPAP(new gLineChart(CPAP_RespiratoryEvent,Qt::magenta,true))); + IE->AddLayer(AddCPAP(new gLineChart(CPAP_IE,Qt::darkRed,true))); + TE->AddLayer(AddCPAP(new gLineChart(CPAP_Te,Qt::darkGreen,true))); + TI->AddLayer(AddCPAP(new gLineChart(CPAP_Ti,Qt::darkBlue,true))); PULSE->AddLayer(AddOXI(new gLineChart(OXI_Pulse,Qt::red,true))); - PULSE->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - PULSE->AddLayer(new gXAxis(),LayerBottom,0,20); - - SPO2->AddLayer(new gXGrid()); SPO2->AddLayer(AddOXI(new gLineChart(OXI_SPO2,Qt::blue,true))); - SPO2->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - SPO2->AddLayer(new gXAxis(),LayerBottom,0,20); - - PLETHY->AddLayer(new gXGrid()); PLETHY->AddLayer(AddOXI(new gLineChart(OXI_Plethysomogram,Qt::darkBlue,false))); - PLETHY->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); - PLETHY->AddLayer(new gXAxis(),LayerBottom,0,20); - - //AddGraph(SF); - //AddGraph(FRW); - //AddGraph(PRD); - - NoData=new QLabel(tr("No data"),ui->graphMainArea); - NoData->setAlignment(Qt::AlignCenter); - QFont font("Sans Serif",20); //NoData->font(); - //font.setBold(true); - NoData->setFont(font); - layout->addWidget(NoData,0); - NoData->hide(); + for (int i=0;iAddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); + graphs[i]->AddLayer(new gXAxis(),LayerBottom,0,20); + } layout->layout(); @@ -494,15 +465,6 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw) TAP->hide(); TAP->SetGradientBackground(false); - G_AHI->SetMargins(0,0,0,0); - 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"); - G_AHI->AddLayer(AddCPAP(seg)); G_AHI->SetGradientBackground(false); G_AHI->hide(); diff --git a/daily.h b/daily.h index 8aa805f2..34917cfe 100644 --- a/daily.h +++ b/daily.h @@ -68,18 +68,10 @@ private: void UpdateCalendarDay(QDate date); void UpdateEventsTree(QTreeWidget * tree,Day *day); - //gLineChart *frw,*prd,*leak,*pr_ipap,*pr_epap,*snore,*pulse,*spo2,*rr,*mv,*tv,*mp,*flg,*ptb; - - //gPointData *tap,*tap_eap,*tap_iap,*g_ahi,*frw,*prd,*leak,*pressure_iap,*pressure_eap,*snore; - //gPointData *pulse,*spo2,*rr,*mv,*tv,*mp,*flg,*ptb; - - //gFlagsGroup *fg; - gGraph *PRD,*FRW,*G_AHI,*TAP,*LEAK,*SF,*TAP_EAP,*TAP_IAP,*PULSE,*SPO2, + gGraph *PRD,*FRW,*GAHI,*TAP,*LEAK,*SF,*TAP_EAP,*TAP_IAP,*PULSE,*SPO2, *SNORE,*RR,*MP,*MV,*TV,*FLG,*PTB,*OF,*INTPULSE,*INTSPO2, *THPR, *PLETHY,*TI,*TE, *RE, *IE; - //gLineChart *pressure, *epap, *ipap; - QList OXIData; QList CPAPData; //QVector Graphs; @@ -99,10 +91,8 @@ private: QDate previous_date; //QScrollArea *scrollArea; //QVBoxLayout *splitter; - QLabel *NoData; - QWidget *spacer; QMenu *show_graph_menu; - QWidget *GraphLayout; + gGraphView *GraphView; MyScrollBar *scrollbar; QHBoxLayout *layout; diff --git a/oximetry.cpp b/oximetry.cpp index c7b1bc84..336e2f99 100644 --- a/oximetry.cpp +++ b/oximetry.cpp @@ -107,6 +107,7 @@ Oximetry::Oximetry(QWidget *parent,gGraphView * shared) : PULSE->AddLayer(pulse); SPO2->AddLayer(spo2); + GraphView->setEmptyText(""); GraphView->updateGL(); on_RefreshPortsButton_clicked(); @@ -202,6 +203,8 @@ void Oximetry::on_RunButton_toggled(bool checked) ev_plethy->setLast(lasttime+3600000); PLETHY->SetMinX(lasttime); PLETHY->SetMaxX(lasttime+30000); + CONTROL->SetMinX(lasttime); + CONTROL->SetMaxX(lasttime+30000); ev_pulse->setFirst(lasttime); ev_pulse->setLast(lasttime+3600000); @@ -263,9 +266,14 @@ void Oximetry::on_RunButton_toggled(bool checked) PLETHY->MinX(); PLETHY->MaxX(); //GraphView->ResetBounds(); - CONTROL->SetMinX(ev_plethy->first()); - CONTROL->SetMaxX(lasttime); - CONTROL->ResetBounds(); + //CONTROL->SetMinX(PLETHY->MinX()); + //CONTROL->SetMaxX(PLETHY->MaxX()); + //CONTROL->SetMinY(ev_plethy->min()); + //CONTROL->SetMaxY(ev_plethy->max()); + CONTROL->MinX(); + CONTROL->MaxX(); + + //CONTROL->ResetBounds(); qint64 d=session->length(); // if (d<=30000) @@ -366,6 +374,8 @@ void Oximetry::UpdatePlethy(qint8 d) lasttime+=20; // 50 samples per second PLETHY->SetMinY(ev_plethy->min()); PLETHY->SetMaxY(ev_plethy->max()); + CONTROL->SetMinY(ev_plethy->min()); + CONTROL->SetMaxY(ev_plethy->max()); PULSE->SetMinY(ev_pulse->min()); PULSE->SetMaxY(ev_pulse->max()); SPO2->SetMinY(ev_spo2->min()); @@ -377,10 +387,14 @@ void Oximetry::UpdatePlethy(qint8 d) PULSE->SetMinX(lasttime-30000); SPO2->SetMaxX(lasttime); SPO2->SetMinX(lasttime-30000); + CONTROL->SetMaxX(lasttime); + CONTROL->SetMinX(lasttime-30000); session->set_last(lasttime); day->setLast(lasttime); PLETHY->MinX(); PLETHY->MaxX(); + CONTROL->MinX(); + CONTROL->MaxX(); } bool Oximetry::UpdatePulse(qint8 pul) { @@ -438,7 +452,7 @@ void Oximetry::onReadyRead() } } - if ((ev_plethy->count()==1) || (ev_pulse->count()==1) || (ev_spo2->count()==1)) { + if ((ev_plethy->count()<=2) || (ev_pulse->count()<=2) || (ev_spo2->count()<=2)) { GraphView->updateScale(); } GraphView->updateGL(); // damn...