diff --git a/sleepyhead/Graphs/gFlagsLine.cpp b/sleepyhead/Graphs/gFlagsLine.cpp index 07be5ef4..6463f894 100644 --- a/sleepyhead/Graphs/gFlagsLine.cpp +++ b/sleepyhead/Graphs/gFlagsLine.cpp @@ -240,8 +240,6 @@ bool gFlagsGroup::mouseMoveEvent(QMouseEvent *event, gGraph *graph) } } - - return false; } @@ -424,5 +422,5 @@ bool gFlagsLine::mouseMoveEvent(QMouseEvent *event, gGraph *graph) Q_UNUSED(graph) // qDebug() << code() << event->x() << event->y() << graph->rect(); - return false; + return true; } diff --git a/sleepyhead/SleepLib/machine.cpp b/sleepyhead/SleepLib/machine.cpp index 2910f86a..7601f2b3 100644 --- a/sleepyhead/SleepLib/machine.cpp +++ b/sleepyhead/SleepLib/machine.cpp @@ -23,6 +23,7 @@ #include "profiles.h" #include #include "SleepLib/schema.h" +#include "SleepLib/day.h" extern QProgressBar *qprogress; @@ -389,7 +390,6 @@ const QString Machine::getBackupPath() return p_profile->Get("{" + STR_GEN_DataFolder + "}/" + info.loadername + "_" + (info.serial.isEmpty() ? hexid() : info.serial) + "/Backup/"); } - bool Machine::Load() { QString path = getDataPath(); @@ -670,6 +670,27 @@ bool Machine::Save() return true; } +QList Machine::availableChannels(schema::ChanType chantype) +{ + QHash chanhash; + + // look through the daylist and return a list of available channels for this machine + QMap::iterator dit; + QMap::iterator day_end = day.end(); + for (dit = day.begin(); dit != day_end; ++dit) { + QList::iterator sess_end = dit.value()->end(); + for (QList::iterator sit = dit.value()->begin(); sit != sess_end; ++sit) { + // sessions desperately need to cache this.. + ///sit.value + } + } + QList channels; + + return channels; +} + + + ////////////////////////////////////////////////////////////////////////////////////////// // CPAP implmementation ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/sleepyhead/SleepLib/machine.h b/sleepyhead/SleepLib/machine.h index 4203ad01..f1bf2433 100644 --- a/sleepyhead/SleepLib/machine.h +++ b/sleepyhead/SleepLib/machine.h @@ -29,7 +29,7 @@ #include "SleepLib/machine_common.h" #include "SleepLib/event.h" #include "SleepLib/session.h" - +#include "SleepLib/schema.h" #include "SleepLib/day.h" @@ -194,6 +194,8 @@ class Machine void setLoaderName(QString value); + QList availableChannels(schema::ChanType chantype); + MachineLoader * loader() { return m_loader; } // much more simpler multithreading... diff --git a/sleepyhead/SleepLib/schema.h b/sleepyhead/SleepLib/schema.h index ae9af97f..5c87a069 100644 --- a/sleepyhead/SleepLib/schema.h +++ b/sleepyhead/SleepLib/schema.h @@ -35,7 +35,14 @@ enum Function { }; enum ChanType { - DATA = 0, SETTING, FLAG, MINOR_FLAG, SPAN, WAVEFORM + DATA = 1, + SETTING = 2, + FLAG = 4, + MINOR_FLAG = 8, + SPAN = 16, + WAVEFORM = 32, + + ALL = 0xFFFF }; enum DataType { diff --git a/sleepyhead/SleepLib/session.cpp b/sleepyhead/SleepLib/session.cpp index 3af433a8..c334de91 100644 --- a/sleepyhead/SleepLib/session.cpp +++ b/sleepyhead/SleepLib/session.cpp @@ -29,7 +29,7 @@ const quint16 filetype_data = 1; // This is the uber important database version for SleepyHeads internal storage // Increment this after stuffing with Session's save & load code. -const quint16 summary_version = 14; +const quint16 summary_version = 15; const quint16 events_version = 10; Session::Session(Machine *m, SessionID session) @@ -199,11 +199,26 @@ bool Session::StoreSummary(QString filename) out << m_firstchan; out << m_lastchan; + // <- 8 out << m_valuesummary; out << m_timesummary; - out << m_gain; + // 8 -> + // <- 9 + out << m_gain; + // 9 -> + + // <- 15 + out << m_availableChannels; + out << m_timeAboveTheshold; + out << m_upperThreshold; + out << m_timeBelowTheshold; + out << m_lowerThreshold; + // 15 -> + + // <- 13 out << s_summaryOnly; + // 13 -> file.close(); return true; @@ -422,6 +437,15 @@ bool Session::LoadSummary(QString filename) } } + // screwed up with version 14 + if (version >= 15) { + in >> m_availableChannels; + in >> m_timeAboveTheshold; + in >> m_upperThreshold; + in >> m_timeBelowTheshold; + in >> m_lowerThreshold; + } // else this is ugly.. forced machine database upgrade will solve it though. + if (version == 13) { QHash::iterator it = settings.find(CPAP_SummaryOnly); if (it != settings.end()) { @@ -900,6 +924,7 @@ void Session::updateCountSummary(ChannelID code) void Session::UpdateSummaries() { + ChannelID id; calcAHIGraph(this); @@ -915,8 +940,11 @@ void Session::UpdateSummaries() QHash >::iterator c = eventlist.begin(); QHash >::iterator ev_end = eventlist.end(); + m_availableChannels.clear(); + for (; c != ev_end; c++) { id = c.key(); + m_availableChannels.push_back(id); schema::ChanType ctype = schema::channel[id].type(); if (ctype != schema::SETTING) { @@ -951,6 +979,7 @@ void Session::UpdateSummaries() wavg(id); } } + timeAboveThreshold(CPAP_Leak, p_profile->cpap->leakRedline()); } EventDataType Session::SearchValue(ChannelID code, qint64 time, bool square) @@ -1789,6 +1818,17 @@ EventDataType Session::sph(ChannelID id) // sum per hour, assuming id is a time EventDataType Session::timeAboveThreshold(ChannelID id, EventDataType threshold) { + QHash::iterator th = m_upperThreshold.find(id); + if (th != m_upperThreshold.end()) { + if (fabs(th.value()-threshold) < 0.00000001) { // close enough + th = m_timeAboveTheshold.find(id); + if (th != m_timeAboveTheshold.end()) { + return th.value(); + } + } + } + bool loaded = s_events_loaded; + this->OpenEvents(); QHash >::iterator j = eventlist.find(id); if (j == eventlist.end()) { @@ -1825,11 +1865,26 @@ EventDataType Session::timeAboveThreshold(ChannelID id, EventDataType threshold) total += ti-started; } EventDataType time = double(total) / 60000.0; + + m_timeAboveTheshold[id] = time; + m_upperThreshold[id] = threshold; + if (!loaded) this->TrashEvents(); // otherwise leave it open return time; } EventDataType Session::timeBelowThreshold(ChannelID id, EventDataType threshold) { + QHash::iterator th = m_lowerThreshold.find(id); + if (th != m_lowerThreshold.end()) { + if (fabs(th.value()-threshold) < 0.00000001) { // close enough + th = m_timeBelowTheshold.find(id); + if (th != m_timeBelowTheshold.end()) { + return th.value(); + } + } + } + bool loaded = s_events_loaded; + QHash >::iterator j = eventlist.find(id); if (j == eventlist.end()) { return 0.0f; @@ -1867,6 +1922,11 @@ EventDataType Session::timeBelowThreshold(ChannelID id, EventDataType threshold) } EventDataType time = double(total) / 60000.0; + + m_timeBelowTheshold[id] = time; + m_lowerThreshold[id] = threshold; + if (!loaded) this->TrashEvents(); // otherwise leave it open + return time; } diff --git a/sleepyhead/SleepLib/session.h b/sleepyhead/SleepLib/session.h index e1a830d8..8c2b05f7 100644 --- a/sleepyhead/SleepLib/session.h +++ b/sleepyhead/SleepLib/session.h @@ -168,6 +168,15 @@ class Session QHash > m_timesummary; QHash m_gain; + QHash m_lowerThreshold; + QHash m_timeBelowTheshold; + QHash m_upperThreshold; + QHash m_timeAboveTheshold; + + QList m_availableChannels; + + const QList & availableChannels() { return m_availableChannels; } + //! \brief Generates sum and time data for each distinct value in 'code' events.. void updateCountSummary(ChannelID code); diff --git a/sleepyhead/mainwindow.cpp b/sleepyhead/mainwindow.cpp index 6ac50094..ab96bfb7 100644 --- a/sleepyhead/mainwindow.cpp +++ b/sleepyhead/mainwindow.cpp @@ -877,10 +877,11 @@ void MainWindow::on_action_Import_Data_triggered() time.start(); QDialog popup(this, Qt::FramelessWindowHint); popup.setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); - QLabel waitmsg(tr("Please wait, scanning for CPAP data cards...")); - QVBoxLayout waitlayout(&popup); - waitlayout.addWidget(&waitmsg,1,Qt::AlignCenter); - waitlayout.addWidget(qprogress,1); + QLabel * waitmsg = new QLabel(tr("Please wait, scanning for CPAP data cards...")); + QVBoxLayout *waitlayout = new QVBoxLayout(); + waitlayout->addWidget(waitmsg,1,Qt::AlignCenter); + waitlayout->addWidget(qprogress,1); + popup.setLayout(waitlayout); bool asknew = false; qprogress->setVisible(false); @@ -912,13 +913,13 @@ void MainWindow::on_action_Import_Data_triggered() ui->statusbar->insertWidget(2,qprogress,1); return; } else if (res == QMessageBox::No) { - waitmsg.setText(tr("Please wait, launching file dialog...")); + waitmsg->setText(tr("Please wait, launching file dialog...")); datacards.clear(); asknew = true; } } else { - waitmsg.setText(tr("No CPAP data card detected, launching file dialog...")); + waitmsg->setText(tr("No CPAP data card detected, launching file dialog...")); asknew = true; }