From 0faf09a151dd0f9d3066eac5cfdbb36a0044d61a Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Wed, 28 Dec 2011 22:03:48 +1000 Subject: [PATCH] Activate Hide sessions switches --- Graphs/gFlagsLine.cpp | 2 ++ Graphs/gLineChart.cpp | 4 +++- Graphs/gLineOverlay.cpp | 2 ++ Graphs/gSegmentChart.cpp | 4 ++++ Graphs/gSummaryChart.cpp | 7 +++++-- SleepLib/day.cpp | 38 ++++++++++++++++++++++++++++++++++++-- SleepLib/profiles.cpp | 2 ++ SleepLib/session.cpp | 21 +++++++++++++++++++++ SleepLib/session.h | 7 +++++++ daily.cpp | 29 ++++++++++++++++++++--------- 10 files changed, 102 insertions(+), 14 deletions(-) diff --git a/Graphs/gFlagsLine.cpp b/Graphs/gFlagsLine.cpp index b489d605..8e01af21 100644 --- a/Graphs/gFlagsLine.cpp +++ b/Graphs/gFlagsLine.cpp @@ -140,6 +140,8 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height) qint64 X,Y; m_flag_color=schema::channel[m_code].defaultColor(); for (QVector::iterator s=m_day->begin();s!=m_day->end(); s++) { + if (!(*s)->enabled()) continue; + if ((*s)->eventlist.find(m_code)==(*s)->eventlist.end()) continue; EventList & el=*((*s)->eventlist[m_code][0]); diff --git a/Graphs/gLineChart.cpp b/Graphs/gLineChart.cpp index a19945f7..28a71c7f 100644 --- a/Graphs/gLineChart.cpp +++ b/Graphs/gLineChart.cpp @@ -189,10 +189,12 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height) codepoints=0; for (int svi=0;svisize();svi++) { - if (!(*m_day)[svi]) { + Session *sess=(*m_day)[svi]; + if (!sess) { qWarning() << "gLineChart::Plot() NULL Session Record.. This should not happen"; continue; } + if (!sess->enabled()) continue; schema::Channel ch=schema::channel[code]; bool fndbetter=false; for (QList::iterator l=ch.m_links.begin();l!=ch.m_links.end();l++) { diff --git a/Graphs/gLineOverlay.cpp b/Graphs/gLineOverlay.cpp index 72d2eded..edc8e529 100644 --- a/Graphs/gLineOverlay.cpp +++ b/Graphs/gLineOverlay.cpp @@ -61,6 +61,7 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh } EventStoreType raw; for (QVector::iterator s=m_day->begin();s!=m_day->end(); s++) { + if (!(*s)->enabled()) continue; cei=(*s)->eventlist.find(m_code); if (cei==(*s)->eventlist.end()) continue; if (cei.value().size()==0) continue; @@ -166,6 +167,7 @@ void gLineOverlaySummary::paint(gGraph & w,int left, int top, int width, int hei // Calculate the session time. for (QVector::iterator s=m_day->begin();s!=m_day->end(); s++) { + if (!(*s)->enabled()) continue; first=(*s)->first(); last=(*s)->last(); if (last < w.min_x) continue; diff --git a/Graphs/gSegmentChart.cpp b/Graphs/gSegmentChart.cpp index 4a42ec8b..da84fa40 100644 --- a/Graphs/gSegmentChart.cpp +++ b/Graphs/gSegmentChart.cpp @@ -38,6 +38,8 @@ void gSegmentChart::SetDay(Day *d) for (int c=0;c::iterator s=m_day->begin();s!=m_day->end();s++) { + if (!(*s)->enabled()) continue; + int cnt=(*s)->count(m_codes[c]); m_values[c]+=cnt; m_total+=cnt; @@ -211,6 +213,8 @@ void gTAPGraph::SetDay(Day *d) //bool changed; EventDataType gain=1,offset=0; for (QVector::iterator s=m_day->begin();s!=m_day->end();s++) { + if (!(*s)->enabled()) continue; + if ((*s)->eventlist.find(m_code)==(*s)->eventlist.end()) continue; for (int q=0;q<(*s)->eventlist[m_code].size();q++) { EventList &el=*(*s)->eventlist[m_code][q]; diff --git a/Graphs/gSummaryChart.cpp b/Graphs/gSummaryChart.cpp index 06bfea8c..24a373a2 100644 --- a/Graphs/gSummaryChart.cpp +++ b/Graphs/gSummaryChart.cpp @@ -93,10 +93,13 @@ void SummaryChart::SetDay(Day * nullday) dz2*=86400; // ft = first sessions time, rounded back to midnight.. for (int s=0;ssize();s++) { - tmp=(*day)[s]->hours(); + Session *sess=(*day)[s]; + if (!sess->enabled()) continue; + + tmp=sess->hours(); m_values[dn][s]=tmp; total+=tmp; - zt=qint64((*day)[s]->first())/1000L; + zt=qint64(sess->first())/1000L; zt+=tz_offset; tmp2=zt-dn*86400; diff --git a/SleepLib/day.cpp b/SleepLib/day.cpp index 76a09b50..770f3b9e 100644 --- a/SleepLib/day.cpp +++ b/SleepLib/day.cpp @@ -54,6 +54,8 @@ EventDataType Day::settings_sum(ChannelID code) EventDataType val=0; QVector::iterator s; for (s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; + Session & sess=*(*s); QHash::iterator i=sess.settings.find(code); if (i!=sess.settings.end()) { @@ -69,6 +71,8 @@ EventDataType Day::settings_max(ChannelID code) QVector::iterator s; for (s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; + Session & sess=*(*s); QHash::iterator i=sess.settings.find(code); if (i!=sess.settings.end()) { @@ -86,6 +90,8 @@ EventDataType Day::settings_min(ChannelID code) QVector::iterator s; for (s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; + Session & sess=*(*s); QHash::iterator i=sess.settings.find(code); if (i!=sess.settings.end()) { @@ -108,6 +114,8 @@ EventDataType Day::settings_avg(ChannelID code) int cnt=0; QVector::iterator s; for (s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; + Session & sess=*(*s); QHash::iterator i=sess.settings.find(code); if (i!=sess.settings.end()) { @@ -122,6 +130,8 @@ EventDataType Day::settings_wavg(ChannelID code) { double s0=0,s1=0,s2=0,tmp; for (QVector::iterator s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; + Session & sess=*(*s); QHash::iterator i=sess.settings.find(code); @@ -148,6 +158,8 @@ EventDataType Day::percentile(ChannelID code,EventDataType percentile) // Don't assume sessions are in order. QVector ar; for (s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; + Session & sess=*(*s); QHash > ::iterator ei=sess.m_valuesummary.find(code); if (ei==sess.m_valuesummary.end()) continue; @@ -195,6 +207,8 @@ EventDataType Day::avg(ChannelID code) // Don't assume sessions are in order. for (s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; + Session & sess=*(*s); if (sess.m_avg.contains(code)) { val+=sess.avg(code); @@ -212,6 +226,8 @@ EventDataType Day::sum(ChannelID code) QVector::iterator s; for (s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; + Session & sess=*(*s); if (sess.m_sum.contains(code)) { val+=sess.sum(code); @@ -225,7 +241,10 @@ EventDataType Day::wavg(ChannelID code) double s0=0,s1=0,s2=0; qint64 d; for (QVector::iterator s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; + Session & sess=*(*s); + if (sess.m_wavg.contains(code)) { d=sess.length();//.last(code)-sess.first(code); s0=double(d)/3600000.0; @@ -245,6 +264,8 @@ qint64 Day::total_time() { qint64 d_totaltime=0; for (QVector::iterator s=begin();s!=end();s++) { + if (!(*s)->enabled()) continue; + Session & sess=*(*s); d_totaltime+=sess.length(); } @@ -273,6 +294,7 @@ qint64 Day::first(ChannelID code) qint64 tmp; for (QVector::iterator s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; tmp=(*s)->first(code); if (!tmp) continue; if (!date) { @@ -290,6 +312,7 @@ qint64 Day::last(ChannelID code) qint64 tmp; for (QVector::iterator s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; tmp=(*s)->last(code); if (!tmp) continue; if (!date) { @@ -306,9 +329,9 @@ EventDataType Day::Min(ChannelID code) EventDataType tmp; bool first=true; for (QVector::iterator s=sessions.begin();s!=sessions.end();s++) { - if (!(*s)->m_min.contains(code)) + + if ((!(*s)->m_min.contains(code)) || (!(*s)->enabled())) continue; - //if ((*s)->eventlist.find(code)==(*s)->eventlist.end()) continue; tmp=(*s)->Min(code); if (first) { min=tmp; @@ -324,6 +347,7 @@ bool Day::hasData(ChannelID code, SummaryType type) { bool has=false; for (QVector::iterator s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; Session *sess=*s; switch(type) { case ST_90P: @@ -377,6 +401,8 @@ EventDataType Day::Max(ChannelID code) EventDataType tmp; bool first=true; for (QVector::iterator s=sessions.begin();s!=sessions.end();s++) { + if (!(*s)->enabled()) continue; + if (!(*s)->m_max.contains(code)) continue; // if ((*s)->eventlist.find(code)==(*s)->eventlist.end()) continue; tmp=(*s)->Max(code); @@ -394,6 +420,7 @@ EventDataType Day::cph(ChannelID code) EventDataType sum=0; //EventDataType h=0; for (int i=0;ienabled()) continue; if (!sessions[i]->m_cph.contains(code)) continue; sum+=sessions[i]->cph(code)*sessions[i]->hours(); //h+=sessions[i]->hours(); @@ -407,6 +434,7 @@ EventDataType Day::sph(ChannelID code) EventDataType sum=0; EventDataType h=0; for (int i=0;ienabled()) continue; if (!sessions[i]->m_sum.contains(code)) continue; sum+=sessions[i]->sum(code)/3600.0;//*sessions[i]->hours(); //h+=sessions[i]->hours(); @@ -420,6 +448,7 @@ int Day::count(ChannelID code) { int sum=0; for (int i=0;ienabled()) continue; sum+=sessions[i]->count(code); } return sum; @@ -427,6 +456,7 @@ int Day::count(ChannelID code) bool Day::settingExists(ChannelID id) { for (int j=0;jenabled()) continue; QHash::iterator i=sessions[j]->settings.find(id); if (i!=sessions[j]->settings.end()) { return true; @@ -450,6 +480,8 @@ bool Day::channelExists(ChannelID id) { bool r=false; for (int i=0;ienabled()) continue; + if (sessions[i]->eventlist.contains(id)) { r=true; break; @@ -464,6 +496,8 @@ bool Day::channelHasData(ChannelID id) { bool r=false; for (int i=0;ienabled()) continue; + if (sessions[i]->channelExists(id)) { r=true; break; diff --git a/SleepLib/profiles.cpp b/SleepLib/profiles.cpp index 5650e3d1..34efbe79 100644 --- a/SleepLib/profiles.cpp +++ b/SleepLib/profiles.cpp @@ -758,6 +758,8 @@ EventDataType Profile::calcPercentile(ChannelID code, EventDataType percent, Mac if (day) { for (int i=0;isize();i++) { for (QVector::iterator s=day->begin();s!=day->end();s++) { + if (!(*s)->enabled()) continue; + Session *sess=*s; gain=sess->m_gain[code]; if (!gain) gain=1; diff --git a/SleepLib/session.cpp b/SleepLib/session.cpp index a1fccaa2..01d00f48 100644 --- a/SleepLib/session.cpp +++ b/SleepLib/session.cpp @@ -35,6 +35,7 @@ Session::Session(Machine * m,SessionID session) s_changed=false; s_events_loaded=false; _first_session=true; + s_enabled=-1; s_first=s_last=0; s_eventfile=""; @@ -649,6 +650,25 @@ bool Session::SearchEvent(ChannelID code, qint64 time, qint64 dist) return false; } +bool Session::enabled() +{ + if (s_enabled>=0) { + return s_enabled; + } + if (!settings.contains(SESSION_ENABLED)) { + settings[SESSION_ENABLED]=s_enabled=true; + return true; + } + s_enabled=settings[SESSION_ENABLED].toBool(); + return s_enabled; +} + +void Session::setEnabled(bool b) +{ + settings[SESSION_ENABLED]=s_enabled=b; + SetChanged(true); +} + EventDataType Session::Min(ChannelID id) { @@ -762,6 +782,7 @@ qint64 Session::last(ChannelID id) } bool Session::channelExists(ChannelID id) { + if (!enabled()) return false; if (s_events_loaded) { QHash >::iterator j=eventlist.find(id); if (j==eventlist.end()) // eventlist not loaded. diff --git a/SleepLib/session.h b/SleepLib/session.h index 02aeedb2..62b2b98d 100644 --- a/SleepLib/session.h +++ b/SleepLib/session.h @@ -64,6 +64,12 @@ public: return s_session; } + //! \brief Returns whether or not session is being used. + bool enabled(); + + //! \brief Sets whether or not session is being used. + void setEnabled(bool b); + //! \brief Return the start of this sessions time range (in milliseconds since epoch) qint64 first() { return s_first; @@ -245,6 +251,7 @@ protected: bool _first_session; bool s_events_loaded; + char s_enabled; QString s_eventfile; }; diff --git a/daily.cpp b/daily.cpp index ba3bdb66..e4bbc38e 100644 --- a/daily.cpp +++ b/daily.cpp @@ -350,20 +350,30 @@ void Daily::Link_clicked(const QUrl &url) QString data=url.toString().section("=",1); int sid=data.toInt(); Day *day=NULL; - if (code=="togglecpapsession") { + if (code=="togglecpapsession") { // Enable/Disable CPAP session day=PROFILE.GetDay(previous_date,MT_CPAP); Session *sess=day->find(sid); if (!sess) return; - bool b; - if (sess->settings.contains(SESSION_ENABLED)) b=false; - else b=!sess->settings[SESSION_ENABLED].toBool(); - sess->settings[SESSION_ENABLED]=b; - sess->SetChanged(true); - day->machine->Save(); - GraphView->ResetBounds(); + sess->setEnabled(!sess->enabled()); - // reload day + // Messy, this rewrites both summary & events.. TODO: Write just the session summary file + day->machine->Save(); + + // Reload day + this->LoadDate(previous_date); + return; + } else if (code=="toggleoxisession") { // Enable/Disable Oximetry session + day=PROFILE.GetDay(previous_date,MT_OXIMETER); + Session *sess=day->find(sid); + if (!sess) + return; + sess->setEnabled(!sess->enabled()); + // Messy, this rewrites both summary & events.. TODO: Write just the session summary file + day->machine->Save(); + + // Reload day + this->LoadDate(previous_date); return; } else if (code=="cpap") { day=PROFILE.GetDay(previous_date,MT_CPAP); @@ -438,6 +448,7 @@ void Daily::UpdateEventsTree(QTreeWidget *tree,Day *day) QHash mccnt; int total_events=0; for (QVector::iterator s=day->begin();s!=day->end();s++) { + if (!(*s)->enabled()) continue; QHash >::iterator m;