in EventFlag graph add thin bar indicating the length and time of each CPAP session

This commit is contained in:
LoudSnorer 2023-03-20 19:02:23 -04:00
parent 95981dc3a3
commit c5aa443a4e
2 changed files with 36 additions and 12 deletions

View File

@ -75,6 +75,10 @@ void gFlagsGroup::SetDay(Day *d)
return;
}
m_sessions = d->getSessions(MT_CPAP);
m_start = d->first(MT_CPAP);
m_duration = d->last(MT_CPAP) - m_start;
if (m_duration<=0) m_duration = 1; // avoid divide by zero
quint32 z = schema::FLAG | schema::SPAN | schema::MINOR_FLAG;
if (p_profile->general->showUnknownFlags()) z |= schema::UNKNOWN;
@ -145,12 +149,21 @@ void gFlagsGroup::refreshConfiguration(gGraph* graph)
if (numOn==0) numOn=1; // always have an area showing in graph.
float barHeight = QFontMetrics(*defaultfont).capHeight() + QFontMetrics(*defaultfont).descent() ;
int height (barHeight * numOn);
height += sessionBarHeight();
setMinimumHeight (height);
graph->setHeight (height);
}
int gFlagsGroup::sessionBarHeight() {
static const int m_sessionHeight = 7;
return (m_sessions.size()>1 ) ? m_sessionHeight : 0;
};
void gFlagsGroup::paint(QPainter &painter, gGraph &g, const QRegion &region)
{
if (!m_visible) { return; }
if (!m_day) { return; }
QRectF outline(region.boundingRect());
outline.translate(0.0f, 0.001f);
@ -159,10 +172,6 @@ void gFlagsGroup::paint(QPainter &painter, gGraph &g, const QRegion &region)
int width = region.boundingRect().width();
int height = region.boundingRect().height();
if (!m_visible) { return; }
if (!m_day) { return; }
QVector<gFlagsLine *> visflags;
for (const auto & flagsline : lvisible) {
@ -170,13 +179,15 @@ void gFlagsGroup::paint(QPainter &painter, gGraph &g, const QRegion &region)
visflags.push_back(flagsline);
}
int sheight = (m_sessions.size()>1?sessionBarHeight():0);
int vis = visflags.size();
m_barh = float(height) / float(vis);
float linetop = top;
m_barh = float(height-sheight) / float(vis);
float linetop = top+sheight-2;
qint64 minx,maxx,dur;
g.graphView()->GetXBounds(minx,maxx);
dur = maxx - minx;
#if BAR_TITLE_BAR_DEBUG
// debug for minimum size for event flags. adding required height for enabled events , number eventTypes , height of an event bar
QString text= QString("%1 -> %2 %3: %4 H:%5 Vis:%6 barH:%7").
@ -219,6 +230,17 @@ void gFlagsGroup::paint(QPainter &painter, gGraph &g, const QRegion &region)
linetop += m_barh;
}
// graph each session at top
if (m_sessions.size()>1 ) {
QRect sessBox(0,g.top,0,sessionBarHeight());
double adjustment = width/(double)m_duration;
for (const auto & sess : m_sessions) {
sessBox.setX(left + (sess->first()-m_start)*adjustment);
sessBox.setWidth( sess->length() * adjustment);
painter.fillRect(sessBox, QBrush(Qt::gray));
}
}
painter.setPen(COLOR_Outline);
painter.drawRect(outline);

View File

@ -127,6 +127,7 @@ class gFlagsGroup: public LayerGroup
void CloneInto(gFlagsGroup * layer) {
layer->m_alwaysvisible = m_alwaysvisible;
layer->availableChans = availableChans;
layer->m_sessions = m_sessions;
for (int i=0; i<lvisible.size(); i++) {
layer->lvisible.append(dynamic_cast<gFlagsLine *>(lvisible.at(i)->Clone()));
@ -139,15 +140,16 @@ class gFlagsGroup: public LayerGroup
protected:
virtual bool mouseMoveEvent(QMouseEvent *event, gGraph *graph);
QList<ChannelID> m_alwaysvisible;
QList<ChannelID> availableChans;
QList<Session*> m_sessions;
qint64 m_start ;
qint64 m_duration ;
QVector<gFlagsLine*> lvisible;
float m_barh;
bool m_empty;
bool m_rebuild_cpap;
int sessionBarHeight();
};
#endif // GFLAGSLINE_H