StatsLine under graphs test

This commit is contained in:
Mark Watkins 2011-08-30 18:46:24 +10:00
parent 964d4dae7e
commit d6a11894ed
10 changed files with 155 additions and 29 deletions

View File

@ -9,7 +9,7 @@
#include "gBarChart.h"
gBarChart::gBarChart(ChannelID code,QColor col,Qt::Orientation o)
:gLayer(code),m_orientation(o)
:Layer(code),m_orientation(o)
{
color.clear();
color.push_back(col);
@ -21,23 +21,21 @@ gBarChart::~gBarChart()
delete Xaxis;
}
void gBarChart::Plot(gGraphWindow & w,float scrx,float scry)
void gBarChart::paint(gGraphWindow & w,int left, int top, int width, int height)
{
if (!m_visible) return;
/*if (!data) return;
if (!data->IsReady()) return;
// if (!data) return;
//if (!data->IsReady()) 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;
double xx=w.max_x - w.min_x;
double days=int(xx);
//days=data->np[0];
days=0;
for (int i=0;i<data->np[0];i++) {
/* for (int i=0;i<data->np[0];i++) {
if ((data->point[0][i].x() >= w.min_x) && (data->point[0][i].x()<w.max_x)) days+=1;
}
if (days==0) return;

View File

@ -7,15 +7,16 @@
#ifndef GBARCHART_H
#define GBARCHART_H
#include "graphlayer.h"
#include "gGraphView.h"
#include "gXAxis.h"
class gBarChart:public gLayer
class gBarChart:public Layer
{
public:
gBarChart(ChannelID code=EmptyChannel,QColor col=QColor("blue"),Qt::Orientation o=Qt::Horizontal);
virtual ~gBarChart();
virtual void Plot(gGraphWindow & w,float scrx,float scry);
virtual void paint(gGraphWindow & w,int left, int top, int width, int height);
protected:
Qt::Orientation m_orientation;

View File

@ -228,14 +228,17 @@ void gGraph::paint(int originX, int originY, int width, int height)
{
m_lastbounds=QRect(originX,originY,width,height);
/*glEnable(GL_BLEND);
glBegin(GL_QUADS);
glColor4f(1,1,1,1.0); // Gradient End
glColor4f(1,1,1,0.4); // Gradient End
glVertex2i(originX,originY);
glVertex2i(originX+width,originY);
glColor4f(1,1,1.0,1.0); // Gradient End
glColor4f(1,1,1.0,.7); // Gradient End
glVertex2i(originX+width,originY+height);
glVertex2i(originX,originY+height);
glEnd();
glDisable(GL_BLEND);
*/
glColor4f(0,0,0,1);
renderText(title(),20,originY+height/2,90);
@ -948,7 +951,7 @@ void gGraphView::paintGL()
glVertex2f(0, height());
glVertex2f(0, 0);
glColor4f(0.6,0.6,1.0,1.0); // Gradient End
glColor4f(0.7,0.7,1.0,1.0); // Gradient End
glVertex2f(width(), 0);
glVertex2f(width(), height());

View File

@ -12,6 +12,7 @@ gSegmentChart::gSegmentChart(GraphSegmentType type,QColor gradient_color,QColor
: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;
}
gSegmentChart::~gSegmentChart()
{
@ -37,19 +38,18 @@ void gSegmentChart::SetDay(Day *d)
m_total+=cnt;
}
}
m_empty=true;
for (int i=0;i<m_codes.size();i++) {
if (m_day->count(m_codes[i])>0) {
m_empty=false;
break;
}
}
}
bool gSegmentChart::isEmpty()
{
bool res=true;
if (!m_day) return true;
for (int i=0;i<m_codes.size();i++) {
if (m_day->count(m_codes[i])>0) {
res=false;
break;
}
}
return res;
return m_empty;
}
void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height)
@ -84,7 +84,7 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height)
float x,y;
GetTextExtent(a,x,y,bigfont);
w.renderText(a,start_px+xoffset-x/2, (start_py+yoffset-y/2),0,col,bigfont);
w.renderText(a,start_px+xoffset-x/2, (start_py+yoffset+y/2),0,col,bigfont);
return;
}

View File

@ -31,6 +31,7 @@ protected:
GraphSegmentType m_graph_type;
QColor m_gradient_color;
QColor m_outline_color;
bool m_empty;
};
class gTAPGraph:public gSegmentChart

