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-09-06 07:33:34 +00:00
# include <QNetworkRequest>
# 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>
# include <QPainter>
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"
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-09-05 02:30:10 +00:00
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-11-08 15:03:39 +00:00
QString version = PREF [ " VersionString " ] . toString ( ) ;
if ( QString ( GIT_BRANCH ) ! = " master " ) version + = QString ( " " ) + QString ( GIT_BRANCH ) ;
this - > setWindowTitle ( tr ( " SleepyHead " ) + QString ( " v%1 (Profile: %2) " ) . arg ( version ) . arg ( PREF [ " Profile " ] . toString ( ) ) ) ;
2011-07-17 15:57:45 +00:00
ui - > tabWidget - > setCurrentIndex ( 0 ) ;
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-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-10-05 12:45:40 +00:00
if ( ! PROFILE . Exists ( " ShowDebug " ) ) PROFILE [ " ShowDebug " ] = false ;
2011-10-05 07:41:56 +00:00
ui - > actionDebug - > setChecked ( PROFILE [ " ShowDebug " ] . toBool ( ) ) ;
2011-07-17 15:57:45 +00:00
2011-10-05 07:41:56 +00:00
if ( ! PROFILE [ " ShowDebug " ] . toBool ( ) ) {
2011-07-17 16:07:37 +00:00
ui - > logText - > hide ( ) ;
}
2011-10-08 13:56:33 +00:00
// TODO: Move all this to profile creation.
2011-09-11 11:03:37 +00:00
// This speeds up the second part of importing craploads.. later it will speed up the first part too.
2011-10-05 07:41:56 +00:00
if ( ! PROFILE . Exists ( " EnableMultithreading " ) ) PROFILE [ " EnableMultithreading " ] = QThread : : idealThreadCount ( ) > 1 ;
2011-10-08 13:56:33 +00:00
2011-10-05 07:41:56 +00:00
if ( ! PROFILE . Exists ( " MemoryHog " ) ) PROFILE [ " MemoryHog " ] = false ;
2011-11-21 10:20:11 +00:00
if ( ! PROFILE . Exists ( " EnableGraphSnapshots " ) ) PROFILE [ " EnableGraphSnapshots " ] = true ;
if ( ! PROFILE . Exists ( " SquareWavePlots " ) ) PROFILE [ " SquareWavePlots " ] = false ;
2011-10-12 03:17:40 +00:00
if ( ! PROFILE . Exists ( " EnableOximetry " ) ) PROFILE [ " EnableOximetry " ] = false ;
2011-10-08 13:56:33 +00:00
if ( ! PROFILE . Exists ( " LinkGroups " ) ) PROFILE [ " LinkGroups " ] = false ;
2011-10-05 07:41:56 +00:00
if ( ! PROFILE . Exists ( " AlwaysShowOverlayBars " ) ) PROFILE [ " AlwaysShowOverlayBars " ] = 0 ;
if ( ! PROFILE . Exists ( " UseAntiAliasing " ) ) PROFILE [ " UseAntiAliasing " ] = false ;
if ( ! PROFILE . Exists ( " IntentionalLeak " ) ) PROFILE [ " IntentionalLeak " ] = ( double ) 0.0 ;
if ( ! PROFILE . Exists ( " IgnoreShorterSessions " ) ) PROFILE [ " IgnoreShorterSessions " ] = 0 ;
if ( ! PROFILE . Exists ( " CombineCloserSessions " ) ) PROFILE [ " CombineCloserSessions " ] = 0 ;
if ( ! PROFILE . Exists ( " DaySplitTime " ) ) PROFILE [ " DaySplitTime " ] = QTime ( 12 , 0 , 0 , 0 ) ;
2011-11-18 08:33:31 +00:00
if ( ! PROFILE . Exists ( " EventWindowSize " ) ) PROFILE [ " EventWindowSize " ] = 4 ;
2011-11-28 04:05:09 +00:00
if ( ! PROFILE . Exists ( " SPO2DropPercentage " ) ) PROFILE [ " PulseChangeDuration " ] = 4 ;
if ( ! PROFILE . Exists ( " SPO2DropDuration " ) ) PROFILE [ " PulseChangeDuration " ] = 5 ;
if ( ! PROFILE . Exists ( " PulseChangeBPM " ) ) PROFILE [ " PulseChangeDuration " ] = 5 ;
if ( ! PROFILE . Exists ( " PulseChangeDuration " ) ) PROFILE [ " PulseChangeDuration " ] = 8 ;
2011-11-30 12:58:41 +00:00
if ( ! PROFILE . Exists ( " GraphHeight " ) ) PROFILE [ " GraphHeight " ] = 180 ;
2011-07-28 07:32:02 +00:00
2011-10-05 07:41:56 +00:00
//ui->actionUse_AntiAliasing->setChecked(PROFILE["UseAntiAliasing"].toBool());
2011-10-07 05:28:35 +00:00
ui - > action_Link_Graph_Groups - > setChecked ( PROFILE [ " LinkGroups " ] . toBool ( ) ) ;
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 " ) ;
this - > restoreGeometry ( settings . value ( " MainWindow/geometry " ) . toByteArray ( ) ) ;
2011-09-10 14:17:45 +00:00
2011-07-24 07:58:20 +00:00
ui - > tabWidget - > setCurrentWidget ( ui - > welcome ) ;
2011-06-26 08:30:44 +00:00
2011-09-06 07:33:34 +00:00
netmanager = new QNetworkAccessManager ( this ) ;
connect ( netmanager , SIGNAL ( finished ( QNetworkReply * ) ) , this , SLOT ( replyFinished ( QNetworkReply * ) ) ) ;
2011-09-11 06:16:45 +00:00
connect ( ui - > webView , SIGNAL ( statusBarMessage ( QString ) ) , this , SLOT ( updatestatusBarMessage ( QString ) ) ) ;
2011-09-17 12:39:00 +00:00
2011-10-21 07:06:06 +00:00
if ( QSystemTrayIcon : : isSystemTrayAvailable ( ) & & QSystemTrayIcon : : supportsMessages ( ) ) {
systray = new QSystemTrayIcon ( QIcon ( " :/docs/sheep.png " ) , this ) ;
systray - > show ( ) ;
systraymenu = new QMenu ( this ) ;
systray - > setContextMenu ( systraymenu ) ;
QAction * a = systraymenu - > addAction ( " SleepyHead v " + PREF [ " VersionString " ] . toString ( ) ) ;
a - > setEnabled ( false ) ;
systraymenu - > addSeparator ( ) ;
systraymenu - > addAction ( " About " , this , SLOT ( on_action_About_triggered ( ) ) ) ;
systraymenu - > addAction ( " Check for Updates " , this , SLOT ( on_actionCheck_for_Updates_triggered ( ) ) ) ;
systraymenu - > addSeparator ( ) ;
systraymenu - > addAction ( " Exit " , this , SLOT ( close ( ) ) ) ;
} else {
systray = NULL ;
systraymenu = NULL ;
}
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 ( systray ) delete systray ;
if ( systraymenu ) delete systraymenu ;
2011-10-05 11:51:33 +00:00
//if (!isMaximized()) {
2011-10-05 03:05:35 +00:00
QSettings settings ( " Jedimark " , " SleepyHead " ) ;
settings . setValue ( " MainWindow/geometry " , saveGeometry ( ) ) ;
2011-10-05 11:51:33 +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-06-28 01:51:21 +00:00
DoneGraphs ( ) ;
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-10-21 07:06:06 +00:00
void MainWindow : : Notify ( QString s )
{
if ( systray ) {
systray - > showMessage ( " SleepyHead v " + PREF [ " VersionString " ] . toString ( ) , s , QSystemTrayIcon : : Information , 5000 ) ;
} else {
ui - > statusbar - > showMessage ( s , 5000 ) ;
}
}
2011-06-26 08:30:44 +00:00
2011-06-27 06:26:29 +00:00
void MainWindow : : Startup ( )
{
2011-10-05 07:41:56 +00:00
qDebug ( ) < < PREF [ " AppName " ] . toString ( ) . toAscii ( ) + " v " + PREF [ " VersionString " ] . toString ( ) . 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-10-05 07:41:56 +00:00
daily = new Daily ( ui - > tabWidget , NULL , this ) ;
2011-09-02 05:13:07 +00:00
ui - > tabWidget - > insertTab ( 1 , daily , tr ( " Daily " ) ) ;
2011-11-27 14:35:25 +00:00
overview = new Overview ( ui - > tabWidget , daily - > graphView ( ) ) ;
2011-10-05 03:11:18 +00:00
ui - > tabWidget - > insertTab ( 2 , overview , tr ( " Overview " ) ) ;
2011-10-12 03:17:40 +00:00
if ( PROFILE [ " EnableOximetry " ] . toBool ( ) ) {
2011-11-27 14:35:25 +00:00
oximetry = new Oximetry ( ui - > tabWidget , daily - > graphView ( ) ) ;
2011-10-12 03:17:40 +00:00
ui - > tabWidget - > insertTab ( 3 , oximetry , tr ( " Oximetry " ) ) ;
}
2011-12-01 15:40:32 +00:00
SnapshotGraph = new gGraphView ( this , daily - > graphView ( ) ) ;
SnapshotGraph - > setMaximumSize ( 1024 , 512 ) ;
SnapshotGraph - > setMinimumSize ( 1024 , 512 ) ;
//ReportGraph->setMaximumSize(graph_print_width,graph_print_height);
//ReportGraph->setMinimumSize(graph_print_width,graph_print_height);
SnapshotGraph - > hide ( ) ;
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-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 ( ) ;
}
bool addnew = false ;
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 ;
}
if ( asknew ) {
2011-11-25 06:56:39 +00:00
QFileDialog w ;
w . setFileMode ( QFileDialog : : DirectoryOnly ) ;
2011-11-28 22:49:43 +00:00
w . setOption ( QFileDialog : : DontUseNativeDialog , true ) ;
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 ) ;
}
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 ) ;
if ( ! importLocations . contains ( newdir ) ) {
importLocations . append ( newdir ) ;
addnew = true ;
}
2011-06-30 04:55:20 +00:00
}
2011-11-25 06:56:39 +00:00
/*newdir=QFileDialog::getExistingDirectory(this,"Select a folder to import","",QFileDialog::ShowDirsOnly);
if ( newdir . isEmpty ( ) ) {
// inform the user or just abort?
return ;
} */
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 ;
for ( int i = 0 ; i < importLocations . size ( ) ; i + + ) {
QString dir = importLocations [ i ] ;
if ( ! dir . isEmpty ( ) ) {
qprogress - > setValue ( 0 ) ;
qprogress - > show ( ) ;
qstatus - > setText ( tr ( " Importing Data " ) ) ;
int c = PROFILE . Import ( dir ) ;
if ( ! c ) {
2011-12-01 01:47:09 +00:00
mainwin - > Notify ( " Import Problem \n \n Couldn't Find any Machine Data at this location: \n " + dir ) ;
2011-11-20 23:39:55 +00:00
if ( newdir = = dir ) addnew = false ; // Don't bother asking to add it.
}
qDebug ( ) < < " Finished Importing data " < < c ;
if ( c ) {
successful = true ;
}
qstatus - > setText ( " " ) ;
qprogress - > hide ( ) ;
}
}
if ( successful ) {
PROFILE . Save ( ) ;
if ( daily ) daily - > ReloadGraphs ( ) ;
if ( overview ) overview - > ReloadGraphs ( ) ;
if ( addnew & & ( 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 ) ) {
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-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_actionView_Welcome_triggered ( )
{
2011-06-27 15:00:00 +00:00
ui - > tabWidget - > setCurrentWidget ( ui - > welcome ) ;
2011-06-26 08:30:44 +00:00
}
void MainWindow : : on_action_Fullscreen_triggered ( )
{
if ( ui - > action_Fullscreen - > isChecked ( ) )
this - > showFullScreen ( ) ;
else
this - > showNormal ( ) ;
}
void MainWindow : : on_homeButton_clicked ( )
{
2011-06-26 11:49:40 +00:00
QString file = " qrc:/docs/index.html " ;
2011-06-26 08:30:44 +00:00
QUrl url ( file ) ;
ui - > webView - > setUrl ( url ) ;
}
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-09-13 04:36:49 +00:00
qstatus2 - > setText ( " 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-09-13 04:36:49 +00:00
qstatus2 - > setText ( " 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-06-26 08:30:44 +00:00
}
void MainWindow : : on_webView_loadStarted ( )
{
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 ;
QString msg = tr ( " <html><body><div align='center'><h2>SleepyHead v%1.%2.%3</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-11-15 02:14:44 +00:00
" </div></body></html> " ) . arg ( major_version ) . arg ( minor_version ) . arg ( revision_number ) . arg ( __DATE__ ) . arg ( __TIME__ ) . arg ( gitrev ) ;
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-10-05 07:41:56 +00:00
PROFILE [ " ShowDebug " ] = 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-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-10-12 03:17:40 +00:00
if ( ! PROFILE . Exists ( " EnableOximetry " ) | | ! PROFILE [ " EnableOximetry " ] . toBool ( ) ) {
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-10-12 03:17:40 +00:00
PROFILE [ " EnableOximetry " ] = 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-10-05 06:45:33 +00:00
ui - > tabWidget - > insertTab ( 3 , oximetry , tr ( " Oximetry " ) ) ;
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 ( ) ;
qstatus2 - > setText ( " 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-10-21 07:06:06 +00:00
mainwin - > Notify ( " Checking for Updates " ) ;
2011-10-21 05:50:31 +00:00
on_actionCheck_for_Updates_triggered ( ) ;
}
2011-09-06 07:33:34 +00:00
void MainWindow : : on_actionCheck_for_Updates_triggered ( )
{
2011-10-21 05:50:31 +00:00
if ( PREF . Exists ( " Updates_LastChecked " ) ) {
2011-11-28 12:03:43 +00:00
if ( PREF [ " Updates_LastChecked " ] . toDateTime ( ) . secsTo ( QDateTime : : currentDateTime ( ) ) < 7200 ) {
2011-10-21 05:50:31 +00:00
// Instead of doing this, just use the cached crud
if ( prefdialog ) prefdialog - > RefreshLastChecked ( ) ;
2011-11-28 12:03:43 +00:00
mainwin - > Notify ( " No New Updates - You already checked recently... " ) ;
2011-10-21 05:50:31 +00:00
return ;
}
}
2011-09-06 07:33:34 +00:00
netmanager - > get ( QNetworkRequest ( QUrl ( " http://sleepyhead.sourceforge.net/current_version.txt " ) ) ) ;
}
void MainWindow : : replyFinished ( QNetworkReply * reply )
{
if ( reply - > error ( ) = = QNetworkReply : : NoError ) {
// Wrap this crap in XML/JSON so can do other stuff.
if ( reply - > size ( ) > 20 ) {
qDebug ( ) < < " Doesn't look like a version file... :( " ;
} else {
// check in size
QByteArray data = reply - > readAll ( ) ;
QString a = data ;
a = a . trimmed ( ) ;
2011-10-21 05:50:31 +00:00
PREF [ " Updates_LastChecked " ] = QDateTime : : currentDateTime ( ) ;
if ( prefdialog ) prefdialog - > RefreshLastChecked ( ) ;
2011-10-05 07:41:56 +00:00
if ( a > PREF [ " VersionString " ] . toString ( ) ) {
2011-09-06 07:33:34 +00:00
if ( QMessageBox : : question ( this , " New Version " , " A newer version of SleepyHead is available, v " + a + " . \n Would you like to update? " , QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : Yes ) {
QMessageBox : : information ( this , " Laziness Warning " , " I'd love to do it for you automatically, but it's not implemented yet.. :) " , QMessageBox : : Ok ) ;
}
} else {
2011-10-21 07:06:06 +00:00
mainwin - > Notify ( " Checked for Updates: SleepyHead is already up to date! " ) ;
2011-09-06 07:33:34 +00:00
}
}
} else {
qDebug ( ) < < " Network Error: " < < reply - > errorString ( ) ;
}
reply - > deleteLater ( ) ;
}
2011-09-07 08:08:27 +00:00
void MainWindow : : on_action_Screenshot_triggered ( )
{
QTimer : : singleShot ( 250 , this , SLOT ( DelayedScreenshot ( ) ) ) ;
}
void MainWindow : : DelayedScreenshot ( )
{
QPixmap pixmap = QPixmap : : grabWindow ( this - > winId ( ) ) ;
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-01 15:40:32 +00:00
PrintReport ( overview - > graphView ( ) , " Overview " ) ;
} else if ( ui - > tabWidget - > currentWidget ( ) = = daily ) {
2011-12-01 17:23:19 +00:00
PrintReport ( daily - > graphView ( ) , " Daily " , daily - > getDate ( ) ) ;
2011-12-01 15:40:32 +00:00
} else if ( ui - > tabWidget - > currentWidget ( ) = = oximetry ) {
if ( oximetry )
PrintReport ( oximetry - > graphView ( ) , " Oximetry " ) ;
2011-09-11 06:16:45 +00:00
} else {
2011-12-01 15:40:32 +00:00
//QPrinter printer();
//ui->webView->print(printer)
2011-09-11 07:03:04 +00:00
QMessageBox : : information ( this , " Not supported Yet " , " 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-10-05 07:41:56 +00:00
newprof . edit ( PREF [ " 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 )
{
PROFILE [ " LinkGroups " ] = 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 " ) ) ;
ui - > tabWidget - > setCurrentIndex ( 0 ) ;
}
void MainWindow : : on_action_Frequently_Asked_Questions_triggered ( )
{
ui - > webView - > load ( QUrl ( " http://sourceforge.net/apps/mediawiki/sleepyhead/index.php?title=Frequently_Asked_Questions " ) ) ;
ui - > tabWidget - > setCurrentIndex ( 0 ) ;
}
2011-11-27 14:35:25 +00:00
2011-12-01 03:05:23 +00:00
EventList * packEventList ( EventList * ev )
{
EventList * nev = new EventList ( EVL_Event ) ;
EventDataType val , lastval = 0 ;
qint64 time , lasttime = 0 , lasttime2 = 0 ;
lastval = ev - > data ( 0 ) ;
lasttime = ev - > time ( 0 ) ;
nev - > AddEvent ( lasttime , lastval ) ;
2011-12-01 06:06:13 +00:00
for ( unsigned i = 1 ; i < ev - > count ( ) ; i + + ) {
2011-12-01 03:05:23 +00:00
val = ev - > data ( i ) ;
time = ev - > time ( i ) ;
if ( val ! = lastval ) {
nev - > AddEvent ( time , val ) ;
lasttime2 = time ;
}
lastval = val ;
lasttime = time ;
}
if ( val = = lastval ) {
nev - > AddEvent ( lasttime , val ) ;
}
return nev ;
}
2011-12-01 01:47:09 +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-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-01 15:57:06 +00:00
Notify ( " There are no graphs visible to print " ) ;
return ;
}
2011-12-01 17:23:19 +00:00
QString username = PROFILE . Get ( " _{Username}_ " ) ;
QString filename = QFileDialog : : getSaveFileName ( this , " Select filename to save PDF report to " , PREF . Get ( " {home}/ " + name + username + date . toString ( Qt : : ISODate ) + " .pdf " ) , " PDF Files (*.pdf) " ) ;
2011-12-01 15:57:06 +00:00
if ( filename . isEmpty ( ) )
return ;
Notify ( " Saving " + name + " report as \" " + filename + " \" . " ) ;
//QString filename=PREF.Get("{home}/"+name+"_{user}.pdf");
2011-12-01 15:40:32 +00:00
QPrinter printer ( QPrinter : : ScreenResolution ) ; //QPrinter::HighResolution); //QPrinter::ScreenResolution);
printer . setOutputFileName ( filename ) ;
printer . setOrientation ( QPrinter : : Portrait ) ;
QPainter painter ;
painter . begin ( & printer ) ;
2011-12-01 17:23:19 +00:00
2011-12-01 15:40:32 +00:00
QRect res = printer . pageRect ( ) ;
qDebug ( ) < < " Printer Resolution is " < < res . width ( ) < < " x " < < res . height ( ) ;
const int graphs_per_page = 5 ;
float gw = res . width ( ) ;
2011-12-01 17:23:19 +00:00
float gh = ( res . height ( ) - 40 ) / graphs_per_page ;
2011-12-01 15:40:32 +00:00
mainwin - > snapshotGraph ( ) - > setMinimumSize ( gw , gh ) ;
mainwin - > snapshotGraph ( ) - > setMaximumSize ( gw , gh ) ;
2011-12-01 17:23:19 +00:00
int page = 1 ;
int pages = ceil ( float ( visgraphs + 1 ) / float ( graphs_per_page ) ) ;
2011-12-01 15:40:32 +00:00
int i = 0 ;
int top = 0 ;
int gcnt = 0 ;
if ( qprogress ) {
qprogress - > setValue ( 0 ) ;
qprogress - > setMaximum ( gv - > size ( ) ) ;
qprogress - > show ( ) ;
}
2011-12-01 17:23:19 +00:00
int header_height = 140 ;
if ( ! PROFILE [ " FirstName " ] . toString ( ) . isEmpty ( ) ) {
QString userinfo = " Name: \t " + PROFILE [ " LastName " ] . toString ( ) + " , " + PROFILE [ " FirstName " ] . toString ( ) + " \n " ;
userinfo + = " DOB: \t " + PROFILE [ " DOB " ] . toString ( ) + " \n " ;
userinfo + = " Phone: \t " + PROFILE [ " Phone " ] . toString ( ) + " \n " ;
userinfo + = " Email: \t " + PROFILE [ " EmailAddress " ] . toString ( ) + " \n " ;
if ( ! PROFILE [ " Address " ] . toString ( ) . isEmpty ( ) ) userinfo + = " \n Address: \n " + PROFILE [ " Address " ] . toString ( ) + " \n " ;
QRectF bounds = painter . boundingRect ( QRectF ( 0 , 0 , res . width ( ) , 200 ) , userinfo , QTextOption ( Qt : : AlignLeft ) ) ;
painter . drawText ( bounds , userinfo , QTextOption ( Qt : : AlignLeft ) ) ;
top = header_height ;
}
if ( name = = " Daily " ) {
QString cpapinfo = " Date: " + date . toString ( Qt : : SystemLocaleLongDate ) + " \n " ;
Day * cpap = PROFILE . GetDay ( date , MT_CPAP ) ;
if ( cpap ) {
int f = cpap - > first ( ) / 1000L ;
int l = cpap - > last ( ) / 1000L ;
int tt = qint64 ( cpap - > total_time ( ) ) / 1000L ;
int h = tt / 3600 ;
int m = ( tt / 60 ) % 60 ;
int s = tt % 60 ;
cpapinfo + = " Mask Time: " + QString ( ) . sprintf ( " %2i hours %2i minutes " , h , m ) + " \n " ;
cpapinfo + = " Bedtime: " + QDateTime : : fromTime_t ( f ) . time ( ) . toString ( " HH:mm:ss " ) + " \n " ;
cpapinfo + = " Wake-up: " + QDateTime : : fromTime_t ( l ) . time ( ) . toString ( " HH:mm:ss " ) + " \n \n " ;
float ahi = ( cpap - > count ( CPAP_Obstructive ) + cpap - > count ( CPAP_Hypopnea ) + cpap - > count ( CPAP_ClearAirway ) + cpap - > count ( CPAP_Apnea ) ) / cpap - > hours ( ) ;
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 ( ) ;
QString stats ;
stats = " AHI \t " + QString : : number ( ahi , ' f ' , 2 ) + " \n " ;
stats + = " AI \t " + QString : : number ( oai , ' f ' , 2 ) + " \n " ;
stats + = " HI \t " + QString : : number ( hi , ' f ' , 2 ) + " \n " ;
stats + = " CAI \t " + QString : : number ( cai , ' f ' , 2 ) + " \n " ;
if ( cpap - > machine - > GetClass ( ) = = " PRS1 " ) {
stats + = " REI \t " + QString : : number ( rei , ' f ' , 2 ) + " \n " ;
stats + = " VSI \t " + QString : : number ( vsi , ' f ' , 2 ) + " \n " ;
stats + = " FLI \t " + QString : : number ( fli , ' f ' , 2 ) + " \n " ;
stats + = " PB/CSR \t " + QString : : number ( csr , ' f ' , 2 ) + " % \n " ;
} else if ( cpap - > machine - > GetClass ( ) = = " ResMed " ) {
stats + = " UAI \t " + QString : : number ( uai , ' f ' , 2 ) + " \n " ;
} else if ( cpap - > machine - > GetClass ( ) = = " Intellipap " ) {
stats + = " NRI \t " + QString : : number ( nri , ' f ' , 2 ) + " \n " ;
stats + = " LKI \t " + QString : : number ( lki , ' f ' , 2 ) + " \n " ;
stats + = " EPI \t " + QString : : number ( exp , ' f ' , 2 ) + " \n " ;
}
QRectF bounds = painter . boundingRect ( QRectF ( res . width ( ) - 250 , 0 , 250 , 200 ) , stats , QTextOption ( Qt : : AlignRight ) ) ;
painter . drawText ( bounds , stats , QTextOption ( Qt : : AlignRight ) ) ;
}
QRectF bounds = painter . boundingRect ( QRectF ( 250 , 0 , res . width ( ) - 250 , 200 ) , cpapinfo , QTextOption ( Qt : : AlignLeft ) ) ;
painter . drawText ( bounds , cpapinfo , QTextOption ( Qt : : AlignLeft ) ) ;
}
const int footer_height = 40 ;
bool first = true ;
2011-12-01 15:40:32 +00:00
do {
2011-12-01 17:23:19 +00:00
//+" on "+d.toString(Qt::SystemLocaleLongDate)
if ( first ) {
QString footer = " SleepyHead v " + PREF [ " VersionString " ] . toString ( ) ;
QRectF bounds = painter . boundingRect ( QRectF ( 0 , res . height ( ) - footer_height , res . width ( ) , footer_height ) , footer , QTextOption ( Qt : : AlignHCenter ) ) ;
painter . drawText ( bounds , footer , QTextOption ( Qt : : AlignHCenter ) ) ;
QRectF pagebnds ( res . width ( ) - 80 , res . height ( ) - footer_height , 80 , footer_height ) ;
painter . drawText ( pagebnds , " Page " + QString : : number ( page ) + " of " + QString : : number ( pages ) , QTextOption ( Qt : : AlignRight ) ) ;
first = false ;
}
2011-12-01 15:40:32 +00:00
gGraph * g = ( * gv ) [ i ] ;
if ( g - > isEmpty ( ) ) continue ;
if ( ! g - > visible ( ) ) continue ;
g - > deselect ( ) ;
QPixmap pm = g - > renderPixmap ( gw , gh ) ;
//QPixmap pm2=pm.scaledToWidth(res.width());
painter . drawPixmap ( 0 , top , pm . width ( ) , pm . height ( ) , pm ) ;
top + = pm . height ( ) ;
gcnt + + ;
2011-12-01 17:23:19 +00:00
if ( ( gcnt > = graphs_per_page ) | | ( top > ( res . height ( ) - footer_height - header_height ) ) ) { //top+pm.height()>res.height()) {
2011-12-01 15:40:32 +00:00
top = 0 ;
gcnt = 0 ;
2011-12-01 17:23:19 +00:00
header_height = 0 ;
page + + ;
if ( page > pages ) break ;
first = true ;
2011-12-01 15:40:32 +00:00
if ( ! printer . newPage ( ) ) {
qWarning ( " failed in flushing page to disk, disk full? " ) ;
break ;
}
}
if ( qprogress ) {
qprogress - > setValue ( i ) ;
QApplication : : processEvents ( ) ;
}
} while ( + + i < gv - > size ( ) ) ;
qprogress - > hide ( ) ;
painter . end ( ) ;
}
2011-12-01 01:47:09 +00:00
void MainWindow : : on_action_Rebuild_Oximetry_Index_triggered ( )
{
Day * day ;
QVector < QString > valid ;
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
QVector < QString > invalid ;
2011-12-01 03:05:23 +00:00
QVector < Machine * > machines = PROFILE . GetMachines ( MT_OXIMETER ) ;
Machine * m ;
for ( int z = 0 ; z < machines . size ( ) ; z + + ) {
m = machines [ z ] ;
//m->sessionlist.erase(m->sessionlist.find(0));
for ( QHash < SessionID , Session * > : : iterator s = m - > sessionlist . begin ( ) ; s ! = m - > sessionlist . end ( ) ; s + + ) {
Session * sess = s . value ( ) ;
if ( ! sess ) continue ;
sess - > OpenEvents ( ) ;
invalid . clear ( ) ;
for ( QHash < ChannelID , QVector < EventList * > > : : iterator e = sess - > eventlist . begin ( ) ; e ! = sess - > eventlist . end ( ) ; e + + ) {
if ( ! valid . contains ( e . key ( ) ) ) {
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 {
int i = 0 ;
QVector < EventList * > newlist ;
for ( int i = 0 ; i < e . value ( ) . size ( ) ; i + + ) {
if ( e . value ( ) [ i ] - > count ( ) > 1 ) {
newlist . push_back ( e . value ( ) [ i ] ) ;
} else {
delete e . value ( ) [ i ] ;
}
}
for ( int i = 0 ; i < newlist . size ( ) ; i + + ) {
EventList * nev = packEventList ( newlist [ i ] ) ;
if ( nev - > count ( ) ! = e . value ( ) [ i ] - > count ( ) ) {
delete newlist [ i ] ;
newlist [ i ] = nev ;
} else {
delete nev ;
}
}
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 ] ) ) ;
}
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 ( ) ;
}