diff --git a/sleepyhead/Graphs/MinutesAtPressure.cpp b/sleepyhead/Graphs/MinutesAtPressure.cpp index 2b25942f..ed78a5b8 100644 --- a/sleepyhead/Graphs/MinutesAtPressure.cpp +++ b/sleepyhead/Graphs/MinutesAtPressure.cpp @@ -50,19 +50,12 @@ void MinutesAtPressure::SetDay(Day *day) Machine * cpap = nullptr; if (day) cpap = day->machine(MT_CPAP); if (cpap) { - QList::iterator sit; EventDataType minpressure = 20; EventDataType maxpressure = 0; - QMap::iterator it; - QMap::iterator day_end = cpap->day.end(); // look at overall pressure ranges and find the max - - for (it = cpap->day.begin(); it != day_end; ++it) { - Day * d = it.value(); - QList::iterator sess_end = d->end(); - for (sit = d->begin(); sit != sess_end; ++sit) { - Session * sess = (*sit); + for (const auto d : cpap->day) { + for (const auto sess : d->sessions) { if (sess->channelExists(CPAP_Pressure)) { minpressure = qMin(sess->Min(CPAP_Pressure), minpressure); maxpressure = qMax(sess->Max(CPAP_Pressure), maxpressure); @@ -157,7 +150,6 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r m_lastminx = m_minx; m_lastmaxx = m_maxx; - QMap::iterator it; if (graph.printing()) { // Could just lock the mutex QMutex instead mutex.lock(); @@ -245,8 +237,8 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r //////////////////////////////////////////////////////////////////// double pstep = xstep * pressureMult; - xp = left;// /2.0; - for (int i = 0; i<=max-min; ++i) { + xp = left; + for (int i=0, end=max-min; i<=end; ++i) { yp = bottom+1; painter.drawLine(xp, yp, xp, yp+6); if (i>0) { // skip the first mid tick @@ -335,11 +327,12 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r double lastyp = bottom - (s2 * ystep); int tmax = qMin(ipap.times.size(), max); + const auto & ipaptimes = ipap.times; for (int i=qMax(min,1); i0) { double evpeak = ipap.peakevents; double bot = bottom+1; @@ -403,7 +393,6 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r evpeak = ceil(evpeak/g)*g; r = double(height+3) / (evpeak / g); - yp = bot; widest_YAxis+=2; for (double f=0.0; f<=evpeak; f+=g) { @@ -421,8 +410,7 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r } estep = double(height) / ipap.peakevents; - for (int k=0; k qMax(min,0)) { - s2 = double(epap.times[qMax(min,0)]/60.0); + const auto & epaptimes = epap.times; + if ( epaptimes.size() > qMax(min,0)) { + s2 = double(epaptimes[qMax(min,0)]/60.0); } else { s2 = 0; } xp=left, lastyp = bottom - (s2 * ystep); - int tmax = qMin(epap.times.size(), max); + int tmax = qMin(epaptimes.size(), max); for (int i=qMax(min,1); i::iterator times_end = times.end(); + /*auto times_end = times.end(); QPoint mouse = graph.graphView()->currentMousePos(); float ypos = top; @@ -637,9 +628,9 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r ypos += hix * 2; // left = rect.left(); - QHash >::iterator eit; - //QHash >::iterator ev_end = events.end(); - QMap::iterator vit; + auto eit; + //auto ev_end = events.end(); + auto vit; int row = 0; @@ -654,7 +645,7 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r xpos = left; - QMap::iterator eit_end = eit.value().end(); + auto eit_end = eit.value().end(); QString text = chan.label(); rec = QRectF(titleWidth, ypos, marginWidth, hix); @@ -796,7 +787,7 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r if (type == schema::SPAN) continue; eit = events.find(code); - QMap::iterator eit_end = eit.value().end(); + auto eit_end = eit.value().end(); for (it = times.begin(), vit = eit.value().begin(); vit != eit_end; ++vit, ++it) { //float minutes = float(it.value()) / 60.0; float value = vit.value(); @@ -823,7 +814,7 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r xpos = left;//+pix/2; y1 = 0; - QMap::iterator eit_end = eit.value().end(); + auto eit_end = eit.value().end(); for (it = times.begin(), vit = eit.value().begin(); vit != eit_end; ++vit, ++it) { //float minutes = float(it.value()) / 60.0; float value = vit.value(); @@ -879,19 +870,16 @@ void RecalcMAP::updateTimes(PressureInfo & info, Session * sess) if (code == 0) return; // Find pressure channel - QHash >::iterator ei = sess->eventlist.find(code); + auto ei = sess->eventlist.find(code); // Done already if no channel if (ei == sess->eventlist.end()) return; - const QVector & evec = ei.value(); - int esize = evec.size(); - pressureMult = (sess->machine()->loaderName() == "PRS1") ? 2 : 5; // Loop through event lists - for (int ei = 0; ei < esize; ++ei) { - const EventList *EL = evec.at(ei); + + for (const auto & EL : ei.value()) { gain = EL->gain(); // Don't bother with short sessions @@ -939,10 +927,8 @@ void RecalcMAP::updateTimes(PressureInfo & info, Session * sess) key = lastdata; info.times[key] += duration; - int cs = info.chans.size(); - for (int c = 0; c < cs; ++c) { - ChannelID cod = info.chans.at(c); + for (const auto & cod : info.chans) { schema::Channel & chan = schema::channel[cod]; if (chan.type() == schema::SPAN) { info.events[cod][key] += val = sess->rangeSum(cod, d1, d2); @@ -966,10 +952,8 @@ void RecalcMAP::updateTimes(PressureInfo & info, Session * sess) duration = (d2 - d1) / 1000L; key = lastdata; info.times[key] += duration; - int cs = info.chans.size(); - for (int c = 0; c < cs; ++c) { - ChannelID cod = info.chans.at(c); + for (const auto & cod : info.chans) { schema::Channel & chan = schema::channel[cod]; if (chan.type() == schema::SPAN) { info.events[cod][key] += sess->rangeSum(cod, d1, d2); @@ -977,9 +961,7 @@ void RecalcMAP::updateTimes(PressureInfo & info, Session * sess) info.events[cod][key] += sess->rangeCount(cod, d1, d2); } } - } - } } @@ -991,7 +973,7 @@ void PressureInfo::finishCalcs() int val; - for (int i=0; i >::iterator OB = events.find(CPAP_Obstructive); - QHash >::iterator HY = events.find(CPAP_Hypopnea); - QHash >::iterator A = events.find(CPAP_Apnea); - QHash >::iterator CA = events.find(CPAP_ClearAirway); - + auto OB = events.find(CPAP_Obstructive); + auto HY = events.find(CPAP_Hypopnea); + auto A = events.find(CPAP_Apnea); + auto CA = events.find(CPAP_ClearAirway); for (int i = 0; i < size; i++) { @@ -1034,9 +1014,7 @@ void PressureInfo::finishCalcs() } */ for (int i = 0; i < size; i++) { - - for (int j=0 ; j < chans.size(); ++j) { - cod = chans.at(j); + for (const auto & cod : chans) { if ((cod == CPAP_AHI) || (schema::channel[cod].type() == schema::SPAN)) continue; val = events[cod][i]; peakevents = qMax(val, peakevents); @@ -1052,14 +1030,6 @@ void RecalcMAP::run() Day * day = map->m_day; if (!day) return; - QList::iterator sit; - QList::iterator sess_end = day->end(); - - - QMap times; - - QHash > events; - // Get the channels for specified Channel types QList chans = day->getSortedMachineChannels(schema::FLAG); @@ -1109,8 +1079,7 @@ void RecalcMAP::run() - for (sit = day->begin(); sit != sess_end; ++sit) { - Session * sess = (*sit); + for (const auto & sess : day->sessions) { updateTimes(EPAP, sess); updateTimes(IPAP, sess); @@ -1121,11 +1090,11 @@ void RecalcMAP::run() } -/* QHash >::iterator ei = sess->eventlist.find(ipapcode); +/* auto ei = sess->eventlist.find(ipapcode); if (ei == sess->eventlist.end()) continue; - const QVector & evec = ei.value(); + const auto & evec = ei.value(); int esize = evec.size(); for (int ei = 0; ei < esize; ++ei) { const EventList *EL = evec.at(ei); @@ -1218,12 +1187,11 @@ skip: EPAP.finishCalcs(); IPAP.finishCalcs(); -/* QMap::iterator it; - QMap::iterator times_end = times.end(); +/* int maxtime = 0; QList trash; - for (it = times.begin(); it != times_end; ++it) { + for (auto it=times.begin(), end=times.end(); it != end; ++it) { //EventStoreType key = it.key(); int value = it.value(); // if (value == 0) { @@ -1254,13 +1222,12 @@ skip: maxevents = qMax(val, maxevents); } } - QHash >::iterator eit; // for (int i=0; i< trash.size(); ++i) { // EventStoreType key = trash.at(i); // times.remove(key); -// for (eit = events.begin(); eit != events.end(); ++eit) { +// for (auto eit=events.begin(), end=events.end(); eit != end; ++eit) { // eit.value().remove(key); // } // } diff --git a/sleepyhead/Graphs/gFlagsLine.cpp b/sleepyhead/Graphs/gFlagsLine.cpp index f008c27c..0950ffa1 100644 --- a/sleepyhead/Graphs/gFlagsLine.cpp +++ b/sleepyhead/Graphs/gFlagsLine.cpp @@ -1,4 +1,4 @@ -/* gFlagsLine Implementation +/* gFlagsLine Implementation * * Copyright (c) 2011-2018 Mark Watkins * @@ -79,10 +79,8 @@ void gFlagsGroup::SetDay(Day *d) if (m_rebuild_cpap) { QHash chans; - for (int i=0; i< m_day->size(); ++i) { - Session * sess = m_day->sessions.at(i); - QHash >::iterator it; - for (it = sess->eventlist.begin(); it != sess->eventlist.end(); ++it) { + for (const auto & sess : m_day->sessions) { + for (auto it=sess->eventlist.begin(), end=sess->eventlist.end(); it != end; ++it) { ChannelID code = it.key(); if (chans.contains(code)) continue; @@ -103,10 +101,8 @@ void gFlagsGroup::SetDay(Day *d) } lvisible.clear(); - for (int i=0; i < availableChans.size(); ++i) { - ChannelID code = availableChans.at(i); + for (const auto code : availableChans) { // const schema::Channel & chan = schema::channel[code]; - gFlagsLine * fl = new gFlagsLine(code); fl->SetDay(d); lvisible.push_back(fl); @@ -164,9 +160,9 @@ void gFlagsGroup::paint(QPainter &painter, gGraph &g, const QRegion ®ion) QVector visflags; - for (int i = 0; i < lvisible.size(); i++) { - if (schema::channel[lvisible.at(i)->code()].enabled()) - visflags.push_back(lvisible.at(i)); + for (const auto & flagsline : lvisible) { + if (schema::channel[flagsline->code()].enabled()) + visflags.push_back(flagsline); } int vis = visflags.size(); @@ -175,7 +171,7 @@ void gFlagsGroup::paint(QPainter &painter, gGraph &g, const QRegion ®ion) QColor barcol; - for (int i = 0; i < visflags.size(); i++) { + for (int i=0, end=visflags.size(); i < end; i++) { //schema::Channel & chan = schema::channel[visflags.at(i)->code()]; // Alternating box color @@ -221,15 +217,15 @@ bool gFlagsGroup::mouseMoveEvent(QMouseEvent *event, gGraph *graph) return false; } - for (int i = 0; i < lvisible.size(); i++) { - gFlagsLine *fl = lvisible[i]; + for (int i=0, end=lvisible.size(); i < end; i++) { + gFlagsLine *fl = lvisible.at(i); if (fl->m_rect.contains(event->x(), event->y())) { if (fl->mouseMoveEvent(event, graph)) { return true; } } else { // Inside main graph area? if ((event->y() > fl->m_rect.y()) && (event->y()) < (fl->m_rect.y() + fl->m_rect.height())) { - if (event->x() < lvisible[i]->m_rect.x()) { + if (event->x() < fl->m_rect.x()) { // Display tooltip QString ttip = schema::channel[fl->code()].fullname() + "\n" + schema::channel[fl->code()].description(); @@ -309,27 +305,26 @@ void gFlagsLine::paint(QPainter &painter, gGraph &w, const QRegion ®ion) int tooltipTimeout = AppSetting->tooltipTimeout(); bool hover = false; - for (QList::iterator s = m_day->begin(); s != m_day->end(); s++) { - if (!(*s)->enabled()) { + for (const auto & sess : m_day->sessions) { + if (!sess->enabled()) { continue; } - drift = ((*s)->type() == MT_CPAP) ? clockdrift : 0; + drift = (sess->type() == MT_CPAP) ? clockdrift : 0; - cei = (*s)->eventlist.find(m_code); + cei = sess->eventlist.find(m_code); - if (cei == (*s)->eventlist.end()) { + if (cei == sess->eventlist.end()) { continue; } - QVector &evlist = cei.value(); - for (int k = 0; k < evlist.size(); k++) { - EventList &el = *(evlist[k]); - start = el.first() + drift; - tptr = el.rawTime(); - dptr = el.rawData(); - int np = el.count(); + for (const auto & el : cei.value()) { + + start = el->first() + drift; + tptr = el->rawTime(); + dptr = el->rawData(); + int np = el->count(); eptr = dptr + np; for (idx = 0; dptr < eptr; dptr++, tptr++, idx++) { diff --git a/sleepyhead/Graphs/gGraph.cpp b/sleepyhead/Graphs/gGraph.cpp index e6d32cdf..1591a30d 100644 --- a/sleepyhead/Graphs/gGraph.cpp +++ b/sleepyhead/Graphs/gGraph.cpp @@ -1,4 +1,4 @@ -/* gGraph Implemntation +/* gGraph Implemntation * * Copyright (c) 2011-2018 Mark Watkins * @@ -116,8 +116,8 @@ void DestroyGraphGlobals() delete bigfont; delete mediumfont; - for (QHash::iterator i = images.begin(); i != images.end(); i++) { - delete i.value(); + for (auto & image : images) { + delete image; } globalsInitialized = false; @@ -187,9 +187,9 @@ gGraph::gGraph(QString name, gGraphView *graphview, QString title, QString units } gGraph::~gGraph() { - for (int i = 0; i < m_layers.size(); i++) { - if (m_layers[i]->unref()) { - delete m_layers[i]; + for (auto & layer : m_layers) { + if (layer->unref()) { + delete layer; } } @@ -216,16 +216,16 @@ void gGraph::Timeout() void gGraph::deselect() { - for (QVector::iterator l = m_layers.begin(); l != m_layers.end(); l++) { - (*l)->deselect(); + for (auto & layer : m_layers) { + layer->deselect(); } } bool gGraph::isSelected() { bool res = false; - for (QVector::iterator l = m_layers.begin(); l != m_layers.end(); l++) { - res = (*l)->isSelected(); + for (const auto & layer : m_layers) { + res = layer->isSelected(); if (res) { break; } } @@ -237,14 +237,13 @@ bool gGraph::isEmpty() { bool empty = true; - for (QVector::iterator l = m_layers.begin(); l != m_layers.end(); l++) { - if (!(*l)->isEmpty()) { + for (const auto & layer : m_layers) { + if (!layer->isEmpty()) { empty = false; break; } } - return empty; } @@ -272,8 +271,8 @@ void gGraph::setDay(Day *day) m_day = day; - for (int i = 0; i < m_layers.size(); i++) { - m_layers[i]->SetDay(day); + for (auto & layer : m_layers) { + layer->SetDay(day); } rmin_y = rmax_y = 0; @@ -369,31 +368,27 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion) // left = 0; - for (int i = 0; i < m_layers.size(); i++) { - Layer *ll = m_layers[i]; + for (const auto & layer : m_layers) { + if (!layer->visible()) { continue; } - if (!ll->visible()) { continue; } + tmp = layer->minimumHeight();// * m_graphview->printScaleY(); - tmp = ll->minimumHeight();// * m_graphview->printScaleY(); - - if (ll->position() == LayerTop) { top += tmp; } - if (ll->position() == LayerBottom) { bottom += tmp * printScaleY(); } + if (layer->position() == LayerTop) { top += tmp; } + if (layer->position() == LayerBottom) { bottom += tmp * printScaleY(); } } - for (int i = 0; i < m_layers.size(); i++) { - Layer *ll = m_layers[i]; + for (const auto & layer : m_layers) { + if (!layer->visible()) { continue; } - if (!ll->visible()) { continue; } - - tmp = ll->minimumWidth(); + tmp = layer->minimumWidth(); tmp *= m_graphview->printScaleX(); tmp *= m_graphview->devicePixelRatio(); - if (ll->position() == LayerLeft) { + if (layer->position() == LayerLeft) { QRect rect(originX + left, originY + top, tmp, height - top - bottom); - ll->m_rect = rect; - // ll->paint(painter, *this, QRegion(rect)); + layer->m_rect = rect; + // layer->paint(painter, *this, QRegion(rect)); left += tmp; #ifdef DEBUG_LAYOUT QColor col = Qt::red; @@ -402,11 +397,11 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion) #endif } - if (ll->position() == LayerRight) { + if (layer->position() == LayerRight) { right += tmp; QRect rect(originX + width - right, originY + top, tmp, height - top - bottom); - ll->m_rect = rect; - //ll->paint(painter, *this, QRegion(rect)); + layer->m_rect = rect; + //layer->paint(painter, *this, QRegion(rect)); #ifdef DEBUG_LAYOUT QColor col = Qt::red; painter.setPen(col); @@ -418,25 +413,23 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion) bottom = marginBottom() * printScaleY(); top = marginTop(); - for (int i = 0; i < m_layers.size(); i++) { - Layer *ll = m_layers[i]; + for (const auto & layer : m_layers) { + if (!layer->visible()) { continue; } - if (!ll->visible()) { continue; } + tmp = layer->minimumHeight(); - tmp = ll->minimumHeight(); - - if (ll->position() == LayerTop) { + if (layer->position() == LayerTop) { QRect rect(originX + left, originY + top, width - left - right, tmp); - ll->m_rect = rect; - ll->paint(painter, *this, QRegion(rect)); + layer->m_rect = rect; + layer->paint(painter, *this, QRegion(rect)); top += tmp; } - if (ll->position() == LayerBottom) { + if (layer->position() == LayerBottom) { bottom += tmp * printScaleY(); QRect rect(originX + left, originY + height - bottom, width - left - right, tmp); - ll->m_rect = rect; - ll->paint(painter, *this, QRegion(rect)); + layer->m_rect = rect; + layer->paint(painter, *this, QRegion(rect)); } } @@ -445,25 +438,21 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion) painter.fillRect(originX + left, originY + top, width - right, height - bottom - top, QBrush(QColor(Qt::white))); } - for (int i = 0; i < m_layers.size(); i++) { - Layer *ll = m_layers[i]; + for (const auto & layer : m_layers) { + if (!layer->visible()) { continue; } - if (!ll->visible()) { continue; } - - if (ll->position() == LayerCenter) { + if (layer->position() == LayerCenter) { QRect rect(originX + left, originY + top, width - left - right, height - top - bottom); - ll->m_rect = rect; - ll->paint(painter, *this, QRegion(rect)); + layer->m_rect = rect; + layer->paint(painter, *this, QRegion(rect)); } } // Draw anything like the YAxis labels afterwards, in case the graph scale was updated during draw - for (int i = 0; i < m_layers.size(); i++) { - Layer *ll = m_layers[i]; - - if (!ll->visible()) { continue; } - if ((ll->position() == LayerLeft) || (ll->position() == LayerRight)) { - ll->paint(painter, *this, QRegion(ll->m_rect)); + for (const auto & layer : m_layers) { + if (!layer->visible()) { continue; } + if ((layer->position() == LayerLeft) || (layer->position() == LayerRight)) { + layer->paint(painter, *this, QRegion(layer->m_rect)); } } @@ -697,9 +686,8 @@ void gGraph::AddLayer(Layer *l, LayerPosition position, short width, short heigh void gGraph::dataChanged() { - int size = m_layers.size(); - for (int i=0; i < size; i++) { - m_layers[i]->dataChanged(); + for (auto & layer : m_layers) { + layer->dataChanged(); } } @@ -739,11 +727,10 @@ void gGraph::mouseMoveEvent(QMouseEvent *event) timedRedraw(0); - for (int i = 0; i < m_layers.size(); i++) { - if (m_layers[i]->m_rect.contains(x, y)) - if (m_layers[i]->mouseMoveEvent(event, this)) { + for (const auto & layer : m_layers) { + if (layer->m_rect.contains(x, y)) + if (layer->mouseMoveEvent(event, this)) { return; -// doredraw = true; } } @@ -754,7 +741,6 @@ void gGraph::mouseMoveEvent(QMouseEvent *event) int w = m_rect.width() - left - right; - double xx; //= max_x - min_x; double xmult;// = xx / double(w); @@ -888,9 +874,9 @@ void gGraph::mousePressEvent(QMouseEvent *event) int y = event->pos().y(); int x = event->pos().x(); - for (int i = 0; i < m_layers.size(); i++) { - if (m_layers[i]->m_rect.contains(x, y)) - if (m_layers[i]->mousePressEvent(event, this)) { + for (const auto & layer : m_layers) { + if (layer->m_rect.contains(x, y)) + if (layer->mousePressEvent(event, this)) { return; } } @@ -914,9 +900,9 @@ void gGraph::mouseReleaseEvent(QMouseEvent *event) int y = event->pos().y(); int x = event->pos().x(); - for (int i = 0; i < m_layers.size(); i++) { - if (m_layers[i]->m_rect.contains(x, y)) - if (m_layers[i]->mouseReleaseEvent(event, this)) { + for (const auto & layer : m_layers) { + if (layer->m_rect.contains(x, y)) + if (layer->mouseReleaseEvent(event, this)) { return; } } @@ -924,14 +910,12 @@ void gGraph::mouseReleaseEvent(QMouseEvent *event) x -= m_rect.left(); y -= m_rect.top(); - int w = m_rect.width() - left - right; //(m_marginleft+left+right+m_marginright); int h = m_rect.height() - bottom; //+m_marginbottom); int x2 = m_graphview->pointClicked().x() - m_rect.left(); //int y2 = m_graphview->pointClicked().y() - m_rect.top(); - m_selDurString = QString(); //qDebug() << m_title << "Released" << min_x << max_x << x << y << x2 << y2 << left << right << top << bottom << m_width << m_height; @@ -1091,9 +1075,9 @@ void gGraph::wheelEvent(QWheelEvent *event) int y = event->pos().y(); x = event->pos().x(); - for (int i = 0; i < m_layers.size(); i++) { - if (m_layers[i]->m_rect.contains(x, y)) { - m_layers[i]->wheelEvent(event, this); + for (const auto & layer : m_layers) { + if (layer->m_rect.contains(x, y)) { + layer->wheelEvent(event, this); } } @@ -1105,9 +1089,9 @@ void gGraph::mouseDoubleClickEvent(QMouseEvent *event) int y = event->pos().y(); int x = event->pos().x(); - for (int i = 0; i < m_layers.size(); i++) { - if (m_layers[i]->m_rect.contains(x, y)) { - m_layers[i]->mouseDoubleClickEvent(event, this); + for (const auto & layer : m_layers) { + if (layer->m_rect.contains(x, y)) { + layer->mouseDoubleClickEvent(event, this); } } @@ -1131,8 +1115,8 @@ void gGraph::mouseDoubleClickEvent(QMouseEvent *event) } void gGraph::keyPressEvent(QKeyEvent *event) { - for (QVector::iterator i = m_layers.begin(); i != m_layers.end(); i++) { - (*i)->keyPressEvent(event, this); + for (const auto & layer : m_layers) { + layer->keyPressEvent(event, this); } //qDebug() << m_title << "Key Pressed.. implement me" << event->key(); @@ -1225,12 +1209,12 @@ qint64 gGraph::MinX() { qint64 val = 0, tmp; - for (QVector::iterator l = m_layers.begin(); l != m_layers.end(); l++) { - if ((*l)->isEmpty()) { + for (const auto & layer : m_layers) { + if (layer->isEmpty()) { continue; } - tmp = (*l)->Minx(); + tmp = layer->Minx(); if (!tmp) { continue; @@ -1250,15 +1234,15 @@ qint64 gGraph::MaxX() //bool first=true; qint64 val = 0, tmp; - for (QVector::iterator l = m_layers.begin(); l != m_layers.end(); l++) { - if ((*l)->isEmpty()) { + for (const auto & layer : m_layers) { + if (layer->isEmpty()) { continue; } - tmp = (*l)->Maxx(); + tmp = layer->Maxx(); //if (!tmp) continue; - if (!val || tmp > val) { + if (!val || (tmp > val)) { val = tmp; } } @@ -1277,12 +1261,12 @@ EventDataType gGraph::MinY() return rmin_y = f_miny; } - for (QVector::iterator l = m_layers.begin(); l != m_layers.end(); l++) { - if ((*l)->isEmpty() || ((*l)->layerType() == LT_Other)) { + for (const auto & layer : m_layers) { + if (layer->isEmpty() || (layer->layerType() == LT_Other)) { continue; } - tmp = (*l)->Miny(); + tmp = layer->Miny(); // if (tmp == 0 && tmp == (*l)->Maxy()) { // continue; @@ -1309,9 +1293,7 @@ EventDataType gGraph::MaxY() return rmax_y = f_maxy; } - QVector::const_iterator iterEnd = m_layers.constEnd(); - for (QVector::const_iterator iter = m_layers.constBegin(); iter != iterEnd; ++iter) { - Layer *layer = *iter; + for (const auto & layer : m_layers) { if (layer->isEmpty() || (layer->layerType() == LT_Other)) { continue; } @@ -1341,9 +1323,7 @@ EventDataType gGraph::physMinY() //if (m_enforceMinY) return rmin_y=f_miny; - QVector::const_iterator iterEnd = m_layers.constEnd(); - for (QVector::const_iterator iter = m_layers.constBegin(); iter != iterEnd; ++iter) { - Layer *layer = *iter; + for (const auto & layer : m_layers) { if (layer->isEmpty()) { continue; } @@ -1372,9 +1352,7 @@ EventDataType gGraph::physMaxY() // if (m_enforceMaxY) return rmax_y=f_maxy; - QVector::const_iterator iterEnd = m_layers.constEnd(); - for (QVector::const_iterator iter = m_layers.constBegin(); iter != iterEnd; ++iter) { - Layer *layer = *iter; + for (const auto & layer : m_layers) { if (layer->isEmpty()) { continue; } @@ -1421,8 +1399,8 @@ Layer *gGraph::getLineChart() { gLineChart *lc; - for (int i = 0; i < m_layers.size(); i++) { - lc = dynamic_cast(m_layers[i]); + for (auto & layer : m_layers) { + lc = dynamic_cast(layer); if (lc) { return lc; } } @@ -1436,8 +1414,8 @@ int gGraph::minHeight() // int top = 0; // int center = 0; // int bottom = 0; - for (int i=0; iminimumHeight(); + for (const auto & layer : m_layers) { + int mh = layer->minimumHeight(); mh += m_margintop + m_marginbottom; if (mh > minheight) minheight = mh; } @@ -1452,13 +1430,11 @@ int GetXHeight(QFont *font) } void gGraph::dumpInfo() { - for (int i = 0; i < m_layers.size(); i++) { - Layer *ll = m_layers[i]; + for (const auto & layer : m_layers) { + if (!layer->visible()) { continue; } - if (!ll->visible()) { continue; } - - if (ll->position() == LayerCenter) { - gLineChart *lc = dynamic_cast(ll); + if (layer->position() == LayerCenter) { + gLineChart *lc = dynamic_cast(layer); if (lc != nullptr) { QString text = lc->getMetaString(currentTime()); if (!text.isEmpty()) { diff --git a/sleepyhead/Graphs/gGraphView.cpp b/sleepyhead/Graphs/gGraphView.cpp index b783f21e..bfd5a62e 100644 --- a/sleepyhead/Graphs/gGraphView.cpp +++ b/sleepyhead/Graphs/gGraphView.cpp @@ -266,8 +266,8 @@ void gGraphView::queGraph(gGraph *g, int left, int top, int width, int height) void gGraphView::trashGraphs(bool destroy) { if (destroy) { - for (int i=0; i< m_graphs.size(); ++i) { - delete m_graphs[i]; + for (auto & graph : m_graphs) { + delete graph; } } // Don't actually want to delete them here.. we are just borrowing the graphs @@ -505,15 +505,14 @@ void gGraphView::popoutGraph() gv->m_graphsbyname[newname] = newgraph; newgraph->m_graphview = gv; - for (int i=0; i < graph->m_layers.size(); ++i) { - Layer * layer = graph->m_layers.at(i)->Clone(); + for (auto & l : graph->m_layers) { + Layer * layer = l->Clone(); if (layer) { newgraph->m_layers.append(layer); } } - for (int i=0;igroup(), group); } newgraph->setGroup(group+1); @@ -578,7 +577,7 @@ gGraphView::~gGraphView() #ifdef ENABLE_THREADED_DRAWING - for (int i = 0; i < m_threads.size(); i++) { + for (int i=0; i < m_threads.size(); i++) { delete m_threads[i]; } @@ -586,8 +585,7 @@ gGraphView::~gGraphView() #endif // Note: This will cause a crash if two graphs accidentally have the same name - for (QList::iterator g = m_graphs.begin(); g!= m_graphs.end(); ++g) { - gGraph * graph = *g; + for (auto & graph : m_graphs) { delete graph; } @@ -616,17 +614,17 @@ bool gGraphView::pinchTriggered(QPinchGesture * gesture) { gGraph * graph = nullptr; int group =0; - if (!graph) { +// if (!graph) { // just pick any graph then - for (int i = 0; i < m_graphs.size(); i++) { - if (!m_graphs[i]) continue; - if (!m_graphs[i]->isEmpty()) { - graph = m_graphs[i]; + for (const auto & g : m_graphs) { + if (!g) continue; + if (!g->isEmpty()) { + graph = g; group = graph->group(); break; } } - } else group=graph->group(); +// } else group=graph->group(); if (!graph) { return true; } @@ -694,10 +692,8 @@ void gGraphView::dumpInfo() mainwin->log(QString("Available Channels for %1").arg(dt.toString("MMM dd yyyy"))); QHash > list; - for (int i=0; i< day->size(); ++i) { - Session * sess = day->sessions.at(i); - QHash >::iterator it; - for (it = sess->eventlist.begin(); it != sess->eventlist.end(); ++it) { + for (const auto & sess : day->sessions) { + for (auto it=sess->eventlist.begin(), end=sess->eventlist.end(); it != end; ++it) { ChannelID code = it.key(); schema::Channel * chan = &schema::channel[code]; list[chan->type()].append(chan); @@ -705,7 +701,7 @@ void gGraphView::dumpInfo() } QHash >::iterator lit; - for (lit = list.begin(); lit != list.end(); ++lit) { + for (auto lit = list.begin(), end=list.end(); lit != end; ++lit) { switch (lit.key()) { case schema::DATA: text = "DATA: "; @@ -732,8 +728,8 @@ void gGraphView::dumpInfo() break; } QStringList str; - for (int i=0; i< lit.value().size(); ++i) { - str.append(lit.value().at(i)->code()); + for (const auto & chan : lit.value()) { + str.append(chan->code()); } str.sort(); text.append(str.join(", ")); @@ -825,13 +821,9 @@ void gGraphView::DrawTextQue(QPainter &painter) { { // process the text drawing queue - int m_textque_items = m_textque.size(); - int h,w; - for (int i = 0; i < m_textque_items; ++i) { - const TextQue &q = m_textque.at(i); - + for (const auto & q : m_textque) { // can do antialiased text via texture cache fine on mac if (usePixmapCache()) { // Generate the pixmap cache "key" @@ -919,12 +911,9 @@ void gGraphView::DrawTextQue(QPainter &painter) //////////////////////////////////////////////////////////////////////// // Text Rectangle Queues.. //////////////////////////////////////////////////////////////////////// - int items = m_textqueRect.size(); float ww, hh; - for (int i = 0; i < items; ++i) { - const TextQueRect &q = m_textqueRect.at(i); - + for (const auto & q : m_textqueRect) { // can do antialiased text via texture cache fine on mac if (usePixmapCache()) { // Generate the pixmap cache "key" @@ -1065,8 +1054,7 @@ float gGraphView::totalHeight() { float th = 0; - for (int i = 0; i < m_graphs.size(); i++) { - gGraph * g = m_graphs[i]; + for (const auto & g : m_graphs) { if (g->isEmpty() || (!g->visible())) { continue; } th += g->height() + graphSpacer; @@ -1079,12 +1067,12 @@ float gGraphView::findTop(gGraph *graph) { float th = -m_offsetY; - for (int i = 0; i < m_graphs.size(); i++) { - if (m_graphs[i] == graph) { break; } + for (const auto & g : m_graphs) { + if (g == graph) { break; } - if (m_graphs[i]->isEmpty() || (!m_graphs[i]->visible())) { continue; } + if (g->isEmpty() || (!g->visible())) { continue; } - th += m_graphs[i]->height() * m_scaleY + graphSpacer; + th += g->height() * m_scaleY + graphSpacer; } return ceil(th); @@ -1094,10 +1082,10 @@ float gGraphView::scaleHeight() { float th = 0; - for (int i = 0; i < m_graphs.size(); i++) { - if (m_graphs[i]->isEmpty() || (!m_graphs[i]->visible())) { continue; } + for (const auto & graph : m_graphs) { + if (graph->isEmpty() || (!graph->visible())) { continue; } - th += m_graphs[i]->height() * m_scaleY + graphSpacer; + th += graph->height() * m_scaleY + graphSpacer; } return ceil(th); @@ -1136,8 +1124,8 @@ void gGraphView::resizeEvent(QResizeEvent *e) updateScale(); if (m_scaleY > 0.0001) { - for (int i = 0; i < m_graphs.size(); i++) { - m_graphs[i]->resize(e->size().width(), m_graphs[i]->height() * m_scaleY); + for (auto & graph : m_graphs) { + graph->resize(e->size().width(), graph->height() * m_scaleY); } } e->accept(); @@ -1158,20 +1146,13 @@ void gGraphView::scrollbarValueChanged(int val) void gGraphView::GetRXBounds(qint64 &st, qint64 &et) { - //qint64 m1=0,m2=0; - gGraph *g = nullptr; - - for (int i = 0; i < m_graphs.size(); i++) { - g = m_graphs[i]; - - if (g->group() == 0) { + for (const auto & graph : m_graphs) { + if (graph->group() == 0) { + st = graph->rmin_x; + et = graph->rmax_x; break; } } - if (g) { - st = g->rmin_x; - et = g->rmax_x; - } } void gGraphView::ResetBounds(bool refresh) //short group) @@ -1179,18 +1160,18 @@ void gGraphView::ResetBounds(bool refresh) //short group) if (m_graphs.size() == 0) return; Q_UNUSED(refresh) qint64 m1 = 0, m2 = 0; - gGraph *g = nullptr; + gGraph *graph = nullptr; - for (int i = 0; i < m_graphs.size(); i++) { - m_graphs[i]->ResetBounds(); + for (auto & g : m_graphs) { + g->ResetBounds(); - if (!m_graphs[i]->min_x) { continue; } + if (!g->min_x) { continue; } - g = m_graphs[i]; + graph = g; - if (!m1 || m_graphs[i]->min_x < m1) { m1 = m_graphs[i]->min_x; } + if (!m1 || g->min_x < m1) { m1 = g->min_x; } - if (!m2 || m_graphs[i]->max_x > m2) { m2 = m_graphs[i]->max_x; } + if (!m2 || g->max_x > m2) { m2 = g->max_x; } } // if (p_profile->general->linkGroups()) { @@ -1200,12 +1181,12 @@ void gGraphView::ResetBounds(bool refresh) //short group) // } // } - if (!g) { - g = m_graphs[0]; + if (!graph) { + graph = m_graphs[0]; } - m_minx = g->min_x; - m_maxx = g->max_x; + m_minx = graph->min_x; + m_maxx = graph->max_x; updateScale(); } @@ -1218,9 +1199,9 @@ void gGraphView::GetXBounds(qint64 &st, qint64 &et) void gGraphView::SetXBounds(qint64 minx, qint64 maxx, short group, bool refresh) { - for (int i = 0; i < m_graphs.size(); i++) { - if ((m_graphs[i]->group() == group)) { - m_graphs[i]->SetXBounds(minx, maxx); + for (auto & graph : m_graphs) { + if ((graph->group() == group)) { + graph->SetXBounds(minx, maxx); } } @@ -1241,8 +1222,8 @@ void gGraphView::updateScrollBar() float vis = 0; - for (int i = 0; i < m_graphs.size(); i++) { - vis += (m_graphs[i]->isEmpty() || !m_graphs[i]->visible()) ? 0 : 1; + for (const auto & graph : m_graphs) { + vis += (graph->isEmpty() || !graph->visible()) ? 0 : 1; } if (th < h) { // less graphs than fits on screen @@ -1304,10 +1285,8 @@ bool gGraphView::renderGraphs(QPainter &painter) float pinned_height = 0; // pixel height total int pinned_graphs = 0; // count - gGraph * g = nullptr; - for (int i = 0; i < m_graphs.size(); i++) { - g = m_graphs[i]; + for (auto & g : m_graphs) { int minh = g->minHeight(); if (g->height() < minh) { g->setHeight(minh); @@ -1326,8 +1305,7 @@ bool gGraphView::renderGraphs(QPainter &painter) py += pinned_height; // start drawing at the end of pinned space // Draw non pinned graphs - for (int i = 0; i < m_graphs.size(); i++) { - g = m_graphs[i]; + for (auto & g : m_graphs) { if (g->isEmpty()) { continue; } if (!g->visible()) { continue; } @@ -1367,13 +1345,10 @@ bool gGraphView::renderGraphs(QPainter &painter) } // Physically draw the unpinned graphs - int s = m_drawlist.size(); - - for (int i = 0; i < s; i++) { - g = m_drawlist.at(0); - m_drawlist.pop_front(); + for (const auto & g : m_drawlist) { g->paint(painter, QRegion(g->m_rect)); } + m_drawlist.clear(); if (m_graphs.size() > 1) { DrawTextQue(painter); @@ -1389,8 +1364,7 @@ bool gGraphView::renderGraphs(QPainter &painter) py = 0; // start drawing at top... // Draw Pinned graphs - for (int i = 0; i < m_graphs.size(); i++) { - g = m_graphs[i]; + for (const auto & g : m_graphs) { if (g->isEmpty()) { continue; } if (!g->visible()) { continue; } @@ -1439,13 +1413,10 @@ bool gGraphView::renderGraphs(QPainter &painter) masterlock->release(m_idealthreads); } else { #endif - s = m_drawlist.size(); - - for (int i = 0; i < s; i++) { - g = m_drawlist.at(0); - m_drawlist.pop_front(); + for (const auto & g : m_drawlist) { g->paint(painter, QRegion(g->m_rect)); } + m_drawlist.clear(); #ifdef ENABLED_THREADED_DRAWING } @@ -1776,22 +1747,22 @@ void gGraphView::mouseMoveEvent(QMouseEvent *event) bool done = false; // Do pinned graphs first - for (int i = 0; i < m_graphs.size(); i++) { + for (const auto & graph : m_graphs) { - if (m_graphs[i]->isEmpty() || !m_graphs[i]->visible() || !m_graphs[i]->isPinned()) { + if (graph->isEmpty() || !graph->visible() || !graph->isPinned()) { continue; } - h = m_graphs[i]->height() * m_scaleY; + h = graph->height() * m_scaleY; pinned_height += h + graphSpacer; if (py > height()) { break; // we are done.. can't draw anymore } - if (!((y >= py + m_graphs[i]->top) && (y < py + h - m_graphs[i]->bottom))) { - if (m_graphs[i]->isSelected()) { - m_graphs[i]->deselect(); + if (!((y >= py + graph->top) && (y < py + h - graph->bottom))) { + if (graph->isSelected()) { + graph->deselect(); timedRedraw(150); } } @@ -1817,7 +1788,7 @@ void gGraphView::mouseMoveEvent(QMouseEvent *event) // QPoint p(x,y); // QMouseEvent e(event->type(),p,event->button(),event->buttons(),event->modifiers()); - m_graphs[i]->mouseMoveEvent(event); + graph->mouseMoveEvent(event); done = true; } @@ -1831,21 +1802,21 @@ void gGraphView::mouseMoveEvent(QMouseEvent *event) // Propagate mouseMove events to relevant graphs if (!done) - for (int i = 0; i < m_graphs.size(); i++) { + for (const auto & graph : m_graphs) { - if (m_graphs[i]->isEmpty() || !m_graphs[i]->visible() || m_graphs[i]->isPinned()) { + if (graph->isEmpty() || !graph->visible() || graph->isPinned()) { continue; } - h = m_graphs[i]->height() * m_scaleY; + h = graph->height() * m_scaleY; if (py > height()) { break; // we are done.. can't draw anymore } - if (!((y >= py + m_graphs[i]->top) && (y < py + h - m_graphs[i]->bottom))) { - if (m_graphs[i]->isSelected()) { - m_graphs[i]->deselect(); + if (!((y >= py + graph->top) && (y < py + h - graph->bottom))) { + if (graph->isSelected()) { + graph->deselect(); timedRedraw(150); } } @@ -1867,11 +1838,9 @@ void gGraphView::mouseMoveEvent(QMouseEvent *event) m_horiz_travel += qAbs(x - m_lastxpos) + qAbs(y - m_lastypos); m_lastxpos = x; m_lastypos = y; - gGraph *g = m_graphs[i]; - if (g) { - g->mouseMoveEvent(event); + if (graph) { + graph->mouseMoveEvent(event); } - } /* else if (!m_button_down && (y >= py) && (y < py+m_graphs[i]->top)) { @@ -1936,10 +1905,9 @@ void gGraphView::mouseMoveEvent(QMouseEvent *event) Layer * gGraphView::findLayer(gGraph * graph, LayerType type) { - for (int i=0; i< graph->layers().size(); i++) { - Layer * l = graph->layers()[i]; - if (l->layerType() == type) { - return l; + for (auto & layer : graph->m_layers) { + if (layer->layerType() == type) { + return layer; } } return nullptr; @@ -2020,8 +1988,6 @@ void MinMaxWidget::onComboChanged(int idx) void MinMaxWidget::createLayout() { - - QGridLayout * layout = new QGridLayout; layout->setMargin(4); layout->setSpacing(4); @@ -2106,7 +2072,6 @@ void gGraphView::populateMenu(gGraph * graph) { QAction * action; - if (graph->isSnapshot()) { snap_action->setText(tr("Remove Clone")); snap_action->setData(graph->name()+"|remove"); @@ -2117,7 +2082,6 @@ void gGraphView::populateMenu(gGraph * graph) // zoom100_action->setVisible(true); } - // Menu title fonts QFont font = QApplication::font(); font.setBold(true); @@ -2127,7 +2091,6 @@ void gGraphView::populateMenu(gGraph * graph) SummaryChart * sc = dynamic_cast(findLayer(graph,LT_SummaryChart)); gSummaryChart * stg = dynamic_cast(findLayer(graph,LT_Overview)); - limits_menu->clear(); if (lc || sc || stg) { QWidgetAction * widget = new QWidgetAction(this); @@ -2141,12 +2104,11 @@ void gGraphView::populateMenu(gGraph * graph) limits_menu->menuAction()->setVisible(false); } - // First check for any linechart for this graph.. if (lc) { lines_menu->clear(); - for (int i=0; i < lc->m_dotlines.size(); i++) { - DottedLine & dot = lc->m_dotlines[i]; + for (int i=0, end=lc->m_dotlines.size(); i < end; i++) { + const DottedLine & dot = lc->m_dotlines[i]; if (!lc->m_enabled[dot.code]) continue; @@ -2171,15 +2133,7 @@ void gGraphView::populateMenu(gGraph * graph) bool b = lc->m_dot_enabled[dot.code][dot.type]; //chan.calc[dot.type].enabled; chbox->setChecked(b); lines_menu->addAction(widget); - - - -// QAction *action = lines_menu->addAction(chan.calc[dot.type].label()); -// action->setData(graph->name()); -// action->setCheckable(true); -// action->setChecked(chan.calc[dot.type].enabled); } - } lines_menu->menuAction()->setVisible(lines_menu->actions().size() > 0); @@ -2194,45 +2148,35 @@ void gGraphView::populateMenu(gGraph * graph) } - - ////////////////////////////////////////////////////////////////////////////////////// // Populate Plots Menus ////////////////////////////////////////////////////////////////////////////////////// plots_menu->clear(); - if (lc->m_codes.size() > 1) { - for (int i=0; i m_codes.size(); ++i) { - ChannelID code = lc->m_codes[i]; - if (lc->m_day && !lc->m_day->channelHasData(code)) continue; + for (const auto code : lc->m_codes) { + if (lc->m_day && !lc->m_day->channelHasData(code)) continue; - QWidgetAction * widget = new QWidgetAction(context_menu); + QWidgetAction * widget = new QWidgetAction(context_menu); - QCheckBox *chbox = new QCheckBox(schema::channel[code].label(), context_menu); - chbox->setMouseTracking(true); - chbox->setToolTip(schema::channel[code].description()); - chbox->setStyleSheet(QString("QCheckBox:hover { background: %1; }").arg(QApplication::palette().highlight().color().name())); + QCheckBox *chbox = new QCheckBox(schema::channel[code].label(), context_menu); + chbox->setMouseTracking(true); + chbox->setToolTip(schema::channel[code].description()); + chbox->setStyleSheet(QString("QCheckBox:hover { background: %1; }").arg(QApplication::palette().highlight().color().name())); - widget->setDefaultWidget(chbox); + widget->setDefaultWidget(chbox); - widget->setCheckable(true); - widget->setData(QString("%1|%2").arg(graph->name()).arg(code)); + widget->setCheckable(true); + widget->setData(QString("%1|%2").arg(graph->name()).arg(code)); - connect(chbox, SIGNAL(toggled(bool)), widget, SLOT(setChecked(bool))); - connect(chbox, SIGNAL(clicked()), widget, SLOT(trigger())); + connect(chbox, SIGNAL(toggled(bool)), widget, SLOT(setChecked(bool))); + connect(chbox, SIGNAL(clicked()), widget, SLOT(trigger())); - bool b = lc->m_enabled[code]; - chbox->setChecked(b); + bool b = lc->m_enabled[code]; + chbox->setChecked(b); - plots_menu->addAction(widget); - -// QAction * action = plots_menu->addAction(schema::channel[code].label()); -// action->setData(QString("%1|%2").arg(graph->name()).arg(code)); -// action->setCheckable(true); -// action->setChecked(lc->m_enabled[code]); - } + plots_menu->addAction(widget); } plots_menu->menuAction()->setVisible((plots_menu->actions().size() > 1)); @@ -2258,10 +2202,9 @@ void gGraphView::populateMenu(gGraph * graph) if (p_profile->general->showUnknownFlags()) showflags |= schema::UNKNOWN; QList chans = lc->m_day->getSortedMachineChannels(showflags); - QHash Vis; - for (int i=0; i < chans.size() ; ++i) { - ChannelID code = chans.at(i); + + for (const auto code : chans) { schema::Channel & chan = schema::channel[code]; QWidgetAction * widget = new QWidgetAction(context_menu); @@ -2272,7 +2215,6 @@ void gGraphView::populateMenu(gGraph * graph) chbox->setToolTip(schema::channel[code].description()); chbox->setStyleSheet(QString("QCheckBox:hover { background: %1; }").arg(QApplication::palette().highlight().color().name())); - widget->setDefaultWidget(chbox); widget->setCheckable(true); @@ -2285,7 +2227,6 @@ void gGraphView::populateMenu(gGraph * graph) chbox->setChecked(b); Vis[chan.machtype()] += b ? 1 : 0; - action = nullptr; if (chan.machtype() == MT_OXIMETER) { oximeter_menu->insertAction(nullptr, widget); @@ -2311,7 +2252,6 @@ void gGraphView::populateMenu(gGraph * graph) action->setData(QString("%1|ShowAll:CPAP").arg(graph->name())); } - // Show CPAP Events menu Header... cpap_menu->insertSeparator(cpap_menu->actions()[0]); action = new QAction(QObject::tr("%1").arg(graph->title()), cpap_menu); @@ -2354,7 +2294,7 @@ void gGraphView::onSnapshotGraphToggle() { QString name = snap_action->data().toString().section("|",0,0); QString cmd = snap_action->data().toString().section("|",-1).toLower(); - QHash::iterator it = m_graphsbyname.find(name); + auto it = m_graphsbyname.find(name); if (it == m_graphsbyname.end()) return; gGraph * graph = it.value(); @@ -2387,8 +2327,8 @@ void gGraphView::onSnapshotGraphToggle() for (int i=1; i < 100; i++) { newtitle = graph->title()+"-"+QString::number(i); fnd = false; - for (int j=0; jtitle() == newtitle) { + for (const auto & graph : m_graphs) { + if (graph->title() == newtitle) { fnd = true; break; } @@ -2400,7 +2340,6 @@ void gGraphView::onSnapshotGraphToggle() return; } - gGraph * newgraph = new gGraph(newname, nullptr, newtitle, graph->units(), graph->height(), graph->group()); // newgraph->setBlockSelect(true); newgraph->setHeight(graph->height()); @@ -2410,15 +2349,14 @@ void gGraphView::onSnapshotGraphToggle() m_graphsbyname[newname] = newgraph; newgraph->m_graphview = this; - for (int i=0; i < graph->m_layers.size(); ++i) { - Layer * layer = graph->m_layers.at(i)->Clone(); + for (const auto & l : graph->m_layers) { + Layer * layer = l->Clone(); if (layer) { newgraph->m_layers.append(layer); } } - for (int i=0;igroup(), group); } newgraph->setGroup(group+1); @@ -2456,7 +2394,6 @@ void gGraphView::onSnapshotGraphToggle() m_graphs.removeAll(it.value()); delete graph; - updateScale(); timedRedraw(0); @@ -2467,10 +2404,8 @@ void gGraphView::onSnapshotGraphToggle() bool gGraphView::hasSnapshots() { - int size = m_graphs.size(); bool snap = false; - for (int i=0; i< size; ++i) { - gGraph * graph = m_graphs.at(i); + for (const auto & graph : m_graphs) { if (graph->isSnapshot()) { snap = true; break; @@ -2485,7 +2420,7 @@ void gGraphView::onPlotsClicked(QAction *action) QString name = action->data().toString().section("|",0,0); ChannelID code = action->data().toString().section("|",-1).toInt(); - QHash::iterator it = m_graphsbyname.find(name); + auto it = m_graphsbyname.find(name); if (it == m_graphsbyname.end()) return; gGraph * graph = it.value(); @@ -2506,7 +2441,7 @@ void gGraphView::onOverlaysClicked(QAction *action) { QString name = action->data().toString().section("|",0,0); QString data = action->data().toString().section("|",-1); - QHash::iterator it = m_graphsbyname.find(name); + auto it = m_graphsbyname.find(name); if (it == m_graphsbyname.end()) return; gGraph * graph = it.value(); @@ -2539,11 +2474,8 @@ void gGraphView::onOverlaysClicked(QAction *action) else if (group == "OXI") mtype = MT_OXIMETER; else mtype = MT_UNKNOWN; - QHash::iterator it; - QHash::iterator mfe = lc->m_flags_enabled.end(); - // First toggle the actual flag bits - for (it = lc->m_flags_enabled.begin(); it != mfe; ++it) { + for (auto it=lc->m_flags_enabled.begin(), end=lc->m_flags_enabled.end(); it != end; ++it) { if (schema::channel[it.key()].machtype() == mtype) { lc->m_flags_enabled[it.key()] = value; } @@ -2551,15 +2483,15 @@ void gGraphView::onOverlaysClicked(QAction *action) // Now toggle the menu actions.. bleh if (mtype == MT_CPAP) { - for (int i=0; i< cpap_menu->actions().size(); i++) { - if (cpap_menu->actions().at(i)->isCheckable()) { - cpap_menu->actions().at(i)->setChecked(value); + for (auto & action : cpap_menu->actions()) { + if (action->isCheckable()) { + action->setChecked(value); } } } else if (mtype == MT_OXIMETER) { - for (int i=0; i< oximeter_menu->actions().size(); i++) { - if (oximeter_menu->actions().at(i)->isCheckable()) { - oximeter_menu->actions().at(i)->setChecked(value); + for (auto & action : oximeter_menu->actions()) { + if (action->isCheckable()) { + action->setChecked(value); } } } @@ -2573,7 +2505,7 @@ void gGraphView::onLinesClicked(QAction *action) QString name = action->data().toString().section("|",0,0); QString data = action->data().toString().section("|",-1); - QHash::iterator it = m_graphsbyname.find(name); + auto it = m_graphsbyname.find(name); if (it == m_graphsbyname.end()) return; gGraph * graph = it.value(); @@ -2607,8 +2539,8 @@ void gGraphView::mousePressEvent(QMouseEvent *event) // first handle pinned graphs. // Calculate total height of all pinned graphs - for (int i = 0; i < m_graphs.size(); i++) { - gGraph *g = m_graphs[i]; + for (int i=0, end=m_graphs.size(); iisEmpty() || !g->visible() || !g->isPinned()) { continue; @@ -2684,10 +2616,9 @@ void gGraphView::mousePressEvent(QMouseEvent *event) py = -m_offsetY; py += pinned_height; - if (!done) - for (int i = 0; i < m_graphs.size(); i++) { + if (!done) { + for (int i=0, end=m_graphs.size(); iisEmpty() || !g->visible() || g->isPinned()) { continue; } @@ -2753,7 +2684,7 @@ void gGraphView::mousePressEvent(QMouseEvent *event) py += h + graphSpacer; done=true; } - + } if (!done) { // if (event->button() == Qt::RightButton) { // this->setCursor(Qt::ArrowCursor); @@ -2778,8 +2709,7 @@ void gGraphView::mouseReleaseEvent(QMouseEvent *event) m_button_down = false; // Handle pinned graphs first - for (int i = 0; i < m_graphs.size(); i++) { - gGraph *g = m_graphs[i]; + for (const auto & g : m_graphs) { if (!g || g->isEmpty() || !g->visible() || !g->isPinned()) { continue; @@ -2818,8 +2748,7 @@ void gGraphView::mouseReleaseEvent(QMouseEvent *event) py += pinned_height; if (done) - for (int i = 0; i < m_graphs.size(); i++) { - gGraph *g = m_graphs[i]; + for (const auto & g : m_graphs) { if (!g || g->isEmpty() || !g->visible() || g->isPinned()) { continue; @@ -2893,7 +2822,6 @@ void gGraphView::keyReleaseEvent(QKeyEvent *event) } m_metaselect = false; - timedRedraw(50); } if (event->key() == Qt::Key_Escape) { @@ -2929,8 +2857,7 @@ void gGraphView::mouseDoubleClickEvent(QMouseEvent *event) bool done = false; // Handle pinned graphs first - for (int i = 0; i < m_graphs.size(); i++) { - gGraph *g = m_graphs[i]; + for (const auto & g : m_graphs) { if (!g || g->isEmpty() || !g->visible() || !g->isPinned()) { continue; } @@ -2972,8 +2899,7 @@ void gGraphView::mouseDoubleClickEvent(QMouseEvent *event) py += pinned_height; if (!done) // then handle unpinned graphs - for (int i = 0; i < m_graphs.size(); i++) { - gGraph *g = m_graphs[i]; + for (const auto & g : m_graphs) { if (!g || g->isEmpty() || !g->visible() || g->isPinned()) { continue; } @@ -3046,8 +2972,8 @@ void gGraphView::wheelEvent(QWheelEvent *event) // Find graph hovered over - for (int i = 0; i < m_graphs.size(); i++) { - gGraph *g = m_graphs[i]; + for (const auto & g : m_graphs) { + if (!g || g->isEmpty() || !g->visible() || !g->isPinned()) { continue; } @@ -3077,8 +3003,7 @@ void gGraphView::wheelEvent(QWheelEvent *event) py = -m_offsetY; py += pinned_height; - for (int i = 0; i < m_graphs.size(); i++) { - gGraph *g = m_graphs[i]; + for (const auto & g : m_graphs) { if (!g || g->isEmpty() || !g->visible() || g->isPinned()) { continue; } @@ -3110,10 +3035,10 @@ void gGraphView::wheelEvent(QWheelEvent *event) if (event->modifiers() == Qt::NoModifier) { if (!graph) { // just pick any graph then - for (int i = 0; i < m_graphs.size(); i++) { - if (!m_graphs[i]) continue; - if (!m_graphs[i]->isEmpty()) { - graph = m_graphs[i]; + for (const auto & g : m_graphs) { + if (!g) continue; + if (!g->isEmpty()) { + graph = g; group = graph->group(); break; } @@ -3272,19 +3197,19 @@ void gGraphView::keyPressEvent(QKeyEvent *event) int group = 0; // Pick the first valid graph in the primary group - for (int i = 0; i < m_graphs.size(); i++) { - if (m_graphs[i]->group() == group) { - if (!m_graphs[i]->isEmpty() && m_graphs[i]->visible()) { - g = m_graphs[i]; + for (const auto & gr : m_graphs) { + if (gr->group() == group) { + if (!gr->isEmpty() && gr->visible()) { + g = gr; break; } } } if (!g) { - for (int i = 0; i < m_graphs.size(); i++) { - if (!m_graphs[i]->isEmpty()) { - g = m_graphs[i]; + for (const auto & gr : m_graphs) { + if (!gr->isEmpty()) { + g = gr; group = g->group(); break; } @@ -3350,8 +3275,8 @@ void gGraphView::setDay(Day *day) m_day = day; - for (int i = 0; i < m_graphs.size(); i++) { - if (m_graphs[i]) m_graphs[i]->setDay(day); + for (const auto & g : m_graphs) { + if (g) g->setDay(day); } ResetBounds(false); @@ -3360,8 +3285,7 @@ bool gGraphView::isEmpty() { bool res = true; - for (int i = 0; i < m_graphs.size(); i++) { - gGraph * graph = m_graphs.at(i); + for (const auto & graph : m_graphs) { if (!graph->isSnapshot() && !graph->isEmpty()) { res = false; break; @@ -3397,8 +3321,8 @@ void gGraphView::resetLayout() { int default_height = AppSetting->graphHeight(); - for (int i = 0; i < m_graphs.size(); i++) { - if (m_graphs[i]) m_graphs[i]->setHeight(default_height); + for (auto & graph : m_graphs) { + if (graph) graph->setHeight(default_height); } updateScale(); @@ -3406,8 +3330,8 @@ void gGraphView::resetLayout() } void gGraphView::deselect() { - for (int i = 0; i < m_graphs.size(); i++) { - if (m_graphs[i]) m_graphs[i]->deselect(); + for (auto & graph : m_graphs) { + if (graph) graph->deselect(); } } @@ -3429,8 +3353,7 @@ void gGraphView::SaveSettings(QString title) out << (qint16)size(); - for (qint16 i = 0; i < size(); i++) { - gGraph * graph = m_graphs[i]; + for (auto & graph : m_graphs) { if (!graph) continue; if (graph->isSnapshot()) continue; @@ -3586,17 +3509,17 @@ bool gGraphView::LoadSettings(QString title) gGraph *gGraphView::findGraph(QString name) { - QHash::iterator i = m_graphsbyname.find(name); + auto it = m_graphsbyname.find(name); - if (i == m_graphsbyname.end()) { return nullptr; } + if (it == m_graphsbyname.end()) { return nullptr; } - return i.value(); + return it.value(); } gGraph *gGraphView::findGraphTitle(QString title) { - for (int i=0; i< m_graphs.size(); ++i) { - if (m_graphs[i]->title() == title) return m_graphs[i]; + for (auto & graph : m_graphs) { + if (graph->title() == title) return graph; } return nullptr; } @@ -3605,8 +3528,8 @@ int gGraphView::visibleGraphs() { int cnt = 0; - for (int i = 0; i < m_graphs.size(); i++) { - if (m_graphs[i]->visible() && !m_graphs[i]->isEmpty()) { cnt++; } + for (auto & graph : m_graphs) { + if (graph->visible() && !graph->isEmpty()) { cnt++; } } return cnt; @@ -3614,8 +3537,8 @@ int gGraphView::visibleGraphs() void gGraphView::dataChanged() { - for (int i = 0; i < m_graphs.size(); i++) { - m_graphs[i]->dataChanged(); + for (auto & graph : m_graphs) { + graph->dataChanged(); } } diff --git a/sleepyhead/Graphs/gLineChart.cpp b/sleepyhead/Graphs/gLineChart.cpp index d9466337..b1dcdd24 100644 --- a/sleepyhead/Graphs/gLineChart.cpp +++ b/sleepyhead/Graphs/gLineChart.cpp @@ -1,4 +1,4 @@ -/* gLineChart Implementation +/* gLineChart Implementation * * Copyright (c) 2011-2018 Mark Watkins * @@ -64,8 +64,7 @@ gLineChart::gLineChart(ChannelID code, bool square_plot, bool disable_accel) } gLineChart::~gLineChart() { - QHash::iterator fit; - for (fit = flags.begin(); fit != flags.end(); ++fit) { + for (auto fit = flags.begin(), end=flags.end(); fit != end; ++fit) { // destroy any overlay bar from previous day delete fit.value(); } @@ -78,10 +77,8 @@ bool gLineChart::isEmpty() { if (!m_day) { return true; } - for (int j = 0; j < m_codes.size(); j++) { - ChannelID code = m_codes[j]; - - for (int i = 0; i < m_day->size(); i++) { + for (const auto code : m_codes) { + for (int i=0, end=m_day->size(); i < end; i++) { Session *sess = m_day->sessions[i]; if (sess->channelExists(code)) { @@ -112,10 +109,9 @@ void gLineChart::SetDay(Day *d) bool first = true; - for (int j = 0; j < m_codes.size(); j++) { - ChannelID code = m_codes[j]; + for (auto & code : m_codes) { - for (int i = 0; i < d->size(); i++) { + for (int i=0, end=d->size(); i < end; i++) { Session *sess = d->sessions[i]; if (!sess->enabled()) continue; @@ -129,7 +125,7 @@ void gLineChart::SetDay(Day *d) if (code == CPAP_MaskPressure) { if (sess->channelExists(CPAP_MaskPressureHi)) { - code = m_codes[j] = CPAP_MaskPressureHi; + code = CPAP_MaskPressureHi; // verify setting m_codes[] m_enabled[code] = schema::channel[CPAP_MaskPressureHi].enabled(); goto skipcheck; // why not :P @@ -192,8 +188,7 @@ skipcheck: subtract_offset = 0; - QHash::iterator fit; - for (fit = flags.begin(); fit != flags.end(); ++fit) { + for (auto fit = flags.begin(), end=flags.end(); fit != end; ++fit) { // destroy any overlay bar from previous day delete fit.value(); } @@ -204,8 +199,7 @@ skipcheck: if (p_profile->general->showUnknownFlags()) z |= schema::UNKNOWN; QList available = m_day->getSortedMachineChannels(z); - for (int i=0; i < available.size(); ++i) { - ChannelID code = available.at(i); + for (const auto & code : available) { if (!m_flags_enabled.contains(code)) { bool b = false; @@ -215,7 +209,6 @@ skipcheck: } if (!m_day->channelExists(code)) continue; - schema::Channel * chan = &schema::channel[code]; gLineOverlayBar * lob = nullptr; @@ -235,9 +228,8 @@ skipcheck: m_dotlines.clear(); - for (int i=0; i< m_codes.size(); i++) { - ChannelID code = m_codes[i]; - schema::Channel & chan = schema::channel[code]; + for (const auto & code : m_codes) { + const schema::Channel & chan = schema::channel[code]; addDotLine(DottedLine(code, Calc_Max,chan.calc[Calc_Max].enabled)); if ((code != CPAP_FlowRate) && (code != CPAP_MaskPressure) && (code != CPAP_MaskPressureHi)) { addDotLine(DottedLine(code, Calc_Perc,chan.calc[Calc_Perc].enabled)); @@ -260,20 +252,19 @@ skipcheck: if (m_day) { - for (int i=0; i < m_dotlines.size(); i++) { - m_dotlines[i].calc(m_day); + for (auto & dot : m_dotlines) { + dot.calc(m_day); - ChannelID code = m_dotlines[i].code; - ChannelCalcType type = m_dotlines[i].type; + ChannelID code = dot.code; + ChannelCalcType type = dot.type; bool b = false; // default value - QHash >::iterator cit = m_dot_enabled.find(code); - + const auto & cit = m_dot_enabled.find(code); if (cit == m_dot_enabled.end()) { m_dot_enabled[code].insert(type, b); } else { - QHash::iterator it = cit.value().find(type); + const auto & it = cit.value().find(type); if (it == cit.value().end()) { cit.value().insert(type, b); } @@ -283,15 +274,13 @@ skipcheck: } EventDataType gLineChart::Miny() { - int size = m_codes.size(); - if (size == 0) return 0; + if (m_codes.size() == 0) return 0; if (!m_day) return 0; bool first = false; EventDataType min = 0, tmp; - for (int i=0; i< size; ++i) { - ChannelID code = m_codes[i]; + for (const auto code : m_codes) { if (!m_enabled[code] || !m_day->channelExists(code)) continue; tmp = m_day->Min(code); @@ -308,27 +297,16 @@ EventDataType gLineChart::Miny() m_miny = min; return min; -// int m = Layer::Miny(); - -// if (subtract_offset > 0) { -// m -= subtract_offset; - -// if (m < 0) { m = 0; } -// } - -// return m; } EventDataType gLineChart::Maxy() { - int size = m_codes.size(); - if (size == 0) return 0; + if (m_codes.size() == 0) return 0; if (!m_day) return 0; bool first = false; EventDataType max = 0, tmp; - for (int i=0; i< size; ++i) { - ChannelID code = m_codes[i]; + for (const auto code : m_codes) { if (!m_enabled[code] || !m_day->channelExists(code)) continue; tmp = m_day->Max(code); @@ -357,18 +335,15 @@ bool gLineChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph) QString gLineChart::getMetaString(qint64 time) { - lasttext = QString(); if (!m_day) return lasttext; - + lasttext = QString(); EventDataType val; EventDataType ipap = 0, epap = 0; bool addPS = false; - for (int i=0; ichannelHasData(code)) { val = m_day->lookupValue(code, time, m_square_plot); lasttext += " "+QString("%1: %2").arg(schema::channel[code].label()).arg(val,0,'f',2); //.arg(schema::channel[code].units()); @@ -543,33 +518,27 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) painter.setFont(*defaultfont); bool showDottedLines = true; - int dotlinesize = m_dotlines.size(); - // Unset Dotted lines visible status, so we only draw necessary labels later - for (int i=0; i < dotlinesize; i++) { - DottedLine & dot = m_dotlines[i]; + for (auto & dot : m_dotlines) { dot.visible = false; } - Session * sess = nullptr; ChannelID code; float lineThickness = AppSetting->lineThickness()+0.001F; - for (int gi = 0; gi < m_codes.size(); gi++) { - code = m_codes[gi]; - schema::Channel &chan = schema::channel[code]; + for (const auto & code : m_codes) { + const schema::Channel &chan = schema::channel[code]; //////////////////////////////////////////////////////////////////////// // Draw the Channel Threshold dotted lines, and flow waveform centreline //////////////////////////////////////////////////////////////////////// if (showDottedLines) { - for (int i=0; i < dotlinesize; i++) { - DottedLine & dot = m_dotlines[i]; + for (auto & dot : m_dotlines) { if ((dot.code != code) || (!m_dot_enabled[dot.code][dot.type]) || (!dot.available) || (!m_enabled[dot.code])) { continue; } - schema::Channel & chan = schema::channel[code]; + //schema::Channel & chan = schema::channel[code]; dot.visible = true; QColor color = chan.calc[dot.type].color; @@ -588,10 +557,7 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) codepoints = 0; // For each session... - int daysize = m_day->size(); - for (int svi = 0; svi < daysize; svi++) { - sess = (*m_day)[svi]; - + for (const auto & sess : m_day->sessions) { if (!sess) { qWarning() << "gLineChart::Plot() nullptr Session Record.. This should not happen"; continue; @@ -604,12 +570,10 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) schema::Channel ch = schema::channel[code]; bool fndbetter = false; - QList::iterator mlend=ch.m_links.end(); - for (QList::iterator l = ch.m_links.begin(); l != mlend; l++) { - schema::Channel &c = *(*l); - ci = (*m_day)[svi]->eventlist.find(c.id()); + for (const auto & c : ch.m_links) { + ci = sess->eventlist.find(c->id()); - if (ci != (*m_day)[svi]->eventlist.end()) { + if (ci != sess->eventlist.end()) { fndbetter = true; break; } @@ -617,20 +581,15 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) } if (!fndbetter) { - ci = (*m_day)[svi]->eventlist.find(code); + ci = sess->eventlist.find(code); - if (ci == (*m_day)[svi]->eventlist.end()) { continue; } + if (ci == sess->eventlist.end()) { continue; } } - - QVector &evec = ci.value(); num_points = 0; - QVector::iterator evec_end = evec.end(); - QVector::iterator ni; - - for (ni = evec.begin(); ni != evec_end; ++ni) { - num_points += (*ni)->count(); + for (const auto & ni : ci.value()) { + num_points += ni->count(); } total_points += num_points; @@ -639,9 +598,8 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) // Max number of samples taken from samples per pixel for better min/max values const int num_averages = 20; - int n=0; - for (ni = evec.begin(); ni != evec_end; ++ni, ++n) { - EventList & el = *(EventList*) (*ni); + for (auto & ni : ci.value()) { + EventList & el = (*ni); accel = (el.type() == EVL_Waveform); // Turn on acceleration if this is a waveform. @@ -656,7 +614,6 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) if (m_disable_accel) { accel = false; } - square_plot = m_square_plot; if (accel || num_points > 20000) { // Don't square plot if too many points or waveform @@ -882,7 +839,6 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) w.graphView()->lines_drawn_this_frame += lines.count(); lines.clear(); - } else { ////////////////////////////////////////////////////////////////// // Standard events/zoomed in Plot @@ -1050,8 +1006,7 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) //////////////////////////////////////////////////////////////////// // Draw Channel Threshold legend markers //////////////////////////////////////////////////////////////////// - for (int i=0; i < dotlinesize; i++) { - DottedLine & dot = m_dotlines[i]; + for (const auto & dot : m_dotlines) { if (!dot.visible) continue; code = dot.code; schema::Channel &chan = schema::channel[code]; @@ -1074,8 +1029,6 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) int yp = rec.top()+(rec.height()/2); painter.drawLine(rec.left()-linewidth, yp , rec.left()-(2 * ratioX), yp); legendx -= linewidth + (2*ratioX); - - } painter.setClipping(true); @@ -1094,8 +1047,7 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) double time = 0; // Calculate the CPAP session time. - for (QList::iterator s = m_day->begin(); s != m_day->end(); s++) { - sess = *s; + for (auto & sess : m_day->sessions) { if (!sess->enabled() || (sess->type() != MT_CPAP)) continue; first = sess->first(); @@ -1134,10 +1086,8 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) // Draw the linechart overlays if (m_day && (AppSetting->lineCursorMode() || (m_codes[0]==CPAP_FlowRate))) { - QHash::iterator fit; bool blockhover = false; - - for (fit = flags.begin(); fit != flags.end(); ++fit) { + for (auto fit=flags.begin(), end=flags.end(); fit != end; ++fit) { code = fit.key(); if ((!m_flags_enabled[code]) || (!m_day->channelExists(code))) continue; gLineOverlayBar * lob = fit.value(); @@ -1151,8 +1101,6 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) } } } -// if (m_codes[0] == OXI_SPO2Drop) { -// } if (m_codes[0] == CPAP_FlowRate) { float hours = time / 3600.0; int h = time / 3600; diff --git a/sleepyhead/Graphs/gLineOverlay.cpp b/sleepyhead/Graphs/gLineOverlay.cpp index 00c5e419..b1298ef0 100644 --- a/sleepyhead/Graphs/gLineOverlay.cpp +++ b/sleepyhead/Graphs/gLineOverlay.cpp @@ -1,4 +1,4 @@ -/* gLineOverlayBar Implementation +/* gLineOverlayBar Implementation * * Copyright (c) 2011-2018 Mark Watkins * @@ -86,28 +86,24 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion ®ion) int tooltipTimeout = AppSetting->tooltipTimeout(); // For each session, process it's eventlist - for (QList::iterator s = m_day->begin(); s != m_day->end(); s++) { + for (const auto sess : m_day->sessions) { + if (!sess->enabled()) { continue; } - if (!(*s)->enabled()) { continue; } + cei = sess->eventlist.find(m_code); - cei = (*s)->eventlist.find(m_code); + if (cei == sess->eventlist.end()) { continue; } - if (cei == (*s)->eventlist.end()) { continue; } + if (cei.value().size() == 0) { continue; } - QVector &evlist = cei.value(); - - if (evlist.size() == 0) { continue; } - - drift = ((*s)->type() == MT_CPAP) ? clockdrift : 0; + drift = (sess->type() == MT_CPAP) ? clockdrift : 0; // Could loop through here, but nowhere uses more than one yet.. - for (int k = 0; k < evlist.size(); k++) { - EventList &el = *(evlist[k]); - count = el.count(); - stime = el.first() + drift; - dptr = el.rawData(); + for (const auto & el : cei.value()) { + count = el->count(); + stime = el->first() + drift; + dptr = el->rawData(); eptr = dptr + count; - tptr = el.rawTime(); + tptr = el->rawTime(); //////////////////////////////////////////////////////////////////////////// // Skip data previous to minx bounds @@ -352,22 +348,22 @@ void gLineOverlaySummary::paint(QPainter &painter, gGraph &w, const QRegion ® double sum = 0; bool isSpan = false; - for (int i = 0; i < m_overlays.size(); i++) { - cnt += m_overlays[i]->count(); - sum += m_overlays[i]->sum(); + for (const auto & lobar : m_overlays) { + cnt += lobar->count(); + sum += lobar->sum(); - if (m_overlays[i]->flagtype() == FT_Span) { isSpan = true; } + if (lobar->flagtype() == FT_Span) { isSpan = true; } } double val, first, last; double time = 0; // Calculate the session time. - for (QList::iterator s = m_day->begin(); s != m_day->end(); s++) { - if (!(*s)->enabled()) { continue; } + for (const auto & sess : m_day->sessions) { + if (!sess->enabled()) { continue; } - first = (*s)->first(); - last = (*s)->last(); + first = sess->first(); + last = sess->last(); if (last < w.min_x) { continue; } diff --git a/sleepyhead/Graphs/gSegmentChart.cpp b/sleepyhead/Graphs/gSegmentChart.cpp index a92ef36f..afa80789 100644 --- a/sleepyhead/Graphs/gSegmentChart.cpp +++ b/sleepyhead/Graphs/gSegmentChart.cpp @@ -1,4 +1,4 @@ -/* gSegmentChart Implementation +/* gSegmentChart Implementation * * Copyright (c) 2011-2018 Mark Watkins * @@ -33,13 +33,17 @@ void gSegmentChart::SetDay(Day *d) if (!m_day) { return; } - for (int c = 0; c < m_codes.size(); c++) { - m_values[c] = 0; - for (QList::iterator s = m_day->begin(); s != m_day->end(); ++s) { - if ((*s)->enabled() && (*s)->m_cnt.contains(m_codes[c])) { - EventDataType cnt = (*s)->count(m_codes[c]); - m_values[c] += cnt; + for (int c = 0; c < m_codes.size(); c++) { + auto & mval = m_values[c]; + auto & mcode = m_codes[c]; + + mval = 0; + + for (const auto & sess : m_day->sessions) { + if (sess->enabled() && sess->m_cnt.contains(mcode)) { + EventDataType cnt = sess->count(mcode); + mval += cnt; m_total += cnt; } } @@ -47,8 +51,8 @@ void gSegmentChart::SetDay(Day *d) m_empty = true; - for (int i = 0; i < m_codes.size(); i++) { - if (m_day->count(m_codes[i]) > 0) { + for (const auto & mc : m_codes) { + if (m_day->count(mc) > 0) { m_empty = false; break; } @@ -249,27 +253,25 @@ void gTAPGraph::SetDay(Day *d) EventDataType gain = 1, offset = 0; QHash >::iterator ei; - for (QList::iterator s = m_day->begin(); s != m_day->end(); ++s) { - if (!(*s)->enabled()) { continue; } + for (const auto & sess : m_day->sessions) { + if (!sess->enabled()) { continue; } - if ((ei = (*s)->eventlist.find(m_code)) == (*s)->eventlist.end()) { continue; } + ei = sess->eventlist.find(m_code); + if (ei == sess->eventlist.end()) { continue; } - for (int q = 0; q < ei.value().size(); q++) { - EventList &el = *(ei.value()[q]); - lasttime = el.time(0); - lastval = el.raw(0); + for (const auto & el : ei.value()) { + lasttime = el->time(0); + lastval = el->raw(0); if (rfirst) { - gain = el.gain(); - offset = el.offset(); + gain = el->gain(); + offset = el->offset(); rfirst = false; } - //first=true; - //changed=false; - for (quint32 i = 1; i < el.count(); i++) { - data = el.raw(i); - time = el.time(i); + for (quint32 i=1, end=el->count(); i < end; i++) { + data = el->raw(i); + time = el->time(i); if (lastval != data) { qint64 v = (time - lasttime); @@ -303,7 +305,7 @@ void gTAPGraph::SetDay(Day *d) m_total = 0; EventDataType val; - for (QMap::iterator i = tap.begin(); i != tap.end(); i++) { + for (auto i=tap.begin(), end=tap.end(); i != end; i++) { val = float(i.key()) * gain + offset; m_values.push_back(i.value() / 1000L); diff --git a/sleepyhead/Graphs/gSessionTimesChart.cpp b/sleepyhead/Graphs/gSessionTimesChart.cpp index dc16decc..386bfc37 100644 --- a/sleepyhead/Graphs/gSessionTimesChart.cpp +++ b/sleepyhead/Graphs/gSessionTimesChart.cpp @@ -77,7 +77,7 @@ void gSummaryChart::SetDay(Day *unused_day) QDate date = firstday; int idx = 0; do { - QMap::iterator di = p_profile->daylist.find(date); + auto di = p_profile->daylist.find(date); Day * day = nullptr; if (di != p_profile->daylist.end()) { day = di.value(); @@ -146,7 +146,7 @@ bool gSummaryChart::mouseReleaseEvent(QMouseEvent *event, gGraph *graph) date = date.addDays(idx); - QMap::iterator it = dayindex.find(date); + auto it = dayindex.find(date); if (it != dayindex.end()) { Day * day = daylist.at(it.value()); if (day) { @@ -162,8 +162,7 @@ void gSummaryChart::preCalc() { midcalc = p_profile->general->prefCalcMiddle(); - for (int i=0; i & slices) return; } float hour = day->hours(m_machtype); + for (int i=0; i < size; ++i) { const SummaryChartSlice & slice = slices.at(i); SummaryCalcItem & calc = calcitems[i]; @@ -208,8 +208,8 @@ void gSummaryChart::afterDraw(QPainter &painter, gGraph &graph, QRect rect) schema::Channel & chan = schema::channel[calcitems.at(0).code]; - for (int i=0; i & slices = cache[idx]; QString txt; - for (int i=0; i< slices.size(); ++i) { - SummaryChartSlice & slice = slices[i]; + const auto & slices = cache[idx]; + for (const auto & slice : slices) { txt += QString("\n%1: %2").arg(slice.name).arg(float(slice.value), 0, 'f', 2); } @@ -316,10 +315,8 @@ QString gSummaryChart::tooltipData(Day *, int idx) void gSummaryChart::populate(Day * day, int idx) { - int size = calcitems.size(); bool good = false; - for (int i=0; i < size; ++i) { - const SummaryCalcItem & item = calcitems.at(i); + for (const auto & item : calcitems) { if (day->hasData(item.code, item.type)) { good = true; break; @@ -327,12 +324,12 @@ void gSummaryChart::populate(Day * day, int idx) } if (!good) return; - QVector & slices = cache[idx]; + auto & slices = cache[idx]; float hours = day->hours(m_machtype); float base = 0; - for (int i=0; i < size; ++i) { - SummaryCalcItem & item = calcitems[i]; + + for (auto & item : calcitems) { ChannelID code = item.code; schema::Channel & chan = schema::channel[code]; float value = 0; @@ -413,7 +410,7 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io //float lasty1 = rect.bottom(); - QMap::iterator it = dayindex.find(date); + auto it = dayindex.find(date); idx_start = 0; if (it == dayindex.end()) { it = dayindex.begin(); @@ -423,7 +420,7 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io int idx = idx_start; - QMap::iterator ite = dayindex.find(enddate); + auto ite = dayindex.find(enddate); idx_end = daylist.size()-1; if (ite != dayindex.end()) { idx_end = ite.value(); @@ -486,7 +483,7 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io day->OpenSummary(); - QHash >::iterator cit = cache.find(i); + auto cit = cache.find(i); if (cit == cache.end()) { populate(day, i); @@ -494,11 +491,8 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io } if (cit != cache.end()) { - QVector & list = cit.value(); float base = 0, val; - int listsize = list.size(); - for (int j=0; j < listsize; ++j) { - SummaryChartSlice & slice = list[j]; + for (const auto & slice : cit.value()) { val = slice.height; base += val; } @@ -559,7 +553,7 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io hlday = true; } - QHash >::iterator cit = cache.find(idx); + auto cit = cache.find(idx); if (cit == cache.end()) { populate(day, idx); @@ -574,12 +568,9 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io QVector & list = cit.value(); customCalc(day, list); - int listsize = list.size(); QLinearGradient gradient(lastx1, 0, lastx1 + barw, 0); //rect.bottom(), barw, rect.bottom()); - for (int i=0; i < listsize; ++i) { - SummaryChartSlice & slice = list[i]; - + for (const auto & slice : list) { val = slice.height; y1 = ((lastval-miny) * ymult); y2 = (val * ymult); @@ -608,14 +599,11 @@ void gSummaryChart::paint(QPainter &painter, gGraph &graph, const QRegion ®io } lastval += val; - } - } lastx1 = x1; it++; - } while (++idx <= idx_end); painter.setPen(QPen(Qt::black,1)); painter.drawRects(outlines); @@ -756,11 +744,9 @@ void gSessionTimesChart::customCalc(Day *, QVector & slices) calc1.update(slices.size(), 1); EventDataType max = 0; - for (int i=0; iupdate(slice.height, slice.height); max = qMax(slice.height, max); } @@ -837,7 +823,7 @@ void gSessionTimesChart::paint(QPainter &painter, gGraph &graph, const QRegion & // float lasty1 = rect.bottom(); float lastx1 = rect.left(); - QMap::iterator it = dayindex.find(date); + auto it = dayindex.find(date); int idx=0; if (it == dayindex.end()) { @@ -846,7 +832,7 @@ void gSessionTimesChart::paint(QPainter &painter, gGraph &graph, const QRegion & idx = it.value(); } - QMap::iterator ite = dayindex.find(enddate); + auto ite = dayindex.find(enddate); int idx_end = daylist.size()-1; if (ite != dayindex.end()) { idx_end = ite.value(); @@ -860,14 +846,14 @@ void gSessionTimesChart::paint(QPainter &painter, gGraph &graph, const QRegion & int size = idx_end - idx; outlines.reserve(size * 5); - QMap::iterator it2 = it; + auto it2 = it; ///////////////////////////////////////////////////////////////////// /// Calculate Graph Peaks ///////////////////////////////////////////////////////////////////// peak_value = 0; min_value = 999; - QMap::iterator it_end = dayindex.end(); + auto it_end = dayindex.end(); float right_edge = (rect.left()+rect.width()+1); for (int i=idx; (i <= idx_end) && (it2 != it_end); ++i, ++it2, lastx1 += barw) { @@ -880,13 +866,12 @@ void gSessionTimesChart::paint(QPainter &painter, gGraph &graph, const QRegion & continue; } - QHash >::iterator cit = cache.find(i); + auto cit = cache.find(i); if (cit == cache.end()) { day->OpenSummary(); date = it2.key(); splittime = QDateTime(date, split); - QList::iterator si; QVector & slices = cache[i]; @@ -896,16 +881,13 @@ void gSessionTimesChart::paint(QPainter &painter, gGraph &graph, const QRegion & QString datestr = date.toString(Qt::SystemLocaleShortDate); - for (si = day->begin(); si != day->end(); ++si) { - Session *sess = (*si); + for (const auto & sess : day->sessions) { if (!sess->enabled() || (sess->type() != m_machtype)) continue; // Look at mask on/off slices... - int slize = sess->m_slices.size(); - if (slize > 0) { + if (sess->m_slices.size() > 0) { // segments - for (int j=0; jm_slices.at(j); + for (const auto & slice : sess->m_slices) { QDateTime st = QDateTime::fromMSecsSinceEpoch(slice.start, Qt::LocalTime); float s1 = float(splittime.secsTo(st)) / 3600.0; @@ -936,13 +918,9 @@ void gSessionTimesChart::paint(QPainter &painter, gGraph &graph, const QRegion & } if (cit != cache.end()) { - QVector & list = cit.value(); - int listsize = list.size(); - float peak = 0, base = 999; - for (int j=0; j < listsize; ++j) { - SummaryChartSlice & slice = list[j]; + for (const auto & slice : cit.value()) { float s1 = slice.value; float s2 = slice.height; @@ -994,7 +972,7 @@ void gSessionTimesChart::paint(QPainter &painter, gGraph &graph, const QRegion & continue; } - QHash >::iterator cit = cache.find(idx); + auto cit = cache.find(idx); float x1 = lastx1 + barw; @@ -1011,12 +989,10 @@ void gSessionTimesChart::paint(QPainter &painter, gGraph &graph, const QRegion & QVector & slices = cit.value(); customCalc(day, slices); - int size = slices.size(); QLinearGradient gradient(lastx1, rect.bottom(), lastx1+barw, rect.bottom()); - for (int i=0; i < size; ++i) { - const SummaryChartSlice & slice = slices.at(i); + for (const auto & slice : slices) { float s1 = slice.value - miny; float s2 = slice.height; @@ -1028,7 +1004,6 @@ void gSessionTimesChart::paint(QPainter &painter, gGraph &graph, const QRegion & QRect rec(lastx1, rect.bottom() - y1 - y2, barw, y2); rec = rec.intersected(rect); -// QBrush brush = slice.brush; if (rec.contains(mouse)) { col = Qt::yellow; graph.ToolTip(slice.name, mouse.x() - 15,mouse.y() + 15, TT_AlignRight); @@ -1068,6 +1043,7 @@ void gTTIAChart::preCalc() { gSummaryChart::preCalc(); } + void gTTIAChart::customCalc(Day *, QVector & slices) { if (slices.size() == 0) return; @@ -1075,13 +1051,12 @@ void gTTIAChart::customCalc(Day *, QVector & slices) calcitems[0].update(slice.value, slice.value); } + void gTTIAChart::afterDraw(QPainter &, gGraph &graph, QRect rect) { QStringList txtlist; - int num_channels = calcitems.size(); - for (int i=0; i < num_channels; ++i) { - SummaryCalcItem & calc = calcitems[i]; + for (auto & calc : calcitems) { //ChannelID code = calc.code; //schema::Channel & chan = schema::channel[code]; float mid = 0; @@ -1108,6 +1083,7 @@ void gTTIAChart::afterDraw(QPainter &, gGraph &graph, QRect rect) QString txt = txtlist.join(", "); graph.renderText(txt, rect.left(), rect.top()-5*graph.printScaleY(), 0); } + void gTTIAChart::populate(Day *day, int idx) { QVector & slices = cache[idx]; @@ -1116,9 +1092,8 @@ void gTTIAChart::populate(Day *day, int idx) int m = int(ttia) / 60 % 60; int s = int(ttia) % 60; slices.append(SummaryChartSlice(&calcitems[0], ttia / 60.0, ttia / 60.0, QObject::tr("\nTTIA: %1").arg(QString().sprintf("%02i:%02i:%02i",h,m,s)), QColor(255,147,150))); - - } + QString gTTIAChart::tooltipData(Day *, int idx) { QVector & slices = cache[idx]; @@ -1151,8 +1126,8 @@ void gAHIChart::customCalc(Day *day, QVector &list) if (size == 0) return; EventDataType hours = day->hours(m_machtype); EventDataType ahi_cnt = 0; - for (int i=0; i < size; ++i) { - SummaryChartSlice & slice = list[i]; + + for (auto & slice : list) { SummaryCalcItem * calc = slice.calc; EventDataType value = slice.value; @@ -1171,8 +1146,6 @@ void gAHIChart::customCalc(Day *day, QVector &list) break; } - - calc->min = qMin(valh, calc->min); calc->max = qMax(valh, calc->max); @@ -1220,10 +1193,7 @@ void gAHIChart::afterDraw(QPainter & /*painter */, gGraph &graph, QRect rect) QStringList txtlist; if (!skip) txtlist.append(QObject::tr("%1 %2 / %3 / %4").arg(STR_TR_AHI).arg(min_ahi, 0, 'f', 2).arg(med, 0, 'f', 2).arg(max_ahi, 0, 'f', 2)); - int num_channels = calcitems.size(); - - for (int i=0; i < num_channels; ++i) { - SummaryCalcItem & calc = calcitems[i]; + for (auto & calc : calcitems) { ChannelID code = calc.code; schema::Channel & chan = schema::channel[code]; float mid = 0; @@ -1260,10 +1230,8 @@ void gAHIChart::populate(Day *day, int idx) QVector & slices = cache[idx]; float hours = day->hours(); - int num_channels = calcitems.size(); - for (int i=0; i < num_channels; ++i) { - SummaryCalcItem & calc = calcitems[i]; + for (auto & calc : calcitems) { ChannelID code = calc.code; if (!day->hasData(code, ST_CNT)) continue; @@ -1279,11 +1247,9 @@ QString gAHIChart::tooltipData(Day *day, int idx) float total = 0; float hour = day->hours(m_machtype); QString txt; - for (int i=0; i< slices.size(); ++i) { - SummaryChartSlice & slice = slices[i]; + for (const auto & slice : slices) { total += slice.value; txt += QString("\n%1: %2").arg(slice.name).arg(float(slice.value) / hour, 0, 'f', 2); - } return QString("\n%1: %2").arg(STR_TR_AHI).arg(float(total) / hour,0,'f',2)+txt; } diff --git a/sleepyhead/Graphs/gSummaryChart.cpp b/sleepyhead/Graphs/gSummaryChart.cpp index 5c62ac59..50b9174b 100644 --- a/sleepyhead/Graphs/gSummaryChart.cpp +++ b/sleepyhead/Graphs/gSummaryChart.cpp @@ -125,9 +125,9 @@ void SummaryChart::SetDay(Day * nullday) bool first = true; // For each day in the main profile daylist - QMap::iterator d; - for (d = p_profile->daylist.begin(); d != p_profile->daylist.end(); d++) { + for (auto d=p_profile->daylist.begin(), dend=p_profile->daylist.end(); d!=dend; ++d) { + Day * day = d.value(); // get the timestamp of this day. tt = QDateTime(d.key(), QTime(0, 0, 0), Qt::UTC).toTime_t(); @@ -155,7 +155,6 @@ void SummaryChart::SetDay(Day * nullday) } // for each day object on record for this date - day = d.value(); // skip any empty or irrelevant day records if (!day || (day->machine(m_machinetype) == nullptr)) { continue; } @@ -168,7 +167,7 @@ void SummaryChart::SetDay(Day * nullday) // ft = first sessions time, rounded back to midnight.. // For each session in this day record - for (int s = 0; s < day->size(); s++) { + for (int s=0, size=day->size(); s < size; s++) { Session *sess = (*day)[s]; if (!sess->enabled()) { continue; } @@ -366,8 +365,8 @@ void SummaryChart::SetDay(Day * nullday) m_empty = true; - for (int i = 0; i < m_goodcodes.size(); i++) { - if (m_goodcodes[i]) { + for (const auto & goodcode : m_goodcodes) { + if (goodcode) { m_empty = false; break; } @@ -486,7 +485,7 @@ void SummaryChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) lastY.resize(numcodes); int zd = minx / 86400000L; zd--; - QHash >::iterator d = m_values.find(zd); + auto d = m_values.find(zd); QVector goodcodes; goodcodes.resize(m_goodcodes.size()); @@ -619,7 +618,7 @@ void SummaryChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) if (graphtype == GT_SESSIONS) { int j; - QHash >::iterator times = m_times.find(zd); + auto times = m_times.find(zd); QColor col = m_colors[0]; //if (hours 0) { - for (int i = 0; i < goodcodes.size(); i++) { - goodcodes[i] = true; + for (auto & goodcode : goodcodes) { + goodcode = true; } } @@ -695,7 +694,7 @@ void SummaryChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) bool good; SummaryType type; - for (QMap::iterator g = d.value().begin(); g != d.value().end(); g++) { + for (auto g=d.value().begin(), dend=d.value().end(); g != dend; g++) { short j = g.key(); if (!j) { continue; } @@ -1077,7 +1076,7 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph) hl_day = zd; graph->Trigger(2000); - QHash >::iterator d = m_values.find(hl_day); + auto d = m_values.find(hl_day); QMap &valhash = d.value(); diff --git a/sleepyhead/SleepLib/calcs.cpp b/sleepyhead/SleepLib/calcs.cpp index d00bcbb2..c53527eb 100644 --- a/sleepyhead/SleepLib/calcs.cpp +++ b/sleepyhead/SleepLib/calcs.cpp @@ -1,4 +1,4 @@ -/* Custom CPAP/Oximetry Calculations Header +/* Custom CPAP/Oximetry Calculations Header * * Copyright (c) 2011-2018 Mark Watkins * @@ -19,8 +19,7 @@ bool SearchEvent(Session * session, ChannelID code, qint64 time, int dur, bool update=true) { qint64 t, start; - QHash >::iterator it; - it = session->eventlist.find(code); + auto it = session->eventlist.find(code); quint32 *tptr; EventStoreType *dptr; @@ -34,12 +33,10 @@ bool SearchEvent(Session * session, ChannelID code, qint64 time, int dur, bool u update=false; } - QHash >::iterator evend = session->eventlist.end(); + auto evend = session->eventlist.end(); if (it != evend) { - int el_size=it.value().size(); - for (int i = 0; i < el_size; i++) { - EventList *el = it.value()[i]; - // rate=el->rate(); + for (const auto & el : it.value()) { + //rate=el->rate(); cnt = el->count(); // why would this be necessary??? @@ -901,30 +898,22 @@ void calcRespRate(Session *session, FlowParser *flowparser) calcTv = calcMv = calcResp = true; } - QVector &list = session->eventlist[CPAP_RespRate]; - int size = list.size(); - for (int i = 0; i < size; ++i) { - delete list[i]; + auto & list = session->eventlist[CPAP_RespRate]; + for (auto & l : list) { + delete l; } - session->eventlist[CPAP_RespRate].clear(); - QVector &list2 = session->eventlist[CPAP_TidalVolume]; - - size = list2.size(); - for (int i = 0; i < size; ++i) { - delete list2[i]; + auto & list2 = session->eventlist[CPAP_TidalVolume]; + for (auto & l2 : list2) { + delete l2; } - session->eventlist[CPAP_TidalVolume].clear(); - QVector &list3 = session->eventlist[CPAP_MinuteVent]; - - size = list3.size(); - for (int i = 0; i < size; ++i) { - delete list3[i]; + auto & list3 = session->eventlist[CPAP_MinuteVent]; + for (auto & l3 : list3) { + delete l3; } - session->eventlist[CPAP_MinuteVent].clear(); } @@ -936,14 +925,9 @@ void calcRespRate(Session *session, FlowParser *flowparser) //flowparser->addFilter(FilterPercentile,7,0.5); //flowparser->addFilter(FilterPercentile,5,0.5); //flowparser->addFilter(FilterXPass,0.5); - EventList *flow; - - QVector &EVL = session->eventlist[CPAP_FlowRate]; - int size = EVL.size(); - - for (int ws = 0; ws < size; ++ws) { - flow = EVL[ws]; + auto & EVL = session->eventlist[CPAP_FlowRate]; + for (auto & flow : EVL) { if (flow->count() > 20) { flowparser->openFlow(session, flow); flowparser->calc(calcResp, calcTv, calcTi , calcTe, calcMv); @@ -1258,19 +1242,15 @@ void zMaskProfile::save() void zMaskProfile::scanPressureList(Session *session, ChannelID code) { - QHash >::iterator it = session->eventlist.find(code); - + auto it = session->eventlist.find(code); if (it == session->eventlist.end()) return; int prescnt = session->count(code); Pressure.reserve(Pressure.size() + prescnt); - QVector &EVL = it.value(); - int size = EVL.size(); - - for (int j = 0; j < size; ++j) { - EventList * el = EVL[j]; + auto & EVL = it.value(); + for (const auto & el : EVL) { qint64 start = el->first(); int count = el->count(); EventStoreType *dptr = el->rawData(); @@ -1310,7 +1290,6 @@ void zMaskProfile::scanLeakList(EventList *el) EventStoreType pressure, leak; //EventDataType fleak; - // QMap::iterator pmin; qint64 ti; bool found; @@ -1386,25 +1365,17 @@ void zMaskProfile::scanLeakList(EventList *el) } void zMaskProfile::scanLeaks(Session *session) { - QHash >::iterator ELV = session->eventlist.find(CPAP_LeakTotal); - + auto ELV = session->eventlist.find(CPAP_LeakTotal); if (ELV == session->eventlist.end()) return; - QVector &elv = ELV.value(); - int size=elv.size(); - if (!size) - return; + auto & elv = ELV.value(); - QVector::iterator end = elv.end(); - QVector::iterator it; - for (it = elv.begin(); it != end; ++it) { - scanLeakList(*it); + for (auto & it : elv) { + scanLeakList(it); } } void zMaskProfile::updatePressureMin() { - QMap >::iterator it; - EventStoreType pressure; //EventDataType perc=0.1; //EventDataType tmp,l1,l2; @@ -1418,22 +1389,16 @@ void zMaskProfile::updatePressureMin() int sum1, sum2, w1, w2, N, k; - - QMap >::iterator plend = pressureleaks.end(); - - QMap::iterator lmend; - // Calculate a weighted percentile of all leak values contained within each pressure, using pressureleaks histogram - - for (it = pressureleaks.begin(); it != plend; it++) { + for (auto it = pressureleaks.begin(), plend=pressureleaks.end(); it != plend; it++) { pressure = it.key(); QMap &leakmap = it.value(); //lks = leakmap.size(); SN = 0; + auto lmend = leakmap.end(); // First sum total counts of all leaks - lmend = leakmap.end(); - for (QMap::iterator lit = leakmap.begin(); lit != lmend; ++lit) { + for (auto lit = leakmap.begin(); lit != lmend; ++lit) { SN += lit.value(); } @@ -1453,14 +1418,14 @@ void zMaskProfile::updatePressureMin() double total = 0; // why do this effectively twice? and k = size - for (QMap::iterator lit = leakmap.begin(); lit != lmend; ++lit, ++k) { + for (auto lit = leakmap.begin(); lit != lmend; ++lit, ++k) { total += lit.value(); } pressuretotal[pressure] = total; k = 0; - for (QMap::iterator lit = leakmap.begin(); lit != lmend; ++lit, ++k) { + for (auto lit=leakmap.begin(); lit != lmend; ++lit, ++k) { //for (k=0;k < N;k++) { v1 = lit.key(); w1 = lit.value(); @@ -1573,8 +1538,8 @@ void zMaskProfile::updateProfile(Session *session) EventDataType maxcnt, maxval, lastval; //, lastcnt; - QMap >::iterator plend = pressureleaks.end(); - QMap >::iterator it = pressureleaks.begin(); + auto plend = pressureleaks.end(); + auto it = pressureleaks.begin(); QMap::iterator lit; QMap::iterator lvend; @@ -1634,13 +1599,12 @@ void zMaskProfile::updateProfile(Session *session) QMap pressureval2; EventDataType max = 0, tmp2, tmp3; - QMap::iterator ptit; - QMap::iterator ptend = pressuretotal.end(); - for (ptit = pressuretotal.begin(); ptit != ptend; ++ptit) { + auto ptend = pressuretotal.end(); + for (auto ptit = pressuretotal.begin(); ptit != ptend; ++ptit) { if (max < ptit.value()) { max = ptit.value(); } } - for (ptit = pressuretotal.begin(); ptit != pressuretotal.end(); ptit++) { + for (auto ptit = pressuretotal.begin(); ptit != ptend; ptit++) { p = ptit.key(); tmp = pressurecount[p]; tmp2 = ptit.value(); @@ -1674,7 +1638,7 @@ void zMaskProfile::updateProfile(Session *session) m_factor = (maxL - minL) / (maxP - minP); - // for (QMap::iterator it=pressuremin.begin();it!=pressuremin.end()-1;it++) { + // for (auto it=pressuremin.begin();it!=pressuremin.end()-1;it++) { // p1=it.key(); // p2=(it+1).key(); // l1=it.value(); @@ -1695,7 +1659,7 @@ void zMaskProfile::updateProfile(Session *session) // QTextStream out(&f); // EventDataType p,l,c; // QString fmt; - // for (QMap::iterator it=pressuremin.begin();it!=pressuremin.end();it++) { + // for (auto it=pressuremin.begin();it!=pressuremin.end();it++) { // p=EventDataType(it.key()/10.0); // l=it.value(); // fmt=QString("%1,%2\n").arg(p,0,'f',1).arg(l); @@ -1703,9 +1667,9 @@ void zMaskProfile::updateProfile(Session *session) // } // cruft - // for (QMap >::iterator it=pressureleaks.begin();it!=pressureleaks.end();it++) { - // QMap & leakval=it.value(); - // for (QMap::iterator lit=leakval.begin();lit!=leakval.end();lit++) { + // for (auto it=pressureleaks.begin();it!=pressureleaks.end();it++) { + // auto & leakval=it.value(); + // for (auto lit=leakval.begin();lit!=leakval.end();lit++) { // l=lit.key(); // c=lit.value(); // fmt=QString("%1,%2,%3\n").arg(p,0,'f',2).arg(l).arg(c); @@ -1746,8 +1710,7 @@ int calcLeaks(Session *session) EventList *leak = session->AddEventList(CPAP_Leak, EVL_Event, 1); - QVector & EVL = session->eventlist[CPAP_LeakTotal]; - int evlsize = EVL.size(); + auto & EVL = session->eventlist[CPAP_LeakTotal]; TimeValue *p2, *pstr, *pend; @@ -1757,17 +1720,20 @@ int calcLeaks(Session *session) pend = maskProfile->Pressure.data()+(mppressize-1); // For each sessions Total Leaks list - for (int i = 0; i < evlsize; ++i) { - EventList &el = *EVL[i]; - EventDataType gain = el.gain(), tmp, val; - int count = el.count(); - EventStoreType *dptr = el.rawData(); - EventStoreType *eptr = dptr + count; - quint32 *tptr = el.rawTime(); - qint64 start = el.first(), ti; - EventStoreType pressure; + EventDataType gain, tmp, val; + int count; + EventStoreType *dptr, *eptr, pressure; + quint32 * tptr; + qint64 start, ti; + bool found; - bool found; + for (auto & el : EVL) { + gain = el->gain(); + count = el->count(); + dptr = el->rawData(); + eptr = dptr + count; + tptr = el->rawTime(); + start = el->first(); // Scan through this Total Leak list's data for (; dptr < eptr; ++dptr) { @@ -1834,21 +1800,21 @@ void flagLargeLeaks(Session *session) EventList * LL = nullptr; qint64 time = 0; - EventDataType lastvalue=-1; + EventDataType value, lastvalue=-1; qint64 leaktime=0; - for (int ec = 0; ec < evlsize; ++ec) { - EventList &el = *EVL[ec]; - int count = el.count(); + int count; + + for (auto & el : EVL) { + count = el->count(); if (!count) continue; leaktime = 0; //EventDataType leakvalue = 0; lastvalue = -1; - for (int i=0; i < count; ++i) { - time = el.time(i); - EventDataType value = el.data(i); + time = el->time(i); + value = el->data(i); if (value >= threshold) { if (lastvalue < threshold) { leaktime = time; @@ -1879,7 +1845,7 @@ int calcPulseChange(Session *session) { if (session->eventlist.contains(OXI_PulseChange)) { return 0; } - QHash >::iterator it = session->eventlist.find(OXI_Pulse); + auto it = session->eventlist.find(OXI_Pulse); if (it == session->eventlist.end()) { return 0; } @@ -1898,26 +1864,23 @@ int calcPulseChange(Session *session) int max; - int size = it.value().size(); - for (int e = 0; e < size; ++e) { - EventList &el = *(it.value()[e]); - - int elcount=el.count(); + int elcount; + for (auto & el : it.value()) { + elcount = el->count(); for (int i = 0; i < elcount; ++i) { - val = el.data(i); - time = el.time(i); - + val = el->data(i); + time = el->time(i); lastt = 0; lv = change; max = 0; for (int j = i + 1; j < elcount; ++j) { // scan ahead in the window - time2 = el.time(j); + time2 = el->time(j); if (time2 > time + window) { break; } - val2 = el.data(j); + val2 = el->data(j); tmp = qAbs(val2 - val); if (tmp > lv) { @@ -1958,8 +1921,7 @@ int calcSPO2Drop(Session *session) { if (session->eventlist.contains(OXI_SPO2Drop)) { return 0; } - QHash >::iterator it = session->eventlist.find(OXI_SPO2); - + auto it = session->eventlist.find(OXI_SPO2); if (it == session->eventlist.end()) { return 0; } EventDataType val, val2, change, tmp; @@ -1987,14 +1949,12 @@ int calcSPO2Drop(Session *session) // Calculate median baseline QList med; - int evsize = it.value().size(); - for (int e = 0; e < evsize; ++e) { - EventList &el = *(it.value()[e]); - - int elcount = el.count(); + int elcount; + for (auto & el : it.value()) { + elcount = el->count(); for (int i = 0; i < elcount; i++) { - val = el.data(i); - time = el.time(i); + val = el->data(i); + time = el->time(i); if (val > 0) { med.push_back(val); } @@ -2026,16 +1986,14 @@ int calcSPO2Drop(Session *session) EventDataType current; qDebug() << "Calculated baseline" << baseline; - for (int e = 0; e < evsize; ++e) { - EventList &el = *(it.value()[e]); - - int elcount = el.count(); + for (auto & el : it.value()) { + elcount = el->count(); for (int i = 0; i < elcount; ++i) { - current = el.data(i); + current = el->data(i); if (!current) { continue; } - time = el.time(i); + time = el->time(i); /*ring[rp]=val; rtime[rp]=time; rp++; @@ -2067,9 +2025,9 @@ int calcSPO2Drop(Session *session) min = val; for (int j = i; j < elcount; ++j) { // scan ahead in the window - time2 = el.time(j); + time2 = el->time(j); //if (time2 > time+window) break; - val2 = el.data(j); + val2 = el->data(j); if (val2 > baseline - change) { break; } diff --git a/sleepyhead/SleepLib/day.cpp b/sleepyhead/SleepLib/day.cpp index 9baf3c2d..601e4e3d 100644 --- a/sleepyhead/SleepLib/day.cpp +++ b/sleepyhead/SleepLib/day.cpp @@ -26,8 +26,8 @@ Day::Day() } Day::~Day() { - for (QList::iterator s = sessions.begin(); s != sessions.end(); ++s) { - delete(*s); + for (auto & sess : sessions) { + delete sess; } } @@ -38,9 +38,7 @@ void Day::updateCPAPCache() OpenSummary(); QList channels = getSortedMachineChannels(MT_CPAP, schema::FLAG | schema::MINOR_FLAG | schema::SPAN); - int num_channels = channels.size(); - for (int i=0; i< num_channels; ++i) { - ChannelID code = channels.at(i); + for (const auto code : channels) { d_count[code] = count(code); d_sum[code] = count(code); d_machhours[MT_CPAP] = hours(MT_CPAP); @@ -49,8 +47,7 @@ void Day::updateCPAPCache() Session * Day::firstSession(MachineType type) { - for (int i=0; ienabled()) continue; if (sess->type() == type) { return sess; @@ -70,7 +67,7 @@ bool Day::addMachine(Machine *mach) } Machine *Day::machine(MachineType type) { - QHash::iterator it = machines.find(type); + auto it = machines.find(type); if (it != machines.end()) return it.value(); return nullptr; @@ -78,31 +75,25 @@ Machine *Day::machine(MachineType type) QList Day::getSessions(MachineType type, bool ignore_enabled) { - QList::iterator it; - QList::iterator sess_end = sessions.end(); - QList newlist; - for (it = sessions.begin(); it != sess_end; ++it) { - if (!ignore_enabled && !(*it)->enabled()) + for (auto & sess : sessions) { + if (!ignore_enabled && !sess->enabled()) continue; - if ((*it)->type() == type) - newlist.append((*it)); + if (sess->type() == type) + newlist.append(sess); } - return newlist; } Session *Day::find(SessionID sessid) { - QList::iterator end=sessions.end(); - for (QList::iterator s = sessions.begin(); s != end; ++s) { - if ((*s)->session() == sessid) { - return (*s); + for (auto & sess : sessions) { + if (sess->session() == sessid) { + return sess; } } - return nullptr; } @@ -113,8 +104,7 @@ void Day::addSession(Session *s) return; } invalidate(); - QHash::iterator mi = machines.find(s->type()); - + auto mi = machines.find(s->type()); if (mi != machines.end()) { if (mi.value() != s->machine()) { qDebug() << "SleepyHead can't add session" << s->session() << "to this day record, as it already contains a different machine of the same MachineType"; @@ -170,13 +160,10 @@ QString Day::calcPercentileLabel(ChannelID code) EventDataType Day::countInsideSpan(ChannelID span, ChannelID code) { - QList::iterator end = sessions.end(); int count = 0; - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - - if (sess.enabled()) { - count += sess.countInsideSpan(span, code); + for (auto & sess : sessions) { + if (sess->enabled()) { + count += sess->countInsideSpan(span, code); } } return count; @@ -184,14 +171,11 @@ EventDataType Day::countInsideSpan(ChannelID span, ChannelID code) EventDataType Day::lookupValue(ChannelID code, qint64 time, bool square) { - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - - if (sess.enabled()) { - if ((time > sess.first()) && (time < sess.last())) { - if (sess.channelExists(code)) { - return sess.SearchValue(code,time,square); + for (auto & sess : sessions) { + if (sess->enabled()) { + if ((time > sess->first()) && (time < sess->last())) { + if (sess->channelExists(code)) { + return sess->SearchValue(code,time,square); } } } @@ -204,15 +188,11 @@ EventDataType Day::timeAboveThreshold(ChannelID code, EventDataType threshold) { EventDataType val = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - - if (sess.enabled() && sess.m_availableChannels.contains(code)) { - val += sess.timeAboveThreshold(code,threshold); + for (auto & sess : sessions) { + if (sess->enabled() && sess->m_availableChannels.contains(code)) { + val += sess->timeAboveThreshold(code,threshold); } } - return val; } @@ -220,15 +200,11 @@ EventDataType Day::timeBelowThreshold(ChannelID code, EventDataType threshold) { EventDataType val = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - - if (sess.enabled()) { - val += sess.timeBelowThreshold(code,threshold); + for (auto & sess : sessions) { + if (sess->enabled()) { + val += sess->timeBelowThreshold(code,threshold); } } - return val; } @@ -237,19 +213,14 @@ EventDataType Day::settings_sum(ChannelID code) { EventDataType val = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - - if (sess.enabled()) { - QHash::iterator set = sess.settings.find(code); - - if (set != sess.settings.end()) { + for (auto & sess : sessions) { + if (sess->enabled()) { + auto set = sess->settings.find(code); + if (set != sess->settings.end()) { val += set.value().toDouble(); } } } - return val; } @@ -259,17 +230,14 @@ EventDataType Day::settings_max(ChannelID code) EventDataType max = min; EventDataType value; - QList::iterator end = sessions.end(); - for(QList::iterator it = sessions.begin(); it < end; ++it) { - Session &sess = *(*it); - if (sess.enabled()) { - value = sess.settings.value(code, min).toFloat(); + for (auto & sess : sessions) { + if (sess->enabled()) { + value = sess->settings.value(code, min).toFloat(); if (value > max) { max = value; } } } - return max; } @@ -279,18 +247,14 @@ EventDataType Day::settings_min(ChannelID code) EventDataType min = max; EventDataType value; - QList::iterator end=sessions.end(); - - for(QList::iterator it = sessions.begin(); it < end; ++it) { - Session &sess = *(*it); - if (sess.enabled()) { - value = sess.settings.value(code, max).toFloat(); + for (auto & sess : sessions) { + if (sess->enabled()) { + value = sess->settings.value(code, max).toFloat(); if (value < min) { min = value; } } } - return min; } @@ -299,19 +263,16 @@ EventDataType Day::settings_avg(ChannelID code) EventDataType val = 0; int cnt = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; it++) { - Session &sess = *(*it); - if (sess.enabled()) { - QHash::iterator set = sess.settings.find(code); + for (auto & sess : sessions) { + if (sess->enabled()) { + auto set = sess->settings.find(code); - if (set != sess.settings.end()) { + if (set != sess->settings.end()) { val += set.value().toDouble(); cnt++; } } } - val = (cnt > 0) ? (val / EventDataType(cnt)) : val; return val; @@ -321,22 +282,18 @@ EventDataType Day::settings_wavg(ChannelID code) { double s0 = 0, s1 = 0, s2 = 0, tmp; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; it++) { - Session &sess = *(*it); + for (auto & sess : sessions) { + if (sess->enabled()) { + auto set = sess->settings.find(code); - if (sess.enabled()) { - QHash::iterator set = sess.settings.find(code); - - if (set != sess.settings.end()) { - s0 = sess.hours(); + if (set != sess->settings.end()) { + s0 = sess->hours(); tmp = set.value().toDouble(); s1 += tmp * s0; s2 += s0; } } } - if (s2 == 0) { return 0; } tmp = (s1 / s2); @@ -366,18 +323,15 @@ EventDataType Day::percentile(ChannelID code, EventDataType percentile) // First Calculate count of all events bool timeweight; - QList::iterator sess_end = sessions.end(); - for (QList::iterator sess_it = sessions.begin(); sess_it != sess_end; ++sess_it) { - Session &sess = *(*sess_it); - if (!sess.enabled()) { continue; } + for (auto & sess : sessions) { + if (!sess->enabled()) { continue; } - QHash >::iterator ei = sess.m_valuesummary.find(code); + auto ei = sess->m_valuesummary.find(code); + if (ei == sess->m_valuesummary.end()) { continue; } - if (ei == sess.m_valuesummary.end()) { continue; } - - QHash >::iterator tei = sess.m_timesummary.find(code); - timeweight = (tei != sess.m_timesummary.end()); - gain = sess.m_gain[code]; + auto tei = sess->m_timesummary.find(code); + timeweight = (tei != sess->m_timesummary.end()); + gain = sess->m_gain[code]; // Here's assuming gains don't change accross a days sessions // Can't assume this in any multi day calculations.. @@ -393,20 +347,17 @@ EventDataType Day::percentile(ChannelID code, EventDataType percentile) //qint64 tval; if (timeweight) { - QHash::iterator teival_end = tei.value().end(); wmap.reserve(wmap.size() + tei.value().size()); - for (QHash::iterator it = tei.value().begin(); it != teival_end; ++it) { + for (auto it = tei.value().begin(), teival_end=tei.value().end(); it != teival_end; ++it) { weight = it.value(); SN += weight; wmap[it.key()] += weight; } } else { - QHash::iterator eival_end = ei.value().end(); - wmap.reserve(wmap.size() + ei.value().size()); - for (QHash::iterator it = ei.value().begin(); it != eival_end; ++it) { + for (auto it = ei.value().begin(), eival_end=ei.value().end(); it != eival_end; ++it) { weight = it.value(); SN += weight; @@ -421,9 +372,9 @@ EventDataType Day::percentile(ChannelID code, EventDataType percentile) valcnt.resize(wmap.size()); // Build sorted list of value/counts - QHash::iterator wmap_end = wmap.end(); + auto wmap_end = wmap.end(); int ii=0; - for (QHash::iterator it = wmap.begin(); it != wmap_end; ++it) { + for (auto it = wmap.begin(); it != wmap_end; ++it) { valcnt[ii++]=ValueCount(EventDataType(it.key()) * gain, it.value(), 0); } @@ -493,12 +444,9 @@ EventDataType Day::rangeCount(ChannelID code, qint64 st, qint64 et) { int cnt = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - - if (sess.enabled()) { - cnt += sess.rangeCount(code, st, et); + for (auto & sess : sessions) { + if (sess->enabled()) { + cnt += sess->rangeCount(code, st, et); } } @@ -508,12 +456,9 @@ EventDataType Day::rangeSum(ChannelID code, qint64 st, qint64 et) { double val = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - - if (sess.enabled()) { - val += sess.rangeSum(code, st, et); + for (auto & sess : sessions) { + if (sess->enabled()) { + val += sess->rangeSum(code, st, et); } } @@ -524,16 +469,12 @@ EventDataType Day::rangeAvg(ChannelID code, qint64 st, qint64 et) double val = 0; int cnt = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - - if (sess.enabled()) { - val += sess.rangeSum(code, st, et); - cnt += sess.rangeCount(code, st,et); + for (auto & sess : sessions) { + if (sess->enabled()) { + val += sess->rangeSum(code, st, et); + cnt += sess->rangeCount(code, st,et); } } - if (cnt == 0) { return 0; } val /= double(cnt); @@ -543,30 +484,26 @@ EventDataType Day::rangeWavg(ChannelID code, qint64 st, qint64 et) { double sum = 0; double cnt = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - QHash >::iterator EVEC = sess.eventlist.find(code); - if (EVEC == sess.eventlist.end()) continue; + qint64 lasttime, time; + double data, duration; - QVector::iterator EL; - QVector::iterator EVEC_end = EVEC.value().end(); - for (EL = EVEC.value().begin(); EL != EVEC_end; ++EL) { - EventList * el = *EL; + for (auto & sess : sessions) { + auto EVEC = sess->eventlist.find(code); + if (EVEC == sess->eventlist.end()) continue; + + for (auto & el : EVEC.value()) { if (el->count() < 1) continue; - //EventDataType lastdata = el->data(0); - qint64 lasttime = el->time(0); + lasttime = el->time(0); if (lasttime < st) lasttime = st; for (unsigned i=1; icount(); i++) { - double data = el->data(i); - qint64 time = el->time(i); + data = el->data(i); + time = el->time(i); if (time < st) { lasttime = st; - //lastdata = data; continue; } @@ -574,14 +511,13 @@ EventDataType Day::rangeWavg(ChannelID code, qint64 st, qint64 et) time = et; } - double duration = double(time - lasttime) / 1000.0; + duration = double(time - lasttime) / 1000.0; sum += data * duration; cnt += duration; if (time >= et) break; lasttime = time; - //lastdata = data; } } } @@ -598,19 +534,15 @@ EventDataType Day::rangePercentile(ChannelID code, float p, qint64 st, qint64 et QVector list; list.resize(count); int idx = 0; + qint64 time; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - QHash >::iterator EVEC = sess.eventlist.find(code); - if (EVEC == sess.eventlist.end()) continue; + for (auto & sess : sessions) { + auto EVEC = sess->eventlist.find(code); + if (EVEC == sess->eventlist.end()) continue; - QVector::iterator EL; - QVector::iterator EVEC_end = EVEC.value().end(); - for (EL = EVEC.value().begin(); EL != EVEC_end; ++EL) { - EventList * el = *EL; + for (auto & el : EVEC.value()) { for (unsigned i=0; icount(); i++) { - qint64 time = el->time(i); + time = el->time(i); if ((time < st) || (time > et)) continue; list[idx++] = el->data(i); } @@ -646,16 +578,12 @@ EventDataType Day::avg(ChannelID code) // Cache this? int cnt = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - - if (sess.enabled()) { - val += sess.sum(code); - cnt += sess.count(code); + for (auto & sess : sessions) { + if (sess->enabled()) { + val += sess->sum(code); + cnt += sess->count(code); } } - if (cnt == 0) { return 0; } val /= double(cnt); @@ -667,12 +595,9 @@ EventDataType Day::sum(ChannelID code) // Cache this? EventDataType val = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - - if (sess.enabled() && sess.m_sum.contains(code)) { - val += sess.sum(code); + for (auto & sess : sessions) { + if (sess->enabled() && sess->m_sum.contains(code)) { + val += sess->sum(code); } } @@ -684,17 +609,13 @@ EventDataType Day::wavg(ChannelID code) double s0 = 0, s1 = 0, s2 = 0; qint64 d; - QList::iterator end = sessions.end(); - - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - - if (sess.enabled() && sess.m_wavg.contains(code)) { - d = sess.length(); //.last(code)-sess.first(code); + for (auto & sess : sessions) { + if (sess->enabled() && sess->m_wavg.contains(code)) { + d = sess->length(); s0 = double(d) / 3600000.0; if (s0 > 0) { - s1 += sess.wavg(code) * s0; + s1 += sess->wavg(code) * s0; s2 += s0; } } @@ -717,25 +638,23 @@ qint64 Day::total_time() // Remember sessions may overlap.. qint64 first, last; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - int slicesize = sess.m_slices.size(); - if (sess.enabled() && (sess.type() != MT_JOURNAL)) { - first = sess.first(); - last = sess.last(); + for (auto & sess : sessions) { + int slicesize = sess->m_slices.size(); + + if (sess->enabled() && (sess->type() != MT_JOURNAL)) { + first = sess->first(); + last = sess->last(); if (slicesize == 0) { // This algorithm relies on non zero length, and correctly ordered sessions if (last > first) { range.insert(first, 0); range.insert(last, 1); - d_totaltime += sess.length(); + d_totaltime += sess->length(); } } else { - for (int i=0; im_slices) { if (slice.status == EquipmentOn) { range.insert(slice.start, 0); range.insert(slice.end, 1); @@ -754,8 +673,8 @@ qint64 Day::total_time() // This is my implementation of a typical "brace counting" algorithm mentioned here: // http://stackoverflow.com/questions/7468948/problem-calculating-overlapping-date-ranges - QMultiMap::iterator rend = range.end(); - for (QMultiMap::iterator rit = range.begin(); rit != rend; ++rit) { + auto rend = range.end(); + for (auto rit = range.begin(); rit != rend; ++rit) { b = rit.value(); if (!b) { @@ -790,25 +709,22 @@ qint64 Day::total_time(MachineType type) // Remember sessions may overlap.. qint64 first, last; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session &sess = *(*it); - int slicesize = sess.m_slices.size(); + for (auto & sess : sessions) { + int slicesize = sess->m_slices.size(); - if (sess.enabled() && (sess.type() == type)) { - first = sess.first(); - last = sess.last(); + if (sess->enabled() && (sess->type() == type)) { + first = sess->first(); + last = sess->last(); // This algorithm relies on non zero length, and correctly ordered sessions if (slicesize == 0) { if (last > first) { range.insert(first, 0); range.insert(last, 1); - d_totaltime += sess.length(); + d_totaltime += sess->length(); } } else { - for (int i=0; im_slices) { if (slice.status == EquipmentOn) { range.insert(slice.start, 0); range.insert(slice.end, 1); @@ -827,8 +743,8 @@ qint64 Day::total_time(MachineType type) // This is my implementation of a typical "brace counting" algorithm mentioned here: // http://stackoverflow.com/questions/7468948/problem-calculating-overlapping-date-ranges - QMultiMap::iterator rend = range.end(); - for (QMultiMap::iterator rit = range.begin(); rit != rend; ++rit) { + auto rend = range.end(); + for (auto rit = range.begin(); rit != rend; ++rit) { b = rit.value(); if (!b) { @@ -856,27 +772,21 @@ qint64 Day::total_time(MachineType type) bool Day::hasEnabledSessions() { - QList::iterator end = sessions.end(); - - for (QList::iterator it = sessions.begin(); it != end; ++it) { - if ((*it)->enabled()) { + for (auto & sess : sessions) { + if (sess->enabled()) { return true; } } - return false; } bool Day::hasEnabledSessions(MachineType type) { - QList::iterator end = sessions.end(); - - for (QList::iterator it = sessions.begin(); it != end; ++it) { - if (((*it)->type() == type) && (*it)->enabled()) { + for (auto & sess : sessions) { + if ((sess->type() == type) && sess->enabled()) { return true; } } - return false; } @@ -885,10 +795,9 @@ bool Day::hasEnabledSessions(MachineType type) double val=0; int cnt=0; - for (QList::iterator s=sessions.begin();s!=sessions.end();s++) { - Session & sess=*(*s); - if (sess.eventlist.find(code)!=sess.eventlist.end()) { - val+=sess.percentile(code,percent); + for (auto & sess : sessions) { + if (sess->eventlist.find(code)!=sess->eventlist.end()) { + val+=sess->percentile(code,percent); cnt++; } } @@ -902,12 +811,9 @@ qint64 Day::first(ChannelID code) qint64 date = 0; qint64 tmp; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess=*(*it); - - if (sess.enabled()) { - tmp = sess.first(code); + for (auto & sess : sessions) { + if (sess->enabled()) { + tmp = sess->first(code); if (!tmp) { continue; } @@ -927,12 +833,9 @@ qint64 Day::last(ChannelID code) qint64 date = 0; qint64 tmp; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; it++) { - Session & sess = *(*it); - - if (sess.enabled()) { - tmp = sess.last(code); + for (auto & sess : sessions) { + if (sess->enabled()) { + tmp = sess->last(code); if (!tmp) { continue; } @@ -953,13 +856,10 @@ EventDataType Day::Min(ChannelID code) EventDataType tmp; bool first = true; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; it++) { - Session & sess = *(*it); + for (auto & sess : sessions) { + if (sess->enabled() && sess->m_min.contains(code)) { - if (sess.enabled() && sess.m_min.contains(code)) { - - tmp = sess.Min(code); + tmp = sess->Min(code); if (first) { min = tmp; @@ -979,13 +879,10 @@ EventDataType Day::physMin(ChannelID code) EventDataType tmp; bool first = true; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); + for (auto & sess : sessions) { + if (sess->enabled() && sess->m_min.contains(code)) { - if (sess.enabled() && sess.m_min.contains(code)) { - - tmp = sess.physMin(code); + tmp = sess->physMin(code); if (first) { min = tmp; @@ -1003,59 +900,56 @@ bool Day::hasData(ChannelID code, SummaryType type) { bool has = false; - QList::iterator end = sessions.end(); + for (auto & sess : sessions) { + if (sess->type() == MT_JOURNAL) continue; - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - if (sess.type() == MT_JOURNAL) continue; - - if (sess.enabled()) { + if (sess->enabled()) { switch (type) { // case ST_90P: // has=sess->m_90p.contains(code); // break; case ST_PERC: - has = sess.m_valuesummary.contains(code); + has = sess->m_valuesummary.contains(code); break; case ST_MIN: - has = sess.m_min.contains(code); + has = sess->m_min.contains(code); break; case ST_MAX: - has = sess.m_max.contains(code); + has = sess->m_max.contains(code); break; case ST_CNT: - has = sess.m_cnt.contains(code); + has = sess->m_cnt.contains(code); break; case ST_AVG: - has = sess.m_avg.contains(code); + has = sess->m_avg.contains(code); break; case ST_WAVG: - has = sess.m_wavg.contains(code); + has = sess->m_wavg.contains(code); break; case ST_CPH: - has = sess.m_cph.contains(code); + has = sess->m_cph.contains(code); break; case ST_SPH: - has = sess.m_sph.contains(code); + has = sess->m_sph.contains(code); break; case ST_FIRST: - has = sess.m_firstchan.contains(code); + has = sess->m_firstchan.contains(code); break; case ST_LAST: - has = sess.m_lastchan.contains(code); + has = sess->m_lastchan.contains(code); break; case ST_SUM: - has = sess.m_sum.contains(code); + has = sess->m_sum.contains(code); break; default: @@ -1075,13 +969,10 @@ EventDataType Day::Max(ChannelID code) EventDataType tmp; bool first = true; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); + for (auto & sess : sessions) { + if (sess->enabled() && sess->m_max.contains(code)) { - if (sess.enabled() && sess.m_max.contains(code)) { - - tmp = sess.Max(code); + tmp = sess->Max(code); if (first) { max = tmp; @@ -1091,7 +982,6 @@ EventDataType Day::Max(ChannelID code) } } } - return max; } @@ -1101,12 +991,9 @@ EventDataType Day::physMax(ChannelID code) EventDataType tmp; bool first = true; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - - if (sess.enabled() && sess.m_max.contains(code)) { - tmp = sess.physMax(code); + for (auto & sess : sessions) { + if (sess->enabled() && sess->m_max.contains(code)) { + tmp = sess->physMax(code); if (first) { max = tmp; @@ -1116,24 +1003,17 @@ EventDataType Day::physMax(ChannelID code) } } } - return max; } EventDataType Day::cph(ChannelID code) { double sum = 0; - //EventDataType h=0; - - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - - if (sess.enabled() && sess.m_cnt.contains(code)) { - sum += sess.count(code); + for (auto & sess : sessions) { + if (sess->enabled() && sess->m_cnt.contains(code)) { + sum += sess->count(code); } } - sum /= hours(); return sum; } @@ -1143,13 +1023,9 @@ EventDataType Day::sph(ChannelID code) EventDataType sum = 0; EventDataType h = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - - if (sess.enabled() && sess.m_sum.contains(code)) { - sum += sess.sum(code) / 3600.0; //*sessions[i]->hours(); - //h+=sessions[i]->hours(); + for (auto & sess : sessions) { + if (sess->enabled() && sess->m_sum.contains(code)) { + sum += sess->sum(code) / 3600.0; } } @@ -1162,27 +1038,21 @@ EventDataType Day::count(ChannelID code) { EventDataType total = 0; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - - if (sess.enabled() && sess.m_cnt.contains(code)) { - total += sess.count(code); + for (auto & sess : sessions) { + if (sess->enabled() && sess->m_cnt.contains(code)) { + total += sess->count(code); } } - return total; } bool Day::summaryOnly(Machine * mach) { - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - if ((mach == nullptr) && sess.summaryOnly()) { + for (auto & sess : sessions) { + if ((mach == nullptr) && sess->summaryOnly()) { // If this day generally has just summary data. return true; - } else if ((mach == sess.machine()) && sess.summaryOnly()) { + } else if ((mach == sess->machine()) && sess->summaryOnly()) { // Focus only on machine mach return true; } @@ -1192,29 +1062,21 @@ bool Day::summaryOnly(Machine * mach) bool Day::settingExists(ChannelID id) { - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - - if (sess.enabled()) { - QHash::iterator set = sess.settings.find(id); - - if (set != sess.settings.end()) { + for (auto & sess : sessions) { + if (sess->enabled()) { + auto set = sess->settings.find(id); + if (set != sess->settings.end()) { return true; } } } - return false; } bool Day::eventsLoaded() { - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - - if (sess.eventsLoaded()) { + for (auto & sess : sessions) { + if (sess->eventsLoaded()) { return true; } } @@ -1224,11 +1086,8 @@ bool Day::eventsLoaded() bool Day::channelExists(ChannelID id) { - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - - if (sess.enabled() && sess.eventlist.contains(id)) { + for (auto & sess : sessions) { + if (sess->enabled() && sess->eventlist.contains(id)) { return true; } } @@ -1236,30 +1095,25 @@ bool Day::channelExists(ChannelID id) return false; } bool Day::hasEvents() { - int s=sessions.size(); - for (int i=0; ieventlist.size() > 0) return true; + for (auto & sess : sessions) { + if (sess->eventlist.size() > 0) return true; } return false; } bool Day::channelHasData(ChannelID id) { - QList::iterator end = sessions.end(); - - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - - if (sess.enabled()) { - if (sess.m_cnt.contains(id)) { + for (auto & sess : sessions) { + if (sess->enabled()) { + if (sess->m_cnt.contains(id)) { return true; } - if (sess.eventlist.contains(id)) { + if (sess->eventlist.contains(id)) { return true; } - if (sess.m_valuesummary.contains(id)) { + if (sess->m_valuesummary.contains(id)) { return true; } } @@ -1270,11 +1124,9 @@ bool Day::channelHasData(ChannelID id) void Day::OpenEvents() { -// if (d_events_open) -// return; - Q_FOREACH(Session * session, sessions) { - if (session->type() != MT_JOURNAL) - session->OpenEvents(); + for (auto & sess : sessions) { + if (sess->type() != MT_JOURNAL) + sess->OpenEvents(); } d_events_open = true; } @@ -1282,8 +1134,8 @@ void Day::OpenEvents() void Day::OpenSummary() { if (d_summaries_open) return; - Q_FOREACH(Session * session, sessions) { - session->LoadSummary(); + for (auto & sess : sessions) { + sess->LoadSummary(); } d_summaries_open = true; } @@ -1291,8 +1143,8 @@ void Day::OpenSummary() void Day::CloseEvents() { - Q_FOREACH(Session * session, sessions) { - session->TrashEvents(); + for (auto & sess : sessions) { + sess->TrashEvents(); } d_events_open = false; } @@ -1300,23 +1152,20 @@ void Day::CloseEvents() QList Day::getSortedMachineChannels(MachineType type, quint32 chantype) { QList available; - QHash::iterator mi_end = machines.end(); - for (QHash::iterator mi = machines.begin(); mi != mi_end; mi++) { + auto mi_end = machines.end(); + for (auto mi = machines.begin(); mi != mi_end; mi++) { if (mi.key() != type) continue; available.append(mi.value()->availableChannels(chantype)); } QMultiMap order; - for (int i=0; i < available.size(); ++i) { - ChannelID code = available.at(i); + for (const auto code : available) { order.insert(schema::channel[code].order(), code); } - QMultiMap::iterator it; - QList channels; - for (it = order.begin(); it != order.end(); ++it) { + for (auto it = order.begin(); it != order.end(); ++it) { ChannelID code = it.value(); channels.append(code); } @@ -1327,23 +1176,20 @@ QList Day::getSortedMachineChannels(MachineType type, quint32 chantyp QList Day::getSortedMachineChannels(quint32 chantype) { QList available; - QHash::iterator mi_end = machines.end(); - for (QHash::iterator mi = machines.begin(); mi != mi_end; mi++) { + auto mi_end = machines.end(); + for (auto mi = machines.begin(); mi != mi_end; mi++) { if (mi.key() == MT_JOURNAL) continue; available.append(mi.value()->availableChannels(chantype)); } QMultiMap order; - for (int i=0; i < available.size(); ++i) { - ChannelID code = available.at(i); + for (auto code : available) { order.insert(schema::channel[code].order(), code); } - QMultiMap::iterator it; - QList channels; - for (it = order.begin(); it != order.end(); ++it) { + for (auto it = order.begin(); it != order.end(); ++it) { ChannelID code = it.value(); channels.append(code); } @@ -1355,12 +1201,9 @@ qint64 Day::first(MachineType type) qint64 date = 0; qint64 tmp; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - - if ((sess.type() == type) && sess.enabled()) { - tmp = sess.first(); + for (auto & sess : sessions) { + if ((sess->type() == type) && sess->enabled()) { + tmp = sess->first(); if (!tmp) { continue; } @@ -1371,7 +1214,6 @@ qint64 Day::first(MachineType type) } } } - return date; } @@ -1380,15 +1222,11 @@ qint64 Day::first() qint64 date = 0; qint64 tmp; - QList::iterator end = sessions.end(); - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - if (sess.type() == MT_JOURNAL) continue; - if (sess.enabled()) { - tmp = sess.first(); - + for (auto & sess : sessions) { + if (sess->type() == MT_JOURNAL) continue; + if (sess->enabled()) { + tmp = sess->first(); if (!tmp) { continue; } - if (!date) { date = tmp; } else { @@ -1396,7 +1234,6 @@ qint64 Day::first() } } } - return date; } @@ -1406,17 +1243,11 @@ qint64 Day::last() qint64 date = 0; qint64 tmp; - QList::iterator end = sessions.end(); - - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - if (sess.type() == MT_JOURNAL) continue; - - if (sess.enabled()) { - tmp = sess.last(); - + for (auto & sess : sessions) { + if (sess->type() == MT_JOURNAL) continue; + if (sess->enabled()) { + tmp = sess->last(); if (!tmp) { continue; } - if (!date) { date = tmp; } else { @@ -1424,7 +1255,6 @@ qint64 Day::last() } } } - return date; } @@ -1433,17 +1263,10 @@ qint64 Day::last(MachineType type) qint64 date = 0; qint64 tmp; - QList::iterator end = sessions.end(); - - - for (QList::iterator it = sessions.begin(); it != end; ++it) { - Session & sess = *(*it); - - if ((sess.type() == type) && sess.enabled()) { - tmp = sess.last(); - + for (auto & sess : sessions) { + if ((sess->type() == type) && sess->enabled()) { + tmp = sess->last(); if (!tmp) { continue; } - if (!date) { date = tmp; } else { @@ -1451,7 +1274,6 @@ qint64 Day::last(MachineType type) } } } - return date; } @@ -1465,8 +1287,8 @@ bool Day::removeSession(Session *sess) return b; } bool Day::searchMachine(MachineType mt) { - for (int i=0; i < sessions.size(); ++i) { - if (sessions.at(i)->type() == mt) + for (auto & sess : sessions) { + if (sess->type() == mt) return true; } return false; @@ -1474,8 +1296,8 @@ bool Day::searchMachine(MachineType mt) { bool Day::hasMachine(Machine * mach) { - for (int i=0; i < sessions.size(); ++i) { - if (sessions.at(i)->machine() == mach) + for (auto & sess : sessions) { + if (sess->machine() == mach) return true; } return false; diff --git a/sleepyhead/SleepLib/day.h b/sleepyhead/SleepLib/day.h index e1860527..67a91fa4 100644 --- a/sleepyhead/SleepLib/day.h +++ b/sleepyhead/SleepLib/day.h @@ -172,7 +172,7 @@ class Day return d_hours = double(total_time()) / 3600000.0; } EventDataType hours(MachineType type) { - QHash::iterator it = d_machhours.find(type); + auto it = d_machhours.find(type); if (it == d_machhours.end()) { return d_machhours[type] = double(total_time(type)) / 3600000.0; } diff --git a/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp b/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp index 07ea83a1..416bd253 100644 --- a/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp +++ b/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp @@ -742,8 +742,7 @@ int PRS1Loader::OpenMachine(const QString & path) finishAddingSessions(); if (unknownCodes.size() > 0) { - QMap::iterator it; - for (it = unknownCodes.begin(); it != unknownCodes.end(); ++it) { + for (auto it = unknownCodes.begin(), end=unknownCodes.end(); it != end; ++it) { qDebug() << QString("Unknown CPAP Codes '0x%1' was detected during import").arg((short)it.key(), 2, 16, QChar(0)); QStringList & strlist = it.value(); for (int i=0;i::iterator it; @@ -2383,11 +2381,36 @@ bool PRS1Import::ParseSummaryF3() session->settings[CPAP_Mode] = (int)mode; if ((it=hbdata.find(5)) != hbdata.end()) { - duration = (it.value()[1] << 8 ) + it.value()[0]; + summary_duration = (it.value()[1] << 8 ) + it.value()[0]; } +/* QDateTime date = QDateTime::fromMSecsSinceEpoch(session->first()); + if (date.date() == QDate(2018,5,1)) { + + qDebug() << "Dumping session" << (int)session->session() << "summary file"; + QString hexstr = QString("%1@0000: ").arg(session->session(),8,16,QChar('0')); + const unsigned char * data = (const unsigned char *)summary->m_data.constData(); + int size = summary->m_data.size(); + for (int i=0; isession(),8,16,QChar('0')).arg(i+1, 4, 16, QChar('0')); + } + } + qDebug() << "Dumping mainblock"; + for (auto it=mainblock.cbegin(), end=mainblock.cend(); it!=end; ++it) { + qDebug() << it.key() << it.value().toHex(); + } + qDebug() << "Dumping hbdata"; + for (auto it=hbdata.cbegin(), end=hbdata.cend(); it!=end; ++it) { + qDebug() << it.key() << it.value().toHex(); + } + + qDebug() << "In date"; + } */ - summary_duration = duration; return true; } diff --git a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp index afda7932..1d3a25c4 100644 --- a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp +++ b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp @@ -44,11 +44,10 @@ const QString STR_UnknownModel = "Resmed S9 ???"; const QString & lookupModel(quint16 model) { - QHash >::iterator end = Resmed_Model_Map.end(); - for (QHash >::iterator it = Resmed_Model_Map.begin(); it != end; ++it) { + for (auto it=Resmed_Model_Map.begin(),end = Resmed_Model_Map.end(); it != end; ++it) { QList & list = it.value(); - for (int i=0; i < list.size(); ++i) { - if (list.at(i) == model) { + for (auto val : list) { + if (val == model) { return it.key(); } } @@ -74,8 +73,7 @@ ResMedEDFParser::~ResMedEDFParser() EDFSignal *ResMedEDFParser::lookupSignal(ChannelID ch) { // Get list of all known foreign language names for this channel - QHash::iterator channames = resmed_codes.find(ch); - + auto channames = resmed_codes.find(ch); if (channames == resmed_codes.end()) { // no alternatives strings found for this channel return nullptr; @@ -84,8 +82,8 @@ EDFSignal *ResMedEDFParser::lookupSignal(ChannelID ch) // This is bad, because ResMed thinks it was a cool idea to use two channels with the same name. // Scan through EDF's list of signals to see if any match - for (int i = 0; i < channames.value().size(); i++) { - EDFSignal *sig = lookupLabel(channames.value()[i]); + for (auto & name : channames.value()) { + EDFSignal *sig = lookupLabel(name); if (sig) return sig; } @@ -96,18 +94,14 @@ EDFSignal *ResMedEDFParser::lookupSignal(ChannelID ch) // Check if given string matches any alternative signal names for this channel bool matchSignal(ChannelID ch, const QString & name) { - QHash::iterator channames = resmed_codes.find(ch); - + auto channames = resmed_codes.find(ch); if (channames == resmed_codes.end()) { return false; } - QStringList & strings = channames.value(); - int size = strings.size(); - - for (int i=0; i < size; ++i) { + for (auto & string : channames.value()) { // Using starts with, because ResMed is very lazy about consistency - if (name.startsWith(strings.at(i), Qt::CaseInsensitive)) { + if (name.startsWith(string, Qt::CaseInsensitive)) { return true; } } @@ -117,14 +111,14 @@ bool matchSignal(ChannelID ch, const QString & name) // This function parses a list of STR files and creates a date ordered map of individual records void ResmedLoader::ParseSTR(Machine *mach, QMap & STRmap) { + Q_UNUSED(mach) + if (!qprogress) { qWarning() << "What happened to qprogress object in ResmedLoader::ParseSTR()"; return; } - QMap::iterator it; - - for (it = STRmap.begin(); it!= STRmap.end(); ++it) { + for (auto it=STRmap.begin(), end=STRmap.end(); it != end; ++it) { STRFile & file = it.value(); QString & strfile = file.filename; ResMedEDFParser & str = *file.edf; @@ -151,7 +145,7 @@ void ResmedLoader::ParseSTR(Machine *mach, QMap & STRmap) // For each data record, representing 1 day each for (int rec = 0; rec < size; ++rec, date = date.addDays(1)) { - QMap::iterator rit = resdayList.find(date); + auto rit = resdayList.find(date); if (rit != resdayList.end()) { // Already seen this record.. should check if the data is the same, but meh. continue; @@ -1488,7 +1482,7 @@ int ResmedLoader::scanFiles(Machine * mach, const QString & datalog_path) // EDFType type = lookupEDFType(ext); // Find or create ResMedDay object for this date - QMap::iterator rd = resdayList.find(date); + auto rd = resdayList.find(date); if (rd == resdayList.end()) { rd = resdayList.insert(date, ResMedDay()); rd.value().date = date; @@ -1967,7 +1961,9 @@ struct OverlappingEDF { void ResDayTask::run() { - + if (this->resday->date == QDate(2016,1,20)) { + qDebug() << "in resday" << this->resday->date; + } /*loader->sessionMutex.lock(); Day *day = p_profile->FindDay(resday->date, MT_CPAP); if (day) { @@ -2054,8 +2050,7 @@ void ResDayTask::run() QMap EVElist, CSLlist; - QHash::iterator fit; - for (fit=resday->files.begin(); fit!=resday->files.end(); ++fit) { + for (auto fit=resday->files.begin(), fend=resday->files.end(); fit!=fend; ++fit) { const QString & key = fit.key(); const QString & fullpath = fit.value(); QString ext = key.section("_", -1).section(".",0,0).toUpper(); @@ -2074,8 +2069,7 @@ void ResDayTask::run() } bool added = false; - for (int i=0; i< overlaps.size(); i++) { - OverlappingEDF & ovr = overlaps[i]; + for (auto & ovr : overlaps) { if ((tt >= (ovr.start)) && (tt < ovr.end)) { ovr.filemap.insert(tt, key); @@ -2111,16 +2105,14 @@ void ResDayTask::run() // Create an ordered map and see how far apart the sessions really are. QMap mapov; - for (int i=0;i::iterator oit; - for (oit=mapov.begin(); oit != mapov.end(); ++oit) { + for (auto oit=mapov.begin(), oend=mapov.end(); oit != oend; ++oit) { // Get next in line - QMap::iterator next_oit = oit+1; + auto next_oit = oit+1; if (next_oit != mapov.end()) { OverlappingEDF & A = oit.value(); OverlappingEDF & B = next_oit.value(); @@ -2134,16 +2126,13 @@ void ResDayTask::run() if (overlaps.size()==0) return; - // Now overlaps is populated with zero or more individual session groups of EDF files (zero because of sucky summary only days) - for (int s=0; s::iterator mit; - for (mit = ovr.filemap.begin(); mit != ovr.filemap.end(); ++mit) { + for (auto mit=ovr.filemap.begin(), mend=ovr.filemap.end(); mit != mend; ++mit) { const QString & filename = mit.value(); const QString & fullpath = resday->files[filename]; QString ext = filename.section("_", -1).section(".",0,0).toUpper(); @@ -2172,13 +2161,11 @@ void ResDayTask::run() // Turns out there is only one or sometimes two EVE's per day, and they store data for the whole day // So we have to extract Annotations data and apply it for all sessions - QMap::iterator eit; - for (eit = EVElist.begin(); eit != EVElist.end(); ++eit) { + for (auto eit=EVElist.begin(), eveend=EVElist.end(); eit != eveend; ++eit) { const QString & fullpath = resday->files[eit.value()]; - loader->LoadEVE(ovr.sess, fullpath); } - for (eit = CSLlist.begin(); eit != CSLlist.end(); ++eit) { + for (auto eit=CSLlist.begin(), cslend=CSLlist.end(); eit != cslend; ++eit) { const QString & fullpath = resday->files[eit.value()]; loader->LoadCSL(ovr.sess, fullpath); } @@ -2397,7 +2384,7 @@ int ResmedLoader::Open(const QString & dirpath) /////////////////////////////////////////////////////////////////////////////////// // Parse the idmap into machine objects properties, (overwriting any old values) /////////////////////////////////////////////////////////////////////////////////// - for (QHash::iterator i = idmap.begin(); i != idmap.end(); i++) { + for (auto i=idmap.begin(), idend=idmap.end(); i != idend; i++) { mach->properties[i.key()] = i.value(); } @@ -2426,10 +2413,8 @@ int ResmedLoader::Open(const QString & dirpath) dir.setFilter(QDir::Files | QDir::Hidden | QDir::Readable); QFileInfoList flist = dir.entryInfoList(); - int size = flist.size(); // Add any STR_Backup versions to the file list - for (int i = 0; i < size; i++) { - QFileInfo fi = flist.at(i); + for (auto & fi : flist) { filename = fi.fileName(); if (!filename.startsWith("STR", Qt::CaseInsensitive)) continue; @@ -2439,8 +2424,7 @@ int ResmedLoader::Open(const QString & dirpath) } // Now place any of these files in the Backup folder sorted by the file date - for (int i=0;iParse()) { qDebug() << "Faulty STR file" << filename; @@ -2506,8 +2490,7 @@ int ResmedLoader::Open(const QString & dirpath) int size = flist.size(); // Add any STR_Backup versions to the file list - for (int i = 0; i < size; i++) { - QFileInfo fi = flist.at(i); + for (auto & fi : flist) { filename = fi.fileName(); if (!filename.startsWith("STR", Qt::CaseInsensitive)) continue; @@ -2546,8 +2529,7 @@ int ResmedLoader::Open(const QString & dirpath) ParseSTR(mach, STRmap); // We are done with the Parsed STR EDF objects, so delete them - QMap::iterator it; - for (it=STRmap.begin(); it!= STRmap.end(); ++it) { + for (auto it=STRmap.begin(), end=STRmap.end(); it != end; ++it) { delete it.value().edf; } @@ -2588,9 +2570,7 @@ int ResmedLoader::Open(const QString & dirpath) // Now at this point we have resdayList populated with processable summary and EDF files data // that can be processed in threads.. - QMap::iterator rdi; - - for (rdi = resdayList.begin(); rdi != resdayList.end(); rdi++) { + for (auto rdi=resdayList.begin(), rend=resdayList.end(); rdi != rend; rdi++) { QDate date = rdi.key(); ResMedDay & resday = rdi.value(); @@ -2606,13 +2586,11 @@ int ResmedLoader::Open(const QString & dirpath) // but the worst case scenario is this session is deleted and reimported.. this just slows things down a bit in that case // This day was first imported as a summary from STR.edf, so we now totally want to redo this day - QList sessions = day->getSessions(MT_CPAP); - - // Delete sessions for this day so they recreate with a clean slate. - for (int i=0;iremoveSession(sess); - delete sess; + for (auto & sess : day->sessions) { + if (sess->type() == MT_CPAP) { + day->removeSession(sess); + delete sess; + } } reimporting = true; @@ -2747,8 +2725,7 @@ int ResmedLoader::Open(const QString & dirpath) qint64 totalns = 0; qDebug() << "Time Delta Efficiency Information"; - for (QHash::iterator it = channel_efficiency.begin(); - it != channel_efficiency.end(); it++) { + for (auto it = channel_efficiency.begin(), end=channel_efficiency.end(); it != end; it++) { ChannelID code = it.key(); qint64 value = it.value(); qint64 ns = channel_time[code]; @@ -3154,9 +3131,7 @@ bool ResmedLoader::LoadBRP(Session *sess, const QString & path) qint64 duration = edf.GetNumDataRecords() * edf.GetDuration(); sess->updateLast(edf.startdate + duration); - for (int s = 0; s < edf.GetNumSignals(); s++) { - EDFSignal &es = edf.edfsignals[s]; - + for (auto & es : edf.edfsignals) { long recs = es.nr * edf.GetNumDataRecords(); if (recs < 0) continue; @@ -3338,7 +3313,7 @@ void ResmedLoader::ToTimeDelta(Session *sess, ResMedEDFParser &edf, EDFSignal &e int cnt = el->count(); int bytes = cnt * (sizeof(EventStoreType) + sizeof(quint32)); int wvbytes = recs * (sizeof(EventStoreType)); - QHash::iterator it = channel_efficiency.find(code); + auto it = channel_efficiency.find(code); if (it == channel_efficiency.end()) { channel_efficiency[code] = wvbytes - bytes; @@ -3362,8 +3337,7 @@ bool ResmedLoader::LoadSAD(Session *sess, const QString & path) qint64 duration = edf.GetNumDataRecords() * edf.GetDuration(); sess->updateLast(edf.startdate + duration); - for (int s = 0; s < edf.GetNumSignals(); s++) { - EDFSignal &es = edf.edfsignals[s]; + for (auto & es : edf.edfsignals) { //qDebug() << "SAD:" << es.label << es.digital_maximum << es.digital_minimum << es.physical_maximum << es.physical_minimum; long recs = es.nr * edf.GetNumDataRecords(); ChannelID code; @@ -3419,9 +3393,8 @@ bool ResmedLoader::LoadPLD(Session *sess, const QString & path) long recs; ChannelID code; - for (int s = 0; s < edf.GetNumSignals(); s++) { + for (auto & es : edf.edfsignals) { a = nullptr; - EDFSignal &es = edf.edfsignals[s]; recs = es.nr * edf.GetNumDataRecords(); if (recs <= 0) { continue; } diff --git a/sleepyhead/SleepLib/machine_loader.cpp b/sleepyhead/SleepLib/machine_loader.cpp index a516daeb..b0a52d5e 100644 --- a/sleepyhead/SleepLib/machine_loader.cpp +++ b/sleepyhead/SleepLib/machine_loader.cpp @@ -69,8 +69,8 @@ void RegisterLoader(MachineLoader *loader) } void DestroyLoaders() { - for (QList::iterator i = m_loaders.begin(); i != m_loaders.end(); i++) { - delete(*i); + for (auto & loader : m_loaders) { + delete(loader); } m_loaders.clear(); @@ -89,33 +89,17 @@ MachineLoader::MachineLoader() :QObject(nullptr) MachineLoader::~MachineLoader() { -// for (QList::iterator m = m_machlist.begin(); m != m_machlist.end(); m++) { -// delete *m; -// } } void MachineLoader::finishAddingSessions() { - QMap::iterator it; - QMap::iterator it_end = new_sessions.end(); - // Using a map specifically so they are inserted in order. - for (it = new_sessions.begin(); it != it_end; ++it) { + for (auto it=new_sessions.begin(), end=new_sessions.end(); it != end; ++it) { Session * sess = it.value(); Machine * mach = sess->machine(); mach->AddSession(sess); } - new_sessions.clear(); - -/* QHash >::iterator mlit = MachineList.find(loaderName()); - - if (mlit != MachineList.end()) { - for(QHash::iterator mit = mlit.value().begin(); mit!=mlit.value().end(); ++mit) { - mit.value()->SaveSummary(); - } - } */ - } bool uncompressFile(QString infile, QString outfile) diff --git a/sleepyhead/SleepLib/profiles.cpp b/sleepyhead/SleepLib/profiles.cpp index c63b6c68..9629b90c 100644 --- a/sleepyhead/SleepLib/profiles.cpp +++ b/sleepyhead/SleepLib/profiles.cpp @@ -86,12 +86,12 @@ Profile::~Profile() delete general; // delete machine objects... - for (int i=0; i::iterator d = daylist.begin(); d != daylist.end(); d++) { - delete d.value(); + for (auto & day : daylist) { + delete day; } } @@ -340,7 +340,7 @@ QString Environment::searchInDirectory(const QStringList & execs, QString direct if (!directory.endsWith(slash)) directory += slash; - foreach (const QString & exec, execs) { + for (auto & exec : execs) { QFileInfo fi(directory + exec); if (fi.exists() && fi.isFile() && fi.isExecutable()) return fi.absoluteFilePath(); @@ -387,7 +387,7 @@ QString Environment::searchInPath(const QString &executable, const QStringList & if (executable.indexOf(QLatin1Char('/')) != -1) return QString(); - foreach (const QString &p, path()) { + for (auto & p : path()) { if (alreadyChecked.contains(p)) continue; alreadyChecked.insert(p); @@ -550,16 +550,14 @@ void Profile::UnloadMachineData() return; } - QMap::iterator it; - for (it = daylist.begin(); it != daylist.end(); ++it) { - delete it.value(); + for (auto & day : daylist) { + delete day; } daylist.clear(); - for (int i=0; isessionlist.clear(); - m->day.clear(); + for (auto & mach : m_machlist) { + mach->sessionlist.clear(); + mach->day.clear(); } removeLock(); } @@ -567,36 +565,34 @@ void Profile::LoadMachineData() { addLock(); - for (int i=0; iversion() < loader->Version()) { - DataFormatError(m); + if (mach->version() < loader->Version()) { + DataFormatError(mach); } else { try { - m->Load(); + mach->Load(); } catch (OldDBVersion& e) { Q_UNUSED(e) - DataFormatError(m); + DataFormatError(mach); } } } else { - m->Load(); + mach->Load(); } } loadChannels(); } -void Profile::removeMachine(Machine * m) +void Profile::removeMachine(Machine * mach) { - m_machlist.removeAll(m); - QHash >::iterator mlit = MachineList.find(m->loaderName()); + m_machlist.removeAll(mach); + auto mlit = MachineList.find(mach->loaderName()); if (mlit != MachineList.end()) { - QHash::iterator mit = mlit.value().find(m->serial()); + auto mit = mlit.value().find(mach->serial()); if (mit != mlit.value().end()) { mlit.value().erase(mit); } @@ -606,9 +602,9 @@ void Profile::removeMachine(Machine * m) Machine * Profile::lookupMachine(QString serial, QString loadername) { - QHash >::iterator mlit = MachineList.find(loadername); + auto mlit = MachineList.find(loadername); if (mlit != MachineList.end()) { - QHash::iterator mit = mlit.value().find(serial); + auto mit = mlit.value().find(serial); if (mit != mlit.value().end()) { return mit.value(); } @@ -619,13 +615,12 @@ Machine * Profile::lookupMachine(QString serial, QString loadername) Machine * Profile::CreateMachine(MachineInfo info, MachineID id) { - Machine *m = nullptr; - QHash >::iterator mlit = MachineList.find(info.loadername); + auto mlit = MachineList.find(info.loadername); if (mlit != MachineList.end()) { - QHash::iterator mit = mlit.value().find(info.serial); + auto mit = mlit.value().find(info.serial); if (mit != mlit.value().end()) { mit.value()->setInfo(info); // update info return mit.value(); @@ -701,7 +696,7 @@ void Profile::DelMachine(Machine *m) Day *Profile::addDay(QDate date) { - QMap::iterator dit = daylist.find(date); + auto dit = daylist.find(date); if (dit == daylist.end()) { dit = daylist.insert(date, new Day()); } @@ -732,11 +727,10 @@ Day *Profile::GetGoodDay(QDate date, MachineType type) return nullptr; // For a machine match, find at least one enabled Session. - for (int i = 0; i < day->size(); ++i) { - Session * sess = (*day)[i]; + + for (auto & sess : day->sessions) { if (((type == MT_UNKNOWN) || (sess->type() == type)) && sess->enabled()) { day->OpenSummary(); - return day; } } @@ -752,8 +746,7 @@ Day *Profile::FindGoodDay(QDate date, MachineType type) return nullptr; // For a machine match, find at least one enabled Session. - for (int i = 0; i < day->size(); ++i) { - Session * sess = (*day)[i]; + for (auto & sess : day->sessions) { if (((type == MT_UNKNOWN) || (sess->type() == type)) && sess->enabled()) { return day; } @@ -766,7 +759,7 @@ Day *Profile::FindGoodDay(QDate date, MachineType type) Day *Profile::GetDay(QDate date, MachineType type) { - QMap::iterator di = daylist.find(date); + auto di = daylist.find(date); if (di == daylist.end()) return nullptr; Day * day = di.value(); @@ -786,7 +779,7 @@ Day *Profile::GetDay(QDate date, MachineType type) Day *Profile::FindDay(QDate date, MachineType type) { - QMap::iterator di = daylist.find(date); + auto di = daylist.find(date); if (di == daylist.end()) return nullptr; Day * day = di.value(); @@ -815,7 +808,7 @@ int Profile::Import(QString path) QListloaders = GetLoaders(MT_CPAP); - Q_FOREACH(MachineLoader * loader, loaders) { + for(auto & loader : loaders) { if (c += loader->Open(path)) { break; } @@ -826,9 +819,9 @@ int Profile::Import(QString path) MachineLoader *GetLoader(QString name) { - QListloaders = GetLoaders(); + QList loaders = GetLoaders(); - Q_FOREACH(MachineLoader * loader, loaders) { + for (auto & loader : loaders) { if (loader->loaderName() == name) { return loader; } @@ -843,17 +836,16 @@ QList Profile::GetMachines(MachineType t) { QList vec; - for (int i=0; itype(); + MachineType mt = mach->type(); if ((t == MT_UNKNOWN) || (mt == t)) { - vec.push_back(m); + vec.push_back(mach); } } @@ -905,11 +897,8 @@ Machine *Profile::GetMachine(MachineType t) bool Profile::unlinkDay(Day * day) { - QMap::iterator it; - QMap::iterator it_end = daylist.end(); - // Find the key... - for (it = daylist.begin(); it != it_end; ++it) { + for (auto it = daylist.begin(), it_end = daylist.end(); it != it_end; ++it) { if (it.value() == day) { daylist.erase(it); return true; @@ -995,9 +984,7 @@ void saveProfileList() root.appendChild(doc.createComment("This file is created during Profile Scan for cloud access convenience, it's not used by Desktop version of SleepyHead.")); - QMap::iterator it; - - for (it = profiles.begin(); it != profiles.end(); ++it) { + for (auto it = profiles.begin(); it != profiles.end(); ++it) { QDomElement elem = doc.createElement("profile"); elem.setAttribute("name", it.key()); // Not technically nessesary.. @@ -1027,8 +1014,7 @@ int CleanupProfile(Profile *prof) << STR_CS_UserEventPieChart << STR_AS_OverlayType << STR_AS_OverviewLinechartMode; int cnt = 0; - for (int i=0; icontains(prf)) { qDebug() << "Migrating profile preference" << prf; PREF[prf] = (*prof)[prf]; @@ -1068,8 +1054,7 @@ void Scan() int cleanup = 0; // Iterate through subdirectories and load profiles.. - for (int i = 0; i < list.size(); i++) { - QFileInfo fi = list.at(i); + for (auto & fi : list) { QString npath = fi.canonicalFilePath(); Profile *prof = new Profile(npath); //prof->Open(); @@ -1354,15 +1339,10 @@ EventDataType Profile::calcBelowThreshold(ChannelID code, EventDataType threshol Day * Profile::findSessionDay(Session * session) { -// MachineType mt = session->type(); - - QMap::iterator it; - QMap::iterator it_end = p_profile->daylist.end(); - for (it = p_profile->daylist.begin(); it != it_end; ++it) { + for (auto it=p_profile->daylist.begin(),it_end = p_profile->daylist.end(); it != it_end; ++it) { Day *day = it.value(); - for (int i=0; isize(); i++) { - Session * s = day->sessions.at(i); - if (s == session) { + for (auto & sess : day->sessions) { + if (sess == session) { return day; } } @@ -1661,13 +1641,14 @@ EventDataType Profile::calcPercentile(ChannelID code, EventDataType percent, Mac summaryOnly = true; break; } - for (int i = 0; i < day->size(); i++) { - for (QList::iterator s = day->begin(); s != day->end(); s++) { - if (!(*s)->enabled()) { + + // why was this nested like this??? + //for (int i = 0; i < day->size(); i++) { + for (auto & sess : day->sessions) { + if (!sess->enabled()) { continue; } - Session *sess = *s; gain = sess->m_gain[code]; if (!gain) { gain = 1; } @@ -1683,7 +1664,7 @@ EventDataType Profile::calcPercentile(ChannelID code, EventDataType percent, Mac QHash &tsum = tsi.value(); if (timeweight) { - for (QHash::iterator k = tsum.begin(); k != tsum.end(); k++) { + for (auto k=tsum.begin(), tsumend=tsum.end(); k != tsumend; k++) { weight = k.value(); value = EventDataType(k.key()) * gain; @@ -1697,7 +1678,7 @@ EventDataType Profile::calcPercentile(ChannelID code, EventDataType percent, Mac } } } else { - for (QHash::iterator k = vsum.begin(); k != vsum.end(); k++) { + for (auto k=vsum.begin(), vsumend=vsum.end(); k!=vsumend; k++) { weight = k.value(); value = EventDataType(k.key()) * gain; @@ -1712,7 +1693,7 @@ EventDataType Profile::calcPercentile(ChannelID code, EventDataType percent, Mac } } } - } + // } } date = date.addDays(1); @@ -1879,8 +1860,7 @@ QDate Profile::LastGoodDay(MachineType mt) bool Profile::channelAvailable(ChannelID code) { - for (int i=0; ihasChannel(code)) return true; } @@ -1942,10 +1922,7 @@ void Profile::saveChannels() quint16 size = schema::channel.channels.size(); out << size; - QHash::iterator it; - QHash::iterator it_end = schema::channel.channels.end(); - - for (it = schema::channel.channels.begin(); it != it_end; ++it) { + for (auto it = schema::channel.channels.begin(),it_end = schema::channel.channels.end(); it != it_end; ++it) { schema::Channel * chan = it.value(); out << it.key(); out << chan->code(); diff --git a/sleepyhead/SleepLib/schema.cpp b/sleepyhead/SleepLib/schema.cpp index 6d84ddb9..e493c899 100644 --- a/sleepyhead/SleepLib/schema.cpp +++ b/sleepyhead/SleepLib/schema.cpp @@ -787,8 +787,8 @@ ChannelList::ChannelList() } ChannelList::~ChannelList() { - for (QHash::iterator i = channels.begin(); i != channels.end(); i++) { - delete i.value(); + for (auto & chan : channels) { + delete chan; } } bool ChannelList::Load(QString filename) @@ -835,8 +835,7 @@ bool ChannelList::Load(QString filename) bool ok; int id, linkid; - QString chantype, scopestr, typestr, name, group, idtxt, details, label, unit, datatypestr, - defcolor, link; + QString chantype, scopestr, typestr, name, group, idtxt, details, label, unit, datatypestr, defcolor, link; ChanType type; DataType datatype; Channel *chan; @@ -1031,19 +1030,14 @@ bool ChannelList::Save(QString filename) QDomElement root = doc.createElement("channels"); droot.appendChild(root); - QHash >::iterator git; - QHash >::iterator groups_end = groups.end(); - for (git = groups.begin(); git != groups_end; ++git) { - QHash & chanlist = git.value(); - QHash::iterator it; - QHash::iterator chend = chanlist.end(); + for (auto git=groups.begin(), end=groups.end(); git != end; ++git) { + auto & chanlist = git.value(); QDomElement grp = doc.createElement("group"); grp.setAttribute("name", git.key()); root.appendChild(grp); - - for (it =chanlist.begin(); it!= chend; ++it) { + for (auto it = chanlist.begin(), cend=chanlist.end(); it!=cend; ++it) { Channel * chan = it.value(); QDomElement cn = doc.createElement("channel"); cn.setAttribute("id", chan->id()); @@ -1058,8 +1052,7 @@ bool ChannelList::Save(QString filename) cn.setAttribute("type", chan->type()); cn.setAttribute("datatype", chan->datatype()); cn.setAttribute("overview", chan->showInOverview()); - QHash::iterator op; - for (op = chan->m_options.begin(); op!=chan->m_options.end(); ++op) { + for (auto op=chan->m_options.begin(), opend=chan->m_options.end(); op!=opend; ++op) { QDomElement c2 = doc.createElement("option"); c2.setAttribute("key", op.key()); c2.setAttribute("value", op.value()); @@ -1069,10 +1062,8 @@ bool ChannelList::Save(QString filename) //cn.appendChild(doc.createTextNode(i.value().toDateTime().toString("yyyy-MM-dd HH:mm:ss"))); grp.appendChild(cn); } - } - QFile file(filename); if (!file.open(QIODevice::WriteOnly)) { @@ -1083,11 +1074,10 @@ bool ChannelList::Save(QString filename) ts << doc.toString(); file.close(); - return true; } -} +} // namespace QString ChannelCalc::label() {