73
Graphs/gStatsLine.cpp Normal file
View File

@ -0,0 +1,73 @@
#include "SleepLib/day.h"
#include "gYAxis.h"
#include "gStatsLine.h"
gStatsLine::gStatsLine(ChannelID code,QString label,QColor textcolor)
:Layer(code),m_label(label),m_textcolor(textcolor)
{
}
void gStatsLine::paint(gGraph & w, int left, int top, int width, int height)
{
if (!m_visible) return;
//if (m_empty) return;
float x,y;
m_text=m_label;
GetTextExtent(m_text,x,y);
int z=(width+gYAxis::Margin)/5;
int p=left-gYAxis::Margin;
top+=8+y;
w.renderText(m_text,p,top,0,m_textcolor);
p+=z;
m_text="Min="+QString::number(m_min,'f',2);
GetTextExtent(m_text,x,y);
w.renderText(m_text,p,top,0,m_textcolor);
p+=z;
m_text="Avg="+QString::number(m_avg,'f',2);
GetTextExtent(m_text,x,y);
w.renderText(m_text,p,top,0,m_textcolor);
p+=z;
m_text="90%="+QString::number(m_p90,'f',2);
GetTextExtent(m_text,x,y);
w.renderText(m_text,p,top,0,m_textcolor);
p+=z;
m_text="Max="+QString::number(m_max,'f',2);
GetTextExtent(m_text,x,y);
w.renderText(m_text,p,top,0,m_textcolor);
// GetTextExtent(m_text,m_tx,m_ty);
}
void gStatsLine::SetDay(Day *d)
{
Layer::SetDay(d);
if (!m_day) return;
m_min=d->min(m_code);
m_max=d->max(m_code);
m_avg=d->wavg(m_code);
m_p90=d->p90(m_code);
m_text.clear();
// m_stext.setText(m_text);
// m_empty=true;
/* for (int i=0;i<m_codes.size();i++) {
if (m_day->count(m_codes[i])>0) {
m_empty=false;
break;
}
} */
}
//bool gStatsLine::isEmpty()
//{
// return m_empty;
//}

26
Graphs/gStatsLine.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef GSTATSLINE_H
#define GSTATSLINE_H
#include "SleepLib/machine.h"
#include <QStaticText>
#include "gGraphView.h"
class gStatsLine : public Layer
{
public:
gStatsLine(ChannelID code,QString label="",QColor textcolor=Qt::black);
virtual void paint(gGraph & w, int left, int top, int width, int height);
void SetDay(Day *d);
//bool isEmpty();
protected:
QColor m_textcolor;
//bool m_empty;
EventDataType m_min,m_max,m_avg,m_p90;
QString m_label;
QString m_text;
QStaticText m_stext;
float m_tx,m_ty;
};
#endif // GSTATSLINE_H

View File

@ -56,7 +56,8 @@ SOURCES += main.cpp\
qextserialport/qextserialport.cpp \
Graphs/gSplitter.cpp \
preferencesdialog.cpp \
Graphs/gGraphView.cpp
Graphs/gGraphView.cpp \
Graphs/gStatsLine.cpp
unix:SOURCES += qextserialport/posix_qextserialport.cpp
unix:!macx:SOURCES += qextserialport/qextserialenumerator_unix.cpp
@ -108,7 +109,8 @@ HEADERS += \
qextserialport/qextserialenumerator.h \
Graphs/gSplitter.h \
preferencesdialog.h \
Graphs/gGraphView.h
Graphs/gGraphView.h \
Graphs/gStatsLine.h
FORMS += \

View File

