From 32026446a5170fe186075f489881c9a4ea95d5e4 Mon Sep 17 00:00:00 2001
From: Guy Scharf <guy.oscar@moxis.com>
Date: Sun, 2 Aug 2020 13:01:31 -0700
Subject: [PATCH 1/2] Rename variables for clarity -- no effect on code

---
 oscar/Graphs/gSummaryChart.cpp | 72 +++++++++++++++++-----------------
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/oscar/Graphs/gSummaryChart.cpp b/oscar/Graphs/gSummaryChart.cpp
index 24196c4b..d245ee5c 100644
--- a/oscar/Graphs/gSummaryChart.cpp
+++ b/oscar/Graphs/gSummaryChart.cpp
@@ -1045,26 +1045,26 @@ QString formatTime(EventDataType v, bool show_seconds = false, bool duration = f
 bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
 {
     graph->timedRedraw(0);
-    int x = event->x();
-    int y = event->y();
+    int xposLeft = event->x();
+    int yPosTop = event->y();
 
-    if (!m_rect.contains(x, y)) {
+    if (!m_rect.contains(xposLeft, yPosTop)) {
         //    if ((x<0 || y<0 || x>l_width || y>l_height)) {
         hl_day = -1;
         //graph->timedRedraw(2000);
         return false;
     }
 
-    x -= m_rect.left();
-    y -= m_rect.top();
+    xposLeft -= m_rect.left();
+    yPosTop -= m_rect.top();
 
-    Q_UNUSED(y)
+    Q_UNUSED(yPosTop)
 
     double xx = l_maxx - l_minx;
 
     double xmult = xx / double(l_width + barw);
 
-    qint64 mx = ceil(xmult * double(x - offset));
+    qint64 mx = ceil(xmult * double(xposLeft - offset));
     mx += l_minx;
     mx = mx + l_offset; //-86400000L;
     int zd = mx / 86400000L;
@@ -1080,7 +1080,7 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
 
         QMap<short, EventDataType> &valhash = d.value();
 
-        x += m_rect.left(); //gYAxis::Margin+gGraphView::titleWidth; //graph->m_marginleft+
+        xposLeft += m_rect.left(); //gYAxis::Margin+gGraphView::titleWidth; //graph->m_marginleft+
         int y = event->y() - m_rect.top() + rtop - 15;
         //QDateTime dt1=QDateTime::fromTime_t(hl_day*86400).toLocalTime();
         QDateTime dt2 = QDateTime::fromTime_t(hl_day * 86400).toUTC();
@@ -1094,7 +1094,7 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
         if ((d != m_values.end()) && (day != nullptr)) {
             bool summary_only = day->summaryOnly();
 
-            QString z = dt.toString(Qt::SystemLocaleShortDate);
+            QString strTooltip = dt.toString(Qt::SystemLocaleShortDate);
 
             // Day * day=m_days[hl_day];
             //EventDataType val;
@@ -1112,10 +1112,10 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
                     val = QString::number(d.value()[0], 'f', 2);
                 }
 
-                z += "\r\n" + m_label + ": " + val;
+                strTooltip += "\r\n" + m_label + ": " + val;
 
                 if (m_type[1] == ST_SESSIONS) {
-                    z += " "+QString(QObject::tr("(Sess: %1)")).arg(day->size(), 0);
+                    strTooltip += " "+QString(QObject::tr("(Sess: %1)")).arg(day->size(), 0);
                 }
 
                 EventDataType v = m_times[zd][0];
@@ -1123,9 +1123,9 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
 
                 if (lastt < 0) { lastt = 0; }
 
-                z += "\r\n"+QString(QObject::tr("Bedtime: %1")).arg(formatTime(v, false, false, true));
+                strTooltip += "\r\n"+QString(QObject::tr("Bedtime: %1")).arg(formatTime(v, false, false, true));
                 v = m_times[zd][lastt] + m_values[zd][lastt];
-                z += "\r\n"+QString(QObject::tr("Waketime: %1")).arg(formatTime(v, false, false, true));
+                strTooltip += "\r\n"+QString(QObject::tr("Waketime: %1")).arg(formatTime(v, false, false, true));
 
             } else if (m_graphtype == GT_BAR) {
                 if (m_type[0] == ST_HOURS) {
@@ -1138,11 +1138,11 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
                     val = QString::number(d.value()[0], 'f', 2);
                 }
 
-                z += "\r\n" + m_label + ": " + val;
+                strTooltip += "\r\n" + m_label + ": " + val;
                 //z+="\r\nMode="+QString::number(day->settings_min("FlexSet"),'f',0);
 
             } else {
-                QString a;
+                QString strDataType;
 
                 for (int i = 0; i < m_type.size(); i++) {
                     if (!m_goodcodes[i]) {
@@ -1157,64 +1157,64 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
 
                     switch (m_type[i]) {
                     case ST_WAVG:
-                        a = STR_TR_WAvg;
+                        strDataType = STR_TR_WAvg;
                         break;
 
                     case ST_AVG:
-                        a = STR_TR_Avg;
+                        strDataType = STR_TR_Avg;
                         break;
 
                     case ST_90P:
-                        a = QObject::tr("90%");
+                        strDataType = QObject::tr("90%");
                         break;
 
                     case ST_PERC:
-                        if (tval >= 0.99) { a = STR_TR_Max; }
-                        else if (tval == 0.5) { a = STR_TR_Med; }
-                        else { a = QString("%1%").arg(tval * 100.0, 0, 'f', 0); }
+                        if (tval >= 0.99) { strDataType = STR_TR_Max; }
+                        else if (tval == 0.5) { strDataType = STR_TR_Med; }
+                        else { strDataType = QString("%1%").arg(tval * 100.0, 0, 'f', 0); }
 
                         break;
 
                     case ST_MIN:
-                        a = STR_TR_Min;
+                        strDataType = STR_TR_Min;
                         break;
 
                     case ST_MAX:
-                        a = STR_TR_Max;
+                        strDataType = STR_TR_Max;
                         break;
 
                     case ST_CPH:
-                        a = "";
+                        strDataType = "";
                         break;
 
                     case ST_SPH:
-                        a = "%";
+                        strDataType = "%";
                         break;
 
                     case ST_HOURS:
-                        a = STR_UNIT_Hours;
+                        strDataType = STR_UNIT_Hours;
                         break;
 
                     case ST_SESSIONS:
-                        a = STR_TR_Sessions;
+                        strDataType = STR_TR_Sessions;
                         break;
 
                     case ST_SETMIN:
-                        a = STR_TR_Min;
+                        strDataType = STR_TR_Min;
                         break;
 
                     case ST_SETMAX:
-                        a = STR_TR_Max;
+                        strDataType = STR_TR_Max;
                         break;
 
                     default:
-                        a = "";
+                        strDataType = "";
                         break;
                     }
 
                     if (m_type[i] == ST_SESSIONS) {
                         val = QString::number(d.value()[i + 1], 'f', 0);
-                        z += "\r\n" + a + ": " + val;
+                        strTooltip += "\r\n" + strDataType + ": " + val;
                     } else {
                         //if (day && (day->channelExists(m_codes[i]) || day->settingExists(m_codes[i]))) {
                         schema::Channel &chan = schema::channel[m_codes[i]];
@@ -1230,26 +1230,24 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
                             val = QString::number(v, 'f', 2);
                         }
 
-                        z += "\r\n" + chan.label() + " " + a + ": " + val;
+                        strTooltip += "\r\n" + chan.label() + " " + strDataType + ": " + val;
                         //}
                     }
                 }
 
             }
             if (summary_only) {
-                z += "\r\n"+QObject::tr("(Summary Only)");
+                strTooltip += "\r\n"+QObject::tr("(Summary Only)");
             }
 
-            graph->ToolTip(z, x, y - 15);
+            graph->ToolTip(strTooltip, xposLeft, y - 15);
             return false;
         } else {
             QString z = dt.toString(Qt::SystemLocaleShortDate) + "\r\n"+QObject::tr("No Data");
-            graph->ToolTip(z, x, y - 15);
+            graph->ToolTip(z, xposLeft, y - 15);
             return false;
         }
     }
