2014-04-09 21:01:57 +00:00
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim : set ts = 8 sts = 4 et sw = 4 tw = 99 :
*
* Daily Panel
*
* Copyright ( c ) 2011 - 2014 Mark Watkins < jedimark @ users . sourceforge . net >
*
* This file is subject to the terms and conditions of the GNU General Public
* License . See the file COPYING in the main directory of the Linux
* distribution for more details . */
2011-06-26 08:30:44 +00:00
# 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-12-01 06:06:13 +00:00
# include <QSpacerItem>
2011-12-28 20:15:25 +00:00
# include <QWebFrame>
2013-10-13 08:07:43 +00:00
# include <QFontMetrics>
2013-10-10 17:36:53 +00:00
# include <QLabel>
2011-12-02 13:48:05 +00:00
# include <cmath>
2011-12-01 15:40:32 +00:00
//#include <QPrinter>
//#include <QProgressBar>
2011-06-26 08:30:44 +00:00
2011-11-27 22:36:38 +00:00
# include "daily.h"
# include "ui_daily.h"
2011-11-15 21:22:08 +00:00
# include "common_gui.h"
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-12-01 15:40:32 +00:00
//extern QProgressBar *qprogress;
2011-12-18 10:53:51 +00:00
extern MainWindow * mainwin ;
2011-12-01 15:40:32 +00:00
2014-05-13 08:14:20 +00:00
// This was Sean Stangl's idea.. but I couldn't apply that patch.
inline QString channelInfo ( ChannelID code ) {
return schema : : channel [ code ] . fullname ( ) + " \n " + schema : : channel [ code ] . description ( ) + " \n ( " + schema : : channel [ code ] . units ( ) + " ) " ;
}
2011-12-18 10:53:51 +00:00
Daily : : Daily ( QWidget * parent , gGraphView * shared )
: QWidget ( parent ) , 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
2011-12-02 11:40:47 +00:00
//ui->tabWidget->removeTab(3);
2011-10-05 12:43:34 +00:00
2011-12-03 09:26:59 +00:00
ZombieMeterMoved = false ;
BookmarksChanged = false ;
2014-04-23 13:19:56 +00:00
lastcpapday = nullptr ;
2013-10-22 11:42:57 +00:00
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
2014-06-16 00:16:49 +00:00
layout = new QHBoxLayout ( ) ;
2011-08-25 06:11:44 +00:00
layout - > setSpacing ( 0 ) ;
layout - > setMargin ( 0 ) ;
layout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2013-10-10 17:36:53 +00:00
2013-10-12 08:07:57 +00:00
dateDisplay = new QLabel ( " " , this ) ;
dateDisplay - > setAlignment ( Qt : : AlignCenter ) ;
dateDisplay - > setTextFormat ( Qt : : RichText ) ;
ui - > sessionBarLayout - > addWidget ( dateDisplay , 1 ) ;
2013-10-12 07:40:45 +00:00
// const bool sessbar_under_graphs=false;
// if (sessbar_under_graphs) {
// ui->sessionBarLayout->addWidget(sessbar,1);
// } else {
// ui->splitter->insertWidget(2,sessbar);
// sessbar->setMaximumHeight(sessbar->height());
// sessbar->setMinimumHeight(sessbar->height());
// }
2013-10-10 17:36:53 +00:00
2014-05-17 11:33:33 +00:00
ui - > calNavWidget - > setMaximumHeight ( ui - > calNavWidget - > height ( ) ) ;
ui - > calNavWidget - > setMinimumHeight ( ui - > calNavWidget - > height ( ) ) ;
2014-04-23 13:19:56 +00:00
sessbar = nullptr ;
2013-10-10 17:36:53 +00:00
2013-10-12 07:40:45 +00:00
webView = new MyWebView ( this ) ;
QWebSettings : : globalSettings ( ) - > setAttribute ( QWebSettings : : PluginsEnabled , true ) ;
ui - > tabWidget - > insertTab ( 0 , webView , QIcon ( ) , " Details " ) ;
2014-05-17 11:33:33 +00:00
ui - > graphFrame - > setLayout ( layout ) ;
2011-08-25 06:11:44 +00:00
//ui->graphMainArea->setLayout(layout);
ui - > graphMainArea - > setAutoFillBackground ( false ) ;
2014-05-17 11:33:33 +00:00
GraphView = new gGraphView ( ui - > graphFrame , shared ) ;
2011-08-25 06:11:44 +00:00
GraphView - > setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Expanding ) ;
2013-07-28 05:33:44 +00:00
snapGV = new gGraphView ( GraphView ) ; //ui->graphMainArea);
2011-09-21 14:10:10 +00:00
snapGV - > setMinimumSize ( 172 , 172 ) ;
snapGV - > hideSplitter ( ) ;
snapGV - > hide ( ) ;
2011-12-08 14:47:10 +00:00
2014-05-17 11:33:33 +00:00
scrollbar = new MyScrollBar ( ui - > graphFrame ) ;
2011-08-25 06:11:44 +00:00
scrollbar - > setOrientation ( Qt : : Vertical ) ;
scrollbar - > setSizePolicy ( QSizePolicy : : Maximum , QSizePolicy : : Expanding ) ;
scrollbar - > setMaximumWidth ( 20 ) ;
2011-12-02 11:40:47 +00:00
ui - > bookmarkTable - > setColumnCount ( 2 ) ;
ui - > bookmarkTable - > setColumnWidth ( 0 , 70 ) ;
//ui->bookmarkTable->setEditTriggers(QAbstractItemView::SelectedClicked);
//ui->bookmarkTable->setColumnHidden(2,true);
//ui->bookmarkTable->setColumnHidden(3,true);
2011-08-25 06:11:44 +00:00
GraphView - > setScrollBar ( scrollbar ) ;
layout - > addWidget ( GraphView , 1 ) ;
layout - > addWidget ( scrollbar , 0 ) ;
2011-07-29 14:58:44 +00:00
2014-07-11 12:09:38 +00:00
int default_height = p_profile - > appearance - > graphHeight ( ) ;
2014-04-05 02:27:47 +00:00
2014-05-13 08:14:20 +00:00
gGraph * GAHI = nullptr ,
// *TAP = nullptr,
* SF = nullptr ,
* AHI = nullptr ;
2014-07-16 17:12:52 +00:00
graphlist [ STR_GRAPH_SleepFlags ] = SF = new gGraph ( STR_GRAPH_SleepFlags , GraphView , STR_TR_EventFlags , STR_TR_EventFlags , default_height ) ;
2014-04-05 01:28:07 +00:00
SF - > setPinned ( true ) ;
2011-12-24 05:55:44 +00:00
2014-05-13 08:14:20 +00:00
ChannelID cpapcodes [ ] = {
CPAP_FlowRate , CPAP_MaskPressure , CPAP_Pressure , CPAP_Leak , CPAP_Snore , CPAP_RespRate ,
CPAP_TidalVolume , CPAP_MinuteVent , CPAP_FLG , CPAP_PTB , CPAP_RespEvent , CPAP_Ti , CPAP_Te ,
CPAP_IE , ZEO_SleepStage , POS_Inclination , POS_Orientation
} ;
int cpapsize = sizeof ( cpapcodes ) / sizeof ( ChannelID ) ;
ChannelID oxicodes [ ] = {
OXI_Pulse , OXI_SPO2 , OXI_Plethy
} ;
int oxisize = sizeof ( oxicodes ) / sizeof ( ChannelID ) ;
for ( int i = 0 ; i < cpapsize ; + + i ) {
ChannelID code = cpapcodes [ i ] ;
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ code ] . code ( ) ] = new gGraph ( schema : : channel [ code ] . code ( ) , GraphView , schema : : channel [ code ] . label ( ) , channelInfo ( code ) , default_height ) ;
2014-05-13 08:14:20 +00:00
}
2014-07-11 12:09:38 +00:00
int oxigrp = p_profile - > ExistsAndTrue ( " SyncOximetry " ) ? 0 : 1 ; // Contemplating killing this setting...
2014-05-13 08:14:20 +00:00
for ( int i = 0 ; i < oxisize ; + + i ) {
ChannelID code = oxicodes [ i ] ;
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ code ] . code ( ) ] = new gGraph ( schema : : channel [ code ] . code ( ) , GraphView , schema : : channel [ code ] . label ( ) , channelInfo ( code ) , default_height , oxigrp ) ;
2014-05-13 08:14:20 +00:00
}
2011-12-24 05:55:44 +00:00
2014-07-11 12:09:38 +00:00
if ( p_profile - > general - > calculateRDI ( ) ) {
2014-07-16 17:12:52 +00:00
AHI = new gGraph ( " AHI " , GraphView , STR_TR_RDI , channelInfo ( CPAP_RDI ) , default_height ) ;
2014-05-13 08:14:20 +00:00
} else {
2014-07-16 17:12:52 +00:00
AHI = new gGraph ( " AHI " , GraphView , STR_TR_AHI , channelInfo ( CPAP_AHI ) , default_height ) ;
2014-05-13 08:14:20 +00:00
}
graphlist [ " AHI " ] = AHI ;
2014-07-16 17:12:52 +00:00
graphlist [ " INTPULSE " ] = new gGraph ( " INTPULSE " , GraphView , tr ( " Int. Pulse " ) , channelInfo ( OXI_Pulse ) , default_height , oxigrp ) ;
graphlist [ " INTSPO2 " ] = new gGraph ( " INTSPO2 " , GraphView , tr ( " Int. SpO2 " ) , channelInfo ( OXI_SPO2 ) , default_height , oxigrp ) ;
2014-04-15 13:59:24 +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)
2011-12-21 14:24:09 +00:00
// TAP=new gGraph(GraphView,"Time@Pressure",STR_UNIT_CMH2O,100);
2011-12-14 04:54:17 +00:00
// TAP->showTitle(false);
// gTAPGraph * tap=new gTAPGraph(CPAP_Pressure,GST_Line);
// TAP->AddLayer(AddCPAP(tap));
//TAP->setMargins(0,0,0,0);
2014-07-16 17:12:52 +00:00
graphlist [ STR_GRAPH_EventBreakdown ] = GAHI = new gGraph ( STR_GRAPH_EventBreakdown , snapGV , tr ( " Breakdown " ) , tr ( " events " ) , 172 ) ;
2011-09-21 14:10:10 +00:00
gSegmentChart * evseg = new gSegmentChart ( GST_Pie ) ;
2013-09-10 15:09:09 +00:00
evseg - > AddSlice ( CPAP_Hypopnea , QColor ( 0x40 , 0x40 , 0xff , 0xff ) , STR_TR_H ) ;
evseg - > AddSlice ( CPAP_Apnea , QColor ( 0x20 , 0x80 , 0x20 , 0xff ) , STR_TR_UA ) ;
evseg - > AddSlice ( CPAP_Obstructive , QColor ( 0x40 , 0xaf , 0xbf , 0xff ) , STR_TR_OA ) ;
evseg - > AddSlice ( CPAP_ClearAirway , QColor ( 0xb2 , 0x54 , 0xcd , 0xff ) , STR_TR_CA ) ;
evseg - > AddSlice ( CPAP_RERA , QColor ( 0xff , 0xff , 0x80 , 0xff ) , STR_TR_RE ) ;
evseg - > AddSlice ( CPAP_NRI , QColor ( 0x00 , 0x80 , 0x40 , 0xff ) , STR_TR_NR ) ;
evseg - > AddSlice ( CPAP_FlowLimit , QColor ( 0x40 , 0x40 , 0x40 , 0xff ) , STR_TR_FL ) ;
2014-05-15 03:51:32 +00:00
evseg - > AddSlice ( CPAP_SensAwake , QColor ( 0x40 , 0xC0 , 0x40 , 0xff ) , STR_TR_SA ) ;
2014-07-20 09:22:31 +00:00
if ( p_profile - > cpap - > userEventPieChart ( ) ) {
evseg - > AddSlice ( CPAP_UserFlag1 , QColor ( 0xe0 , 0xe0 , 0xe0 , 0xff ) , tr ( " UF1 " ) ) ;
evseg - > AddSlice ( CPAP_UserFlag2 , QColor ( 0xc0 , 0xc0 , 0xe0 , 0xff ) , tr ( " UF2 " ) ) ;
}
2011-09-21 14:10:10 +00:00
GAHI - > AddLayer ( AddCPAP ( evseg ) ) ;
GAHI - > setMargins ( 0 , 0 , 0 , 0 ) ;
2011-08-25 06:11:44 +00:00
gFlagsGroup * fg = new gFlagsGroup ( ) ;
2011-11-28 04:05:09 +00:00
SF - > AddLayer ( AddCPAP ( fg ) ) ;
2014-05-13 08:14:20 +00:00
// Spans
2014-05-03 08:28:05 +00:00
fg - > AddLayer ( ( new gFlagsLine ( CPAP_CSR , COLOR_CSR , STR_TR_PB , false , FT_Span ) ) ) ;
2014-05-17 05:04:40 +00:00
fg - > AddLayer ( ( new gFlagsLine ( CPAP_LargeLeak , COLOR_LargeLeak , STR_TR_LL , false , FT_Span ) ) ) ;
2014-07-28 13:56:29 +00:00
fg - > AddLayer ( ( new gFlagsLine ( CPAP_Ramp , COLOR_Ramp , schema : : channel [ CPAP_Ramp ] . label ( ) , false , FT_Span ) ) ) ;
2014-05-13 08:14:20 +00:00
// Flags
2013-09-10 15:09:09 +00:00
fg - > AddLayer ( ( new gFlagsLine ( CPAP_ClearAirway , COLOR_ClearAirway , STR_TR_CA , false ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_Obstructive , COLOR_Obstructive , STR_TR_OA , true ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_Apnea , COLOR_Apnea , STR_TR_UA ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_Hypopnea , COLOR_Hypopnea , STR_TR_H , true ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_ExP , COLOR_ExP , STR_TR_EP , false ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_LeakFlag , COLOR_LeakFlag , STR_TR_LE , false ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_NRI , COLOR_NRI , STR_TR_NRI , false ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_FlowLimit , COLOR_FlowLimit , STR_TR_FL ) ) ) ;
2014-05-15 03:51:32 +00:00
fg - > AddLayer ( ( new gFlagsLine ( CPAP_SensAwake , COLOR_SensAwake , STR_TR_SA ) ) ) ;
2013-09-10 15:09:09 +00:00
fg - > AddLayer ( ( new gFlagsLine ( CPAP_RERA , COLOR_RERA , STR_TR_RE ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_VSnore , COLOR_VibratorySnore , STR_TR_VS ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_VSnore2 , COLOR_VibratorySnore , STR_TR_VS2 ) ) ) ;
2014-07-11 12:09:38 +00:00
if ( p_profile - > cpap - > userEventFlagging ( ) ) {
2013-09-10 15:09:09 +00:00
fg - > AddLayer ( ( new gFlagsLine ( CPAP_UserFlag1 , COLOR_Yellow , STR_TR_UF1 ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_UserFlag2 , COLOR_DarkGreen , STR_TR_UF2 ) ) ) ;
fg - > AddLayer ( ( new gFlagsLine ( CPAP_UserFlag3 , COLOR_Brown , STR_TR_UF3 ) ) ) ;
2012-01-06 16:07:54 +00:00
}
2013-09-10 15:09:09 +00:00
//fg->AddLayer((new gFlagsLine(PRS1_0B,COLOR_DarkGreen,tr("U0B"))));
2011-08-25 08:02:04 +00:00
SF - > setBlockZoom ( true ) ;
2011-08-25 09:00:19 +00:00
SF - > AddLayer ( new gShadowArea ( ) ) ;
2013-10-25 10:39:30 +00:00
SF - > AddLayer ( new gFlagsLabelArea ( fg ) , LayerLeft , gYAxis : : Margin ) ;
2011-08-27 05:06:08 +00:00
//SF->AddLayer(new gFooBar(),LayerBottom,0,1);
2013-09-10 15:09:09 +00:00
SF - > AddLayer ( new gXAxis ( COLOR_Text , false ) , LayerBottom , 0 , 20 ) ; //gXAxis::Margin);
2011-08-25 06:11:44 +00:00
2014-05-13 08:14:20 +00:00
// The following list contains graphs that don't have standard xgrid/yaxis labels
QStringList skipgraph ;
skipgraph . push_back ( " EventBreakdown " ) ;
skipgraph . push_back ( " SF " ) ;
QHash < QString , gGraph * > : : iterator it ;
for ( it = graphlist . begin ( ) ; it ! = graphlist . end ( ) ; + + it ) {
if ( skipgraph . contains ( it . key ( ) ) ) continue ;
it . value ( ) - > AddLayer ( new gXGrid ( ) ) ;
}
2011-08-25 06:11:44 +00:00
gLineChart * l ;
2013-09-10 15:09:09 +00:00
l = new gLineChart ( CPAP_FlowRate , COLOR_Black , false , false ) ;
2011-12-21 11:09:50 +00:00
gLineOverlaySummary * los = new gLineOverlaySummary ( tr ( " Selection AHI " ) , 5 , - 4 ) ;
2011-08-25 06:11:44 +00:00
AddCPAP ( l ) ;
2014-05-13 08:14:20 +00:00
2014-08-03 13:00:13 +00:00
gGraph * FRW = graphlist [ schema : : channel [ CPAP_FlowRate ] . code ( ) ] ;
2014-05-13 08:14:20 +00:00
// Draw layer is important... spans first..
2014-05-03 08:28:05 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_CSR , COLOR_CSR , STR_TR_CSR , FT_Span ) ) ) ;
2014-05-17 05:04:40 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_LargeLeak , COLOR_LargeLeak , STR_TR_LL , FT_Span ) ) ) ;
2014-07-28 13:56:29 +00:00
//FRW->AddLayer(AddCPAP(new gLineOverlayBar(CPAP_Ramp, COLOR_Ramp, schema::channel[CPAP_Ramp].label(), FT_Span)));
2014-05-13 08:14:20 +00:00
// Then the graph itself
2011-08-25 06:11:44 +00:00
FRW - > AddLayer ( l ) ;
2014-05-13 08:14:20 +00:00
// Then the LineOverlaySummaries
2013-09-10 15:09:09 +00:00
FRW - > AddLayer ( AddCPAP ( los - > add ( new gLineOverlayBar ( CPAP_Hypopnea , COLOR_Hypopnea , STR_TR_H ) ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_PressurePulse , COLOR_PressurePulse , STR_TR_PP , FT_Dot ) ) ) ;
//FRW->AddLayer(AddCPAP(new gLineOverlayBar(CPAP_Pressure, COLOR_White,STR_TR_P,FT_Dot)));
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( PRS1_0B , COLOR_Blue , " 0B " , FT_Dot ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( PRS1_0E , COLOR_DarkRed , " 0E " , FT_Dot ) ) ) ;
2014-05-13 08:14:20 +00:00
gLineOverlayBar * rera = new gLineOverlayBar ( CPAP_RERA , COLOR_RERA , STR_TR_RE ) ;
2014-07-11 12:09:38 +00:00
if ( p_profile - > general - > calculateRDI ( ) ) {
2014-05-13 08:14:20 +00:00
FRW - > AddLayer ( AddCPAP ( los - > add ( rera ) ) ) ;
2014-05-03 08:28:05 +00:00
} else {
2014-05-13 08:14:20 +00:00
FRW - > AddLayer ( AddCPAP ( rera ) ) ;
2014-05-03 08:28:05 +00:00
}
2013-09-10 15:09:09 +00:00
FRW - > AddLayer ( AddCPAP ( los - > add ( new gLineOverlayBar ( CPAP_Apnea , COLOR_Apnea , STR_TR_UA ) ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_VSnore , COLOR_VibratorySnore , STR_TR_VS ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_FlowLimit , COLOR_FlowLimit , STR_TR_FL ) ) ) ;
2014-05-15 03:51:32 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_SensAwake , COLOR_SensAwake , STR_TR_SA ) ) ) ;
2013-09-10 15:09:09 +00:00
FRW - > AddLayer ( AddCPAP ( los - > add ( new gLineOverlayBar ( CPAP_Obstructive , COLOR_Obstructive , STR_TR_OA ) ) ) ) ;
FRW - > AddLayer ( AddCPAP ( los - > add ( new gLineOverlayBar ( CPAP_ClearAirway , COLOR_ClearAirway , STR_TR_CA ) ) ) ) ;
2014-07-11 12:09:38 +00:00
if ( p_profile - > cpap - > userEventFlagging ( ) ) {
2013-09-10 15:09:09 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_UserFlag1 , COLOR_Yellow , tr ( " U1 " ) , FT_Bar ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_UserFlag2 , COLOR_Orange , tr ( " U2 " ) , FT_Bar ) ) ) ;
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_UserFlag3 , COLOR_Brown , tr ( " U3 " ) , FT_Bar ) ) ) ;
2012-01-06 16:07:54 +00:00
}
2013-10-13 17:33:43 +00:00
FRW - > AddLayer ( AddCPAP ( new gLineOverlayBar ( OXI_SPO2Drop , COLOR_SPO2Drop , STR_TR_O2 ) ) ) ;
2013-09-10 15:09:09 +00:00
FRW - > AddLayer ( AddOXI ( new gLineOverlayBar ( OXI_SPO2Drop , COLOR_SPO2Drop , STR_TR_O2 ) ) ) ;
//FRW->AddLayer(AddOXI(new gLineOverlayBar(OXI_PulseChange, COLOR_PulseChange, STR_TR_PC,FT_Dot)));
2011-11-28 13:16:50 +00:00
2011-11-12 13:58:58 +00:00
FRW - > AddLayer ( AddCPAP ( los ) ) ;
2011-08-25 06:11:44 +00:00
2014-07-11 12:09:38 +00:00
bool square = p_profile - > appearance - > squareWavePlots ( ) ;
2013-09-10 15:09:09 +00:00
gLineChart * pc = new gLineChart ( CPAP_Pressure , COLOR_Pressure , square ) ;
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ CPAP_Pressure ] . code ( ) ] - > AddLayer ( AddCPAP ( pc ) ) ;
graphlist [ schema : : channel [ CPAP_Pressure ] . code ( ) ] - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_Ramp , COLOR_Ramp , schema : : channel [ CPAP_Ramp ] . label ( ) , FT_Span ) ) ) ;
2013-09-10 15:09:09 +00:00
pc - > addPlot ( CPAP_EPAP , COLOR_EPAP , square ) ;
pc - > addPlot ( CPAP_IPAPLo , COLOR_IPAPLo , square ) ;
pc - > addPlot ( CPAP_IPAP , COLOR_IPAP , square ) ;
pc - > addPlot ( CPAP_IPAPHi , COLOR_IPAPHi , square ) ;
2011-11-07 04:10:48 +00:00
2014-07-11 12:09:38 +00:00
if ( p_profile - > general - > calculateRDI ( ) ) {
2013-09-10 15:09:09 +00:00
AHI - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_RDI , COLOR_RDI , square ) ) ) ;
2012-01-10 10:00:08 +00:00
// AHI->AddLayer(AddCPAP(new AHIChart(QColor("#37a24b"))));
2011-12-24 05:55:44 +00:00
} else {
2013-09-10 15:09:09 +00:00
AHI - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_AHI , COLOR_AHI , square ) ) ) ;
2011-12-24 05:55:44 +00:00
}
2011-11-30 06:56:20 +00:00
2014-05-15 19:45:46 +00:00
// this is class wide because the leak redline can be reset in preferences..
// Better way would be having a search for linechart layers in graphlist[...]
2014-07-21 08:33:04 +00:00
gLineChart * leakchart = new gLineChart ( CPAP_Leak , COLOR_LeakTotal , square ) ;
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ CPAP_Leak ] . code ( ) ] - > AddLayer ( AddCPAP ( new gLineOverlayBar ( CPAP_LargeLeak , COLOR_LargeLeak , STR_TR_LL , FT_Span ) ) ) ;
2014-07-15 07:01:47 +00:00
2014-07-21 08:33:04 +00:00
leakchart - > addPlot ( CPAP_LeakTotal , COLOR_Leak , square ) ;
2014-05-15 19:45:46 +00:00
leakchart - > addPlot ( CPAP_MaxLeak , COLOR_MaxLeak , square ) ;
2014-05-15 21:48:53 +00:00
schema : : channel [ CPAP_Leak ] . setUpperThresholdColor ( Qt : : red ) ;
schema : : channel [ CPAP_Leak ] . setLowerThresholdColor ( Qt : : green ) ;
2014-05-15 19:45:46 +00:00
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ CPAP_Leak ] . code ( ) ] - > AddLayer ( AddCPAP ( leakchart ) ) ;
2013-09-10 15:09:09 +00:00
//LEAK->AddLayer(AddCPAP(new gLineChart(CPAP_Leak, COLOR_Leak,square)));
//LEAK->AddLayer(AddCPAP(new gLineChart(CPAP_MaxLeak, COLOR_MaxLeak,square)));
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ CPAP_Snore ] . code ( ) ] - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_Snore , COLOR_Snore , true ) ) ) ;
2012-01-09 03:43:42 +00:00
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ CPAP_PTB ] . code ( ) ] - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_PTB , COLOR_PTB , square ) ) ) ;
2014-05-15 17:56:53 +00:00
2014-05-15 19:45:46 +00:00
gLineChart * lc = nullptr ;
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ CPAP_MaskPressure ] . code ( ) ] - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_MaskPressure , COLOR_MaskPressure , false ) ) ) ;
graphlist [ schema : : channel [ CPAP_RespRate ] . code ( ) ] - > AddLayer ( AddCPAP ( lc = new gLineChart ( CPAP_RespRate , COLOR_RespRate , square ) ) ) ;
2014-04-15 13:59:24 +00:00
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ POS_Inclination ] . code ( ) ] - > AddLayer ( AddPOS ( new gLineChart ( POS_Inclination ) ) ) ;
graphlist [ schema : : channel [ POS_Orientation ] . code ( ) ] - > AddLayer ( AddPOS ( new gLineChart ( POS_Orientation ) ) ) ;
2012-01-09 03:43:42 +00:00
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ CPAP_MinuteVent ] . code ( ) ] - > AddLayer ( AddCPAP ( lc = new gLineChart ( CPAP_MinuteVent , COLOR_MinuteVent , square ) ) ) ;
2013-09-10 15:09:09 +00:00
lc - > addPlot ( CPAP_TgMV , COLOR_TgMV , square ) ;
2012-01-09 15:38:41 +00:00
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ CPAP_TidalVolume ] . code ( ) ] - > AddLayer ( AddCPAP ( lc = new gLineChart ( CPAP_TidalVolume , COLOR_TidalVolume , square ) ) ) ;
2013-09-10 15:09:09 +00:00
//lc->addPlot(CPAP_Test2,COLOR_DarkYellow,square);
2012-01-09 03:43:42 +00:00
2014-08-03 13:00:13 +00:00
//graphlist[schema::channel[CPAP_TidalVolume].code()]->AddLayer(AddCPAP(new gLineChart("TidalVolume2",COLOR_Magenta,square)));
graphlist [ schema : : channel [ CPAP_FLG ] . code ( ) ] - > AddLayer ( AddCPAP ( new gLineChart ( CPAP_FLG , COLOR_FLG , true ) ) ) ;
//graphlist[schema::channel[CPAP_RespiratoryEvent].code()]->AddLayer(AddCPAP(new gLineChart(CPAP_RespiratoryEvent,COLOR_Magenta,true)));
graphlist [ schema : : channel [ CPAP_IE ] . code ( ) ] - > AddLayer ( AddCPAP ( lc = new gLineChart ( CPAP_IE , COLOR_IE , square ) ) ) ;
graphlist [ schema : : channel [ CPAP_Te ] . code ( ) ] - > AddLayer ( AddCPAP ( lc = new gLineChart ( CPAP_Te , COLOR_Te , square ) ) ) ;
graphlist [ schema : : channel [ CPAP_Ti ] . code ( ) ] - > AddLayer ( AddCPAP ( lc = new gLineChart ( CPAP_Ti , COLOR_Ti , square ) ) ) ;
2013-09-10 15:09:09 +00:00
//lc->addPlot(CPAP_Test2,COLOR:DarkYellow,square);
2011-11-28 22:49:43 +00:00
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ ZEO_SleepStage ] . code ( ) ] - > AddLayer ( AddSTAGE ( new gLineChart ( ZEO_SleepStage , COLOR_SleepStage , true ) ) ) ;
2012-01-11 13:55:46 +00:00
2014-05-17 05:04:40 +00:00
gLineOverlaySummary * los1 = new gLineOverlaySummary ( STR_UNIT_EventsPerHour , 5 , - 4 ) ;
gLineOverlaySummary * los2 = new gLineOverlaySummary ( STR_UNIT_EventsPerHour , 5 , - 4 ) ;
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ OXI_Pulse ] . code ( ) ] - > AddLayer ( AddOXI ( los1 - > add ( new gLineOverlayBar ( OXI_PulseChange , COLOR_PulseChange , STR_TR_PC , FT_Span ) ) ) ) ;
graphlist [ schema : : channel [ OXI_Pulse ] . code ( ) ] - > AddLayer ( AddOXI ( los1 ) ) ;
graphlist [ schema : : channel [ OXI_SPO2 ] . code ( ) ] - > AddLayer ( AddOXI ( los2 - > add ( new gLineOverlayBar ( OXI_SPO2Drop , COLOR_SPO2Drop , STR_TR_O2 , FT_Span ) ) ) ) ;
graphlist [ schema : : channel [ OXI_SPO2 ] . code ( ) ] - > AddLayer ( AddOXI ( los2 ) ) ;
2011-11-28 22:49:43 +00:00
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ OXI_Pulse ] . code ( ) ] - > AddLayer ( AddOXI ( new gLineChart ( OXI_Pulse , COLOR_Pulse , square ) ) ) ;
graphlist [ schema : : channel [ OXI_SPO2 ] . code ( ) ] - > AddLayer ( AddOXI ( new gLineChart ( OXI_SPO2 , COLOR_SPO2 , true ) ) ) ;
graphlist [ schema : : channel [ OXI_Plethy ] . code ( ) ] - > AddLayer ( AddOXI ( new gLineChart ( OXI_Plethy , COLOR_Plethy , false ) ) ) ;
2011-08-26 03:26:53 +00:00
2014-05-13 08:14:20 +00:00
// Fix me
2014-05-17 05:04:40 +00:00
gLineOverlaySummary * los3 = new gLineOverlaySummary ( STR_UNIT_EventsPerHour , 5 , - 4 ) ;
2014-05-13 08:14:20 +00:00
graphlist [ " INTPULSE " ] - > AddLayer ( AddCPAP ( los3 - > add ( new gLineOverlayBar ( OXI_PulseChange , COLOR_PulseChange , STR_TR_PC , FT_Span ) ) ) ) ;
graphlist [ " INTPULSE " ] - > AddLayer ( AddCPAP ( los3 ) ) ;
graphlist [ " INTPULSE " ] - > AddLayer ( AddCPAP ( new gLineChart ( OXI_Pulse , COLOR_Pulse , square ) ) ) ;
2014-05-17 05:04:40 +00:00
gLineOverlaySummary * los4 = new gLineOverlaySummary ( STR_UNIT_EventsPerHour , 5 , - 4 ) ;
2014-05-13 08:14:20 +00:00
graphlist [ " INTSPO2 " ] - > AddLayer ( AddCPAP ( los4 - > add ( new gLineOverlayBar ( OXI_SPO2Drop , COLOR_SPO2Drop , STR_TR_O2 , FT_Span ) ) ) ) ;
graphlist [ " INTSPO2 " ] - > AddLayer ( AddCPAP ( los4 ) ) ;
graphlist [ " INTSPO2 " ] - > AddLayer ( AddCPAP ( new gLineChart ( OXI_SPO2 , COLOR_SPO2 , true ) ) ) ;
2013-10-13 17:33:43 +00:00
2014-08-03 13:00:13 +00:00
graphlist [ schema : : channel [ CPAP_PTB ] . code ( ) ] - > setForceMaxY ( 100 ) ;
graphlist [ schema : : channel [ OXI_SPO2 ] . code ( ) ] - > setForceMaxY ( 100 ) ;
2013-10-13 17:33:43 +00:00
2014-05-13 08:14:20 +00:00
for ( it = graphlist . begin ( ) ; it ! = graphlist . end ( ) ; + + it ) {
if ( skipgraph . contains ( it . key ( ) ) ) continue ;
2011-11-27 06:25:27 +00:00
2014-05-13 08:14:20 +00:00
it . value ( ) - > AddLayer ( new gYAxis ( ) , LayerLeft , gYAxis : : Margin ) ;
it . value ( ) - > AddLayer ( new gXAxis ( ) , LayerBottom , 0 , 20 ) ;
2011-08-29 11:42:40 +00:00
}
2011-08-25 06:11:44 +00:00
2014-07-11 12:09:38 +00:00
if ( p_profile - > cpap - > showLeakRedline ( ) ) {
schema : : channel [ CPAP_Leak ] . setUpperThreshold ( p_profile - > cpap - > leakRedline ( ) ) ;
2014-05-15 22:48:51 +00:00
} else {
schema : : channel [ CPAP_Leak ] . setUpperThreshold ( 0 ) ; // switch it off
}
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 ) ;
2013-09-10 15:09:09 +00:00
format . setForeground ( QBrush ( COLOR_Black , Qt : : SolidPattern ) ) ;
2011-08-26 03:26:53 +00:00
ui - > calendar - > setWeekdayTextFormat ( Qt : : Saturday , format ) ;
ui - > calendar - > setWeekdayTextFormat ( Qt : : Sunday , format ) ;
2011-11-15 21:22:08 +00:00
Qt : : DayOfWeek dow = firstDayOfWeekFromLocale ( ) ;
ui - > calendar - > setFirstDayOfWeek ( dow ) ;
2011-08-26 03:26:53 +00:00
2013-10-12 07:40:45 +00:00
ui - > tabWidget - > setCurrentWidget ( webView ) ;
2011-10-05 10:44:41 +00:00
2013-10-12 07:40:45 +00:00
webView - > settings ( ) - > setFontSize ( QWebSettings : : DefaultFontSize , QApplication : : font ( ) . pointSize ( ) ) ;
webView - > page ( ) - > setLinkDelegationPolicy ( QWebPage : : DelegateAllLinks ) ;
connect ( webView , SIGNAL ( linkClicked ( QUrl ) ) , this , SLOT ( Link_clicked ( QUrl ) ) ) ;
2011-11-27 07:41:00 +00:00
2014-07-11 12:09:38 +00:00
int ews = p_profile - > general - > eventWindowSize ( ) ;
2011-11-27 07:41:00 +00:00
ui - > evViewSlider - > setValue ( ews ) ;
ui - > evViewLCD - > display ( ews ) ;
2011-11-27 16:07:28 +00:00
GraphView - > LoadSettings ( " Daily " ) ;
2014-04-05 01:28:07 +00:00
2012-01-03 16:29:35 +00:00
icon_on = new QIcon ( " :/icons/session-on.png " ) ;
icon_off = new QIcon ( " :/icons/session-off.png " ) ;
2011-12-23 14:12:04 +00:00
ui - > splitter - > setVisible ( false ) ;
2011-12-01 06:06:13 +00:00
2014-07-11 12:09:38 +00:00
if ( p_profile - > general - > unitSystem ( ) = = US_Archiac ) {
2011-12-21 12:47:47 +00:00
ui - > weightSpinBox - > setSuffix ( STR_UNIT_POUND ) ;
2011-12-02 13:48:05 +00:00
ui - > weightSpinBox - > setDecimals ( 0 ) ;
ui - > ouncesSpinBox - > setVisible ( true ) ;
2011-12-21 12:47:47 +00:00
ui - > ouncesSpinBox - > setSuffix ( STR_UNIT_OUNCE ) ;
2011-12-21 11:09:50 +00:00
} else {
ui - > ouncesSpinBox - > setVisible ( false ) ;
ui - > weightSpinBox - > setDecimals ( 3 ) ;
2011-12-21 12:47:47 +00:00
ui - > weightSpinBox - > setSuffix ( STR_UNIT_KG ) ;
2011-12-02 13:48:05 +00:00
}
2013-09-09 15:56:02 +00:00
GraphView - > setEmptyText ( STR_TR_NoData ) ;
2012-01-25 22:34:21 +00:00
previous_date = QDate ( ) ;
2011-10-30 03:09:43 +00:00
}
2011-06-26 08:30:44 +00:00
2014-05-11 19:04:34 +00:00
2011-06-26 08:30:44 +00:00
Daily : : ~ Daily ( )
{
2013-10-12 07:40:45 +00:00
// disconnect(sessbar, SIGNAL(toggledSession(Session*)), this, SLOT(doToggleSession(Session*)));
2011-11-27 16:07:28 +00:00
2011-06-26 08:30:44 +00:00
// Save any last minute changes..
2011-08-02 10:28:29 +00:00
// delete splitter;
2011-06-26 08:30:44 +00:00
delete ui ;
2012-01-03 16:29:35 +00:00
delete icon_on ;
delete icon_off ;
2011-06-26 08:30:44 +00:00
}
2013-10-10 17:36:53 +00:00
2014-05-15 21:48:53 +00:00
void Daily : : showEvent ( QShowEvent * )
{
RedrawGraphs ( ) ;
}
2014-05-11 19:04:34 +00:00
void Daily : : closeEvent ( QCloseEvent * event )
{
2014-07-28 13:56:29 +00:00
2014-05-11 19:04:34 +00:00
disconnect ( webView , SIGNAL ( linkClicked ( QUrl ) ) , this , SLOT ( Link_clicked ( QUrl ) ) ) ;
if ( previous_date . isValid ( ) )
Unload ( previous_date ) ;
GraphView - > SaveSettings ( " Daily " ) ;
QWidget : : closeEvent ( event ) ;
2014-07-28 13:56:29 +00:00
event - > accept ( ) ;
2014-05-11 19:04:34 +00:00
}
2013-10-10 17:36:53 +00:00
void Daily : : doToggleSession ( Session * sess )
{
2013-10-26 13:59:37 +00:00
Q_UNUSED ( sess )
2014-05-25 07:07:08 +00:00
sess - > setEnabled ( ! sess - > enabled ( ) ) ;
2013-10-10 17:36:53 +00:00
// sess->StoreSummary();
2014-07-11 12:09:38 +00:00
Day * day = p_profile - > GetDay ( previous_date , MT_CPAP ) ;
2013-10-10 17:36:53 +00:00
if ( day ) {
day - > machine - > Save ( ) ;
this - > LoadDate ( previous_date ) ;
}
}
2011-12-03 08:52:24 +00:00
void Daily : : Link_clicked ( const QUrl & url )
2011-11-24 23:03:33 +00:00
{
QString code = url . toString ( ) . section ( " = " , 0 , 0 ) . toLower ( ) ;
QString data = url . toString ( ) . section ( " = " , 1 ) ;
int sid = data . toInt ( ) ;
2014-04-23 13:19:56 +00:00
Day * day = nullptr ;
2011-12-28 12:03:48 +00:00
if ( code = = " togglecpapsession " ) { // Enable/Disable CPAP session
2014-07-11 12:09:38 +00:00
day = p_profile - > GetDay ( previous_date , MT_CPAP ) ;
2011-12-27 13:21:10 +00:00
Session * sess = day - > find ( sid ) ;
if ( ! sess )
return ;
2013-10-12 07:40:45 +00:00
int i = webView - > page ( ) - > mainFrame ( ) - > scrollBarMaximum ( Qt : : Vertical ) - webView - > page ( ) - > mainFrame ( ) - > scrollBarValue ( Qt : : Vertical ) ;
2011-12-28 12:03:48 +00:00
sess - > setEnabled ( ! sess - > enabled ( ) ) ;
// Messy, this rewrites both summary & events.. TODO: Write just the session summary file
day - > machine - > Save ( ) ;
// Reload day
this - > LoadDate ( previous_date ) ;
2013-10-12 07:40:45 +00:00
webView - > page ( ) - > mainFrame ( ) - > setScrollBarValue ( Qt : : Vertical , webView - > page ( ) - > mainFrame ( ) - > scrollBarMaximum ( Qt : : Vertical ) - i ) ;
2011-12-28 12:03:48 +00:00
return ;
} else if ( code = = " toggleoxisession " ) { // Enable/Disable Oximetry session
2014-07-11 12:09:38 +00:00
day = p_profile - > GetDay ( previous_date , MT_OXIMETER ) ;
2011-12-28 12:03:48 +00:00
Session * sess = day - > find ( sid ) ;
if ( ! sess )
return ;
2013-10-12 07:40:45 +00:00
int i = webView - > page ( ) - > mainFrame ( ) - > scrollBarMaximum ( Qt : : Vertical ) - webView - > page ( ) - > mainFrame ( ) - > scrollBarValue ( Qt : : Vertical ) ;
2011-12-28 12:03:48 +00:00
sess - > setEnabled ( ! sess - > enabled ( ) ) ;
// Messy, this rewrites both summary & events.. TODO: Write just the session summary file
2011-12-27 13:21:10 +00:00
day - > machine - > Save ( ) ;
2011-12-28 12:03:48 +00:00
// Reload day
this - > LoadDate ( previous_date ) ;
2013-10-12 07:40:45 +00:00
webView - > page ( ) - > mainFrame ( ) - > setScrollBarValue ( Qt : : Vertical , webView - > page ( ) - > mainFrame ( ) - > scrollBarMaximum ( Qt : : Vertical ) - i ) ;
2011-12-27 13:21:10 +00:00
return ;
} else if ( code = = " cpap " ) {
2014-07-11 12:09:38 +00:00
day = p_profile - > GetDay ( previous_date , MT_CPAP ) ;
2011-11-24 23:03:33 +00:00
} else if ( code = = " oxi " ) {
2014-07-11 12:09:38 +00:00
//day=p_profile->GetDay(previous_date,MT_OXIMETER);
2014-07-09 03:49:20 +00:00
//Session *sess=day->machine->sessionlist[sid];
2011-12-06 14:39:14 +00:00
return ;
2011-11-24 23:03:33 +00:00
} else if ( code = = " event " ) {
2013-10-26 05:06:56 +00:00
QList < QTreeWidgetItem * > list = ui - > treeWidget - > findItems ( schema : : channel [ sid ] . fullname ( ) , Qt : : MatchContains ) ;
2011-11-24 23:03:33 +00:00
if ( list . size ( ) > 0 ) {
2011-11-24 23:14:17 +00:00
ui - > treeWidget - > collapseAll ( ) ;
ui - > treeWidget - > expandItem ( list . at ( 0 ) ) ;
QTreeWidgetItem * wi = list . at ( 0 ) - > child ( 0 ) ;
ui - > treeWidget - > setCurrentItem ( wi ) ;
2011-11-24 23:03:33 +00:00
ui - > tabWidget - > setCurrentIndex ( 1 ) ;
2011-12-03 08:52:24 +00:00
} else {
2013-10-26 05:06:56 +00:00
mainwin - > Notify ( tr ( " No %1 events are recorded this day " ) . arg ( schema : : channel [ sid ] . fullname ( ) ) , " " , 1500 ) ;
2011-11-24 23:03:33 +00:00
}
2011-12-03 03:43:23 +00:00
} else if ( code = = " graph " ) {
qDebug ( ) < < " Select graph " < < data ;
2011-11-24 23:03:33 +00:00
} else {
qDebug ( ) < < " Clicked on " < < code < < data ;
}
if ( day ) {
Session * sess = day - > machine - > sessionlist [ sid ] ;
2011-12-28 14:03:09 +00:00
if ( sess & & sess - > enabled ( ) ) {
2011-11-24 23:03:33 +00:00
GraphView - > SetXBounds ( sess - > first ( ) , sess - > last ( ) ) ;
}
}
}
2011-07-04 11:37:26 +00:00
2011-06-26 08:30:44 +00:00
void Daily : : ReloadGraphs ( )
{
2014-05-19 07:30:10 +00:00
GraphView - > setDay ( nullptr ) ;
2011-12-23 14:12:04 +00:00
ui - > splitter - > setVisible ( true ) ;
2011-12-06 14:39:14 +00:00
QDate d ;
2012-01-05 04:37:22 +00:00
2011-12-06 14:39:14 +00:00
if ( previous_date . isValid ( ) ) {
d = previous_date ;
2012-01-05 04:37:22 +00:00
// Unload(d);
}
2014-07-11 12:09:38 +00:00
d = p_profile - > LastDay ( ) ;
2011-06-26 08:30:44 +00:00
if ( ! d . isValid ( ) ) {
d = ui - > calendar - > selectedDate ( ) ;
}
on_calendar_currentPageChanged ( d . year ( ) , d . month ( ) ) ;
2012-01-05 04:37:22 +00:00
// this fires a signal which unloads the old and loads the new
2014-05-19 07:30:10 +00:00
ui - > calendar - > blockSignals ( true ) ;
2011-06-26 08:30:44 +00:00
ui - > calendar - > setSelectedDate ( d ) ;
2014-05-19 07:30:10 +00:00
ui - > calendar - > blockSignals ( false ) ;
Load ( d ) ;
2014-05-25 07:07:08 +00:00
ui - > calButton - > setText ( ui - > calendar - > selectedDate ( ) . toString ( Qt : : TextDate ) ) ;
2014-05-28 17:45:42 +00:00
graphView ( ) - > redraw ( ) ;
2011-06-26 08:30:44 +00:00
}
2014-05-19 07:30:10 +00:00
2011-06-26 08:30:44 +00:00
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 ) ;
}
}
2014-05-19 07:30:10 +00:00
2011-06-26 08:30:44 +00:00
void Daily : : UpdateEventsTree ( QTreeWidget * tree , Day * day )
{
tree - > clear ( ) ;
2011-06-27 10:55:55 +00:00
if ( ! day ) return ;
2011-06-26 08:30:44 +00:00
tree - > setColumnCount ( 1 ) ; // 1 visible common.. (1 hidden)
2014-04-23 13:19:56 +00:00
QTreeWidgetItem * root = nullptr ;
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 ;
2012-01-06 16:07:54 +00:00
bool userflags = p_profile - > cpap - > userEventFlagging ( ) ;
2012-01-19 15:18:34 +00:00
2014-07-11 12:09:38 +00:00
qint64 drift = 0 , clockdrift = p_profile - > cpap - > clockDrift ( ) * 1000L ;
2013-10-22 11:42:57 +00:00
for ( QList < Session * > : : iterator s = day - > begin ( ) ; s ! = day - > end ( ) ; + + s ) {
2011-12-28 12:03:48 +00:00
if ( ! ( * s ) - > enabled ( ) ) continue ;
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-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 )
2011-12-21 11:09:50 +00:00
& & ( code ! = CPAP_UserFlag1 )
& & ( code ! = CPAP_UserFlag2 )
2012-01-09 08:05:20 +00:00
& & ( code ! = CPAP_UserFlag3 )
2011-11-24 23:03:33 +00:00
& & ( code ! = CPAP_NRI )
& & ( code ! = CPAP_LeakFlag )
2014-05-17 05:04:40 +00:00
& & ( code ! = CPAP_LargeLeak )
2011-11-24 23:03:33 +00:00
& & ( code ! = CPAP_ExP )
2011-07-27 09:53:29 +00:00
& & ( code ! = CPAP_FlowLimit )
2014-05-15 03:51:32 +00:00
& & ( code ! = CPAP_SensAwake )
2011-07-31 20:24:43 +00:00
& & ( code ! = CPAP_PressurePulse )
2011-12-24 05:55:44 +00:00
& & ( code ! = CPAP_VSnore2 )
2011-07-27 09:53:29 +00:00
& & ( code ! = CPAP_VSnore ) ) continue ;
2012-01-06 16:07:54 +00:00
2012-01-09 08:05:20 +00:00
if ( ! userflags & & ( ( code = = CPAP_UserFlag1 ) | | ( code = = CPAP_UserFlag2 ) | | ( code = = CPAP_UserFlag3 ) ) ) continue ;
2014-07-28 13:56:29 +00:00
drift = ( ( * s ) - > machine ( ) - > type ( ) = = MT_CPAP ) ? clockdrift : 0 ;
2012-01-06 16:07:54 +00:00
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 ) ;
2012-01-14 07:41:50 +00:00
if ( ! cnt ) continue ; // If no events than don't bother showing..
2011-07-05 05:33:06 +00:00
total_events + = cnt ;
2013-10-26 05:06:56 +00:00
QString st = schema : : channel [ code ] . fullname ( ) ;
2011-06-26 08:30:44 +00:00
if ( st . isEmpty ( ) ) {
2013-10-09 15:56:46 +00:00
st = QString ( " Fixme %1 " ) . arg ( code ) ;
2011-06-26 08:30:44 +00:00
}
2011-12-21 11:09:50 +00:00
st + = " " ;
if ( cnt = = 1 ) st + = tr ( " %1 event " ) . arg ( cnt ) ;
else st + = tr ( " %1 events " ) . arg ( cnt ) ;
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 ] ;
}
2012-01-11 04:58:46 +00:00
2011-07-31 20:24:43 +00:00
for ( int z = 0 ; z < m . value ( ) . size ( ) ; z + + ) {
2012-01-11 04:58:46 +00:00
EventList & ev = * ( m . value ( ) [ z ] ) ;
for ( quint32 o = 0 ; o < ev . count ( ) ; o + + ) {
2012-01-19 15:18:34 +00:00
qint64 t = ev . time ( o ) + drift ;
2011-07-30 03:52:29 +00:00
2011-12-25 05:05:12 +00:00
if ( code = = CPAP_CSR ) { // center it in the middle of span
2012-01-11 04:58:46 +00:00
t - = float ( ev . raw ( o ) / 2.0 ) * 1000.0 ;
2011-07-27 09:21:53 +00:00
}
QStringList a ;
2014-05-31 21:25:07 +00:00
QDateTime d = QDateTime : : fromMSecsSinceEpoch ( t ) ;
2011-12-25 05:05:12 +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 ) ;
2011-12-25 05:05:12 +00:00
QTreeWidgetItem * item = new QTreeWidgetItem ( a ) ;
item - > setData ( 0 , Qt : : UserRole , t ) ;
//a.append(d.toString("yyyy-MM-dd HH:mm:ss"));
mcr - > addChild ( item ) ;
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
}
2014-05-31 21:25:07 +00:00
QTreeWidgetItem * start = new QTreeWidgetItem ( QStringList ( tr ( " Session Start Times " ) ) ) ;
QTreeWidgetItem * end = new QTreeWidgetItem ( QStringList ( tr ( " Session End Times " ) ) ) ;
tree - > insertTopLevelItem ( cnt + + , start ) ;
tree - > insertTopLevelItem ( cnt + + , end ) ;
for ( QList < Session * > : : iterator s = day - > begin ( ) ; s ! = day - > end ( ) ; + + s ) {
QDateTime st = QDateTime : : fromMSecsSinceEpoch ( ( * s ) - > first ( ) ) ;
QDateTime et = QDateTime : : fromMSecsSinceEpoch ( ( * s ) - > last ( ) ) ;
QTreeWidgetItem * item = new QTreeWidgetItem ( QStringList ( st . toString ( " HH:mm:ss " ) ) ) ;
item - > setData ( 0 , Qt : : UserRole , ( * s ) - > first ( ) ) ;
start - > addChild ( item ) ;
item = new QTreeWidgetItem ( QStringList ( et . toString ( " HH:mm:ss " ) ) ) ;
item - > setData ( 0 , Qt : : UserRole , ( * s ) - > last ( ) ) ;
end - > addChild ( item ) ;
}
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();
}
2011-12-01 06:06:13 +00:00
2011-06-26 08:30:44 +00:00
void Daily : : UpdateCalendarDay ( QDate date )
{
2011-12-11 09:45:28 +00:00
QTextCharFormat nodata ;
QTextCharFormat cpaponly ;
QTextCharFormat cpapjour ;
2011-07-03 12:08:30 +00:00
QTextCharFormat oxiday ;
2011-12-11 09:45:28 +00:00
QTextCharFormat oxicpap ;
2011-12-02 14:18:47 +00:00
QTextCharFormat jourday ;
2012-01-11 14:49:22 +00:00
QTextCharFormat stageday ;
2011-12-11 09:45:28 +00:00
2013-09-10 15:09:09 +00:00
cpaponly . setForeground ( QBrush ( COLOR_Blue , Qt : : SolidPattern ) ) ;
2011-12-11 09:45:28 +00:00
cpaponly . setFontWeight ( QFont : : Normal ) ;
2013-09-10 15:09:09 +00:00
cpapjour . setForeground ( QBrush ( COLOR_Blue , Qt : : SolidPattern ) ) ;
2011-12-11 09:45:28 +00:00
cpapjour . setFontWeight ( QFont : : Bold ) ;
2013-09-10 15:09:09 +00:00
oxiday . setForeground ( QBrush ( COLOR_Red , Qt : : SolidPattern ) ) ;
2011-12-11 09:45:28 +00:00
oxiday . setFontWeight ( QFont : : Normal ) ;
2013-09-10 15:09:09 +00:00
oxicpap . setForeground ( QBrush ( COLOR_Red , Qt : : SolidPattern ) ) ;
2011-12-11 09:45:28 +00:00
oxicpap . setFontWeight ( QFont : : Bold ) ;
2013-09-10 15:09:09 +00:00
stageday . setForeground ( QBrush ( COLOR_Magenta , Qt : : SolidPattern ) ) ;
2012-01-11 14:49:22 +00:00
stageday . setFontWeight ( QFont : : Bold ) ;
2013-09-10 15:09:09 +00:00
jourday . setForeground ( QBrush ( COLOR_Black , Qt : : SolidPattern ) ) ;
2011-12-02 14:18:47 +00:00
jourday . setFontWeight ( QFont : : Bold ) ;
2013-09-10 15:09:09 +00:00
nodata . setForeground ( QBrush ( COLOR_Black , Qt : : SolidPattern ) ) ;
2011-12-11 09:45:28 +00:00
nodata . setFontWeight ( QFont : : Normal ) ;
2011-12-02 14:18:47 +00:00
2014-07-11 12:09:38 +00:00
bool hascpap = p_profile - > GetDay ( date , MT_CPAP ) ! = nullptr ;
bool hasoxi = p_profile - > GetDay ( date , MT_OXIMETER ) ! = nullptr ;
bool hasjournal = p_profile - > GetDay ( date , MT_JOURNAL ) ! = nullptr ;
bool hasstage = p_profile - > GetDay ( date , MT_SLEEPSTAGE ) ! = nullptr ;
bool haspos = p_profile - > GetDay ( date , MT_POSITION ) ! = nullptr ;
2011-07-03 12:08:30 +00:00
if ( hascpap ) {
if ( hasoxi ) {
2011-12-11 09:45:28 +00:00
ui - > calendar - > setDateTextFormat ( date , oxicpap ) ;
2011-12-02 14:18:47 +00:00
} else if ( hasjournal ) {
2011-12-11 09:45:28 +00:00
ui - > calendar - > setDateTextFormat ( date , cpapjour ) ;
2014-04-15 13:59:24 +00:00
} else if ( hasstage | | haspos ) {
2012-01-11 14:49:22 +00:00
ui - > calendar - > setDateTextFormat ( date , stageday ) ;
2011-07-03 12:08:30 +00:00
} else {
2011-12-11 09:45:28 +00:00
ui - > calendar - > setDateTextFormat ( date , cpaponly ) ;
2011-07-03 12:08:30 +00:00
}
2011-12-11 09:45:28 +00:00
} else if ( hasoxi ) {
ui - > calendar - > setDateTextFormat ( date , oxiday ) ;
} else if ( hasjournal ) {
ui - > calendar - > setDateTextFormat ( date , jourday ) ;
2014-04-15 13:59:24 +00:00
} else if ( hasstage ) {
ui - > calendar - > setDateTextFormat ( date , oxiday ) ;
} else if ( haspos ) {
ui - > calendar - > setDateTextFormat ( date , oxiday ) ;
2011-06-26 08:30:44 +00:00
} else {
2011-12-11 09:45:28 +00:00
ui - > calendar - > setDateTextFormat ( date , nodata ) ;
2011-06-26 08:30:44 +00:00
}
ui - > calendar - > setHorizontalHeaderFormat ( QCalendarWidget : : ShortDayNames ) ;
}
2011-10-28 03:45:31 +00:00
void Daily : : LoadDate ( QDate date )
{
2014-07-25 07:53:48 +00:00
if ( ! date . isValid ( ) ) {
qDebug ( ) < < " LoadDate called with invalid date " ;
return ;
}
2011-12-26 04:58:02 +00:00
ui - > calendar - > blockSignals ( true ) ;
2011-12-26 18:26:06 +00:00
if ( date . month ( ) ! = previous_date . month ( ) ) {
on_calendar_currentPageChanged ( date . year ( ) , date . month ( ) ) ;
}
2011-10-28 03:45:31 +00:00
ui - > calendar - > setSelectedDate ( date ) ;
2011-12-26 04:58:02 +00:00
ui - > calendar - > blockSignals ( false ) ;
on_calendar_selectionChanged ( ) ;
2011-10-28 03:45:31 +00:00
}
2011-06-26 08:30:44 +00:00
void Daily : : on_calendar_selectionChanged ( )
{
2014-07-20 10:30:33 +00:00
graphView ( ) - > releaseKeyboard ( ) ;
2012-01-05 04:37:22 +00:00
QTime time ;
time_t unload_time , load_time , other_time ;
time . start ( ) ;
2011-06-26 08:30:44 +00:00
2012-01-05 04:37:22 +00:00
this - > setCursor ( Qt : : BusyCursor ) ;
2011-12-20 11:12:52 +00:00
if ( previous_date . isValid ( ) ) {
2011-12-25 16:38:37 +00:00
// GraphView->fadeOut();
2011-12-20 11:12:52 +00:00
Unload ( previous_date ) ;
}
2012-01-05 04:37:22 +00:00
unload_time = time . restart ( ) ;
2012-01-02 15:34:17 +00:00
//bool fadedir=previous_date < ui->calendar->selectedDate();
2011-12-02 11:40:47 +00:00
ZombieMeterMoved = false ;
2011-06-26 08:30:44 +00:00
Load ( ui - > calendar - > selectedDate ( ) ) ;
2012-01-05 04:37:22 +00:00
load_time = time . restart ( ) ;
2011-12-25 16:38:37 +00:00
//GraphView->fadeIn(fadedir);
2011-12-25 16:58:22 +00:00
GraphView - > redraw ( ) ;
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-12-02 13:48:05 +00:00
2014-07-11 12:09:38 +00:00
if ( p_profile - > general - > unitSystem ( ) = = US_Archiac ) {
2011-12-21 12:47:47 +00:00
ui - > weightSpinBox - > setSuffix ( STR_UNIT_POUND ) ;
2011-12-02 13:48:05 +00:00
ui - > weightSpinBox - > setDecimals ( 0 ) ;
ui - > ouncesSpinBox - > setVisible ( true ) ;
2011-12-21 12:47:47 +00:00
ui - > ouncesSpinBox - > setSuffix ( STR_UNIT_OUNCE ) ;
2011-12-21 11:09:50 +00:00
} else {
ui - > ouncesSpinBox - > setVisible ( false ) ;
ui - > weightSpinBox - > setDecimals ( 3 ) ;
2011-12-21 12:47:47 +00:00
ui - > weightSpinBox - > setSuffix ( STR_UNIT_KG ) ;
2011-12-02 13:48:05 +00:00
}
2011-12-25 16:38:37 +00:00
this - > setCursor ( Qt : : ArrowCursor ) ;
2012-01-05 04:37:22 +00:00
other_time = time . restart ( ) ;
qDebug ( ) < < " Page change time (in ms): Unload = " < < unload_time < < " Load = " < < load_time < < " Other = " < < other_time ;
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-07-28 14:20:59 +00:00
}
2011-12-03 08:52:24 +00:00
void Daily : : graphtogglebutton_toggled ( bool b )
2011-12-01 06:06:13 +00:00
{
2011-12-03 08:52:24 +00:00
Q_UNUSED ( b )
2011-12-01 06:06:13 +00:00
for ( int i = 0 ; i < GraphView - > size ( ) ; i + + ) {
QString title = ( * GraphView ) [ i ] - > title ( ) ;
( * GraphView ) [ i ] - > setVisible ( GraphToggles [ title ] - > isChecked ( ) ) ;
}
GraphView - > updateScale ( ) ;
2011-12-20 11:12:52 +00:00
GraphView - > redraw ( ) ;
2011-12-01 06:06:13 +00:00
}
2013-10-12 07:40:45 +00:00
MyWebPage : : MyWebPage ( QObject * parent ) :
QWebPage ( parent )
{
// Enable plugin support
settings ( ) - > setAttribute ( QWebSettings : : PluginsEnabled , true ) ;
}
QObject * MyWebPage : : createPlugin ( const QString & classid , const QUrl & url , const QStringList & paramNames , const QStringList & paramValues )
{
Q_UNUSED ( paramNames )
Q_UNUSED ( paramValues )
2013-10-26 13:59:37 +00:00
Q_UNUSED ( url )
2013-10-13 06:27:55 +00:00
2013-10-12 07:40:45 +00:00
if ( classid = = " SessionBar " ) {
return mainwin - > getDaily ( ) - > sessionBar ( ) ;
}
2013-10-13 06:27:55 +00:00
qDebug ( ) < < " Request for unknown MyWebPage plugin " ;
return new QWidget ( ) ;
2013-10-12 07:40:45 +00:00
}
MyWebView : : MyWebView ( QWidget * parent ) :
QWebView ( parent ) ,
m_page ( this )
{
// Set the page of our own PageView class, MyPageView,
// because only objects of this class will handle
// object-tags correctly.
setPage ( & m_page ) ;
}
2014-04-15 13:59:24 +00:00
QString Daily : : getSessionInformation ( Day * cpap , Day * oxi , Day * stage , Day * posit )
2013-10-13 16:35:53 +00:00
{
QString html ;
QList < Day * > list ;
if ( cpap ) list . push_back ( cpap ) ;
if ( oxi ) list . push_back ( oxi ) ;
if ( stage ) list . push_back ( stage ) ;
2014-04-15 13:59:24 +00:00
if ( posit ) list . push_back ( posit ) ;
2013-10-13 16:35:53 +00:00
if ( list . isEmpty ( ) )
return html ;
html = " <table cellpadding=0 cellspacing=0 border=0 width=100%> " ;
html + = QString ( " <tr><td colspan=5 align=center><b> " + tr ( " Session Information " ) + " </b></td></tr> " ) ;
html + = " <tr><td colspan=5 align=center> </td></tr> " ;
QFontMetrics FM ( * defaultfont ) ;
QRect r = FM . boundingRect ( ' @ ' ) ;
if ( cpap ) {
html + = QString ( " <tr><td colspan=5 align=center> "
" <object type= \" application/x-qt-plugin \" classid= \" SessionBar \" name= \" sessbar \" height=%1 width=100%></object> "
// "<script>"
// "sessbar.show();"
// "</script>"
" </td></tr> " ) . arg ( r . height ( ) * 3 , 0 , 10 ) ;
html + = " <tr><td colspan=5 align=center> </td></tr> " ;
}
QDateTime fd , ld ;
bool corrupted_waveform = false ;
QString tooltip ;
2014-06-02 02:56:22 +00:00
html + = QString ( " <tr> "
" <td><b> " + STR_TR_On + " </b></td> "
" <td align=center><b> " + STR_TR_Date + " </b></td> "
" <td align=center><b> " + STR_TR_Start + " </b></td> "
" <td align=center><b> " + STR_TR_End + " </b></td> "
" <td align=left><b> " + tr ( " Duration " ) + " </b></td></tr> " ) ;
2013-10-13 16:35:53 +00:00
QList < Day * > : : iterator di ;
QString type ;
for ( di = list . begin ( ) ; di ! = list . end ( ) ; di + + ) {
Day * day = * di ;
html + = " <tr><td align=left colspan=5><i> " ;
switch ( day - > machine_type ( ) ) {
case MT_CPAP : type = " cpap " ;
html + = tr ( " CPAP Sessions " ) ;
break ;
case MT_OXIMETER : type = " oxi " ;
html + = tr ( " Oximetery Sessions " ) ;
break ;
case MT_SLEEPSTAGE : type = " stage " ;
html + = tr ( " Sleep Stage Sessions " ) ;
break ;
2014-04-15 13:59:24 +00:00
case MT_POSITION : type = " stage " ;
html + = tr ( " Position Sensor Sessions " ) ;
break ;
2013-10-13 16:35:53 +00:00
default :
type = " unknown " ;
html + = tr ( " Unknown Session " ) ;
break ;
}
html + = " </i></td></tr> \n " ;
2013-10-22 11:42:57 +00:00
for ( QList < Session * > : : iterator s = day - > begin ( ) ; s ! = day - > end ( ) ; + + s ) {
2013-10-13 16:35:53 +00:00
if ( ( day - > machine_type ( ) = = MT_CPAP ) & &
( ( * s ) - > settings . find ( CPAP_BrokenWaveform ) ! = ( * s ) - > settings . end ( ) ) )
corrupted_waveform = true ;
fd = QDateTime : : fromTime_t ( ( * s ) - > first ( ) / 1000L ) ;
ld = QDateTime : : fromTime_t ( ( * s ) - > last ( ) / 1000L ) ;
int len = ( * s ) - > length ( ) / 1000L ;
int h = len / 3600 ;
int m = ( len / 60 ) % 60 ;
int s1 = len % 60 ;
2014-07-28 13:56:29 +00:00
tooltip = day - > machine - > loaderName ( ) + QString ( " :#%1 " ) . arg ( ( * s ) - > session ( ) , 8 , 10 , QChar ( ' 0 ' ) ) ;
2014-06-02 02:56:22 +00:00
# define DEBUG_SESSIONS
# ifdef DEBUG_SESSIONS
tooltip + = " " + QString : : number ( len ) + " s " ;
# endif
2013-10-13 16:35:53 +00:00
// tooltip needs to lookup language.. :-/
Session * sess = * s ;
if ( ! sess - > settings . contains ( SESSION_ENABLED ) ) {
sess - > settings [ SESSION_ENABLED ] = true ;
}
bool b = sess - > settings [ SESSION_ENABLED ] . toBool ( ) ;
2013-11-19 13:37:02 +00:00
html + = QString ( " <tr> "
2013-10-13 16:35:53 +00:00
" <td width=26><a href='toggle " + type + " session=%1'> "
2014-06-02 02:56:22 +00:00
" <img src='qrc:/icons/session-%4.png' width=24px></a></td> "
" <td align=center>%5</td> "
" <td align=center>%6</td> "
" <td align=center>%7</td> "
" <td align=left><a class=info href=' " + type + " =%1'>%3<span>%2</span></a></td> "
" </tr> " )
2013-10-13 16:35:53 +00:00
. arg ( ( * s ) - > session ( ) )
. arg ( tooltip )
. arg ( QString ( " %1h %2m %3s " ) . arg ( h , 2 , 10 , QChar ( ' 0 ' ) ) . arg ( m , 2 , 10 , QChar ( ' 0 ' ) ) . arg ( s1 , 2 , 10 , QChar ( ' 0 ' ) ) )
. arg ( ( b ? " on " : " off " ) )
. arg ( fd . date ( ) . toString ( Qt : : SystemLocaleShortDate ) )
. arg ( fd . toString ( " HH:mm " ) )
. arg ( ld . toString ( " HH:mm " ) ) ;
}
}
if ( corrupted_waveform ) {
html + = QString ( " <tr><td colspan=5 align=center><i>%1</i></td></tr> " ) . arg ( tr ( " One or more waveform record for this session had faulty source data. Some waveform overlay points may not match up correctly. " ) ) ;
}
html + = " </table> " ;
return html ;
}
QString Daily : : getMachineSettings ( Day * cpap ) {
QString html ;
if ( cpap & & cpap - > hasEnabledSessions ( ) ) {
html = " <table cellpadding=0 cellspacing=0 border=0 width=100%> " ;
html + = QString ( " <tr><td colspan=5 align=center><b>%1</b></td></tr> " ) . arg ( tr ( " Machine Settings " ) ) ;
html + = " <tr><td colspan=5> </td></tr> " ;
2014-07-02 14:32:01 +00:00
if ( ( cpap & & cpap - > settingExists ( CPAP_BrokenSummary ) ) ) {
html + = " <tr><td colspan=5 align=center><i> " + tr ( " Machine Settings Unavailable " ) + " </i></td></tr></table><hr/> \n " ;
return html ;
}
2014-08-03 13:00:13 +00:00
ChannelID pr_level_chan = NoChannel ;
ChannelID pr_mode_chan = NoChannel ;
CPAPLoader * loader = dynamic_cast < CPAPLoader * > ( cpap - > machine - > loader ( ) ) ;
if ( loader ) {
pr_level_chan = loader - > PresReliefLevel ( ) ;
pr_mode_chan = loader - > PresReliefMode ( ) ;
}
2014-07-06 00:22:50 +00:00
2014-08-03 13:00:13 +00:00
if ( ( pr_level_chan ! = NoChannel ) & & ( cpap - > settingExists ( pr_level_chan ) ) ) {
QString flexstr = cpap - > getPressureRelief ( ) ;
2014-07-06 00:22:50 +00:00
2013-11-19 04:42:10 +00:00
html + = QString ( " <tr><td><a class='info' href='#'>%1<span>%2</span></a></td><td colspan=4>%3</td></tr> " )
2014-08-03 13:00:13 +00:00
. arg ( schema : : channel [ pr_mode_chan ] . label ( ) )
. arg ( schema : : channel [ pr_mode_chan ] . description ( ) )
2013-11-19 04:42:10 +00:00
. arg ( flexstr ) ;
}
2014-08-03 13:00:13 +00:00
2014-07-28 13:56:29 +00:00
QString mclass = cpap - > machine - > loaderName ( ) ;
2013-10-13 16:35:53 +00:00
if ( mclass = = STR_MACH_PRS1 | | mclass = = STR_MACH_FPIcon ) {
int humid = round ( cpap - > settings_wavg ( CPAP_HumidSetting ) ) ;
html + = QString ( " <tr><td><a class='info' href='#'> " + STR_TR_Humidifier + " <span>%1</span></a></td><td colspan=4>%2</td></tr> " )
. arg ( schema : : channel [ CPAP_HumidSetting ] . description ( ) )
. arg ( humid = = 0 ? STR_GEN_Off : " x " + QString : : number ( humid ) ) ;
}
html + = " </table> " ;
html + = " <hr/> \n " ;
}
return html ;
}
QString Daily : : getOximeterInformation ( Day * oxi )
{
QString html ;
if ( oxi & & oxi - > hasEnabledSessions ( ) ) {
html = " <table cellpadding=0 cellspacing=0 border=0 width=100%> " ;
html + = QString ( " <tr><td colspan=5 align=center><b>%1</b></td></tr> \n " ) . arg ( tr ( " Oximeter Information " ) ) ;
html + = " <tr><td colspan=5 align=center> </td></tr> " ;
2014-07-30 20:25:06 +00:00
html + = " <tr><td colspan=5 align=center> " + oxi - > machine - > brand ( ) + " " + oxi - > machine - > series ( ) + " </td></tr> \n " ;
2013-10-13 16:35:53 +00:00
html + = " <tr><td colspan=5 align=center> </td></tr> " ;
2014-05-27 17:43:28 +00:00
html + = QString ( " <tr><td colspan=5 align=center>%1: %2 (%3%)</td></tr> " ) . arg ( tr ( " SpO2 Desaturations " ) ) . arg ( oxi - > count ( OXI_SPO2Drop ) ) . arg ( ( 100.0 / oxi - > hours ( ) ) * ( oxi - > sum ( OXI_SPO2Drop ) / 3600.0 ) , 0 , ' f ' , 2 ) ;
html + = QString ( " <tr><td colspan=5 align=center>%1: %2 (%3%)</td></tr> " ) . arg ( tr ( " Pulse Change events " ) ) . arg ( oxi - > count ( OXI_PulseChange ) ) . arg ( ( 100.0 / oxi - > hours ( ) ) * ( oxi - > sum ( OXI_PulseChange ) / 3600.0 ) , 0 , ' f ' , 2 ) ;
html + = QString ( " <tr><td colspan=5 align=center>%1: %2%</td></tr> " ) . arg ( tr ( " SpO2 Baseline Used " ) ) . arg ( oxi - > settings_wavg ( OXI_SPO2Drop ) , 0 , ' f ' , 2 ) ; // CHECKME: Should this value be wavg OXI_SPO2 isntead?
2013-10-13 16:35:53 +00:00
html + = " </table> \n " ;
html + = " <hr/> \n " ;
}
return html ;
}
QString Daily : : getCPAPInformation ( Day * cpap )
{
QString html ;
if ( ! cpap )
return html ;
2014-07-28 13:56:29 +00:00
MachineInfo info = cpap - > machine - > getInfo ( ) ;
2013-10-13 16:35:53 +00:00
html = " <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
2014-07-30 20:25:06 +00:00
html + = " <tr><td align=center><a class=info2 href='#'> " + info . series + " " + info . model + " <span> " ;
2014-07-28 13:56:29 +00:00
QString tooltip = ( info . brand + " \n " + info . series + " " + info . modelnumber + " \n " + info . serial ) ;
2013-10-13 16:35:53 +00:00
tooltip = tooltip . replace ( " " , " " ) ;
html + = tooltip ;
html + = " </span></td></tr> \n " ;
2014-07-25 07:53:48 +00:00
//CPAPMode mode=(CPAPMode)(int)cpap->settings_max(CPAP_Mode);
2014-07-28 17:10:26 +00:00
html + = " <tr><td align=center> " ;
2013-11-19 04:42:10 +00:00
2014-07-25 07:53:48 +00:00
html + = tr ( " PAP Mode: %1<br/> " ) . arg ( cpap - > getCPAPMode ( ) ) ;
html + = cpap - > getPressureSettings ( ) ;
2013-11-19 04:42:10 +00:00
html + = " </td></tr> \n " ;
2014-07-02 14:32:01 +00:00
if ( ( cpap & & cpap - > settingExists ( CPAP_BrokenSummary ) ) ) {
2014-07-28 17:10:26 +00:00
html + = " <tr><td> </td></tr> \n " ;
html + = QString ( " <tr><td colspan=2><i>%1</i></td></tr> " ) . arg ( " <b> " + STR_MessageBox_PleaseNote + " :</b> " + tr ( " This day has missing pressure, mode and settings data. " ) ) ;
2014-07-02 14:32:01 +00:00
}
2013-10-13 16:35:53 +00:00
html + = " </table> \n " ;
2013-11-19 04:42:10 +00:00
html + = " <hr/> \n " ;
2013-10-13 16:35:53 +00:00
return html ;
}
2014-04-15 13:59:24 +00:00
QString Daily : : getStatisticsInfo ( Day * cpap , Day * oxi , Day * pos )
2013-10-13 16:35:53 +00:00
{
QList < Day * > list ;
list . push_back ( cpap ) ;
list . push_back ( oxi ) ;
2014-04-15 13:59:24 +00:00
list . push_back ( pos ) ;
2013-10-13 16:35:53 +00:00
2014-07-11 12:09:38 +00:00
int mididx = p_profile - > general - > prefCalcMiddle ( ) ;
2013-10-13 16:35:53 +00:00
SummaryType ST_mid ;
if ( mididx = = 0 ) ST_mid = ST_PERC ;
if ( mididx = = 1 ) ST_mid = ST_WAVG ;
if ( mididx = = 2 ) ST_mid = ST_AVG ;
2014-07-11 12:09:38 +00:00
float percentile = p_profile - > general - > prefCalcPercentile ( ) / 100.0 ;
2013-10-13 16:35:53 +00:00
2014-07-11 12:09:38 +00:00
SummaryType ST_max = p_profile - > general - > prefCalcMax ( ) ? ST_PERC : ST_MAX ;
2013-10-13 16:35:53 +00:00
const EventDataType maxperc = 0.995F ;
QString midname ;
2014-05-17 08:34:16 +00:00
if ( ST_mid = = ST_WAVG ) midname = STR_TR_WAvg ;
else if ( ST_mid = = ST_AVG ) midname = STR_TR_Avg ;
else if ( ST_mid = = ST_PERC ) midname = STR_TR_Med ;
2013-10-13 16:35:53 +00:00
QString html ;
html + = " <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
html + = QString ( " <tr><td colspan=5 align=center><b>%1</b></td></tr> \n " ) . arg ( tr ( " Statistics " ) ) ;
html + = QString ( " <tr><td><b>%1</b></td><td><b>%2</b></td><td><b>%3</b></td><td><b>%4</b></td><td><b>%5</b></td></tr> " )
. arg ( STR_TR_Channel )
. arg ( STR_TR_Min )
. arg ( midname )
2014-05-17 08:34:16 +00:00
. arg ( tr ( " %1%2 " ) . arg ( percentile * 100 , 0 , ' f ' , 0 ) . arg ( STR_UNIT_Percentage ) )
2013-10-13 16:35:53 +00:00
. arg ( STR_TR_Max ) ;
ChannelID chans [ ] = {
CPAP_Pressure , CPAP_EPAP , CPAP_IPAP , CPAP_PS , CPAP_PTB ,
CPAP_MinuteVent , CPAP_RespRate , CPAP_RespEvent , CPAP_FLG ,
CPAP_Leak , CPAP_LeakTotal , CPAP_Snore , CPAP_IE , CPAP_Ti , CPAP_Te , CPAP_TgMV ,
2014-04-15 13:59:24 +00:00
CPAP_TidalVolume , OXI_Pulse , OXI_SPO2 , POS_Inclination , POS_Orientation
2013-10-13 16:35:53 +00:00
} ;
int numchans = sizeof ( chans ) / sizeof ( ChannelID ) ;
int ccnt = 0 ;
EventDataType tmp , med , perc , mx , mn ;
QList < Day * > : : iterator di ;
for ( di = list . begin ( ) ; di ! = list . end ( ) ; di + + ) {
Day * day = * di ;
if ( ! day )
continue ;
for ( int i = 0 ; i < numchans ; i + + ) {
ChannelID code = chans [ i ] ;
if ( ! day - > channelHasData ( code ) )
continue ;
QString tooltip = schema : : channel [ code ] . description ( ) ;
if ( ! schema : : channel [ code ] . units ( ) . isEmpty ( ) ) tooltip + = " ( " + schema : : channel [ code ] . units ( ) + " ) " ;
2014-05-06 02:19:26 +00:00
if ( ST_max = = ST_MAX ) {
2013-10-13 16:35:53 +00:00
mx = day - > Max ( code ) ;
} else {
mx = day - > percentile ( code , maxperc ) ;
}
mn = day - > Min ( code ) ;
perc = day - > percentile ( code , percentile ) ;
2014-05-17 08:34:16 +00:00
if ( ST_mid = = ST_PERC ) {
2013-10-13 16:35:53 +00:00
med = day - > percentile ( code , 0.5 ) ;
tmp = day - > wavg ( code ) ;
if ( tmp > 0 | | mx = = 0 ) {
tooltip + = QString ( " <br/> " + STR_TR_WAvg + " : %1 " ) . arg ( tmp , 0 , ' f ' , 2 ) ;
}
2014-05-17 08:34:16 +00:00
} else if ( ST_mid = = ST_WAVG ) {
2013-10-13 16:35:53 +00:00
med = day - > wavg ( code ) ;
tmp = day - > percentile ( code , 0.5 ) ;
if ( tmp > 0 | | mx = = 0 ) {
tooltip + = QString ( " <br/> " + STR_TR_Median + " : %1 " ) . arg ( tmp , 0 , ' f ' , 2 ) ;
}
2014-05-17 08:34:16 +00:00
} else if ( ST_mid = = ST_AVG ) {
2013-10-13 16:35:53 +00:00
med = day - > avg ( code ) ;
tmp = day - > percentile ( code , 0.5 ) ;
if ( tmp > 0 | | mx = = 0 ) {
tooltip + = QString ( " <br/> " + STR_TR_Median + " : %1 " ) . arg ( tmp , 0 , ' f ' , 2 ) ;
}
}
html + = QString ( " <tr><td align=left class='info' onmouseover= \" style.color='blue'; \" onmouseout= \" style.color=' " + COLOR_Text . name ( ) + " '; \" >%1<span>%6</span></td><td>%2</td><td>%3</td><td>%4</td><td>%5</td></tr> " )
. arg ( schema : : channel [ code ] . label ( ) )
. arg ( mn , 0 , ' f ' , 2 )
. arg ( med , 0 , ' f ' , 2 )
. arg ( perc , 0 , ' f ' , 2 )
. arg ( mx , 0 , ' f ' , 2 )
. arg ( tooltip ) ;
ccnt + + ;
}
}
2014-07-02 14:32:01 +00:00
2014-07-02 11:58:36 +00:00
if ( GraphView - > isEmpty ( ) & & ( ( ccnt > 0 ) | | ( cpap & & cpap - > summaryOnly ( ) ) ) ) {
2013-10-13 16:35:53 +00:00
html + = " <tr><td colspan=5> </td></tr> \n " ;
2014-05-17 05:04:40 +00:00
html + = QString ( " <tr><td colspan=5 align=center><i>%1</i></td></tr> " ) . arg ( " <b> " + STR_MessageBox_PleaseNote + " </b> " + tr ( " This day just contains summary data, only limited information is available . " ) ) ;
2014-07-28 13:56:29 +00:00
} else if ( cpap & & p_profile - > cpap - > showLeakRedline ( ) ) {
2014-07-11 12:09:38 +00:00
float rlt = cpap - > timeAboveThreshold ( CPAP_Leak , p_profile - > cpap - > leakRedline ( ) ) / 60.0 ;
2014-05-15 20:48:05 +00:00
float pc = 100.0 / cpap - > hours ( ) * rlt ;
html + = " <tr><td colspan=5> </td></tr> " ;
html + = " <tr><td colspan=3 align='left' bgcolor='white'><b> " + tr ( " Time over leak redline " ) +
QString ( " </b></td><td colspan=2 bgcolor='white'>%1%</td></tr> " ) . arg ( pc , 0 , ' f ' , 3 ) ;
}
2014-07-28 13:56:29 +00:00
if ( cpap ) {
2014-07-30 20:25:06 +00:00
int l = cpap - > sum ( CPAP_Ramp ) ;
2014-07-30 17:14:28 +00:00
if ( l > 0 ) {
2014-07-30 20:25:06 +00:00
html + = " <tr><td colspan=3 align='left' bgcolor='white'> " + tr ( " Total ramp time " ) +
QString ( " </td><td colspan=2 bgcolor='white'>%1:%2:%3</td></tr> " ) . arg ( l / 3600 , 2 , 10 , QChar ( ' 0 ' ) ) . arg ( ( l / 60 ) % 60 , 2 , 10 , QChar ( ' 0 ' ) ) . arg ( l % 60 , 2 , 10 , QChar ( ' 0 ' ) ) ;
2014-07-30 17:14:28 +00:00
float v = ( cpap - > hours ( ) - ( float ( l ) / 3600.0 ) ) ;
int q = v * 3600.0 ;
2014-07-30 20:25:06 +00:00
html + = " <tr><td colspan=3 align='left' bgcolor='white'> " + tr ( " Time outside of ramp " ) +
QString ( " </td><td colspan=2 bgcolor='white'>%1:%2:%3</td></tr> " ) . arg ( q / 3600 , 2 , 10 , QChar ( ' 0 ' ) ) . arg ( ( q / 60 ) % 60 , 2 , 10 , QChar ( ' 0 ' ) ) . arg ( q % 60 , 2 , 10 , QChar ( ' 0 ' ) ) ;
2014-07-30 17:14:28 +00:00
EventDataType hc = cpap - > count ( CPAP_Hypopnea ) - cpap - > countInsideSpan ( CPAP_Ramp , CPAP_Hypopnea ) ;
EventDataType oc = cpap - > count ( CPAP_Obstructive ) - cpap - > countInsideSpan ( CPAP_Ramp , CPAP_Obstructive ) ;
EventDataType tc = cpap - > count ( CPAP_Hypopnea ) + cpap - > count ( CPAP_Obstructive ) ;
2014-07-30 20:25:06 +00:00
EventDataType ahi = ( hc + oc ) / v ;
html + = " <tr><td colspan=3 align='left' bgcolor='white'> " + tr ( " AHI excluding ramp " ) +
QString ( " </td><td colspan=2 bgcolor='white'>%1</td></tr> " ) . arg ( ahi , 0 , ' f ' , 2 ) ;
2014-07-28 17:10:26 +00:00
}
2014-07-28 13:56:29 +00:00
}
2013-10-13 16:35:53 +00:00
html + = " </table> \n " ;
html + = " <hr/> \n " ;
return html ;
}
QString Daily : : getEventBreakdown ( Day * cpap )
2011-06-26 08:30:44 +00:00
{
2013-10-26 13:59:37 +00:00
Q_UNUSED ( cpap )
2013-10-13 16:35:53 +00:00
QString html ;
html + = " <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
html + = " </table> " ;
return html ;
}
QString Daily : : getSleepTime ( Day * cpap , Day * oxi )
{
QString html ;
2014-04-23 13:19:56 +00:00
Day * day = nullptr ;
2013-10-13 16:35:53 +00:00
if ( cpap & & cpap - > hours ( ) > 0 )
day = cpap ;
else if ( oxi & & oxi - > hours ( ) > 0 )
day = oxi ;
else
return html ;
html + = " <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
html + = " <tr><td align='center'><b> " + STR_TR_Date + " </b></td><td align='center'><b> " + tr ( " Sleep " ) + " </b></td><td align='center'><b> " + tr ( " Wake " ) + " </b></td><td align='center'><b> " + STR_UNIT_Hours + " </b></td></tr> " ;
int tt = qint64 ( day - > total_time ( ) ) / 1000L ;
QDateTime date = QDateTime : : fromTime_t ( day - > first ( ) / 1000L ) ;
QDateTime date2 = QDateTime : : fromTime_t ( day - > last ( ) / 1000L ) ;
int h = tt / 3600 ;
int m = ( tt / 60 ) % 60 ;
int s = tt % 60 ;
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 " )
. arg ( date . date ( ) . toString ( Qt : : SystemLocaleShortDate ) )
. arg ( date . toString ( " HH:mm " ) )
. arg ( date2 . toString ( " HH:mm " ) )
. arg ( QString ( ) . sprintf ( " %02i:%02i:%02i " , h , m , s ) ) ;
html + = " </table> \n " ;
// html+="<hr/>";
return html ;
}
2013-10-13 10:13:14 +00:00
2013-10-13 16:35:53 +00:00
void Daily : : Load ( QDate date )
{
2013-10-12 08:07:57 +00:00
dateDisplay - > setText ( " <i> " + date . toString ( Qt : : SystemLocaleLongDate ) + " </i> " ) ;
2011-06-26 08:30:44 +00:00
previous_date = date ;
2014-07-11 12:09:38 +00:00
Day * cpap = p_profile - > GetDay ( date , MT_CPAP ) ;
Day * oxi = p_profile - > GetDay ( date , MT_OXIMETER ) ;
Day * stage = p_profile - > GetDay ( date , MT_SLEEPSTAGE ) ;
Day * posit = p_profile - > GetDay ( date , MT_POSITION ) ;
2011-06-26 08:30:44 +00:00
2014-07-11 12:09:38 +00:00
if ( ! p_profile - > session - > cacheSessions ( ) ) {
2013-10-22 11:42:57 +00:00
// Getting trashed on purge last day...
2014-05-18 17:06:58 +00:00
// lastcpapday can get purged and be invalid
2011-07-28 07:32:02 +00:00
if ( lastcpapday & & ( lastcpapday ! = cpap ) ) {
2013-10-22 11:42:57 +00:00
for ( QList < 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
}
}
2011-12-03 08:52:24 +00:00
2011-12-28 14:03:09 +00:00
if ( ( cpap & & oxi ) & & oxi - > hasEnabledSessions ( ) ) {
2011-12-25 05:05:12 +00:00
int gr ;
if ( qAbs ( cpap - > first ( ) - oxi - > first ( ) ) > 30000 ) {
2014-04-09 05:00:34 +00:00
mainwin - > Notify ( tr ( " Oximetry data exists for this day, but its timestamps are too different, so the Graphs will not be linked. " ) , " " , 3000 ) ;
2011-12-25 05:05:12 +00:00
gr = 1 ;
} else
gr = 0 ;
2014-07-16 17:12:52 +00:00
( * GraphView ) [ schema : : channel [ OXI_Pulse ] . code ( ) ] - > setGroup ( gr ) ;
( * GraphView ) [ schema : : channel [ OXI_SPO2 ] . code ( ) ] - > setGroup ( gr ) ;
( * GraphView ) [ schema : : channel [ OXI_Plethy ] . code ( ) ] - > setGroup ( gr ) ;
2011-12-03 08:52:24 +00:00
}
2011-07-27 10:47:50 +00:00
lastcpapday = cpap ;
2011-12-10 15:50:40 +00:00
2011-11-24 23:03:33 +00:00
QString html = " <html><head><style type='text/css'> "
2011-12-10 15:50:40 +00:00
" p,a,td,body { font-family: ' " + QApplication : : font ( ) . family ( ) + " '; } "
" p,a,td,body { font-size: " + QString : : number ( QApplication : : font ( ) . pointSize ( ) + 2 ) + " px; } "
2011-11-24 23:03:33 +00:00
" </style> "
2011-12-28 23:46:45 +00:00
" <link rel='stylesheet' type='text/css' href='qrc:/docs/tooltips.css' /> "
2011-12-07 12:23:19 +00:00
" <script language='javascript'><!-- "
" func dosession(sessid) { "
" "
" } "
" --></script> "
2011-07-05 05:33:06 +00:00
" </head> "
2013-10-13 16:35:53 +00:00
" <body leftmargin=0 rightmargin=0 topmargin=0 marginwidth=0 marginheight=0> " ;
2011-06-26 08:30:44 +00:00
QString tmp ;
2012-01-06 16:07:54 +00:00
2011-07-28 12:13:28 +00:00
UpdateOXIGraphs ( oxi ) ;
2011-07-22 13:46:17 +00:00
UpdateCPAPGraphs ( cpap ) ;
2012-01-11 13:55:46 +00:00
UpdateSTAGEGraphs ( stage ) ;
2014-04-15 13:59:24 +00:00
UpdatePOSGraphs ( posit ) ;
2011-07-28 12:13:28 +00:00
UpdateEventsTree ( ui - > treeWidget , cpap ) ;
2011-12-22 10:29:12 +00:00
2014-04-28 03:27:33 +00:00
// FIXME:
// Generating entire statistics because bookmarks may have changed.. (This updates the side panel too)
mainwin - > GenerateStatistics ( ) ;
2011-12-22 10:29:12 +00:00
2011-09-21 14:10:10 +00:00
snapGV - > setDay ( cpap ) ;
2012-01-06 05:22:13 +00:00
2011-12-20 11:12:52 +00:00
GraphView - > ResetBounds ( false ) ;
2011-08-25 06:11:44 +00:00
2011-07-28 12:13:28 +00:00
if ( ! cpap & & ! oxi ) {
2011-08-25 06:11:44 +00:00
scrollbar - > hide ( ) ;
2011-07-27 09:21:53 +00:00
} else {
2011-08-25 06:11:44 +00:00
scrollbar - > show ( ) ;
2011-07-27 09:21:53 +00:00
}
2011-12-01 06:06:13 +00:00
2012-01-06 05:22:13 +00:00
QString modestr ;
2011-06-26 08:30:44 +00:00
CPAPMode mode = MODE_UNKNOWN ;
QString a ;
2011-12-10 12:14:48 +00:00
bool isBrick = false ;
2011-12-23 10:52:31 +00:00
2012-01-03 16:29:35 +00:00
updateGraphCombo ( ) ;
2013-10-13 16:35:53 +00:00
2011-06-26 08:30:44 +00:00
if ( cpap ) {
2012-01-11 04:58:46 +00:00
float hours = cpap - > hours ( ) ;
if ( GraphView - > isEmpty ( ) & & ( hours > 0 ) ) {
2014-07-11 12:09:38 +00:00
if ( ! p_profile - > hasChannel ( CPAP_Obstructive ) & & ! p_profile - > hasChannel ( CPAP_Hypopnea ) ) {
2011-12-30 23:02:45 +00:00
GraphView - > setEmptyText ( tr ( " No Graphs :( " ) ) ;
2011-12-22 10:29:12 +00:00
2011-12-30 23:02:45 +00:00
isBrick = true ;
}
2011-12-10 12:14:48 +00:00
}
2011-12-22 10:29:12 +00:00
2011-12-17 14:50:59 +00:00
mode = ( CPAPMode ) ( int ) cpap - > settings_max ( CPAP_Mode ) ;
2011-12-14 05:15:13 +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
2013-10-20 16:20:31 +00:00
EventDataType ahi = ( cpap - > count ( CPAP_Obstructive ) + cpap - > count ( CPAP_Hypopnea ) + cpap - > count ( CPAP_ClearAirway ) + cpap - > count ( CPAP_Apnea ) ) ;
2014-07-11 12:09:38 +00:00
if ( p_profile - > general - > calculateRDI ( ) ) ahi + = cpap - > count ( CPAP_RERA ) ;
2012-01-11 04:58:46 +00:00
ahi / = hours ;
2014-07-20 06:08:38 +00:00
EventDataType csr , uai , oai , hi , cai , rei , fli , sai , nri , lki , vs , vs2 , exp , lk2 , uf1 , uf2 ;
2011-12-24 05:55:44 +00:00
2012-01-11 04:58:46 +00:00
if ( ! isBrick & & hours > 0 ) {
2013-10-13 16:35:53 +00:00
html + = " <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
ChannelID ahichan = CPAP_AHI ;
QString ahiname = STR_TR_AHI ;
2014-07-11 12:09:38 +00:00
if ( p_profile - > general - > calculateRDI ( ) ) {
2013-10-13 16:35:53 +00:00
ahichan = CPAP_RDI ;
ahiname = STR_TR_RDI ;
2011-12-24 05:55:44 +00:00
}
2013-10-13 16:35:53 +00:00
html + = " <tr> " ;
html + = QString ( " <td colspan=4 bgcolor='%1' align=center><a class=info2 href='#'><font size=+4 color='%2'><b>%3</b></font><span>%4</span></a> <font size=+4 color='%2'><b>%5</b></font></td> \n " )
2014-07-28 17:10:26 +00:00
. arg ( " #F88017 " ) . arg ( COLOR_Text . name ( ) ) . arg ( ahiname ) . arg ( schema : : channel [ ahichan ] . fullname ( ) ) . arg ( ahi , 0 , ' f ' , 2 ) ;
2013-10-13 16:35:53 +00:00
html + = " </tr> \n " ;
html + = " </table> \n " ;
html + = getCPAPInformation ( cpap ) ;
html + = getSleepTime ( cpap , oxi ) ;
2013-10-20 16:20:31 +00:00
struct ChannelInfo {
ChannelID id ;
QColor color ;
QColor color2 ;
EventDataType value ;
} ;
ChannelInfo chans [ ] = {
2013-10-26 05:06:56 +00:00
{ CPAP_Hypopnea , COLOR_Hypopnea , Qt : : white , hi = ( cpap - > count ( CPAP_ExP ) + cpap - > count ( CPAP_Hypopnea ) ) / hours } ,
{ CPAP_Obstructive , COLOR_Obstructive , Qt : : black , oai = cpap - > count ( CPAP_Obstructive ) / hours } ,
{ CPAP_Apnea , COLOR_Apnea , Qt : : black , uai = cpap - > count ( CPAP_Apnea ) / hours } ,
{ CPAP_ClearAirway , COLOR_ClearAirway , Qt : : black , cai = cpap - > count ( CPAP_ClearAirway ) / hours } ,
{ CPAP_NRI , COLOR_NRI , Qt : : black , nri = cpap - > count ( CPAP_NRI ) / hours } ,
{ CPAP_FlowLimit , COLOR_FlowLimit , Qt : : white , fli = cpap - > count ( CPAP_FlowLimit ) / hours } ,
2014-05-15 06:20:54 +00:00
{ CPAP_SensAwake , COLOR_SensAwake , Qt : : black , sai = cpap - > count ( CPAP_SensAwake ) / hours } ,
2013-10-26 05:06:56 +00:00
{ CPAP_ExP , COLOR_ExP , Qt : : black , exp = cpap - > count ( CPAP_ExP ) / hours } ,
{ CPAP_RERA , COLOR_RERA , Qt : : black , rei = cpap - > count ( CPAP_RERA ) / hours } ,
{ CPAP_VSnore , COLOR_VibratorySnore , Qt : : black , vs = cpap - > count ( CPAP_VSnore ) / cpap - > hours ( ) } ,
{ CPAP_VSnore2 , COLOR_VibratorySnore , Qt : : black , vs2 = cpap - > count ( CPAP_VSnore2 ) / cpap - > hours ( ) } ,
{ CPAP_LeakFlag , COLOR_LeakFlag , Qt : : black , lki = cpap - > count ( CPAP_LeakFlag ) / hours } ,
2014-05-17 05:04:40 +00:00
{ CPAP_LargeLeak , COLOR_LargeLeak , Qt : : black , lk2 = ( 100.0 / cpap - > hours ( ) ) * ( cpap - > sum ( CPAP_LargeLeak ) / 3600.0 ) } ,
2014-07-20 09:22:31 +00:00
{ CPAP_CSR , COLOR_CSR , Qt : : black , csr = ( 100.0 / cpap - > hours ( ) ) * ( cpap - > sum ( CPAP_CSR ) / 3600.0 ) } ,
{ CPAP_UserFlag1 , COLOR_UserFlag1 , Qt : : black , uf1 = cpap - > count ( CPAP_UserFlag1 ) / hours } ,
{ CPAP_UserFlag2 , COLOR_UserFlag2 , Qt : : black , uf2 = cpap - > count ( CPAP_UserFlag2 ) / hours } ,
2013-10-20 16:20:31 +00:00
} ;
int numchans = sizeof ( chans ) / sizeof ( ChannelInfo ) ;
2013-10-13 16:35:53 +00:00
html + = " <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
2013-10-20 16:20:31 +00:00
for ( int i = 0 ; i < numchans ; i + + ) {
if ( ! cpap - > channelHasData ( chans [ i ] . id ) )
continue ;
2014-07-28 13:56:29 +00:00
if ( ( cpap - > machine - > loaderName ( ) = = STR_MACH_PRS1 ) & & ( chans [ i ] . id = = CPAP_VSnore ) )
2013-10-20 16:20:31 +00:00
continue ;
html + = QString ( " <tr><td align='left' bgcolor='%1'><b><font color='%2'><a href='event=%5'>%3</a></font></b></td><td width=20% bgcolor='%1'><b><font color='%2'>%4</font></b></td></tr> \n " )
2013-10-26 05:06:56 +00:00
. arg ( chans [ i ] . color . name ( ) ) . arg ( chans [ i ] . color2 . name ( ) ) . arg ( schema : : channel [ chans [ i ] . id ] . fullname ( ) ) . arg ( chans [ i ] . value , 0 , ' f ' , 2 ) . arg ( chans [ i ] . id ) ;
2013-10-20 16:20:31 +00:00
// keep in case tooltips are needed
//html+=QString("<tr><td align='left' bgcolor='%1'><b><font color='%2'><a class=info href='event=%6'>%3<span>%4</span></a></font></b></td><td width=20% bgcolor='%1'><b><font color='%2'>%5</font></b></td></tr>\n")
// .arg(chans[i].color.name()).arg(chans[i].color2.name()).arg(chans[i].name).arg(schema::channel[chans[i].id].description()).arg(chans[i].value,0,'f',2).arg(chans[i].id);
2012-01-09 08:05:20 +00:00
}
2013-10-20 16:20:31 +00:00
html + = " </table> " ;
2012-01-06 18:15:21 +00:00
2013-10-20 16:20:31 +00:00
html + = " <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
// Show Event Breakdown pie chart
2014-07-11 12:09:38 +00:00
if ( ( hours > 0 ) & & p_profile - > appearance - > graphSnapshots ( ) ) { // AHI Pie Chart
2014-05-15 03:51:32 +00:00
if ( ( oai + hi + cai + uai + rei + fli + sai ) > 0 ) {
2013-10-20 16:20:31 +00:00
html + = " <tr><td align=center> </td></tr> " ;
html + = QString ( " <tr><td align=center><b>%1</b></td></tr> " ) . arg ( tr ( " Event Breakdown " ) ) ;
2014-05-13 08:14:20 +00:00
eventBreakdownPie ( ) - > setShowTitle ( false ) ;
2012-01-07 04:41:07 +00:00
2013-11-03 12:14:17 +00:00
int w = 155 ;
int h = 155 ;
2014-05-13 08:14:20 +00:00
QPixmap pixmap = eventBreakdownPie ( ) - > renderPixmap ( w , h , false ) ;
2013-01-15 05:55:39 +00:00
if ( ! pixmap . isNull ( ) ) {
QByteArray byteArray ;
QBuffer buffer ( & byteArray ) ; // use buffer to store pixmap into byteArray
buffer . open ( QIODevice : : WriteOnly ) ;
pixmap . save ( & buffer , " PNG " ) ;
2013-11-03 12:14:17 +00:00
html + = " <tr><td align=center><img src= \" data:image/png;base64, " + byteArray . toBase64 ( ) + QString ( " \" width='%1' height='%2px'></td></tr> \n " ) . arg ( w ) . arg ( h ) ;
2013-01-15 05:55:39 +00:00
} else {
2013-10-20 16:20:31 +00:00
html + = " <tr><td align=center>Unable to display Pie Chart on this system</td></tr> \n " ;
2013-01-15 05:55:39 +00:00
}
2014-06-20 16:19:17 +00:00
} else if ( cpap - > channelHasData ( CPAP_Obstructive )
| | cpap - > channelHasData ( CPAP_Hypopnea )
| | cpap - > channelHasData ( CPAP_ClearAirway )
| | cpap - > channelHasData ( CPAP_RERA )
| | cpap - > channelHasData ( CPAP_Apnea )
| | cpap - > channelHasData ( CPAP_FlowLimit )
| | cpap - > channelHasData ( CPAP_SensAwake )
) {
html + = " <tr><td align=center><img src= \" qrc:/docs/0.0.gif \" ></td></tr> \n " ;
2011-12-10 12:14:48 +00:00
}
2011-08-07 11:37:56 +00:00
}
2011-12-10 12:14:48 +00:00
2013-10-13 16:35:53 +00:00
html + = " </table> \n " ;
2011-12-23 10:52:31 +00:00
2013-10-13 16:35:53 +00:00
} else {
html + = " <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
2012-01-11 04:58:46 +00:00
if ( ! isBrick ) {
html + = " <tr><td colspan='5'> </td></tr> \n " ;
if ( cpap - > size ( ) > 0 ) {
html + = " <tr><td colspan='5' align='center'><b><h2> " + tr ( " Sessions all off! " ) + " </h2></b></td></tr> " ;
html + = " <tr><td colspan='5' align='center'><i> " + tr ( " Sessions exist for this day but are switched off. " ) + " </i></td></tr> \n " ;
} else {
html + = " <tr><td colspan='5' align='center'><b><h2> " + tr ( " Impossibly short session " ) + " </h2></b></td></tr> " ;
html + = " <tr><td colspan='5' align='center'><i> " + tr ( " Zero hours?? " ) + " </i></td></tr> \n " ;
}
2013-10-13 16:35:53 +00:00
} else { // machine is a brick
2012-01-11 04:58:46 +00:00
html + = " <tr><td colspan='5' align='center'><b><h2> " + tr ( " BRICK :( " ) + " </h2></b></td></tr> " ;
2013-10-13 16:35:53 +00:00
html + = " <tr><td colspan='5' align='center'><i> " + tr ( " Sorry, your machine only provides compliance data. " ) + " </i></td></tr> \n " ;
2012-01-11 04:58:46 +00:00
html + = " <tr><td colspan='5' align='center'><i> " + tr ( " Complain to your Equipment Provider! " ) + " </i></td></tr> \n " ;
}
2011-12-23 10:52:31 +00:00
html + = " <tr><td colspan='5'> </td></tr> \n " ;
2013-10-13 16:35:53 +00:00
html + = " </table> \n " ;
2011-12-23 10:52:31 +00:00
}
2013-10-13 16:35:53 +00:00
html + = " <hr/> \n " ;
2011-12-23 10:52:31 +00:00
} // if (!CPAP)
2013-10-13 16:35:53 +00:00
else html + = getSleepTime ( cpap , oxi ) ;
2012-01-12 23:34:52 +00:00
2014-04-15 13:59:24 +00:00
if ( ( cpap & & ! isBrick & & ( cpap - > hours ( ) > 0 ) ) | | oxi | | posit ) {
2012-01-12 23:34:52 +00:00
2014-04-15 13:59:24 +00:00
html + = getStatisticsInfo ( cpap , oxi , posit ) ;
2014-05-15 20:48:05 +00:00
2011-06-26 08:30:44 +00:00
} else {
2012-01-11 04:58:46 +00:00
if ( cpap & & cpap - > hours ( ) = = 0 ) {
} else {
2013-10-13 16:35:53 +00:00
html + = " <table cellspacing=0 cellpadding=0 border=0 width='100%'> \n " ;
html + = " <tr><td colspan=5 align=center><i> " + tr ( " No data available " ) + " </i></td></tr> \n " ;
2012-01-11 04:58:46 +00:00
html + = " <tr><td colspan=5> </td></tr> \n " ;
2013-10-13 16:35:53 +00:00
html + = " </table> \n " ;
html + = " <hr/> \n " ;
2012-01-11 04:58:46 +00:00
}
2011-06-26 08:30:44 +00:00
}
2013-10-13 16:35:53 +00:00
html + = getOximeterInformation ( oxi ) ;
html + = getMachineSettings ( cpap ) ;
2014-04-15 13:59:24 +00:00
html + = getSessionInformation ( cpap , oxi , stage , posit ) ;
2011-12-31 11:36:19 +00:00
2011-08-25 06:11:44 +00:00
html + = " </body></html> " ;
2011-06-26 08:30:44 +00:00
2013-10-12 07:40:45 +00:00
QColor cols [ ] = {
QColor ( " gold " ) ,
QColor ( " light blue " ) ,
} ;
const int maxcolors = sizeof ( cols ) / sizeof ( QColor ) ;
2013-10-22 11:42:57 +00:00
QList < Session * > : : iterator i ;
2013-10-12 07:40:45 +00:00
// WebView trashes it without asking.. :(
2013-10-12 07:46:06 +00:00
if ( cpap ) {
sessbar = new SessionBar ( this ) ;
sessbar - > setMouseTracking ( true ) ;
2014-05-25 07:07:08 +00:00
connect ( sessbar , SIGNAL ( sessionClicked ( Session * ) ) , this , SLOT ( doToggleSession ( Session * ) ) ) ;
2013-10-12 07:46:06 +00:00
int c = 0 ;
for ( i = cpap - > begin ( ) ; i ! = cpap - > end ( ) ; + + i ) {
Session * s = * i ;
sessbar - > add ( s , cols [ c % maxcolors ] ) ;
c + + ;
}
2014-04-23 13:19:56 +00:00
} else sessbar = nullptr ;
2013-10-12 07:40:45 +00:00
//sessbar->update();
webView - > setHtml ( html ) ;
2011-06-26 08:30:44 +00:00
2011-09-17 15:41:31 +00:00
ui - > JournalNotes - > clear ( ) ;
2011-12-02 11:40:47 +00:00
2011-12-18 16:39:36 +00:00
ui - > bookmarkTable - > clearContents ( ) ;
2011-12-02 11:40:47 +00:00
ui - > bookmarkTable - > setRowCount ( 0 ) ;
QStringList sl ;
2011-12-18 16:39:36 +00:00
//sl.append(tr("Starts"));
//sl.append(tr("Notes"));
2011-12-02 11:40:47 +00:00
ui - > bookmarkTable - > setHorizontalHeaderLabels ( sl ) ;
2011-12-10 15:24:45 +00:00
ui - > ZombieMeter - > blockSignals ( true ) ;
ui - > weightSpinBox - > blockSignals ( true ) ;
ui - > ouncesSpinBox - > blockSignals ( true ) ;
2011-12-02 11:40:47 +00:00
ui - > weightSpinBox - > setValue ( 0 ) ;
2011-12-02 13:48:05 +00:00
ui - > ouncesSpinBox - > setValue ( 0 ) ;
2011-12-10 12:14:48 +00:00
ui - > ZombieMeter - > setValue ( 5 ) ;
2011-12-10 15:24:45 +00:00
ui - > ouncesSpinBox - > blockSignals ( false ) ;
ui - > weightSpinBox - > blockSignals ( false ) ;
ui - > ZombieMeter - > blockSignals ( false ) ;
2011-12-03 01:05:17 +00:00
ui - > BMI - > display ( 0 ) ;
ui - > BMI - > setVisible ( false ) ;
ui - > BMIlabel - > setVisible ( false ) ;
2011-12-02 14:18:47 +00:00
BookmarksChanged = false ;
2011-06-26 08:30:44 +00:00
Session * journal = GetJournalSession ( date ) ;
if ( journal ) {
2011-12-02 11:40:47 +00:00
bool ok ;
if ( journal - > settings . contains ( Journal_Notes ) )
ui - > JournalNotes - > setHtml ( journal - > settings [ Journal_Notes ] . toString ( ) ) ;
2011-12-21 05:47:33 +00:00
if ( journal - > settings . contains ( Journal_Weight ) ) {
double kg = journal - > settings [ Journal_Weight ] . toDouble ( & ok ) ;
2011-12-21 11:09:50 +00:00
2014-07-11 12:09:38 +00:00
if ( p_profile - > general - > unitSystem ( ) = = US_Metric ) {
2011-12-02 13:48:05 +00:00
ui - > weightSpinBox - > setDecimals ( 3 ) ;
2011-12-10 15:24:45 +00:00
ui - > weightSpinBox - > blockSignals ( true ) ;
2011-12-02 13:48:05 +00:00
ui - > weightSpinBox - > setValue ( kg ) ;
2011-12-10 15:24:45 +00:00
ui - > weightSpinBox - > blockSignals ( false ) ;
2011-12-02 13:48:05 +00:00
ui - > ouncesSpinBox - > setVisible ( false ) ;
2011-12-21 12:47:47 +00:00
ui - > weightSpinBox - > setSuffix ( STR_UNIT_KG ) ;
2011-12-02 13:48:05 +00:00
} else {
float ounces = ( kg * 1000.0 ) / ounce_convert ;
int pounds = ounces / 16.0 ;
double oz ;
double frac = modf ( ounces , & oz ) ;
ounces = ( int ( ounces ) % 16 ) + frac ;
2011-12-10 15:24:45 +00:00
ui - > weightSpinBox - > blockSignals ( true ) ;
ui - > ouncesSpinBox - > blockSignals ( true ) ;
2011-12-02 13:48:05 +00:00
ui - > weightSpinBox - > setValue ( pounds ) ;
ui - > ouncesSpinBox - > setValue ( ounces ) ;
2011-12-10 15:24:45 +00:00
ui - > ouncesSpinBox - > blockSignals ( false ) ;
ui - > weightSpinBox - > blockSignals ( false ) ;
2011-12-02 13:48:05 +00:00
2011-12-21 12:47:47 +00:00
ui - > weightSpinBox - > setSuffix ( STR_UNIT_POUND ) ;
2011-12-02 13:48:05 +00:00
ui - > weightSpinBox - > setDecimals ( 0 ) ;
ui - > ouncesSpinBox - > setVisible ( true ) ;
2011-12-21 12:47:47 +00:00
ui - > ouncesSpinBox - > setSuffix ( STR_UNIT_OUNCE ) ;
2011-12-02 13:48:05 +00:00
}
2014-07-11 12:09:38 +00:00
double height = p_profile - > user - > height ( ) / 100.0 ;
2011-12-03 01:05:17 +00:00
if ( height > 0 & & kg > 0 ) {
2011-12-14 04:54:17 +00:00
double bmi = kg / ( height * height ) ;
2011-12-03 01:05:17 +00:00
ui - > BMI - > setVisible ( true ) ;
ui - > BMIlabel - > setVisible ( true ) ;
2011-12-14 04:54:17 +00:00
ui - > BMI - > display ( bmi ) ;
2011-12-03 01:05:17 +00:00
}
2011-12-02 13:48:05 +00:00
}
2011-12-02 11:40:47 +00:00
2011-12-21 05:47:33 +00:00
if ( journal - > settings . contains ( Journal_ZombieMeter ) ) {
2011-12-10 15:24:45 +00:00
ui - > ZombieMeter - > blockSignals ( true ) ;
2011-12-21 05:47:33 +00:00
ui - > ZombieMeter - > setValue ( journal - > settings [ Journal_ZombieMeter ] . toDouble ( & ok ) ) ;
2011-12-10 15:24:45 +00:00
ui - > ZombieMeter - > blockSignals ( false ) ;
}
2011-12-02 11:40:47 +00:00
2011-12-21 05:47:33 +00:00
if ( journal - > settings . contains ( Bookmark_Start ) ) {
QVariantList start = journal - > settings [ Bookmark_Start ] . toList ( ) ;
QVariantList end = journal - > settings [ Bookmark_End ] . toList ( ) ;
QStringList notes = journal - > settings [ Bookmark_Notes ] . toStringList ( ) ;
2011-12-02 11:40:47 +00:00
2011-12-11 13:57:07 +00:00
ui - > bookmarkTable - > blockSignals ( true ) ;
2012-01-19 15:18:34 +00:00
2014-07-11 12:09:38 +00:00
qint64 clockdrift = p_profile - > cpap - > clockDrift ( ) * 1000L , drift ;
Day * dday = p_profile - > GetDay ( previous_date , MT_CPAP ) ;
2014-04-23 13:19:56 +00:00
drift = ( dday ! = nullptr ) ? clockdrift : 0 ;
2012-01-19 15:18:34 +00:00
2011-12-02 11:40:47 +00:00
bool ok ;
for ( int i = 0 ; i < start . size ( ) ; i + + ) {
2012-01-19 15:18:34 +00:00
qint64 st = start . at ( i ) . toLongLong ( & ok ) + drift ;
qint64 et = end . at ( i ) . toLongLong ( & ok ) + drift ;
2011-12-02 11:40:47 +00:00
QDateTime d = QDateTime : : fromTime_t ( st / 1000L ) ;
//int row=ui->bookmarkTable->rowCount();
ui - > bookmarkTable - > insertRow ( i ) ;
QTableWidgetItem * tw = new QTableWidgetItem ( notes . at ( i ) ) ;
QTableWidgetItem * dw = new QTableWidgetItem ( d . time ( ) . toString ( " HH:mm:ss " ) ) ;
dw - > setFlags ( Qt : : ItemIsSelectable | Qt : : ItemIsEnabled ) ;
ui - > bookmarkTable - > setItem ( i , 0 , dw ) ;
ui - > bookmarkTable - > setItem ( i , 1 , tw ) ;
tw - > setData ( Qt : : UserRole , st ) ;
tw - > setData ( Qt : : UserRole + 1 , et ) ;
2011-12-23 10:52:31 +00:00
} // for (int i
2011-12-11 13:57:07 +00:00
ui - > bookmarkTable - > blockSignals ( false ) ;
2011-12-23 10:52:31 +00:00
} // if (journal->settings.contains(Bookmark_Start))
} // if (journal)
2011-06-26 08:30:44 +00:00
}
2011-12-02 13:48:05 +00:00
void Daily : : UnitsChanged ( )
{
double kg ;
2014-07-11 12:09:38 +00:00
if ( p_profile - > general - > unitSystem ( ) = = US_Archiac ) {
2011-12-02 13:48:05 +00:00
kg = ui - > weightSpinBox - > value ( ) ;
float ounces = ( kg * 1000.0 ) / ounce_convert ;
int pounds = ounces / 16 ;
float oz = fmodf ( ounces , 16 ) ;
ui - > weightSpinBox - > setValue ( pounds ) ;
ui - > ouncesSpinBox - > setValue ( oz ) ;
ui - > weightSpinBox - > setDecimals ( 0 ) ;
2011-12-21 12:47:47 +00:00
ui - > weightSpinBox - > setSuffix ( STR_UNIT_POUND ) ;
2011-12-02 13:48:05 +00:00
ui - > ouncesSpinBox - > setVisible ( true ) ;
2011-12-21 12:47:47 +00:00
ui - > ouncesSpinBox - > setSuffix ( STR_UNIT_OUNCE ) ;
2011-12-02 13:48:05 +00:00
} else {
kg = ( ui - > weightSpinBox - > value ( ) * ( ounce_convert * 16.0 ) ) + ( ui - > ouncesSpinBox - > value ( ) * ounce_convert ) ;
kg / = 1000.0 ;
ui - > weightSpinBox - > setDecimals ( 3 ) ;
ui - > weightSpinBox - > setValue ( kg ) ;
ui - > ouncesSpinBox - > setVisible ( false ) ;
2011-12-21 12:47:47 +00:00
ui - > weightSpinBox - > setSuffix ( STR_UNIT_KG ) ;
2011-12-02 13:48:05 +00:00
}
}
2013-10-22 11:42:57 +00:00
void Daily : : clearLastDay ( )
{
2014-04-23 13:19:56 +00:00
lastcpapday = nullptr ;
2013-10-22 11:42:57 +00:00
}
2011-06-26 08:30:44 +00:00
void Daily : : Unload ( QDate date )
{
2014-07-25 07:53:48 +00:00
if ( ! date . isValid ( ) ) {
date = getDate ( ) ;
if ( ! date . isValid ( ) ) {
graphView ( ) - > setDay ( nullptr ) ;
return ;
}
}
2014-07-13 09:47:27 +00:00
webView - > setHtml ( " " ) ;
2011-09-17 15:41:31 +00:00
Session * journal = GetJournalSession ( date ) ;
2011-06-26 08:30:44 +00:00
2011-12-02 11:40:47 +00:00
bool nonotes = ui - > JournalNotes - > toPlainText ( ) . isEmpty ( ) ;
if ( journal ) {
QString jhtml = ui - > JournalNotes - > toHtml ( ) ;
2011-12-02 11:48:02 +00:00
if ( ( ! journal - > settings . contains ( Journal_Notes ) & & ! nonotes ) | | ( journal - > settings [ Journal_Notes ] ! = jhtml ) ) {
2011-09-17 15:41:31 +00:00
journal - > settings [ Journal_Notes ] = jhtml ;
2011-06-26 08:30:44 +00:00
journal - > SetChanged ( true ) ;
}
2011-12-02 11:40:47 +00:00
} else {
2011-12-11 13:57:07 +00:00
if ( ! nonotes ) {
2011-12-02 11:40:47 +00:00
journal = CreateJournalSession ( date ) ;
if ( ! nonotes ) {
journal - > settings [ Journal_Notes ] = ui - > JournalNotes - > toHtml ( ) ;
journal - > SetChanged ( true ) ;
}
}
2011-06-26 08:30:44 +00:00
}
2011-12-02 11:40:47 +00:00
2011-06-26 08:30:44 +00:00
if ( journal ) {
2011-12-02 11:48:02 +00:00
if ( nonotes ) {
QHash < ChannelID , QVariant > : : iterator it = journal - > settings . find ( Journal_Notes ) ;
if ( it ! = journal - > settings . end ( ) ) {
journal - > settings . erase ( it ) ;
}
}
2011-12-02 13:48:05 +00:00
if ( journal - > IsChanged ( ) ) {
2012-01-05 15:17:50 +00:00
// blah.. was updating overview graphs here.. Was too slow.
2011-12-02 13:48:05 +00:00
}
2014-07-11 12:09:38 +00:00
Machine * jm = p_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 ( )
{
2013-09-10 15:09:09 +00:00
QColor col = QColorDialog : : getColor ( COLOR_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 )
{
2014-07-11 12:09:38 +00:00
Machine * m = p_profile - > GetMachine ( MT_JOURNAL ) ;
2011-06-26 08:30:44 +00:00
if ( ! m ) {
2014-07-11 12:09:38 +00:00
m = new Machine ( 0 ) ;
2014-07-28 13:56:29 +00:00
MachineInfo info ;
info . loadername = " Journal " ;
info . serial = m - > hexid ( ) ;
info . brand = " Journal " ;
info . type = MT_JOURNAL ;
m - > setInfo ( info ) ;
2014-07-11 12:09:38 +00:00
p_profile - > AddMachine ( m ) ;
2011-06-26 08:30:44 +00:00
}
Session * sess = new Session ( m , 0 ) ;
2011-12-25 05:05:12 +00:00
qint64 st , et ;
2014-07-11 12:09:38 +00:00
Day * cday = p_profile - > GetDay ( date , MT_CPAP ) ;
2011-12-25 05:05:12 +00:00
if ( cday ) {
st = cday - > first ( ) ;
et = cday - > last ( ) ;
} else {
QDateTime dt ( date , QTime ( 20 , 0 ) ) ;
st = qint64 ( dt . toTime_t ( ) ) * 1000L ;
et = st + 3600000 ;
}
sess - > set_first ( st ) ;
sess - > set_last ( et ) ;
2011-06-26 08:30:44 +00:00
sess - > SetChanged ( true ) ;
2014-07-11 12:09:38 +00:00
m - > AddSession ( sess ) ;
2011-06-26 08:30:44 +00:00
return sess ;
}
Session * Daily : : GetJournalSession ( QDate date ) // Get the first journal session
{
2014-07-11 12:09:38 +00:00
Day * journal = p_profile - > GetDay ( date , MT_JOURNAL ) ;
2011-06-26 08:30:44 +00:00
if ( ! journal )
2014-04-23 13:19:56 +00:00
return nullptr ; //CreateJournalSession(date);
2013-10-22 11:42:57 +00:00
QList < Session * > : : iterator s ;
2011-06-26 08:30:44 +00:00
s = journal - > begin ( ) ;
if ( s ! = journal - > end ( ) )
return * s ;
2014-04-23 13:19:56 +00:00
return nullptr ;
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
}
2012-01-11 13:55:46 +00:00
void Daily : : UpdateSTAGEGraphs ( Day * day )
{
//if (!day) return;
if ( day ) {
day - > OpenEvents ( ) ;
}
for ( QList < Layer * > : : iterator g = STAGEData . begin ( ) ; g ! = STAGEData . end ( ) ; g + + ) {
( * g ) - > SetDay ( day ) ;
}
}
2011-06-26 08:30:44 +00:00
2014-04-15 13:59:24 +00:00
void Daily : : UpdatePOSGraphs ( Day * day )
{
//if (!day) return;
if ( day ) {
day - > OpenEvents ( ) ;
}
for ( QList < Layer * > : : iterator g = POSData . begin ( ) ; g ! = POSData . end ( ) ; g + + ) {
( * 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-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 ( )
{
2014-05-15 19:45:46 +00:00
// setting this here, because it needs to be done when preferences change
2014-07-11 12:09:38 +00:00
if ( p_profile - > cpap - > showLeakRedline ( ) ) {
schema : : channel [ CPAP_Leak ] . setUpperThreshold ( p_profile - > cpap - > leakRedline ( ) ) ;
2014-05-15 19:45:46 +00:00
} else {
2014-05-15 21:48:53 +00:00
schema : : channel [ CPAP_Leak ] . setUpperThreshold ( 0 ) ; // switch it off
2014-05-15 19:45:46 +00:00
}
2011-12-20 11:12:52 +00:00
GraphView - > redraw ( ) ;
2011-06-27 07:45:59 +00:00
}
2011-06-26 08:30:44 +00:00
2011-11-27 22:36:38 +00:00
void Daily : : on_treeWidget_itemClicked ( QTreeWidgetItem * item , int column )
2011-06-26 08:30:44 +00:00
{
2011-12-02 14:36:40 +00:00
Q_UNUSED ( column ) ;
2011-06-26 08:30:44 +00:00
QDateTime d ;
2011-12-25 05:05:12 +00:00
if ( ! item - > data ( 0 , Qt : : UserRole ) . isNull ( ) ) {
2014-07-11 12:09:38 +00:00
qint64 winsize = qint64 ( p_profile - > general - > eventWindowSize ( ) ) * 60000L ;
2011-12-25 05:05:12 +00:00
qint64 t = item - > data ( 0 , Qt : : UserRole ) . toLongLong ( ) ;
double st = t - ( winsize / 2 ) ;
double et = t + ( winsize / 2 ) ;
2014-07-19 06:18:54 +00:00
gGraph * g = GraphView - > findGraph ( STR_GRAPH_SleepFlags ) ;
2011-11-27 22:36:38 +00:00
if ( ! g ) return ;
if ( st < g - > rmin_x ) {
st = g - > rmin_x ;
2011-12-25 05:05:12 +00:00
et = st + winsize ;
2011-11-27 08:31:05 +00:00
}
2011-11-27 22:36:38 +00:00
if ( et > g - > rmax_x ) {
et = g - > rmax_x ;
2011-12-25 05:05:12 +00:00
st = et - winsize ;
2011-11-27 08:31:05 +00:00
}
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
2011-11-27 22:36:38 +00:00
void Daily : : on_treeWidget_itemSelectionChanged ( )
{
if ( ui - > treeWidget - > selectedItems ( ) . size ( ) = = 0 ) return ;
QTreeWidgetItem * item = ui - > treeWidget - > selectedItems ( ) . at ( 0 ) ;
if ( ! item ) return ;
on_treeWidget_itemClicked ( item , 0 ) ;
}
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 ( )
{
2014-07-11 12:09:38 +00:00
if ( ! p_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 ) ;
2014-07-11 12:09:38 +00:00
if ( p_profile - > GetDay ( d ) ) {
2011-10-30 04:51:57 +00:00
LoadDate ( d ) ;
break ;
}
2011-10-30 04:43:15 +00:00
}
}
2011-10-30 02:46:17 +00:00
}
void Daily : : on_nextDayButton_clicked ( )
{
2014-07-11 12:09:38 +00:00
if ( ! p_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 ) ;
2014-07-11 12:09:38 +00:00
if ( p_profile - > GetDay ( d ) ) {
2011-10-30 04:51:57 +00:00
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 = checked ;
2014-05-17 11:33:33 +00:00
ui - > calendarFrame - > setVisible ( b ) ;
if ( ! b ) {
ui - > calButton - > setArrowType ( Qt : : DownArrow ) ;
} 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 ( ) ;
2014-07-11 12:09:38 +00:00
if ( d > p_profile - > LastDay ( ) ) d = p_profile - > LastDay ( ) ;
2011-10-30 03:18:20 +00:00
LoadDate ( d ) ;
}
2011-11-24 12:47:25 +00:00
2011-11-27 07:41:00 +00:00
void Daily : : on_evViewSlider_valueChanged ( int value )
{
ui - > evViewLCD - > display ( value ) ;
2014-07-11 12:09:38 +00:00
p_profile - > general - > setEventWindowSize ( value ) ;
2011-11-27 08:00:20 +00:00
2011-12-21 12:47:47 +00:00
int winsize = value * 60 ;
2011-11-27 08:31:05 +00:00
2014-07-16 17:12:52 +00:00
gGraph * g = GraphView - > findGraph ( STR_GRAPH_SleepFlags ) ;
2011-12-11 13:57:07 +00:00
if ( ! g ) return ;
qint64 st = g - > min_x ;
qint64 et = g - > max_x ;
qint64 len = et - st ;
qint64 d = st + len / 2.0 ;
st = d - ( winsize / 2 ) * 1000 ;
et = d + ( winsize / 2 ) * 1000 ;
if ( st < g - > rmin_x ) {
st = g - > rmin_x ;
et = st + winsize * 1000 ;
}
if ( et > g - > rmax_x ) {
et = g - > rmax_x ;
st = et - winsize * 1000 ;
2011-11-27 08:00:20 +00:00
}
2011-12-11 13:57:07 +00:00
GraphView - > SetXBounds ( st , et ) ;
2011-11-27 07:41:00 +00:00
}
2011-12-01 15:40:32 +00:00
2011-12-02 11:40:47 +00:00
void Daily : : on_bookmarkTable_itemClicked ( QTableWidgetItem * item )
{
int row = item - > row ( ) ;
qint64 st , et ;
2014-07-11 12:09:38 +00:00
// qint64 clockdrift=p_profile->cpap->clockDrift()*1000L,drift;
// Day * dday=p_profile->GetDay(previous_date,MT_CPAP);
2014-04-23 13:19:56 +00:00
// drift=(dday!=nullptr) ? clockdrift : 0;
2012-01-19 15:18:34 +00:00
2011-12-02 11:40:47 +00:00
QTableWidgetItem * it = ui - > bookmarkTable - > item ( row , 1 ) ;
bool ok ;
st = it - > data ( Qt : : UserRole ) . toLongLong ( & ok ) ;
et = it - > data ( Qt : : UserRole + 1 ) . toLongLong ( & ok ) ;
2012-01-05 12:12:42 +00:00
qint64 st2 = 0 , et2 = 0 , st3 , et3 ;
2014-07-11 12:09:38 +00:00
Day * day = p_profile - > GetGoodDay ( previous_date , MT_CPAP ) ;
2011-12-28 14:21:45 +00:00
if ( day ) {
st2 = day - > first ( ) ;
et2 = day - > last ( ) ;
}
2014-07-11 12:09:38 +00:00
Day * oxi = p_profile - > GetGoodDay ( previous_date , MT_OXIMETER ) ;
2011-12-28 14:21:45 +00:00
if ( oxi ) {
st3 = oxi - > first ( ) ;
et3 = oxi - > last ( ) ;
}
if ( oxi & & day ) {
st2 = qMin ( st2 , st3 ) ;
et2 = qMax ( et2 , et3 ) ;
} else if ( oxi ) {
st2 = st3 ;
et2 = et3 ;
} else if ( ! day ) return ;
if ( ( et < st2 ) | | ( st > et2 ) ) {
2013-09-09 15:56:02 +00:00
mainwin - > Notify ( tr ( " This bookmarked is in a currently disabled area.. " ) ) ;
2011-12-28 14:21:45 +00:00
return ;
}
if ( st < st2 ) st = st2 ;
if ( et > et2 ) et = et2 ;
2011-12-02 11:40:47 +00:00
GraphView - > SetXBounds ( st , et ) ;
2011-12-20 11:12:52 +00:00
GraphView - > redraw ( ) ;
2011-12-02 11:40:47 +00:00
}
void Daily : : on_addBookmarkButton_clicked ( )
{
qint64 st , et ;
2011-12-11 14:05:07 +00:00
ui - > bookmarkTable - > blockSignals ( true ) ;
2011-12-02 11:40:47 +00:00
GraphView - > GetXBounds ( st , et ) ;
QDateTime d = QDateTime : : fromTime_t ( st / 1000L ) ;
int row = ui - > bookmarkTable - > rowCount ( ) ;
ui - > bookmarkTable - > insertRow ( row ) ;
2013-09-09 15:56:02 +00:00
QTableWidgetItem * tw = new QTableWidgetItem ( tr ( " Bookmark at %1 " ) . arg ( d . time ( ) . toString ( " HH:mm:ss " ) ) ) ;
2011-12-02 11:40:47 +00:00
QTableWidgetItem * dw = new QTableWidgetItem ( d . time ( ) . toString ( " HH:mm:ss " ) ) ;
dw - > setFlags ( Qt : : ItemIsSelectable | Qt : : ItemIsEnabled ) ;
ui - > bookmarkTable - > setItem ( row , 0 , dw ) ;
ui - > bookmarkTable - > setItem ( row , 1 , tw ) ;
2014-07-11 12:09:38 +00:00
qint64 clockdrift = p_profile - > cpap - > clockDrift ( ) * 1000L , drift ;
Day * day = p_profile - > GetDay ( previous_date , MT_CPAP ) ;
2014-04-23 13:19:56 +00:00
drift = ( day ! = nullptr ) ? clockdrift : 0 ;
2012-01-19 15:18:34 +00:00
// Counter CPAP clock drift for storage, in case user changes it later on
// This won't fix the text string names..
tw - > setData ( Qt : : UserRole , st - drift ) ;
tw - > setData ( Qt : : UserRole + 1 , et - drift ) ;
2011-12-02 11:40:47 +00:00
2011-12-11 14:05:07 +00:00
ui - > bookmarkTable - > blockSignals ( false ) ;
2011-12-11 13:57:07 +00:00
update_Bookmarks ( ) ;
2011-12-26 04:41:28 +00:00
mainwin - > updateFavourites ( ) ;
2011-12-11 13:57:07 +00:00
2011-12-02 11:40:47 +00:00
//ui->bookmarkTable->setItem(row,2,new QTableWidgetItem(QString::number(st)));
//ui->bookmarkTable->setItem(row,3,new QTableWidgetItem(QString::number(et)));
}
2011-12-11 13:57:07 +00:00
void Daily : : update_Bookmarks ( )
{
QVariantList start ;
QVariantList end ;
QStringList notes ;
QTableWidgetItem * item ;
for ( int row = 0 ; row < ui - > bookmarkTable - > rowCount ( ) ; row + + ) {
item = ui - > bookmarkTable - > item ( row , 1 ) ;
2011-12-11 14:05:07 +00:00
2011-12-11 13:57:07 +00:00
start . push_back ( item - > data ( Qt : : UserRole ) ) ;
end . push_back ( item - > data ( Qt : : UserRole + 1 ) ) ;
notes . push_back ( item - > text ( ) ) ;
}
Session * journal = GetJournalSession ( previous_date ) ;
if ( ! journal ) {
journal = CreateJournalSession ( previous_date ) ;
}
2011-12-21 05:47:33 +00:00
journal - > settings [ Bookmark_Start ] = start ;
journal - > settings [ Bookmark_End ] = end ;
journal - > settings [ Bookmark_Notes ] = notes ;
2011-12-11 13:57:07 +00:00
journal - > SetChanged ( true ) ;
BookmarksChanged = true ;
2011-12-26 04:41:28 +00:00
mainwin - > updateFavourites ( ) ;
2011-12-11 13:57:07 +00:00
}
2011-12-02 11:40:47 +00:00
void Daily : : on_removeBookmarkButton_clicked ( )
{
int row = ui - > bookmarkTable - > currentRow ( ) ;
if ( row > = 0 ) {
2011-12-11 14:05:07 +00:00
ui - > bookmarkTable - > blockSignals ( true ) ;
2011-12-02 11:40:47 +00:00
ui - > bookmarkTable - > removeRow ( row ) ;
2011-12-11 14:05:07 +00:00
ui - > bookmarkTable - > blockSignals ( false ) ;
2011-12-11 13:57:07 +00:00
update_Bookmarks ( ) ;
2011-12-02 11:40:47 +00:00
}
2011-12-26 04:41:28 +00:00
mainwin - > updateFavourites ( ) ;
2011-12-02 11:40:47 +00:00
}
2011-12-10 15:24:45 +00:00
void Daily : : on_ZombieMeter_valueChanged ( int action )
2011-12-02 11:40:47 +00:00
{
2011-12-02 14:36:40 +00:00
Q_UNUSED ( action ) ;
2011-12-02 11:40:47 +00:00
ZombieMeterMoved = true ;
2011-12-10 15:24:45 +00:00
Session * journal = GetJournalSession ( previous_date ) ;
if ( ! journal ) {
journal = CreateJournalSession ( previous_date ) ;
}
2011-12-21 05:47:33 +00:00
journal - > settings [ Journal_ZombieMeter ] = ui - > ZombieMeter - > value ( ) ;
2011-12-10 15:24:45 +00:00
journal - > SetChanged ( true ) ;
2012-01-05 15:17:50 +00:00
if ( mainwin - > getOverview ( ) ) mainwin - > getOverview ( ) - > ResetGraph ( " Zombie " ) ;
2011-12-02 11:40:47 +00:00
}
2011-12-02 14:18:47 +00:00
void Daily : : on_bookmarkTable_itemChanged ( QTableWidgetItem * item )
{
Q_UNUSED ( item ) ;
2011-12-11 13:57:07 +00:00
update_Bookmarks ( ) ;
2011-12-02 14:18:47 +00:00
}
2012-01-05 15:17:50 +00:00
2011-12-03 01:05:17 +00:00
void Daily : : on_weightSpinBox_valueChanged ( double arg1 )
{
2012-01-05 15:17:50 +00:00
// Update the BMI display
double kg ;
2014-07-11 12:09:38 +00:00
if ( p_profile - > general - > unitSystem ( ) = = US_Archiac ) {
2012-01-05 15:17:50 +00:00
kg = ( ( arg1 * pound_convert ) + ( ui - > ouncesSpinBox - > value ( ) * ounce_convert ) ) / 1000.0 ;
} else kg = arg1 ;
2014-07-11 12:09:38 +00:00
double height = p_profile - > user - > height ( ) / 100.0 ;
2012-01-05 15:17:50 +00:00
if ( ( height > 0 ) & & ( kg > 0 ) ) {
double bmi = kg / ( height * height ) ;
ui - > BMI - > display ( bmi ) ;
ui - > BMI - > setVisible ( true ) ;
}
}
void Daily : : on_weightSpinBox_editingFinished ( )
{
double arg1 = ui - > weightSpinBox - > value ( ) ;
2014-07-11 12:09:38 +00:00
double height = p_profile - > user - > height ( ) / 100.0 ;
2011-12-10 15:24:45 +00:00
Session * journal = GetJournalSession ( previous_date ) ;
if ( ! journal ) {
journal = CreateJournalSession ( previous_date ) ;
}
2011-12-03 01:05:17 +00:00
double kg ;
2014-07-11 12:09:38 +00:00
if ( p_profile - > general - > unitSystem ( ) = = US_Archiac ) {
2012-01-05 15:17:50 +00:00
kg = ( ( arg1 * pound_convert ) + ( ui - > ouncesSpinBox - > value ( ) * ounce_convert ) ) / 1000.0 ;
2011-12-21 11:09:50 +00:00
} else {
kg = arg1 ;
2011-12-03 01:05:17 +00:00
}
2011-12-21 05:47:33 +00:00
journal - > settings [ Journal_Weight ] = kg ;
2011-12-10 15:24:45 +00:00
gGraphView * gv = mainwin - > getOverview ( ) - > graphView ( ) ;
gGraph * g ;
if ( gv ) {
2014-07-16 17:12:52 +00:00
g = gv - > findGraph ( STR_GRAPH_Weight ) ;
2014-04-23 13:19:56 +00:00
if ( g ) g - > setDay ( nullptr ) ;
2011-12-10 15:24:45 +00:00
}
2011-12-03 01:05:17 +00:00
if ( ( height > 0 ) & & ( kg > 0 ) ) {
double bmi = kg / ( height * height ) ;
ui - > BMI - > display ( bmi ) ;
2011-12-03 05:10:23 +00:00
ui - > BMI - > setVisible ( true ) ;
2011-12-21 05:47:33 +00:00
journal - > settings [ Journal_BMI ] = bmi ;
2011-12-10 15:24:45 +00:00
if ( gv ) {
2014-07-16 17:12:52 +00:00
g = gv - > findGraph ( STR_GRAPH_BMI ) ;
2014-04-23 13:19:56 +00:00
if ( g ) g - > setDay ( nullptr ) ;
2011-12-10 15:24:45 +00:00
}
2011-12-03 01:05:17 +00:00
}
2011-12-10 15:24:45 +00:00
journal - > SetChanged ( true ) ;
2011-12-03 01:05:17 +00:00
}
2012-01-05 15:17:50 +00:00
2011-12-03 01:05:17 +00:00
void Daily : : on_ouncesSpinBox_valueChanged ( int arg1 )
{
2012-01-05 15:17:50 +00:00
// just update for BMI display
2014-07-11 12:09:38 +00:00
double height = p_profile - > user - > height ( ) / 100.0 ;
2012-01-05 15:17:50 +00:00
double kg = ( ( ui - > weightSpinBox - > value ( ) * pound_convert ) + ( arg1 * ounce_convert ) ) / 1000.0 ;
if ( ( height > 0 ) & & ( kg > 0 ) ) {
double bmi = kg / ( height * height ) ;
ui - > BMI - > display ( bmi ) ;
ui - > BMI - > setVisible ( true ) ;
}
}
void Daily : : on_ouncesSpinBox_editingFinished ( )
{
double arg1 = ui - > ouncesSpinBox - > value ( ) ;
2011-12-10 15:24:45 +00:00
Session * journal = GetJournalSession ( previous_date ) ;
if ( ! journal ) {
journal = CreateJournalSession ( previous_date ) ;
}
2014-07-11 12:09:38 +00:00
double height = p_profile - > user - > height ( ) / 100.0 ;
2012-01-05 15:17:50 +00:00
double kg = ( ( ui - > weightSpinBox - > value ( ) * pound_convert ) + ( arg1 * ounce_convert ) ) / 1000.0 ;
2011-12-21 05:47:33 +00:00
journal - > settings [ Journal_Weight ] = kg ;
2011-12-10 15:24:45 +00:00
gGraph * g ;
if ( mainwin - > getOverview ( ) ) {
2014-07-16 17:12:52 +00:00
g = mainwin - > getOverview ( ) - > graphView ( ) - > findGraph ( STR_GRAPH_Weight ) ;
2014-04-23 13:19:56 +00:00
if ( g ) g - > setDay ( nullptr ) ;
2011-12-10 15:24:45 +00:00
}
2011-12-03 01:05:17 +00:00
if ( ( height > 0 ) & & ( kg > 0 ) ) {
double bmi = kg / ( height * height ) ;
ui - > BMI - > display ( bmi ) ;
2011-12-03 05:10:23 +00:00
ui - > BMI - > setVisible ( true ) ;
2011-12-10 15:24:45 +00:00
2011-12-21 05:47:33 +00:00
journal - > settings [ Journal_BMI ] = bmi ;
2011-12-10 15:24:45 +00:00
if ( mainwin - > getOverview ( ) ) {
2014-07-16 17:12:52 +00:00
g = mainwin - > getOverview ( ) - > graphView ( ) - > findGraph ( STR_GRAPH_BMI ) ;
2014-04-23 13:19:56 +00:00
if ( g ) g - > setDay ( nullptr ) ;
2011-12-10 15:24:45 +00:00
}
2011-12-03 01:05:17 +00:00
}
2011-12-10 15:24:45 +00:00
journal - > SetChanged ( true ) ;
2014-07-16 17:12:52 +00:00
if ( mainwin - > getOverview ( ) ) mainwin - > getOverview ( ) - > ResetGraph ( STR_GRAPH_Weight ) ;
2011-12-03 01:05:17 +00:00
}
2012-01-05 15:17:50 +00:00
2011-12-12 03:39:00 +00:00
QString Daily : : GetDetailsText ( )
{
2013-10-12 07:40:45 +00:00
webView - > triggerPageAction ( QWebPage : : SelectAll ) ;
QString text = webView - > page ( ) - > selectedText ( ) ;
webView - > triggerPageAction ( QWebPage : : MoveToEndOfDocument ) ;
webView - > triggerPageAction ( QWebPage : : SelectEndOfDocument ) ;
2011-12-12 03:39:00 +00:00
return text ;
}
2012-01-03 16:29:35 +00:00
void Daily : : on_graphCombo_activated ( int index )
{
if ( index < 0 )
return ;
gGraph * g ;
QString s ;
s = ui - > graphCombo - > currentText ( ) ;
bool b = ! ui - > graphCombo - > itemData ( index , Qt : : UserRole ) . toBool ( ) ;
ui - > graphCombo - > setItemData ( index , b , Qt : : UserRole ) ;
if ( b ) {
ui - > graphCombo - > setItemIcon ( index , * icon_on ) ;
} else {
ui - > graphCombo - > setItemIcon ( index , * icon_off ) ;
}
2014-07-16 17:12:52 +00:00
g = GraphView - > findGraphTitle ( s ) ;
2012-01-03 16:29:35 +00:00
g - > setVisible ( b ) ;
updateCube ( ) ;
GraphView - > updateScale ( ) ;
GraphView - > redraw ( ) ;
}
void Daily : : updateCube ( )
{
//brick..
if ( ( GraphView - > visibleGraphs ( ) = = 0 ) ) {
ui - > toggleGraphs - > setArrowType ( Qt : : UpArrow ) ;
ui - > toggleGraphs - > setToolTip ( tr ( " Show all graphs " ) ) ;
ui - > toggleGraphs - > blockSignals ( true ) ;
ui - > toggleGraphs - > setChecked ( true ) ;
ui - > toggleGraphs - > blockSignals ( false ) ;
2014-07-13 04:39:26 +00:00
if ( ui - > graphCombo - > count ( ) > 0 ) {
2012-01-03 16:29:35 +00:00
GraphView - > setEmptyText ( tr ( " No Graphs On! " ) ) ;
} else {
2014-07-13 04:39:26 +00:00
if ( ! p_profile - > GetGoodDay ( getDate ( ) , MT_CPAP )
& & ! p_profile - > GetGoodDay ( getDate ( ) , MT_OXIMETER )
& & ! p_profile - > GetGoodDay ( getDate ( ) , MT_SLEEPSTAGE )
& & ! p_profile - > GetGoodDay ( getDate ( ) , MT_POSITION ) ) {
GraphView - > setEmptyText ( STR_TR_NoData ) ;
} else {
GraphView - > setEmptyText ( tr ( " Summary Only :( " ) ) ;
}
2012-01-03 16:29:35 +00:00
}
} else {
ui - > toggleGraphs - > setArrowType ( Qt : : DownArrow ) ;
ui - > toggleGraphs - > setToolTip ( tr ( " Hide all graphs " ) ) ;
ui - > toggleGraphs - > blockSignals ( true ) ;
ui - > toggleGraphs - > setChecked ( false ) ;
ui - > toggleGraphs - > blockSignals ( false ) ;
}
2014-07-13 04:39:26 +00:00
2012-01-03 16:29:35 +00:00
}
void Daily : : on_toggleGraphs_clicked ( bool checked )
{
QString s ;
QIcon * icon = checked ? icon_off : icon_on ;
for ( int i = 0 ; i < ui - > graphCombo - > count ( ) ; i + + ) {
s = ui - > graphCombo - > itemText ( i ) ;
ui - > graphCombo - > setItemIcon ( i , * icon ) ;
ui - > graphCombo - > setItemData ( i , ! checked , Qt : : UserRole ) ;
}
2012-01-06 05:22:13 +00:00
for ( int i = 0 ; i < GraphView - > size ( ) ; i + + ) {
( * GraphView ) [ i ] - > setVisible ( ! checked ) ;
}
2012-01-03 16:29:35 +00:00
updateCube ( ) ;
GraphView - > updateScale ( ) ;
GraphView - > redraw ( ) ;
}
void Daily : : updateGraphCombo ( )
{
ui - > graphCombo - > clear ( ) ;
gGraph * g ;
for ( int i = 0 ; i < GraphView - > size ( ) ; i + + ) {
g = ( * GraphView ) [ i ] ;
if ( g - > isEmpty ( ) ) continue ;
if ( g - > visible ( ) ) {
ui - > graphCombo - > addItem ( * icon_on , g - > title ( ) , true ) ;
} else {
ui - > graphCombo - > addItem ( * icon_off , g - > title ( ) , false ) ;
}
}
ui - > graphCombo - > setCurrentIndex ( 0 ) ;
updateCube ( ) ;
}
void Daily : : on_zoomFullyOut_clicked ( )
{
GraphView - > ResetBounds ( true ) ;
GraphView - > redraw ( ) ;
}
void Daily : : on_resetLayoutButton_clicked ( )
{
GraphView - > resetLayout ( ) ;
}