@ -27,6 +27,7 @@
#include "Graphs/gYAxis.h"
#include "Graphs/gBarChart.h"
#include "Graphs/gSegmentChart.h"
#include "Graphs/gStatsLine.h"
const int min_height=150;
const int default_height=150;
@ -98,6 +99,8 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
IE=new gGraph(GraphView,"I:E",default_height);
TE=new gGraph(GraphView,"Te",default_height);
TI=new gGraph(GraphView,"Ti",default_height);
INTPULSE=new gGraph(GraphView,"Pulse",default_height,1);
INTSPO2=new gGraph(GraphView,"SPO2",default_height,1);
PULSE=new gGraph(GraphView,"Pulse",default_height,1);
SPO2=new gGraph(GraphView,"SPO2",default_height,1);
PLETHY=new gGraph(GraphView,"Plethy",default_height,1);
@ -145,16 +148,32 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
FRW->AddLayer(AddCPAP(new gLineOverlayBar(CPAP_ClearAirway,QColor("purple"),"CA")));
gGraph *graphs[]={ PRD, LEAK, SNORE, PTB, MP, RR, MV, TV, FLG, IE, TI, TE, SPO2, PLETHY, PULSE };
gGraph *graphs[]={ PRD, LEAK, SNORE, PTB, MP, RR, MV, TV, FLG, IE, TI, TE, SPO2, PLETHY, PULSE,INTPULSE, INTSPO2 };
int ng=sizeof(graphs)/sizeof(gGraph*);
for (int i=0;i<ng;i++){
graphs[i]->AddLayer(new gXGrid());
}
PRD->AddLayer(AddCPAP(new gStatsLine(CPAP_Pressure,"Pressure")),LayerBottom,0,20,1);
PRD->AddLayer(AddCPAP(new gStatsLine(CPAP_EPAP,"EPAP")),LayerBottom,0,20,1);
PRD->AddLayer(AddCPAP(new gStatsLine(CPAP_IPAP,"IPAP")),LayerBottom,0,20,1);
LEAK->AddLayer(AddCPAP(new gStatsLine(CPAP_Leak)),LayerBottom,0,20,1);
SNORE->AddLayer(AddCPAP(new gStatsLine(CPAP_Snore)),LayerBottom,0,20,1);
PTB->AddLayer(AddCPAP(new gStatsLine(CPAP_PatientTriggeredBreaths)),LayerBottom,0,20,1);
RR->AddLayer(AddCPAP(new gStatsLine(CPAP_RespiratoryRate)),LayerBottom,0,20,1);
MV->AddLayer(AddCPAP(new gStatsLine(CPAP_MinuteVentilation)),LayerBottom,0,20,1);
TV->AddLayer(AddCPAP(new gStatsLine(CPAP_TidalVolume)),LayerBottom,0,20,1);
FLG->AddLayer(AddCPAP(new gStatsLine(CPAP_FlowLimitGraph)),LayerBottom,0,20,1);
IE->AddLayer(AddCPAP(new gStatsLine(CPAP_IE)),LayerBottom,0,20,1);
TE->AddLayer(AddCPAP(new gStatsLine(CPAP_Te)),LayerBottom,0,20,1);
TI->AddLayer(AddCPAP(new gStatsLine(CPAP_Ti)),LayerBottom,0,20,1);
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)));
SNORE->AddLayer(AddCPAP(new gLineChart(CPAP_Snore,Qt::darkGray,true)));
PTB->AddLayer(AddCPAP(new gLineChart(CPAP_PatientTriggeredBreaths,Qt::gray,true)));
MP->AddLayer(AddCPAP(new gLineChart(CPAP_MaskPressure,Qt::blue,false)));
RR->AddLayer(AddCPAP(new gLineChart(CPAP_RespiratoryRate,Qt::darkMagenta,true)));
@ -165,6 +184,8 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
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)));
INTPULSE->AddLayer(AddCPAP(new gLineChart(CPAP_Pulse,Qt::red,true)));
INTSPO2->AddLayer(AddCPAP(new gLineChart(CPAP_SPO2,Qt::blue,true)));
PULSE->AddLayer(AddOXI(new gLineChart(OXI_Pulse,Qt::red,true)));
SPO2->AddLayer(AddOXI(new gLineChart(OXI_SPO2,Qt::blue,true)));
PLETHY->AddLayer(AddOXI(new gLineChart(OXI_Plethysomogram,Qt::darkBlue,false)));
@ -174,6 +195,8 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
graphs[i]->AddLayer(new gXAxis(),LayerBottom,0,20);
}
layout->layout();
QTextCharFormat format = ui->calendar->weekdayTextFormat(Qt::Saturday);

View File

@ -17,7 +17,6 @@
#include "SleepLib/day.h"
#include "SleepLib/session.h"
//#include "Graphs/graphwindow.h"
#include "Graphs/gLineChart.h"
#include "Graphs/gFooBar.h"