From 8d7e6f785addeb60c69df8ca9e61c186ad877fe0 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Thu, 8 Dec 2011 14:10:35 +1000 Subject: [PATCH] Added Purge CPAP Day option in Data->Advanced. (Be careful, does not yet ask for confirmation) --- Graphs/gGraphView.cpp | 2 +- Graphs/gSummaryChart.cpp | 8 ++-- SleepLib/calcs.cpp | 10 ++--- SleepLib/loader_plugins/cms50_loader.cpp | 4 +- SleepLib/loader_plugins/intellipap_loader.cpp | 4 +- SleepLib/loader_plugins/prs1_loader.cpp | 4 +- SleepLib/loader_plugins/resmed_loader.cpp | 4 +- SleepLib/loader_plugins/zeo_loader.cpp | 4 +- SleepLib/machine.cpp | 4 +- SleepLib/machine_loader.cpp | 8 ++-- SleepLib/machine_loader.h | 4 +- SleepLib/profiles.cpp | 22 +++++----- SleepLib/profiles.h | 5 +-- daily.h | 1 - mainwindow.cpp | 41 ++++++++++++++++--- mainwindow.h | 2 + mainwindow.ui | 20 +++++++++ 17 files changed, 98 insertions(+), 49 deletions(-) diff --git a/Graphs/gGraphView.cpp b/Graphs/gGraphView.cpp index a16301a1..a6e890b0 100644 --- a/Graphs/gGraphView.cpp +++ b/Graphs/gGraphView.cpp @@ -1196,7 +1196,7 @@ void gGraph::mouseMoveEvent(QMouseEvent * event) if (a2>w) a2=w; m_selecting_area=true; m_selection=QRect(a1-m_marginleft-1,0,a2-a1,m_lastbounds.height()); - double w2=m_lastbounds.width();-(right+m_marginright)-(m_marginleft+left); + double w2=m_lastbounds.width(); //-(right+m_marginright)-(m_marginleft+left); if (m_blockzoom) { xmult=(rmax_x-rmin_x)/w2; } else xmult=(max_x-min_x)/w2; diff --git a/Graphs/gSummaryChart.cpp b/Graphs/gSummaryChart.cpp index cb1719d7..4007e93d 100644 --- a/Graphs/gSummaryChart.cpp +++ b/Graphs/gSummaryChart.cpp @@ -62,7 +62,7 @@ void SummaryChart::SetDay(Day * nullday) m_empty=true; int suboffset; SummaryType type; - for (QMap >::iterator d=PROFILE.daylist.begin();d!=PROFILE.daylist.end();d++) { + for (QMap >::iterator d=PROFILE.daylist.begin();d!=PROFILE.daylist.end();d++) { tt=QDateTime(d.key(),QTime(0,0,0),Qt::UTC).toTime_t(); dn=tt/86400; tt*=1000L; @@ -75,7 +75,7 @@ void SummaryChart::SetDay(Day * nullday) for (int i=0;imachine_type()!=m_machinetype) continue; int ft=qint64(day->first())/1000L; @@ -181,11 +181,11 @@ void SummaryChart::SetDay(Day * nullday) ChannelID code=m_codes[j]; if (type==ST_HOURS || type==ST_SESSIONS || m_zeros[j]) continue; - for (QMap >::iterator d=PROFILE.daylist.begin();d!=PROFILE.daylist.end();d++) { + for (QMap >::iterator d=PROFILE.daylist.begin();d!=PROFILE.daylist.end();d++) { tt=QDateTime(d.key(),QTime(0,0,0),Qt::UTC).toTime_t(); dn=tt/86400; for (int i=0;imachine_type()!=m_machinetype) continue; if (!m_values[dn].contains(j+1)) { m_days[dn]=day; diff --git a/SleepLib/calcs.cpp b/SleepLib/calcs.cpp index 027f099e..9469fcc4 100644 --- a/SleepLib/calcs.cpp +++ b/SleepLib/calcs.cpp @@ -88,7 +88,7 @@ int filterFlow(EventList *in, EventList *out, EventList *tv, EventList *mv, doub QVector breaths; QVector TV; QVector breaths_start; - int lasti=0; + //int lasti=0; for (i=0;i TV2; QVector TV2_start; - int fir=0,fir2=0; + int fir=0;//,fir2=0; EventDataType T,L; bool done=false; do { @@ -208,7 +208,7 @@ int filterFlow(EventList *in, EventList *out, EventList *tv, EventList *mv, doub t1+=window/2.0; t2+=window/2.0; - } while (t2last()); + } while (t2last() && !done); for (int i=2;ifirst(), - last=session->last(), - f; + //qint64 first=session->first(), last=session->last(), f; EventList *leak=new EventList(EVL_Event); session->eventlist[CPAP_Leak].push_back(leak); diff --git a/SleepLib/loader_plugins/cms50_loader.cpp b/SleepLib/loader_plugins/cms50_loader.cpp index e6d97552..39b20724 100644 --- a/SleepLib/loader_plugins/cms50_loader.cpp +++ b/SleepLib/loader_plugins/cms50_loader.cpp @@ -309,9 +309,9 @@ Machine *CMS50Loader::CreateMachine(Profile *profile) // NOTE: This only allows for one CMS50 machine per profile.. // Upgrading their oximeter will use this same record.. - QVector ml=profile->GetMachines(MT_OXIMETER); + QList ml=profile->GetMachines(MT_OXIMETER); - for (QVector::iterator i=ml.begin(); i!=ml.end(); i++) { + for (QList::iterator i=ml.begin(); i!=ml.end(); i++) { if ((*i)->GetClass()==cms50_class_name) { return (*i); break; diff --git a/SleepLib/loader_plugins/intellipap_loader.cpp b/SleepLib/loader_plugins/intellipap_loader.cpp index 3b57f531..d252aefd 100644 --- a/SleepLib/loader_plugins/intellipap_loader.cpp +++ b/SleepLib/loader_plugins/intellipap_loader.cpp @@ -351,9 +351,9 @@ Machine *IntellipapLoader::CreateMachine(QString serial,Profile *profile) return NULL; qDebug() << "Create Machine " << serial; - QVector ml=profile->GetMachines(MT_CPAP); + QList ml=profile->GetMachines(MT_CPAP); bool found=false; - QVector::iterator i; + QList::iterator i; for (i=ml.begin(); i!=ml.end(); i++) { if (((*i)->GetClass()==intellipap_class_name) && ((*i)->properties["Serial"]==serial)) { MachList[serial]=*i; //static_cast(*i); diff --git a/SleepLib/loader_plugins/prs1_loader.cpp b/SleepLib/loader_plugins/prs1_loader.cpp index e37da422..cc6ed8a7 100644 --- a/SleepLib/loader_plugins/prs1_loader.cpp +++ b/SleepLib/loader_plugins/prs1_loader.cpp @@ -120,9 +120,9 @@ Machine *PRS1Loader::CreateMachine(QString serial,Profile *profile) return NULL; qDebug() << "Create Machine " << serial; - QVector ml=profile->GetMachines(MT_CPAP); + QList ml=profile->GetMachines(MT_CPAP); bool found=false; - QVector::iterator i; + QList::iterator i; for (i=ml.begin(); i!=ml.end(); i++) { if (((*i)->GetClass()=="PRS1") && ((*i)->properties["Serial"]==serial)) { PRS1List[serial]=*i; //static_cast(*i); diff --git a/SleepLib/loader_plugins/resmed_loader.cpp b/SleepLib/loader_plugins/resmed_loader.cpp index f661b567..f4eb4a75 100644 --- a/SleepLib/loader_plugins/resmed_loader.cpp +++ b/SleepLib/loader_plugins/resmed_loader.cpp @@ -215,9 +215,9 @@ ResmedLoader::~ResmedLoader() Machine *ResmedLoader::CreateMachine(QString serial,Profile *profile) { if (!profile) return NULL; - QVector ml=profile->GetMachines(MT_CPAP); + QList ml=profile->GetMachines(MT_CPAP); bool found=false; - QVector::iterator i; + QList::iterator i; for (i=ml.begin(); i!=ml.end(); i++) { if (((*i)->GetClass()==resmed_class_name) && ((*i)->properties["Serial"]==serial)) { ResmedList[serial]=*i; //static_cast(*i); diff --git a/SleepLib/loader_plugins/zeo_loader.cpp b/SleepLib/loader_plugins/zeo_loader.cpp index 864923c0..12b7c98d 100644 --- a/SleepLib/loader_plugins/zeo_loader.cpp +++ b/SleepLib/loader_plugins/zeo_loader.cpp @@ -60,9 +60,9 @@ Machine *ZEOLoader::CreateMachine(Profile *profile) // NOTE: This only allows for one ZEO machine per profile.. // Upgrading their ZEO will use this same record.. - QVector ml=profile->GetMachines(MT_SLEEPSTAGE); + QList ml=profile->GetMachines(MT_SLEEPSTAGE); - for (QVector::iterator i=ml.begin(); i!=ml.end(); i++) { + for (QList::iterator i=ml.begin(); i!=ml.end(); i++) { if ((*i)->GetClass()==zeo_class_name) { return (*i); break; diff --git a/SleepLib/machine.cpp b/SleepLib/machine.cpp index ef660480..6a807d3c 100644 --- a/SleepLib/machine.cpp +++ b/SleepLib/machine.cpp @@ -173,8 +173,8 @@ Day *Machine::AddSession(Session *s,Profile *p) for (QVector::iterator i=nextday.value()->begin();i!=nextday.value()->end();i++) { dd->AddSession(*i); } - QMap >::iterator nd=p->daylist.find(date.addDays(1)); - for (QVector::iterator i=nd->begin();i!=nd->end();i++) { + QMap >::iterator nd=p->daylist.find(date.addDays(1)); + for (QList::iterator i=nd->begin();i!=nd->end();i++) { if (*i==nextday.value()) { nd.value().erase(i); } diff --git a/SleepLib/machine_loader.cpp b/SleepLib/machine_loader.cpp index 6216ea99..81a9bffe 100644 --- a/SleepLib/machine_loader.cpp +++ b/SleepLib/machine_loader.cpp @@ -10,9 +10,9 @@ #include "machine_loader.h" // This crap moves to Profile -QVector m_loaders; +QList m_loaders; -QVector GetLoaders() +QList GetLoaders() { return m_loaders; } @@ -23,7 +23,7 @@ void RegisterLoader(MachineLoader *loader) } void DestroyLoaders() { - for (QVector::iterator i=m_loaders.begin(); i!=m_loaders.end(); i++) { + for (QList::iterator i=m_loaders.begin(); i!=m_loaders.end(); i++) { delete (*i); } m_loaders.clear(); @@ -40,7 +40,7 @@ MachineLoader::MachineLoader() }*/ MachineLoader::~MachineLoader() { - for (QVector::iterator m=m_machlist.begin();m!=m_machlist.end();m++) { + for (QList::iterator m=m_machlist.begin();m!=m_machlist.end();m++) { delete *m; } } diff --git a/SleepLib/machine_loader.h b/SleepLib/machine_loader.h index fea0cb0e..3c1be0f3 100644 --- a/SleepLib/machine_loader.h +++ b/SleepLib/machine_loader.h @@ -47,7 +47,7 @@ public: virtual bool SaveWaveform(Machine * m, QString & filename);*/ protected: - QVector m_machlist; + QList m_machlist; QString m_class; MachineType m_type; Profile * m_profile; @@ -55,6 +55,6 @@ protected: void RegisterLoader(MachineLoader *loader); void DestroyLoaders(); -QVector GetLoaders(); +QList GetLoaders(); #endif //MACHINE_LOADER_H diff --git a/SleepLib/profiles.cpp b/SleepLib/profiles.cpp index 1044360e..1aadb968 100644 --- a/SleepLib/profiles.cpp +++ b/SleepLib/profiles.cpp @@ -204,8 +204,8 @@ void Profile::AddDay(QDate date,Day *day,MachineType mt) { if (m_last & dl=daylist[date]; - for (QVector::iterator a=dl.begin();a!=dl.end();a++) { + QList & dl=daylist[date]; + for (QList::iterator a=dl.begin();a!=dl.end();a++) { if ((*a)->machine->GetType()==mt) { throw OneTypePerDay(); } @@ -218,7 +218,7 @@ Day * Profile::GetDay(QDate date,MachineType type) Day *day=NULL; // profile-> why did I d that?? if (daylist.find(date)!=daylist.end()) { - for (QVector::iterator di=daylist[date].begin();di!=daylist[date].end();di++) { + for (QList::iterator di=daylist[date].begin();di!=daylist[date].end();di++) { if (type==MT_UNKNOWN) { // Who cares.. We just want to know there is data available. day=(*di); break; @@ -244,8 +244,8 @@ int Profile::Import(QString path) path=path.replace("\\","/"); if (path.endsWith("/")) path.chop(1); - QVectorloaders=GetLoaders(); - for (QVector::iterator i=loaders.begin(); i!=loaders.end(); i++) { + QListloaders=GetLoaders(); + for (QList::iterator i=loaders.begin(); i!=loaders.end(); i++) { if (c+=(*i)->Open(path,this)) break; } //qDebug() << "Import Done"; @@ -255,8 +255,8 @@ int Profile::Import(QString path) MachineLoader * GetLoader(QString name) { MachineLoader *l=NULL; - QVectorloaders=GetLoaders(); - for (QVector::iterator i=loaders.begin(); i!=loaders.end(); i++) { + QListloaders=GetLoaders(); + for (QList::iterator i=loaders.begin(); i!=loaders.end(); i++) { if ((*i)->ClassName()==name) { l=*i; break; @@ -266,10 +266,10 @@ MachineLoader * GetLoader(QString name) } -QVector Profile::GetMachines(MachineType t) +QList Profile::GetMachines(MachineType t) // Returns a QVector containing all machine objects regisered of type t { - QVector vec; + QList vec; QHash::iterator i; for (i=machlist.begin(); i!=machlist.end(); i++) { @@ -286,7 +286,7 @@ QVector Profile::GetMachines(MachineType t) Machine * Profile::GetMachine(MachineType t) { - QVectorvec=GetMachines(t); + QListvec=GetMachines(t); if (vec.size()==0) return NULL; return vec[0]; @@ -294,7 +294,7 @@ Machine * Profile::GetMachine(MachineType t) void Profile::RemoveSession(Session * sess) { - QMap >::iterator di; + QMap >::iterator di; for (di=daylist.begin();di!=daylist.end();di++) { for (int d=0;d -#include #include "machine.h" #include "machine_loader.h" #include "preferences.h" @@ -43,14 +42,14 @@ public: void AddDay(QDate date,Day *day,MachineType mt); Day * GetDay(QDate date,MachineType type=MT_UNKNOWN); - QVector GetMachines(MachineType t); + QList GetMachines(MachineType t); Machine * GetMachine(MachineType t,QDate date); Machine * GetMachine(MachineType t); virtual void ExtraLoad(QDomElement & root); virtual QDomElement ExtraSave(QDomDocument & doc); - QMap > daylist; + QMap > daylist; const QDate & FirstDay() { return m_first; } const QDate & LastDay() { return m_last; } diff --git a/daily.h b/daily.h index 95e36b3a..38439239 100644 --- a/daily.h +++ b/daily.h @@ -45,7 +45,6 @@ public: void RedrawGraphs(); void LoadDate(QDate date); QDate getDate() { return previous_date; } - void PrintReport(); void UnitsChanged(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 912cfefa..78746b5c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -860,9 +860,6 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date) first=false; } gGraph *g=(*gv)[i]; - if (g->title()=="Minute Vent.") { - int i=0; - } if (g->isEmpty()) continue; if (!g->visible()) continue; g->deselect(); @@ -907,14 +904,14 @@ void MainWindow::on_action_Rebuild_Oximetry_Index_triggered() QVector invalid; - QVector machines=PROFILE.GetMachines(MT_OXIMETER); + QList machines=PROFILE.GetMachines(MT_OXIMETER); bool ok; int discard_threshold=PROFILE["OxiDiscardThreshold"].toInt(&ok); if (!ok) discard_threshold=10; Machine *m; for (int z=0;zsessionlist.erase(m->sessionlist.find(0)); for (QHash::iterator s=m->sessionlist.begin();s!=m->sessionlist.end();s++) { Session *sess=s.value(); @@ -1009,3 +1006,37 @@ void MainWindow::on_actionChange_User_triggered() #endif } + +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; + QString path=PROFILE.Get("DataFolder")+QDir::separator()+m->hexid()+QDir::separator(); + + QVector::iterator s,km=day->end(); + + 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 & dl=PROFILE.daylist[date]; + QList::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(); +} diff --git a/mainwindow.h b/mainwindow.h index 4708826d..9daa195a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -118,6 +118,8 @@ private slots: void on_actionChange_User_triggered(); + void on_actionPurge_Current_Day_triggered(); + private: Ui::MainWindow *ui; diff --git a/mainwindow.ui b/mainwindow.ui index 174ab1ff..e136e388 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -615,7 +615,22 @@ &Data + + + &Advanced + + + + &Purge CPAP Data + + + + + + + + @@ -779,6 +794,11 @@ Change &User + + + &Current Selected Day + +