-
-
     return false;
 }
 

From 4f83c9b184921070b3fb3297d930f3b4167daa73 Mon Sep 17 00:00:00 2001
From: Guy Scharf <guy.oscar@moxis.com>
Date: Sun, 2 Aug 2020 20:24:56 -0700
Subject: [PATCH 2/2] Re-order popup labels on Overview graph to match order of
 slices     Also change heading on AHI Overview to show same order     Improve
 some variable names for ease of understanding code

---
 oscar/Graphs/gLineOverlay.cpp       |  6 ++---
 oscar/Graphs/gSessionTimesChart.cpp | 35 ++++++++++++++++-------------
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/oscar/Graphs/gLineOverlay.cpp b/oscar/Graphs/gLineOverlay.cpp
index b2d731cf..b6e1484f 100644
--- a/oscar/Graphs/gLineOverlay.cpp
+++ b/oscar/Graphs/gLineOverlay.cpp
@@ -223,11 +223,11 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion &region)
                             painter.drawRect(rect);
 
                             // Queue tooltip
-                            QString lab2 = QString("%1").arg(schema::channel[m_code].fullname());
+                            QString strEventTooltip = QString("%1").arg(schema::channel[m_code].fullname());
                             if (raw != 0)  // Hide duration when it is zero
-                                lab2 += QString(" (%1)").arg(raw);
+                                strEventTooltip += QString(" (%1)").arg(raw);
 
