OSCAR-code/overview.cpp

340 lines
12 KiB
C++
Raw Normal View History

2011-06-28 15:25:20 +00:00
/*
2011-06-26 08:30:44 +00:00
Overview GUI Implementation
Copyright (c)2011 Mark Watkins <jedimark@users.sourceforge.net>
License: GPL
2011-06-28 15:25:20 +00:00
*/
2011-06-26 08:30:44 +00:00
#include <QCalendarWidget>
#include <QTextCharFormat>
2011-07-19 14:04:54 +00:00
#include <QSystemLocale>
#include <QDebug>
2011-09-12 03:07:57 +00:00
#include <QDateTimeEdit>
#include <QCalendarWidget>
2011-09-12 16:10:18 +00:00
#include <QFileDialog>
//#include <QProgressBar>
#include "SleepLib/profiles.h"
2011-06-26 08:30:44 +00:00
#include "overview.h"
#include "ui_overview.h"
#include "common_gui.h"
2011-06-26 08:30:44 +00:00
#include "Graphs/gXAxis.h"
#include "Graphs/gLineChart.h"
#include "Graphs/gYAxis.h"
#include "Graphs/gSessionTime.h"
2011-06-26 08:30:44 +00:00
2011-12-02 14:36:40 +00:00
#include "mainwindow.h"
extern MainWindow * mainwin;
//extern QProgressBar * qprogress;
Overview::Overview(QWidget *parent,gGraphView * shared) :
2011-06-26 08:30:44 +00:00
QWidget(parent),
ui(new Ui::Overview),
m_shared(shared)
2011-06-26 08:30:44 +00:00
{
ui->setupUi(this);
2011-10-31 11:55:25 +00:00
// Set Date controls locale to 4 digit years
QLocale locale=QLocale::system();
QString shortformat=locale.dateFormat(QLocale::ShortFormat);
if (!shortformat.toLower().contains("yyyy")) {
shortformat.replace("yy","yyyy");
}
ui->dateStart->setDisplayFormat(shortformat);
ui->dateEnd->setDisplayFormat(shortformat);
Qt::DayOfWeek dow=firstDayOfWeekFromLocale();
ui->dateStart->calendarWidget()->setFirstDayOfWeek(dow);
ui->dateEnd->calendarWidget()->setFirstDayOfWeek(dow);
2011-10-31 11:55:25 +00:00
// Stop both calendar drop downs highlighting weekends in red
QTextCharFormat format = ui->dateStart->calendarWidget()->weekdayTextFormat(Qt::Saturday);
format.setForeground(QBrush(Qt::black, Qt::SolidPattern));
ui->dateStart->calendarWidget()->setWeekdayTextFormat(Qt::Saturday, format);
ui->dateStart->calendarWidget()->setWeekdayTextFormat(Qt::Sunday, format);
ui->dateEnd->calendarWidget()->setWeekdayTextFormat(Qt::Saturday, format);
ui->dateEnd->calendarWidget()->setWeekdayTextFormat(Qt::Sunday, format);
// Connect the signals to update which days have CPAP data when the month is changed
connect(ui->dateStart->calendarWidget(),SIGNAL(currentPageChanged(int,int)),SLOT(dateStart_currentPageChanged(int,int)));
connect(ui->dateEnd->calendarWidget(),SIGNAL(currentPageChanged(int,int)),SLOT(dateEnd_currentPageChanged(int,int)));
// Create the horizontal layout to hold the GraphView object and it's scrollbar
layout=new QHBoxLayout(ui->graphArea);
2011-10-31 11:55:25 +00:00
layout->setSpacing(0); // remove the ugly margins/spacing
layout->setMargin(0);
layout->setContentsMargins(0,0,0,0);
ui->graphArea->setLayout(layout);
ui->graphArea->setAutoFillBackground(false);
2011-10-31 11:55:25 +00:00
// Create the GraphView Object
GraphView=new gGraphView(ui->graphArea,m_shared);
GraphView->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
2011-10-31 11:55:25 +00:00
// Create the custom scrollbar and attach to GraphView
scrollbar=new MyScrollBar(ui->graphArea);
scrollbar->setOrientation(Qt::Vertical);
scrollbar->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Expanding);
scrollbar->setMaximumWidth(20);
GraphView->setScrollBar(scrollbar);
2011-10-31 11:55:25 +00:00
// Add the graphView and scrollbar to the layout.
layout->addWidget(GraphView,1);
layout->addWidget(scrollbar,0);
layout->layout();
2011-10-31 11:55:25 +00:00
// TODO: Automate graph creation process
// The following code (to the closing marker) is crap --->
AHI=createGraph("AHI","Apnea\nHypopnea\nIndex");
UC=createGraph("Usage","Usage\n(time)");
2011-11-30 12:58:41 +00:00
int default_height=PROFILE["GraphHeight"].toInt();
US=new gGraph(GraphView,"Session Times","Session Times\n(time)",default_height,0);
US->AddLayer(new gYAxisTime(),LayerLeft,gYAxis::Margin);
gXAxis *x=new gXAxis();
x->setUtcFix(true);
US->AddLayer(x,LayerBottom,0,gXAxis::Margin);
US->AddLayer(new gXGrid());
PR=createGraph("Pressure","Pressure\n(cmH2O)");
SET=createGraph("Settings","Settings");
LK=createGraph("Leaks","Leak Rate\n(L/min)");
SES=createGraph("Sessions","Sessions\n(count)");
NPB=createGraph("% in PB","Periodic\nBreathing\n(% of night)");
RR=createGraph("Resp. Rate","Respiratory\nRate\n(breaths/min)");
TV=createGraph("Tidal Volume","Tidal\nVolume\n(ml)");
MV=createGraph("Minute Vent.","Minute\nVentilation\n(L/min)");
PTB=createGraph("Pat. Trig. Br.","Patient\nTriggered\nBreaths\n(%)");
PULSE=createGraph("Pulse Rate","Pulse Rate\n(bpm)");
SPO2=createGraph("SpO2","Oxygen Saturation\n(%)");
WEIGHT=createGraph("Weight","Weight\n(kg)");
BMI=createGraph("BMI","Body\nMass\nIndex");
ZOMBIE=createGraph("Zombie","How you felt\n(% awesome)");
2011-12-02 12:05:57 +00:00
2011-12-02 14:18:47 +00:00
weight=new SummaryChart("Weight",GT_LINE);
2011-12-02 12:05:57 +00:00
weight->setMachineType(MT_JOURNAL);
2011-12-04 14:26:32 +00:00
weight->addSlice("Weight",QColor("black"),ST_SETAVG,true);
2011-12-02 12:05:57 +00:00
WEIGHT->AddLayer(weight);
bmi=new SummaryChart("BMI",GT_LINE);
bmi->setMachineType(MT_JOURNAL);
2011-12-04 14:26:32 +00:00
bmi->addSlice("BMI",QColor("dark blue"),ST_SETAVG,true);
BMI->AddLayer(bmi);
2011-12-02 12:05:57 +00:00
zombie=new SummaryChart("Zombie Meter",GT_LINE);
zombie->setMachineType(MT_JOURNAL);
2011-12-04 14:26:32 +00:00
zombie->addSlice("ZombieMeter",QColor("dark red"),ST_SETAVG,true);
2011-12-02 12:05:57 +00:00
ZOMBIE->AddLayer(zombie);
2011-12-01 00:18:59 +00:00
pulse=new SummaryChart("Pulse Rate",GT_LINE);
pulse->setMachineType(MT_OXIMETER);
2011-12-04 14:26:32 +00:00
pulse->addSlice(OXI_Pulse,QColor("red"),ST_WAVG,true);
pulse->addSlice(OXI_Pulse,QColor("pink"),ST_MIN,true);
pulse->addSlice(OXI_Pulse,QColor("orange"),ST_MAX,true);
2011-12-01 00:18:59 +00:00
PULSE->AddLayer(pulse);
spo2=new SummaryChart("SpO2",GT_LINE);
spo2->setMachineType(MT_OXIMETER);
2011-12-04 14:26:32 +00:00
spo2->addSlice(OXI_SPO2,QColor("cyan"),ST_WAVG,true);
spo2->addSlice(OXI_SPO2,QColor("light blue"),ST_90P,true);
spo2->addSlice(OXI_SPO2,QColor("blue"),ST_MIN,true);
2011-12-01 00:18:59 +00:00
SPO2->AddLayer(spo2);
uc=new SummaryChart("Hours",GT_BAR);
2011-12-04 14:26:32 +00:00
uc->addSlice("",QColor("green"),ST_HOURS,true);
UC->AddLayer(uc);
us=new SummaryChart("Hours",GT_SESSIONS);
2011-12-04 14:26:32 +00:00
us->addSlice("",QColor("dark blue"),ST_HOURS,true);
us->addSlice("",QColor("blue"),ST_SESSIONS,true);
US->AddLayer(us);
2011-10-30 15:25:53 +00:00
ses=new SummaryChart("Sessions",GT_LINE);
2011-12-04 14:26:32 +00:00
ses->addSlice("",QColor("blue"),ST_SESSIONS,true);
2011-10-30 15:25:53 +00:00
SES->AddLayer(ses);
bc=new SummaryChart("AHI",GT_BAR);
2011-12-04 14:26:32 +00:00
bc->addSlice(CPAP_Hypopnea,QColor("blue"),ST_CPH,false);
bc->addSlice(CPAP_Apnea,QColor("dark green"),ST_CPH,false);
bc->addSlice(CPAP_Obstructive,QColor("#40c0ff"),ST_CPH,false);
bc->addSlice(CPAP_ClearAirway,QColor("purple"),ST_CPH,false);
AHI->AddLayer(bc);
set=new SummaryChart("",GT_LINE);
2011-09-18 15:43:14 +00:00
//set->addSlice("SysOneResistSet",QColor("grey"),ST_SETAVG);
2011-12-05 11:17:28 +00:00
set->addSlice("HumidSet",QColor("blue"),ST_SETWAVG,true);
set->addSlice("FlexSet",QColor("red"),ST_SETWAVG,true);
set->addSlice("EPR",QColor("green"),ST_SETWAVG,true);
set->addSlice("SmartFlex",QColor("purple"),ST_SETWAVG,true);
SET->setRecMinY(0);
SET->setRecMaxY(5);
2011-09-18 15:43:14 +00:00
SET->AddLayer(set);
rr=new SummaryChart("breaths/min",GT_LINE);
2011-12-04 14:26:32 +00:00
rr->addSlice(CPAP_RespRate,QColor("light blue"),ST_MIN,true);
rr->addSlice(CPAP_RespRate,QColor("light green"),ST_90P,true);
rr->addSlice(CPAP_RespRate,QColor("blue"),ST_WAVG,true);
RR->AddLayer(rr);
tv=new SummaryChart("L/b",GT_LINE);
2011-12-04 14:26:32 +00:00
tv->addSlice(CPAP_TidalVolume,QColor("light blue"),ST_MIN,true);
tv->addSlice(CPAP_TidalVolume,QColor("light green"),ST_90P,true);
tv->addSlice(CPAP_TidalVolume,QColor("blue"),ST_WAVG,true);
TV->AddLayer(tv);
mv=new SummaryChart("L/m",GT_LINE);
2011-12-04 14:26:32 +00:00
mv->addSlice(CPAP_MinuteVent,QColor("light blue"),ST_MIN,true);
mv->addSlice(CPAP_MinuteVent,QColor("light green"),ST_90P,true);
mv->addSlice(CPAP_MinuteVent,QColor("blue"),ST_WAVG,true);
MV->AddLayer(mv);
ptb=new SummaryChart("%PTB",GT_LINE);
2011-12-04 14:26:32 +00:00
ptb->addSlice(CPAP_PTB,QColor("yellow"),ST_MIN,true);
ptb->addSlice(CPAP_PTB,QColor("light gray"),ST_90P,true);
ptb->addSlice(CPAP_PTB,QColor("orange"),ST_WAVG,true);
PTB->AddLayer(ptb);
pr=new SummaryChart("cmH2O",GT_LINE);
//PR->setRecMinY(4.0);
//PR->setRecMaxY(12.0);
2011-12-04 14:26:32 +00:00
pr->addSlice(CPAP_Pressure,QColor("dark green"),ST_WAVG,true);
pr->addSlice(CPAP_Pressure,QColor("orange"),ST_MIN,true);
pr->addSlice(CPAP_Pressure,QColor("red"),ST_MAX,true);
pr->addSlice(CPAP_Pressure,QColor("grey"),ST_90P,true);
pr->addSlice(CPAP_EPAP,QColor("light green"),ST_MIN,true);
pr->addSlice(CPAP_IPAP,QColor("light blue"),ST_MAX,true);
PR->AddLayer(pr);
lk=new SummaryChart("Avg Leak",GT_LINE);
2011-12-04 14:26:32 +00:00
lk->addSlice(CPAP_Leak,QColor("dark grey"),ST_90P,false);
lk->addSlice(CPAP_Leak,QColor("dark blue"),ST_WAVG,false);
//lk->addSlice(CPAP_Leak,QColor("dark yellow"));
//pr->addSlice(CPAP_IPAP,QColor("red"));
LK->AddLayer(lk);
NPB->AddLayer(npb=new SummaryChart("% PB",GT_BAR));
2011-12-04 14:26:32 +00:00
npb->addSlice(CPAP_CSR,QColor("light green"),ST_SPH,false);
2011-10-31 11:55:25 +00:00
// <--- The code to the previous marker is crap
GraphView->LoadSettings("Overview");
}
Overview::~Overview()
{
GraphView->SaveSettings("Overview");
2011-10-05 08:09:57 +00:00
disconnect(this,SLOT(dateStart_currentPageChanged(int,int)));
disconnect(this,SLOT(dateEnd_currentPageChanged(int,int)));
delete ui;
}
gGraph * Overview::createGraph(QString name,QString units)
2011-10-31 11:55:25 +00:00
{
2011-11-30 12:58:41 +00:00
int default_height=PROFILE["GraphHeight"].toInt();
gGraph *g=new gGraph(GraphView,name,units,default_height,0);
2011-10-31 11:55:25 +00:00
g->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin);
gXAxis *x=new gXAxis();
x->setUtcFix(true);
g->AddLayer(x,LayerBottom,0,gXAxis::Margin);
g->AddLayer(new gXGrid());
return g;
}
void Overview::ReloadGraphs()
{
ui->dateStart->setDate(p_profile->FirstDay());
ui->dateEnd->setDate(p_profile->LastDay());
GraphView->setDay(NULL);
2011-06-26 08:30:44 +00:00
}
void Overview::RedrawGraphs()
{
GraphView->updateGL();
}
2011-09-12 03:07:57 +00:00
void Overview::UpdateCalendarDay(QDateEdit * dateedit,QDate date)
{
QCalendarWidget *calendar=dateedit->calendarWidget();
QTextCharFormat bold;
QTextCharFormat cpapcol;
QTextCharFormat normal;
QTextCharFormat oxiday;
bold.setFontWeight(QFont::Bold);
cpapcol.setForeground(QBrush(Qt::blue, Qt::SolidPattern));
cpapcol.setFontWeight(QFont::Bold);
oxiday.setForeground(QBrush(Qt::red, Qt::SolidPattern));
oxiday.setFontWeight(QFont::Bold);
2011-10-31 11:55:25 +00:00
bool hascpap=p_profile->GetDay(date,MT_CPAP)!=NULL;
bool hasoxi=p_profile->GetDay(date,MT_OXIMETER)!=NULL;
//bool hasjournal=p_profile->GetDay(date,MT_JOURNAL)!=NULL;
2011-09-12 03:07:57 +00:00
if (hascpap) {
if (hasoxi) {
calendar->setDateTextFormat(date,oxiday);
} else {
calendar->setDateTextFormat(date,cpapcol);
}
} else if (p_profile->GetDay(date)) {
2011-09-12 03:07:57 +00:00
calendar->setDateTextFormat(date,bold);
} else {
calendar->setDateTextFormat(date,normal);
}
calendar->setHorizontalHeaderFormat(QCalendarWidget::ShortDayNames);
}
2011-10-05 08:09:57 +00:00
void Overview::dateStart_currentPageChanged(int year, int month)
2011-09-12 03:07:57 +00:00
{
QDate d(year,month,1);
int dom=d.daysInMonth();
for (int i=1;i<=dom;i++) {
d=QDate(year,month,i);
UpdateCalendarDay(ui->dateStart,d);
}
}
2011-10-05 08:09:57 +00:00
void Overview::dateEnd_currentPageChanged(int year, int month)
2011-09-12 03:07:57 +00:00
{
QDate d(year,month,1);
int dom=d.daysInMonth();
for (int i=1;i<=dom;i++) {
d=QDate(year,month,i);
UpdateCalendarDay(ui->dateEnd,d);
}
}
2011-06-26 08:30:44 +00:00
void Overview::on_dateEnd_dateChanged(const QDate &date)
{
qint64 d1=qint64(QDateTime(ui->dateStart->date(),QTime(0,0,0),Qt::UTC).toTime_t())*1000L;
qint64 d2=qint64(QDateTime(date,QTime(23,59,59),Qt::UTC).toTime_t())*1000L;
GraphView->SetXBounds(d1,d2);
2011-07-17 07:03:26 +00:00
2011-06-26 08:30:44 +00:00
}
void Overview::on_dateStart_dateChanged(const QDate &date)
2011-06-26 08:30:44 +00:00
{
qint64 d1=qint64(QDateTime(date,QTime(0,0,0),Qt::UTC).toTime_t())*1000L;
qint64 d2=qint64(QDateTime(ui->dateEnd->date(),QTime(23,59,59),Qt::UTC).toTime_t())*1000L;
GraphView->SetXBounds(d1,d2);
2011-06-26 08:30:44 +00:00
}
void Overview::on_toolButton_clicked()
2011-06-26 08:30:44 +00:00
{
qint64 d1=qint64(QDateTime(ui->dateStart->date(),QTime(0,0,0),Qt::UTC).toTime_t())*1000L;
qint64 d2=qint64(QDateTime(ui->dateEnd->date(),QTime(23,59,59),Qt::UTC).toTime_t())*1000L;
GraphView->SetXBounds(d1,d2);
2011-06-26 08:30:44 +00:00
}
2011-09-12 16:10:18 +00:00
void Overview::on_printButton_clicked()
{
2011-12-02 14:36:40 +00:00
mainwin->PrintReport(GraphView,"Overview");
2011-09-12 16:10:18 +00:00
}
void Overview::ResetGraphLayout()
{
GraphView->resetLayout();
}