2011-06-28 15:25:20 +00:00
/*
2011-06-26 08:30:44 +00:00
MainWindow 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 <QGLFormat>
# include <QFileDialog>
# include <QMessageBox>
# include <QResource>
# include <QProgressBar>
2011-06-27 10:46:33 +00:00
# include <QWebHistory>
2011-12-27 13:21:10 +00:00
# include <QWebFrame>
2011-09-06 07:33:34 +00:00
# include <QNetworkRequest>
2011-12-26 03:06:39 +00:00
# include <QDesktopServices>
2011-09-06 07:33:34 +00:00
# include <QNetworkReply>
2011-06-27 06:26:29 +00:00
# include <QTimer>
2011-10-05 03:05:35 +00:00
# include <QSettings>
2011-11-08 15:47:54 +00:00
# include <QPixmap>
# include <QDesktopWidget>
2011-11-25 06:56:39 +00:00
# include <QListView>
2011-12-01 15:40:32 +00:00
# include <QPrinter>
2011-12-02 14:36:40 +00:00
# include <QPrintDialog>
2011-12-01 15:40:32 +00:00
# include <QPainter>
2011-12-03 05:27:57 +00:00
# include <QProcess>
2011-12-12 14:06:08 +00:00
# include <QFontMetrics>
2011-12-01 17:23:19 +00:00
# include <cmath>
2011-11-08 15:47:54 +00:00
2011-06-26 08:30:44 +00:00
# include "mainwindow.h"
# include "ui_mainwindow.h"
2011-10-02 03:38:51 +00:00
# include "newprofile.h"
2011-11-14 14:10:46 +00:00
# include "exportcsv.h"
2011-09-17 12:39:00 +00:00
# include "SleepLib/schema.h"
2011-06-26 08:30:44 +00:00
# include "Graphs/glcommon.h"
2011-12-16 18:15:57 +00:00
# include "UpdaterWindow.h"
2011-12-18 16:39:36 +00:00
# include "version.h"
2011-06-26 08:30:44 +00:00
QProgressBar * qprogress ;
QLabel * qstatus ;
2011-07-19 05:05:02 +00:00
QLabel * qstatus2 ;
2011-07-19 02:52:03 +00:00
QStatusBar * qstatusbar ;
2011-06-26 08:30:44 +00:00
2011-10-05 07:41:56 +00:00
extern Profile * profile ;
2011-07-17 15:57:45 +00:00
void MainWindow : : Log ( QString s )
{
2011-09-05 02:30:10 +00:00
2011-09-19 11:13:28 +00:00
if ( ! strlock . tryLock ( ) )
return ;
// strlock.lock();
2011-09-18 14:43:15 +00:00
QString tmp = QString ( " %1: %2 " ) . arg ( logtime . elapsed ( ) , 5 , 10 , QChar ( ' 0 ' ) ) . arg ( s ) ;
2011-09-05 02:30:10 +00:00
2011-09-18 14:43:15 +00:00
logbuffer . append ( tmp ) ; //QStringList appears not to be threadsafe
2011-09-05 02:30:10 +00:00
strlock . unlock ( ) ;
strlock . lock ( ) ;
2011-09-18 14:43:15 +00:00
// only do this in the main thread?
for ( int i = 0 ; i < logbuffer . size ( ) ; i + + )
ui - > logText - > appendPlainText ( logbuffer [ i ] ) ;
logbuffer . clear ( ) ;
2011-09-05 02:30:10 +00:00
strlock . unlock ( ) ;
2011-09-18 14:43:15 +00:00
//loglock.unlock();
2011-07-17 15:57:45 +00:00
}
2011-06-26 08:30:44 +00:00
MainWindow : : MainWindow ( QWidget * parent ) :
QMainWindow ( parent ) ,
ui ( new Ui : : MainWindow )
{
2011-10-05 07:41:56 +00:00
Q_ASSERT ( p_profile ! = NULL ) ;
2011-09-18 14:43:15 +00:00
logtime . start ( ) ;
2011-06-26 08:30:44 +00:00
ui - > setupUi ( this ) ;
2011-12-18 10:53:51 +00:00
2011-12-22 10:29:12 +00:00
QString version = VersionString ;
2011-11-08 15:03:39 +00:00
if ( QString ( GIT_BRANCH ) ! = " master " ) version + = QString ( " " ) + QString ( GIT_BRANCH ) ;
2011-12-21 14:24:09 +00:00
this - > setWindowTitle ( tr ( " SleepyHead " ) + QString ( " v%1 (Profile: %2) " ) . arg ( version ) . arg ( PREF [ STR_GEN_Profile ] . toString ( ) ) ) ;
2011-12-23 14:12:04 +00:00
//ui->tabWidget->setCurrentIndex(1);
2011-11-08 15:47:54 +00:00
2011-10-05 03:05:35 +00:00
overview = NULL ;
daily = NULL ;
oximetry = NULL ;
2011-10-21 05:50:31 +00:00
prefdialog = NULL ;
2011-07-22 13:46:17 +00:00
2011-12-18 10:53:51 +00:00
// Initialize Status Bar objects
2011-07-19 02:52:03 +00:00
qstatusbar = ui - > statusbar ;
2011-06-26 08:30:44 +00:00
qprogress = new QProgressBar ( this ) ;
qprogress - > setMaximum ( 100 ) ;
2011-07-19 05:05:02 +00:00
qstatus2 = new QLabel ( " Welcome " , this ) ;
qstatus2 - > setFrameStyle ( QFrame : : Raised ) ;
qstatus2 - > setFrameShadow ( QFrame : : Sunken ) ;
qstatus2 - > setFrameShape ( QFrame : : Box ) ;
//qstatus2->setMinimumWidth(100);
qstatus2 - > setMaximumWidth ( 100 ) ;
qstatus2 - > setAlignment ( Qt : : AlignRight | Qt : : AlignVCenter ) ;
2011-06-27 06:26:29 +00:00
qstatus = new QLabel ( " " , this ) ;
qprogress - > hide ( ) ;
2011-07-19 05:05:02 +00:00
ui - > statusbar - > setMinimumWidth ( 200 ) ;
ui - > statusbar - > addPermanentWidget ( qstatus , 0 ) ;
2011-07-30 02:08:19 +00:00
ui - > statusbar - > addPermanentWidget ( qprogress , 1 ) ;
2011-07-30 01:51:52 +00:00
ui - > statusbar - > addPermanentWidget ( qstatus2 , 0 ) ;
2011-07-22 13:46:17 +00:00
2011-12-21 12:47:47 +00:00
ui - > actionDebug - > setChecked ( PROFILE . general - > showDebug ( ) ) ;
2011-12-18 10:53:51 +00:00
2011-12-21 12:47:47 +00:00
if ( ! PROFILE . general - > showDebug ( ) ) {
2011-07-17 16:07:37 +00:00
ui - > logText - > hide ( ) ;
}
2011-12-21 12:47:47 +00:00
ui - > action_Link_Graph_Groups - > setChecked ( PROFILE . general - > linkGroups ( ) ) ;
2011-07-18 03:36:26 +00:00
2011-09-23 03:54:48 +00:00
first_load = true ;
2011-10-05 07:41:56 +00:00
// Using the dirty registry here. :(
2011-10-05 03:05:35 +00:00
QSettings settings ( " Jedimark " , " SleepyHead " ) ;
2011-12-18 10:53:51 +00:00
// Load previous Window geometry
2011-10-05 03:05:35 +00:00
this - > restoreGeometry ( settings . value ( " MainWindow/geometry " ) . toByteArray ( ) ) ;
2011-09-10 14:17:45 +00:00
2011-12-23 14:12:04 +00:00
daily = new Daily ( ui - > tabWidget , NULL ) ;
ui - > tabWidget - > insertTab ( 1 , daily , STR_TR_Daily ) ;
2011-12-25 16:19:08 +00:00
// Start with the Summary Tab
ui - > tabWidget - > setCurrentWidget ( ui - > summaryTab ) ; // setting this to daily shows the cube during loading..
2011-06-26 08:30:44 +00:00
2011-12-18 10:53:51 +00:00
// Nifty Notification popups in System Tray (uses Growl on Mac)
2011-10-21 07:06:06 +00:00
if ( QSystemTrayIcon : : isSystemTrayAvailable ( ) & & QSystemTrayIcon : : supportsMessages ( ) ) {
2011-12-29 05:43:47 +00:00
systray = new QSystemTrayIcon ( QIcon ( " :/icons/bob-v3.0.png " ) , this ) ;
2011-10-21 07:06:06 +00:00
systray - > show ( ) ;
systraymenu = new QMenu ( this ) ;
systray - > setContextMenu ( systraymenu ) ;
2011-12-22 10:29:12 +00:00
QAction * a = systraymenu - > addAction ( " SleepyHead v " + VersionString ) ;
2011-10-21 07:06:06 +00:00
a - > setEnabled ( false ) ;
systraymenu - > addSeparator ( ) ;
2011-12-21 12:47:47 +00:00
systraymenu - > addAction ( " &About " , this , SLOT ( on_action_About_triggered ( ) ) ) ;
systraymenu - > addAction ( " Check for &Updates " , this , SLOT ( on_actionCheck_for_Updates_triggered ( ) ) ) ;
2011-10-21 07:06:06 +00:00
systraymenu - > addSeparator ( ) ;
2011-12-21 12:47:47 +00:00
systraymenu - > addAction ( " E&xit " , this , SLOT ( close ( ) ) ) ;
2011-12-18 10:53:51 +00:00
} else { // if not available, the messages will popup in the taskbar
2011-10-21 07:06:06 +00:00
systray = NULL ;
systraymenu = NULL ;
}
2011-12-25 13:27:47 +00:00
ui - > toolBox - > setCurrentIndex ( 0 ) ;
2011-12-23 14:12:04 +00:00
daily - > graphView ( ) - > redraw ( ) ;
2011-12-25 13:27:47 +00:00
ui - > recordsBox - > page ( ) - > setLinkDelegationPolicy ( QWebPage : : DelegateAllLinks ) ;
2011-12-27 13:21:10 +00:00
ui - > summaryView - > page ( ) - > setLinkDelegationPolicy ( QWebPage : : DelegateAllLinks ) ;
2011-12-26 03:06:39 +00:00
ui - > webView - > page ( ) - > setLinkDelegationPolicy ( QWebPage : : DelegateExternalLinks ) ;
2011-12-25 15:00:10 +00:00
ui - > toolBox - > setStyleSheet (
" QToolBox::tab { "
" background: #6789ab; "
" color: lightGray;} "
" QToolBox { icon-size: 32px; } "
" QToolBox::tab:selected { "
" font: bold; "
" background: #9090ee; "
" color: white; } "
) ;
2011-12-28 14:03:09 +00:00
2011-12-25 15:00:10 +00:00
//"font-weight: bold; "
//"border-top-left-radius: 8px;"
//"border-top-right-radius: 8px;"
2011-12-25 13:27:47 +00:00
2011-12-25 16:56:22 +00:00
QString loadingtxt = " <HTML><body style='text-align: center; vertical-align: center'><table width='100%' height='100%'><tr><td align=center><h1>Loading...</h1></td></tr></table></body></HTML> " ;
ui - > summaryView - > setHtml ( loadingtxt ) ;
2011-12-26 19:25:17 +00:00
on_tabWidget_currentChanged ( 0 ) ;
2011-07-24 07:58:20 +00:00
}
extern MainWindow * mainwin ;
2011-06-26 08:30:44 +00:00
MainWindow : : ~ MainWindow ( )
{
2011-10-21 07:06:06 +00:00
if ( systraymenu ) delete systraymenu ;
2011-12-18 10:53:51 +00:00
if ( systray ) delete systray ;
2011-10-21 07:06:06 +00:00
2011-12-18 10:53:51 +00:00
// Save current window position
2011-10-05 03:05:35 +00:00
QSettings settings ( " Jedimark " , " SleepyHead " ) ;
settings . setValue ( " MainWindow/geometry " , saveGeometry ( ) ) ;
2011-12-18 10:53:51 +00:00
2011-06-26 08:30:44 +00:00
if ( daily ) {
daily - > close ( ) ;
delete daily ;
}
2011-09-07 08:35:55 +00:00
if ( overview ) {
2011-06-26 08:30:44 +00:00
overview - > close ( ) ;
delete overview ;
2011-09-07 08:35:55 +00:00
}
2011-07-13 05:27:27 +00:00
if ( oximetry ) {
oximetry - > close ( ) ;
delete oximetry ;
2011-07-29 14:58:44 +00:00
}
2011-12-18 10:53:51 +00:00
// Trash anything allocated by the Graph objects
2011-06-28 01:51:21 +00:00
DoneGraphs ( ) ;
2011-12-18 10:53:51 +00:00
// Shutdown and Save the current User profile
2011-06-26 08:30:44 +00:00
Profiles : : Done ( ) ;
2011-07-24 07:58:20 +00:00
mainwin = NULL ;
delete ui ;
2011-06-26 08:30:44 +00:00
}
2011-12-18 12:31:11 +00:00
2011-12-18 16:39:36 +00:00
void MainWindow : : Notify ( QString s , QString title , int ms )
2011-10-21 07:06:06 +00:00
{
if ( systray ) {
2011-12-16 16:31:58 +00:00
systray - > showMessage ( title , s , QSystemTrayIcon : : Information , ms ) ;
2011-10-21 07:06:06 +00:00
} else {
2011-12-03 08:52:24 +00:00
ui - > statusbar - > showMessage ( s , ms ) ;
2011-10-21 07:06:06 +00:00
}
}
2011-06-26 08:30:44 +00:00
2011-06-27 06:26:29 +00:00
void MainWindow : : Startup ( )
{
2011-12-22 10:29:12 +00:00
qDebug ( ) < < PREF [ " AppName " ] . toString ( ) . toAscii ( ) + " v " + VersionString . toAscii ( ) < < " built with Qt " < < QT_VERSION_STR < < " on " < < __DATE__ < < __TIME__ ;
2011-06-27 15:00:00 +00:00
qstatus - > setText ( tr ( " Loading Data " ) ) ;
2011-06-27 06:26:29 +00:00
qprogress - > show ( ) ;
2011-07-24 07:58:20 +00:00
//qstatusbar->showMessage(tr("Loading Data"),0);
2011-06-27 06:26:29 +00:00
2011-10-05 07:41:56 +00:00
// profile is a global variable set in main after login
PROFILE . LoadMachineData ( ) ;
2011-06-27 06:26:29 +00:00
2011-12-08 14:47:10 +00:00
SnapshotGraph = new gGraphView ( this ) ; //daily->graphView());
2011-12-14 06:39:03 +00:00
//SnapshotGraph->setMaximumSize(1024,512);
//SnapshotGraph->setMinimumSize(1024,512);
2011-12-08 14:47:10 +00:00
SnapshotGraph - > hide ( ) ;
2011-11-27 14:35:25 +00:00
overview = new Overview ( ui - > tabWidget , daily - > graphView ( ) ) ;
2011-12-21 14:24:09 +00:00
ui - > tabWidget - > insertTab ( 2 , overview , STR_TR_Overview ) ;
2011-12-21 12:47:47 +00:00
if ( PROFILE . oxi - > oximetryEnabled ( ) ) {
2011-11-27 14:35:25 +00:00
oximetry = new Oximetry ( ui - > tabWidget , daily - > graphView ( ) ) ;
2011-12-21 14:24:09 +00:00
ui - > tabWidget - > insertTab ( 3 , oximetry , STR_TR_Oximetry ) ;
2011-10-12 03:17:40 +00:00
}
2011-12-01 15:40:32 +00:00
2011-12-25 16:19:08 +00:00
ui - > tabWidget - > setCurrentWidget ( ui - > summaryTab ) ;
2011-07-24 07:58:20 +00:00
if ( daily ) daily - > ReloadGraphs ( ) ;
2011-09-10 15:43:40 +00:00
if ( overview ) overview - > ReloadGraphs ( ) ;
2011-06-27 06:26:29 +00:00
qprogress - > hide ( ) ;
2011-07-30 01:51:52 +00:00
qstatus - > setText ( " " ) ;
2011-12-23 14:12:04 +00:00
on_summaryButton_clicked ( ) ;
2011-12-22 13:22:40 +00:00
2011-06-27 06:26:29 +00:00
}
2011-06-26 08:30:44 +00:00
void MainWindow : : on_action_Import_Data_triggered ( )
{
2011-11-20 23:39:55 +00:00
QStringList importLocations ;
{
QString filename = PROFILE . Get ( " {DataFolder}/ImportLocations.txt " ) ;
QFile file ( filename ) ;
file . open ( QFile : : ReadOnly ) ;
QTextStream textStream ( & file ) ;
while ( 1 ) {
QString line = textStream . readLine ( ) ;
if ( line . isNull ( ) )
break ;
else if ( line . isEmpty ( ) )
continue ;
else {
importLocations . append ( line ) ;
}
2011-11-21 02:15:10 +00:00
}
2011-11-20 23:39:55 +00:00
file . close ( ) ;
}
2011-12-08 11:41:44 +00:00
//bool addnew=false;
2011-11-20 23:39:55 +00:00
QString newdir ;
bool asknew = false ;
if ( importLocations . size ( ) = = 0 ) {
asknew = true ;
} else {
int res = QMessageBox : : question ( this , " Import from where? " , " Do you just want to Import from the usual (remembered) locations? \n " , " The Usual " , " New Location " , " Cancel " , 0 , 2 ) ;
if ( res = = 1 ) {
asknew = true ;
2011-08-07 12:14:30 +00:00
}
2011-11-20 23:39:55 +00:00
if ( res = = 2 ) return ;
}
2011-12-03 05:10:23 +00:00
QStringList importFrom = importLocations ;
2011-11-20 23:39:55 +00:00
if ( asknew ) {
2011-11-25 06:56:39 +00:00
QFileDialog w ;
2011-12-13 12:49:48 +00:00
w . setFileMode ( QFileDialog : : Directory ) ;
w . setOption ( QFileDialog : : ShowDirsOnly , true ) ;
# if defined(Q_WS_MAC) && (QT_VERSION_CHECK(4,8,0) > QT_VERSION)
// Fix for tetragon, 10.6 barfs up Qt's custom dialog
2011-11-28 22:49:43 +00:00
w . setOption ( QFileDialog : : DontUseNativeDialog , true ) ;
2011-12-13 12:49:48 +00:00
# else
w . setOption ( QFileDialog : : DontUseNativeDialog , false ) ;
2011-11-25 06:56:39 +00:00
QListView * l = w . findChild < QListView * > ( " listView " ) ;
if ( l ) {
l - > setSelectionMode ( QAbstractItemView : : MultiSelection ) ;
}
QTreeView * t = w . findChild < QTreeView * > ( ) ;
if ( t ) {
t - > setSelectionMode ( QAbstractItemView : : MultiSelection ) ;
}
2011-12-13 12:49:48 +00:00
# endif
2011-11-25 06:56:39 +00:00
if ( w . exec ( ) ! = QDialog : : Accepted ) {
2011-11-20 23:39:55 +00:00
return ;
}
2011-11-25 06:56:39 +00:00
for ( int i = 0 ; i < w . selectedFiles ( ) . size ( ) ; i + + ) {
QString newdir = w . selectedFiles ( ) . at ( i ) ;
2011-12-03 05:10:23 +00:00
if ( ! importFrom . contains ( newdir ) ) {
importFrom . append ( newdir ) ;
2011-12-08 11:41:44 +00:00
//addnew=true;
2011-11-25 06:56:39 +00:00
}
2011-06-30 04:55:20 +00:00
}
2011-11-20 23:39:55 +00:00
}
2011-06-26 08:30:44 +00:00
2011-11-20 23:39:55 +00:00
int successful = false ;
2011-12-03 05:10:23 +00:00
QStringList goodlocations ;
for ( int i = 0 ; i < importFrom . size ( ) ; i + + ) {
QString dir = importFrom [ i ] ;
2011-11-20 23:39:55 +00:00
if ( ! dir . isEmpty ( ) ) {
qprogress - > setValue ( 0 ) ;
qprogress - > show ( ) ;
qstatus - > setText ( tr ( " Importing Data " ) ) ;
int c = PROFILE . Import ( dir ) ;
qDebug ( ) < < " Finished Importing data " < < c ;
if ( c ) {
2011-12-03 05:10:23 +00:00
if ( ! importLocations . contains ( dir ) )
goodlocations . push_back ( dir ) ;
2011-11-20 23:39:55 +00:00
successful = true ;
}
qstatus - > setText ( " " ) ;
qprogress - > hide ( ) ;
}
}
if ( successful ) {
PROFILE . Save ( ) ;
if ( daily ) daily - > ReloadGraphs ( ) ;
if ( overview ) overview - > ReloadGraphs ( ) ;
2011-12-03 05:10:23 +00:00
if ( ( goodlocations . size ( ) > 0 ) & & ( QMessageBox : : question ( this , " Remember this Location? " , " Would you like to remember this import location for next time? \n " + newdir , QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : Yes ) ) {
for ( int i = 0 ; i < goodlocations . size ( ) ; i + + ) {
importLocations . push_back ( goodlocations [ i ] ) ;
}
2011-11-20 23:39:55 +00:00
QString filename = PROFILE . Get ( " {DataFolder}/ImportLocations.txt " ) ;
QFile file ( filename ) ;
file . open ( QFile : : WriteOnly ) ;
QTextStream ts ( & file ) ;
for ( int i = 0 ; i < importLocations . size ( ) ; i + + ) {
ts < < importLocations [ i ] < < endl ;
//file.write(importLocations[i].toUtf8());
}
file . close ( ) ;
}
2011-12-25 16:38:37 +00:00
on_summaryButton_clicked ( ) ;
2011-12-03 05:10:23 +00:00
} else {
mainwin - > Notify ( " Import Problem \n \n Couldn't find any new Machine Data at the locations given " ) ;
2011-06-26 08:30:44 +00:00
}
}
2011-07-30 04:54:22 +00:00
QMenu * MainWindow : : CreateMenu ( QString title )
{
QMenu * menu = new QMenu ( title , ui - > menubar ) ;
ui - > menubar - > insertMenu ( ui - > menu_Help - > menuAction ( ) , menu ) ;
return menu ;
}
2011-06-26 08:30:44 +00:00
void MainWindow : : on_action_Fullscreen_triggered ( )
{
if ( ui - > action_Fullscreen - > isChecked ( ) )
this - > showFullScreen ( ) ;
else
this - > showNormal ( ) ;
}
2011-12-22 13:22:40 +00:00
QString htmlHeader ( )
{
return QString ( " <html><head> "
" </head> "
" <style type='text/css'> "
" <!--h1,p,a,td,body { font-family: 'FreeSans', 'Sans Serif' } --/> "
" p,a,td,body { font-size: 14px } "
" a:link,a:visited { color: '#000020'; text-decoration: none; font-weight: bold;} "
" a:hover { background-color: inherit; color: red; text-decoration:none; font-weight: bold; } "
" </style> "
2011-12-27 13:21:10 +00:00
" <script type='text/javascript'> "
" function ChangeColor(tableRow, highLight) "
" { tableRow.style.backgroundColor = highLight; } "
" function Go(url) { window.location=url; } "
" </script> "
2011-12-22 13:22:40 +00:00
" </head> "
" <body leftmargin=0 topmargin=0 rightmargin=0> "
2011-12-25 05:05:12 +00:00
" <div align=center><table cellpadding=3 cellspacing=0 border=0> "
2011-12-29 05:43:47 +00:00
" <tr><td><img src='qrc:/icons/bob-v3.0.png' width=100px height=100px><td valign=center align=center><h1>SleepyHead v " + VersionString + " </h1><i>This is a beta software and some functionality may not work as intended yet.<br/>Please report any bugs you find to SleepyHead's SourceForge page.</i></td></tr></table> "
2011-12-24 05:55:44 +00:00
" </div> "
2011-12-22 15:24:23 +00:00
" <hr/> " ) ;
2011-12-22 13:22:40 +00:00
}
QString htmlFooter ( )
{
return QString ( " </body></html> " ) ;
}
2011-12-22 15:24:23 +00:00
EventDataType calcAHI ( QDate start , QDate end )
{
EventDataType val = ( p_profile - > calcCount ( CPAP_Obstructive , MT_CPAP , start , end )
+ p_profile - > calcCount ( CPAP_Hypopnea , MT_CPAP , start , end )
+ p_profile - > calcCount ( CPAP_ClearAirway , MT_CPAP , start , end )
2011-12-24 05:55:44 +00:00
+ p_profile - > calcCount ( CPAP_Apnea , MT_CPAP , start , end ) ) ;
if ( PROFILE . general - > calculateRDI ( ) )
val + = p_profile - > calcCount ( CPAP_RERA , MT_CPAP , start , end ) ;
2012-01-01 14:14:18 +00:00
EventDataType hours = p_profile - > calcHours ( MT_CPAP , start , end ) ;
if ( hours > 0 )
val / = hours ;
else
val = 0 ;
2011-12-22 15:24:23 +00:00
return val ;
}
struct RXChange
{
2011-12-23 10:52:31 +00:00
RXChange ( ) { highlight = 0 ; }
2011-12-22 15:24:23 +00:00
RXChange ( const RXChange & copy ) {
first = copy . first ;
last = copy . last ;
days = copy . days ;
ahi = copy . ahi ;
mode = copy . mode ;
min = copy . min ;
2011-12-23 10:52:31 +00:00
max = copy . max ;
2011-12-31 11:36:19 +00:00
maxhi = copy . maxhi ;
machine = copy . machine ;
2011-12-24 05:55:44 +00:00
per1 = copy . per1 ;
per2 = copy . per2 ;
2011-12-23 10:52:31 +00:00
highlight = copy . highlight ;
weighted = copy . weighted ;
2011-12-28 03:17:20 +00:00
prelief = copy . prelief ;
prelset = copy . prelset ;
2011-12-22 15:24:23 +00:00
}
QDate first ;
QDate last ;
int days ;
EventDataType ahi ;
CPAPMode mode ;
EventDataType min ;
EventDataType max ;
2011-12-31 11:36:19 +00:00
EventDataType maxhi ;
2011-12-24 05:55:44 +00:00
EventDataType per1 ;
EventDataType per2 ;
2011-12-23 10:52:31 +00:00
EventDataType weighted ;
2011-12-28 03:17:20 +00:00
PRTypes prelief ;
2011-12-31 11:36:19 +00:00
Machine * machine ;
2011-12-28 03:17:20 +00:00
short prelset ;
2011-12-23 10:52:31 +00:00
short highlight ;
2011-12-22 15:24:23 +00:00
} ;
2011-12-31 11:36:19 +00:00
enum RXSortMode { RX_first , RX_last , RX_days , RX_ahi , RX_mode , RX_min , RX_max , RX_maxhi , RX_per1 , RX_per2 , RX_weighted } ;
2011-12-23 10:52:31 +00:00
RXSortMode RXsort = RX_first ;
bool RXorder = false ;
bool RXSort ( const RXChange * comp1 , const RXChange * comp2 ) {
if ( RXorder ) {
switch ( RXsort ) {
case RX_ahi : return comp1 - > ahi < comp2 - > ahi ;
case RX_days : return comp1 - > days < comp2 - > days ;
case RX_first : return comp1 - > first < comp2 - > first ;
case RX_last : return comp1 - > last < comp2 - > last ;
case RX_mode : return comp1 - > mode < comp2 - > mode ;
case RX_min : return comp1 - > min < comp2 - > min ;
case RX_max : return comp1 - > max < comp2 - > max ;
2011-12-31 11:36:19 +00:00
case RX_maxhi : return comp1 - > maxhi < comp2 - > maxhi ;
2011-12-24 05:55:44 +00:00
case RX_per1 : return comp1 - > per1 < comp2 - > per1 ;
case RX_per2 : return comp1 - > per2 < comp2 - > per2 ;
2011-12-23 10:52:31 +00:00
case RX_weighted : return comp1 - > weighted < comp2 - > weighted ;
} ;
} else {
switch ( RXsort ) {
case RX_ahi : return comp1 - > ahi > comp2 - > ahi ;
case RX_days : return comp1 - > days > comp2 - > days ;
case RX_first : return comp1 - > first > comp2 - > first ;
case RX_last : return comp1 - > last > comp2 - > last ;
case RX_mode : return comp1 - > mode > comp2 - > mode ;
case RX_min : return comp1 - > min > comp2 - > min ;
case RX_max : return comp1 - > max > comp2 - > max ;
2011-12-31 11:36:19 +00:00
case RX_maxhi : return comp1 - > maxhi > comp2 - > maxhi ;
2011-12-24 05:55:44 +00:00
case RX_per1 : return comp1 - > per1 > comp2 - > per1 ;
case RX_per2 : return comp1 - > per2 > comp2 - > per2 ;
2011-12-23 10:52:31 +00:00
case RX_weighted : return comp1 - > weighted > comp2 - > weighted ;
} ;
}
return true ;
2011-12-22 15:24:23 +00:00
}
2011-12-23 10:52:31 +00:00
//bool operator<(const RXChange * & comp1, const RXChange * & comp2) {
//}
2011-06-26 08:30:44 +00:00
void MainWindow : : on_homeButton_clicked ( )
2011-12-23 14:12:04 +00:00
{
ui - > webView - > setUrl ( QUrl ( " qrc:/docs/index.html " ) ) ;
}
2011-12-23 15:01:14 +00:00
QString formatTime ( float time )
{
int hours = time ;
int seconds = time * 3600.0 ;
int minutes = ( seconds / 60 ) % 60 ;
seconds % = 60 ;
return QString ( ) . sprintf ( " %02i:%02i " , hours , minutes ) ; //,seconds);
}
2011-12-23 14:12:04 +00:00
void MainWindow : : on_summaryButton_clicked ( )
2011-06-26 08:30:44 +00:00
{
2011-12-22 13:22:40 +00:00
QString html = htmlHeader ( ) ;
2011-12-28 12:36:40 +00:00
QDate lastcpap = p_profile - > LastGoodDay ( MT_CPAP ) ;
QDate firstcpap = p_profile - > FirstGoodDay ( MT_CPAP ) ;
2011-12-22 13:22:40 +00:00
QDate cpapweek = lastcpap . addDays ( - 7 ) ;
QDate cpapmonth = lastcpap . addDays ( - 30 ) ;
QDate cpap6month = lastcpap . addMonths ( - 6 ) ;
QDate cpapyear = lastcpap . addYears ( - 12 ) ;
if ( cpapweek < firstcpap ) cpapweek = firstcpap ;
if ( cpapmonth < firstcpap ) cpapmonth = firstcpap ;
if ( cpap6month < firstcpap ) cpap6month = firstcpap ;
if ( cpapyear < firstcpap ) cpapyear = firstcpap ;
2011-12-28 03:17:20 +00:00
2011-12-23 10:52:31 +00:00
QList < Machine * > cpap_machines = PROFILE . GetMachines ( MT_CPAP ) ;
QList < Machine * > oximeters = PROFILE . GetMachines ( MT_OXIMETER ) ;
QList < Machine * > mach ;
mach . append ( cpap_machines ) ;
mach . append ( oximeters ) ;
2011-12-24 01:22:41 +00:00
2011-12-25 16:56:22 +00:00
if ( mach . size ( ) = = 0 ) {
html + = " <table cellpadding=2 cellspacing=0 border=0 width=100% height=70%> " ;
html + = " <tr><td align=center><h1>Please Import Some Data</h1><br/><i>SleepyHead is pretty much useless without it.</i></td></tr></table> " ;
html + = htmlFooter ( ) ;
ui - > summaryView - > setHtml ( html ) ;
return ;
}
2011-12-23 10:52:31 +00:00
int cpapdays = PROFILE . countDays ( MT_CPAP , firstcpap , lastcpap ) ;
2011-12-28 03:17:20 +00:00
int cpapweekdays = PROFILE . countDays ( MT_CPAP , cpapweek , lastcpap ) ;
int cpapmonthdays = PROFILE . countDays ( MT_CPAP , cpapmonth , lastcpap ) ;
int cpapyeardays = PROFILE . countDays ( MT_CPAP , cpapyear , lastcpap ) ;
int cpap6monthdays = PROFILE . countDays ( MT_CPAP , cpap6month , lastcpap ) ;
2011-12-23 14:12:04 +00:00
CPAPMode cpapmode = ( CPAPMode ) p_profile - > calcSettingsMax ( CPAP_Mode , MT_CPAP , firstcpap , lastcpap ) ;
2011-12-24 05:55:44 +00:00
float percentile = 0.95 ;
QString ahitxt ;
if ( PROFILE . general - > calculateRDI ( ) ) {
ahitxt = tr ( " RDI " ) ;
} else {
ahitxt = tr ( " AHI " ) ;
}
2011-12-25 05:05:12 +00:00
html + = " <div align=center> " ;
html + = QString ( " <table cellpadding=2 cellspacing=0 border=1 width=90%> " ) ;
2011-12-24 01:22:41 +00:00
if ( cpapdays = = 0 ) {
2011-12-25 16:56:22 +00:00
html + = " <tr><td colspan=6 align=center>No CPAP Machine Data Imported</td></tr> " ;
2011-12-22 15:24:23 +00:00
} else {
2011-12-25 17:01:04 +00:00
html + = QString ( " <tr><td colspan=6 align=center><b>CPAP Statistics as of %1</b></td></tr> " ) . arg ( lastcpap . toString ( Qt : : SystemLocaleLongDate ) ) ;
2011-12-23 10:52:31 +00:00
if ( cpap_machines . size ( ) > 0 ) {
2011-12-25 17:01:04 +00:00
// html+=QString("<tr><td colspan=6 align=center><b>%1</b></td></tr>").arg(tr("CPAP Summary"));
2011-12-23 10:52:31 +00:00
if ( ! cpapdays ) {
2011-12-25 17:01:04 +00:00
html + = QString ( " <tr><td colspan=6 align=center><b>%1</b></td></tr> " ) . arg ( tr ( " No CPAP data available. " ) ) ;
2011-12-23 10:52:31 +00:00
} else if ( cpapdays = = 1 ) {
2011-12-25 17:01:04 +00:00
html + = QString ( " <tr><td colspan=6 align=center>%1</td></tr> " ) . arg ( QString ( tr ( " %1 day of CPAP Data, on %2. " ) ) . arg ( cpapdays ) . arg ( firstcpap . toString ( Qt : : SystemLocaleShortDate ) ) ) ;
2011-12-23 10:52:31 +00:00
} else {
2011-12-25 17:01:04 +00:00
html + = QString ( " <tr><td colspan=6 align=center>%1</td></tr> " ) . arg ( QString ( tr ( " %1 days of CPAP Data, between %2 and %3 " ) ) . arg ( cpapdays ) . arg ( firstcpap . toString ( Qt : : SystemLocaleShortDate ) ) . arg ( lastcpap . toString ( Qt : : SystemLocaleShortDate ) ) ) ;
2011-12-23 10:52:31 +00:00
}
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><td><b>%6</td></tr> " )
. arg ( tr ( " Details " ) ) . arg ( tr ( " Most Recent " ) ) . arg ( tr ( " Last 7 Days " ) ) . arg ( tr ( " Last 30 Days " ) ) . arg ( tr ( " Last 6 months " ) ) . arg ( tr ( " Last Year " ) ) ;
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
2011-12-24 05:55:44 +00:00
. arg ( ahitxt )
2011-12-23 10:52:31 +00:00
. arg ( calcAHI ( lastcpap , lastcpap ) , 0 , ' f ' , 3 )
. arg ( calcAHI ( cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( calcAHI ( cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( calcAHI ( cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( calcAHI ( cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
2011-12-28 03:17:20 +00:00
if ( PROFILE . calcCount ( CPAP_RERA , MT_CPAP , cpapyear , lastcpap ) ) {
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " RERA Index " ) )
. arg ( PROFILE . calcCount ( CPAP_RERA , MT_CPAP , lastcpap , lastcpap ) / PROFILE . calcHours ( MT_CPAP , lastcpap , lastcpap ) , 0 , ' f ' , 3 )
. arg ( PROFILE . calcCount ( CPAP_RERA , MT_CPAP , cpapweek , lastcpap ) / PROFILE . calcHours ( MT_CPAP , cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( PROFILE . calcCount ( CPAP_RERA , MT_CPAP , cpapmonth , lastcpap ) / PROFILE . calcHours ( MT_CPAP , cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( PROFILE . calcCount ( CPAP_RERA , MT_CPAP , cpap6month , lastcpap ) / PROFILE . calcHours ( MT_CPAP , cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( PROFILE . calcCount ( CPAP_RERA , MT_CPAP , cpapyear , lastcpap ) / PROFILE . calcHours ( MT_CPAP , cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
}
if ( PROFILE . calcCount ( CPAP_FlowLimit , MT_CPAP , cpapyear , lastcpap ) ) {
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " Flow Limit Index " ) )
. arg ( PROFILE . calcCount ( CPAP_FlowLimit , MT_CPAP , lastcpap , lastcpap ) / PROFILE . calcHours ( MT_CPAP , lastcpap , lastcpap ) , 0 , ' f ' , 3 )
. arg ( PROFILE . calcCount ( CPAP_FlowLimit , MT_CPAP , cpapweek , lastcpap ) / PROFILE . calcHours ( MT_CPAP , cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( PROFILE . calcCount ( CPAP_FlowLimit , MT_CPAP , cpapmonth , lastcpap ) / PROFILE . calcHours ( MT_CPAP , cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( PROFILE . calcCount ( CPAP_FlowLimit , MT_CPAP , cpap6month , lastcpap ) / PROFILE . calcHours ( MT_CPAP , cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( PROFILE . calcCount ( CPAP_FlowLimit , MT_CPAP , cpapyear , lastcpap ) / PROFILE . calcHours ( MT_CPAP , cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
}
2011-12-23 10:52:31 +00:00
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
2011-12-24 05:55:44 +00:00
. arg ( tr ( " Hours per Night " ) )
2011-12-23 15:01:14 +00:00
. arg ( formatTime ( p_profile - > calcHours ( MT_CPAP ) ) )
. arg ( formatTime ( p_profile - > calcHours ( MT_CPAP , cpapweek , lastcpap ) / float ( cpapweekdays ) ) )
. arg ( formatTime ( p_profile - > calcHours ( MT_CPAP , cpapmonth , lastcpap ) / float ( cpapmonthdays ) ) )
. arg ( formatTime ( p_profile - > calcHours ( MT_CPAP , cpap6month , lastcpap ) / float ( cpap6monthdays ) ) )
. arg ( formatTime ( p_profile - > calcHours ( MT_CPAP , cpapyear , lastcpap ) / float ( cpapyeardays ) ) ) ;
2011-12-23 10:52:31 +00:00
2011-12-27 15:09:57 +00:00
if ( cpapmode > = MODE_BIPAP ) {
2011-12-24 05:55:44 +00:00
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " Min EPAP " ) )
. arg ( p_profile - > calcMin ( CPAP_EPAP , MT_CPAP ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( CPAP_EPAP , MT_CPAP , cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( CPAP_EPAP , MT_CPAP , cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( CPAP_EPAP , MT_CPAP , cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( CPAP_EPAP , MT_CPAP , cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " 95% EPAP " ) )
. arg ( p_profile - > calcPercentile ( CPAP_EPAP , percentile , MT_CPAP ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_EPAP , percentile , MT_CPAP , cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_EPAP , percentile , MT_CPAP , cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_EPAP , percentile , MT_CPAP , cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_EPAP , percentile , MT_CPAP , cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " Max IPAP " ) )
. arg ( p_profile - > calcMax ( CPAP_IPAP , MT_CPAP ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMax ( CPAP_IPAP , MT_CPAP , cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMax ( CPAP_IPAP , MT_CPAP , cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMax ( CPAP_IPAP , MT_CPAP , cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMax ( CPAP_IPAP , MT_CPAP , cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " 95% IPAP " ) )
. arg ( p_profile - > calcPercentile ( CPAP_IPAP , percentile , MT_CPAP ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_IPAP , percentile , MT_CPAP , cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_IPAP , percentile , MT_CPAP , cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_IPAP , percentile , MT_CPAP , cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_IPAP , percentile , MT_CPAP , cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
2011-12-27 15:09:57 +00:00
} else if ( cpapmode > = MODE_APAP ) {
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " Average Pressure " ) )
. arg ( p_profile - > calcWavg ( CPAP_Pressure , MT_CPAP ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( CPAP_Pressure , MT_CPAP , cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( CPAP_Pressure , MT_CPAP , cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( CPAP_Pressure , MT_CPAP , cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( CPAP_Pressure , MT_CPAP , cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " 95% Pressure " ) )
. arg ( p_profile - > calcPercentile ( CPAP_Pressure , percentile , MT_CPAP ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_Pressure , percentile , MT_CPAP , cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_Pressure , percentile , MT_CPAP , cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_Pressure , percentile , MT_CPAP , cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( CPAP_Pressure , percentile , MT_CPAP , cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
} else {
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " Pressure " ) )
2011-12-31 11:36:19 +00:00
. arg ( p_profile - > calcSettingsMin ( CPAP_Pressure , MT_CPAP ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcSettingsMin ( CPAP_Pressure , MT_CPAP , cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcSettingsMin ( CPAP_Pressure , MT_CPAP , cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcSettingsMin ( CPAP_Pressure , MT_CPAP , cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcSettingsMin ( CPAP_Pressure , MT_CPAP , cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
2011-12-23 10:52:31 +00:00
}
//html+="<tr><td colspan=6>TODO: 90% pressure.. Any point showing if this is all CPAP?</td></tr>";
2011-12-28 03:17:20 +00:00
ChannelID leak ;
if ( p_profile - > calcCount ( CPAP_LeakTotal , MT_CPAP , cpapyear , lastcpap ) > 0 ) {
leak = CPAP_LeakTotal ;
} else leak = CPAP_Leak ;
2011-12-23 10:52:31 +00:00
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
2011-12-28 03:17:20 +00:00
. arg ( tr ( " Average %1 " ) . arg ( schema : : channel [ leak ] . label ( ) ) )
. arg ( p_profile - > calcWavg ( leak , MT_CPAP ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( leak , MT_CPAP , cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( leak , MT_CPAP , cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( leak , MT_CPAP , cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( leak , MT_CPAP , cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
2011-12-23 14:12:04 +00:00
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
2011-12-28 03:17:20 +00:00
. arg ( tr ( " %1% %2 " ) . arg ( percentile * 100.0f , 0 , ' f ' , 0 ) . arg ( schema : : channel [ leak ] . label ( ) ) )
. arg ( p_profile - > calcPercentile ( leak , percentile , MT_CPAP ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( leak , percentile , MT_CPAP , cpapweek , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( leak , percentile , MT_CPAP , cpapmonth , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( leak , percentile , MT_CPAP , cpap6month , lastcpap ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcPercentile ( leak , percentile , MT_CPAP , cpapyear , lastcpap ) , 0 , ' f ' , 3 ) ;
2011-12-24 05:55:44 +00:00
html + = " <tr><td colspan=6>Note, AHI calcs here are different to overview calcs.. Overview shows a average of the dialy AHI's, this shows combined counts divide by combined hours</td></tr> " ;
2011-12-23 10:52:31 +00:00
}
2011-12-25 05:05:12 +00:00
}
int oxisize = oximeters . size ( ) ;
if ( oxisize > 0 ) {
2011-12-28 12:36:40 +00:00
QDate lastoxi = p_profile - > LastGoodDay ( MT_OXIMETER ) ;
QDate firstoxi = p_profile - > FirstGoodDay ( MT_OXIMETER ) ;
2011-12-25 05:05:12 +00:00
int days = PROFILE . countDays ( MT_OXIMETER , firstoxi , lastoxi ) ;
if ( days > 0 ) {
2011-12-25 17:01:04 +00:00
html + = QString ( " <tr><td colspan=6 align=center><b>%1</b></td></tr> " ) . arg ( tr ( " Oximetry Summary " ) ) ;
2011-12-25 05:05:12 +00:00
if ( days = = 1 ) {
2011-12-25 17:01:04 +00:00
html + = QString ( " <tr><td colspan=6 align=center>%1</td></tr> " ) . arg ( QString ( tr ( " %1 day of Oximetry Data, on %2. " ) ) . arg ( days ) . arg ( firstoxi . toString ( Qt : : SystemLocaleShortDate ) ) ) ;
2011-12-25 05:05:12 +00:00
} else {
2011-12-25 17:01:04 +00:00
html + = QString ( " <tr><td colspan=6 align=center>%1</td></tr> " ) . arg ( QString ( tr ( " %1 days of Oximetry Data, between %2 and %3 " ) ) . arg ( days ) . arg ( firstoxi . toString ( Qt : : SystemLocaleShortDate ) ) . arg ( lastoxi . toString ( Qt : : SystemLocaleShortDate ) ) ) ;
2011-12-25 05:05:12 +00:00
}
2011-12-23 14:30:49 +00:00
2011-12-25 05:05:12 +00:00
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><td><b>%6</td></tr> " )
2011-12-23 14:30:49 +00:00
. arg ( tr ( " Details " ) ) . arg ( tr ( " Most Recent " ) ) . arg ( tr ( " Last 7 Days " ) ) . arg ( tr ( " Last 30 Days " ) ) . arg ( tr ( " Last 6 months " ) ) . arg ( tr ( " Last Year " ) ) ;
2011-12-25 05:05:12 +00:00
QDate oxiweek = lastoxi . addDays ( - 7 ) ;
QDate oximonth = lastoxi . addDays ( - 30 ) ;
QDate oxi6month = lastoxi . addMonths ( - 6 ) ;
QDate oxiyear = lastoxi . addYears ( - 12 ) ;
if ( oxiweek < firstoxi ) oxiweek = firstoxi ;
if ( oximonth < firstoxi ) oximonth = firstoxi ;
if ( oxi6month < firstoxi ) oxi6month = firstoxi ;
if ( oxiyear < firstoxi ) oxiyear = firstoxi ;
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " Average SpO2 " ) )
. arg ( p_profile - > calcWavg ( OXI_SPO2 , MT_OXIMETER ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( OXI_SPO2 , MT_OXIMETER , oxiweek , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( OXI_SPO2 , MT_OXIMETER , oximonth , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( OXI_SPO2 , MT_OXIMETER , oxi6month , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( OXI_SPO2 , MT_OXIMETER , oxiyear , lastoxi ) , 0 , ' f ' , 3 ) ;
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " Minimum SpO2 " ) )
. arg ( p_profile - > calcMin ( OXI_SPO2 , MT_OXIMETER ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( OXI_SPO2 , MT_OXIMETER , oxiweek , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( OXI_SPO2 , MT_OXIMETER , oximonth , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( OXI_SPO2 , MT_OXIMETER , oxi6month , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( OXI_SPO2 , MT_OXIMETER , oxiyear , lastoxi ) , 0 , ' f ' , 3 ) ;
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " SpO2 Events / Hour " ) )
. arg ( p_profile - > calcCount ( OXI_SPO2Drop , MT_OXIMETER ) / p_profile - > calcHours ( MT_OXIMETER ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcCount ( OXI_SPO2Drop , MT_OXIMETER , oxiweek , lastoxi ) / p_profile - > calcHours ( MT_OXIMETER , oxiweek , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcCount ( OXI_SPO2Drop , MT_OXIMETER , oximonth , lastoxi ) / p_profile - > calcHours ( MT_OXIMETER , oximonth , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcCount ( OXI_SPO2Drop , MT_OXIMETER , oxi6month , lastoxi ) / p_profile - > calcHours ( MT_OXIMETER , oxi6month , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcCount ( OXI_SPO2Drop , MT_OXIMETER , oxiyear , lastoxi ) / p_profile - > calcHours ( MT_OXIMETER , oxiyear , lastoxi ) , 0 , ' f ' , 3 ) ;
html + = QString ( " <tr><td>%1</td><td>%2 \ %</td><td>%3 \ %</td><td>%4 \ %</td><td>%5 \ %</td><td>%6 \ %</td></tr> " )
. arg ( tr ( " % of time in SpO2 Events " ) )
. arg ( 100.0 / p_profile - > calcHours ( MT_OXIMETER ) * p_profile - > calcSum ( OXI_SPO2Drop , MT_OXIMETER ) / 3600.0 , 0 , ' f ' , 3 )
. arg ( 100.0 / p_profile - > calcHours ( MT_OXIMETER , oxiweek , lastoxi ) * p_profile - > calcSum ( OXI_SPO2Drop , MT_OXIMETER , oxiweek , lastoxi ) / 3600.0 , 0 , ' f ' , 3 )
. arg ( 100.0 / p_profile - > calcHours ( MT_OXIMETER , oximonth , lastoxi ) * p_profile - > calcSum ( OXI_SPO2Drop , MT_OXIMETER , oximonth , lastoxi ) / 3600.0 , 0 , ' f ' , 3 )
. arg ( 100.0 / p_profile - > calcHours ( MT_OXIMETER , oxi6month , lastoxi ) * p_profile - > calcSum ( OXI_SPO2Drop , MT_OXIMETER , oxi6month , lastoxi ) / 3600.0 , 0 , ' f ' , 3 )
. arg ( 100.0 / p_profile - > calcHours ( MT_OXIMETER , oxiyear , lastoxi ) * p_profile - > calcSum ( OXI_SPO2Drop , MT_OXIMETER , oxiyear , lastoxi ) / 3600.0 , 0 , ' f ' , 3 ) ;
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " Average Pulse Rate " ) )
. arg ( p_profile - > calcWavg ( OXI_Pulse , MT_OXIMETER ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( OXI_Pulse , MT_OXIMETER , oxiweek , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( OXI_Pulse , MT_OXIMETER , oximonth , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( OXI_Pulse , MT_OXIMETER , oxi6month , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcWavg ( OXI_Pulse , MT_OXIMETER , oxiyear , lastoxi ) , 0 , ' f ' , 3 ) ;
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " Minimum Pulse Rate " ) )
. arg ( p_profile - > calcMin ( OXI_Pulse , MT_OXIMETER ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( OXI_Pulse , MT_OXIMETER , oxiweek , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( OXI_Pulse , MT_OXIMETER , oximonth , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( OXI_Pulse , MT_OXIMETER , oxi6month , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMin ( OXI_Pulse , MT_OXIMETER , oxiyear , lastoxi ) , 0 , ' f ' , 3 ) ;
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " Maximum Pulse Rate " ) )
. arg ( p_profile - > calcMax ( OXI_Pulse , MT_OXIMETER ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMax ( OXI_Pulse , MT_OXIMETER , oxiweek , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMax ( OXI_Pulse , MT_OXIMETER , oximonth , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMax ( OXI_Pulse , MT_OXIMETER , oxi6month , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcMax ( OXI_Pulse , MT_OXIMETER , oxiyear , lastoxi ) , 0 , ' f ' , 3 ) ;
2011-12-28 06:27:26 +00:00
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td><td>%6</td></tr> " )
. arg ( tr ( " Pulse Change Events / Hour " ) )
. arg ( p_profile - > calcCount ( OXI_PulseChange , MT_OXIMETER ) / p_profile - > calcHours ( MT_OXIMETER ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcCount ( OXI_PulseChange , MT_OXIMETER , oxiweek , lastoxi ) / p_profile - > calcHours ( MT_OXIMETER , oxiweek , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcCount ( OXI_PulseChange , MT_OXIMETER , oximonth , lastoxi ) / p_profile - > calcHours ( MT_OXIMETER , oximonth , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcCount ( OXI_PulseChange , MT_OXIMETER , oxi6month , lastoxi ) / p_profile - > calcHours ( MT_OXIMETER , oxi6month , lastoxi ) , 0 , ' f ' , 3 )
. arg ( p_profile - > calcCount ( OXI_PulseChange , MT_OXIMETER , oxiyear , lastoxi ) / p_profile - > calcHours ( MT_OXIMETER , oxiyear , lastoxi ) , 0 , ' f ' , 3 ) ;
2011-12-23 10:52:31 +00:00
}
2011-12-25 05:05:12 +00:00
}
2011-12-23 10:52:31 +00:00
2011-12-25 05:05:12 +00:00
html + = " </table> " ;
html + = " </div> " ;
2011-12-25 13:27:47 +00:00
QDate bestAHIdate , worstAHIdate ;
EventDataType bestAHI = 999.0 , worstAHI = 0 ;
2011-12-25 05:05:12 +00:00
if ( cpapdays > 0 ) {
QDate first , last = lastcpap ;
CPAPMode mode , cmode = MODE_UNKNOWN ;
2011-12-31 11:36:19 +00:00
EventDataType cmin = 0 , cmax = 0 , cmaxhi = 0 , min , max , maxhi ;
Machine * mach , * lastmach = NULL ;
2012-01-01 14:14:18 +00:00
PRTypes lastpr , prelief = PR_UNKNOWN ;
short prelset , lastprelset = - 1 ;
2011-12-25 05:05:12 +00:00
QDate date = lastcpap ;
Day * day ;
2011-12-26 18:26:06 +00:00
bool lastchanged = false ;
2011-12-25 05:05:12 +00:00
int cnt = 0 ;
QVector < RXChange > rxchange ;
do {
2011-12-28 12:36:40 +00:00
day = PROFILE . GetGoodDay ( date , MT_CPAP ) ;
2011-12-25 13:27:47 +00:00
2011-12-25 05:05:12 +00:00
if ( day ) {
2011-12-26 18:26:06 +00:00
lastchanged = false ;
2011-12-26 04:41:28 +00:00
2011-12-26 03:06:39 +00:00
EventDataType hours = day - > hours ( ) ;
if ( hours > PROFILE . cpap - > complianceHours ( ) ) {
EventDataType ahi = day - > count ( CPAP_Obstructive ) + day - > count ( CPAP_Hypopnea ) + day - > count ( CPAP_Apnea ) + day - > count ( CPAP_ClearAirway ) ;
if ( PROFILE . general - > calculateRDI ( ) ) ahi + = day - > count ( CPAP_RERA ) ;
ahi / = day - > hours ( ) ;
if ( ahi > worstAHI ) {
worstAHI = ahi ;
worstAHIdate = date ;
}
if ( ahi < bestAHI ) {
bestAHI = ahi ;
bestAHIdate = date ;
}
2011-12-25 13:27:47 +00:00
}
2012-01-01 14:14:18 +00:00
prelief = ( PRTypes ) round ( day - > settings_wavg ( CPAP_PresReliefType ) ) ;
prelset = round ( day - > settings_wavg ( CPAP_PresReliefSet ) ) ;
2011-12-25 05:05:12 +00:00
mode = ( CPAPMode ) round ( day - > settings_wavg ( CPAP_Mode ) ) ;
2011-12-31 11:36:19 +00:00
if ( mode > = MODE_ASV ) {
min = day - > settings_min ( CPAP_EPAP ) ;
max = day - > settings_max ( CPAP_IPAPLo ) ;
maxhi = day - > settings_max ( CPAP_IPAPHi ) ;
} else if ( mode > = MODE_BIPAP ) {
min = day - > settings_min ( CPAP_EPAP ) ;
max = day - > settings_max ( CPAP_IPAP ) ;
} else if ( mode > = MODE_APAP ) {
min = day - > settings_min ( CPAP_PressureMin ) ;
max = day - > settings_max ( CPAP_PressureMax ) ;
} else {
min = day - > settings_min ( CPAP_Pressure ) ;
}
2012-01-01 14:14:18 +00:00
if ( ( mode ! = cmode ) | | ( min ! = cmin ) | | ( max ! = cmax ) | | ( maxhi ! = cmaxhi ) | | ( day - > machine ! = lastmach ) | | ( prelief ! = lastpr ) ) {
2011-12-25 05:05:12 +00:00
if ( cmode ! = MODE_UNKNOWN ) {
first = date . addDays ( 1 ) ;
int days = PROFILE . countDays ( MT_CPAP , first , last ) ;
RXChange rx ;
rx . first = first ;
rx . last = last ;
rx . days = days ;
rx . ahi = calcAHI ( first , last ) ;
rx . mode = cmode ;
rx . min = cmin ;
rx . max = cmax ;
2011-12-31 11:36:19 +00:00
rx . maxhi = cmaxhi ;
2012-01-01 14:14:18 +00:00
rx . prelief = lastpr ;
rx . prelset = lastprelset ;
2011-12-31 11:36:19 +00:00
2011-12-25 05:05:12 +00:00
if ( mode < MODE_BIPAP ) {
rx . per1 = p_profile - > calcPercentile ( CPAP_Pressure , percentile , MT_CPAP , first , last ) ;
rx . per2 = 0 ;
2011-12-31 11:36:19 +00:00
} else if ( mode < MODE_ASV ) {
2011-12-25 05:05:12 +00:00
rx . per1 = p_profile - > calcPercentile ( CPAP_EPAP , percentile , MT_CPAP , first , last ) ;
rx . per2 = p_profile - > calcPercentile ( CPAP_IPAP , percentile , MT_CPAP , first , last ) ;
2011-12-31 11:36:19 +00:00
} else {
rx . per1 = p_profile - > calcPercentile ( CPAP_EPAP , percentile , MT_CPAP , first , last ) ;
rx . per2 = p_profile - > calcPercentile ( CPAP_IPAPHi , percentile , MT_CPAP , first , last ) ;
2011-12-23 10:52:31 +00:00
}
2011-12-25 05:05:12 +00:00
rx . weighted = float ( rx . days ) / float ( cpapdays ) * rx . ahi ;
rxchange . push_back ( rx ) ;
2011-12-22 15:24:23 +00:00
}
2011-12-25 05:05:12 +00:00
cmode = mode ;
cmin = min ;
cmax = max ;
2011-12-31 11:36:19 +00:00
cmaxhi = maxhi ;
2012-01-01 14:14:18 +00:00
lastpr = prelief ;
lastprelset = prelset ;
2011-12-25 05:05:12 +00:00
last = date ;
2011-12-31 11:36:19 +00:00
lastmach = day - > machine ;
2011-12-25 05:05:12 +00:00
lastchanged = true ;
2011-12-24 05:55:44 +00:00
}
2011-12-25 05:05:12 +00:00
2011-12-22 15:24:23 +00:00
}
2011-12-25 05:05:12 +00:00
date = date . addDays ( - 1 ) ;
} while ( date > = firstcpap ) ;
2012-01-01 14:14:18 +00:00
lastchanged = false ;
2011-12-25 05:05:12 +00:00
if ( ! lastchanged ) {
2011-12-26 19:09:29 +00:00
// last=date.addDays(1);
2011-12-25 05:05:12 +00:00
first = firstcpap ;
int days = PROFILE . countDays ( MT_CPAP , first , last ) ;
RXChange rx ;
rx . first = first ;
rx . last = last ;
rx . days = days ;
rx . ahi = calcAHI ( first , last ) ;
rx . mode = mode ;
rx . min = min ;
rx . max = max ;
2011-12-31 11:36:19 +00:00
rx . maxhi = maxhi ;
2012-01-01 14:14:18 +00:00
rx . prelief = prelief ;
rx . prelset = prelset ;
2011-12-25 05:05:12 +00:00
if ( mode < MODE_BIPAP ) {
rx . per1 = p_profile - > calcPercentile ( CPAP_Pressure , 0.9 , MT_CPAP , first , last ) ;
rx . per2 = 0 ;
2011-12-31 11:36:19 +00:00
} else if ( mode < MODE_ASV ) {
2011-12-25 05:05:12 +00:00
rx . per1 = p_profile - > calcPercentile ( CPAP_EPAP , 0.9 , MT_CPAP , first , last ) ;
rx . per2 = p_profile - > calcPercentile ( CPAP_IPAP , 0.9 , MT_CPAP , first , last ) ;
2011-12-31 11:36:19 +00:00
} else {
rx . per1 = p_profile - > calcPercentile ( CPAP_EPAP , percentile , MT_CPAP , first , last ) ;
rx . per2 = p_profile - > calcPercentile ( CPAP_IPAPHi , percentile , MT_CPAP , first , last ) ;
2011-12-23 10:52:31 +00:00
}
2011-12-25 05:05:12 +00:00
rx . weighted = float ( rx . days ) / float ( cpapdays ) ;
//rx.weighted=float(days)*rx.ahi;
rxchange . push_back ( rx ) ;
}
2011-12-25 17:46:06 +00:00
int rxthresh = 5 ;
2011-12-25 05:05:12 +00:00
QVector < RXChange * > tmpRX ;
for ( int i = 0 ; i < rxchange . size ( ) ; i + + ) {
RXChange & rx = rxchange [ i ] ;
2011-12-25 17:46:06 +00:00
if ( rx . days > rxthresh )
2011-12-25 05:05:12 +00:00
tmpRX . push_back ( & rx ) ;
}
2011-12-25 13:27:47 +00:00
QString recbox = " <html><head><style type='text/css'> "
" p,a,td,body { font-family: ' " + QApplication : : font ( ) . family ( ) + " '; } "
" p,a,td,body { font-size: " + QString : : number ( QApplication : : font ( ) . pointSize ( ) + 2 ) + " px; } "
" a:link,a:visited { color: inherit; text-decoration: none; } " //font-weight: normal;
" a:hover { background-color: inherit; color: white; text-decoration:none; font-weight: bold; } "
" </style></head><body> " ;
recbox + = " <table width=100% cellpadding=2 cellspacing=0> " ;
2011-12-26 06:05:42 +00:00
recbox + = QString ( " <tr><td><b><a href='daily=%1'>%2</b></td><td><b>%3</b></td></tr> " ) . arg ( bestAHIdate . toString ( Qt : : ISODate ) ) . arg ( tr ( " Best %1 " ) . arg ( ahitxt ) ) . arg ( bestAHI , 0 , ' f ' , 2 ) ;
2011-12-25 13:27:47 +00:00
recbox + = QString ( " <tr><td colspan=2>%1</td></tr> " ) . arg ( bestAHIdate . toString ( Qt : : SystemLocaleShortDate ) ) ;
recbox + = QString ( " <tr><td colspan=2> </td></tr> " ) ;
2011-12-26 06:05:42 +00:00
recbox + = QString ( " <tr><td><b><a href='daily=%1'>%2</a></b></td><td><b>%3</b></td></tr> " ) . arg ( worstAHIdate . toString ( Qt : : ISODate ) ) . arg ( tr ( " Worst %1 " ) . arg ( ahitxt ) ) . arg ( worstAHI , 0 , ' f ' , 2 ) ;
2011-12-25 13:27:47 +00:00
recbox + = QString ( " <tr><td colspan=2>%1</td></tr> " ) . arg ( worstAHIdate . toString ( Qt : : SystemLocaleShortDate ) ) ;
recbox + = QString ( " <tr><td colspan=2> </td></tr> " ) ;
2011-12-26 18:26:06 +00:00
if ( tmpRX . size ( ) > 0 ) {
RXsort = RX_ahi ;
2011-12-31 11:36:19 +00:00
QString minstr , maxstr , modestr , maxhistr ;
2011-12-26 18:26:06 +00:00
qSort ( tmpRX . begin ( ) , tmpRX . end ( ) , RXSort ) ;
tmpRX [ 0 ] - > highlight = 4 ; // worst
int ls = tmpRX . size ( ) - 1 ;
tmpRX [ ls ] - > highlight = 1 ; //best
CPAPMode mode = ( CPAPMode ) ( int ) PROFILE . calcSettingsMax ( CPAP_Mode , MT_CPAP , tmpRX [ ls ] - > first , tmpRX [ ls ] - > first ) ;
if ( mode < MODE_APAP ) { // is CPAP?
minstr = " Pressure " ;
maxstr = " " ;
modestr = tr ( " CPAP " ) ;
} else if ( mode < MODE_BIPAP ) { // is AUTO?
minstr = " Min " ;
maxstr = " Max " ;
modestr = tr ( " APAP " ) ;
2011-12-31 11:36:19 +00:00
} else if ( mode < MODE_ASV ) { // BIPAP
2011-12-26 18:26:06 +00:00
minstr = " EPAP " ;
maxstr = " IPAP " ;
2011-12-31 11:36:19 +00:00
modestr = tr ( " Bi-Level " ) ;
} else {
minstr = " EPAP " ;
maxstr = " IPAPLo " ;
maxhistr = " IPAPHi " ;
modestr = tr ( " ST/ASV " ) ;
2011-12-26 18:26:06 +00:00
}
2011-12-25 13:27:47 +00:00
2011-12-26 18:26:06 +00:00
recbox + = QString ( " <tr><td colspan=2><b><a href='overview=%1,%2'>%3</a></b></td></tr> " )
. arg ( tmpRX [ ls ] - > first . toString ( Qt : : ISODate ) )
. arg ( tmpRX [ ls ] - > last . toString ( Qt : : ISODate ) )
. arg ( tr ( " Best RX Setting " ) ) ;
recbox + = QString ( " <tr><td colspan=2>%1: %2</td></tr> " ) . arg ( ahitxt ) . arg ( tmpRX [ ls ] - > ahi , 0 , ' f ' , 2 ) ;
recbox + = QString ( " <tr><td colspan=2>%1: %2</td></tr> " ) . arg ( tr ( " Mode " ) ) . arg ( modestr ) ;
recbox + = QString ( " <tr><td colspan=2>%1: %2 " ) . arg ( minstr ) . arg ( tmpRX [ ls ] - > min , 0 , ' f ' , 1 ) ;
if ( ! maxstr . isEmpty ( ) ) recbox + = QString ( " %1: %2 " ) . arg ( maxstr ) . arg ( tmpRX [ ls ] - > max , 0 , ' f ' , 1 ) ;
2011-12-31 11:36:19 +00:00
if ( ! maxhistr . isEmpty ( ) ) recbox + = QString ( " %1: %2 " ) . arg ( maxhistr ) . arg ( tmpRX [ 0 ] - > maxhi , 0 , ' f ' , 1 ) ;
2011-12-26 18:26:06 +00:00
recbox + = " </td></tr> " ;
recbox + = QString ( " <tr><td colspan=2>%1: %2</td></tr> " ) . arg ( tr ( " Start " ) ) . arg ( tmpRX [ ls ] - > first . toString ( Qt : : SystemLocaleShortDate ) ) ;
recbox + = QString ( " <tr><td colspan=2>%1: %2</td></tr> " ) . arg ( tr ( " End " ) ) . arg ( tmpRX [ ls ] - > last . toString ( Qt : : SystemLocaleShortDate ) ) ;
recbox + = QString ( " <tr><td colspan=2> </td></tr> " ) ;
mode = ( CPAPMode ) ( int ) PROFILE . calcSettingsMax ( CPAP_Mode , MT_CPAP , tmpRX [ 0 ] - > first , tmpRX [ 0 ] - > first ) ;
if ( mode < MODE_APAP ) { // is CPAP?
minstr = " Pressure " ;
maxstr = " " ;
modestr = tr ( " CPAP " ) ;
} else if ( mode < MODE_BIPAP ) { // is AUTO?
minstr = " Min " ;
maxstr = " Max " ;
modestr = tr ( " APAP " ) ;
2011-12-31 11:36:19 +00:00
} else if ( mode < MODE_ASV ) { // BIPAP or greater
2011-12-26 18:26:06 +00:00
minstr = " EPAP " ;
maxstr = " IPAP " ;
modestr = tr ( " Bi-Level/ASV " ) ;
2011-12-31 11:36:19 +00:00
} else {
minstr = " EPAP " ;
maxstr = " IPAPLo " ;
maxhistr = " IPAPHi " ;
modestr = tr ( " ST/ASV " ) ;
2011-12-26 18:26:06 +00:00
}
recbox + = QString ( " <tr><td colspan=2><b><a href='overview=%1,%2'>%3</a></b></td></tr> " )
. arg ( tmpRX [ 0 ] - > first . toString ( Qt : : ISODate ) )
. arg ( tmpRX [ 0 ] - > last . toString ( Qt : : ISODate ) )
. arg ( tr ( " Worst RX Setting " ) ) ;
recbox + = QString ( " <tr><td colspan=2>%1: %2</td></tr> " ) . arg ( ahitxt ) . arg ( tmpRX [ 0 ] - > ahi , 0 , ' f ' , 2 ) ;
recbox + = QString ( " <tr><td colspan=2>%1: %2</td></tr> " ) . arg ( tr ( " Mode " ) ) . arg ( modestr ) ;
recbox + = QString ( " <tr><td colspan=2>%1: %2 " ) . arg ( minstr ) . arg ( tmpRX [ 0 ] - > min , 0 , ' f ' , 1 ) ;
if ( ! maxstr . isEmpty ( ) ) recbox + = QString ( " %1: %2 " ) . arg ( maxstr ) . arg ( tmpRX [ 0 ] - > max , 0 , ' f ' , 1 ) ;
2011-12-31 11:36:19 +00:00
if ( ! maxhistr . isEmpty ( ) ) recbox + = QString ( " %1: %2 " ) . arg ( maxhistr ) . arg ( tmpRX [ 0 ] - > maxhi , 0 , ' f ' , 1 ) ;
2011-12-26 18:26:06 +00:00
recbox + = " </td></tr> " ;
recbox + = QString ( " <tr><td colspan=2>%1: %2</td></tr> " ) . arg ( tr ( " Start " ) ) . arg ( tmpRX [ 0 ] - > first . toString ( Qt : : SystemLocaleShortDate ) ) ;
recbox + = QString ( " <tr><td colspan=2>%1: %2</td></tr> " ) . arg ( tr ( " End " ) ) . arg ( tmpRX [ 0 ] - > last . toString ( Qt : : SystemLocaleShortDate ) ) ;
2011-12-25 13:27:47 +00:00
}
2011-12-26 18:26:06 +00:00
recbox + = " </table> " ;
2011-12-25 13:27:47 +00:00
recbox + = " </body></html> " ;
ui - > recordsBox - > setHtml ( recbox ) ;
2011-12-25 05:05:12 +00:00
html + = " <div align=center> " ;
html + = QString ( " <br/><b>Changes to Prescription Settings</b> " ) ;
html + = QString ( " <table cellpadding=2 cellspacing=0 border=1 width=90%> " ) ;
QString extratxt ;
2011-12-31 11:36:19 +00:00
if ( cpapmode > = MODE_ASV ) {
extratxt = QString ( " <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> " )
. arg ( tr ( " EPAP " ) ) . arg ( tr ( " IPAPLo " ) ) . arg ( tr ( " IPAPHi " ) ) . arg ( tr ( " %1% EPAP " ) . arg ( percentile * 100.0 ) ) . arg ( tr ( " %1% IPAP " ) . arg ( percentile * 100.0 ) ) ;
} else if ( cpapmode > = MODE_BIPAP ) {
2011-12-25 05:05:12 +00:00
extratxt = QString ( " <td><b>%1</b></td><td><b>%2</b></td><td><b>%3</b></td><td><b>%4</b></td> " )
2011-12-27 15:09:57 +00:00
. arg ( tr ( " EPAP " ) ) . arg ( tr ( " IPAP " ) ) . arg ( tr ( " %1% EPAP " ) . arg ( percentile * 100.0 ) ) . arg ( tr ( " %1% IPAP " ) . arg ( percentile * 100.0 ) ) ;
2011-12-25 05:05:12 +00:00
} else if ( cpapmode > MODE_CPAP ) {
extratxt = QString ( " <td><b>%1</b></td><td><b>%2</b></td><td><b>%3</b></td> " )
. arg ( tr ( " Min Pressure " ) ) . arg ( tr ( " Max Pressure " ) ) . arg ( tr ( " %1% Pressure " ) . arg ( percentile * 100.0 ) ) ;
} else {
extratxt = QString ( " <td><b>%1</b></td> " )
. arg ( tr ( " Pressure " ) ) ;
}
2012-01-01 14:14:18 +00:00
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><td><b>%6</b></td>%7</tr> " )
2011-12-25 05:05:12 +00:00
. arg ( tr ( " First " ) )
. arg ( tr ( " Last " ) )
. arg ( tr ( " Days " ) )
. arg ( ahitxt )
. arg ( tr ( " Mode " ) )
2012-01-01 14:14:18 +00:00
. arg ( tr ( " Pr. Rel. " ) )
2011-12-25 05:05:12 +00:00
. arg ( extratxt ) ;
for ( int i = 0 ; i < rxchange . size ( ) ; i + + ) {
RXChange rx = rxchange . at ( i ) ;
QString color ;
if ( rx . highlight = = 1 ) {
2011-12-27 13:21:10 +00:00
color = " #c0ffc0 " ;
2011-12-25 05:05:12 +00:00
} else if ( rx . highlight = = 2 ) {
2011-12-27 13:21:10 +00:00
color = " #e0ffe0 " ;
2011-12-25 05:05:12 +00:00
} else if ( rx . highlight = = 3 ) {
2011-12-27 13:21:10 +00:00
color = " #ffe0e0 " ;
2011-12-25 05:05:12 +00:00
} else if ( rx . highlight = = 4 ) {
2011-12-27 13:21:10 +00:00
color = " #ffc0c0 " ;
2011-12-25 05:05:12 +00:00
} else color = " " ;
2011-12-31 11:36:19 +00:00
if ( cpapmode > = MODE_ASV ) {
extratxt = QString ( " <td>%1</td><td>%2</td><td>%3</td><td>%4</td> " )
. arg ( rx . max , 0 , ' f ' , 2 ) . arg ( rx . maxhi , 0 , ' f ' , 2 ) . arg ( rx . per1 , 0 , ' f ' , 2 ) . arg ( rx . per2 , 0 , ' f ' , 2 ) ;
} else if ( cpapmode > = MODE_BIPAP ) {
2011-12-25 05:05:12 +00:00
extratxt = QString ( " <td>%1</td><td>%2</td><td>%3</td> " ) . arg ( rx . max , 0 , ' f ' , 2 ) . arg ( rx . per1 , 0 , ' f ' , 2 ) . arg ( rx . per2 , 0 , ' f ' , 2 ) ;
2011-12-24 05:55:44 +00:00
} else if ( cpapmode > MODE_CPAP ) {
2011-12-25 05:05:12 +00:00
extratxt = QString ( " <td>%1</td><td>%2</td> " ) . arg ( rx . max , 0 , ' f ' , 2 ) . arg ( rx . per1 , 0 , ' f ' , 2 ) ;
} else extratxt = " " ;
2012-01-01 14:14:18 +00:00
QString presrel ;
if ( rx . prelset > 0 ) {
presrel = schema : : channel [ CPAP_PresReliefType ] . option ( int ( rx . prelief ) ) ;
presrel + = QString ( " x%1 " ) . arg ( rx . prelset ) ;
} else presrel = " None " ;
html + = QString ( " <tr bgcolor=' " + color + " ' onmouseover='ChangeColor(this, \" #dddddd \" );' onmouseout='ChangeColor(this, \" " + color + " \" );' onclick='tabwidget.setCurrentIndex(3); print \" %1 %2 \" ;'><td>%3</td><td>%4</td><td>%5</td><td>%6</td><td>%7</td><td>%8</td><td>%9</td>%10</tr> " )
2011-12-27 13:21:10 +00:00
. arg ( rx . first . toString ( Qt : : ISODate ) )
. arg ( rx . last . toString ( Qt : : ISODate ) )
2011-12-25 05:05:12 +00:00
. arg ( rx . first . toString ( Qt : : SystemLocaleShortDate ) )
. arg ( rx . last . toString ( Qt : : SystemLocaleShortDate ) )
. arg ( rx . days )
. arg ( rx . ahi , 0 , ' f ' , 2 )
. arg ( schema : : channel [ CPAP_Mode ] . option ( int ( rx . mode ) - 1 ) )
2012-01-01 14:14:18 +00:00
. arg ( presrel )
2011-12-25 05:05:12 +00:00
. arg ( rx . min , 0 , ' f ' , 2 )
. arg ( extratxt ) ;
2011-12-22 15:24:23 +00:00
}
2011-12-25 05:05:12 +00:00
html + = " </table> " ;
2011-12-25 17:46:06 +00:00
html + = QString ( " <i>The above has a threshold which excludes day counts less than %1 from the best/worst highlighting</i><br/> " ) . arg ( rxthresh ) ;
2011-12-25 05:05:12 +00:00
html + = " </div> " ;
2011-12-22 13:22:40 +00:00
2011-12-22 15:24:23 +00:00
}
if ( mach . size ( ) > 0 ) {
2011-12-23 14:12:04 +00:00
html + = " <div align=center> " ;
2011-12-22 15:24:23 +00:00
html + = QString ( " <br/><b>Machine Information</b> " ) ;
2011-12-23 14:12:04 +00:00
html + = QString ( " <table cellpadding=2 cellspacing=0 border=1 width=90%> " ) ;
2011-12-22 15:24:23 +00:00
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 ( tr ( " Brand " ) )
. arg ( tr ( " Model " ) )
. arg ( tr ( " Serial " ) )
. arg ( tr ( " First Use " ) )
. arg ( tr ( " Last Use " ) ) ;
Machine * m ;
for ( int i = 0 ; i < mach . size ( ) ; i + + ) {
m = mach . at ( i ) ;
2011-12-23 10:52:31 +00:00
if ( m - > GetType ( ) = = MT_JOURNAL ) continue ;
2011-12-22 15:24:23 +00:00
QString mn = m - > properties [ STR_PROP_ModelNumber ] ;
//if (mn.isEmpty())
html + = QString ( " <tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td><td>%5</td></tr> " )
. arg ( m - > properties [ STR_PROP_Brand ] )
. arg ( m - > properties [ STR_PROP_Model ] + " " + m - > properties [ STR_PROP_SubModel ] + ( mn . isEmpty ( ) ? " " : QString ( " ( " ) + mn + QString ( " ) " ) ) )
. arg ( m - > properties [ STR_PROP_Serial ] )
. arg ( m - > FirstDay ( ) . toString ( Qt : : SystemLocaleShortDate ) )
. arg ( m - > LastDay ( ) . toString ( Qt : : SystemLocaleShortDate ) ) ;
}
html + = " </table> " ;
2011-12-23 14:12:04 +00:00
html + = " </div> " ;
2011-12-22 15:24:23 +00:00
}
2011-12-26 04:41:28 +00:00
updateFavourites ( ) ;
2011-12-22 13:22:40 +00:00
html + = htmlFooter ( ) ;
2011-12-27 13:21:10 +00:00
QWebFrame * frame = ui - > summaryView - > page ( ) - > currentFrame ( ) ;
frame - > addToJavaScriptWindowObject ( " mainwin " , this ) ;
2011-12-25 16:19:08 +00:00
ui - > summaryView - > setHtml ( html ) ;
2011-12-22 13:22:40 +00:00
// QString file="qrc:/docs/index.html";
// QUrl url(file);
// ui->webView->setUrl(url);
2011-06-26 08:30:44 +00:00
}
2011-12-26 04:41:28 +00:00
void MainWindow : : updateFavourites ( )
{
2011-12-28 14:03:09 +00:00
QDate date = PROFILE . LastDay ( MT_JOURNAL ) ;
2011-12-26 18:26:06 +00:00
if ( ! date . isValid ( ) )
return ;
2011-12-26 04:41:28 +00:00
2011-12-28 14:03:09 +00:00
ui - > favouritesList - > blockSignals ( true ) ;
ui - > favouritesList - > clear ( ) ;
2011-12-26 04:41:28 +00:00
do {
2011-12-28 14:03:09 +00:00
Day * journal = PROFILE . GetDay ( date , MT_JOURNAL ) ;
2011-12-26 04:41:28 +00:00
if ( journal ) {
if ( journal - > size ( ) > 0 ) {
Session * sess = ( * journal ) [ 0 ] ;
if ( sess - > settings . contains ( Bookmark_Start ) ) {
QVariantList start = sess - > settings [ Bookmark_Start ] . toList ( ) ;
QVariantList end = sess - > settings [ Bookmark_End ] . toList ( ) ;
QStringList notes = sess - > settings [ Bookmark_Notes ] . toStringList ( ) ;
if ( notes . size ( ) > 0 ) {
QListWidgetItem * item = new QListWidgetItem ( date . toString ( ) ) ;
2011-12-26 18:26:06 +00:00
/*QString tooltip;
for ( int i = 0 ; i < notes . size ( ) ; i + + ) {
QDate d = start [ i ] . toDate ( ) ;
tooltip + = d . toString ( Qt : : SystemLocaleShortDate ) + " : " + notes [ i ] ;
if ( i < notes . size ( ) - 1 ) tooltip + = " \n " ;
}
item - > setToolTip ( tooltip ) ; */
2011-12-26 04:41:28 +00:00
item - > setData ( Qt : : UserRole , date ) ;
ui - > favouritesList - > addItem ( item ) ;
}
}
}
}
date = date . addDays ( - 1 ) ;
2011-12-28 14:03:09 +00:00
} while ( date > = PROFILE . FirstDay ( MT_JOURNAL ) ) ;
2011-12-26 04:58:02 +00:00
ui - > favouritesList - > blockSignals ( false ) ;
2011-12-26 04:41:28 +00:00
}
2011-06-26 08:30:44 +00:00
void MainWindow : : on_backButton_clicked ( )
{
ui - > webView - > back ( ) ;
}
void MainWindow : : on_forwardButton_clicked ( )
{
ui - > webView - > forward ( ) ;
}
void MainWindow : : on_webView_urlChanged ( const QUrl & arg1 )
{
ui - > urlBar - > setEditText ( arg1 . toString ( ) ) ;
}
void MainWindow : : on_urlBar_activated ( const QString & arg1 )
{
QUrl url ( arg1 ) ;
ui - > webView - > setUrl ( url ) ;
}
void MainWindow : : on_dailyButton_clicked ( )
{
ui - > tabWidget - > setCurrentWidget ( daily ) ;
2011-09-02 02:00:04 +00:00
daily - > RedrawGraphs ( ) ;
2011-12-21 14:24:09 +00:00
qstatus2 - > setText ( STR_TR_Daily ) ;
2011-06-26 08:30:44 +00:00
}
2011-10-28 03:45:31 +00:00
void MainWindow : : JumpDaily ( )
{
on_dailyButton_clicked ( ) ;
}
2011-06-26 08:30:44 +00:00
void MainWindow : : on_overviewButton_clicked ( )
{
2011-09-07 09:15:33 +00:00
ui - > tabWidget - > setCurrentWidget ( overview ) ;
2011-12-21 14:24:09 +00:00
qstatus2 - > setText ( STR_TR_Overview ) ;
2011-06-26 08:30:44 +00:00
}
void MainWindow : : on_webView_loadFinished ( bool arg1 )
{
2011-07-01 10:10:44 +00:00
arg1 = arg1 ;
2011-06-26 08:30:44 +00:00
qprogress - > hide ( ) ;
2011-06-27 06:26:29 +00:00
if ( first_load ) {
QTimer : : singleShot ( 0 , this , SLOT ( Startup ( ) ) ) ;
first_load = false ;
} else {
2011-07-30 01:51:52 +00:00
qstatus - > setText ( " " ) ;
2011-06-27 06:26:29 +00:00
}
2011-06-27 10:46:33 +00:00
ui - > backButton - > setEnabled ( ui - > webView - > history ( ) - > canGoBack ( ) ) ;
ui - > forwardButton - > setEnabled ( ui - > webView - > history ( ) - > canGoForward ( ) ) ;
2011-12-26 05:51:53 +00:00
connect ( ui - > webView - > page ( ) , SIGNAL ( linkHovered ( QString , QString , QString ) ) , this , SLOT ( LinkHovered ( QString , QString , QString ) ) ) ;
2011-06-26 08:30:44 +00:00
}
void MainWindow : : on_webView_loadStarted ( )
{
2011-12-26 05:51:53 +00:00
disconnect ( ui - > webView - > page ( ) , SIGNAL ( linkHovered ( QString , QString , QString ) ) , this , SLOT ( LinkHovered ( QString , QString , QString ) ) ) ;
2011-06-27 06:26:29 +00:00
if ( ! first_load ) {
2011-06-27 15:00:00 +00:00
qstatus - > setText ( tr ( " Loading " ) ) ;
2011-06-27 06:26:29 +00:00
qprogress - > reset ( ) ;
qprogress - > show ( ) ;
}
2011-06-26 08:30:44 +00:00
}
void MainWindow : : on_webView_loadProgress ( int progress )
{
qprogress - > setValue ( progress ) ;
}
2011-06-26 16:35:54 +00:00
void MainWindow : : on_action_About_triggered ( )
{
2011-11-08 15:03:39 +00:00
2011-11-15 02:14:44 +00:00
QString gitrev = QString ( GIT_REVISION ) ;
if ( ! gitrev . isEmpty ( ) ) gitrev = " Revision: " + gitrev ;
2011-12-22 10:29:12 +00:00
QString msg = tr ( " <html><body><div align='center'><h2>SleepyHead v%1.%2.%3 (%7)</h2>Build Date: %4 %5<br/>%6<hr> "
2011-07-15 10:01:28 +00:00
" Copyright ©2011 Mark Watkins (jedimark) <br> \n "
" <a href='http://sleepyhead.sourceforge.net'>http://sleepyhead.sourceforge.net</a> <hr> "
" This software is released under the GNU Public License <br> "
" <i>This software comes with absolutely no warranty, either express of implied. It comes with no guarantee of fitness for any particular purpose. No guarantees are made regarding the accuracy of any data this program displays. "
2011-12-22 10:29:12 +00:00
" </div></body></html> " ) . arg ( major_version ) . arg ( minor_version ) . arg ( revision_number ) . arg ( __DATE__ ) . arg ( __TIME__ ) . arg ( gitrev ) . arg ( ReleaseStatus ) ;
2011-06-27 15:00:00 +00:00
QMessageBox msgbox ( QMessageBox : : Information , tr ( " About SleepyHead " ) , " " , QMessageBox : : Ok , this ) ;
2011-06-26 16:35:54 +00:00
msgbox . setTextFormat ( Qt : : RichText ) ;
msgbox . setText ( msg ) ;
msgbox . exec ( ) ;
}
2011-06-27 15:00:00 +00:00
2011-07-17 15:57:45 +00:00
void MainWindow : : on_actionDebug_toggled ( bool checked )
{
2011-12-21 14:24:09 +00:00
PROFILE . general - > setShowDebug ( checked ) ;
2011-07-17 15:57:45 +00:00
if ( checked ) {
2011-07-17 16:05:16 +00:00
ui - > logText - > show ( ) ;
2011-07-17 15:57:45 +00:00
} else {
2011-07-17 16:05:16 +00:00
ui - > logText - > hide ( ) ;
2011-07-17 15:57:45 +00:00
}
}
2011-07-18 03:36:26 +00:00
2011-07-28 14:20:59 +00:00
void MainWindow : : on_action_Reset_Graph_Layout_triggered ( )
{
2011-09-12 17:47:37 +00:00
if ( daily & & ( ui - > tabWidget - > currentWidget ( ) = = daily ) ) daily - > ResetGraphLayout ( ) ;
if ( overview & & ( ui - > tabWidget - > currentWidget ( ) = = overview ) ) overview - > ResetGraphLayout ( ) ;
2011-07-28 14:20:59 +00:00
}
2011-08-02 22:37:15 +00:00
void MainWindow : : on_action_Preferences_triggered ( )
{
2011-10-05 07:41:56 +00:00
PreferencesDialog pd ( this , p_profile ) ;
2011-10-21 05:50:31 +00:00
prefdialog = & pd ;
2011-08-02 22:37:15 +00:00
if ( pd . exec ( ) = = PreferencesDialog : : Accepted ) {
qDebug ( ) < < " Preferences Accepted " ;
2011-09-08 09:50:05 +00:00
pd . Save ( ) ;
2011-09-23 03:54:48 +00:00
if ( daily ) {
2011-10-30 05:01:51 +00:00
//daily->ReloadGraphs();
2011-09-23 03:54:48 +00:00
daily - > RedrawGraphs ( ) ;
}
if ( overview ) {
overview - > ReloadGraphs ( ) ;
overview - > RedrawGraphs ( ) ;
}
2011-08-02 22:37:15 +00:00
}
2011-10-21 05:50:31 +00:00
prefdialog = NULL ;
2011-08-02 22:37:15 +00:00
}
2011-12-06 14:39:14 +00:00
void MainWindow : : selectOximetryTab ( )
{
on_oximetryButton_clicked ( ) ;
}
2011-08-05 00:12:23 +00:00
2011-08-05 08:20:28 +00:00
void MainWindow : : on_oximetryButton_clicked ( )
{
2011-10-05 06:45:33 +00:00
bool first = false ;
if ( ! oximetry ) {
2011-12-21 14:24:09 +00:00
if ( ! PROFILE . oxi - > oximetryEnabled ( ) ) {
2011-12-01 01:47:09 +00:00
if ( QMessageBox : : question ( this , " Question " , " Do you have a CMS50[x] Oximeter? \n One is required to use this section. " , QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : No ) return ;
2011-12-21 14:24:09 +00:00
PROFILE . oxi - > setOximetryEnabled ( true ) ;
2011-10-05 06:49:12 +00:00
}
2011-11-27 14:35:25 +00:00
oximetry = new Oximetry ( ui - > tabWidget , daily - > graphView ( ) ) ;
2011-12-21 14:24:09 +00:00
ui - > tabWidget - > insertTab ( 3 , oximetry , STR_TR_Oximetry ) ;
2011-10-05 06:45:33 +00:00
first = true ;
2011-08-05 08:20:28 +00:00
}
2011-10-05 06:45:33 +00:00
ui - > tabWidget - > setCurrentWidget ( oximetry ) ;
if ( ! first ) oximetry - > RedrawGraphs ( ) ;
2011-12-21 14:24:09 +00:00
qstatus2 - > setText ( STR_TR_Oximetry ) ;
2011-08-05 08:20:28 +00:00
}
2011-09-04 13:09:21 +00:00
2011-10-21 05:50:31 +00:00
void MainWindow : : CheckForUpdates ( )
{
2011-12-16 16:31:58 +00:00
on_actionCheck_for_Updates_triggered ( ) ;
2011-10-21 05:50:31 +00:00
}
2011-09-06 07:33:34 +00:00
void MainWindow : : on_actionCheck_for_Updates_triggered ( )
{
2011-12-16 18:15:57 +00:00
UpdaterWindow * w = new UpdaterWindow ( this ) ;
2011-12-16 16:31:58 +00:00
w - > checkForUpdates ( ) ;
2011-09-06 07:33:34 +00:00
}
2011-09-07 08:08:27 +00:00
void MainWindow : : on_action_Screenshot_triggered ( )
{
QTimer : : singleShot ( 250 , this , SLOT ( DelayedScreenshot ( ) ) ) ;
}
void MainWindow : : DelayedScreenshot ( )
{
2011-12-10 12:14:48 +00:00
//#ifdef Q_WS_MAC
// CGImageRef windowImage = CGWindowListCreateImage(imageBounds, singleWindowListOptions, windowID, imageOptions);
// originalPixmap = new QPixmap(QPixmap::fromMacCGImageRef(windowImage));
// CGImageRef img = CGDisplayCreateImageForRect(displayID, *rect);
// CFMutableDataRef imgData = CFDataCreateMutable(0, 0);
// CGImageDestinationRef imgDst = CGImageDestinationCreateWithData(imgData, kUTTypeJPEG2000, 1, 0);
// CGImageDestinationAddImage(imgDst, img, 0);
// CGImageDestinationFinalize(imgDst);
// CFRelease(imgDst);
// QPixmap pixmap=QPixmap::fromMacCGImageRef(img);
//#else
2011-09-07 08:08:27 +00:00
QPixmap pixmap = QPixmap : : grabWindow ( this - > winId ( ) ) ;
2011-12-10 12:14:48 +00:00
//#endif
2011-10-05 07:41:56 +00:00
QString a = PREF . Get ( " {home} " ) + " /Screenshots " ;
2011-09-07 08:08:27 +00:00
QDir dir ( a ) ;
if ( ! dir . exists ( ) ) {
dir . mkdir ( a ) ;
}
a + = " /screenshot- " + QDateTime : : currentDateTime ( ) . toString ( Qt : : ISODate ) + " .png " ;
pixmap . save ( a ) ;
}
2011-09-07 09:15:33 +00:00
void MainWindow : : on_actionView_O_ximetry_triggered ( )
{
on_oximetryButton_clicked ( ) ;
}
2011-09-11 06:16:45 +00:00
void MainWindow : : updatestatusBarMessage ( const QString & text )
{
ui - > statusbar - > showMessage ( text , 1000 ) ;
}
void MainWindow : : on_actionPrint_Report_triggered ( )
{
if ( ui - > tabWidget - > currentWidget ( ) = = overview ) {
2011-12-21 14:24:09 +00:00
PrintReport ( overview - > graphView ( ) , STR_TR_Overview ) ;
2011-12-01 15:40:32 +00:00
} else if ( ui - > tabWidget - > currentWidget ( ) = = daily ) {
2011-12-21 14:24:09 +00:00
PrintReport ( daily - > graphView ( ) , STR_TR_Daily , daily - > getDate ( ) ) ;
2011-12-01 15:40:32 +00:00
} else if ( ui - > tabWidget - > currentWidget ( ) = = oximetry ) {
if ( oximetry )
2011-12-21 14:24:09 +00:00
PrintReport ( oximetry - > graphView ( ) , STR_TR_Oximetry ) ;
2011-09-11 06:16:45 +00:00
} else {
2011-12-25 17:12:54 +00:00
QPrinter printer ;
# ifdef Q_WS_X11
printer . setPrinterName ( " Print to File (PDF) " ) ;
printer . setOutputFormat ( QPrinter : : PdfFormat ) ;
2011-12-25 17:20:30 +00:00
QString name ;
QString datestr ;
if ( ui - > tabWidget - > currentWidget ( ) = = ui - > summaryTab ) {
name = " Summary " ;
datestr = QDate : : currentDate ( ) . toString ( Qt : : ISODate ) ;
} else if ( ui - > tabWidget - > currentWidget ( ) = = ui - > helpTab ) {
name = " Help " ;
datestr = QDateTime : : currentDateTime ( ) . toString ( Qt : : ISODate ) ;
} else name = " Unknown " ;
QString filename = PREF . Get ( " {home}/ " + name + " _ " + PROFILE . user - > userName ( ) + " _ " + datestr + " .pdf " ) ;
2011-12-25 17:12:54 +00:00
printer . setOutputFileName ( filename ) ;
# endif
printer . setPrintRange ( QPrinter : : AllPages ) ;
printer . setOrientation ( QPrinter : : Portrait ) ;
printer . setFullPage ( false ) ; // This has nothing to do with scaling
printer . setNumCopies ( 1 ) ;
printer . setPageMargins ( 10 , 10 , 10 , 10 , QPrinter : : Millimeter ) ;
QPrintDialog pdlg ( & printer , this ) ;
if ( pdlg . exec ( ) = = QPrintDialog : : Accepted ) {
2011-12-25 17:20:30 +00:00
if ( ui - > tabWidget - > currentWidget ( ) = = ui - > summaryTab ) {
ui - > summaryView - > print ( & printer ) ;
} else if ( ui - > tabWidget - > currentWidget ( ) = = ui - > helpTab ) {
ui - > webView - > print ( & printer ) ;
}
2011-12-25 17:12:54 +00:00
}
//QMessageBox::information(this,tr("Not supported Yet"),tr("Sorry, printing from this page is not supported yet"),QMessageBox::Ok);
2011-09-11 06:16:45 +00:00
}
}
2011-10-01 12:59:05 +00:00
void MainWindow : : on_action_Edit_Profile_triggered ( )
{
2011-10-02 03:38:51 +00:00
NewProfile newprof ( this ) ;
2011-12-21 14:24:09 +00:00
newprof . edit ( PREF [ STR_GEN_Profile ] . toString ( ) ) ;
2011-10-02 03:38:51 +00:00
newprof . exec ( ) ;
2011-10-01 12:59:05 +00:00
}
2011-10-07 05:28:35 +00:00
void MainWindow : : on_action_Link_Graph_Groups_toggled ( bool arg1 )
{
2011-12-21 12:47:47 +00:00
PROFILE . general - > setLinkGroups ( arg1 ) ;
2011-10-08 14:13:39 +00:00
if ( daily ) daily - > RedrawGraphs ( ) ;
2011-10-07 05:28:35 +00:00
}
2011-10-28 11:31:31 +00:00
void MainWindow : : on_action_CycleTabs_triggered ( )
{
int i ;
qDebug ( ) < < " Switching Tabs " ;
i = ui - > tabWidget - > currentIndex ( ) + 1 ;
if ( i > = ui - > tabWidget - > count ( ) )
i = 0 ;
ui - > tabWidget - > setCurrentIndex ( i ) ;
}
2011-11-14 14:10:46 +00:00
void MainWindow : : on_actionExp_ort_triggered ( )
{
ExportCSV ex ( this ) ;
if ( ex . exec ( ) = = ExportCSV : : Accepted ) {
}
}
2011-11-21 10:20:11 +00:00
void MainWindow : : on_actionOnline_Users_Guide_triggered ( )
{
ui - > webView - > load ( QUrl ( " http://sourceforge.net/apps/mediawiki/sleepyhead/index.php?title=SleepyHead_Users_Guide " ) ) ;
2011-12-25 16:19:08 +00:00
ui - > tabWidget - > setCurrentWidget ( ui - > helpTab ) ;
2011-11-21 10:20:11 +00:00
}
void MainWindow : : on_action_Frequently_Asked_Questions_triggered ( )
{
ui - > webView - > load ( QUrl ( " http://sourceforge.net/apps/mediawiki/sleepyhead/index.php?title=Frequently_Asked_Questions " ) ) ;
2011-12-25 16:19:08 +00:00
ui - > tabWidget - > setCurrentWidget ( ui - > helpTab ) ;
2011-11-21 10:20:11 +00:00
}
2011-11-27 14:35:25 +00:00
2011-12-01 17:23:19 +00:00
void MainWindow : : PrintReport ( gGraphView * gv , QString name , QDate date )
2011-12-01 15:40:32 +00:00
{
if ( ! gv ) return ;
2011-12-11 13:57:07 +00:00
Session * journal = NULL ;
2011-12-01 17:23:19 +00:00
//QDate d=QDate::currentDate();
2011-12-01 15:40:32 +00:00
2011-12-01 17:23:19 +00:00
int visgraphs = gv - > visibleGraphs ( ) ;
if ( visgraphs = = 0 ) {
2011-12-21 05:47:33 +00:00
Notify ( tr ( " There are no graphs visible to print " ) ) ;
2011-12-01 15:57:06 +00:00
return ;
}
2011-12-01 17:23:19 +00:00
2011-12-21 17:00:19 +00:00
QString username = PROFILE . Get ( QString ( " _{ " ) + QString ( UI_STR_UserName ) + " }_ " ) ;
2011-12-12 03:39:00 +00:00
bool print_bookmarks = false ;
2011-12-21 14:24:09 +00:00
if ( name = = STR_TR_Daily ) {
2011-12-12 03:39:00 +00:00
QVariantList book_start ;
2011-12-11 13:57:07 +00:00
journal = getDaily ( ) - > GetJournalSession ( getDaily ( ) - > getDate ( ) ) ;
2011-12-21 05:47:33 +00:00
if ( journal & & journal - > settings . contains ( Bookmark_Start ) ) {
book_start = journal - > settings [ Bookmark_Start ] . toList ( ) ;
2011-12-12 03:39:00 +00:00
if ( book_start . size ( ) > 0 ) {
2011-12-21 05:47:33 +00:00
if ( QMessageBox : : question ( this , tr ( " Bookmarks " ) , tr ( " Would you like to show bookmarked areas in this report? " ) , QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : Yes ) {
2011-12-11 13:57:07 +00:00
print_bookmarks = true ;
}
}
}
}
2011-12-01 15:57:06 +00:00
2011-12-12 04:30:06 +00:00
QPrinter * printer ;
2011-12-06 23:49:26 +00:00
2011-12-21 14:24:09 +00:00
//bool highres;
bool aa_setting = PROFILE . appearance - > antiAliasing ( ) ;
2011-12-12 02:51:22 +00:00
2011-12-13 09:16:16 +00:00
# ifdef Q_WS_MAC
2011-12-21 14:24:09 +00:00
PROFILE . appearance - > setHighResPrinting ( true ) ; // forced on
2011-12-20 02:28:22 +00:00
// bool force_antialiasing=true;
//#else
2011-12-13 09:16:16 +00:00
# endif
2011-12-21 14:24:09 +00:00
bool force_antialiasing = aa_setting ;
2011-12-12 03:39:00 +00:00
2011-12-21 14:24:09 +00:00
if ( PROFILE . appearance - > highResPrinting ( ) ) {
2011-12-12 04:30:06 +00:00
printer = new QPrinter ( QPrinter : : HighResolution ) ;
2011-12-21 14:24:09 +00:00
//highres=true;
2011-12-06 23:49:26 +00:00
} else {
2011-12-12 04:30:06 +00:00
printer = new QPrinter ( QPrinter : : ScreenResolution ) ;
2011-12-21 14:24:09 +00:00
//highres=false;
2011-12-06 23:49:26 +00:00
}
2011-12-02 14:36:40 +00:00
# ifdef Q_WS_X11
2011-12-12 04:30:06 +00:00
printer - > setPrinterName ( " Print to File (PDF) " ) ;
printer - > setOutputFormat ( QPrinter : : PdfFormat ) ;
2011-12-21 14:24:09 +00:00
QString filename = PREF . Get ( " {home}/ " + name + username + date . toString ( Qt : : ISODate ) + " .pdf " ) ;
2011-12-03 04:32:01 +00:00
2011-12-12 04:30:06 +00:00
printer - > setOutputFileName ( filename ) ;
# endif
printer - > setPrintRange ( QPrinter : : AllPages ) ;
printer - > setOrientation ( QPrinter : : Portrait ) ;
printer - > setFullPage ( false ) ; // This has nothing to do with scaling
printer - > setNumCopies ( 1 ) ;
printer - > setPageMargins ( 10 , 10 , 10 , 10 , QPrinter : : Millimeter ) ;
QPrintDialog dialog ( printer ) ;
# ifdef Q_WS_MAC
// QTBUG-17913
2011-12-12 04:34:20 +00:00
QApplication : : processEvents ( ) ;
2011-12-02 14:36:40 +00:00
# endif
2011-12-06 23:49:26 +00:00
if ( dialog . exec ( ) ! = QDialog : : Accepted ) {
2011-12-12 04:30:06 +00:00
delete printer ;
2011-12-01 15:57:06 +00:00
return ;
2011-12-02 14:36:40 +00:00
}
2011-12-18 16:39:36 +00:00
Notify ( tr ( " This make take some time to complete.. \n Please don't touch anything until it's done. " ) , tr ( " Printing %1 Report " ) . arg ( name ) , 20000 ) ;
2011-12-01 15:40:32 +00:00
QPainter painter ;
2011-12-12 04:30:06 +00:00
painter . begin ( printer ) ;
2011-12-01 17:23:19 +00:00
2011-12-12 14:06:08 +00:00
GLint gw ;
2011-12-19 18:12:04 +00:00
//#ifdef Q_WS_WIN32
2011-12-13 10:20:22 +00:00
gw = 2048 ; // Rough guess.. No GL_MAX_RENDERBUFFER_SIZE in mingw.. :(
2011-12-19 18:12:04 +00:00
//#else
// glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE,&gw);
//#endif
2011-12-07 10:19:28 +00:00
2011-12-19 15:33:01 +00:00
//QSizeF pxres=printer->paperSize(QPrinter::DevicePixel);
QRect prect = printer - > pageRect ( ) ;
float ratio = float ( prect . height ( ) ) / float ( prect . width ( ) ) ;
float virt_width = gw ;
float virt_height = virt_width * ratio ;
painter . setWindow ( 0 , 0 , virt_width , virt_height ) ;
painter . setViewport ( 0 , 0 , prect . width ( ) , prect . height ( ) ) ;
painter . setViewTransformEnabled ( true ) ;
QFont report_font = * defaultfont ;
QFont medium_font = * mediumfont ;
QFont title_font = * bigfont ;
float normal_height = 30 ; //fm2.ascent();
report_font . setPixelSize ( normal_height ) ;
medium_font . setPixelSize ( 40 ) ;
title_font . setPixelSize ( 90 ) ;
painter . setFont ( report_font ) ;
2011-12-07 10:19:28 +00:00
2011-12-19 15:33:01 +00:00
//QFontMetrics fm2(*defaultfont);
qDebug ( ) < < " Printer Resolution is " < < virt_width < < " x " < < virt_height ;
const int graphs_per_page = 6 ;
float full_graph_height = ( virt_height - ( normal_height * graphs_per_page ) ) / float ( graphs_per_page ) ;
2011-12-07 10:19:28 +00:00
2011-12-18 16:39:36 +00:00
QString title = tr ( " %1 Report " ) . arg ( name ) ;
2011-12-19 15:33:01 +00:00
painter . setFont ( title_font ) ;
2011-12-12 14:06:08 +00:00
int top = 0 ;
2011-12-19 15:33:01 +00:00
QRectF bounds = painter . boundingRect ( QRectF ( 0 , top , virt_width , 0 ) , title , QTextOption ( Qt : : AlignHCenter | Qt : : AlignTop ) ) ;
2011-12-12 09:16:26 +00:00
painter . drawText ( bounds , title , QTextOption ( Qt : : AlignHCenter | Qt : : AlignTop ) ) ;
2011-12-14 06:58:10 +00:00
top + = bounds . height ( ) + normal_height / 2.0 ;
2011-12-19 15:33:01 +00:00
painter . setFont ( report_font ) ;
2011-12-12 14:06:08 +00:00
2011-12-06 14:39:14 +00:00
int maxy = 0 ;
2011-12-21 14:24:09 +00:00
if ( ! PROFILE . user - > firstName ( ) . isEmpty ( ) ) {
QString userinfo = tr ( " Name: \t %1, %2 \n " ) . arg ( PROFILE . user - > lastName ( ) ) . arg ( PROFILE . user - > firstName ( ) ) ;
userinfo + = tr ( " DOB: \t %1 \n " ) . arg ( PROFILE . user - > DOB ( ) . toString ( Qt : : SystemLocaleShortDate ) ) ;
2012-01-01 17:10:37 +00:00
if ( ! PROFILE . doctor - > patientID ( ) . isEmpty ( ) ) userinfo + = tr ( " Patient ID: \t %1 \n " ) . arg ( PROFILE . doctor - > patientID ( ) ) ;
2011-12-21 14:24:09 +00:00
userinfo + = tr ( " Phone: \t %1 \n " ) . arg ( PROFILE . user - > phone ( ) ) ;
userinfo + = tr ( " Email: \t %1 \n " ) . arg ( PROFILE . user - > email ( ) ) ;
if ( ! PROFILE . user - > address ( ) . isEmpty ( ) ) userinfo + = tr ( " \n Address: \n %1 " ) . arg ( PROFILE . user - > address ( ) ) ;
2011-12-19 15:33:01 +00:00
QRectF bounds = painter . boundingRect ( QRectF ( 0 , top , virt_width , 0 ) , userinfo , QTextOption ( Qt : : AlignLeft | Qt : : AlignTop ) ) ;
2011-12-12 14:06:08 +00:00
painter . drawText ( bounds , userinfo , QTextOption ( Qt : : AlignLeft | Qt : : AlignTop ) ) ;
2011-12-06 14:39:14 +00:00
if ( bounds . height ( ) > maxy ) maxy = bounds . height ( ) ;
2011-12-01 17:23:19 +00:00
}
2011-12-25 05:05:12 +00:00
Day * cpap = NULL , * oxi = NULL ;
2011-12-13 11:08:02 +00:00
int graph_slots = 0 ;
2011-12-21 14:24:09 +00:00
if ( name = = STR_TR_Daily ) {
2011-12-28 12:36:40 +00:00
cpap = PROFILE . GetGoodDay ( date , MT_CPAP ) ;
oxi = PROFILE . GetGoodDay ( date , MT_OXIMETER ) ;
2011-12-13 07:50:22 +00:00
QString cpapinfo = date . toString ( Qt : : SystemLocaleLongDate ) + " \n \n " ;
2011-12-01 17:23:19 +00:00
if ( cpap ) {
2011-12-01 17:46:25 +00:00
time_t f = cpap - > first ( ) / 1000L ;
time_t l = cpap - > last ( ) / 1000L ;
2011-12-01 17:23:19 +00:00
int tt = qint64 ( cpap - > total_time ( ) ) / 1000L ;
int h = tt / 3600 ;
int m = ( tt / 60 ) % 60 ;
int s = tt % 60 ;
2011-12-18 16:39:36 +00:00
cpapinfo + = tr ( " Mask Time: " ) + QString ( ) . sprintf ( " %2i hours, %2i minutes, %2i seconds " , h , m , s ) + " \n " ;
cpapinfo + = tr ( " Bedtime: " ) + QDateTime : : fromTime_t ( f ) . time ( ) . toString ( " HH:mm:ss " ) + " " ;
cpapinfo + = tr ( " Wake-up: " ) + QDateTime : : fromTime_t ( l ) . time ( ) . toString ( " HH:mm:ss " ) + " \n \n " ;
2011-12-12 09:16:26 +00:00
QString submodel ;
2011-12-18 16:39:36 +00:00
cpapinfo + = tr ( " Machine: " ) ;
2011-12-21 14:24:09 +00:00
if ( cpap - > machine - > properties . find ( STR_PROP_SubModel ) ! = cpap - > machine - > properties . end ( ) )
submodel = " \n " + cpap - > machine - > properties [ STR_PROP_SubModel ] ;
cpapinfo + = cpap - > machine - > properties [ STR_PROP_Brand ] + " " + cpap - > machine - > properties [ STR_PROP_Model ] + submodel ;
2011-12-17 14:50:59 +00:00
CPAPMode mode = ( CPAPMode ) ( int ) cpap - > settings_max ( CPAP_Mode ) ;
2011-12-18 16:39:36 +00:00
cpapinfo + = tr ( " \n Mode: " ) ;
2011-12-12 09:16:26 +00:00
2011-12-31 11:36:19 +00:00
if ( mode = = MODE_CPAP ) {
EventDataType min = round ( cpap - > settings_wavg ( CPAP_Pressure ) * 2 ) / 2.0 ;
cpapinfo + = tr ( " CPAP " ) + " " + QString : : number ( min ) + STR_UNIT_CMH2O ;
} else if ( mode = = MODE_APAP ) {
EventDataType min = cpap - > settings_min ( CPAP_PressureMin ) ;
EventDataType max = cpap - > settings_max ( CPAP_PressureMax ) ;
cpapinfo + = tr ( " APAP " ) + " " + QString : : number ( min ) + " - " + QString : : number ( max ) + STR_UNIT_CMH2O ;
} else if ( mode = = MODE_BIPAP ) {
EventDataType epap = cpap - > settings_min ( CPAP_EPAP ) ;
EventDataType ipap = cpap - > settings_max ( CPAP_IPAP ) ;
EventDataType ps = cpap - > settings_max ( CPAP_PS ) ;
cpapinfo + = tr ( " Bi-Level " ) + QString ( " \n EPAP: %1 IPAP: %2 %3 \n PS: %4 " )
. arg ( epap , 0 , ' f ' , 1 ) . arg ( ipap , 0 , ' f ' , 1 ) . arg ( STR_UNIT_CMH2O ) . arg ( ps , 0 , ' f ' , 1 ) ;
}
else if ( mode = = MODE_ASV ) {
EventDataType epap = cpap - > settings_min ( CPAP_EPAP ) ;
EventDataType low = cpap - > settings_min ( CPAP_IPAPLo ) ;
EventDataType high = cpap - > settings_max ( CPAP_IPAPHi ) ;
EventDataType psl = cpap - > settings_min ( CPAP_PSMin ) ;
EventDataType psh = cpap - > settings_max ( CPAP_PSMax ) ;
cpapinfo + = tr ( " ASV " ) + QString ( " \n EPAP: %1 IPAP: %2 - %3 %4 \n PS: %5 / %6 " )
. arg ( epap , 0 , ' f ' , 1 )
. arg ( low , 0 , ' f ' , 1 )
. arg ( high , 0 , ' f ' , 1 )
. arg ( STR_UNIT_CMH2O )
. arg ( psl , 0 , ' f ' , 1 )
. arg ( psh , 0 , ' f ' , 1 ) ;
}
else cpapinfo + = tr ( " Unknown " ) ;
2011-12-12 09:16:26 +00:00
2011-12-24 05:55:44 +00:00
float ahi = ( cpap - > count ( CPAP_Obstructive ) + cpap - > count ( CPAP_Hypopnea ) + cpap - > count ( CPAP_ClearAirway ) + cpap - > count ( CPAP_Apnea ) ) ;
if ( PROFILE . general - > calculateRDI ( ) ) ahi + = cpap - > count ( CPAP_RERA ) ;
ahi / = cpap - > hours ( ) ;
2011-12-01 17:23:19 +00:00
float csr = ( 100.0 / cpap - > hours ( ) ) * ( cpap - > sum ( CPAP_CSR ) / 3600.0 ) ;
float uai = cpap - > count ( CPAP_Apnea ) / cpap - > hours ( ) ;
float oai = cpap - > count ( CPAP_Obstructive ) / cpap - > hours ( ) ;
float hi = ( cpap - > count ( CPAP_ExP ) + cpap - > count ( CPAP_Hypopnea ) ) / cpap - > hours ( ) ;
float cai = cpap - > count ( CPAP_ClearAirway ) / cpap - > hours ( ) ;
float rei = cpap - > count ( CPAP_RERA ) / cpap - > hours ( ) ;
float vsi = cpap - > count ( CPAP_VSnore ) / cpap - > hours ( ) ;
float fli = cpap - > count ( CPAP_FlowLimit ) / cpap - > hours ( ) ;
float nri = cpap - > count ( CPAP_NRI ) / cpap - > hours ( ) ;
float lki = cpap - > count ( CPAP_LeakFlag ) / cpap - > hours ( ) ;
float exp = cpap - > count ( CPAP_ExP ) / cpap - > hours ( ) ;
2011-12-25 05:05:12 +00:00
int piesize = ( 2048.0 / 8.0 ) * 1.3 ; // 1.5" in size
2011-12-19 15:33:01 +00:00
//float fscale=font_scale;
//if (!highres)
// fscale=1;
2011-12-14 06:39:03 +00:00
2011-12-20 02:28:22 +00:00
QString stats ;
painter . setFont ( medium_font ) ;
2011-12-24 05:55:44 +00:00
if ( PROFILE . general - > calculateRDI ( ) )
stats = tr ( " RDI \t %1 \n " ) . arg ( ahi , 0 , ' f ' , 2 ) ;
else
stats = tr ( " AHI \t %1 \n " ) . arg ( ahi , 0 , ' f ' , 2 ) ;
2011-12-20 02:28:22 +00:00
QRectF bounds = painter . boundingRect ( QRectF ( 0 , 0 , virt_width , 0 ) , stats , QTextOption ( Qt : : AlignRight ) ) ;
painter . drawText ( bounds , stats , QTextOption ( Qt : : AlignRight ) ) ;
2011-12-14 06:39:03 +00:00
2011-12-25 05:05:12 +00:00
getDaily ( ) - > eventBreakdownPie ( ) - > setShowTitle ( false ) ;
getDaily ( ) - > eventBreakdownPie ( ) - > setMargins ( 0 , 0 , 0 , 0 ) ;
QPixmap ebp ;
if ( ahi > 0 ) {
ebp = getDaily ( ) - > eventBreakdownPie ( ) - > renderPixmap ( piesize , piesize , true ) ;
} else {
ebp = QPixmap ( " :/icons/smileyface.png " ) ;
}
painter . drawPixmap ( virt_width - piesize , bounds . height ( ) , piesize , piesize , ebp ) ;
getDaily ( ) - > eventBreakdownPie ( ) - > setShowTitle ( true ) ;
2011-12-13 10:53:44 +00:00
cpapinfo + = " \n \n " ;
2011-12-19 15:33:01 +00:00
painter . setFont ( report_font ) ;
2011-12-20 02:32:57 +00:00
//bounds=painter.boundingRect(QRectF((virt_width/2)-(virt_width/6),top,virt_width/2,0),cpapinfo,QTextOption(Qt::AlignLeft));
bounds = painter . boundingRect ( QRectF ( 0 , top , virt_width , 0 ) , cpapinfo , QTextOption ( Qt : : AlignHCenter ) ) ;
painter . drawText ( bounds , cpapinfo , QTextOption ( Qt : : AlignHCenter ) ) ;
2011-12-13 10:53:44 +00:00
int ttop = bounds . height ( ) ;
2011-12-12 16:32:10 +00:00
2011-12-18 16:39:36 +00:00
stats = tr ( " AI=%1 HI=%2 CAI=%3 " ) . arg ( oai , 0 , ' f ' , 2 ) . arg ( hi , 0 , ' f ' , 2 ) . arg ( cai , 0 , ' f ' , 2 ) ;
2011-12-21 14:24:09 +00:00
if ( cpap - > machine - > GetClass ( ) = = STR_MACH_PRS1 ) {
2011-12-19 15:33:01 +00:00
stats + = tr ( " REI=%1 VSI=%2 FLI=%3 PB/CSR=%4 \ % " )
2011-12-18 16:39:36 +00:00
. arg ( rei , 0 , ' f ' , 2 ) . arg ( vsi , 0 , ' f ' , 2 )
. arg ( fli , 0 , ' f ' , 2 ) . arg ( csr , 0 , ' f ' , 2 ) ;
2011-12-21 14:24:09 +00:00
} else if ( cpap - > machine - > GetClass ( ) = = STR_MACH_ResMed ) {
2011-12-18 16:39:36 +00:00
stats + = tr ( " UAI=%1 " ) . arg ( uai , 0 , ' f ' , 2 ) ;
2011-12-21 14:24:09 +00:00
} else if ( cpap - > machine - > GetClass ( ) = = STR_MACH_Intellipap ) {
2011-12-18 16:39:36 +00:00
stats + = tr ( " NRI=%1 LKI=%2 EPI=%3 " ) . arg ( nri , 0 , ' f ' , 2 ) . arg ( lki , 0 , ' f ' , 2 ) . arg ( exp , 0 , ' f ' , 2 ) ;
2011-12-01 17:23:19 +00:00
}
2012-01-01 16:52:54 +00:00
bounds = painter . boundingRect ( QRectF ( 0 , top + ttop , virt_width , 0 ) , stats , QTextOption ( Qt : : AlignHCenter ) ) ;
painter . drawText ( bounds , stats , QTextOption ( Qt : : AlignHCenter ) ) ;
2011-12-13 10:53:44 +00:00
ttop + = bounds . height ( ) ;
2012-01-01 16:52:54 +00:00
if ( journal ) {
stats = " " ;
if ( journal - > settings . contains ( Journal_Weight ) )
stats + = tr ( " Weight %1 " ) . arg ( weightString ( journal - > settings [ Journal_Weight ] . toDouble ( ) ) ) ;
if ( journal - > settings . contains ( Journal_BMI ) )
stats + = tr ( " BMI %1 " ) . arg ( journal - > settings [ Journal_BMI ] . toDouble ( ) , 0 , ' f ' , 2 ) ;
if ( journal - > settings . contains ( Journal_ZombieMeter ) )
stats + = tr ( " Zombie %1/10 " ) . arg ( journal - > settings [ Journal_ZombieMeter ] . toDouble ( ) , 0 , ' f ' , 0 ) ;
if ( ! stats . isEmpty ( ) ) {
bounds = painter . boundingRect ( QRectF ( 0 , top + ttop , virt_width , 0 ) , stats , QTextOption ( Qt : : AlignHCenter ) ) ;
painter . drawText ( bounds , stats , QTextOption ( Qt : : AlignHCenter ) ) ;
ttop + = bounds . height ( ) ;
}
ttop + = normal_height ;
if ( journal - > settings . contains ( Journal_Notes ) ) {
QTextDocument doc ;
doc . setHtml ( journal - > settings [ Journal_Notes ] . toString ( ) ) ;
stats = doc . toPlainText ( ) ;
2012-01-01 17:10:37 +00:00
//doc.drawContents(&painter); // doesn't work as intended..
2012-01-01 16:52:54 +00:00
bounds = painter . boundingRect ( QRectF ( 0 , top + ttop , virt_width , 0 ) , stats , QTextOption ( Qt : : AlignHCenter ) ) ;
painter . drawText ( bounds , stats , QTextOption ( Qt : : AlignHCenter ) ) ;
bounds . setLeft ( virt_width / 4 ) ;
bounds . setRight ( virt_width - ( virt_width / 4 ) ) ;
QPen pen ( Qt : : black ) ;
pen . setWidth ( 4 ) ;
painter . setPen ( pen ) ;
painter . drawRect ( bounds ) ;
ttop + = bounds . height ( ) + normal_height ;
}
}
2011-12-13 10:53:44 +00:00
if ( ttop > maxy ) maxy = ttop ;
2011-12-13 07:50:22 +00:00
} else {
2011-12-19 15:33:01 +00:00
bounds = painter . boundingRect ( QRectF ( 0 , top + maxy , virt_width , 0 ) , cpapinfo , QTextOption ( Qt : : AlignCenter ) ) ;
2011-12-13 07:50:22 +00:00
painter . drawText ( bounds , cpapinfo , QTextOption ( Qt : : AlignCenter ) ) ;
if ( maxy + bounds . height ( ) > maxy ) maxy = maxy + bounds . height ( ) ;
2011-12-01 17:23:19 +00:00
}
2011-12-21 14:24:09 +00:00
} else if ( name = = STR_TR_Overview ) {
2011-12-01 17:46:25 +00:00
QDateTime first = QDateTime : : fromTime_t ( ( * gv ) [ 0 ] - > min_x / 1000L ) ;
QDateTime last = QDateTime : : fromTime_t ( ( * gv ) [ 0 ] - > max_x / 1000L ) ;
2011-12-18 16:39:36 +00:00
QString ovinfo = tr ( " Reporting from %1 to %2 " ) . arg ( first . date ( ) . toString ( Qt : : SystemLocaleShortDate ) ) . arg ( last . date ( ) . toString ( Qt : : SystemLocaleShortDate ) ) ;
2012-01-01 16:52:54 +00:00
QRectF bounds = painter . boundingRect ( QRectF ( 0 , top , virt_width , 0 ) , ovinfo , QTextOption ( Qt : : AlignHCenter ) ) ;
painter . drawText ( bounds , ovinfo , QTextOption ( Qt : : AlignHCenter ) ) ;
2011-12-06 14:39:14 +00:00
2011-12-12 14:06:08 +00:00
if ( bounds . height ( ) > maxy ) maxy = bounds . height ( ) ;
2011-12-21 14:24:09 +00:00
} else if ( name = = STR_TR_Oximetry ) {
2011-12-18 16:39:36 +00:00
QString ovinfo = tr ( " Reporting data goes here " ) ;
2012-01-01 16:52:54 +00:00
QRectF bounds = painter . boundingRect ( QRectF ( 0 , top , virt_width , 0 ) , ovinfo , QTextOption ( Qt : : AlignHCenter ) ) ;
painter . drawText ( bounds , ovinfo , QTextOption ( Qt : : AlignHCenter ) ) ;
2011-12-12 14:06:08 +00:00
2011-12-06 14:39:14 +00:00
if ( bounds . height ( ) > maxy ) maxy = bounds . height ( ) ;
2011-12-01 17:23:19 +00:00
}
2011-12-06 14:39:14 +00:00
top + = maxy ;
2011-12-01 17:23:19 +00:00
2012-01-01 16:52:54 +00:00
graph_slots = graphs_per_page - ( ( virt_height - top ) / ( full_graph_height + normal_height ) ) ;
2011-12-01 17:23:19 +00:00
bool first = true ;
2011-12-11 13:57:07 +00:00
QStringList labels ;
QVector < gGraph * > graphs ;
QVector < qint64 > start , end ;
2011-12-25 05:05:12 +00:00
qint64 savest , saveet ;
gv - > GetXBounds ( savest , saveet ) ;
qint64 st = savest , et = saveet ;
2011-12-23 14:12:04 +00:00
gGraph * g ;
2011-12-25 05:05:12 +00:00
if ( name = = STR_TR_Daily ) {
if ( ! print_bookmarks ) {
for ( int i = 0 ; i < gv - > size ( ) ; i + + ) {
gGraph * g = ( * gv ) [ i ] ;
if ( g - > isEmpty ( ) ) continue ;
if ( ! g - > visible ( ) ) continue ;
if ( cpap ) {
st = cpap - > first ( ) ;
et = cpap - > last ( ) ;
} else if ( oxi ) {
st = oxi - > first ( ) ;
et = oxi - > last ( ) ;
}
if ( g - > title ( ) = = STR_TR_FlowRate ) {
if ( ! ( ( qAbs ( savest - st ) < 2000 ) & & ( qAbs ( saveet - et ) < 2000 ) ) ) {
start . push_back ( st ) ;
end . push_back ( et ) ;
graphs . push_back ( g ) ;
labels . push_back ( tr ( " Entire Day's Flow Waveform " ) ) ;
}
}
start . push_back ( savest ) ;
end . push_back ( saveet ) ;
2011-12-23 14:12:04 +00:00
graphs . push_back ( g ) ;
labels . push_back ( " " ) ;
2011-12-25 05:05:12 +00:00
2011-12-23 14:12:04 +00:00
}
2011-12-25 05:05:12 +00:00
} else {
if ( journal ) {
if ( journal - > settings . contains ( Bookmark_Start ) ) {
QVariantList st1 = journal - > settings [ Bookmark_Start ] . toList ( ) ;
QVariantList et1 = journal - > settings [ Bookmark_End ] . toList ( ) ;
QStringList notes = journal - > settings [ Bookmark_Notes ] . toStringList ( ) ;
gGraph * flow = gv - > findGraph ( STR_TR_FlowRate ) ,
* spo2 = gv - > findGraph ( STR_TR_SpO2 ) ,
* pulse = gv - > findGraph ( STR_TR_PulseRate ) ;
if ( cpap & & flow & & ! flow - > isEmpty ( ) & & flow - > visible ( ) ) {
labels . push_back ( " Entire Day " ) ;
start . push_back ( cpap - > first ( ) ) ;
end . push_back ( cpap - > last ( ) ) ;
2011-12-23 14:12:04 +00:00
graphs . push_back ( flow ) ;
}
2011-12-25 05:05:12 +00:00
if ( oxi & & spo2 & & ! spo2 - > isEmpty ( ) & & spo2 - > visible ( ) ) {
labels . push_back ( " Entire Day " ) ;
start . push_back ( oxi - > first ( ) ) ;
end . push_back ( oxi - > last ( ) ) ;
2011-12-23 14:12:04 +00:00
graphs . push_back ( spo2 ) ;
}
2011-12-25 05:05:12 +00:00
if ( oxi & & pulse & & ! pulse - > isEmpty ( ) & & pulse - > visible ( ) ) {
labels . push_back ( " Entire Day " ) ;
start . push_back ( oxi - > first ( ) ) ;
end . push_back ( oxi - > last ( ) ) ;
2011-12-23 14:12:04 +00:00
graphs . push_back ( pulse ) ;
2011-12-11 13:57:07 +00:00
}
2011-12-25 05:05:12 +00:00
for ( int i = 0 ; i < notes . size ( ) ; i + + ) {
if ( flow & & ! flow - > isEmpty ( ) & & flow - > visible ( ) ) {
labels . push_back ( notes . at ( i ) ) ;
start . push_back ( st1 . at ( i ) . toLongLong ( ) ) ;
end . push_back ( et1 . at ( i ) . toLongLong ( ) ) ;
graphs . push_back ( flow ) ;
}
if ( spo2 & & ! spo2 - > isEmpty ( ) & & spo2 - > visible ( ) ) {
labels . push_back ( notes . at ( i ) ) ;
start . push_back ( st1 . at ( i ) . toLongLong ( ) ) ;
end . push_back ( et1 . at ( i ) . toLongLong ( ) ) ;
graphs . push_back ( spo2 ) ;
}
if ( pulse & & ! pulse - > isEmpty ( ) & & pulse - > visible ( ) ) {
labels . push_back ( notes . at ( i ) ) ;
start . push_back ( st1 . at ( i ) . toLongLong ( ) ) ;
end . push_back ( et1 . at ( i ) . toLongLong ( ) ) ;
graphs . push_back ( pulse ) ;
}
}
}
}
for ( int i = 0 ; i < gv - > size ( ) ; i + + ) {
gGraph * g = ( * gv ) [ i ] ;
if ( g - > isEmpty ( ) ) continue ;
if ( ! g - > visible ( ) ) continue ;
if ( ( g - > title ( ) ! = STR_TR_FlowRate ) & & ( g - > title ( ) ! = STR_TR_SpO2 ) & & ( g - > title ( ) ! = STR_TR_PulseRate ) ) {
start . push_back ( st ) ;
end . push_back ( et ) ;
graphs . push_back ( g ) ;
labels . push_back ( tr ( " " ) ) ;
2011-12-11 13:57:07 +00:00
}
}
}
2011-12-25 05:05:12 +00:00
} else {
2011-12-23 14:12:04 +00:00
for ( int i = 0 ; i < gv - > size ( ) ; i + + ) {
gGraph * g = ( * gv ) [ i ] ;
if ( g - > isEmpty ( ) ) continue ;
if ( ! g - > visible ( ) ) continue ;
2011-12-25 05:05:12 +00:00
start . push_back ( st ) ;
end . push_back ( et ) ;
graphs . push_back ( g ) ;
labels . push_back ( " " ) ; // date range?
2011-12-11 13:57:07 +00:00
}
}
2011-12-13 11:08:02 +00:00
int pages = ceil ( float ( graphs . size ( ) + graph_slots ) / float ( graphs_per_page ) ) ;
2011-12-11 13:57:07 +00:00
if ( qprogress ) {
qprogress - > setValue ( 0 ) ;
qprogress - > setMaximum ( graphs . size ( ) ) ;
qprogress - > show ( ) ;
}
2011-12-12 14:06:08 +00:00
int page = 1 ;
int gcnt = 0 ;
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2011-12-13 07:00:56 +00:00
2011-12-19 15:33:01 +00:00
if ( ( top + full_graph_height + normal_height ) > virt_height ) {
2011-12-13 07:00:56 +00:00
top = 0 ;
gcnt = 0 ;
first = true ;
2011-12-13 10:20:22 +00:00
if ( page > pages )
break ;
2011-12-13 07:00:56 +00:00
if ( ! printer - > newPage ( ) ) {
qWarning ( " failed in flushing page to disk, disk full? " ) ;
break ;
}
}
2011-12-01 17:23:19 +00:00
if ( first ) {
2011-12-22 10:29:12 +00:00
QString footer = tr ( " SleepyHead v%1 - http://sleepyhead.sourceforge.net " ) . arg ( VersionString ) ;
2011-12-01 17:23:19 +00:00
2011-12-19 15:33:01 +00:00
QRectF bounds = painter . boundingRect ( QRectF ( 0 , virt_height , virt_width , normal_height ) , footer , QTextOption ( Qt : : AlignHCenter ) ) ;
2011-12-01 17:23:19 +00:00
painter . drawText ( bounds , footer , QTextOption ( Qt : : AlignHCenter ) ) ;
2011-12-18 16:39:36 +00:00
QString pagestr = tr ( " Page %1 of %2 " ) . arg ( page ) . arg ( pages ) ;
2011-12-19 15:33:01 +00:00
QRectF pagebnds = painter . boundingRect ( QRectF ( 0 , virt_height , virt_width , normal_height ) , pagestr , QTextOption ( Qt : : AlignRight ) ) ;
2011-12-06 23:49:26 +00:00
painter . drawText ( pagebnds , pagestr , QTextOption ( Qt : : AlignRight ) ) ;
2011-12-01 17:23:19 +00:00
first = false ;
2011-12-13 07:00:56 +00:00
page + + ;
2011-12-01 17:23:19 +00:00
}
2011-12-13 07:00:56 +00:00
2011-12-11 13:57:07 +00:00
gGraph * g = graphs [ i ] ;
g - > SetXBounds ( start [ i ] , end [ i ] ) ;
2011-12-01 15:40:32 +00:00
g - > deselect ( ) ;
2011-12-07 10:19:28 +00:00
2011-12-11 13:57:07 +00:00
QString label = labels [ i ] ;
2011-12-12 07:10:45 +00:00
if ( ! label . isEmpty ( ) ) {
2011-12-13 07:00:56 +00:00
//label+=":";
top + = normal_height / 3 ;
2012-01-01 16:52:54 +00:00
QRectF bounds = painter . boundingRect ( QRectF ( 0 , top , virt_width , 0 ) , label , QTextOption ( Qt : : AlignHCenter ) ) ;
//QRectF pagebnds=QRectF(0,top,virt_width,normal_height);
painter . drawText ( bounds , label , QTextOption ( Qt : : AlignHCenter ) ) ;
top + = bounds . height ( ) ;
2011-12-12 14:06:08 +00:00
} else top + = normal_height / 2 ;
2011-12-12 07:10:45 +00:00
2011-12-21 14:24:09 +00:00
PROFILE . appearance - > setAntiAliasing ( force_antialiasing ) ;
2011-12-12 07:10:45 +00:00
int tmb = g - > m_marginbottom ;
g - > m_marginbottom = 0 ;
2011-12-12 14:06:08 +00:00
2011-12-12 16:32:10 +00:00
//g->showTitle(false);
2011-12-19 15:33:01 +00:00
QPixmap pm = g - > renderPixmap ( virt_width , full_graph_height - normal_height , 1 ) ; //fscale);
2011-12-12 16:32:10 +00:00
//g->showTitle(true);
2011-12-12 14:06:08 +00:00
2011-12-12 07:10:45 +00:00
g - > m_marginbottom = tmb ;
2011-12-21 14:24:09 +00:00
PROFILE . appearance - > setAntiAliasing ( aa_setting ) ;
2011-12-07 10:19:28 +00:00
2011-12-19 15:33:01 +00:00
painter . drawPixmap ( 0 , top , virt_width , full_graph_height - normal_height , pm ) ;
2011-12-14 11:23:49 +00:00
top + = full_graph_height ;
2011-12-14 06:39:03 +00:00
2011-12-12 07:10:45 +00:00
gcnt + + ;
2011-12-01 15:40:32 +00:00
if ( qprogress ) {
qprogress - > setValue ( i ) ;
QApplication : : processEvents ( ) ;
}
2011-12-12 14:06:08 +00:00
}
2011-12-01 15:40:32 +00:00
2011-12-25 05:05:12 +00:00
gv - > SetXBounds ( savest , saveet ) ;
2011-12-01 15:40:32 +00:00
qprogress - > hide ( ) ;
painter . end ( ) ;
2011-12-12 04:30:06 +00:00
delete printer ;
2011-12-13 10:53:44 +00:00
Notify ( " SleepyHead has finished sending the job to the printer. " ) ;
2011-12-01 15:40:32 +00:00
}
2011-12-23 10:52:31 +00:00
void packEventList ( EventList * el , EventDataType minval = 0 )
{
if ( el - > count ( ) < 2 ) return ;
EventList nel ( EVL_Waveform ) ;
EventDataType t , lastt = 0 ; //el->data(0);
qint64 ti ; //=el->time(0);
//nel.AddEvent(ti,lastt);
bool f ;
qint64 lasttime = 0 ;
EventDataType min = 999 , max = 0 ;
for ( quint32 i = 0 ; i < el - > count ( ) ; i + + ) {
t = el - > data ( i ) ;
ti = el - > time ( i ) ;
f = false ;
if ( t > minval ) {
if ( t ! = lastt ) {
if ( ! lasttime ) {
nel . setFirst ( ti ) ;
}
nel . AddEvent ( ti , t ) ;
if ( t < min ) min = t ;
if ( t > max ) max = t ;
lasttime = ti ;
f = true ;
}
} else {
if ( lastt > minval ) {
nel . AddEvent ( ti , lastt ) ;
lasttime = ti ;
f = true ;
}
}
lastt = t ;
}
if ( ! f ) {
if ( t > minval ) {
nel . AddEvent ( ti , t ) ;
lasttime = ti ;
}
}
el - > setFirst ( nel . first ( ) ) ;
el - > setLast ( nel . last ( ) ) ;
el - > setMin ( min ) ;
el - > setMax ( max ) ;
el - > getData ( ) . clear ( ) ;
el - > getTime ( ) . clear ( ) ;
el - > setCount ( nel . count ( ) ) ;
el - > getData ( ) = nel . getData ( ) ;
el - > getTime ( ) = nel . getTime ( ) ;
}
2011-12-01 01:47:09 +00:00
void MainWindow : : on_action_Rebuild_Oximetry_Index_triggered ( )
{
2011-12-21 17:00:19 +00:00
QVector < ChannelID > valid ;
2011-12-01 01:47:09 +00:00
valid . push_back ( OXI_Pulse ) ;
valid . push_back ( OXI_SPO2 ) ;
valid . push_back ( OXI_Plethy ) ;
2011-12-01 03:05:23 +00:00
//valid.push_back(OXI_PulseChange); // Delete these and recalculate..
//valid.push_back(OXI_SPO2Drop);
2011-12-01 01:47:09 +00:00
2011-12-21 17:00:19 +00:00
QVector < ChannelID > invalid ;
2011-12-01 01:47:09 +00:00
2011-12-08 04:10:35 +00:00
QList < Machine * > machines = PROFILE . GetMachines ( MT_OXIMETER ) ;
2011-12-01 03:05:23 +00:00
2011-12-23 10:52:31 +00:00
qint64 f = 0 , l = 0 ;
2011-12-21 14:24:09 +00:00
int discard_threshold = PROFILE . oxi - > oxiDiscardThreshold ( ) ;
2011-12-01 03:05:23 +00:00
Machine * m ;
for ( int z = 0 ; z < machines . size ( ) ; z + + ) {
2011-12-08 04:10:35 +00:00
m = machines . at ( z ) ;
2011-12-01 03:05:23 +00:00
//m->sessionlist.erase(m->sessionlist.find(0));
2011-12-28 06:27:26 +00:00
// For each Session
2011-12-01 03:05:23 +00:00
for ( QHash < SessionID , Session * > : : iterator s = m - > sessionlist . begin ( ) ; s ! = m - > sessionlist . end ( ) ; s + + ) {
Session * sess = s . value ( ) ;
if ( ! sess ) continue ;
sess - > OpenEvents ( ) ;
2011-12-28 06:27:26 +00:00
// For each EventList contained in session
2011-12-01 03:05:23 +00:00
invalid . clear ( ) ;
2011-12-28 06:27:26 +00:00
f = 0 ;
l = 0 ;
2011-12-01 03:05:23 +00:00
for ( QHash < ChannelID , QVector < EventList * > > : : iterator e = sess - > eventlist . begin ( ) ; e ! = sess - > eventlist . end ( ) ; e + + ) {
2011-12-28 06:27:26 +00:00
// Discard any non data events.
2011-12-01 03:05:23 +00:00
if ( ! valid . contains ( e . key ( ) ) ) {
2011-12-28 06:27:26 +00:00
// delete and push aside for later to clean up
2011-12-01 03:05:23 +00:00
for ( int i = 0 ; i < e . value ( ) . size ( ) ; i + + ) {
delete e . value ( ) [ i ] ;
2011-12-01 01:47:09 +00:00
}
2011-12-01 03:05:23 +00:00
e . value ( ) . clear ( ) ;
invalid . push_back ( e . key ( ) ) ;
} else {
2011-12-28 06:27:26 +00:00
// Valid event
2011-12-01 03:05:23 +00:00
QVector < EventList * > newlist ;
for ( int i = 0 ; i < e . value ( ) . size ( ) ; i + + ) {
2011-12-03 05:27:57 +00:00
if ( e . value ( ) [ i ] - > count ( ) > ( unsigned ) discard_threshold ) {
2011-12-01 03:05:23 +00:00
newlist . push_back ( e . value ( ) [ i ] ) ;
} else {
delete e . value ( ) [ i ] ;
}
}
for ( int i = 0 ; i < newlist . size ( ) ; i + + ) {
2011-12-23 10:52:31 +00:00
packEventList ( newlist [ i ] , 8 ) ;
EventList * el = newlist [ i ] ;
if ( ! f | | f > el - > first ( ) ) f = el - > first ( ) ;
if ( ! l | | l < el - > last ( ) ) l = el - > last ( ) ;
2011-12-01 03:05:23 +00:00
}
2011-12-23 10:52:31 +00:00
e . value ( ) = newlist ;
2011-12-01 01:47:09 +00:00
}
}
2011-12-01 03:05:23 +00:00
for ( int i = 0 ; i < invalid . size ( ) ; i + + ) {
sess - > eventlist . erase ( sess - > eventlist . find ( invalid [ i ] ) ) ;
}
2011-12-23 10:52:31 +00:00
if ( f ) sess - > really_set_first ( f ) ;
if ( l ) sess - > really_set_last ( l ) ;
2011-12-01 03:05:23 +00:00
sess - > m_cnt . clear ( ) ;
sess - > m_sum . clear ( ) ;
sess - > m_min . clear ( ) ;
sess - > m_max . clear ( ) ;
sess - > m_cph . clear ( ) ;
sess - > m_sph . clear ( ) ;
sess - > m_avg . clear ( ) ;
sess - > m_wavg . clear ( ) ;
sess - > m_90p . clear ( ) ;
sess - > m_firstchan . clear ( ) ;
sess - > m_lastchan . clear ( ) ;
sess - > SetChanged ( true ) ;
2011-12-01 01:47:09 +00:00
}
2011-12-01 03:05:23 +00:00
2011-12-01 01:47:09 +00:00
}
2011-12-01 03:05:23 +00:00
for ( int i = 0 ; i < machines . size ( ) ; i + + ) {
Machine * m = machines [ i ] ;
2011-12-01 01:47:09 +00:00
m - > Save ( ) ;
}
getDaily ( ) - > ReloadGraphs ( ) ;
getOverview ( ) - > ReloadGraphs ( ) ;
}
2011-12-03 05:27:57 +00:00
2011-12-13 08:05:33 +00:00
void MainWindow : : RestartApplication ( bool force_login )
2011-12-03 05:27:57 +00:00
{
QString apppath ;
# ifdef Q_OS_MAC
// In Mac OS the full path of aplication binary is:
// <base-path>/myApp.app/Contents/MacOS/myApp
// prune the extra bits to just get the app bundle path
apppath = QApplication : : instance ( ) - > applicationDirPath ( ) . section ( " / " , 0 , - 3 ) ;
QStringList args ;
2011-12-18 04:30:08 +00:00
args < < " -n " ; // -n option is important, as it opens a new process
2011-12-18 05:15:30 +00:00
args < < apppath ;
2011-12-18 06:22:02 +00:00
args < < " --args " ; // SleepyHead binary options after this
args < < " -p " ; // -p starts with 1 second delay, to give this process time to save..
2011-12-18 05:17:48 +00:00
if ( force_login ) args < < " -l " ;
2011-12-03 05:27:57 +00:00
if ( QProcess : : startDetached ( " /usr/bin/open " , args ) ) {
QApplication : : instance ( ) - > exit ( ) ;
2011-12-18 16:39:36 +00:00
} else QMessageBox : : warning ( this , tr ( " Gah! " ) , tr ( " If you can read this, the restart command didn't work. Your going to have to do it yourself manually. " ) , QMessageBox : : Ok ) ;
2011-12-03 05:27:57 +00:00
# else
apppath = QApplication : : instance ( ) - > applicationFilePath ( ) ;
// If this doesn't work on windoze, try uncommenting this method
// Technically should be the same thing..
//if (QDesktopServices::openUrl(apppath)) {
// QApplication::instance()->exit();
//} else
2011-12-11 12:13:38 +00:00
QStringList args ;
args < < " -p " ;
2011-12-13 08:05:33 +00:00
if ( force_login ) args < < " -l " ;
2011-12-11 12:13:38 +00:00
if ( QProcess : : startDetached ( apppath , args ) ) {
2011-12-03 05:27:57 +00:00
QApplication : : instance ( ) - > exit ( ) ;
2011-12-18 16:39:36 +00:00
} else QMessageBox : : warning ( this , tr ( " Gah! " ) , tr ( " If you can read this, the restart command didn't work. Your going to have to do it yourself manually. " ) , QMessageBox : : Ok ) ;
2011-12-03 05:27:57 +00:00
# endif
2011-12-13 08:05:33 +00:00
}
2011-12-03 05:27:57 +00:00
2011-12-13 08:05:33 +00:00
void MainWindow : : on_actionChange_User_triggered ( )
{
PROFILE . Save ( ) ;
PREF . Save ( ) ;
RestartApplication ( true ) ;
2011-12-03 05:27:57 +00:00
}
2011-12-08 04:10:35 +00:00
void MainWindow : : on_actionPurge_Current_Day_triggered ( )
{
QDate date = getDaily ( ) - > getDate ( ) ;
Day * day = PROFILE . GetDay ( date , MT_CPAP ) ;
Machine * m ;
if ( day ) {
m = day - > machine ;
2011-12-22 10:29:12 +00:00
QString path = PROFILE . Get ( " { " + STR_GEN_DataFolder + " }/ " ) + m - > GetClass ( ) + " _ " + m - > hexid ( ) + " / " ;
2011-12-08 04:10:35 +00:00
2011-12-08 13:41:43 +00:00
QVector < Session * > : : iterator s ;
2011-12-08 04:10:35 +00:00
for ( s = day - > begin ( ) ; s ! = day - > end ( ) ; s + + ) {
SessionID id = ( * s ) - > session ( ) ;
QString filename0 = path + QString ( ) . sprintf ( " %08lx.000 " , id ) ;
QString filename1 = path + QString ( ) . sprintf ( " %08lx.001 " , id ) ;
qDebug ( ) < < " Removing " < < filename0 ;
qDebug ( ) < < " Removing " < < filename1 ;
QFile : : remove ( filename0 ) ;
QFile : : remove ( filename1 ) ;
m - > sessionlist . erase ( m - > sessionlist . find ( id ) ) ; // remove from machines session list
}
QList < Day * > & dl = PROFILE . daylist [ date ] ;
QList < Day * > : : iterator it ; //=dl.begin();
for ( it = dl . begin ( ) ; it ! = dl . end ( ) ; it + + ) {
if ( ( * it ) = = day ) break ;
}
if ( it ! = dl . end ( ) ) {
PROFILE . daylist [ date ] . erase ( it ) ;
delete day ;
}
}
getDaily ( ) - > ReloadGraphs ( ) ;
}
2011-12-13 08:05:33 +00:00
void MainWindow : : on_actionAll_Data_for_current_CPAP_machine_triggered ( )
{
QDate date = getDaily ( ) - > getDate ( ) ;
Day * day = PROFILE . GetDay ( date , MT_CPAP ) ;
Machine * m ;
if ( day ) {
m = day - > machine ;
if ( ! m ) {
qDebug ( ) < < " Gah!! no machine to purge " ;
return ;
}
2011-12-21 14:24:09 +00:00
if ( QMessageBox : : question ( this , tr ( " Are you sure? " ) , tr ( " Are you sure you want to purge all CPAP data for the following machine: \n " ) + m - > properties [ STR_PROP_Brand ] + " " + m - > properties [ STR_PROP_Model ] + " " + m - > properties [ STR_PROP_ModelNumber ] + " ( " + m - > properties [ STR_PROP_Serial ] + " ) " , QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : Yes ) {
2011-12-13 08:05:33 +00:00
m - > Purge ( 3478216 ) ;
RestartApplication ( ) ;
}
}
}
2011-12-23 14:12:04 +00:00
2011-12-25 05:05:12 +00:00
void MainWindow : : keyPressEvent ( QKeyEvent * event )
{
qDebug ( ) < < " Keypress: " < < event - > key ( ) ;
}
2011-12-25 11:27:10 +00:00
void MainWindow : : on_summaryButton_2_clicked ( )
{
2011-12-25 16:19:08 +00:00
ui - > tabWidget - > setCurrentWidget ( ui - > summaryTab ) ;
2011-12-25 11:27:10 +00:00
on_summaryButton_clicked ( ) ;
}
void MainWindow : : on_action_Sidebar_Toggle_toggled ( bool visible )
{
ui - > toolBox - > setVisible ( visible ) ;
}
2011-12-25 13:27:47 +00:00
void MainWindow : : on_recordsBox_linkClicked ( const QUrl & linkurl )
{
QString link = linkurl . toString ( ) . section ( " = " , 0 , 0 ) . toLower ( ) ;
QString datestr = linkurl . toString ( ) . section ( " = " , 1 ) . toLower ( ) ;
qDebug ( ) < < linkurl . toString ( ) < < link < < datestr ;
if ( link = = " daily " ) {
QDate date = QDate : : fromString ( datestr , Qt : : ISODate ) ;
daily - > LoadDate ( date ) ;
ui - > tabWidget - > setCurrentWidget ( daily ) ;
} else if ( link = = " overview " ) {
QString date1 = datestr . section ( " , " , 0 , 0 ) ;
QString date2 = datestr . section ( " , " , 1 ) ;
QDate d1 = QDate : : fromString ( date1 , Qt : : ISODate ) ;
QDate d2 = QDate : : fromString ( date2 , Qt : : ISODate ) ;
overview - > setRange ( d1 , d2 ) ;
ui - > tabWidget - > setCurrentWidget ( overview ) ;
}
}
2011-12-25 16:19:08 +00:00
void MainWindow : : on_helpButton_clicked ( )
{
ui - > tabWidget - > setCurrentWidget ( ui - > helpTab ) ;
}
void MainWindow : : on_actionView_S_ummary_triggered ( )
{
ui - > tabWidget - > setCurrentWidget ( ui - > summaryTab ) ;
}
2011-12-26 03:06:39 +00:00
void MainWindow : : on_webView_linkClicked ( const QUrl & url )
{
QString s = url . toString ( ) ;
qDebug ( ) < < " Link Clicked " < < url ;
if ( s . toLower ( ) . startsWith ( " https: " ) ) {
QDesktopServices ( ) . openUrl ( url ) ;
} else {
ui - > webView - > setUrl ( url ) ;
}
}
2011-12-26 04:41:28 +00:00
void MainWindow : : on_favouritesList_itemSelectionChanged ( )
{
QListWidgetItem * item = ui - > favouritesList - > currentItem ( ) ;
if ( ! item ) return ;
QDate date = item - > data ( Qt : : UserRole ) . toDate ( ) ;
if ( date . isValid ( ) ) {
daily - > LoadDate ( date ) ;
ui - > tabWidget - > setCurrentWidget ( daily ) ;
}
}
2011-12-26 04:58:02 +00:00
2011-12-28 14:03:09 +00:00
/*void MainWindow::on_favouritesList_itemClicked(QListWidgetItem *item)
2011-12-26 04:58:02 +00:00
{
if ( ! item ) return ;
QDate date = item - > data ( Qt : : UserRole ) . toDate ( ) ;
if ( date . isValid ( ) ) {
if ( date = = daily - > getDate ( ) ) {
ui - > tabWidget - > setCurrentWidget ( daily ) ;
daily - > graphView ( ) - > ResetBounds ( ) ;
daily - > graphView ( ) - > redraw ( ) ;
}
}
2011-12-28 14:03:09 +00:00
} */
2011-12-26 05:51:53 +00:00
void MainWindow : : on_webView_statusBarMessage ( const QString & text )
{
ui - > statusbar - > showMessage ( text ) ;
}
void MainWindow : : LinkHovered ( const QString & link , const QString & title , const QString & textContent )
{
Q_UNUSED ( title ) ;
Q_UNUSED ( textContent ) ;
ui - > statusbar - > showMessage ( link ) ;
}
2011-12-26 19:25:17 +00:00
void MainWindow : : on_tabWidget_currentChanged ( int index )
{
Q_UNUSED ( index ) ;
QWidget * widget = ui - > tabWidget - > currentWidget ( ) ;
if ( ( widget = = ui - > summaryTab ) | | ( widget = = ui - > helpTab ) ) {
qstatus2 - > setVisible ( false ) ;
} else if ( widget = = daily ) {
qstatus2 - > setVisible ( true ) ;
daily - > graphView ( ) - > selectionTime ( ) ;
} else if ( widget = = overview ) {
qstatus2 - > setVisible ( true ) ;
overview - > graphView ( ) - > selectionTime ( ) ;
} else if ( widget = = oximetry ) {
qstatus2 - > setVisible ( true ) ;
oximetry - > graphView ( ) - > selectionTime ( ) ;
}
}
2011-12-27 13:21:10 +00:00
void MainWindow : : on_summaryView_linkClicked ( const QUrl & arg1 )
{
qDebug ( ) < < arg1 ;
on_recordsBox_linkClicked ( arg1 ) ;
}
void MainWindow : : on_summaryView_urlChanged ( const QUrl & arg1 )
{
// qDebug() << arg1;
// on_recordsBox_linkClicked(arg1);
}