-                            w.ToolTip(lab2, x1 - 10, start_py + 24 + (3 * w.printScaleY()), TT_AlignRight, AppSetting->tooltipTimeout());
+                            w.ToolTip(strEventTooltip, x1 - 10, start_py + 24 + (3 * w.printScaleY()), TT_AlignRight, AppSetting->tooltipTimeout());
 
                             painter.setPen(QPen(col,3));
                         } else {
diff --git a/oscar/Graphs/gSessionTimesChart.cpp b/oscar/Graphs/gSessionTimesChart.cpp
index 29aafb29..766340d2 100644
--- a/oscar/Graphs/gSessionTimesChart.cpp
+++ b/oscar/Graphs/gSessionTimesChart.cpp
@@ -317,9 +317,10 @@ QString gSummaryChart::tooltipData(Day *, int idx)
 {
     QString txt;
     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);
-
+    int i = slices.size();
+    while (i > 0) {
+        i--;
+        txt += QString("\n%1: %2").arg(slices[i].name).arg(float(slices[i].value), 0, 'f', 2);
     }
     return txt;
 }
@@ -1240,33 +1241,35 @@ void gAHIChart::afterDraw(QPainter & /*painter */, gGraph &graph, QRectF 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));
 
-    for (auto & calc : calcitems) {
-        ChannelID code = calc.code;
+    int i = calcitems.size();
+    while (i > 0) {
+        i--;
+        ChannelID code = calcitems[i].code;
         schema::Channel & chan = schema::channel[code];
         float mid = 0;
         skip = true;
         switch (midcalc) {
         case 0:
-            if (calc.median_data.size() > 0) {
-                mid = median(calc.median_data.begin(), calc.median_data.end());
+            if (calcitems[i].median_data.size() > 0) {
+                mid = median(calcitems[i].median_data.begin(), calcitems[i].median_data.end());
                 skip = false;
             }
             break;
         case 1:
-            if (calc.divisor > 0) {
-                mid = calc.wavg_sum / calc.divisor;
+            if (calcitems[i].divisor > 0) {
+                mid = calcitems[i].wavg_sum / calcitems[i].divisor;
                 skip = false;
             }
             break;
         case 2:
-            if (calc.cnt > 0) {
-                mid = calc.avg_sum / calc.cnt;
+            if (calcitems[i].cnt > 0) {
+                mid = calcitems[i].avg_sum / calcitems[i].cnt;
                 skip = false;
             }
             break;
         }
 
-        if (!skip) txtlist.append(QString("%1 %2 / %3 / %4").arg(chan.label()).arg(calc.min, 0, 'f', 2).arg(mid, 0, 'f', 2).arg(calc.max, 0, 'f', 2));
+        if (!skip) txtlist.append(QString("%1 %2 / %3 / %4").arg(chan.label()).arg(calcitems[i].min, 0, 'f', 2).arg(mid, 0, 'f', 2).arg(calcitems[i].max, 0, 'f', 2));
     }
     QString txt = txtlist.join(", ");
     graph.renderText(txt, rect.left(), rect.top()-5*graph.printScaleY(), 0);
@@ -1294,9 +1297,11 @@ QString gAHIChart::tooltipData(Day *day, int idx)
     float total = 0;
     float hour = day->hours(m_machtype);
     QString txt;
-    for (const auto & slice : slices) {
-        total += slice.value;
-        txt += QString("\n%1: %2").arg(slice.name).arg(float(slice.value) / hour, 0, 'f', 2);
+    int i = slices.size();
+    while (i > 0) {
+        i--;
+        total += slices[i].value;
+        txt += QString("\n%1: %2").arg(slices[i].name).arg(float(slices[i].value) / hour, 0, 'f', 2);
     }
     return QString("\n%1: %2").arg(STR_TR_AHI).arg(float(total) / hour,0,'f',2)+txt;
 }