2011-06-28 15:25:20 +00:00
/*
2011-06-26 08:30:44 +00:00
Daily Panel
Copyright ( c ) 2011 Mark Watkins < jedimark @ users . sourceforge . net >
License : GPL
2011-06-28 15:25:20 +00:00
*/
2011-06-26 08:30:44 +00:00
# include "daily.h"
# include "ui_daily.h"
# include <QTextCharFormat>
2011-08-20 07:38:50 +00:00
# include <QPalette>
2011-06-26 08:30:44 +00:00
# include <QTextBlock>
# include <QColorDialog>
2011-07-28 11:09:53 +00:00
# include <QSpacerItem>
2011-06-26 08:30:44 +00:00
# include <QBuffer>
# include <QPixmap>
2011-07-27 09:21:53 +00:00
# include <QMessageBox>
2011-07-28 11:09:53 +00:00
# include <QResizeEvent>
2011-06-26 08:30:44 +00:00
# include "SleepLib/session.h"
# include "Graphs/graphdata_custom.h"
# include "Graphs/gLineOverlay.h"
# include "Graphs/gFlagsLine.h"
# include "Graphs/gFooBar.h"
# include "Graphs/gXAxis.h"
# include "Graphs/gYAxis.h"
# include "Graphs/gBarChart.h"
2011-07-28 17:15:15 +00:00
# include "Graphs/gSegmentChart.h"
2011-06-26 08:30:44 +00:00
2011-08-02 10:28:29 +00:00
const int min_height = 150 ;
2011-07-28 12:13:28 +00:00
const int default_height = 150 ;
2011-07-22 13:46:17 +00:00
2011-08-07 06:21:09 +00:00
MyScrollArea : : MyScrollArea ( QWidget * parent , Daily * daily )
: QScrollArea ( parent ) , m_daily ( daily )
2011-07-29 14:58:44 +00:00
{
2011-08-07 12:53:42 +00:00
timer = new QTimer ( this ) ;
m_time . start ( ) ;
2011-07-29 14:58:44 +00:00
}
MyScrollArea : : ~ MyScrollArea ( )
{
2011-08-07 12:33:00 +00:00
delete timer ;
2011-07-29 14:58:44 +00:00
}
void MyScrollArea : : scrollContentsBy ( int dx , int dy )
{
2011-08-07 06:21:09 +00:00
QScrollArea : : scrollContentsBy ( dx , dy ) ;
2011-08-17 03:06:57 +00:00
//m_daily->RedrawGraphs();
2011-08-09 23:44:36 +00:00
//gGraphWindow g;
2011-08-07 13:57:10 +00:00
# ifdef Q_WS_MAC
2011-08-08 07:08:15 +00:00
if ( timer - > isActive ( ) ) timer - > stop ( ) ;
2011-08-07 12:33:00 +00:00
timer - > setSingleShot ( true ) ;
2011-08-08 07:08:15 +00:00
timer - > setInterval ( 200 ) ;
2011-08-07 12:53:42 +00:00
connect ( timer , SIGNAL ( timeout ( ) ) , SLOT ( UpdateGraphs ( ) ) ) ;
2011-08-07 12:33:00 +00:00
timer - > start ( ) ;
2011-08-08 07:08:15 +00:00
m_time . start ( ) ;
2011-08-07 12:33:00 +00:00
//m_daily->RedrawGraphs();
2011-08-07 13:57:10 +00:00
# endif
2011-07-29 14:58:44 +00:00
}
2011-08-07 12:53:42 +00:00
void MyScrollArea : : UpdateGraphs ( )
{
2011-08-08 07:08:15 +00:00
if ( m_time . elapsed ( ) < 200 )
2011-08-07 12:53:42 +00:00
return ;
m_time . start ( ) ;
2011-08-07 13:57:10 +00:00
qDebug ( ) < < " Redraw! " ;
2011-08-07 12:53:42 +00:00
m_daily - > RedrawGraphs ( ) ;
}
2011-07-29 14:58:44 +00:00
2011-07-30 04:54:22 +00:00
Daily : : Daily ( QWidget * parent , QGLWidget * shared , MainWindow * mw )
: QWidget ( parent ) , mainwin ( mw ) , ui ( new Ui : : Daily )
2011-06-26 08:30:44 +00:00
{
ui - > setupUi ( this ) ;
QString prof = pref [ " Profile " ] . toString ( ) ;
profile = Profiles : : Get ( prof ) ;
if ( ! profile ) {
2011-07-27 09:21:53 +00:00
QMessageBox : : critical ( this , " Profile Error " , QString ( " Couldn't get profile '%1'.. Have to abort! " ) . arg ( pref [ " Profile " ] . toString ( ) ) ) ;
exit ( - 1 ) ;
2011-06-26 08:30:44 +00:00
}
2011-07-29 14:58:44 +00:00
2011-08-07 06:21:09 +00:00
scrollArea = new MyScrollArea ( ui - > graphMainArea , this ) ;
2011-08-20 07:38:50 +00:00
QPalette p ;
p . setColor ( QPalette : : Window , Qt : : white ) ;
scrollArea - > setPalette ( p ) ;
scrollArea - > setBackgroundRole ( QPalette : : Window ) ;
2011-08-07 06:21:09 +00:00
ui - > graphLayout - > addWidget ( scrollArea , 1 ) ;
2011-08-07 15:37:01 +00:00
ui - > graphLayout - > setSpacing ( 0 ) ;
ui - > graphLayout - > setMargin ( 0 ) ;
ui - > graphLayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2011-08-07 06:21:09 +00:00
scrollArea - > setWidgetResizable ( true ) ;
2011-08-20 07:38:50 +00:00
scrollArea - > setAutoFillBackground ( true ) ;
2011-08-07 06:30:20 +00:00
2011-08-08 06:56:06 +00:00
GraphLayout = new QWidget ( scrollArea ) ;
2011-08-20 07:41:56 +00:00
GraphLayout - > setAutoFillBackground ( true ) ;
GraphLayout - > setPalette ( p ) ;
GraphLayout - > setBackgroundRole ( QPalette : : Window ) ;
2011-08-07 06:21:09 +00:00
scrollArea - > setWidget ( GraphLayout ) ;
2011-08-02 12:32:03 +00:00
splitter = new QVBoxLayout ( GraphLayout ) ;
2011-08-07 06:21:09 +00:00
GraphLayout - > setLayout ( splitter ) ;
2011-08-07 06:30:20 +00:00
splitter - > setSpacing ( 0 ) ;
2011-08-02 12:32:03 +00:00
splitter - > setMargin ( 0 ) ;
splitter - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2011-08-07 06:21:09 +00:00
//ui->splitter->layout();
2011-08-02 10:28:29 +00:00
//gSplitter(Qt::Vertical,ui->scrollArea);
//splitter->setStyleSheet("QSplitter::handle { background-color: 'light grey'; }");
//splitter->setHandleWidth(3);
2011-07-30 08:10:02 +00:00
# ifdef Q_WS_MAC
2011-08-02 10:28:29 +00:00
//splitter->setOpaqueResize(false);
2011-07-30 08:10:02 +00:00
# endif
2011-07-30 01:51:52 +00:00
2011-08-07 06:21:09 +00:00
scrollArea - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAlwaysOn ) ;
scrollArea - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
2011-08-02 10:28:29 +00:00
//ui->scrollArea->setWidget(splitter);
2011-07-29 14:58:44 +00:00
//this->connect(ui->scrollArea,
2011-08-02 09:12:10 +00:00
//ui->graphSizer->addWidget(splitter);
2011-08-08 06:41:08 +00:00
//scrollArea->setAutoFillBackground(false);
2011-08-02 10:28:29 +00:00
//splitter->setAutoFillBackground(false);
2011-08-02 12:32:03 +00:00
2011-08-02 09:12:10 +00:00
//splitter->setMinimumHeight(1600);
//splitter->setMinimumWidth(600);
2011-08-07 06:21:09 +00:00
QWidget * parental = GraphLayout ;
2011-08-02 10:28:29 +00:00
SF = new gGraphWindow ( parental , tr ( " Event Flags " ) , shared ) ;
FRW = new gGraphWindow ( parental , tr ( " Flow Rate " ) , SF ) ;
PRD = new gGraphWindow ( parental , tr ( " Pressure " ) , SF ) ;
2011-08-07 01:26:28 +00:00
//EXPR=new gGraphWindow(parental,tr("Exp. Pressure"),SF);
THPR = new gGraphWindow ( parental , tr ( " Therapy Pressure " ) , SF ) ;
2011-08-02 10:28:29 +00:00
LEAK = new gGraphWindow ( parental , tr ( " Leaks " ) , SF ) ;
MP = new gGraphWindow ( parental , tr ( " Mask Pressure " ) , SF ) ;
SNORE = new gGraphWindow ( parental , tr ( " Snore " ) , SF ) ;
FLG = new gGraphWindow ( parental , tr ( " Flow Limitation " ) , SF ) ;
MV = new gGraphWindow ( parental , tr ( " Minute Ventilation " ) , SF ) ;
TV = new gGraphWindow ( parental , tr ( " Tidal Volume " ) , SF ) ;
RR = new gGraphWindow ( parental , tr ( " Respiratory Rate " ) , SF ) ;
PTB = new gGraphWindow ( parental , tr ( " Patient Trig Breaths " ) , SF ) ;
2011-08-09 23:44:36 +00:00
RE = new gGraphWindow ( parental , tr ( " Respiratory Event " ) , SF ) ;
IE = new gGraphWindow ( parental , tr ( " I:E " ) , SF ) ;
TI = new gGraphWindow ( parental , tr ( " Ti " ) , SF ) ;
TE = new gGraphWindow ( parental , tr ( " Te " ) , SF ) ;
2011-08-02 10:28:29 +00:00
//OF=new gGraphWindow(parental,tr("Oxi-Flags"),SF);
2011-08-06 13:37:06 +00:00
INTPULSE = new gGraphWindow ( parental , tr ( " Pulse " ) , SF ) ; // Integrated Pulse
INTSPO2 = new gGraphWindow ( parental , tr ( " SPO2 " ) , SF ) ; // Integrated Pulse
2011-08-02 10:28:29 +00:00
PULSE = new gGraphWindow ( parental , tr ( " Pulse " ) , SF ) ;
SPO2 = new gGraphWindow ( parental , tr ( " SPO2 " ) , SF ) ;
2011-08-07 15:37:01 +00:00
PLETHY = new gGraphWindow ( parental , tr ( " Plethysomogram " ) , SF ) ;
2011-07-22 13:46:17 +00:00
2011-07-27 09:21:53 +00:00
TAP = new gGraphWindow ( NULL , " " , ( QGLWidget * ) NULL ) ;
TAP_EAP = new gGraphWindow ( NULL , " " , ( QGLWidget * ) NULL ) ;
TAP_IAP = new gGraphWindow ( NULL , " " , ( QGLWidget * ) NULL ) ;
G_AHI = new gGraphWindow ( NULL , " " , ( QGLWidget * ) NULL ) ;
2011-07-22 13:46:17 +00:00
/*QGLFormat fmt;
fmt . setDepth ( false ) ;
fmt . setDirectRendering ( false ) ;
fmt . setAlpha ( true ) ;
fmt . setDoubleBuffer ( false ) ;
fmt . setRgba ( true ) ;
//fmt.setDefaultFormat(fmt);
offscreen_context = new QGLContext ( fmt ) ; */
2011-06-26 08:30:44 +00:00
SF - > SetLeftMargin ( SF - > GetLeftMargin ( ) + gYAxis : : Margin ) ;
SF - > SetBlockZoom ( true ) ;
SF - > AddLayer ( new gXAxis ( ) ) ;
2011-07-28 13:49:03 +00:00
SF - > setMinimumHeight ( min_height ) ;
2011-06-28 09:19:35 +00:00
2011-07-22 13:46:17 +00:00
fg = new gFlagsGroup ( ) ;
2011-07-31 20:24:43 +00:00
fg - > AddLayer ( ( new gFlagsLine ( CPAP_CSR , QColor ( " light green " ) , " CSR " , false , FT_Span ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_ClearAirway , QColor ( " purple " ) , " CA " , true ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_Obstructive , QColor ( " #40c0ff " ) , " OA " , true ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_Apnea , QColor ( " dark green " ) , " A " ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_Hypopnea , QColor ( " blue " ) , " H " , true ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_FlowLimit , QColor ( " black " ) , " FL " ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_RERA , QColor ( " gold " ) , " RE " ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_VSnore , QColor ( " red " ) , " VS " ) ) ) ;
//fg->AddLayer(AddCPAP(new gFlagsLine(flags[8],QColor("dark green"),"U0E")));
2011-07-27 09:21:53 +00:00
//fg->AddLayer(AddCPAP(new gFlagsLine(flags[10],QColor("red"),"VS2"));
SF - > AddLayer ( AddCPAP ( fg ) ) ;
2011-07-22 13:46:17 +00:00
// SF Foobar must go last
2011-06-27 07:45:59 +00:00
SF - > AddLayer ( new gFooBar ( 10 , QColor ( " orange " ) , QColor ( " dark grey " ) , true ) ) ;
2011-06-26 08:30:44 +00:00
2011-07-10 16:20:51 +00:00
2011-08-07 00:22:54 +00:00
bool square = true ;
2011-06-26 08:30:44 +00:00
PRD - > AddLayer ( new gXAxis ( ) ) ;
PRD - > AddLayer ( new gYAxis ( ) ) ;
2011-08-07 02:11:54 +00:00
PRD - > AddLayer ( AddCPAP ( pressure = new gLineChart ( CPAP_Pressure , QColor ( " dark green " ) , square ) ) ) ;
PRD - > AddLayer ( AddCPAP ( epap = new gLineChart ( CPAP_EPAP , Qt : : blue , square ) ) ) ;
PRD - > AddLayer ( AddCPAP ( ipap = new gLineChart ( CPAP_IPAP , Qt : : red , square ) ) ) ;
2011-07-28 13:49:03 +00:00
PRD - > setMinimumHeight ( min_height ) ;
2011-06-26 08:30:44 +00:00
2011-08-07 00:22:54 +00:00
THPR - > AddLayer ( new gXAxis ( ) ) ;
THPR - > AddLayer ( new gYAxis ( ) ) ;
THPR - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_TherapyPressure , QColor ( " dark green " ) , square ) ) ) ;
2011-08-07 01:26:28 +00:00
THPR - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_ExpiratoryPressure , QColor ( " dark blue " ) , square ) ) ) ;
2011-08-07 00:22:54 +00:00
THPR - > setMinimumHeight ( min_height ) ;
2011-08-07 01:26:28 +00:00
//EXPR->AddLayer(new gXAxis());
//EXPR->AddLayer(new gYAxis());
//EXPR->setMinimumHeight(min_height);
2011-08-07 00:22:54 +00:00
2011-06-27 10:23:24 +00:00
LEAK - > AddLayer ( new gXAxis ( ) ) ;
LEAK - > AddLayer ( new gYAxis ( ) ) ;
2011-06-28 09:19:35 +00:00
//LEAK->AddLayer(new gFooBar());
2011-07-27 09:21:53 +00:00
LEAK - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_Leak , QColor ( " purple " ) , true ) ) ) ;
2011-06-27 10:23:24 +00:00
2011-07-28 13:49:03 +00:00
LEAK - > setMinimumHeight ( min_height ) ;
2011-06-27 10:23:24 +00:00
2011-06-26 08:30:44 +00:00
2011-07-27 09:21:53 +00:00
MP - > AddLayer ( new gYAxis ( ) ) ;
2011-07-10 17:49:02 +00:00
MP - > AddLayer ( new gXAxis ( ) ) ;
2011-07-27 09:21:53 +00:00
gLineChart * g = new gLineChart ( CPAP_MaskPressure , Qt : : blue , false ) ;
AddCPAP ( g ) ;
2011-07-10 17:49:02 +00:00
g - > ReportEmpty ( true ) ;
MP - > AddLayer ( g ) ;
2011-08-07 02:11:54 +00:00
//MP->AddLayer(AddCPAP(new gLineChart(CPAP_EPAP,Qt::yellow,square)));
//MP->AddLayer(AddCPAP(new gLineChart(CPAP_IPAP,Qt::red,square)));
2011-07-28 13:49:03 +00:00
MP - > setMinimumHeight ( min_height ) ;
2011-07-10 17:49:02 +00:00
2011-06-28 09:19:35 +00:00
//FRW->AddLayer(new gFooBar());
2011-06-27 10:23:24 +00:00
FRW - > AddLayer ( new gYAxis ( ) ) ;
FRW - > AddLayer ( new gXAxis ( ) ) ;
2011-07-27 15:28:46 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_CSR , QColor ( " light green " ) , " CSR " , FT_Span ) ) ) ;
2011-07-27 09:21:53 +00:00
g = new gLineChart ( CPAP_FlowRate , Qt : : black , false ) ;
2011-06-26 08:30:44 +00:00
g - > ReportEmpty ( true ) ;
2011-07-27 09:21:53 +00:00
AddCPAP ( g ) ;
2011-06-26 08:30:44 +00:00
FRW - > AddLayer ( g ) ;
2011-07-27 09:21:53 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_Hypopnea , QColor ( " blue " ) , " H " ) ) ) ;
2011-07-31 20:24:43 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_PressurePulse , QColor ( " red " ) , " PR " , FT_Dot ) ) ) ;
2011-08-06 10:45:00 +00:00
//FRW->AddLayer(AddCPAP(new gLineOverlayBar(CPAP_Pressure,QColor("white"),"P",FT_Dot)));
2011-07-30 03:52:29 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( PRS1_Unknown0B , QColor ( " blue " ) , " 0B " , FT_Dot ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( PRS1_Unknown10 , QColor ( " orange " ) , " 10 " , FT_Dot ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( PRS1_Unknown0E , QColor ( " yellow " ) , " 0E " , FT_Dot ) ) ) ;
2011-07-27 09:21:53 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_RERA , QColor ( " gold " ) , " RE " ) ) ) ;
//FRW->AddLayer(AddCPAP(new gLineOverlayBar(CPAP_Unknown0E,QColor("dark green"),"U0E")));
2011-07-30 08:10:02 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_Apnea , QColor ( " dark green " ) , " A " ) ) ) ;
2011-07-27 09:21:53 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_VSnore , QColor ( " red " ) , " VS " ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_FlowLimit , QColor ( " black " ) , " FL " ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_Obstructive , QColor ( " #40c0ff " ) , " OA " ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_ClearAirway , QColor ( " purple " ) , " CA " ) ) ) ;
2011-07-28 13:49:03 +00:00
FRW - > setMinimumHeight ( min_height ) ;
2011-07-27 09:21:53 +00:00
2011-06-26 08:30:44 +00:00
SNORE - > AddLayer ( new gXAxis ( ) ) ;
SNORE - > AddLayer ( new gYAxis ( ) ) ;
2011-07-27 09:21:53 +00:00
SNORE - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_Snore , Qt : : black , true ) ) ) ;
2011-07-28 13:49:03 +00:00
SNORE - > setMinimumHeight ( min_height ) ;
2011-06-26 08:30:44 +00:00
2011-06-30 12:07:11 +00:00
FLG - > AddLayer ( new gXAxis ( ) ) ;
FLG - > AddLayer ( new gYAxis ( ) ) ;
2011-07-27 09:21:53 +00:00
FLG - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_FlowLimitGraph , Qt : : black , true ) ) ) ;
2011-07-28 13:49:03 +00:00
FLG - > setMinimumHeight ( min_height ) ;
2011-06-30 12:07:11 +00:00
2011-06-30 04:55:20 +00:00
MV - > AddLayer ( new gXAxis ( ) ) ;
MV - > AddLayer ( new gYAxis ( ) ) ;
2011-07-27 09:21:53 +00:00
MV - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_MinuteVentilation , QColor ( 0x20 , 0x20 , 0x7f ) , true ) ) ) ;
2011-07-28 13:49:03 +00:00
MV - > setMinimumHeight ( min_height ) ;
2011-06-30 04:55:20 +00:00
TV - > AddLayer ( new gXAxis ( ) ) ;
TV - > AddLayer ( new gYAxis ( ) ) ;
2011-07-27 09:21:53 +00:00
TV - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_TidalVolume , QColor ( 0x7f , 0x20 , 0x20 ) , true ) ) ) ;
2011-07-28 13:49:03 +00:00
TV - > setMinimumHeight ( min_height ) ;
2011-06-30 04:55:20 +00:00
RR - > AddLayer ( new gXAxis ( ) ) ;
RR - > AddLayer ( new gYAxis ( ) ) ;
2011-07-27 09:21:53 +00:00
RR - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_RespiratoryRate , Qt : : gray , true ) ) ) ;
2011-07-28 13:49:03 +00:00
RR - > setMinimumHeight ( min_height ) ;
2011-06-30 04:55:20 +00:00
2011-08-09 23:44:36 +00:00
RE - > AddLayer ( new gXAxis ( ) ) ;
RE - > AddLayer ( new gYAxis ( ) ) ;
RE - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_RespiratoryEvent , Qt : : darkYellow , false ) ) ) ;
RE - > setMinimumHeight ( min_height ) ;
IE - > AddLayer ( new gXAxis ( ) ) ;
IE - > AddLayer ( new gYAxis ( ) ) ;
IE - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_IE , Qt : : darkMagenta , false ) ) ) ;
IE - > setMinimumHeight ( min_height ) ;
TE - > AddLayer ( new gXAxis ( ) ) ;
TE - > AddLayer ( new gYAxis ( ) ) ;
TE - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_Te , Qt : : darkBlue , false ) ) ) ;
TE - > setMinimumHeight ( min_height ) ;
TI - > AddLayer ( new gXAxis ( ) ) ;
TI - > AddLayer ( new gYAxis ( ) ) ;
TI - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_Ti , Qt : : darkRed , false ) ) ) ;
TI - > setMinimumHeight ( min_height ) ;
2011-07-12 12:43:10 +00:00
PTB - > AddLayer ( new gXAxis ( ) ) ;
PTB - > AddLayer ( new gYAxis ( ) ) ;
2011-07-27 09:21:53 +00:00
PTB - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_PatientTriggeredBreaths , Qt : : gray , true ) ) ) ;
2011-07-28 13:49:03 +00:00
PTB - > setMinimumHeight ( min_height ) ;
2011-07-12 12:43:10 +00:00
2011-08-06 13:37:06 +00:00
INTPULSE - > AddLayer ( new gXAxis ( ) ) ;
INTPULSE - > AddLayer ( new gYAxis ( ) ) ;
INTPULSE - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_Pulse , Qt : : red , true ) ) ) ;
INTPULSE - > setMinimumHeight ( min_height ) ;
INTSPO2 - > AddLayer ( new gXAxis ( ) ) ;
INTSPO2 - > AddLayer ( new gYAxis ( ) ) ;
INTSPO2 - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_SPO2 , Qt : : blue , true ) ) ) ;
INTSPO2 - > setMinimumHeight ( min_height ) ;
2011-08-07 15:37:01 +00:00
PLETHY - > AddLayer ( new gXAxis ( ) ) ;
PLETHY - > AddLayer ( new gYAxis ( ) ) ;
PLETHY - > AddLayer ( AddOXI ( new gLineChart ( OXI_Plethysomogram , Qt : : darkCyan , true ) ) ) ;
PLETHY - > setMinimumHeight ( min_height ) ;
2011-06-26 08:30:44 +00:00
PULSE - > AddLayer ( new gXAxis ( ) ) ;
PULSE - > AddLayer ( new gYAxis ( ) ) ;
2011-07-27 09:21:53 +00:00
PULSE - > AddLayer ( AddOXI ( new gLineChart ( OXI_Pulse , Qt : : red , true ) ) ) ;
2011-07-31 20:24:43 +00:00
PULSE - > AddLayer ( AddOXI ( new gLineOverlayBar ( OXI_PulseChange , Qt : : green , " PC " , FT_Bar ) ) ) ;
2011-07-28 13:49:03 +00:00
PULSE - > setMinimumHeight ( min_height ) ;
2011-06-26 08:30:44 +00:00
2011-07-30 10:40:22 +00:00
SPO2 - > AddLayer ( new gXAxis ( ) ) ;
SPO2 - > AddLayer ( new gYAxis ( ) ) ;
SPO2 - > AddLayer ( AddOXI ( new gLineChart ( OXI_SPO2 , Qt : : blue , true ) ) ) ;
2011-07-31 20:24:43 +00:00
SPO2 - > AddLayer ( AddOXI ( new gLineOverlayBar ( OXI_SPO2Drop , Qt : : red , " SC " , FT_Bar ) ) ) ;
2011-07-30 10:40:22 +00:00
SPO2 - > setMinimumHeight ( min_height ) ;
2011-07-31 20:24:43 +00:00
/*fg=new gFlagsGroup();
fg - > AddLayer ( AddOXI ( new gFlagsLine ( OXI_PulseChange , QColor ( " orange " ) , " PUL " , true ) ) ) ;
fg - > AddLayer ( AddOXI ( new gFlagsLine ( OXI_SPO2Change , QColor ( " gray " ) , " SP " , true ) ) ) ;
OF - > AddLayer ( fg ) ;
OF - > AddLayer ( new gFooBar ( 10 , QColor ( " orange " ) , QColor ( " dark grey " ) , true ) ) ;
OF - > SetLeftMargin ( SF - > GetLeftMargin ( ) + gYAxis : : Margin ) ;
OF - > SetBlockZoom ( true ) ;
OF - > AddLayer ( new gXAxis ( ) ) ;
OF - > setMinimumHeight ( min_height ) ; */
2011-07-30 10:40:22 +00:00
// SPO2->AddLayer(new gFooBar());
2011-07-28 13:49:03 +00:00
// SPO2->setMinimumHeight(min_height);
2011-06-30 07:27:04 +00:00
// SPO2->LinkZoom(PULSE);
// PULSE->LinkZoom(SPO2);
// SPO2->hide();
2011-07-30 10:40:22 +00:00
// PULSE->hide();
2011-06-26 08:30:44 +00:00
2011-07-29 14:58:44 +00:00
gSegmentChart * seg ;
2011-07-28 18:02:51 +00:00
TAP_EAP - > SetMargins ( 0 , 0 , 0 , 0 ) ;
2011-07-31 20:24:43 +00:00
TAP_EAP - > AddLayer ( AddCPAP ( seg = new gTAPGraph ( CPAP_EPAP ) ) ) ;
2011-07-29 14:58:44 +00:00
2011-07-28 18:02:51 +00:00
TAP_EAP - > hide ( ) ;
2011-07-29 14:58:44 +00:00
TAP_EAP - > SetGradientBackground ( false ) ;
2011-06-26 08:30:44 +00:00
2011-07-28 18:02:51 +00:00
TAP_IAP - > SetMargins ( 0 , 0 , 0 , 0 ) ;
2011-07-31 20:24:43 +00:00
TAP_IAP - > AddLayer ( AddCPAP ( seg = new gTAPGraph ( CPAP_IPAP ) ) ) ;
2011-07-28 18:02:51 +00:00
TAP_IAP - > hide ( ) ;
2011-07-29 14:58:44 +00:00
TAP_IAP - > SetGradientBackground ( false ) ;
2011-07-22 13:46:17 +00:00
2011-07-28 17:15:15 +00:00
TAP - > SetMargins ( 0 , 0 , 0 , 0 ) ;
2011-07-29 23:14:06 +00:00
TAP - > AddLayer ( AddCPAP ( seg = new gTAPGraph ( CPAP_Pressure , GST_CandleStick ) ) ) ;
2011-07-28 17:15:15 +00:00
TAP - > hide ( ) ;
2011-07-29 14:58:44 +00:00
TAP - > SetGradientBackground ( false ) ;
2011-07-28 17:15:15 +00:00
2011-07-28 07:32:02 +00:00
G_AHI - > SetMargins ( 0 , 0 , 0 , 0 ) ;
2011-07-29 14:58:44 +00:00
seg = new gSegmentChart ( GST_Pie ) ;
seg - > AddSlice ( CPAP_Hypopnea , QColor ( 0x40 , 0x40 , 0xff , 0xff ) , " H " ) ;
2011-07-30 08:10:02 +00:00
seg - > AddSlice ( CPAP_Apnea , QColor ( 0x20 , 0x80 , 0x20 , 0xff ) , " A " ) ;
2011-07-29 14:58:44 +00:00
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 ) ) ;
2011-06-29 04:53:18 +00:00
G_AHI - > SetGradientBackground ( false ) ;
2011-07-27 09:21:53 +00:00
G_AHI - > hide ( ) ;
2011-08-02 10:28:29 +00:00
NoData = new QLabel ( tr ( " No data " ) , parental ) ;
2011-06-26 08:30:44 +00:00
NoData - > setAlignment ( Qt : : AlignCenter ) ;
2011-06-27 15:00:00 +00:00
QFont font ( " FreeSans " , 20 ) ; //NoData->font();
2011-06-26 08:30:44 +00:00
//font.setBold(true);
NoData - > setFont ( font ) ;
NoData - > hide ( ) ;
2011-08-02 09:12:10 +00:00
splitter - > addWidget ( NoData ) ;
2011-08-02 10:28:29 +00:00
//int i=splitter->indexOf(NoData);
splitter - > setStretchFactor ( NoData , 1 ) ;
2011-07-15 13:07:12 +00:00
2011-08-09 23:44:36 +00:00
gGraphWindow * graphs [ ] = { SF , FRW , MP , RE , MV , TV , PTB , RR , IE , TE , TI , PRD , THPR , LEAK , FLG , SNORE , INTPULSE , INTSPO2 } ;
2011-07-15 13:07:12 +00:00
int ss = sizeof ( graphs ) / sizeof ( gGraphWindow * ) ;
for ( int i = 0 ; i < ss ; i + + ) {
AddGraph ( graphs [ i ] ) ;
2011-08-02 09:12:10 +00:00
//int j=splitter->indexOf(graphs[i]);
2011-08-02 10:28:29 +00:00
splitter - > setStretchFactor ( graphs [ i ] , 1 ) ;
2011-08-02 12:32:03 +00:00
//splitter->setAlignment(graphs[i],Qt::AlignTop);
2011-07-15 13:07:12 +00:00
for ( int j = 0 ; j < ss ; j + + ) {
2011-08-06 13:37:06 +00:00
if ( graphs [ i ] ! = graphs [ j ] ) {
2011-07-15 13:07:12 +00:00
graphs [ i ] - > LinkZoom ( graphs [ j ] ) ;
2011-08-06 13:37:06 +00:00
}
2011-07-15 13:07:12 +00:00
}
}
2011-07-28 13:49:03 +00:00
2011-07-31 20:24:43 +00:00
//AddGraph(OF);
2011-07-04 11:37:26 +00:00
AddGraph ( PULSE ) ;
2011-07-30 10:40:22 +00:00
AddGraph ( SPO2 ) ;
2011-08-07 15:37:01 +00:00
AddGraph ( PLETHY ) ;
2011-07-30 10:40:22 +00:00
2011-07-31 20:24:43 +00:00
//SPO2->LinkZoom(OF);
//PULSE->LinkZoom(OF);
2011-07-30 10:40:22 +00:00
SPO2 - > LinkZoom ( PULSE ) ;
2011-08-07 15:37:01 +00:00
SPO2 - > LinkZoom ( PLETHY ) ;
2011-07-30 10:40:22 +00:00
PULSE - > LinkZoom ( SPO2 ) ;
2011-08-07 15:37:01 +00:00
PULSE - > LinkZoom ( PLETHY ) ;
PLETHY - > LinkZoom ( PULSE ) ;
PLETHY - > LinkZoom ( SPO2 ) ;
2011-07-31 20:24:43 +00:00
//OF->LinkZoom(PULSE);
//OF->LinkZoom(SPO2);
2011-07-28 13:49:03 +00:00
2011-07-15 13:07:12 +00:00
// AddGraph(SPO2);
2011-08-07 06:21:09 +00:00
spacer = new gGraphWindow ( scrollArea , " " , SF ) ;
2011-08-07 04:44:01 +00:00
spacer - > setMinimumHeight ( 1 ) ;
spacer - > setMaximumHeight ( 1 ) ;
splitter - > addWidget ( spacer ) ;
2011-08-02 09:12:10 +00:00
//i=splitter->indexOf(spacer);
//splitter->setStretchFactor(i,1);
//i=splitter->indexOf(FRW);
//splitter->setStretchFactor(i,15);
2011-06-26 08:30:44 +00:00
2011-07-28 14:20:59 +00:00
2011-08-02 09:12:10 +00:00
//splitter->refresh();
2011-06-28 15:25:20 +00:00
2011-08-02 10:28:29 +00:00
//splitter->setChildrenCollapsible(false); // We set this per widget..
2011-08-02 09:12:10 +00:00
//splitter->setCollapsible(splitter->indexOf(SF),false);
//splitter->setStretchFactor(splitter->indexOf(SF),0);
2011-07-23 07:56:13 +00:00
2011-08-02 10:28:29 +00:00
//splitter_sizes=splitter->sizes();
2011-08-02 12:32:03 +00:00
//splitter->layout();
//splitter->update();
2011-06-26 08:30:44 +00:00
2011-07-28 14:20:59 +00:00
2011-06-26 08:30:44 +00:00
QTextCharFormat format = ui - > calendar - > weekdayTextFormat ( Qt : : Saturday ) ;
format . setForeground ( QBrush ( Qt : : black , Qt : : SolidPattern ) ) ;
ui - > calendar - > setWeekdayTextFormat ( Qt : : Saturday , format ) ;
ui - > calendar - > setWeekdayTextFormat ( Qt : : Sunday , format ) ;
2011-06-28 01:51:21 +00:00
ui - > tabWidget - > setCurrentWidget ( ui - > details ) ;
2011-07-30 04:54:22 +00:00
if ( mainwin ) {
show_graph_menu = mainwin - > CreateMenu ( " Graphs " ) ;
show_graph_menu - > clear ( ) ;
2011-07-31 20:24:43 +00:00
for ( int i = 0 ; i < Graphs . size ( ) ; i + + ) {
2011-07-30 04:54:22 +00:00
QAction * action = show_graph_menu - > addAction ( Graphs [ i ] - > Title ( ) , NULL , NULL , 0 ) ;
action - > setCheckable ( true ) ;
action - > setChecked ( true ) ;
connect ( action , SIGNAL ( triggered ( ) ) , this , SLOT ( ShowHideGraphs ( ) ) ) ;
GraphAction . push_back ( action ) ;
}
} else show_graph_menu = NULL ;
2011-06-26 08:30:44 +00:00
}
Daily : : ~ Daily ( )
{
// Save any last minute changes..
if ( previous_date . isValid ( ) )
Unload ( previous_date ) ;
2011-08-02 10:28:29 +00:00
// delete splitter;
2011-06-26 08:30:44 +00:00
delete ui ;
}
2011-07-04 11:37:26 +00:00
void Daily : : AddGraph ( gGraphWindow * w )
{
Graphs . push_back ( w ) ;
2011-08-02 09:12:10 +00:00
splitter - > addWidget ( w ) ;
w - > SetSplitter ( splitter ) ;
2011-07-04 11:37:26 +00:00
}
2011-07-28 11:09:53 +00:00
void Daily : : resizeEvent ( QResizeEvent * event )
{
2011-07-28 12:13:28 +00:00
//const QSize &size=event->size();
2011-08-02 09:12:10 +00:00
// splitter->setMinimumWidth(size.width()-280);
2011-07-28 11:09:53 +00:00
}
2011-07-04 11:37:26 +00:00
2011-06-26 08:30:44 +00:00
void Daily : : ReloadGraphs ( )
{
QDate d = profile - > LastDay ( ) ;
if ( ! d . isValid ( ) ) {
d = ui - > calendar - > selectedDate ( ) ;
}
on_calendar_currentPageChanged ( d . year ( ) , d . month ( ) ) ;
ui - > calendar - > setSelectedDate ( d ) ;
Load ( d ) ;
}
void Daily : : on_calendar_currentPageChanged ( int year , int month )
{
QDate d ( year , month , 1 ) ;
int dom = d . daysInMonth ( ) ;
for ( int i = 1 ; i < = dom ; i + + ) {
d = QDate ( year , month , i ) ;
this - > UpdateCalendarDay ( d ) ;
}
}
void Daily : : UpdateEventsTree ( QTreeWidget * tree , Day * day )
{
tree - > clear ( ) ;
2011-06-27 10:55:55 +00:00
if ( ! day ) return ;
2011-07-27 09:53:29 +00:00
//return;
2011-06-26 08:30:44 +00:00
tree - > setColumnCount ( 1 ) ; // 1 visible common.. (1 hidden)
QTreeWidgetItem * root = NULL ; //new QTreeWidgetItem((QTreeWidget *)0,QStringList("Stuff"));
2011-07-31 20:24:43 +00:00
QHash < ChannelID , QTreeWidgetItem * > mcroot ;
QHash < ChannelID , int > mccnt ;
2011-07-05 05:33:06 +00:00
int total_events = 0 ;
2011-06-26 08:30:44 +00:00
2011-07-31 20:24:43 +00:00
for ( QVector < Session * > : : iterator s = day - > begin ( ) ; s ! = day - > end ( ) ; s + + ) {
2011-06-26 08:30:44 +00:00
2011-07-31 20:24:43 +00:00
QHash < ChannelID , QVector < EventList * > > : : iterator m ;
2011-06-26 08:30:44 +00:00
2011-07-01 10:10:44 +00:00
//QTreeWidgetItem * sroot;
2011-06-26 08:30:44 +00:00
2011-07-27 09:21:53 +00:00
for ( m = ( * s ) - > eventlist . begin ( ) ; m ! = ( * s ) - > eventlist . end ( ) ; m + + ) {
2011-07-31 20:24:43 +00:00
ChannelID code = m . key ( ) ;
2011-07-27 09:53:29 +00:00
if ( ( code ! = CPAP_Obstructive )
& & ( code ! = CPAP_Hypopnea )
& & ( code ! = CPAP_Apnea )
2011-07-31 20:24:43 +00:00
& & ( code ! = PRS1_Unknown0B )
2011-07-27 09:53:29 +00:00
& & ( code ! = CPAP_ClearAirway )
& & ( code ! = CPAP_CSR )
& & ( code ! = CPAP_RERA )
& & ( code ! = CPAP_FlowLimit )
2011-07-31 20:24:43 +00:00
& & ( code ! = CPAP_PressurePulse )
2011-07-27 09:53:29 +00:00
& & ( code ! = CPAP_VSnore ) ) continue ;
2011-06-26 08:30:44 +00:00
QTreeWidgetItem * mcr ;
if ( mcroot . find ( code ) = = mcroot . end ( ) ) {
2011-07-05 05:33:06 +00:00
int cnt = day - > count ( code ) ;
total_events + = cnt ;
2011-07-31 20:24:43 +00:00
QString st = channel [ m . key ( ) ] . details ( ) ;
2011-06-26 08:30:44 +00:00
if ( st . isEmpty ( ) ) {
2011-07-05 05:33:06 +00:00
st = " Fixme " + QString : : number ( ( int ) code ) ;
2011-06-26 08:30:44 +00:00
}
2011-07-30 08:10:02 +00:00
st + = " ( " + QString : : number ( cnt ) + " event " + ( ( cnt > 1 ) ? " s " : " " ) + " ) " ;
2011-06-26 08:30:44 +00:00
QStringList l ( st ) ;
l . append ( " " ) ;
mcroot [ code ] = mcr = new QTreeWidgetItem ( root , l ) ;
mccnt [ code ] = 0 ;
} else {
mcr = mcroot [ code ] ;
}
2011-07-31 20:24:43 +00:00
for ( int z = 0 ; z < m . value ( ) . size ( ) ; z + + ) {
for ( int o = 0 ; o < m . value ( ) [ z ] - > count ( ) ; o + + ) {
qint64 t = m . value ( ) [ z ] - > time ( o ) ;
2011-07-30 03:52:29 +00:00
2011-07-27 09:21:53 +00:00
if ( code = = CPAP_CSR ) {
2011-07-31 20:24:43 +00:00
t - = float ( m . value ( ) [ z ] - > raw ( o ) / 2.0 ) * 1000.0 ;
2011-07-27 09:21:53 +00:00
}
QStringList a ;
QDateTime d = QDateTime : : fromMSecsSinceEpoch ( t ) ;
2011-07-31 20:24:43 +00:00
QString s = QString ( " #%1: %2 (%3) " ) . arg ( ( int ) + + mccnt [ code ] , ( int ) 3 , ( int ) 10 , QChar ( ' 0 ' ) ) . arg ( d . toString ( " HH:mm:ss " ) ) . arg ( m . value ( ) [ z ] - > raw ( o ) ) ;
2011-07-27 09:21:53 +00:00
a . append ( s ) ;
a . append ( d . toString ( " yyyy-MM-dd HH:mm:ss " ) ) ;
mcr - > addChild ( new QTreeWidgetItem ( a ) ) ;
2011-06-26 08:30:44 +00:00
}
2011-07-30 03:52:29 +00:00
}
}
2011-06-26 08:30:44 +00:00
}
int cnt = 0 ;
2011-07-31 20:24:43 +00:00
for ( QHash < ChannelID , QTreeWidgetItem * > : : iterator m = mcroot . begin ( ) ; m ! = mcroot . end ( ) ; m + + ) {
tree - > insertTopLevelItem ( cnt + + , m . value ( ) ) ;
2011-06-26 08:30:44 +00:00
}
2011-07-05 05:33:06 +00:00
//tree->insertTopLevelItem(cnt++,new QTreeWidgetItem(QStringList("[Total Events ("+QString::number(total_events)+")]")));
2011-06-26 08:30:44 +00:00
tree - > sortByColumn ( 0 , Qt : : AscendingOrder ) ;
//tree->expandAll();
}
void Daily : : UpdateCalendarDay ( QDate date )
{
QTextCharFormat bold ;
QTextCharFormat cpapcol ;
QTextCharFormat normal ;
2011-07-03 12:08:30 +00:00
QTextCharFormat oxiday ;
2011-06-26 08:30:44 +00:00
bold . setFontWeight ( QFont : : Bold ) ;
cpapcol . setForeground ( QBrush ( Qt : : blue , Qt : : SolidPattern ) ) ;
cpapcol . setFontWeight ( QFont : : Bold ) ;
2011-07-03 12:08:30 +00:00
oxiday . setForeground ( QBrush ( Qt : : red , Qt : : SolidPattern ) ) ;
oxiday . setFontWeight ( QFont : : Bold ) ;
bool hascpap = profile - > GetDay ( date , MT_CPAP ) ! = NULL ;
bool hasoxi = profile - > GetDay ( date , MT_OXIMETER ) ! = NULL ;
if ( hascpap ) {
if ( hasoxi ) {
ui - > calendar - > setDateTextFormat ( date , oxiday ) ;
} else {
ui - > calendar - > setDateTextFormat ( date , cpapcol ) ;
}
2011-06-26 08:30:44 +00:00
} else if ( profile - > GetDay ( date ) ) {
ui - > calendar - > setDateTextFormat ( date , bold ) ;
} else {
ui - > calendar - > setDateTextFormat ( date , normal ) ;
}
ui - > calendar - > setHorizontalHeaderFormat ( QCalendarWidget : : ShortDayNames ) ;
}
void Daily : : on_calendar_selectionChanged ( )
{
if ( previous_date . isValid ( ) )
Unload ( previous_date ) ;
Load ( ui - > calendar - > selectedDate ( ) ) ;
}
2011-07-28 14:20:59 +00:00
void Daily : : ResetGraphLayout ( )
{
2011-08-02 10:28:29 +00:00
//splitter->setSizes(splitter_sizes);
2011-07-28 18:02:51 +00:00
2011-07-28 14:20:59 +00:00
}
2011-07-30 04:54:22 +00:00
void Daily : : ShowHideGraphs ( )
{
int vis = 0 ;
2011-07-31 20:24:43 +00:00
for ( int i = 0 ; i < Graphs . size ( ) ; i + + ) {
2011-07-30 04:54:22 +00:00
if ( Graphs [ i ] - > isEmpty ( ) ) {
GraphAction [ i ] - > setVisible ( false ) ;
Graphs [ i ] - > hide ( ) ;
} else {
Graphs [ i ] - > ResetBounds ( ) ;
GraphAction [ i ] - > setVisible ( true ) ;
if ( GraphAction [ i ] - > isChecked ( ) ) {
Graphs [ i ] - > show ( ) ;
2011-07-30 05:11:39 +00:00
vis + + ;
2011-07-30 04:54:22 +00:00
} else {
Graphs [ i ] - > hide ( ) ;
}
}
}
2011-08-07 04:44:01 +00:00
GraphLayout - > setMinimumHeight ( vis * default_height + 10 ) ;
2011-08-02 09:12:10 +00:00
//splitter->setMaximumHeight(vis*default_height);
splitter - > layout ( ) ;
2011-08-02 12:32:03 +00:00
//splitter->update();
2011-07-30 04:54:22 +00:00
RedrawGraphs ( ) ;
}
2011-06-26 08:30:44 +00:00
void Daily : : Load ( QDate date )
{
2011-07-27 10:47:50 +00:00
static Day * lastcpapday = NULL ;
2011-06-26 08:30:44 +00:00
previous_date = date ;
Day * cpap = profile - > GetDay ( date , MT_CPAP ) ;
2011-07-28 12:13:28 +00:00
Day * oxi = profile - > GetDay ( date , MT_OXIMETER ) ;
2011-07-01 10:10:44 +00:00
// Day *sleepstage=profile->GetDay(date,MT_SLEEPSTAGE);
2011-06-26 08:30:44 +00:00
2011-07-28 07:32:02 +00:00
if ( ! pref [ " MemoryHog " ] . toBool ( ) ) {
if ( lastcpapday & & ( lastcpapday ! = cpap ) ) {
2011-07-31 20:24:43 +00:00
for ( QVector < Session * > : : iterator s = lastcpapday - > begin ( ) ; s ! = lastcpapday - > end ( ) ; s + + ) {
2011-07-28 07:32:02 +00:00
( * s ) - > TrashEvents ( ) ;
}
2011-07-27 10:47:50 +00:00
}
}
lastcpapday = cpap ;
2011-07-05 05:33:06 +00:00
QString html = " <html><head><style type='text/css'>p,a,td,body { font-family: 'FreeSans', 'Sans Serif'; } p,a,td,body { font-size: 12px; } </style> "
" </head> "
" <body leftmargin=0 rightmargin=0 topmargin=0 marginwidth=0 marginheight=0> "
" <table cellspacing=0 cellpadding=2 border=0 width='100%'> \n " ;
2011-06-26 08:30:44 +00:00
QString tmp ;
2011-07-03 11:49:47 +00:00
const int gwwidth = 240 ;
2011-07-29 14:58:44 +00:00
const int gwheight = 100 ;
2011-07-28 12:13:28 +00:00
UpdateOXIGraphs ( oxi ) ;
2011-07-22 13:46:17 +00:00
UpdateCPAPGraphs ( cpap ) ;
2011-07-28 12:13:28 +00:00
UpdateEventsTree ( ui - > treeWidget , cpap ) ;
2011-06-26 08:30:44 +00:00
2011-07-28 12:13:28 +00:00
if ( ! cpap & & ! oxi ) {
2011-08-02 12:32:03 +00:00
GraphLayout - > setMinimumHeight ( 0 ) ;
2011-08-02 10:28:29 +00:00
//splitter->setMinimumHeight(0);
2011-07-27 09:21:53 +00:00
NoData - > setText ( tr ( " No data for " ) + date . toString ( Qt : : SystemLocaleLongDate ) ) ;
2011-07-28 12:22:34 +00:00
NoData - > show ( ) ;
2011-08-02 22:37:15 +00:00
2011-07-31 20:24:43 +00:00
for ( int i = 0 ; i < Graphs . size ( ) ; i + + ) {
2011-07-30 04:54:22 +00:00
GraphAction [ i ] - > setVisible ( false ) ;
2011-07-28 11:29:35 +00:00
Graphs [ i ] - > hide ( ) ;
}
2011-08-07 04:44:01 +00:00
spacer - > hide ( ) ;
2011-07-27 09:21:53 +00:00
} else {
2011-07-28 12:22:34 +00:00
NoData - > hide ( ) ;
2011-07-30 04:54:22 +00:00
int vis = 0 ;
2011-08-07 06:21:09 +00:00
scrollArea - > setUpdatesEnabled ( false ) ;
2011-07-31 20:24:43 +00:00
for ( int i = 0 ; i < Graphs . size ( ) ; i + + ) {
2011-08-02 12:32:03 +00:00
Graphs [ i ] - > setUpdatesEnabled ( false ) ;
2011-07-28 11:29:35 +00:00
if ( Graphs [ i ] - > isEmpty ( ) ) {
2011-07-30 04:54:22 +00:00
GraphAction [ i ] - > setVisible ( false ) ;
2011-07-28 11:29:35 +00:00
Graphs [ i ] - > hide ( ) ;
} else {
2011-07-30 04:54:22 +00:00
GraphAction [ i ] - > setVisible ( true ) ;
if ( GraphAction [ i ] - > isChecked ( ) ) {
2011-08-07 15:37:01 +00:00
Graphs [ i ] - > ResetBounds ( ) ;
2011-07-30 04:54:22 +00:00
Graphs [ i ] - > show ( ) ;
2011-07-30 05:11:39 +00:00
vis + + ;
2011-07-30 04:54:22 +00:00
} else {
Graphs [ i ] - > hide ( ) ;
}
2011-07-28 11:29:35 +00:00
}
}
2011-07-30 10:40:22 +00:00
if ( ! cpap ) {
2011-08-07 15:37:01 +00:00
GraphAction [ 0 ] - > setVisible ( false ) ;
SF - > hide ( ) ;
vis - - ;
2011-07-30 10:40:22 +00:00
}
2011-08-02 12:32:03 +00:00
//splitter->layout();
for ( int i = 0 ; i < Graphs . size ( ) ; i + + ) {
Graphs [ i ] - > setUpdatesEnabled ( true ) ;
}
2011-08-07 04:44:01 +00:00
spacer - > show ( ) ;
2011-08-02 12:32:03 +00:00
//splitter->addStrut(vis*default_height);
//QSize aa(this->width(),vis*default_height);
//splitter->SetMinimumSize(aa);
//splitter->SetFixedSize(aa);
2011-08-07 04:44:01 +00:00
GraphLayout - > setMinimumHeight ( vis * default_height + 20 ) ;
2011-08-02 12:32:03 +00:00
2011-08-02 22:37:15 +00:00
2011-08-02 09:12:10 +00:00
//splitter->setMinimumHeight(0);
2011-08-02 10:28:29 +00:00
//splitter->setMinimumHeight(vis*default_height);
2011-07-30 05:11:39 +00:00
//if (vis>4) {
2011-08-02 09:12:10 +00:00
//splitter->setMaximumHeight(vis*default_height);
2011-07-30 05:11:39 +00:00
//} //else {
// }
2011-08-02 12:32:03 +00:00
// splitter->blockSignals(true);
2011-08-07 15:37:01 +00:00
splitter - > setSpacing ( 0 ) ;
splitter - > setMargin ( 0 ) ;
2011-08-02 22:37:15 +00:00
splitter - > layout ( ) ;
2011-08-07 06:21:09 +00:00
scrollArea - > setUpdatesEnabled ( true ) ;
scrollArea - > update ( ) ;
2011-08-02 12:32:03 +00:00
//ui->scrollArea->update();
//splitter->layout();
2011-07-28 12:13:28 +00:00
2011-07-30 05:11:39 +00:00
// spacer->show();
2011-07-27 09:21:53 +00:00
}
2011-07-28 14:20:59 +00:00
2011-08-02 12:32:03 +00:00
//splitter->update();
2011-07-27 09:21:53 +00:00
RedrawGraphs ( ) ;
2011-07-28 12:13:28 +00:00
QString epr , modestr ;
2011-06-26 08:30:44 +00:00
float iap90 , eap90 ;
CPAPMode mode = MODE_UNKNOWN ;
PRTypes pr ;
QString a ;
if ( cpap ) {
2011-07-31 20:24:43 +00:00
mode = ( CPAPMode ) cpap - > settings_max ( CPAP_Mode ) ;
pr = ( PRTypes ) cpap - > settings_max ( PRS1_PressureReliefType ) ;
2011-06-26 08:30:44 +00:00
if ( pr = = PR_NONE )
epr = tr ( " No Pressure Relief " ) ;
else {
2011-07-31 20:24:43 +00:00
epr = channel [ PRS1_PressureReliefSetting ] . optionString ( pr ) + QString ( " x%1 " ) . arg ( ( int ) cpap - > settings_max ( PRS1_PressureReliefSetting ) ) ;
2011-06-26 08:30:44 +00:00
}
2011-07-31 20:24:43 +00:00
modestr = channel [ CPAP_Mode ] . optionString ( mode ) ;
2011-06-26 08:30:44 +00:00
2011-07-30 08:10:02 +00:00
float ahi = ( cpap - > count ( CPAP_Obstructive ) + cpap - > count ( CPAP_Hypopnea ) + cpap - > count ( CPAP_ClearAirway ) + cpap - > count ( CPAP_Apnea ) ) / cpap - > hours ( ) ;
2011-06-26 08:30:44 +00:00
float csr = ( 100.0 / cpap - > hours ( ) ) * ( cpap - > sum ( CPAP_CSR ) / 3600.0 ) ;
2011-07-30 08:10:02 +00:00
float uai = cpap - > count ( CPAP_Apnea ) / cpap - > hours ( ) ;
2011-06-26 08:30:44 +00:00
float oai = cpap - > count ( CPAP_Obstructive ) / cpap - > hours ( ) ;
float hi = cpap - > count ( CPAP_Hypopnea ) / cpap - > hours ( ) ;
float cai = cpap - > count ( CPAP_ClearAirway ) / cpap - > hours ( ) ;
float rei = cpap - > count ( CPAP_RERA ) / cpap - > hours ( ) ;
float vsi = cpap - > count ( CPAP_VSnore ) / cpap - > hours ( ) ;
float fli = cpap - > count ( CPAP_FlowLimit ) / cpap - > hours ( ) ;
2011-07-22 13:46:17 +00:00
2011-08-07 20:51:11 +00:00
//float p90=cpap->p90(CPAP_Pressure);
//eap90=cpap->p90(CPAP_EPAP);
//iap90=cpap->p90(CPAP_IPAP);
2011-06-26 08:30:44 +00:00
QString submodel = tr ( " Unknown Model " ) ;
2011-06-30 10:56:22 +00:00
//html+="<tr><td colspan=4 align=center><i>"+tr("Machine Information")+"</i></td></tr>\n";
2011-06-26 08:30:44 +00:00
if ( cpap - > machine - > properties . find ( " SubModel " ) ! = cpap - > machine - > properties . end ( ) )
submodel = " <br> " + cpap - > machine - > properties [ " SubModel " ] ;
2011-06-30 10:56:22 +00:00
html + = " <tr><td colspan=4 align=center><b> " + cpap - > machine - > properties [ " Brand " ] + " </b> <br> " + cpap - > machine - > properties [ " Model " ] + " " + cpap - > machine - > properties [ " ModelNumber " ] + submodel + " </td></tr> \n " ;
2011-06-26 08:30:44 +00:00
if ( pref . Exists ( " ShowSerialNumbers " ) & & pref [ " ShowSerialNumbers " ] . toBool ( ) ) {
2011-06-30 10:56:22 +00:00
html + = " <tr><td colspan=4 align=center> " + cpap - > machine - > properties [ " Serial " ] + " </td></tr> \n " ;
2011-06-26 08:30:44 +00:00
}
2011-06-30 10:56:22 +00:00
html + = " <tr><td align='center'><b>Date</b></td><td align='center'><b> " + tr ( " Sleep " ) + " </b></td><td align='center'><b> " + tr ( " Wake " ) + " </b></td><td align='center'><b> " + tr ( " Hours " ) + " </b></td></tr> " ;
2011-07-31 21:07:40 +00:00
int tt = cpap - > total_time ( ) / 1000.0 ;
2011-07-02 14:35:50 +00:00
QDateTime date = QDateTime : : fromMSecsSinceEpoch ( cpap - > first ( ) ) ;
QDateTime date2 = QDateTime : : fromMSecsSinceEpoch ( cpap - > last ( ) ) ;
2011-07-31 21:07:40 +00:00
int h = tt / 3600.0 ;
int m = ( tt / 60 ) % 60 ;
int s = tt % 60 ;
2011-07-05 05:33:06 +00:00
html + = QString ( " <tr><td align='center'>%1</td><td align='center'>%2</td><td align='center'>%3</td><td align='center'>%4</td></tr> \n "
" <tr><td colspan=4 align=center><hr></td></tr> \n " )
. arg ( date . date ( ) . toString ( Qt : : SystemLocaleShortDate ) )
. arg ( date . toString ( " HH:mm " ) )
. arg ( date2 . toString ( " HH:mm " ) )
2011-07-31 21:07:40 +00:00
. arg ( QString ( ) . sprintf ( " %02i:%02i:%02i " , h , m , s ) ) ;
2011-06-26 08:30:44 +00:00
2011-06-30 09:37:24 +00:00
QString cs ;
if ( cpap - > machine - > GetClass ( ) ! = " PRS1 " ) {
cs = " 4 align=center> " ;
} else cs = " 2> " ;
2011-07-05 05:33:06 +00:00
html + = " <tr><td colspan= " + cs + " <table cellspacing=0 cellpadding=2 border=0 width='100%'> "
" <tr><td align='right' bgcolor='#F88017'><b><font color='black'> " + tr ( " AHI " ) + " </font></b></td><td bgcolor='#F88017'><b><font color='black'> " + QString ( ) . sprintf ( " %.2f " , ahi ) + " </font></b></td></tr> \n "
2011-07-30 08:10:02 +00:00
" <tr><td align='right' bgcolor='#4040ff'><b><font color='white'> " + tr ( " Hypopnea " ) + " </font></b></td><td bgcolor='#4040ff'><font color='white'> " + QString ( ) . sprintf ( " %.2f " , hi ) + " </font></td></tr> \n " ;
if ( cpap - > machine - > GetClass ( ) = = " ResMed " ) {
html + = " <tr><td align='right' bgcolor='#208020'><b> " + tr ( " Apnea " ) + " </b></td><td bgcolor='#208020'> " + QString ( ) . sprintf ( " %.2f " , uai ) + " </td></tr> \n " ;
}
html + = " <tr><td align='right' bgcolor='#40afbf'><b> " + tr ( " Obstructive " ) + " </b></td><td bgcolor='#40afbf'> " + QString ( ) . sprintf ( " %.2f " , oai ) + " </td></tr> \n "
" <tr><td align='right' bgcolor='#b254cd'><b> " + tr ( " Clear Airway " ) + " </b></td><td bgcolor='#b254cd'> " + QString ( ) . sprintf ( " %.2f " , cai ) + " </td></tr> \n "
2011-07-05 05:33:06 +00:00
" </table></td> " ;
2011-06-30 09:37:24 +00:00
if ( cpap - > machine - > GetClass ( ) = = " PRS1 " ) {
2011-07-05 05:33:06 +00:00
html + = " <td colspan=2><table cellspacing=0 cellpadding=2 border=0 width='100%'> "
" <tr><td align='right' bgcolor='#ffff80'><b> " + tr ( " RERA " ) + " </b></td><td bgcolor='#ffff80'> " + QString ( ) . sprintf ( " %.2f " , rei ) + " </td></tr> \n "
" <tr><td align='right' bgcolor='#404040'><b><font color='white'> " + tr ( " FlowLimit " ) + " </font></b></td><td bgcolor='#404040'><font color='white'> " + a . sprintf ( " %.2f " , fli ) + " </font></td></tr> \n "
" <tr><td align='right' bgcolor='#ff4040'><b> " + tr ( " Vsnore " ) + " </b></td><td bgcolor='#ff4040'> " + QString ( ) . sprintf ( " %.2f " , vsi ) + " </td></tr> \n "
" <tr><td align='right' bgcolor='#80ff80'><b> " + tr ( " PB/CSR " ) + " </b></td><td bgcolor='#80ff80'> " + QString ( ) . sprintf ( " %.2f " , csr ) + " %</td></tr> \n "
" </table></td> " ;
2011-06-26 08:30:44 +00:00
}
2011-07-30 08:10:02 +00:00
2011-08-05 15:01:17 +00:00
// Note, this may not be a problem since Qt bug 13622 was discovered
// as it only relates to text drawing, which the Pie chart does not do
2011-08-07 15:37:01 +00:00
// ^^ Scratch that.. pie now includes text..
2011-08-05 15:01:17 +00:00
2011-08-05 00:12:23 +00:00
if ( pref [ " EnableGraphSnapshots " ] . toBool ( ) ) { // AHI Pie Chart
2011-08-07 20:51:11 +00:00
if ( ahi + rei + fli > 0 ) {
html + = " </tr> \n <tr><td colspan=4 align=center><i> " + tr ( " Event Breakdown " ) + " </i></td></tr> \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 + = " <tr><td colspan=4 align=center><img src= \" data:image/png;base64, " + byteArray . toBase64 ( ) + " \" ></td></tr> \n " ;
} else {
html + = " <tr><td colspan=4 align=center><img src= \" qrc:/docs/0.0.gif \" ></td></tr> \n " ;
}
2011-06-26 08:30:44 +00:00
}
2011-08-07 15:37:01 +00:00
}
html + = " </table> "
" <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
if ( cpap | | oxi ) {
html + = " <tr height='2'><td colspan=5 height='2'><hr></td></tr> \n " ;
2011-06-26 08:30:44 +00:00
2011-08-07 11:37:56 +00:00
/* if (mode==MODE_BIPAP) {
html + = " <tr><td colspan=4 align='center'><i> " + tr ( " 90% EPAP " ) + QString ( ) . sprintf ( " %.2f " , eap90 ) + tr ( " cmH2O " ) + " </td></tr> \n "
" <tr><td colspan=4 align='center'><i> " + tr ( " 90% IPAP " ) + QString ( ) . sprintf ( " %.2f " , iap90 ) + tr ( " cmH2O " ) + " </td></tr> \n " ;
2011-06-26 08:30:44 +00:00
} else if ( mode = = MODE_APAP ) {
2011-08-07 11:37:56 +00:00
html + = ( " <tr><td colspan=4 align='center'><i> " ) + tr ( " 90% Auto Pressure " ) + QString ( ) . sprintf ( " %.2f " , p90 ) + ( " </i></td></tr> \n " ) ; //cpap->summary_weighted_avg(CPAP_PressurePercentValue)
2011-06-26 08:30:44 +00:00
} else if ( mode = = MODE_CPAP ) {
2011-08-07 11:37:56 +00:00
html + = ( " <tr><td colspan=4 align='center'><i> " ) + tr ( " CPAP Pressure " ) + QString ( ) . sprintf ( " %.2f " , cpap - > max ( CPAP_Pressure ) ) + ( " </i></td></tr> \n " ) ;
} */
2011-06-26 08:30:44 +00:00
2011-08-07 11:37:56 +00:00
//html+=("<tr><td colspan=4 align=center> </td></tr>\n");
2011-07-12 12:43:10 +00:00
2011-08-07 11:37:56 +00:00
html + = ( " <tr><td> </td><td><b>Min</b></td><td><b>Avg</b></td><td><b>90%</b></td><td><b>Max</b></td></tr> " ) ;
2011-08-09 23:44:36 +00:00
ChannelID chans [ ] = {
CPAP_Pressure , CPAP_EPAP , CPAP_IPAP , CPAP_PressureSupport , CPAP_PatientTriggeredBreaths ,
CPAP_MinuteVentilation , CPAP_RespiratoryRate , CPAP_RespiratoryEvent , CPAP_FlowLimitGraph ,
CPAP_Leak , CPAP_Snore , CPAP_IE , CPAP_Ti , CPAP_Te , CPAP_TidalVolume ,
CPAP_Pulse , CPAP_SPO2 , OXI_Pulse , OXI_SPO2
} ;
2011-08-07 11:37:56 +00:00
int numchans = sizeof ( chans ) / sizeof ( ChannelID ) ;
for ( int i = 0 ; i < numchans ; i + + ) {
ChannelID code = chans [ i ] ;
2011-08-07 15:37:01 +00:00
if ( cpap & & cpap - > channelExists ( code ) ) {
2011-08-07 11:37:56 +00:00
html + = " <tr><td align=left> " + channel [ code ] . label ( ) ;
html + = " </td><td> " + a . sprintf ( " %.2f " , cpap - > min ( code ) ) ;
html + = " </td><td> " + a . sprintf ( " %.2f " , cpap - > wavg ( code ) ) ;
html + = " </td><td> " + a . sprintf ( " %.2f " , cpap - > p90 ( code ) ) ;
html + = " </td><td> " + a . sprintf ( " %.2f " , cpap - > max ( code ) ) ;
html + = " </td><tr> " ;
}
2011-08-07 15:37:01 +00:00
if ( oxi & & oxi - > channelExists ( code ) ) {
html + = " <tr><td align=left> " + channel [ code ] . label ( ) ;
html + = " </td><td> " + a . sprintf ( " %.2f " , oxi - > min ( code ) ) ;
html + = " </td><td> " + a . sprintf ( " %.2f " , oxi - > wavg ( code ) ) ;
html + = " </td><td> " + a . sprintf ( " %.2f " , oxi - > p90 ( code ) ) ;
html + = " </td><td> " + a . sprintf ( " %.2f " , oxi - > max ( code ) ) ;
html + = " </td><tr> " ;
}
2011-06-26 08:30:44 +00:00
}
2011-06-30 10:56:22 +00:00
2011-06-26 08:30:44 +00:00
} else {
2011-08-07 15:37:01 +00:00
html + = " <tr><td colspan=5 align=center><i> " + tr ( " No data available " ) + " </i></td></tr> " ;
2011-08-07 11:37:56 +00:00
html + = " <tr><td colspan=5> </td></tr> \n " ;
2011-06-26 08:30:44 +00:00
}
2011-08-07 15:37:01 +00:00
html + = " </table> " ;
html + = " <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
2011-06-26 08:30:44 +00:00
if ( cpap ) {
2011-08-07 11:37:56 +00:00
if ( pref [ " EnableGraphSnapshots " ] . toBool ( ) ) {
if ( cpap - > channelExists ( CPAP_Pressure ) ) {
html + = ( " <tr><td colspan=4 align=center><i> " ) + tr ( " Time@Pressure " ) + ( " </i></td></tr> \n " ) ;
TAP - > setFixedSize ( gwwidth , 30 ) ;
QPixmap pixmap = TAP - > renderPixmap ( gwwidth , 30 , false ) ;
QByteArray byteArray ;
QBuffer buffer ( & byteArray ) ; // use buffer to store pixmap into byteArray
buffer . open ( QIODevice : : WriteOnly ) ;
pixmap . save ( & buffer , " PNG " ) ;
html + = " <tr><td colspan=4 align=center><img src= \" data:image/png;base64, " + byteArray . toBase64 ( ) + " \" ></td></tr> \n " ;
2011-07-28 18:02:51 +00:00
}
2011-08-07 11:37:56 +00:00
if ( cpap - > channelExists ( CPAP_EPAP ) ) {
//html+="<tr height='2'><td colspan=4 height='2'><hr></td></tr>\n";
html + = ( " <tr><td colspan=4 align=center><i> " ) + tr ( " Time@EPAP " ) + ( " </i></td></tr> \n " ) ;
TAP_EAP - > setFixedSize ( gwwidth , 30 ) ;
QPixmap pixmap = TAP_EAP - > renderPixmap ( gwwidth , 30 , false ) ;
QByteArray byteArray ;
QBuffer buffer ( & byteArray ) ; // use buffer to store pixmap into byteArray
buffer . open ( QIODevice : : WriteOnly ) ;
pixmap . save ( & buffer , " PNG " ) ;
html + = " <tr><td colspan=4 align=center><img src= \" data:image/png;base64, " + byteArray . toBase64 ( ) + " \" ></td></tr> \n " ;
}
if ( cpap - > channelExists ( CPAP_IPAP ) ) {
html + = ( " <tr><td colspan=4 align=center><i> " ) + tr ( " Time@IPAP " ) + ( " </i></td></tr> \n " ) ;
TAP_IAP - > setFixedSize ( gwwidth , 30 ) ;
QPixmap pixmap = TAP_IAP - > renderPixmap ( gwwidth , 30 , false ) ;
QByteArray byteArray ;
QBuffer buffer ( & byteArray ) ; // use buffer to store pixmap into byteArray
buffer . open ( QIODevice : : WriteOnly ) ;
pixmap . save ( & buffer , " PNG " ) ;
html + = " <tr><td colspan=4 align=center><img src= \" data:image/png;base64, " + byteArray . toBase64 ( ) + " \" ></td></tr> \n " ;
2011-08-05 00:12:23 +00:00
}
2011-06-26 08:30:44 +00:00
}
2011-06-30 10:56:22 +00:00
html + = " </table><hr height=2><table cellpadding=0 cellspacing=0 border=0 width=100%> " ;
html + = " <tr><td align=center>SessionID</td><td align=center>Date</td><td align=center>Start</td><td align=center>End</td></tr> " ;
2011-07-02 14:35:50 +00:00
QDateTime fd , ld ;
2011-07-21 03:03:20 +00:00
bool corrupted_waveform = false ;
2011-07-31 20:24:43 +00:00
for ( QVector < Session * > : : iterator s = cpap - > begin ( ) ; s ! = cpap - > end ( ) ; s + + ) {
2011-07-02 14:35:50 +00:00
fd = QDateTime : : fromMSecsSinceEpoch ( ( * s ) - > first ( ) ) ;
ld = QDateTime : : fromMSecsSinceEpoch ( ( * s ) - > last ( ) ) ;
2011-07-31 20:24:43 +00:00
QHash < ChannelID , QVariant > : : iterator i = ( * s ) - > settings . find ( CPAP_BrokenWaveform ) ;
if ( ( i ! = ( * s ) - > settings . end ( ) ) & & i . value ( ) . toBool ( ) ) corrupted_waveform = true ;
2011-07-20 16:01:31 +00:00
tmp . sprintf ( ( " <tr><td align=center>%08i</td><td align=center> " + fd . date ( ) . toString ( Qt : : SystemLocaleShortDate ) + " </td><td align=center> " + fd . toString ( " HH:mm " ) + " </td><td align=center> " + ld . toString ( " HH:mm " ) + " </td></tr> " ) . toLatin1 ( ) , ( * s ) - > session ( ) ) ;
2011-06-26 08:30:44 +00:00
html + = tmp ;
}
2011-06-30 10:56:22 +00:00
html + = " </table> " ;
2011-07-21 03:03:20 +00:00
if ( corrupted_waveform ) {
html + = " <hr><div align=center><i>One or more waveform record for this session had faulty source data. Some waveform overlay points may not match up correctly.</i></div> " ;
}
2011-06-26 08:30:44 +00:00
}
html + = " </html> " ;
ui - > webView - > setHtml ( html ) ;
ui - > JournalNotes - > clear ( ) ;
Session * journal = GetJournalSession ( date ) ;
if ( journal ) {
2011-07-31 20:24:43 +00:00
ui - > JournalNotes - > setHtml ( journal - > settings [ JOURNAL_Notes ] . toString ( ) ) ;
2011-06-26 08:30:44 +00:00
}
2011-07-28 12:13:28 +00:00
2011-06-26 08:30:44 +00:00
}
void Daily : : Unload ( QDate date )
{
Session * journal = GetJournalSession ( date ) ;
if ( ! ui - > JournalNotes - > toPlainText ( ) . isEmpty ( ) ) {
QString jhtml = ui - > JournalNotes - > toHtml ( ) ;
if ( journal ) {
2011-07-31 20:24:43 +00:00
if ( journal - > settings [ JOURNAL_Notes ] ! = jhtml ) {
journal - > settings [ JOURNAL_Notes ] = jhtml ;
2011-06-26 08:30:44 +00:00
journal - > SetChanged ( true ) ;
}
} else {
journal = CreateJournalSession ( date ) ;
2011-07-31 20:24:43 +00:00
journal - > settings [ JOURNAL_Notes ] = jhtml ;
2011-06-26 08:30:44 +00:00
journal - > SetChanged ( true ) ;
}
}
if ( journal ) {
Machine * jm = profile - > GetMachine ( MT_JOURNAL ) ;
if ( jm ) jm - > SaveSession ( journal ) ;
}
UpdateCalendarDay ( date ) ;
}
void Daily : : on_JournalNotesItalic_clicked ( )
{
QTextCursor cursor = ui - > JournalNotes - > textCursor ( ) ;
if ( ! cursor . hasSelection ( ) )
cursor . select ( QTextCursor : : WordUnderCursor ) ;
QTextCharFormat format = cursor . charFormat ( ) ;
format . setFontItalic ( ! format . fontItalic ( ) ) ;
cursor . mergeCharFormat ( format ) ;
//ui->JournalNotes->mergeCurrentCharFormat(format);
}
void Daily : : on_JournalNotesBold_clicked ( )
{
QTextCursor cursor = ui - > JournalNotes - > textCursor ( ) ;
if ( ! cursor . hasSelection ( ) )
cursor . select ( QTextCursor : : WordUnderCursor ) ;
QTextCharFormat format = cursor . charFormat ( ) ;
int fw = format . fontWeight ( ) ;
if ( fw ! = QFont : : Bold )
format . setFontWeight ( QFont : : Bold ) ;
else
format . setFontWeight ( QFont : : Normal ) ;
cursor . mergeCharFormat ( format ) ;
//ui->JournalNotes->mergeCurrentCharFormat(format);
}
void Daily : : on_JournalNotesFontsize_activated ( int index )
{
QTextCursor cursor = ui - > JournalNotes - > textCursor ( ) ;
if ( ! cursor . hasSelection ( ) )
cursor . select ( QTextCursor : : WordUnderCursor ) ;
QTextCharFormat format = cursor . charFormat ( ) ;
QFont font = format . font ( ) ;
int fontsize = 10 ;
if ( index = = 1 ) fontsize = 15 ;
else if ( index = = 2 ) fontsize = 25 ;
font . setPointSize ( fontsize ) ;
format . setFont ( font ) ;
cursor . mergeCharFormat ( format ) ;
}
void Daily : : on_JournalNotesColour_clicked ( )
{
2011-06-27 15:00:00 +00:00
QColor col = QColorDialog : : getColor ( Qt : : black , this , tr ( " Pick a Colour " ) ) ; //,QColorDialog::NoButtons);
2011-06-26 08:30:44 +00:00
if ( ! col . isValid ( ) ) return ;
QTextCursor cursor = ui - > JournalNotes - > textCursor ( ) ;
if ( ! cursor . hasSelection ( ) )
cursor . select ( QTextCursor : : WordUnderCursor ) ;
QBrush b ( col ) ;
QPalette newPalette = palette ( ) ;
newPalette . setColor ( QPalette : : ButtonText , col ) ;
ui - > JournalNotesColour - > setPalette ( newPalette ) ;
QTextCharFormat format = cursor . charFormat ( ) ;
format . setForeground ( b ) ;
cursor . setCharFormat ( format ) ;
}
Session * Daily : : CreateJournalSession ( QDate date )
{
Machine * m = profile - > GetMachine ( MT_JOURNAL ) ;
if ( ! m ) {
m = new Machine ( profile , 0 ) ;
m - > SetClass ( " Journal " ) ;
m - > properties [ " Brand " ] = " Virtual " ;
m - > SetType ( MT_JOURNAL ) ;
profile - > AddMachine ( m ) ;
}
Session * sess = new Session ( m , 0 ) ;
QDateTime dt ;
dt . setDate ( date ) ;
dt . setTime ( QTime ( 17 , 0 ) ) ; //5pm to make sure it goes in the right day
2011-07-02 14:35:50 +00:00
sess - > set_first ( dt . toMSecsSinceEpoch ( ) ) ;
2011-06-26 08:30:44 +00:00
dt = dt . addSecs ( 3600 ) ;
2011-07-02 14:35:50 +00:00
sess - > set_last ( dt . toMSecsSinceEpoch ( ) ) ;
2011-06-26 08:30:44 +00:00
sess - > SetChanged ( true ) ;
m - > AddSession ( sess , profile ) ;
return sess ;
}
Session * Daily : : GetJournalSession ( QDate date ) // Get the first journal session
{
Day * journal = profile - > GetDay ( date , MT_JOURNAL ) ;
if ( ! journal )
return NULL ; //CreateJournalSession(date);
2011-07-31 20:24:43 +00:00
QVector < Session * > : : iterator s ;
2011-06-26 08:30:44 +00:00
s = journal - > begin ( ) ;
if ( s ! = journal - > end ( ) )
return * s ;
return NULL ;
}
void Daily : : on_EnergySlider_sliderMoved ( int position )
{
2011-07-31 20:24:43 +00:00
//Session *s=GetJournalSession(previous_date);
//if (!s)
// s=CreateJournalSession(previous_date);
2011-06-26 08:30:44 +00:00
2011-07-31 20:24:43 +00:00
//s->summary[JOURNAL_Energy]=position;
//s->SetChanged(true);
2011-06-26 08:30:44 +00:00
}
void Daily : : UpdateCPAPGraphs ( Day * day )
{
//if (!day) return;
if ( day ) {
day - > OpenEvents ( ) ;
}
2011-07-31 20:24:43 +00:00
for ( QList < gLayer * > : : iterator g = CPAPData . begin ( ) ; g ! = CPAPData . end ( ) ; g + + ) {
2011-07-27 09:21:53 +00:00
( * g ) - > SetDay ( day ) ;
2011-06-26 08:30:44 +00:00
}
} ;
void Daily : : UpdateOXIGraphs ( Day * day )
{
//if (!day) return;
2011-07-27 10:47:50 +00:00
2011-06-26 08:30:44 +00:00
if ( day ) {
day - > OpenEvents ( ) ;
}
2011-07-31 20:24:43 +00:00
for ( QList < gLayer * > : : iterator g = OXIData . begin ( ) ; g ! = OXIData . end ( ) ; g + + ) {
2011-07-27 09:21:53 +00:00
( * g ) - > SetDay ( day ) ;
2011-06-26 08:30:44 +00:00
}
2011-06-27 07:45:59 +00:00
}
void Daily : : RedrawGraphs ( )
{
2011-07-31 20:24:43 +00:00
for ( int i = 0 ; i < Graphs . size ( ) ; i + + ) {
2011-07-22 13:46:17 +00:00
Graphs [ i ] - > updateGL ( ) ;
2011-06-27 07:45:59 +00:00
}
}
2011-06-26 08:30:44 +00:00
void Daily : : on_treeWidget_itemSelectionChanged ( )
{
2011-06-27 10:55:55 +00:00
if ( ui - > treeWidget - > selectedItems ( ) . size ( ) = = 0 ) return ;
2011-06-26 08:30:44 +00:00
QTreeWidgetItem * item = ui - > treeWidget - > selectedItems ( ) . at ( 0 ) ;
2011-06-27 07:51:37 +00:00
if ( ! item ) return ;
2011-06-26 08:30:44 +00:00
QDateTime d ;
if ( ! item - > text ( 1 ) . isEmpty ( ) ) {
d = d . fromString ( item - > text ( 1 ) , " yyyy-MM-dd HH:mm:ss " ) ;
2011-07-30 08:10:02 +00:00
double st = ( d . addSecs ( - 120 ) ) . toMSecsSinceEpoch ( ) ;
double et = ( d . addSecs ( 120 ) ) . toMSecsSinceEpoch ( ) ;
2011-06-26 08:30:44 +00:00
FRW - > SetXBounds ( st , et ) ;
2011-07-11 04:54:53 +00:00
MP - > SetXBounds ( st , et ) ;
2011-06-26 08:30:44 +00:00
SF - > SetXBounds ( st , et ) ;
PRD - > SetXBounds ( st , et ) ;
LEAK - > SetXBounds ( st , et ) ;
SNORE - > SetXBounds ( st , et ) ;
2011-07-01 05:11:33 +00:00
MV - > SetXBounds ( st , et ) ;
TV - > SetXBounds ( st , et ) ;
RR - > SetXBounds ( st , et ) ;
FLG - > SetXBounds ( st , et ) ;
2011-06-26 08:30:44 +00:00
}
}
2011-06-28 01:51:21 +00:00
void Daily : : on_JournalNotesUnderline_clicked ( )
{
QTextCursor cursor = ui - > JournalNotes - > textCursor ( ) ;
if ( ! cursor . hasSelection ( ) )
cursor . select ( QTextCursor : : WordUnderCursor ) ;
QTextCharFormat format = cursor . charFormat ( ) ;
format . setFontUnderline ( ! format . fontUnderline ( ) ) ;
cursor . mergeCharFormat ( format ) ;
//ui->JournalNotes->mergeCurrentCharFormat(format);
}