From ea18dc58909f727ed41a2ba356f92d9e54ff94e4 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Fri, 22 Jul 2011 23:46:17 +1000 Subject: [PATCH] QPainter does not work in offscreen graphs --- Graphs/gFlagsLine.cpp | 17 ++--- Graphs/glcommon.cpp | 26 ++++--- SleepLib/loader_plugins/prs1_loader.cpp | 63 ++++++++++------- SleepLib/machine.cpp | 9 ++- SleepLib/profiles.cpp | 5 +- SleepLib/session.cpp | 21 ++---- daily.cpp | 91 ++++++++++++------------- daily.h | 10 +-- main.cpp | 18 ++--- mainwindow.cpp | 55 ++++++++++----- mainwindow.h | 1 - mainwindow.ui | 6 +- overview.cpp | 7 +- overview.h | 4 +- oximetry.cpp | 6 +- oximetry.h | 4 +- 16 files changed, 183 insertions(+), 160 deletions(-) diff --git a/Graphs/gFlagsLine.cpp b/Graphs/gFlagsLine.cpp index 153badf8..ff5cb0f7 100644 --- a/Graphs/gFlagsLine.cpp +++ b/Graphs/gFlagsLine.cpp @@ -24,14 +24,6 @@ void gFlagsGroup::Plot(gGraphWindow &w, float scrx, float scry) int width=scrx-(w.GetLeftMargin()+w.GetRightMargin())-1; int height=scry-(w.GetTopMargin()+w.GetBottomMargin()); - glColor3f (0.1F, 0.1F, 0.1F); - glLineWidth (1); - glBegin (GL_LINE_LOOP); - glVertex2f (start_px-1, start_py); - glVertex2f (start_px-1, start_py+height); - glVertex2f (start_px+width,start_py+height); - glVertex2f (start_px+width, start_py); - glEnd (); vector visible; for (unsigned i=0;itotal_lines=vis; visible[i]->Plot(w,scrx,scry); } + glColor3f (0.0F, 0.0F, 0.0F); + glLineWidth (1); + glBegin (GL_LINE_LOOP); + glVertex2f (start_px-1, start_py); + glVertex2f (start_px-1, start_py+height); + glVertex2f (start_px+width,start_py+height); + glVertex2f (start_px+width, start_py); + glEnd (); + } diff --git a/Graphs/glcommon.cpp b/Graphs/glcommon.cpp index 31fe6d61..6435fedd 100644 --- a/Graphs/glcommon.cpp +++ b/Graphs/glcommon.cpp @@ -104,22 +104,28 @@ vector TextQueRot; void DrawTextQueue(gGraphWindow & wid) { - glFlush(); - QPainter painter(&wid); + //glFlush(); for (unsigned i=0;isecond[0])) { //qWarning() << "PRS1Loader: Dodgy summary file " << s->second[0]; - // delete sess; - // continue; + delete sess; + continue; } //sess->SetSessionID(sess->start().GetTicks()); if (!s->second[1].isEmpty()) { @@ -303,20 +302,16 @@ int PRS1Loader::OpenMachine(Machine *m,QString path,Profile *profile) } const double ignore_thresh=300.0/3600.0;// Ignore useless sessions under 5 minute if (sess->hours()<=ignore_thresh) { - qDebug() << "Igoring short session" << session << "which is only" << (sess->hours()*60.0) << "minute(s) long"; + //qDebug() << "Ignoring short session" << session << "which is only" << (sess->hours()*60.0) << "minute(s) long"; delete sess; continue; } - m->AddSession(sess,profile); - - //if (sess->summary.find(CPAP_Obstructive)==sess->summary.end()) { - sess->summary[CPAP_Obstructive]=sess->count_events(CPAP_Obstructive); - sess->summary[CPAP_Hypopnea]=sess->count_events(CPAP_Hypopnea); - sess->summary[CPAP_ClearAirway]=sess->count_events(CPAP_ClearAirway); - sess->summary[CPAP_RERA]=sess->count_events(CPAP_RERA); - sess->summary[CPAP_FlowLimit]=sess->count_events(CPAP_FlowLimit); - sess->summary[CPAP_VSnore]=sess->count_events(CPAP_VSnore); - //} + sess->summary[CPAP_Obstructive]=sess->count_events(CPAP_Obstructive); + sess->summary[CPAP_Hypopnea]=sess->count_events(CPAP_Hypopnea); + sess->summary[CPAP_ClearAirway]=sess->count_events(CPAP_ClearAirway); + sess->summary[CPAP_RERA]=sess->count_events(CPAP_RERA); + sess->summary[CPAP_FlowLimit]=sess->count_events(CPAP_FlowLimit); + sess->summary[CPAP_VSnore]=sess->count_events(CPAP_VSnore); sess->summary[CPAP_CSR]=sess->sum_event_field(CPAP_CSR,0); sess->summary[CPAP_Snore]=sess->sum_event_field(CPAP_Snore,0); @@ -382,13 +377,15 @@ int PRS1Loader::OpenMachine(Machine *m,QString path,Profile *profile) //Printf(sess->start().Format()+wxT(" avgsummary=%.3f avgmine=%.3f\n"),sess->summary[CPAP_PressureAverage].GetDouble(),sess->weighted_avg_event_field(CPAP_Pressure,0)); sess->SetChanged(true); + m->AddSession(sess,profile); + } QString s; s.sprintf("%i",prs1_data_version); m->properties["DataVersion"]=s; - m->Save(); // Save any new sessions to disk in our format + m->Save(); // Save any new sessions to disk in our format */ if (qprogress) qprogress->setValue(100); - qDebug() << "OpenMachine Done"; + //qDebug() << "OpenMachine Done"; return true; } @@ -976,11 +973,27 @@ bool PRS1Loader::OpenWaveforms(Session *session,QString filename) pos+=length; continue; } else { - int diff=(lasttimestamp+duration)-timestamp; + int diff=timestamp-(lasttimestamp+duration); + if (block==1) { + if (diff>0) + start-=diff; + } length=m_buffer[pos+0x1] | m_buffer[pos+0x2] << 8; // block length in bytes duration=m_buffer[pos+0xf] | m_buffer[pos+0x10] << 8; // block duration in seconds - if (diff || corrupt) { - qDebug() << "Timestamp restarts" << diff << corrupt << duration; + /* if (diff<0) { + //diff=abs(diff); + for (int i=0;i0 && wlength[0]>0) { + qDebug() << "Timestamp restarts" << block << diff << corrupt << duration << timestamp-lasttimestamp << filename; + for (int i=0;iAddWaveform(w); } return true; -} -*/ +} */ + void InitModelMap() { ModelMap[34]="RemStar Pro with C-Flex+"; diff --git a/SleepLib/machine.cpp b/SleepLib/machine.cpp index fa857cce..0bc04ee8 100644 --- a/SleepLib/machine.cpp +++ b/SleepLib/machine.cpp @@ -223,6 +223,7 @@ Session *Machine::SessionExists(SessionID session) return NULL; } } + Day *Machine::AddSession(Session *s,Profile *p) { double span=0; @@ -238,8 +239,7 @@ Day *Machine::AddSession(Session *s,Profile *p) //QTime time=d2.time(); // pref["NoonDateSplit"]=true; - - if (pref["NoonDateSplit"].toBool()) { + if (pref.Exists("NoonDataSplit") && pref["NoonDateSplit"].toBool()) { int hour=d2.time().hour(); if (hour<12) date=date.addDays(-1); @@ -302,7 +302,6 @@ Day *Machine::AddSession(Session *s,Profile *p) //qDebug() << "New day: " << d.toString("yyyy-MM-dd HH:mm:ss"); p->AddDay(date,day[date],m_type); } - day[date]->AddSession(s); return day[date]; @@ -432,13 +431,13 @@ bool Machine::Save() for (d=day.begin();d!=day.end();d++) { - qDebug() << "Day Save Commenced"; + //qDebug() << "Day Save Commenced"; for (s=d->second->begin(); s!=d->second->end(); s++) { cnt++; if (qprogress) qprogress->setValue(66.0+(float(cnt)/float(size)*33.0)); if ((*s)->IsChanged()) (*s)->Store(path); } - qDebug() << "Day Save Completed"; + //qDebug() << "Day Save Completed"; } return true; diff --git a/SleepLib/profiles.cpp b/SleepLib/profiles.cpp index 29619e36..de731d5a 100644 --- a/SleepLib/profiles.cpp +++ b/SleepLib/profiles.cpp @@ -160,6 +160,7 @@ TiXmlElement * Profile::ExtraSave() } +#include void Profile::AddDay(QDate date,Day *day,MachineType mt) { //date+=wxTimeSpan::Day(); if (is_first_day) { @@ -170,14 +171,12 @@ void Profile::AddDay(QDate date,Day *day,MachineType mt) { if (m_last & dl=daylist[date]; for (vector::iterator a=dl.begin();a!=dl.end();a++) { if ((*a)->machine->GetType()==mt) { throw OneTypePerDay(); } } - daylist[date].push_back(day); } @@ -213,7 +212,7 @@ int Profile::Import(QString path) for (list::iterator i=loaders.begin(); i!=loaders.end(); i++) { if (c+=(*i)->Open(path,this)) break; } - qDebug() << "Import Done"; + //qDebug() << "Import Done"; return c; } diff --git a/SleepLib/session.cpp b/SleepLib/session.cpp index f8f50927..3fb73803 100644 --- a/SleepLib/session.cpp +++ b/SleepLib/session.cpp @@ -247,9 +247,7 @@ bool Session::OpenEvents() { if(s_events_loaded) return true; bool b; - qDebug() << "Open Events() Start"; b=LoadEvents(s_eventfile); - qDebug() << "Open Events() Done"; if (!b) { qWarning() << "Error Unkpacking Events" << s_eventfile; } @@ -261,9 +259,7 @@ bool Session::OpenWaveforms() { if (s_waves_loaded) return true; bool b; - qDebug() << "OpenWaveforms() Start"; b=LoadWaveforms(s_wavefile); - qDebug() << "OpenWaveforms() Done"; if (!b) { qWarning() << "Error Unkpacking Wavefile" << s_wavefile; } @@ -271,9 +267,6 @@ bool Session::OpenWaveforms() { return b; }; - - - bool Session::Store(QString path) // Storing Session Data in our format // {DataDir}/{MachineID}/{SessionID}.{ext} @@ -285,14 +278,14 @@ bool Session::Store(QString path) QString base; base.sprintf("%08lx",s_session); base=path+"/"+base; - qDebug() << "Storing Session: " << base; + //qDebug() << "Storing Session: " << base; bool a,b,c; a=StoreSummary(base+".000"); // if actually has events - qDebug() << " Summary done"; + //qDebug() << " Summary done"; if (events.size()>0) b=StoreEvents(base+".001"); - qDebug() << " Events done"; + //qDebug() << " Events done"; if (waveforms.size()>0) c=StoreWaveforms(base+".002"); - qDebug() << " Waveform done"; + //qDebug() << " Waveform done"; if (a) { s_changed=false; } @@ -642,13 +635,13 @@ bool Session::StoreWaveforms(QString filename) vector::iterator j; int zz=0; for (i=waveforms.begin(); i!=waveforms.end(); i++) { - qDebug() << "Storing Waveform" << zz++ << filename; + //qDebug() << "Storing Waveform" << zz++ << filename; out << (quint16)i->first; // Machine Code t16=i->second.size(); out << t16; // Number of (hopefully non-linear) waveform chunks int chnk=0; for (j=i->second.begin(); j!=i->second.end(); j++) { - qDebug() << "Storing Waveform Chunk" << chnk++; + //qDebug() << "Storing Waveform Chunk" << chnk++; Waveform &w=*(*j); // 64bit number.. @@ -666,7 +659,7 @@ bool Session::StoreWaveforms(QString filename) //t8=0; // 0=signed, 1=unsigned, 2=float // followed by sample data. - qDebug() << "Writing " << (*j)->samples() << "samples"; + //qDebug() << "Writing " << (*j)->samples() << "samples"; for (int k=0; k<(*j)->samples(); k++) out << w[k]; } } diff --git a/daily.cpp b/daily.cpp index e78bf4c2..cfa3e16e 100644 --- a/daily.cpp +++ b/daily.cpp @@ -25,14 +25,13 @@ #include "Graphs/gBarChart.h" #include "Graphs/gpiechart.h" -Daily::Daily(QWidget *parent,QGLContext *context) : + +Daily::Daily(QWidget *parent,QGLWidget * shared) : QWidget(parent), ui(new Ui::Daily) { ui->setupUi(this); - shared_context=context; - QString prof=pref["Profile"].toString(); profile=Profiles::Get(prof); if (!profile) { @@ -43,18 +42,8 @@ Daily::Daily(QWidget *parent,QGLContext *context) : gSplitter=new QSplitter(Qt::Vertical,ui->scrollArea); gSplitter->setStyleSheet("QSplitter::handle { background-color: 'dark grey'; }"); gSplitter->setHandleWidth(2); - //gSplitter->handle ui->graphSizer->addWidget(gSplitter); - //QPalette pal; - //QColor col("blue"); - //pal.setColor(QPalette::Button, col); - //gSplitter->setPaletteForegroundColor(QColor("blue")); - //gSplitter->setBackgroundRole(QPalette::Button); - //ui->scrollArea->setWidgetResizable(true); - //gSplitter->setMinimumSize(500,500); - //gSplitter->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum); - AddCPAPData(flags[3]=new FlagData(CPAP_Hypopnea,4)); AddCPAPData(flags[0]=new FlagData(CPAP_CSR,7,1,0)); AddCPAPData(flags[1]=new FlagData(CPAP_ClearAirway,6)); @@ -66,15 +55,42 @@ Daily::Daily(QWidget *parent,QGLContext *context) : AddCPAPData(flags[8]=new FlagData(PRS1_Unknown0E,1)); AddCPAPData(flags[9]=new FlagData(CPAP_Snore,1)); // Snore Index - SF=new gGraphWindow(gSplitter,tr("Event Flags"),(QGLWidget *)NULL); - fg=new gFlagsGroup(); + SF=new gGraphWindow(gSplitter,tr("Event Flags"),shared); + FRW=new gGraphWindow(gSplitter,tr("Flow Rate"),SF); + PRD=new gGraphWindow(gSplitter,tr("Pressure"),SF); + LEAK=new gGraphWindow(gSplitter,tr("Leaks"),SF); + MP=new gGraphWindow(gSplitter,tr("Mask Pressure"),SF); + SNORE=new gGraphWindow(gSplitter,tr("Snore"),SF); + FLG=new gGraphWindow(gSplitter,tr("Flow Limitation"),SF); + MV=new gGraphWindow(gSplitter,tr("Minute Ventilation"),SF); + TV=new gGraphWindow(gSplitter,tr("Tidal Volume"),SF); + RR=new gGraphWindow(gSplitter,tr("Respiratory Rate"),SF); + PTB=new gGraphWindow(gSplitter,tr("Patient Trig Breaths"),SF); + PULSE=new gGraphWindow(gSplitter,tr("Pulse & SpO2"),SF); + + /*QGLFormat fmt; + fmt.setDepth(false); + fmt.setDirectRendering(false); + fmt.setAlpha(true); + fmt.setDoubleBuffer(false); + fmt.setRgba(true); + //fmt.setDefaultFormat(fmt); + offscreen_context=new QGLContext(fmt); */ + + TAP=new gGraphWindow(NULL,"",(QGLWidget* )NULL); + TAP_EAP=new gGraphWindow(NULL,"",(QGLWidget* )NULL); + TAP_IAP=new gGraphWindow(NULL,"",(QGLWidget* )NULL); + G_AHI=new gGraphWindow(NULL,"",(QGLWidget* )NULL); + SF->SetLeftMargin(SF->GetLeftMargin()+gYAxis::Margin); SF->SetBlockZoom(true); SF->AddLayer(new gXAxis()); + SF->setMinimumHeight(160); int sfc=7; bool extras=false; //true; + fg=new gFlagsGroup(); fg->AddLayer(new gFlagsLine(flags[0],QColor("light green"),"CSR",false,0,sfc)); fg->AddLayer(new gFlagsLine(flags[1],QColor("purple"),"CA",true,1,sfc)); fg->AddLayer(new gFlagsLine(flags[2],QColor("#40c0ff"),"OA",true,2,sfc)); @@ -82,15 +98,11 @@ Daily::Daily(QWidget *parent,QGLContext *context) : fg->AddLayer(new gFlagsLine(flags[4],QColor("black"),"FL",false,4,sfc)); fg->AddLayer(new gFlagsLine(flags[6],QColor("gold"),"RE",false,6,sfc)); fg->AddLayer(new gFlagsLine(flags[5],QColor("red"),"VS",false,5,sfc)); - if (extras) { - fg->AddLayer(new gFlagsLine(flags[8],QColor("dark green"),"U0E",7,sfc)); - fg->AddLayer(new gFlagsLine(flags[9],QColor("red"),"VS2",8,sfc)); - sfc++; - } + fg->AddLayer(new gFlagsLine(flags[8],QColor("dark green"),"U0E",7,sfc)); + //fg->AddLayer(new gFlagsLine(flags[9],QColor("red"),"VS2",8,sfc)); SF->AddLayer(fg); + // SF Foobar must go last SF->AddLayer(new gFooBar(10,QColor("orange"),QColor("dark grey"),true)); - SF->setMinimumHeight(150+(extras ? 20 : 0)); - // SF->setMaximumHeight(350); AddCPAPData(pressure_iap=new EventData(CPAP_IAP)); AddCPAPData(pressure_eap=new EventData(CPAP_EAP)); @@ -98,7 +110,6 @@ Daily::Daily(QWidget *parent,QGLContext *context) : pressure_eap->ForceMinY(0); pressure_eap->ForceMaxY(30); - PRD=new gGraphWindow(gSplitter,tr("Pressure"),SF); PRD->AddLayer(new gXAxis()); PRD->AddLayer(new gYAxis()); //PRD->AddLayer(new gFooBar()); @@ -109,7 +120,6 @@ Daily::Daily(QWidget *parent,QGLContext *context) : PRD->setMinimumHeight(150); AddCPAPData(leak=new EventData(CPAP_Leak,0)); - LEAK=new gGraphWindow(gSplitter,tr("Leaks"),SF); LEAK->AddLayer(new gXAxis()); LEAK->AddLayer(new gYAxis()); //LEAK->AddLayer(new gFooBar()); @@ -119,7 +129,6 @@ Daily::Daily(QWidget *parent,QGLContext *context) : AddCPAPData(mp=new WaveData(CPAP_MaskPressure,1000000)); //FlowRate - MP=new gGraphWindow(gSplitter,tr("Mask Pressure"),SF); gYAxis *y=new gYAxis(); y->SetScale(.1); MP->AddLayer(y); @@ -129,10 +138,8 @@ Daily::Daily(QWidget *parent,QGLContext *context) : MP->AddLayer(g); MP->setMinimumHeight(120); - AddCPAPData(frw=new WaveData(CPAP_FlowRate,1000000)); //FlowRate // Holy crap resmed stuff is huge.. - FRW=new gGraphWindow(gSplitter,tr("Flow Rate"),SF); //FRW->AddLayer(new gFooBar()); FRW->AddLayer(new gYAxis()); FRW->AddLayer(new gXAxis()); @@ -153,14 +160,12 @@ Daily::Daily(QWidget *parent,QGLContext *context) : FRW->setMinimumHeight(150); AddCPAPData(snore=new EventData(CPAP_Snore,0)); - SNORE=new gGraphWindow(gSplitter,tr("Snore"),SF); SNORE->AddLayer(new gXAxis()); SNORE->AddLayer(new gYAxis()); SNORE->AddLayer(new gLineChart(snore,Qt::black,4096,false,false,true)); SNORE->setMinimumHeight(150); AddCPAPData(flg=new EventData(CPAP_FlowLimitGraph,0)); - FLG=new gGraphWindow(gSplitter,tr("Flow Limitation"),SF); FLG->AddLayer(new gXAxis()); FLG->AddLayer(new gYAxis()); FLG->AddLayer(new gLineChart(flg,Qt::black,4096,false,false,true)); @@ -168,28 +173,24 @@ Daily::Daily(QWidget *parent,QGLContext *context) : AddCPAPData(mv=new EventData(CPAP_MinuteVentilation)); - MV=new gGraphWindow(gSplitter,tr("Minute Ventilation"),SF); MV->AddLayer(new gXAxis()); MV->AddLayer(new gYAxis()); MV->AddLayer(new gLineChart(mv,QColor(0x20,0x20,0x7f),65536,false,false,true)); MV->setMinimumHeight(150); AddCPAPData(tv=new EventData(CPAP_TidalVolume)); - TV=new gGraphWindow(gSplitter,tr("Tidal Volume"),SF); TV->AddLayer(new gXAxis()); TV->AddLayer(new gYAxis()); TV->AddLayer(new gLineChart(tv,QColor(0x7f,0x20,0x20),65536,false,false,true)); TV->setMinimumHeight(150); AddCPAPData(rr=new EventData(CPAP_RespiratoryRate)); - RR=new gGraphWindow(gSplitter,tr("Respiratory Rate"),SF); RR->AddLayer(new gXAxis()); RR->AddLayer(new gYAxis()); RR->AddLayer(new gLineChart(rr,Qt::gray,65536,false,false,true)); RR->setMinimumHeight(150); AddCPAPData(ptb=new EventData(CPAP_PatientTriggeredBreaths )); - PTB=new gGraphWindow(gSplitter,tr("Patient Trig Breaths"),SF); PTB->AddLayer(new gXAxis()); PTB->AddLayer(new gYAxis()); PTB->AddLayer(new gLineChart(ptb,Qt::gray,65536,false,false,true)); @@ -199,7 +200,6 @@ Daily::Daily(QWidget *parent,QGLContext *context) : AddOXIData(pulse=new EventData(OXI_Pulse,0,65536,true)); //pulse->ForceMinY(40); //pulse->ForceMaxY(120); - PULSE=new gGraphWindow(gSplitter,tr("Pulse & SpO2"),SF); PULSE->AddLayer(new gXAxis()); PULSE->AddLayer(new gYAxis()); // PULSE->AddLayer(new gFooBar()); @@ -226,21 +226,18 @@ Daily::Daily(QWidget *parent,QGLContext *context) : AddCPAPData(tap=new TAPData(CPAP_Pressure)); - TAP=new gGraphWindow(gSplitter,"",SF); //TAP->SetMargins(20,15,5,50); TAP->SetMargins(0,0,0,0); TAP->AddLayer(new gCandleStick(tap)); //TAP->AddLayer(new gPieChart(tap)); - TAP_EAP=new gGraphWindow(gSplitter,"",SF); TAP_EAP->SetMargins(0,0,0,0); TAP_EAP->AddLayer(new gCandleStick(tap_eap)); - TAP_IAP=new gGraphWindow(gSplitter,"",SF); TAP_IAP->SetMargins(0,0,0,0); TAP_IAP->AddLayer(new gCandleStick(tap_iap)); - G_AHI=new gGraphWindow(gSplitter,"",SF); + G_AHI->SetMargins(0,0,0,0); AddCPAPData(g_ahi=new AHIData()); //gCandleStick *l=new gCandleStick(g_ahi); @@ -260,6 +257,7 @@ Daily::Daily(QWidget *parent,QGLContext *context) : l->color.push_back(QColor(0x60,0xff,0x60,0xff)); // green G_AHI->AddLayer(l); G_AHI->SetGradientBackground(false); + //G_AHI->setMaximumSize(2000,30); //TAP->setMaximumSize(2000,30); NoData=new QLabel(tr("No data"),gSplitter); @@ -329,7 +327,6 @@ void Daily::ReloadGraphs() if (!d.isValid()) { d=ui->calendar->selectedDate(); } - on_calendar_currentPageChanged(d.year(),d.month()); ui->calendar->setSelectedDate(d); Load(d); @@ -469,8 +466,8 @@ void Daily::Load(QDate date) const int gwwidth=240; const int gwheight=25; - UpdateCPAPGraphs(cpap); UpdateOXIGraphs(oxi); + UpdateCPAPGraphs(cpap); UpdateEventsTree(ui->treeWidget,cpap); QString epr,modestr; @@ -496,6 +493,7 @@ void Daily::Load(QDate date) 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 p90=cpap->percentile(CPAP_Pressure,0,0.9); eap90=cpap->percentile(CPAP_EAP,0,0.9); iap90=cpap->percentile(CPAP_IAP,0,0.9); @@ -541,7 +539,8 @@ void Daily::Load(QDate date) ""; } html+="\n"+tr("Event Breakdown")+"\n"; - { + if (1) { + G_AHI->setFixedSize(gwwidth,gwheight); QPixmap pixmap=G_AHI->renderPixmap(120,120,false); //gwwidth,gwheight,false); QByteArray byteArray; @@ -620,11 +619,6 @@ void Daily::Load(QDate date) // Instead of doing this, check whether any data exists.. // and show based on this factor. - //cpap && cpap->count(CPAP_MinuteVentilation)>0 ? MV->show() : MV->hide(); - //cpap && cpap->count(CPAP_MinuteVentilation)>0 ? MV->show() : MV->hide(); - //cpap && cpap->count(CPAP_TidalVolume)>0 ? TV->show() : TV->hide(); - //cpap && cpap->count(CPAP_RespiratoryRate)>0 ? RR->show() : RR->hide(); - //cpap && cpap->count(CPAP_FlowLimitGraph)>0 ? FLG->show() : FLG->hide(); mv->isEmpty() ? MV->hide() : MV->show(); tv->isEmpty() ? TV->hide() : TV->show(); rr->isEmpty() ? RR->hide() : RR->show(); @@ -882,8 +876,9 @@ void Daily::RedrawGraphs() // could recall Min & Max stuff here to reset cache // instead of using the dodgy notify calls. - for (list::iterator g=Graphs.begin();g!=Graphs.end();g++) { - (*g)->updateGL(); + + for (int i=0;iupdateGL(); } } diff --git a/daily.h b/daily.h index 322097df..f40abffc 100644 --- a/daily.h +++ b/daily.h @@ -28,11 +28,11 @@ class Daily : public QWidget Q_OBJECT public: - explicit Daily(QWidget *parent,QGLContext *context); + explicit Daily(QWidget *parent,QGLWidget *shared=NULL); ~Daily(); - void SetGLContext(QGLContext *context) { shared_context=context; } void ReloadGraphs(); void RedrawGraphs(); + QGLWidget *SharedWidget() { return SF; }; private slots: @@ -65,8 +65,8 @@ private: list OXIData; list CPAPData; - list Graphs; - + vector Graphs; + QGLContext *offscreen_context; void AddCPAPData(gPointData *d) { CPAPData.push_back(d); } void AddOXIData(gPointData *d) { OXIData.push_back(d); } @@ -79,10 +79,10 @@ private: Ui::Daily *ui; Profile *profile; QDate previous_date; - QGLContext *shared_context; QScrollArea *scrollArea; QSplitter *gSplitter; QLabel *NoData; + }; /*class AHIGraph:public QWebPluginFactory diff --git a/main.cpp b/main.cpp index c1f85ed4..be8f1233 100644 --- a/main.cpp +++ b/main.cpp @@ -12,15 +12,14 @@ #include "mainwindow.h" #include "SleepLib/profiles.h" -#include "SleepLib/loader_plugins/prs1_loader.h" -#include "SleepLib/loader_plugins/cms50_loader.h" -#include "SleepLib/loader_plugins/zeo_loader.h" -#include "SleepLib/loader_plugins/resmed_loader.h" -MainWindow *mainwin; +MainWindow *mainwin=NULL; void MyOutputHandler(QtMsgType type, const char *msg) { - if (!mainwin) return; + if (!mainwin) { + + return; + } switch (type) { case QtDebugMsg: mainwin->Log(msg); @@ -42,7 +41,6 @@ void MyOutputHandler(QtMsgType type, const char *msg) { int main(int argc, char *argv[]) { QApplication a(argc, argv); - qInstallMsgHandler(MyOutputHandler); a.setApplicationName("SleepyHead"); @@ -54,12 +52,10 @@ int main(int argc, char *argv[]) a.setFont(QFont("FreeSans",10)); - PRS1Loader::Register(); - CMS50Loader::Register(); - ZEOLoader::Register(); - ResmedLoader::Register(); + MainWindow w; mainwin=&w; + qInstallMsgHandler(MyOutputHandler); w.show(); return a.exec(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 34e1ab8d..08b9c14e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -13,6 +13,12 @@ #include #include "mainwindow.h" #include "ui_mainwindow.h" +#include "SleepLib/loader_plugins/prs1_loader.h" +#include "SleepLib/loader_plugins/cms50_loader.h" +#include "SleepLib/loader_plugins/zeo_loader.h" +#include "SleepLib/loader_plugins/resmed_loader.h" + + #include "daily.h" #include "overview.h" #include "Graphs/glcommon.h" @@ -25,6 +31,9 @@ QStatusBar *qstatusbar; void MainWindow::Log(QString s) { ui->logText->appendPlainText(s); + if (s.startsWith("Warning")) { + int i=5; + } } @@ -34,21 +43,32 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { -#ifndef Q_WS_MAC - this->showMaximized(); -#endif +//#ifndef Q_WS_MAC +// this->showMaximized(); +//#endif ui->setupUi(this); this->setWindowTitle(tr("SleepyHead")+QString(" v0.8.")+subversion); ui->tabWidget->setCurrentIndex(0); - QGLFormat fmt; + PRS1Loader::Register(); + CMS50Loader::Register(); + ZEOLoader::Register(); + ResmedLoader::Register(); + +/* QGLFormat fmt; fmt.setDepth(false); fmt.setDirectRendering(true); fmt.setAlpha(true); fmt.setDoubleBuffer(true); fmt.setRgba(true); fmt.setDefaultFormat(fmt); - shared_context=new QGLContext(fmt); + QGLContext smeg(fmt); */ + //new QGLContext(fmt); + //shared_context->create(shared_context); + + daily=NULL; + overview=NULL; + oximetry=NULL; //ui->tabWidget->setCurrentWidget(daily); qstatusbar=ui->statusbar; @@ -67,8 +87,6 @@ MainWindow::MainWindow(QWidget *parent) : ui->statusbar->addPermanentWidget(qstatus2,0); ui->statusbar->addPermanentWidget(qstatus,0); ui->statusbar->addPermanentWidget(qprogress,10); - daily=NULL; - overview=NULL; Profiles::Scan(); //loader_progress->Show(); @@ -76,6 +94,7 @@ MainWindow::MainWindow(QWidget *parent) : //pref["Version"]=wxString(AutoVersion::_FULLVERSION_STRING,wxConvUTF8); if (!pref.Exists("AppName")) pref["AppName"]="SleepyHead"; if (!pref.Exists("Profile")) pref["Profile"]=getUserName(); + if (!pref.Exists("LinkGraphMovement")) pref["LinkGraphMovement"]=true; else ui->action_Link_Graphs->setChecked(pref["LinkGraphMovement"].toBool()); @@ -129,13 +148,13 @@ void MainWindow::Startup() profile=Profiles::Get(pref["Profile"].toString()); profile->LoadMachineData(); - daily=new Daily(ui->tabWidget,shared_context); + daily=new Daily(ui->tabWidget); ui->tabWidget->insertTab(1,daily,tr("Daily")); - overview=new Overview(ui->tabWidget,shared_context); + overview=new Overview(ui->tabWidget,daily->SharedWidget()); ui->tabWidget->insertTab(2,overview,tr("Overview")); - oximetry=new Oximetry(ui->tabWidget); + oximetry=new Oximetry(ui->tabWidget,daily->SharedWidget()); ui->tabWidget->insertTab(3,oximetry,tr("Oximetry")); qprogress->hide(); @@ -152,7 +171,7 @@ void MainWindow::on_action_Import_Data_triggered() if (qfd.exec()) { qprogress->setValue(0); qprogress->show(); - qstatus->setText(tr("Importing Data")); + //qstatus->setText(tr("Importing Data")); dirNames=qfd.selectedFiles(); int c=0,d; for (int i=0;iSave(); - qDebug() << " profile->Save();"; + //qDebug() << " profile->Save();"; if (daily) daily->ReloadGraphs(); - qDebug() << " daily->ReloadGraphs();"; + + //qDebug() << " daily->ReloadGraphs();"; if (overview) { overview->ReloadGraphs(); overview->UpdateGraphs(); + } - qDebug() << "overview->ReloadGraphs();"; + //qDebug() << "overview->ReloadGraphs();"; } qstatus->setText(tr("Ready")); qprogress->hide(); @@ -285,7 +306,8 @@ void MainWindow::on_action_Link_Graphs_triggered(bool checked) void MainWindow::on_actionUse_AntiAliasing_triggered(bool checked) { pref["UseAntiAliasing"]=checked; - if (daily) daily->RedrawGraphs(); + if (daily) + daily->RedrawGraphs(); } @@ -307,5 +329,6 @@ void MainWindow::on_actionDebug_toggled(bool checked) void MainWindow::on_actionOverlay_Bars_toggled(bool checked) { pref["AlwaysShowOverlayBars"]=checked; - if (daily) daily->RedrawGraphs(); + if (daily) + daily->RedrawGraphs(); } diff --git a/mainwindow.h b/mainwindow.h index 0e1398da..1d921e83 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -75,7 +75,6 @@ private: Daily * daily; Overview * overview; Oximetry * oximetry; - QGLContext *shared_context; bool first_load; Profile *profile; }; diff --git a/mainwindow.ui b/mainwindow.ui index ae53f15c..38b34af3 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 822 - 468 + 930 + 540 @@ -562,7 +562,7 @@ 0 0 - 822 + 930 25 diff --git a/overview.cpp b/overview.cpp index 4f15276b..944fa80c 100644 --- a/overview.cpp +++ b/overview.cpp @@ -18,12 +18,11 @@ #include "Graphs/gFooBar.h" #include "Graphs/gSessionTime.h" -Overview::Overview(QWidget *parent,QGLContext *context) : +Overview::Overview(QWidget *parent,QGLWidget * shared) : QWidget(parent), ui(new Ui::Overview) { ui->setupUi(this); - shared_context=context; profile=Profiles::Get(pref["Profile"].toString()); AddData(ahidata=new HistoryData(profile)); AddData(pressure=new HistoryCodeData(profile,CPAP_PressureAverage)); @@ -46,7 +45,7 @@ Overview::Overview(QWidget *parent,QGLContext *context) : gSplitter->setHandleWidth(3); ui->graphLayout->addWidget(gSplitter); - AddGraph(AHI=new gGraphWindow(ui->SummaryGraphWindow,tr("AHI"),(QGLWidget *)NULL)); + AddGraph(AHI=new gGraphWindow(ui->SummaryGraphWindow,tr("AHI"),shared)); //(QGLContext *)NULL)); AHI->SetTopMargin(10); AHI->SetBottomMargin(AHI->GetBottomMargin()+gXAxis::Margin+25); //AHI->AddLayer(new gFooBar(7)); @@ -130,7 +129,7 @@ void Overview::RedrawGraphs() for (list::iterator g=Graphs.begin();g!=Graphs.end();g++) { (*g)->updateGL(); } - SESSTIMES->updateGL(); + //SESSTIMES->updateGL(); } void Overview::ReloadGraphs() { diff --git a/overview.h b/overview.h index 44cef1c5..008be949 100644 --- a/overview.h +++ b/overview.h @@ -23,10 +23,9 @@ class Overview : public QWidget Q_OBJECT public: - explicit Overview(QWidget *parent,QGLContext *context); + explicit Overview(QWidget *parent,QGLWidget *shared=NULL); ~Overview(); - void SetGLContext(QGLContext *context) { shared_context=context; }; void ReloadGraphs(); void UpdateGraphs(); @@ -43,7 +42,6 @@ private slots: private: Ui::Overview *ui; Profile *profile; - QGLContext *shared_context; void AddData(HistoryData *d) { Data.push_back(d); }; void AddGraph(gGraphWindow *w) { Graphs.push_back(w); }; diff --git a/oximetry.cpp b/oximetry.cpp index c080ae2b..790218a1 100644 --- a/oximetry.cpp +++ b/oximetry.cpp @@ -12,7 +12,7 @@ #include "Graphs/gYAxis.h" #include "Graphs/gFooBar.h" -Oximetry::Oximetry(QWidget *parent) : +Oximetry::Oximetry(QWidget *parent,QGLWidget * shared) : QWidget(parent), ui(new Ui::Oximetry) { @@ -32,7 +32,7 @@ Oximetry::Oximetry(QWidget *parent) : ui->graphLayout->addWidget(gSplitter); AddData(plethy=new WaveData(OXI_Plethy)); - AddGraph(PLETHY=new gGraphWindow(gSplitter,tr("Plethysomogram"),(QGLWidget *)NULL)); + AddGraph(PLETHY=new gGraphWindow(gSplitter,tr("Plethysomogram"),shared)); AddData(pulse=new EventData(OXI_Pulse)); AddGraph(PULSE=new gGraphWindow(gSplitter,tr("Pulse Rate"),PLETHY)); @@ -103,9 +103,9 @@ void Oximetry::on_RefreshPortsButton_clicked() if (!portname.isEmpty() && ports.at(i).qesPORTNAME==portname) current_found=true; ui->SerialPortsCombo->addItem(ports.at(i).qesPORTNAME); z++; + qDebug() << "Serial Port:" << ports.at(i).qesPORTNAME << ports.at(i).friendName; } //qDebug() << "port name:" << ports.at(i).portName; - qDebug() << "Serial Port:" << ports.at(i).qesPORTNAME << ports.at(i).friendName; //qDebug() << "enumerator name:" << ports.at(i).enumName; } if (z>0) { diff --git a/oximetry.h b/oximetry.h index fdd0907f..318ed025 100644 --- a/oximetry.h +++ b/oximetry.h @@ -2,6 +2,8 @@ #define OXIMETRY_H #include +#include + #include #include @@ -21,7 +23,7 @@ class Oximetry : public QWidget Q_OBJECT public: - explicit Oximetry(QWidget *parent = 0); + explicit Oximetry(QWidget *parent,QGLWidget * shared=NULL); ~Oximetry(); void AddData(gPointData *d) { Data.push_back(d); }