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-08-20 08:20:22 +00:00
# include <QScrollBar>
2011-06-26 08:30:44 +00:00
2011-10-05 07:41:56 +00:00
# include "SleepLib/profiles.h"
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"
2011-07-28 17:15:15 +00:00
# include "Graphs/gSegmentChart.h"
2011-08-30 08:46:24 +00:00
# include "Graphs/gStatsLine.h"
2011-06-26 08:30:44 +00:00
2011-08-02 10:28:29 +00:00
const int min_height = 150 ;
2011-07-22 13:46:17 +00:00
2011-10-05 07:41:56 +00:00
Daily : : Daily ( QWidget * parent , gGraphView * shared , MainWindow * mw )
: QWidget ( parent ) , mainwin ( mw ) , ui ( new Ui : : Daily )
2011-06-26 08:30:44 +00:00
{
ui - > setupUi ( this ) ;
2011-10-05 12:43:34 +00:00
// Remove Incomplete Extras Tab
ui - > tabWidget - > removeTab ( 3 ) ;
2011-08-26 13:22:16 +00:00
QList < int > a ;
a . push_back ( 300 ) ;
a . push_back ( this - > width ( ) - 300 ) ;
2011-10-05 03:05:35 +00:00
ui - > splitter_2 - > setStretchFactor ( 1 , 1 ) ;
2011-08-26 13:22:16 +00:00
ui - > splitter_2 - > setSizes ( a ) ;
ui - > splitter_2 - > setStretchFactor ( 1 , 1 ) ;
2011-06-26 08:30:44 +00:00
2011-08-25 06:11:44 +00:00
layout = new QHBoxLayout ( ui - > graphMainArea ) ;
layout - > setSpacing ( 0 ) ;
layout - > setMargin ( 0 ) ;
layout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
ui - > graphMainArea - > setLayout ( layout ) ;
//ui->graphMainArea->setLayout(layout);
ui - > graphMainArea - > setAutoFillBackground ( false ) ;
2011-08-30 17:22:54 +00:00
GraphView = new gGraphView ( ui - > graphMainArea , shared ) ;
2011-08-25 06:11:44 +00:00
GraphView - > setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Expanding ) ;
2011-09-21 14:10:10 +00:00
snapGV = new gGraphView ( ui - > graphMainArea , shared ) ;
snapGV - > setMinimumSize ( 172 , 172 ) ;
snapGV - > hideSplitter ( ) ;
snapGV - > hide ( ) ;
2011-08-25 06:11:44 +00:00
scrollbar = new MyScrollBar ( ui - > graphMainArea ) ;
scrollbar - > setOrientation ( Qt : : Vertical ) ;
scrollbar - > setSizePolicy ( QSizePolicy : : Maximum , QSizePolicy : : Expanding ) ;
scrollbar - > setMaximumWidth ( 20 ) ;
GraphView - > setScrollBar ( scrollbar ) ;
layout - > addWidget ( GraphView , 1 ) ;
layout - > addWidget ( scrollbar , 0 ) ;
2011-07-29 14:58:44 +00:00
2011-09-04 06:18:41 +00:00
SF = new gGraph ( GraphView , " Event Flags " , default_height ) ;
2011-08-31 06:49:40 +00:00
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 ) ;
2011-08-29 11:42:40 +00:00
IE = new gGraph ( GraphView , " I:E " , default_height ) ;
2011-08-31 06:49:40 +00:00
TE = new gGraph ( GraphView , " Te " , default_height ) ;
TI = new gGraph ( GraphView , " Ti " , default_height ) ;
2011-11-14 09:26:58 +00:00
TgMV = new gGraph ( GraphView , " TgMV " , default_height ) ;
2011-08-31 06:49:40 +00:00
INTPULSE = new gGraph ( GraphView , " Pulse " , default_height , 1 ) ;
2011-08-30 08:46:24 +00:00
INTSPO2 = new gGraph ( GraphView , " SPO2 " , default_height , 1 ) ;
2011-08-31 06:49:40 +00:00
PULSE = new gGraph ( GraphView , " Pulse " , default_height , 1 ) ;
2011-08-29 11:42:40 +00:00
SPO2 = new gGraph ( GraphView , " SPO2 " , default_height , 1 ) ;
2011-08-31 06:49:40 +00:00
PLETHY = new gGraph ( GraphView , " Plethy " , default_height , 1 ) ;
2011-08-26 03:26:53 +00:00
2011-09-21 14:10:10 +00:00
// 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);
2011-08-25 06:11:44 +00:00
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 ) ) ) ;
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")));
//fg->AddLayer(AddCPAP(new gFlagsLine(flags[10],QColor("red"),"VS2"));
2011-08-25 08:02:04 +00:00
SF - > setBlockZoom ( true ) ;
2011-08-25 06:11:44 +00:00
SF - > AddLayer ( AddCPAP ( fg ) ) ;
2011-08-25 09:00:19 +00:00
SF - > AddLayer ( new gShadowArea ( ) ) ;
2011-08-25 06:11:44 +00:00
SF - > AddLayer ( new gYSpacer ( ) , LayerLeft , gYAxis : : Margin ) ;
2011-08-27 05:06:08 +00:00
//SF->AddLayer(new gFooBar(),LayerBottom,0,1);
2011-08-26 08:18:14 +00:00
SF - > AddLayer ( new gXAxis ( Qt : : black , false ) , LayerBottom , 0 , gXAxis : : Margin ) ;
2011-08-25 06:11:44 +00:00
gLineChart * l ;
l = new gLineChart ( CPAP_FlowRate , Qt : : black , false , false ) ;
2011-11-14 09:58:50 +00:00
gLineOverlaySummary * los = new gLineOverlaySummary ( " Selection AHI " , 5 , - 3 ) ;
2011-08-25 06:11:44 +00:00
AddCPAP ( l ) ;
2011-08-25 10:38:42 +00:00
FRW - > AddLayer ( new gXGrid ( ) ) ;
2011-08-26 08:23:54 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_CSR , QColor ( " light green " ) , " CSR " , FT_Span ) ) ) ;
2011-08-25 06:11:44 +00:00
FRW - > AddLayer ( l ) ;
FRW - > AddLayer ( new gYAxis ( ) , LayerLeft , gYAxis : : Margin ) ;
FRW - > AddLayer ( new gXAxis ( ) , LayerBottom , 0 , 20 ) ;
2011-11-12 13:58:58 +00:00
FRW - > AddLayer ( AddCPAP ( los - > add ( new gLineOverlayBar ( CPAP_Hypopnea , QColor ( " blue " ) , " H " ) ) ) ) ;
2011-08-25 06:11:44 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_PressurePulse , QColor ( " red " ) , " PR " , FT_Dot ) ) ) ;
//FRW->AddLayer(AddCPAP(new gLineOverlayBar(CPAP_Pressure,QColor("white"),"P",FT_Dot)));
2011-09-17 12:39:00 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( PRS1_0B , QColor ( " blue " ) , " 0B " , FT_Dot ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( PRS1_10 , QColor ( " orange " ) , " 10 " , FT_Dot ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( PRS1_0E , QColor ( " dark red " ) , " 0E " , FT_Dot ) ) ) ;
2011-08-25 06:11:44 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_RERA , QColor ( " gold " ) , " RE " ) ) ) ;
2011-11-12 13:58:58 +00:00
FRW - > AddLayer ( AddCPAP ( los - > add ( new gLineOverlayBar ( CPAP_Apnea , QColor ( " dark green " ) , " A " ) ) ) ) ;
2011-08-25 06:11:44 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_VSnore , QColor ( " red " ) , " VS " ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_FlowLimit , QColor ( " black " ) , " FL " ) ) ) ;
2011-11-12 13:58:58 +00:00
FRW - > AddLayer ( AddCPAP ( los - > add ( new gLineOverlayBar ( CPAP_Obstructive , QColor ( " #40c0ff " ) , " OA " ) ) ) ) ;
FRW - > AddLayer ( AddCPAP ( los - > add ( new gLineOverlayBar ( CPAP_ClearAirway , QColor ( " purple " ) , " CA " ) ) ) ) ;
FRW - > AddLayer ( AddCPAP ( los ) ) ;
2011-08-25 06:11:44 +00:00
2011-11-14 09:26:58 +00:00
gGraph * graphs [ ] = { PRD , LEAK , SNORE , PTB , MP , RR , MV , TV , FLG , IE , TI , TE , TgMV , SPO2 , PLETHY , PULSE , INTPULSE , INTSPO2 } ;
2011-08-29 11:42:40 +00:00
int ng = sizeof ( graphs ) / sizeof ( gGraph * ) ;
for ( int i = 0 ; i < ng ; i + + ) {
graphs [ i ] - > AddLayer ( new gXGrid ( ) ) ;
}
2011-08-31 05:24:48 +00:00
/*PRD->AddLayer(AddCPAP(new gStatsLine(CPAP_Pressure,"Pressure")),LayerBottom,0,20,1);
2011-08-30 08:46:24 +00:00
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 ) ;
2011-08-31 05:24:48 +00:00
TI - > AddLayer ( AddCPAP ( new gStatsLine ( CPAP_Ti ) ) , LayerBottom , 0 , 20 , 1 ) ; */
2011-08-30 08:46:24 +00:00
2011-11-07 08:14:58 +00:00
2011-11-07 04:10:48 +00:00
bool square = PROFILE [ " SquareWavePlots " ] . toBool ( ) ;
PRD - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_Pressure , QColor ( " dark green " ) , square ) ) ) ;
PRD - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_EPAP , Qt : : blue , square ) ) ) ;
PRD - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_IPAP , Qt : : red , square ) ) ) ;
LEAK - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_Leak , Qt : : darkYellow , square ) ) ) ;
2011-11-07 08:14:58 +00:00
SNORE - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_Snore , Qt : : darkGray , true ) ) ) ;
2011-11-07 04:10:48 +00:00
PTB - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_PTB , Qt : : gray , square ) ) ) ;
2011-11-07 05:25:29 +00:00
MP - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_MaskPressure , Qt : : blue , false ) ) ) ;
2011-11-07 04:10:48 +00:00
RR - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_RespRate , Qt : : darkMagenta , square ) ) ) ;
MV - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_MinuteVent , Qt : : darkCyan , square ) ) ) ;
TV - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_TidalVolume , Qt : : magenta , square ) ) ) ;
2011-11-07 08:14:58 +00:00
FLG - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_FLG , Qt : : darkBlue , true ) ) ) ;
2011-08-29 11:42:40 +00:00
//RE->AddLayer(AddCPAP(new gLineChart(CPAP_RespiratoryEvent,Qt::magenta,true)));
2011-11-07 04:10:48 +00:00
IE - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_IE , Qt : : darkRed , square ) ) ) ;
TE - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_Te , Qt : : darkGreen , square ) ) ) ;
TI - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_Ti , Qt : : darkBlue , square ) ) ) ;
2011-11-14 09:26:58 +00:00
TgMV - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_TgMV , Qt : : darkCyan , square ) ) ) ;
2011-11-07 04:10:48 +00:00
INTPULSE - > AddLayer ( AddCPAP ( new gLineChart ( OXI_Pulse , Qt : : red , square ) ) ) ;
INTSPO2 - > AddLayer ( AddCPAP ( new gLineChart ( OXI_SPO2 , Qt : : blue , square ) ) ) ;
PULSE - > AddLayer ( AddOXI ( new gLineChart ( OXI_Pulse , Qt : : red , square ) ) ) ;
SPO2 - > AddLayer ( AddOXI ( new gLineChart ( OXI_SPO2 , Qt : : blue , square ) ) ) ;
2011-09-17 12:39:00 +00:00
PLETHY - > AddLayer ( AddOXI ( new gLineChart ( OXI_Plethy , Qt : : darkBlue , false ) ) ) ;
2011-08-26 03:26:53 +00:00
2011-10-07 07:10:36 +00:00
SPO2 - > forceMaxY ( 100 ) ;
SPO2 - > forceMinY ( 70 ) ;
2011-10-07 05:28:35 +00:00
PULSE - > forceMinY ( 40 ) ;
2011-08-29 11:42:40 +00:00
for ( int i = 0 ; i < ng ; i + + ) {
graphs [ i ] - > AddLayer ( new gYAxis ( ) , LayerLeft , gYAxis : : Margin ) ;
graphs [ i ] - > AddLayer ( new gXAxis ( ) , LayerBottom , 0 , 20 ) ;
}
2011-08-25 06:11:44 +00:00
layout - > layout ( ) ;
2011-08-26 03:26:53 +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-11-15 05:49:41 +00:00
ui - > calendar - > setFirstDayOfWeek ( QLocale : : system ( ) . firstDayOfWeek ( ) ) ;
2011-08-26 03:26:53 +00:00
ui - > tabWidget - > setCurrentWidget ( ui - > details ) ;
2011-10-05 10:44:41 +00:00
ui - > webView - > settings ( ) - > setFontSize ( QWebSettings : : DefaultFontSize , QApplication : : font ( ) . pointSize ( ) ) ;
2011-10-30 03:09:43 +00:00
// TODO: Add preference to hide do this for Widget Haters..
//ui->calNavWidget->hide();
}
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
2011-06-26 08:30:44 +00:00
void Daily : : ReloadGraphs ( )
{
2011-10-05 07:41:56 +00:00
QDate d = PROFILE . LastDay ( ) ;
2011-06-26 08:30:44 +00:00
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-09-17 12:39:00 +00:00
& & ( code ! = PRS1_0B )
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-09-17 12:39:00 +00:00
QString st = schema : : channel [ m . key ( ) ] . description ( ) ;
2011-06-26 08:30:44 +00:00
if ( st . isEmpty ( ) ) {
2011-09-17 12:39:00 +00:00
st = " Fixme " + 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 ;
2011-09-01 13:07:26 +00:00
QDateTime d = QDateTime : : fromTime_t ( t / 1000 ) ;
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 ) ;
2011-10-05 07:41:56 +00:00
bool hascpap = PROFILE . GetDay ( date , MT_CPAP ) ! = NULL ;
bool hasoxi = PROFILE . GetDay ( date , MT_OXIMETER ) ! = NULL ;
2011-07-03 12:08:30 +00:00
if ( hascpap ) {
if ( hasoxi ) {
ui - > calendar - > setDateTextFormat ( date , oxiday ) ;
} else {
ui - > calendar - > setDateTextFormat ( date , cpapcol ) ;
}
2011-10-05 07:41:56 +00:00
} else if ( PROFILE . GetDay ( date ) ) {
2011-06-26 08:30:44 +00:00
ui - > calendar - > setDateTextFormat ( date , bold ) ;
} else {
ui - > calendar - > setDateTextFormat ( date , normal ) ;
}
ui - > calendar - > setHorizontalHeaderFormat ( QCalendarWidget : : ShortDayNames ) ;
}
2011-10-28 03:45:31 +00:00
void Daily : : LoadDate ( QDate date )
{
ui - > calendar - > setSelectedDate ( date ) ;
on_calendar_selectionChanged ( ) ;
}
2011-06-26 08:30:44 +00:00
void Daily : : on_calendar_selectionChanged ( )
{
if ( previous_date . isValid ( ) )
Unload ( previous_date ) ;
Load ( ui - > calendar - > selectedDate ( ) ) ;
2011-10-30 03:44:00 +00:00
ui - > calButton - > setText ( ui - > calendar - > selectedDate ( ) . toString ( Qt : : TextDate ) ) ;
2011-10-30 04:35:55 +00:00
ui - > calendar - > setFocus ( Qt : : ActiveWindowFocusReason ) ;
2011-06-26 08:30:44 +00:00
}
2011-07-28 14:20:59 +00:00
void Daily : : ResetGraphLayout ( )
{
2011-09-12 17:47:37 +00:00
GraphView - > resetLayout ( ) ;
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 ( )
{
2011-08-25 06:11:44 +00:00
/* 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-08-25 06:11:44 +00:00
RedrawGraphs ( ) ; */
2011-07-30 04:54:22 +00:00
}
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 ;
2011-10-05 07:41:56 +00:00
Day * cpap = PROFILE . GetDay ( date , MT_CPAP ) ;
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-10-05 07:41:56 +00:00
if ( ! PROFILE [ " MemoryHog " ] . toBool ( ) ) {
2011-07-28 07:32:02 +00:00
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-08-30 17:22:54 +00:00
//const int gwwidth=240;
//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-09-21 14:10:10 +00:00
snapGV - > setDay ( cpap ) ;
2011-06-26 08:30:44 +00:00
2011-09-02 05:13:07 +00:00
2011-08-25 06:11:44 +00:00
GraphView - > ResetBounds ( ) ;
2011-09-21 14:10:10 +00:00
//snapGV->ResetBounds();
2011-08-26 05:56:43 +00:00
//GraphView->ResetBounds(1);
2011-08-25 06:11:44 +00:00
2011-08-29 07:13:58 +00:00
//GraphView->setEmptyText(tr("No Data")); //tr("No data for ")+date.toString(Qt::SystemLocaleLongDate));
2011-07-28 12:13:28 +00:00
if ( ! cpap & & ! oxi ) {
2011-08-02 10:28:29 +00:00
//splitter->setMinimumHeight(0);
2011-08-25 06:11:44 +00:00
scrollbar - > hide ( ) ;
2011-08-29 07:13:58 +00:00
// GraphView->hide();
2011-07-27 09:21:53 +00:00
} else {
2011-08-29 07:13:58 +00:00
//NoData->hide();
// GraphView->show();
2011-08-25 06:11:44 +00:00
scrollbar - > show ( ) ;
2011-07-27 09:21:53 +00:00
}
2011-08-29 07:13:58 +00:00
GraphView - > updateGL ( ) ;
2011-09-21 14:10:10 +00:00
snapGV - > updateGL ( ) ;
2011-07-28 14:20:59 +00:00
2011-08-25 06:11:44 +00:00
//RedrawGraphs();
2011-07-27 09:21:53 +00:00
2011-07-28 12:13:28 +00:00
QString epr , modestr ;
2011-08-30 17:22:54 +00:00
//float iap90,eap90;
2011-06-26 08:30:44 +00:00
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 ) ;
2011-09-17 12:39:00 +00:00
pr = ( PRTypes ) cpap - > settings_max ( PRS1_FlexMode ) ;
2011-06-26 08:30:44 +00:00
if ( pr = = PR_NONE )
epr = tr ( " No Pressure Relief " ) ;
else {
2011-09-17 12:39:00 +00:00
//epr=schema::channel[PRS1_FlexSet].optionString(pr)+QString(" x%1").arg((int)cpap->settings_max(PRS1_FlexSet));
2011-06-26 08:30:44 +00:00
}
2011-09-17 12:39:00 +00:00
modestr = schema : : channel [ CPAP_Mode ] . m_options [ mode ] ;
2011-07-31 20:24:43 +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-10-05 07:41:56 +00:00
if ( PROFILE . Exists ( " ShowSerialNumbers " ) & & PROFILE [ " 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-09-12 02:24:58 +00:00
int tt = qint64 ( cpap - > total_time ( ) ) / 1000L ;
QDateTime date = QDateTime : : fromTime_t ( cpap - > first ( ) / 1000L ) ;
QDateTime date2 = QDateTime : : fromTime_t ( cpap - > last ( ) / 1000L ) ;
2011-07-02 14:35:50 +00:00
2011-09-12 02:24:58 +00:00
int h = tt / 3600 ;
2011-07-31 21:07:40 +00:00
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-10-05 07:41:56 +00:00
if ( PROFILE [ " EnableGraphSnapshots " ] . toBool ( ) ) { // AHI Pie Chart
2011-09-21 14:10:10 +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 = 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 + = " <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-09-23 04:20:57 +00:00
}
2011-08-07 15:37:01 +00:00
}
2011-08-25 06:11:44 +00:00
html + = " </table> " ;
html + = " <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
2011-08-07 15:37:01 +00:00
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
//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 [ ] = {
2011-09-17 12:39:00 +00:00
CPAP_Pressure , CPAP_EPAP , CPAP_IPAP , CPAP_PS , CPAP_PTB ,
CPAP_MinuteVent , CPAP_RespRate , CPAP_RespEvent , CPAP_FLG ,
2011-11-14 09:26:58 +00:00
CPAP_Leak , CPAP_Snore , CPAP_IE , CPAP_Ti , CPAP_Te , CPAP_TgMV ,
CPAP_TidalVolume , OXI_Pulse , OXI_SPO2
2011-08-09 23:44:36 +00:00
} ;
2011-08-07 11:37:56 +00:00
int numchans = sizeof ( chans ) / sizeof ( ChannelID ) ;
2011-09-23 03:54:48 +00:00
int suboffset ;
2011-08-07 11:37:56 +00:00
for ( int i = 0 ; i < numchans ; i + + ) {
2011-09-23 03:54:48 +00:00
2011-08-07 11:37:56 +00:00
ChannelID code = chans [ i ] ;
2011-09-17 12:39:00 +00:00
if ( cpap & & cpap - > channelHasData ( code ) ) {
2011-10-05 07:41:56 +00:00
if ( code = = CPAP_Leak ) suboffset = PROFILE [ " IntentionalLeak " ] . toDouble ( ) ; else suboffset = 0 ;
2011-09-17 12:39:00 +00:00
html + = " <tr><td align=left> " + schema : : channel [ code ] . label ( ) ;
2011-09-23 03:54:48 +00:00
html + = " </td><td> " + a . sprintf ( " %.2f " , cpap - > min ( code ) - suboffset ) ;
html + = " </td><td> " + a . sprintf ( " %.2f " , cpap - > wavg ( code ) - suboffset ) ;
html + = " </td><td> " + a . sprintf ( " %.2f " , cpap - > p90 ( code ) - suboffset ) ;
html + = " </td><td> " + a . sprintf ( " %.2f " , cpap - > max ( code ) - suboffset ) ;
2011-08-07 11:37:56 +00:00
html + = " </td><tr> " ;
}
2011-09-17 12:39:00 +00:00
if ( oxi & & oxi - > channelHasData ( code ) ) {
html + = " <tr><td align=left> " + schema : : channel [ code ] . label ( ) ;
2011-08-07 15:37:01 +00:00
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-10-05 07:41:56 +00:00
// if ((*profile)["EnableGraphSnapshots"].toBool()) {
2011-08-25 06:11:44 +00:00
/* if (cpap->channelExists(CPAP_Pressure)) {
2011-08-07 11:37:56 +00:00
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-25 06:11:44 +00:00
} */
2011-09-04 13:09:21 +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-10-07 07:10:36 +00:00
if ( cpap ) {
for ( QVector < Session * > : : iterator s = cpap - > begin ( ) ; s ! = cpap - > end ( ) ; s + + ) {
fd = QDateTime : : fromTime_t ( ( * s ) - > first ( ) / 1000L ) ;
ld = QDateTime : : fromTime_t ( ( * s ) - > last ( ) / 1000L ) ;
QHash < ChannelID , QVariant > : : iterator i = ( * s ) - > settings . find ( " BrokenWaveform " ) ;
if ( ( i ! = ( * s ) - > settings . end ( ) ) & & i . value ( ) . toBool ( ) ) corrupted_waveform = true ;
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 ( ) ) ;
html + = tmp ;
}
2011-10-07 05:28:35 +00:00
}
2011-10-07 07:10:36 +00:00
if ( oxi ) {
for ( QVector < Session * > : : iterator s = oxi - > begin ( ) ; s ! = oxi - > end ( ) ; s + + ) {
fd = QDateTime : : fromTime_t ( ( * s ) - > first ( ) / 1000L ) ;
ld = QDateTime : : fromTime_t ( ( * s ) - > last ( ) / 1000L ) ;
QHash < ChannelID , QVariant > : : iterator i = ( * s ) - > settings . find ( " BrokenWaveform " ) ;
if ( ( i ! = ( * s ) - > settings . end ( ) ) & & i . value ( ) . toBool ( ) ) corrupted_waveform = true ;
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 ( ) ) ;
html + = tmp ;
}
2011-06-26 08:30:44 +00:00
}
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
}
2011-08-25 06:11:44 +00:00
html + = " </body></html> " ;
2011-06-26 08:30:44 +00:00
ui - > webView - > setHtml ( html ) ;
2011-09-17 15:41:31 +00:00
ui - > JournalNotes - > clear ( ) ;
2011-06-26 08:30:44 +00:00
Session * journal = GetJournalSession ( date ) ;
if ( journal ) {
2011-09-17 15:41:31 +00:00
ui - > JournalNotes - > setHtml ( journal - > settings [ Journal_Notes ] . toString ( ) ) ;
}
2011-07-28 12:13:28 +00:00
2011-06-26 08:30:44 +00:00
}
void Daily : : Unload ( QDate date )
{
2011-09-17 15:41:31 +00:00
Session * journal = GetJournalSession ( date ) ;
2011-06-26 08:30:44 +00:00
if ( ! ui - > JournalNotes - > toPlainText ( ) . isEmpty ( ) ) {
QString jhtml = ui - > JournalNotes - > toHtml ( ) ;
if ( journal ) {
2011-09-17 15:41:31 +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-09-17 15:41:31 +00:00
journal - > settings [ Journal_Notes ] = jhtml ;
2011-06-26 08:30:44 +00:00
journal - > SetChanged ( true ) ;
}
}
if ( journal ) {
2011-10-05 07:41:56 +00:00
Machine * jm = PROFILE . GetMachine ( MT_JOURNAL ) ;
2011-06-26 08:30:44 +00:00
if ( jm ) jm - > SaveSession ( journal ) ;
2011-09-17 15:41:31 +00:00
}
2011-06-26 08:30:44 +00:00
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 )
{
2011-10-05 07:41:56 +00:00
Machine * m = PROFILE . GetMachine ( MT_JOURNAL ) ;
2011-06-26 08:30:44 +00:00
if ( ! m ) {
2011-10-05 07:41:56 +00:00
m = new Machine ( p_profile , 0 ) ;
2011-06-26 08:30:44 +00:00
m - > SetClass ( " Journal " ) ;
m - > properties [ " Brand " ] = " Virtual " ;
m - > SetType ( MT_JOURNAL ) ;
2011-10-05 07:41:56 +00:00
PROFILE . AddMachine ( m ) ;
2011-06-26 08:30:44 +00:00
}
Session * sess = new Session ( m , 0 ) ;
2011-09-03 01:24:11 +00:00
QDateTime dt ( date , QTime ( 17 , 0 ) ) ;
//dt.setDate(date);
//dt.setTime(QTime(17,0)); //5pm to make sure it goes in the right day
2011-09-01 13:07:26 +00:00
sess - > set_first ( qint64 ( dt . toTime_t ( ) ) * 1000L ) ;
2011-06-26 08:30:44 +00:00
dt = dt . addSecs ( 3600 ) ;
2011-09-01 13:07:26 +00:00
sess - > set_last ( qint64 ( dt . toTime_t ( ) ) * 1000L ) ;
2011-06-26 08:30:44 +00:00
sess - > SetChanged ( true ) ;
2011-10-05 07:41:56 +00:00
m - > AddSession ( sess , p_profile ) ;
2011-06-26 08:30:44 +00:00
return sess ;
}
Session * Daily : : GetJournalSession ( QDate date ) // Get the first journal session
{
2011-10-05 07:41:56 +00:00
Day * journal = PROFILE . GetDay ( date , MT_JOURNAL ) ;
2011-06-26 08:30:44 +00:00
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-08-30 17:22:54 +00:00
position = 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-08-25 06:11:44 +00:00
for ( QList < Layer * > : : 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
}
2011-09-21 14:10:10 +00:00
}
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-08-25 06:11:44 +00:00
for ( QList < Layer * > : : 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-09-02 02:00:04 +00:00
GraphView - > 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-09-01 13:07:26 +00:00
double st = qint64 ( ( d . addSecs ( - 120 ) ) . toTime_t ( ) ) * 1000L ;
double et = qint64 ( ( d . addSecs ( 120 ) ) . toTime_t ( ) ) * 1000L ;
2011-08-25 06:11:44 +00:00
GraphView - > 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);
}
2011-10-30 02:46:17 +00:00
void Daily : : on_prevDayButton_clicked ( )
{
2011-10-30 09:29:04 +00:00
if ( ! PROFILE . ExistsAndTrue ( " SkipEmptyDays " ) ) {
2011-10-30 04:51:57 +00:00
LoadDate ( previous_date . addDays ( - 1 ) ) ;
} else {
QDate d = previous_date ;
for ( int i = 0 ; i < 90 ; i + + ) {
d = d . addDays ( - 1 ) ;
if ( PROFILE . GetDay ( d ) ) {
LoadDate ( d ) ;
break ;
}
2011-10-30 04:43:15 +00:00
}
}
2011-10-30 02:46:17 +00:00
}
void Daily : : on_nextDayButton_clicked ( )
{
2011-10-30 09:29:04 +00:00
if ( ! PROFILE . ExistsAndTrue ( " SkipEmptyDays " ) ) {
2011-10-30 04:51:57 +00:00
LoadDate ( previous_date . addDays ( 1 ) ) ;
} else {
QDate d = previous_date ;
for ( int i = 0 ; i < 90 ; i + + ) {
d = d . addDays ( 1 ) ;
if ( PROFILE . GetDay ( d ) ) {
LoadDate ( d ) ;
break ;
}
2011-10-30 04:43:15 +00:00
}
}
2011-10-30 02:46:17 +00:00
}
void Daily : : on_calButton_toggled ( bool checked )
{
2011-10-30 14:23:59 +00:00
//bool b=!ui->calendar->isVisible();
bool b = checked ;
2011-10-30 04:35:55 +00:00
ui - > calendar - > setVisible ( b ) ;
if ( ! b ) ui - > calButton - > setArrowType ( Qt : : DownArrow ) ;
2011-10-30 04:21:35 +00:00
else ui - > calButton - > setArrowType ( Qt : : UpArrow ) ;
2011-10-30 02:46:17 +00:00
}
2011-10-30 03:18:20 +00:00
void Daily : : on_todayButton_clicked ( )
{
QDate d = QDate : : currentDate ( ) ;
if ( d > PROFILE . LastDay ( ) ) d = PROFILE . LastDay ( ) ;
LoadDate ( d ) ;
}