2011-06-28 15:25:20 +00:00
/*
2011-06-26 08:30:44 +00:00
Overview GUI Implementation
Copyright ( c ) 2011 Mark Watkins < jedimark @ users . sourceforge . net >
License : GPL
2011-06-28 15:25:20 +00:00
*/
2011-06-26 08:30:44 +00:00
# include <QCalendarWidget>
# include <QTextCharFormat>
2011-07-19 14:04:54 +00:00
# include <QSystemLocale>
# include <QDebug>
2011-09-12 03:07:57 +00:00
# include <QDateTimeEdit>
# include <QCalendarWidget>
2011-09-12 16:10:18 +00:00
# include <QFileDialog>
2011-12-25 06:24:40 +00:00
# include <QMessageBox>
2011-12-01 15:40:32 +00:00
//#include <QProgressBar>
2011-10-05 07:41:56 +00:00
# include "SleepLib/profiles.h"
2011-06-26 08:30:44 +00:00
# include "overview.h"
# include "ui_overview.h"
2011-11-15 21:22:08 +00:00
# include "common_gui.h"
2011-06-26 08:30:44 +00:00
# include "Graphs/gXAxis.h"
# include "Graphs/gLineChart.h"
# include "Graphs/gYAxis.h"
2011-12-02 14:36:40 +00:00
# include "mainwindow.h"
extern MainWindow * mainwin ;
2011-12-01 15:40:32 +00:00
//extern QProgressBar * qprogress;
2011-10-05 07:41:56 +00:00
Overview : : Overview ( QWidget * parent , gGraphView * shared ) :
2011-06-26 08:30:44 +00:00
QWidget ( parent ) ,
2011-09-11 06:16:45 +00:00
ui ( new Ui : : Overview ) ,
m_shared ( shared )
2011-06-26 08:30:44 +00:00
{
2011-09-07 08:35:55 +00:00
ui - > setupUi ( this ) ;
2011-10-31 11:55:25 +00:00
// Set Date controls locale to 4 digit years
QLocale locale = QLocale : : system ( ) ;
QString shortformat = locale . dateFormat ( QLocale : : ShortFormat ) ;
if ( ! shortformat . toLower ( ) . contains ( " yyyy " ) ) {
shortformat . replace ( " yy " , " yyyy " ) ;
}
ui - > dateStart - > setDisplayFormat ( shortformat ) ;
ui - > dateEnd - > setDisplayFormat ( shortformat ) ;
2011-11-15 21:22:08 +00:00
Qt : : DayOfWeek dow = firstDayOfWeekFromLocale ( ) ;
ui - > dateStart - > calendarWidget ( ) - > setFirstDayOfWeek ( dow ) ;
ui - > dateEnd - > calendarWidget ( ) - > setFirstDayOfWeek ( dow ) ;
2011-11-15 05:49:41 +00:00
2011-09-07 08:35:55 +00:00
2011-10-31 11:55:25 +00:00
// Stop both calendar drop downs highlighting weekends in red
QTextCharFormat format = ui - > dateStart - > calendarWidget ( ) - > weekdayTextFormat ( Qt : : Saturday ) ;
format . setForeground ( QBrush ( Qt : : black , Qt : : SolidPattern ) ) ;
ui - > dateStart - > calendarWidget ( ) - > setWeekdayTextFormat ( Qt : : Saturday , format ) ;
ui - > dateStart - > calendarWidget ( ) - > setWeekdayTextFormat ( Qt : : Sunday , format ) ;
ui - > dateEnd - > calendarWidget ( ) - > setWeekdayTextFormat ( Qt : : Saturday , format ) ;
ui - > dateEnd - > calendarWidget ( ) - > setWeekdayTextFormat ( Qt : : Sunday , format ) ;
// Connect the signals to update which days have CPAP data when the month is changed
connect ( ui - > dateStart - > calendarWidget ( ) , SIGNAL ( currentPageChanged ( int , int ) ) , SLOT ( dateStart_currentPageChanged ( int , int ) ) ) ;
connect ( ui - > dateEnd - > calendarWidget ( ) , SIGNAL ( currentPageChanged ( int , int ) ) , SLOT ( dateEnd_currentPageChanged ( int , int ) ) ) ;
// Create the horizontal layout to hold the GraphView object and it's scrollbar
2011-09-07 08:35:55 +00:00
layout = new QHBoxLayout ( ui - > graphArea ) ;
2011-10-31 11:55:25 +00:00
layout - > setSpacing ( 0 ) ; // remove the ugly margins/spacing
2011-09-07 08:35:55 +00:00
layout - > setMargin ( 0 ) ;
layout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
ui - > graphArea - > setLayout ( layout ) ;
ui - > graphArea - > setAutoFillBackground ( false ) ;
2011-10-31 11:55:25 +00:00
// Create the GraphView Object
2011-09-07 08:35:55 +00:00
GraphView = new gGraphView ( ui - > graphArea , m_shared ) ;
GraphView - > setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Expanding ) ;
2011-12-25 16:56:22 +00:00
GraphView - > setEmptyText ( " No Data " ) ;
2011-12-20 17:22:02 +00:00
GraphView - > setCubeImage ( images [ " nodata " ] ) ;
2011-10-31 11:55:25 +00:00
// Create the custom scrollbar and attach to GraphView
2011-09-07 08:35:55 +00:00
scrollbar = new MyScrollBar ( ui - > graphArea ) ;
scrollbar - > setOrientation ( Qt : : Vertical ) ;
scrollbar - > setSizePolicy ( QSizePolicy : : Maximum , QSizePolicy : : Expanding ) ;
scrollbar - > setMaximumWidth ( 20 ) ;
GraphView - > setScrollBar ( scrollbar ) ;
2011-10-31 11:55:25 +00:00
2011-12-20 17:22:02 +00:00
2011-10-31 11:55:25 +00:00
// Add the graphView and scrollbar to the layout.
2011-09-07 08:35:55 +00:00
layout - > addWidget ( GraphView , 1 ) ;
layout - > addWidget ( scrollbar , 0 ) ;
layout - > layout ( ) ;
2011-10-31 11:55:25 +00:00
// TODO: Automate graph creation process
2012-01-10 10:00:08 +00:00
ChannelID ahicode = PROFILE . general - > calculateRDI ( ) ? CPAP_RDI : CPAP_AHI ;
2011-10-31 11:55:25 +00:00
2012-01-10 10:00:08 +00:00
if ( ahicode = = CPAP_RDI )
2011-12-24 05:55:44 +00:00
AHI = createGraph ( tr ( " RDI " ) , " Respiratory \n Disturbance \n Index " ) ;
else
AHI = createGraph ( tr ( " AHI " ) , tr ( " Apnea \n Hypopnea \n Index " ) ) ;
2012-01-10 10:00:08 +00:00
2011-12-24 05:55:44 +00:00
UC = createGraph ( tr ( " Usage " ) , tr ( " Usage \n (hours) " ) ) ;
2011-11-30 06:01:38 +00:00
2011-12-21 04:25:01 +00:00
US = createGraph ( tr ( " Session Times " ) , tr ( " Session Times \n (hours) " ) , YT_Time ) ;
2012-01-01 14:14:18 +00:00
PR = createGraph ( STR_TR_Pressure , tr ( " Pressure \n (cmH2O) " ) ) ;
2011-12-18 16:39:36 +00:00
SET = createGraph ( tr ( " Settings " ) , ( " Settings " ) ) ;
2012-01-12 06:24:36 +00:00
LK = createGraph ( tr ( " Leaks " ) , tr ( " Unintentional Leaks \n (L/min) " ) ) ;
TOTLK = createGraph ( tr ( " Total Leaks " ) , tr ( " Total Leaks \n (L/min) " ) ) ;
2011-12-18 16:39:36 +00:00
NPB = createGraph ( tr ( " % in PB " ) , tr ( " Periodic \n Breathing \n (% of night) " ) ) ;
2012-01-10 10:00:08 +00:00
if ( ahicode = = CPAP_RDI ) {
AHIHR = createGraph ( tr ( " Peak RDI " ) , tr ( " Peak RDI \n Shows RDI Clusters \n (RDI/hr) " ) ) ;
} else {
AHIHR = createGraph ( tr ( " Peak AHI " ) , tr ( " Peak AHI \n Shows AHI Clusters \n (AHI/hr) " ) ) ;
}
2011-12-18 16:39:36 +00:00
RR = createGraph ( tr ( " Resp. Rate " ) , tr ( " Respiratory \n Rate \n (breaths/min) " ) ) ;
TV = createGraph ( tr ( " Tidal Volume " ) , tr ( " Tidal \n Volume \n (ml) " ) ) ;
MV = createGraph ( tr ( " Minute Vent. " ) , tr ( " Minute \n Ventilation \n (L/min) " ) ) ;
2012-01-01 15:47:21 +00:00
TGMV = createGraph ( tr ( " Target Vent. " ) , tr ( " Target \n Ventilation \n (L/min) " ) ) ;
2011-12-18 16:39:36 +00:00
PTB = createGraph ( tr ( " Pat. Trig. Br. " ) , tr ( " Patient \n Triggered \n Breaths \n (%) " ) ) ;
SES = createGraph ( tr ( " Sessions " ) , tr ( " Sessions \n (count) " ) ) ;
PULSE = createGraph ( tr ( " Pulse Rate " ) , tr ( " Pulse Rate \n (bpm) " ) ) ;
2011-12-25 05:05:12 +00:00
SPO2 = createGraph ( STR_TR_SpO2 , tr ( " Oxygen Saturation \n (%) " ) ) ;
2011-12-21 05:47:33 +00:00
2011-12-21 14:24:09 +00:00
WEIGHT = createGraph ( STR_TR_Weight , STR_TR_Weight , YT_Weight ) ;
BMI = createGraph ( STR_TR_BMI , tr ( " Body \n Mass \n Index " ) ) ;
2011-12-18 16:39:36 +00:00
ZOMBIE = createGraph ( tr ( " Zombie " ) , tr ( " How you felt \n (0-10) " ) ) ;
2012-01-10 10:00:08 +00:00
ahihr = new SummaryChart ( tr ( " Events/Hr " ) , GT_LINE ) ;
ahihr - > addSlice ( ahicode , QColor ( " blue " ) , ST_MAX ) ;
ahihr - > addSlice ( ahicode , QColor ( " orange " ) , ST_WAVG ) ;
2011-12-06 14:39:14 +00:00
AHIHR - > AddLayer ( ahihr ) ;
2011-12-21 14:24:09 +00:00
weight = new SummaryChart ( STR_TR_Weight , GT_LINE ) ;
2011-12-02 12:05:57 +00:00
weight - > setMachineType ( MT_JOURNAL ) ;
2012-01-03 05:40:35 +00:00
weight - > addSlice ( Journal_Weight , QColor ( " black " ) , ST_SETAVG ) ;
2011-12-02 12:05:57 +00:00
WEIGHT - > AddLayer ( weight ) ;
2011-12-21 14:24:09 +00:00
bmi = new SummaryChart ( STR_TR_BMI , GT_LINE ) ;
2011-12-03 19:13:55 +00:00
bmi - > setMachineType ( MT_JOURNAL ) ;
2012-01-03 05:40:35 +00:00
bmi - > addSlice ( Journal_BMI , QColor ( " dark blue " ) , ST_SETAVG ) ;
2011-12-03 19:13:55 +00:00
BMI - > AddLayer ( bmi ) ;
2011-12-18 16:39:36 +00:00
zombie = new SummaryChart ( tr ( " Zombie Meter " ) , GT_LINE ) ;
2011-12-02 12:05:57 +00:00
zombie - > setMachineType ( MT_JOURNAL ) ;
2012-01-03 05:40:35 +00:00
zombie - > addSlice ( Journal_ZombieMeter , QColor ( " dark red " ) , ST_SETAVG ) ;
2011-12-02 12:05:57 +00:00
ZOMBIE - > AddLayer ( zombie ) ;
2011-12-01 00:18:59 +00:00
2011-12-18 16:39:36 +00:00
pulse = new SummaryChart ( tr ( " Pulse Rate " ) , GT_LINE ) ;
2011-12-01 00:18:59 +00:00
pulse - > setMachineType ( MT_OXIMETER ) ;
2012-01-03 05:40:35 +00:00
pulse - > addSlice ( OXI_Pulse , QColor ( " red " ) , ST_WAVG ) ;
pulse - > addSlice ( OXI_Pulse , QColor ( " pink " ) , ST_MIN ) ;
pulse - > addSlice ( OXI_Pulse , QColor ( " orange " ) , ST_MAX ) ;
2011-12-01 00:18:59 +00:00
PULSE - > AddLayer ( pulse ) ;
2011-12-25 05:05:12 +00:00
spo2 = new SummaryChart ( STR_TR_SpO2 , GT_LINE ) ;
2011-12-01 00:18:59 +00:00
spo2 - > setMachineType ( MT_OXIMETER ) ;
2012-01-03 05:40:35 +00:00
spo2 - > addSlice ( OXI_SPO2 , QColor ( " cyan " ) , ST_WAVG ) ;
spo2 - > addSlice ( OXI_SPO2 , QColor ( " light blue " ) , ST_PERC , 0.95 ) ;
spo2 - > addSlice ( OXI_SPO2 , QColor ( " blue " ) , ST_MIN ) ;
2011-12-01 00:18:59 +00:00
SPO2 - > AddLayer ( spo2 ) ;
2011-09-08 18:38:07 +00:00
2011-12-21 14:24:09 +00:00
uc = new SummaryChart ( STR_UNIT_Hours , GT_BAR ) ;
2012-01-03 05:40:35 +00:00
uc - > addSlice ( NoChannel , QColor ( " green " ) , ST_HOURS ) ;
2011-09-07 08:35:55 +00:00
UC - > AddLayer ( uc ) ;
2011-12-21 14:24:09 +00:00
us = new SummaryChart ( STR_UNIT_Hours , GT_SESSIONS ) ;
2012-01-03 05:40:35 +00:00
us - > addSlice ( NoChannel , QColor ( " dark blue " ) , ST_HOURS ) ;
us - > addSlice ( NoChannel , QColor ( " blue " ) , ST_SESSIONS ) ;
2011-11-30 06:01:38 +00:00
US - > AddLayer ( us ) ;
2011-12-18 16:39:36 +00:00
ses = new SummaryChart ( tr ( " Sessions " ) , GT_LINE ) ;
2012-01-03 05:40:35 +00:00
ses - > addSlice ( NoChannel , QColor ( " blue " ) , ST_SESSIONS ) ;
2011-10-30 15:25:53 +00:00
SES - > AddLayer ( ses ) ;
2011-09-07 08:35:55 +00:00
2012-01-10 10:00:08 +00:00
if ( ahicode = = CPAP_RDI )
2011-12-24 05:55:44 +00:00
bc = new SummaryChart ( tr ( " RDI " ) , GT_BAR ) ;
else
bc = new SummaryChart ( tr ( " AHI " ) , GT_BAR ) ;
2012-01-03 05:40:35 +00:00
bc - > addSlice ( CPAP_Hypopnea , QColor ( " blue " ) , ST_CPH ) ;
bc - > addSlice ( CPAP_Apnea , QColor ( " dark green " ) , ST_CPH ) ;
bc - > addSlice ( CPAP_Obstructive , QColor ( " #40c0ff " ) , ST_CPH ) ;
bc - > addSlice ( CPAP_ClearAirway , QColor ( " purple " ) , ST_CPH ) ;
2011-12-24 05:55:44 +00:00
if ( PROFILE . general - > calculateRDI ( ) ) {
2012-01-03 05:40:35 +00:00
bc - > addSlice ( CPAP_RERA , QColor ( " gold " ) , ST_CPH ) ;
2011-12-24 05:55:44 +00:00
}
2011-09-07 08:35:55 +00:00
AHI - > AddLayer ( bc ) ;
2011-10-05 07:41:56 +00:00
set = new SummaryChart ( " " , GT_LINE ) ;
2011-12-21 17:00:19 +00:00
//set->addSlice(PRS1_SysOneResistSet,QColor("grey"),ST_SETAVG);
2012-01-03 05:40:35 +00:00
set - > addSlice ( PRS1_HumidSetting , QColor ( " blue " ) , ST_SETWAVG ) ;
set - > addSlice ( CPAP_PresReliefSet , QColor ( " red " ) , ST_SETWAVG ) ;
//set->addSlice(RMS9_EPRSet,QColor("green"),ST_SETWAVG);
//set->addSlice(INTP_SmartFlex,QColor("purple"),ST_SETWAVG);
2011-09-18 15:43:14 +00:00
SET - > AddLayer ( set ) ;
2011-09-08 18:38:07 +00:00
2011-12-18 16:39:36 +00:00
rr = new SummaryChart ( tr ( " breaths/min " ) , GT_LINE ) ;
2012-01-03 05:40:35 +00:00
rr - > addSlice ( CPAP_RespRate , QColor ( " light blue " ) , ST_MIN ) ;
rr - > addSlice ( CPAP_RespRate , QColor ( " blue " ) , ST_PERC , 0.5 ) ;
rr - > addSlice ( CPAP_RespRate , QColor ( " light green " ) , ST_PERC , 0.95 ) ;
rr - > addSlice ( CPAP_RespRate , QColor ( " green " ) , ST_PERC , 0.999 ) ;
// rr->addSlice(CPAP_RespRate,QColor("green"),ST_MAX);
2011-11-28 04:05:09 +00:00
RR - > AddLayer ( rr ) ;
2011-12-18 16:39:36 +00:00
tv = new SummaryChart ( tr ( " L/b " ) , GT_LINE ) ;
2012-01-03 05:40:35 +00:00
tv - > addSlice ( CPAP_TidalVolume , QColor ( " light blue " ) , ST_MIN ) ;
tv - > addSlice ( CPAP_TidalVolume , QColor ( " blue " ) , ST_PERC , 0.5 ) ;
tv - > addSlice ( CPAP_TidalVolume , QColor ( " light green " ) , ST_PERC , 0.95 ) ;
tv - > addSlice ( CPAP_TidalVolume , QColor ( " green " ) , ST_PERC , 0.999 ) ;
2011-11-30 15:19:31 +00:00
TV - > AddLayer ( tv ) ;
2011-12-18 16:39:36 +00:00
mv = new SummaryChart ( tr ( " L/m " ) , GT_LINE ) ;
2012-01-03 05:40:35 +00:00
mv - > addSlice ( CPAP_MinuteVent , QColor ( " light blue " ) , ST_MIN ) ;
mv - > addSlice ( CPAP_MinuteVent , QColor ( " blue " ) , ST_PERC , 0.5 ) ;
mv - > addSlice ( CPAP_MinuteVent , QColor ( " light green " ) , ST_PERC , 0.95 ) ;
mv - > addSlice ( CPAP_MinuteVent , QColor ( " green " ) , ST_PERC , 0.999 ) ;
2011-11-30 15:19:31 +00:00
MV - > AddLayer ( mv ) ;
2012-01-01 15:47:21 +00:00
tgmv = new SummaryChart ( tr ( " L/m " ) , GT_LINE ) ;
2012-01-03 05:40:35 +00:00
tgmv - > addSlice ( CPAP_TgMV , QColor ( " light blue " ) , ST_MIN ) ;
tgmv - > addSlice ( CPAP_TgMV , QColor ( " blue " ) , ST_PERC , 0.5 ) ;
tgmv - > addSlice ( CPAP_TgMV , QColor ( " light green " ) , ST_PERC , 0.95 ) ;
tgmv - > addSlice ( CPAP_TgMV , QColor ( " green " ) , ST_PERC , 0.999 ) ;
2012-01-01 15:47:21 +00:00
TGMV - > AddLayer ( tgmv ) ;
2011-12-18 16:39:36 +00:00
ptb = new SummaryChart ( tr ( " %PTB " ) , GT_LINE ) ;
2012-01-03 05:40:35 +00:00
ptb - > addSlice ( CPAP_PTB , QColor ( " yellow " ) , ST_MIN ) ;
ptb - > addSlice ( CPAP_PTB , QColor ( " blue " ) , ST_PERC , 0.5 ) ;
ptb - > addSlice ( CPAP_PTB , QColor ( " light gray " ) , ST_PERC , 0.95 ) ;
ptb - > addSlice ( CPAP_PTB , QColor ( " orange " ) , ST_WAVG ) ;
2011-11-30 15:19:31 +00:00
PTB - > AddLayer ( ptb ) ;
2012-01-01 14:14:18 +00:00
pr = new SummaryChart ( STR_TR_Pressure , GT_LINE ) ;
2011-11-27 16:07:28 +00:00
//PR->setRecMinY(4.0);
//PR->setRecMaxY(12.0);
2011-12-24 05:55:44 +00:00
2012-01-10 07:37:15 +00:00
//CPAPMode mode=(CPAPMode)(int)PROFILE.calcSettingsMax(CPAP_Mode,MT_CPAP,PROFILE.FirstDay(MT_CPAP),PROFILE.LastDay(MT_CPAP));
2011-12-25 05:05:12 +00:00
2012-01-01 14:14:18 +00:00
// //if (mode>=MODE_BIPAP) {
// pr->addSlice(CPAP_EPAP,QColor("green"),ST_SETMIN,true);
// pr->addSlice(CPAP_EPAP,QColor("light green"),ST_PERC,true,0.95);
// pr->addSlice(CPAP_IPAP,QColor("light blue"),ST_PERC,true,0.95);
// pr->addSlice(CPAP_IPAP,QColor("blue"),ST_SETMAX,true);
// //} else if (mode>MODE_CPAP) {
// pr->addSlice(CPAP_PressureMin,QColor("orange"),ST_SETMIN,true);
// pr->addSlice(CPAP_Pressure,QColor("dark green"),ST_WAVG,true);
// //pr->addSlice(CPAP_Pressure,QColor("grey"),ST_90P,true);
// pr->addSlice(CPAP_Pressure,QColor("grey"),ST_PERC,true,0.95);
// pr->addSlice(CPAP_PressureMax,QColor("red"),ST_SETMAX,true);
// //} else {
// pr->addSlice(CPAP_Pressure,QColor("dark green"),ST_SETWAVG,true);
// //}
2011-09-08 18:38:07 +00:00
PR - > AddLayer ( pr ) ;
2012-01-03 07:15:02 +00:00
lk = new SummaryChart ( tr ( " Leaks " ) , GT_LINE ) ;
2012-01-03 05:40:35 +00:00
lk - > addSlice ( CPAP_Leak , QColor ( " light blue " ) , ST_PERC , 0.5 ) ;
lk - > addSlice ( CPAP_Leak , QColor ( " dark grey " ) , ST_PERC , 0.95 ) ;
//lk->addSlice(CPAP_Leak,QColor("dark blue"),ST_WAVG);
lk - > addSlice ( CPAP_Leak , QColor ( " grey " ) , ST_PERC , 0.999 ) ;
2011-09-08 18:38:07 +00:00
//lk->addSlice(CPAP_Leak,QColor("dark yellow"));
LK - > AddLayer ( lk ) ;
2012-01-12 06:24:36 +00:00
totlk = new SummaryChart ( tr ( " Total Leaks " ) , GT_LINE ) ;
totlk - > addSlice ( CPAP_LeakTotal , QColor ( " light blue " ) , ST_PERC , 0.5 ) ;
totlk - > addSlice ( CPAP_LeakTotal , QColor ( " dark grey " ) , ST_PERC , 0.95 ) ;
totlk - > addSlice ( CPAP_LeakTotal , QColor ( " grey " ) , ST_PERC , 0.999 ) ;
//tot->addSlice(CPAP_Leak,QColor("dark blue"),ST_WAVG);
//tot->addSlice(CPAP_Leak,QColor("dark yellow"));
TOTLK - > AddLayer ( totlk ) ;
2011-12-18 16:39:36 +00:00
NPB - > AddLayer ( npb = new SummaryChart ( tr ( " % PB " ) , GT_BAR ) ) ;
2012-01-03 05:40:35 +00:00
npb - > addSlice ( CPAP_CSR , QColor ( " light green " ) , ST_SPH ) ;
2011-10-31 11:55:25 +00:00
// <--- The code to the previous marker is crap
2011-09-11 06:16:45 +00:00
2011-12-18 16:39:36 +00:00
GraphView - > LoadSettings ( " Overview " ) ; //no trans
2011-12-25 06:24:40 +00:00
ui - > rangeCombo - > setCurrentIndex ( 6 ) ;
2012-01-03 11:12:13 +00:00
icon_on = new QIcon ( " :/icons/session-on.png " ) ;
icon_off = new QIcon ( " :/icons/session-off.png " ) ;
2012-01-10 11:10:52 +00:00
SES - > setRecMinY ( 1 ) ;
SET - > setRecMinY ( 0 ) ;
SET - > setRecMaxY ( 5 ) ;
2011-09-07 08:44:04 +00:00
}
Overview : : ~ Overview ( )
{
2011-12-18 16:39:36 +00:00
GraphView - > SaveSettings ( " Overview " ) ; //no trans
2011-10-05 08:09:57 +00:00
disconnect ( this , SLOT ( dateStart_currentPageChanged ( int , int ) ) ) ;
disconnect ( this , SLOT ( dateEnd_currentPageChanged ( int , int ) ) ) ;
2011-09-07 08:44:04 +00:00
delete ui ;
2012-01-03 11:12:13 +00:00
delete icon_on ;
delete icon_off ;
2011-09-07 08:44:04 +00:00
}
2011-12-21 04:25:01 +00:00
gGraph * Overview : : createGraph ( QString name , QString units , YTickerType yttype )
2011-10-31 11:55:25 +00:00
{
2011-12-21 12:47:47 +00:00
int default_height = PROFILE . appearance - > graphHeight ( ) ;
2011-12-05 08:32:46 +00:00
gGraph * g = new gGraph ( GraphView , name , units , default_height , 0 ) ;
2011-12-21 04:25:01 +00:00
gYAxis * yt ;
switch ( yttype ) {
case YT_Time :
yt = new gYAxisTime ( true ) ; // Time scale
break ;
case YT_Weight :
2011-12-21 12:47:47 +00:00
yt = new gYAxisWeight ( PROFILE . general - > unitSystem ( ) ) ;
2011-12-21 04:25:01 +00:00
break ;
default :
yt = new gYAxis ( ) ; // Plain numeric scale
break ;
}
g - > AddLayer ( yt , LayerLeft , gYAxis : : Margin ) ;
2011-10-31 11:55:25 +00:00
gXAxis * x = new gXAxis ( ) ;
x - > setUtcFix ( true ) ;
g - > AddLayer ( x , LayerBottom , 0 , gXAxis : : Margin ) ;
g - > AddLayer ( new gXGrid ( ) ) ;
return g ;
}
2011-09-07 08:44:04 +00:00
void Overview : : ReloadGraphs ( )
{
2011-09-08 18:38:07 +00:00
GraphView - > setDay ( NULL ) ;
2012-01-03 14:59:15 +00:00
updateCube ( ) ;
2011-12-25 06:24:40 +00:00
on_rangeCombo_activated ( ui - > rangeCombo - > currentIndex ( ) ) ;
2011-06-26 08:30:44 +00:00
}
2011-09-23 03:54:48 +00:00
2012-01-03 11:12:13 +00:00
void Overview : : updateGraphCombo ( )
{
ui - > graphCombo - > clear ( ) ;
gGraph * g ;
2012-01-03 14:59:15 +00:00
// ui->graphCombo->addItem("Show All Graphs");
// ui->graphCombo->addItem("Hide All Graphs");
// ui->graphCombo->addItem("---------------");
2012-01-03 11:12:13 +00:00
for ( int i = 0 ; i < GraphView - > size ( ) ; i + + ) {
g = ( * GraphView ) [ i ] ;
2012-01-03 12:03:37 +00:00
if ( g - > isEmpty ( ) ) continue ;
2012-01-03 11:12:13 +00:00
if ( g - > visible ( ) ) {
ui - > graphCombo - > addItem ( * icon_on , g - > title ( ) , true ) ;
} else {
ui - > graphCombo - > addItem ( * icon_off , g - > title ( ) , false ) ;
}
}
2012-01-03 14:59:15 +00:00
ui - > graphCombo - > setCurrentIndex ( 0 ) ;
updateCube ( ) ;
2012-01-03 11:12:13 +00:00
}
2011-12-25 13:27:47 +00:00
void Overview : : ResetGraphs ( )
{
2012-01-05 15:17:50 +00:00
//qint64 st,et;
//GraphView->GetXBounds(st,et);
2011-12-25 13:27:47 +00:00
QDate start = ui - > dateStart - > date ( ) ;
QDate end = ui - > dateEnd - > date ( ) ;
GraphView - > setDay ( NULL ) ;
2012-01-03 14:59:15 +00:00
updateCube ( ) ;
2011-12-25 13:27:47 +00:00
if ( start . isValid ( ) & & end . isValid ( ) ) {
setRange ( start , end ) ;
}
2012-01-05 15:17:50 +00:00
//GraphView->SetXBounds(st,et);
}
void Overview : : ResetGraph ( QString name )
{
gGraph * g = GraphView - > findGraph ( name ) ;
if ( ! g ) return ;
g - > setDay ( NULL ) ;
GraphView - > redraw ( ) ;
2011-12-25 13:27:47 +00:00
}
2011-09-23 03:54:48 +00:00
void Overview : : RedrawGraphs ( )
{
2011-12-20 11:12:52 +00:00
GraphView - > redraw ( ) ;
2011-09-23 03:54:48 +00:00
}
2011-09-12 03:07:57 +00:00
void Overview : : UpdateCalendarDay ( QDateEdit * dateedit , QDate date )
{
QCalendarWidget * calendar = dateedit - > calendarWidget ( ) ;
QTextCharFormat bold ;
QTextCharFormat cpapcol ;
QTextCharFormat normal ;
QTextCharFormat oxiday ;
bold . setFontWeight ( QFont : : Bold ) ;
cpapcol . setForeground ( QBrush ( Qt : : blue , Qt : : SolidPattern ) ) ;
cpapcol . setFontWeight ( QFont : : Bold ) ;
oxiday . setForeground ( QBrush ( Qt : : red , Qt : : SolidPattern ) ) ;
oxiday . setFontWeight ( QFont : : Bold ) ;
2011-10-31 11:55:25 +00:00
bool hascpap = p_profile - > GetDay ( date , MT_CPAP ) ! = NULL ;
bool hasoxi = p_profile - > GetDay ( date , MT_OXIMETER ) ! = NULL ;
//bool hasjournal=p_profile->GetDay(date,MT_JOURNAL)!=NULL;
2011-09-12 03:07:57 +00:00
if ( hascpap ) {
if ( hasoxi ) {
calendar - > setDateTextFormat ( date , oxiday ) ;
} else {
calendar - > setDateTextFormat ( date , cpapcol ) ;
}
2011-10-05 07:41:56 +00:00
} else if ( p_profile - > GetDay ( date ) ) {
2011-09-12 03:07:57 +00:00
calendar - > setDateTextFormat ( date , bold ) ;
} else {
calendar - > setDateTextFormat ( date , normal ) ;
}
calendar - > setHorizontalHeaderFormat ( QCalendarWidget : : ShortDayNames ) ;
}
2011-10-05 08:09:57 +00:00
void Overview : : dateStart_currentPageChanged ( int year , int month )
2011-09-12 03:07:57 +00:00
{
QDate d ( year , month , 1 ) ;
int dom = d . daysInMonth ( ) ;
for ( int i = 1 ; i < = dom ; i + + ) {
d = QDate ( year , month , i ) ;
UpdateCalendarDay ( ui - > dateStart , d ) ;
}
}
2011-10-05 08:09:57 +00:00
void Overview : : dateEnd_currentPageChanged ( int year , int month )
2011-09-12 03:07:57 +00:00
{
QDate d ( year , month , 1 ) ;
int dom = d . daysInMonth ( ) ;
for ( int i = 1 ; i < = dom ; i + + ) {
d = QDate ( year , month , i ) ;
UpdateCalendarDay ( ui - > dateEnd , d ) ;
}
}
2011-06-26 08:30:44 +00:00
2011-09-11 06:16:45 +00:00
void Overview : : on_dateEnd_dateChanged ( const QDate & date )
2011-07-02 09:49:53 +00:00
{
2011-12-25 13:58:07 +00:00
qint64 d1 = qint64 ( QDateTime ( ui - > dateStart - > date ( ) , QTime ( 0 , 10 , 0 ) , Qt : : UTC ) . toTime_t ( ) ) * 1000L ;
qint64 d2 = qint64 ( QDateTime ( date , QTime ( 23 , 0 , 0 ) , Qt : : UTC ) . toTime_t ( ) ) * 1000L ;
2011-09-11 06:16:45 +00:00
GraphView - > SetXBounds ( d1 , d2 ) ;
2012-01-04 01:28:03 +00:00
ui - > dateStart - > setMaximumDate ( date ) ;
2011-06-26 08:30:44 +00:00
}
2011-09-11 06:16:45 +00:00
void Overview : : on_dateStart_dateChanged ( const QDate & date )
2011-06-26 08:30:44 +00:00
{
2011-12-25 13:58:07 +00:00
qint64 d1 = qint64 ( QDateTime ( date , QTime ( 0 , 10 , 0 ) , Qt : : UTC ) . toTime_t ( ) ) * 1000L ;
qint64 d2 = qint64 ( QDateTime ( ui - > dateEnd - > date ( ) , QTime ( 23 , 0 , 0 ) , Qt : : UTC ) . toTime_t ( ) ) * 1000L ;
2011-09-11 06:16:45 +00:00
GraphView - > SetXBounds ( d1 , d2 ) ;
2012-01-04 01:28:03 +00:00
ui - > dateEnd - > setMinimumDate ( date ) ;
2011-06-26 08:30:44 +00:00
}
2011-09-11 06:16:45 +00:00
void Overview : : on_toolButton_clicked ( )
2011-06-26 08:30:44 +00:00
{
2011-12-25 13:43:11 +00:00
qint64 d1 = qint64 ( QDateTime ( ui - > dateStart - > date ( ) , QTime ( 0 , 10 , 0 ) , Qt : : UTC ) . toTime_t ( ) ) * 1000L ;
2011-12-25 13:58:07 +00:00
qint64 d2 = qint64 ( QDateTime ( ui - > dateEnd - > date ( ) , QTime ( 23 , 00 , 0 ) , Qt : : UTC ) . toTime_t ( ) ) * 1000L ;
2011-09-11 06:16:45 +00:00
GraphView - > SetXBounds ( d1 , d2 ) ;
2011-06-26 08:30:44 +00:00
}
2011-12-25 13:27:47 +00:00
//void Overview::on_printButton_clicked()
//{
// mainwin->PrintReport(GraphView,STR_TR_Overview); // Must be translated the same as PrintReport checks.
//}
2011-09-12 16:10:18 +00:00
2011-09-12 17:47:37 +00:00
void Overview : : ResetGraphLayout ( )
{
GraphView - > resetLayout ( ) ;
}
2011-12-01 15:40:32 +00:00
2011-12-25 06:24:40 +00:00
2012-01-05 04:37:22 +00:00
/*void Overview::on_printDailyButton_clicked()
2011-12-25 06:24:40 +00:00
{
qint64 st , et ;
GraphView - > GetXBounds ( st , et ) ;
QDate s1 = QDateTime : : fromTime_t ( st / 1000L ) . date ( ) ;
QDate s2 = QDateTime : : fromTime_t ( et / 1000L ) . date ( ) ;
int len = PROFILE . countDays ( MT_UNKNOWN , s1 , s2 ) ;
if ( len > 7 ) {
if ( QMessageBox : : question ( this , " Woah! " , " Do you really want to print " + QString : : number ( len ) + " days worth of Daily reports, \n from " + s1 . toString ( Qt : : SystemLocaleShortDate ) + " to " + s2 . toString ( Qt : : SystemLocaleShortDate ) + " ? " , QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : No ) {
return ;
}
if ( len > 14 ) {
int weeks = len / 7 ;
if ( QMessageBox : : question ( this , " Hold Up! " , " We are talking about over " + QString : : number ( weeks ) + " weeks of information. \n \n This will likely take a very long time, and a heck of a lot of paper if your not printing to a PDF file. \n \n Are you really sure? " , QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : No ) {
return ;
}
if ( len > 31 ) {
if ( QMessageBox : : question ( this , " Are you serious!!?? " , " We are talking about printing a lot of information. \n \n If your not printing to a PDF file, you must really hate trees. \n \n Are you really REALLY sure? " , QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : No ) {
return ;
}
}
}
mainwin - > Notify ( " I'm not going to nag you any more, but it would probably help if I implemented this feature.. ;) " ) ;
} else mainwin - > Notify ( " If this was implemented yet, You'd be able to print multiple daily reports right now. " ) ;
2012-01-05 04:37:22 +00:00
} */
2011-12-25 06:24:40 +00:00
void Overview : : on_rangeCombo_activated ( int index )
{
2012-01-04 01:28:03 +00:00
ui - > dateStart - > setMinimumDate ( PROFILE . FirstDay ( ) ) ;
ui - > dateEnd - > setMaximumDate ( PROFILE . LastDay ( ) ) ;
2011-12-25 06:24:40 +00:00
QDate end = PROFILE . LastDay ( ) ;
QDate start ;
2012-01-04 01:28:03 +00:00
if ( index = = 8 ) { // Custom
ui - > dateStartLabel - > setEnabled ( true ) ;
ui - > dateEndLabel - > setEnabled ( true ) ;
ui - > dateEnd - > setEnabled ( true ) ;
ui - > dateStart - > setEnabled ( true ) ;
ui - > dateStart - > setMaximumDate ( ui - > dateEnd - > date ( ) ) ;
ui - > dateEnd - > setMinimumDate ( ui - > dateStart - > date ( ) ) ;
return ;
}
ui - > dateEnd - > setEnabled ( false ) ;
ui - > dateStart - > setEnabled ( false ) ;
ui - > dateStartLabel - > setEnabled ( false ) ;
ui - > dateEndLabel - > setEnabled ( false ) ;
2011-12-25 06:24:40 +00:00
if ( index = = 0 ) {
start = end . addDays ( - 6 ) ;
} else if ( index = = 1 ) {
start = end . addDays ( - 13 ) ;
} else if ( index = = 2 ) {
start = end . addMonths ( - 1 ) . addDays ( 1 ) ;
} else if ( index = = 3 ) {
start = end . addMonths ( - 2 ) . addDays ( 1 ) ;
} else if ( index = = 4 ) {
start = end . addMonths ( - 3 ) . addDays ( 1 ) ;
} else if ( index = = 5 ) {
start = end . addMonths ( - 6 ) . addDays ( 1 ) ;
} else if ( index = = 6 ) {
start = end . addYears ( - 1 ) . addDays ( 1 ) ;
2012-01-04 01:28:03 +00:00
} else if ( index = = 7 ) { // Everything
start = PROFILE . FirstDay ( ) ;
2011-12-25 06:24:40 +00:00
}
if ( start < PROFILE . FirstDay ( ) ) start = PROFILE . FirstDay ( ) ;
2011-12-25 13:27:47 +00:00
setRange ( start , end ) ;
}
void Overview : : setRange ( QDate start , QDate end )
{
ui - > dateEnd - > blockSignals ( true ) ;
ui - > dateStart - > blockSignals ( true ) ;
2012-01-09 17:06:03 +00:00
ui - > dateStart - > setMaximumDate ( end ) ;
ui - > dateEnd - > setMinimumDate ( start ) ;
2011-12-25 06:24:40 +00:00
ui - > dateStart - > setDate ( start ) ;
2011-12-25 13:27:47 +00:00
ui - > dateEnd - > setDate ( end ) ;
ui - > dateEnd - > blockSignals ( false ) ;
ui - > dateStart - > blockSignals ( false ) ;
2011-12-25 06:24:40 +00:00
this - > on_toolButton_clicked ( ) ;
2012-01-03 11:12:13 +00:00
updateGraphCombo ( ) ;
}
void Overview : : on_graphCombo_activated ( int index )
{
if ( index < 0 )
return ;
2012-01-03 14:59:15 +00:00
gGraph * g ;
QString s ;
s = ui - > graphCombo - > currentText ( ) ;
2012-01-03 11:12:13 +00:00
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 ) ;
}
2012-01-03 14:59:15 +00:00
g = GraphView - > findGraph ( s ) ;
2012-01-03 12:03:37 +00:00
g - > setVisible ( b ) ;
2012-01-03 14:59:15 +00:00
updateCube ( ) ;
GraphView - > updateScale ( ) ;
GraphView - > redraw ( ) ;
}
void Overview : : updateCube ( )
{
if ( ( GraphView - > visibleGraphs ( ) = = 0 ) ) {
ui - > toggleVisibility - > setArrowType ( Qt : : UpArrow ) ;
ui - > toggleVisibility - > setToolTip ( tr ( " Show all graphs " ) ) ;
ui - > toggleVisibility - > blockSignals ( true ) ;
ui - > toggleVisibility - > setChecked ( true ) ;
ui - > toggleVisibility - > blockSignals ( false ) ;
if ( ui - > graphCombo - > count ( ) > 0 ) {
GraphView - > setEmptyText ( tr ( " No Graphs On! " ) ) ;
2012-01-06 16:07:54 +00:00
GraphView - > setCubeImage ( images [ " nographs " ] ) ;
2012-01-03 14:59:15 +00:00
} else {
GraphView - > setEmptyText ( " No Data " ) ;
GraphView - > setCubeImage ( images [ " nodata " ] ) ;
}
} else {
ui - > toggleVisibility - > setArrowType ( Qt : : DownArrow ) ;
ui - > toggleVisibility - > setToolTip ( tr ( " Hide all graphs " ) ) ;
ui - > toggleVisibility - > blockSignals ( true ) ;
ui - > toggleVisibility - > setChecked ( false ) ;
ui - > toggleVisibility - > blockSignals ( false ) ;
}
}
void Overview : : on_toggleVisibility_clicked ( bool checked )
{
gGraph * g ;
QString s ;
QIcon * icon = checked ? icon_off : icon_on ;
//ui->toggleVisibility->setArrowType(checked ? Qt::UpArrow : Qt::DownArrow);
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 ) ;
g = GraphView - > findGraph ( s ) ;
g - > setVisible ( ! checked ) ;
}
updateCube ( ) ;
2012-01-03 12:03:37 +00:00
GraphView - > updateScale ( ) ;
2012-01-03 11:12:13 +00:00
GraphView - > redraw ( ) ;
2011-12-25 06:24:40 +00:00
}