Auto-convert the Graphs/ subdirectory with astyle.

Signed-off-by: Mark Watkins <jedimark@users.sourceforge.net>
This commit is contained in:
Sean Stangl 2014-04-16 22:55:38 -07:00 committed by Mark Watkins
parent 012e9fd314
commit b5d5b82b59
23 changed files with 2974 additions and 2350 deletions

View File

@ -22,8 +22,10 @@ gFlagsLabelArea::gFlagsLabelArea(gFlagsGroup * group)
} }
bool gFlagsLabelArea::mouseMoveEvent(QMouseEvent *event, gGraph *graph) bool gFlagsLabelArea::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
{ {
if (m_group) if (m_group) {
return m_group->mouseMoveEvent(event, graph); return m_group->mouseMoveEvent(event, graph);
}
return false; return false;
} }
@ -45,6 +47,7 @@ qint64 gFlagsGroup::Minx()
if (m_day) { if (m_day) {
return m_day->first(); return m_day->first();
} }
return 0; return 0;
} }
qint64 gFlagsGroup::Maxx() qint64 gFlagsGroup::Maxx()
@ -52,6 +55,7 @@ qint64 gFlagsGroup::Maxx()
if (m_day) { if (m_day) {
return m_day->last(); return m_day->last();
} }
return 0; return 0;
} }
void gFlagsGroup::SetDay(Day *d) void gFlagsGroup::SetDay(Day *d)
@ -59,40 +63,53 @@ void gFlagsGroup::SetDay(Day * d)
LayerGroup::SetDay(d); LayerGroup::SetDay(d);
lvisible.clear(); lvisible.clear();
int cnt = 0; int cnt = 0;
for (int i = 0; i < layers.size(); i++) { for (int i = 0; i < layers.size(); i++) {
gFlagsLine *f = dynamic_cast<gFlagsLine *>(layers[i]); gFlagsLine *f = dynamic_cast<gFlagsLine *>(layers[i]);
if (!f) continue;
if (!f) { continue; }
bool e = f->isEmpty(); bool e = f->isEmpty();
if (!e || f->isAlwaysVisible()) { if (!e || f->isAlwaysVisible()) {
lvisible.push_back(f); lvisible.push_back(f);
if (!e)
if (!e) {
cnt++; cnt++;
} }
} }
}
m_empty = (cnt == 0); m_empty = (cnt == 0);
if (m_empty) { if (m_empty) {
if (d) { if (d) {
m_empty = !d->channelExists(CPAP_Pressure); m_empty = !d->channelExists(CPAP_Pressure);
} }
} }
m_barh = 0; m_barh = 0;
} }
void gFlagsGroup::paint(gGraph &g, int left, int top, int width, int height) void gFlagsGroup::paint(gGraph &g, int left, int top, int width, int height)
{ {
if (!m_visible) return; if (!m_visible) { return; }
if (!m_day) return;
if (!m_day) { return; }
int vis = lvisible.size(); int vis = lvisible.size();
m_barh = float(height) / float(vis); m_barh = float(height) / float(vis);
float linetop = top; float linetop = top;
QColor barcol; QColor barcol;
for (int i = 0; i < lvisible.size(); i++) { for (int i = 0; i < lvisible.size(); i++) {
// Alternating box color // Alternating box color
if (i & 1) barcol=COLOR_ALT_BG1; else barcol=COLOR_ALT_BG2; if (i & 1) { barcol = COLOR_ALT_BG1; }
quads->add(left, linetop, left, linetop+m_barh, left+width-1, linetop+m_barh, left+width-1, linetop, barcol.rgba()); else { barcol = COLOR_ALT_BG2; }
quads->add(left, linetop, left, linetop + m_barh, left + width - 1, linetop + m_barh,
left + width - 1, linetop, barcol.rgba());
// Paint the actual flags // Paint the actual flags
lvisible[i]->m_rect = QRect(left, linetop, width, m_barh); lvisible[i]->m_rect = QRect(left, linetop, width, m_barh);
@ -112,19 +129,22 @@ void gFlagsGroup::paint(gGraph &g, int left, int top, int width, int height)
bool gFlagsGroup::mouseMoveEvent(QMouseEvent *event, gGraph *graph) bool gFlagsGroup::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
{ {
if (!p_profile->appearance->graphTooltips()) if (!p_profile->appearance->graphTooltips()) {
return false; return false;
}
for (int i = 0; i < lvisible.size(); i++) { for (int i = 0; i < lvisible.size(); i++) {
gFlagsLine *fl = lvisible[i]; gFlagsLine *fl = lvisible[i];
if (fl->m_rect.contains(event->x(), event->y())) { if (fl->m_rect.contains(event->x(), event->y())) {
if (fl->mouseMoveEvent(event,graph)) return true; if (fl->mouseMoveEvent(event, graph)) { return true; }
} else { } else {
// Inside main graph area? // Inside main graph area?
if ((event->y() > fl->m_rect.y()) && (event->y()) < (fl->m_rect.y() + fl->m_rect.height())) { 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() < lvisible[i]->m_rect.x()) {
// Display tooltip // Display tooltip
QString ttip=schema::channel[fl->code()].fullname()+"\n"+schema::channel[fl->code()].description(); QString ttip = schema::channel[fl->code()].fullname() + "\n" +
schema::channel[fl->code()].description();
graph->ToolTip(ttip, event->x(), event->y() - 15); graph->ToolTip(ttip, event->x(), event->y() - 15);
graph->redraw(); graph->redraw();
} }
@ -132,12 +152,15 @@ bool gFlagsGroup::mouseMoveEvent(QMouseEvent * event,gGraph * graph)
} }
} }
return false; return false;
} }
gFlagsLine::gFlagsLine(ChannelID code,QColor flag_color,QString label,bool always_visible,FlagType flt) gFlagsLine::gFlagsLine(ChannelID code, QColor flag_color, QString label, bool always_visible,
:Layer(code),m_label(label),m_always_visible(always_visible),m_flt(flt),m_flag_color(flag_color) FlagType flt)
: Layer(code), m_label(label), m_always_visible(always_visible), m_flt(flt),
m_flag_color(flag_color)
{ {
addVertexBuffer(quads = new gVertexBuffer(2048, GL_QUADS)); addVertexBuffer(quads = new gVertexBuffer(2048, GL_QUADS));
//addGLBuf(lines=new GLBuffer(flag_color,1024,GL_LINES)); //addGLBuf(lines=new GLBuffer(flag_color,1024,GL_LINES));
@ -153,8 +176,10 @@ gFlagsLine::~gFlagsLine()
} }
void gFlagsLine::paint(gGraph &w, int left, int top, int width, int height) void gFlagsLine::paint(gGraph &w, int left, int top, int width, int height)
{ {
if (!m_visible) return; if (!m_visible) { return; }
if (!m_day) return;
if (!m_day) { return; }
lines = w.lines(); lines = w.lines();
double minx; double minx;
double maxx; double maxx;
@ -168,7 +193,8 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
} }
double xx = maxx - minx; double xx = maxx - minx;
if (xx<=0) return;
if (xx <= 0) { return; }
double xmult = width / xx; double xmult = width / xx;
@ -195,15 +221,20 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
qint64 drift = 0; qint64 drift = 0;
for (QList<Session *>::iterator s = m_day->begin(); s != m_day->end(); s++) { for (QList<Session *>::iterator s = m_day->begin(); s != m_day->end(); s++) {
if (!(*s)->enabled()) if (!(*s)->enabled()) {
continue; continue;
}
drift = ((*s)->machine()->GetType() == MT_CPAP) ? clockdrift : 0; drift = ((*s)->machine()->GetType() == MT_CPAP) ? clockdrift : 0;
cei = (*s)->eventlist.find(m_code); cei = (*s)->eventlist.find(m_code);
if (cei==(*s)->eventlist.end())
if (cei == (*s)->eventlist.end()) {
continue; continue;
}
QVector<EventList *> &evlist = cei.value(); QVector<EventList *> &evlist = cei.value();
for (int k = 0; k < evlist.size(); k++) { for (int k = 0; k < evlist.size(); k++) {
EventList &el = *(evlist[k]); EventList &el = *(evlist[k]);
start = el.first() + drift; start = el.first() + drift;
@ -215,13 +246,19 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
for (idx = 0; dptr < eptr; dptr++, tptr++, idx++) { for (idx = 0; dptr < eptr; dptr++, tptr++, idx++) {
X = start + *tptr; X = start + *tptr;
L = *dptr * 1000; L = *dptr * 1000;
if (X >= minx)
if (X >= minx) {
break; break;
}
X2 = X - L; X2 = X - L;
if (X2 >= minx)
if (X2 >= minx) {
break; break;
}
} }
np -= idx; np -= idx;
if (m_flt == FT_Bar) { if (m_flt == FT_Bar) {
@ -233,6 +270,7 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
// This will have to be reverted if multithreaded drawing is ever brought back // This will have to be reverted if multithreaded drawing is ever brought back
int rem = lines->Max() - lines->cnt(); int rem = lines->Max() - lines->cnt();
if ((np << 1) > rem) { if ((np << 1) > rem) {
qDebug() << "gFlagsLine would overfill lines for" << schema::channel[m_code].label(); qDebug() << "gFlagsLine would overfill lines for" << schema::channel[m_code].label();
np = rem >> 1; np = rem >> 1;
@ -242,8 +280,9 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
for (int i = 0; i < np; i++) { for (int i = 0; i < np; i++) {
X = start + *tptr++; X = start + *tptr++;
if (X > maxx) if (X > maxx) {
break; break;
}
x1 = (X - minx) * xmult + left; x1 = (X - minx) * xmult + left;
lines->add(x1, bartop, x1, bottom); lines->add(x1, bartop, x1, bottom);
@ -266,8 +305,9 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
for (; dptr < eptr; dptr++) { for (; dptr < eptr; dptr++) {
X = start + * tptr++; X = start + * tptr++;
if (X > maxx) if (X > maxx) {
break; break;
}
L = *dptr * 1000L; L = *dptr * 1000L;
X2 = X - L; X2 = X - L;
@ -280,10 +320,13 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
} }
} }
if (verts_exceeded) break;
if (verts_exceeded) { break; }
} }
if (verts_exceeded) break;
if (verts_exceeded) { break; }
} }
if (verts_exceeded) { if (verts_exceeded) {
qWarning() << "maxverts exceeded in gFlagsLine::plot()"; qWarning() << "maxverts exceeded in gFlagsLine::plot()";
} }

View File

@ -53,7 +53,8 @@ class gFlagsLine:public Layer
\param always_visible Whether to always show this line, even if empty \param always_visible Whether to always show this line, even if empty
\param Type of Flag, either FT_Bar, or FT_Span \param Type of Flag, either FT_Bar, or FT_Span
*/ */
gFlagsLine(ChannelID code,QColor col=Qt::black,QString label="",bool always_visible=false,FlagType flt=FT_Bar); gFlagsLine(ChannelID code, QColor col = Qt::black, QString label = "", bool always_visible = false,
FlagType flt = FT_Bar);
virtual ~gFlagsLine(); virtual ~gFlagsLine();
//! \brief Drawing code to add the flags and span markers to the Vertex buffers. //! \brief Drawing code to add the flags and span markers to the Vertex buffers.

View File

@ -27,11 +27,13 @@ gShadowArea::~gShadowArea()
} }
void gShadowArea::paint(gGraph &w, int left, int top, int width, int height) void gShadowArea::paint(gGraph &w, int left, int top, int width, int height)
{ {
if (!m_visible) return; if (!m_visible) { return; }
double xx = w.max_x - w.min_x; double xx = w.max_x - w.min_x;
if (xx==0) if (xx == 0) {
return; return;
}
int start_px = left - 1; int start_px = left - 1;
int end_px = left + width; int end_px = left + width;
@ -42,8 +44,10 @@ void gShadowArea::paint(gGraph & w,int left, int top, int width, int height)
double px = ((1.0 / rmx) * (w.min_x - w.rmin_x)) * width; double px = ((1.0 / rmx) * (w.min_x - w.rmin_x)) * width;
double py = ((1.0 / rmx) * (w.max_x - w.rmin_x)) * width; double py = ((1.0 / rmx) * (w.max_x - w.rmin_x)) * width;
quads->add(start_px,top,start_px,top+height,start_px+px, top+height, start_px+px, top,m_shadow_color.rgba()); quads->add(start_px, top, start_px, top + height, start_px + px, top + height, start_px + px, top,
quads->add(start_px+py, top, start_px+py, top+height,end_px, top+height, end_px, top,m_shadow_color.rgba()); m_shadow_color.rgba());
quads->add(start_px + py, top, start_px + py, top + height, end_px, top + height, end_px, top,
m_shadow_color.rgba());
lines->add(start_px + px, top, start_px + py, top, m_line_color.rgba()); lines->add(start_px + px, top, start_px + py, top, m_line_color.rgba());
lines->add(start_px + px, top + height + 1, start_px + py, top + height + 1, m_line_color.rgba()); lines->add(start_px + px, top + height + 1, start_px + py, top + height + 1, m_line_color.rgba());
@ -62,12 +66,14 @@ void gFooBar::paint(gGraph & w,int left, int top, int width, int height)
Q_UNUSED(left); Q_UNUSED(left);
Q_UNUSED(width); Q_UNUSED(width);
Q_UNUSED(height); Q_UNUSED(height);
if (!m_visible) return;
if (!m_visible) { return; }
double xx = w.max_x - w.min_x; double xx = w.max_x - w.min_x;
if (xx==0) if (xx == 0) {
return; return;
}
//int start_px=left; //int start_px=left;
//int end_px=left+width; //int end_px=left+width;

View File

@ -37,7 +37,8 @@ class gShadowArea:public Layer
class gFooBar: public Layer class gFooBar: public Layer
{ {
public: public:
gFooBar(int offset=10,QColor handle_color=QColor("orange"),QColor line_color=QColor("dark grey")); gFooBar(int offset = 10, QColor handle_color = QColor("orange"),
QColor line_color = QColor("dark grey"));
virtual ~gFooBar(); virtual ~gFooBar();
virtual void paint(gGraph &w, int left, int top, int width, int height); virtual void paint(gGraph &w, int left, int top, int width, int height);
static const int Margin = 15; static const int Margin = 15;

View File

@ -71,8 +71,7 @@ typedef quint32 RGBA;
#ifdef BUILD_WITH_MSVC #ifdef BUILD_WITH_MSVC
__declspec(align(1)) __declspec(align(1))
#endif #endif
struct gVertex struct gVertex {
{
gVertex(GLshort _x, GLshort _y, GLuint _c) { x = _x; y = _y; color = _c; } gVertex(GLshort _x, GLshort _y, GLuint _c) { x = _x; y = _y; color = _c; }
GLshort x; GLshort x;
GLshort y; GLshort y;
@ -94,16 +93,16 @@ class gVertexBuffer
m_color(0), m_color(0),
m_stipple(0xffff), m_stipple(0xffff),
m_blendfunc1(GL_SRC_ALPHA), m_blendfunc1(GL_SRC_ALPHA),
m_blendfunc2(GL_ONE_MINUS_SRC_ALPHA) m_blendfunc2(GL_ONE_MINUS_SRC_ALPHA) {
{
// FIXME: Really should not allocate in constructor. // FIXME: Really should not allocate in constructor.
buffer = (gVertex *)calloc(max, sizeof(gVertex)); buffer = (gVertex *)calloc(max, sizeof(gVertex));
} }
~gVertexBuffer() { ~gVertexBuffer() {
if (buffer) if (buffer) {
free(buffer); free(buffer);
} }
}
void add(GLshort x1, GLshort y1, RGBA color); void add(GLshort x1, GLshort y1, RGBA color);
void add(GLshort x1, GLshort y1, GLshort x2, GLshort y2, RGBA color); void add(GLshort x1, GLshort y1, GLshort x2, GLshort y2, RGBA color);
@ -290,8 +289,7 @@ class GLFloatBuffer : public GLBuffer
/*! \struct TextQue /*! \struct TextQue
\brief Holds a single item of text for the drawing queue \brief Holds a single item of text for the drawing queue
*/ */
struct TextQue struct TextQue {
{
//! \variable contains the x axis screen position to draw the text //! \variable contains the x axis screen position to draw the text
short x; short x;
//! \variable contains the y axis screen position to draw the text //! \variable contains the y axis screen position to draw the text
@ -470,27 +468,39 @@ class Layer
//! \brief Mouse wheel moved somewhere over this layer //! \brief Mouse wheel moved somewhere over this layer
virtual bool wheelEvent(QWheelEvent *event, gGraph *graph) { virtual bool wheelEvent(QWheelEvent *event, gGraph *graph) {
Q_UNUSED(event); Q_UNUSED(graph); return false; Q_UNUSED(event);
Q_UNUSED(graph);
return false;
} }
//! \brief Mouse moved somewhere over this layer //! \brief Mouse moved somewhere over this layer
virtual bool mouseMoveEvent(QMouseEvent *event, gGraph *graph) { virtual bool mouseMoveEvent(QMouseEvent *event, gGraph *graph) {
Q_UNUSED(event); Q_UNUSED(graph); return false; Q_UNUSED(event);
Q_UNUSED(graph);
return false;
} }
//! \brief Mouse left or right button pressed somewhere on this layer //! \brief Mouse left or right button pressed somewhere on this layer
virtual bool mousePressEvent(QMouseEvent *event, gGraph *graph) { virtual bool mousePressEvent(QMouseEvent *event, gGraph *graph) {
Q_UNUSED(event); Q_UNUSED(graph); return false; Q_UNUSED(event);
Q_UNUSED(graph);
return false;
} }
//! \brief Mouse button released that was originally pressed somewhere on this layer //! \brief Mouse button released that was originally pressed somewhere on this layer
virtual bool mouseReleaseEvent(QMouseEvent *event, gGraph *graph) { virtual bool mouseReleaseEvent(QMouseEvent *event, gGraph *graph) {
Q_UNUSED(event); Q_UNUSED(graph); return false; Q_UNUSED(event);
Q_UNUSED(graph);
return false;
} }
//! \brief Mouse button double clicked somewhere on this layer //! \brief Mouse button double clicked somewhere on this layer
virtual bool mouseDoubleClickEvent(QMouseEvent *event, gGraph *graph) { virtual bool mouseDoubleClickEvent(QMouseEvent *event, gGraph *graph) {
Q_UNUSED(event); Q_UNUSED(graph); return false; Q_UNUSED(event);
Q_UNUSED(graph);
return false;
} }
//! \brief A key was pressed on the keyboard while the graph area was focused. //! \brief A key was pressed on the keyboard while the graph area was focused.
virtual bool keyPressEvent(QKeyEvent *event, gGraph *graph) { virtual bool keyPressEvent(QKeyEvent *event, gGraph *graph) {
Q_UNUSED(event); Q_UNUSED(graph); return false; Q_UNUSED(event);
Q_UNUSED(graph);
return false;
} }
}; };
@ -837,8 +847,10 @@ class gGraph : public QObject
//! \brief Sets the margins for the four sides of this graph. //! \brief Sets the margins for the four sides of this graph.
void setMargins(short left, short right, short top, short bottom) { void setMargins(short left, short right, short top, short bottom) {
m_marginleft = left; m_marginright = right; m_marginleft = left;
m_margintop = top; m_marginbottom = bottom; m_marginright = right;
m_margintop = top;
m_marginbottom = bottom;
} }
//! \brief Returns this graphs left margin //! \brief Returns this graphs left margin
@ -950,8 +962,7 @@ class gGraph : public QObject
\brief My version of Pixmap cache with texture binding support \brief My version of Pixmap cache with texture binding support
*/ */
struct myPixmapCache struct myPixmapCache {
{
quint64 last_used; quint64 last_used;
QImage image; QImage image;
GLuint textureID; GLuint textureID;

View File

@ -34,15 +34,20 @@ gLineChart::~gLineChart()
bool gLineChart::isEmpty() bool gLineChart::isEmpty()
{ {
if (!m_day) return true; if (!m_day) { return true; }
for (int j = 0; j < m_codes.size(); j++) { for (int j = 0; j < m_codes.size(); j++) {
ChannelID code = m_codes[j]; ChannelID code = m_codes[j];
for (int i = 0; i < m_day->size(); i++) { for (int i = 0; i < m_day->size(); i++) {
Session *sess = m_day->getSessions()[i]; Session *sess = m_day->getSessions()[i];
if (sess->channelExists(code))
if (sess->channelExists(code)) {
return false; return false;
} }
} }
}
return true; return true;
} }
@ -55,8 +60,9 @@ void gLineChart::SetDay(Day *d)
m_miny = 0, m_maxy = 0; m_miny = 0, m_maxy = 0;
m_physminy = 0, m_physmaxy = 0; m_physminy = 0, m_physmaxy = 0;
if (!d) if (!d) {
return; return;
}
qint64 t64; qint64 t64;
EventDataType tmp; EventDataType tmp;
@ -65,9 +71,12 @@ void gLineChart::SetDay(Day *d)
for (int j = 0; j < m_codes.size(); j++) { for (int j = 0; j < m_codes.size(); j++) {
ChannelID code = m_codes[j]; ChannelID code = m_codes[j];
for (int i = 0; i < d->size(); i++) { for (int i = 0; i < d->size(); i++) {
Session *sess = d->getSessions()[i]; Session *sess = d->getSessions()[i];
if (!sess->channelExists(code)) continue;
if (!sess->channelExists(code)) { continue; }
if (first) { if (first) {
m_miny = sess->Min(code); m_miny = sess->Min(code);
m_maxy = sess->Max(code); m_maxy = sess->Max(code);
@ -78,30 +87,42 @@ void gLineChart::SetDay(Day *d)
first = false; first = false;
} else { } else {
tmp = sess->physMin(code); tmp = sess->physMin(code);
if (m_physminy > tmp)
if (m_physminy > tmp) {
m_physminy = tmp; m_physminy = tmp;
}
tmp = sess->physMax(code); tmp = sess->physMax(code);
if (m_physmaxy < tmp)
if (m_physmaxy < tmp) {
m_physmaxy = tmp; m_physmaxy = tmp;
}
tmp = sess->Min(code); tmp = sess->Min(code);
if (m_miny > tmp)
if (m_miny > tmp) {
m_miny = tmp; m_miny = tmp;
}
tmp = sess->Max(code); tmp = sess->Max(code);
if (m_maxy < tmp)
if (m_maxy < tmp) {
m_maxy = tmp; m_maxy = tmp;
}
t64 = sess->first(code); t64 = sess->first(code);
if (m_minx > t64)
if (m_minx > t64) {
m_minx = t64; m_minx = t64;
}
t64 = sess->last(code); t64 = sess->last(code);
if (m_maxx < t64)
if (m_maxx < t64) {
m_maxx = t64; m_maxx = t64;
} }
} }
}
} }
@ -115,10 +136,13 @@ void gLineChart::SetDay(Day *d)
EventDataType gLineChart::Miny() EventDataType gLineChart::Miny()
{ {
int m = Layer::Miny(); int m = Layer::Miny();
if (subtract_offset > 0) { if (subtract_offset > 0) {
m -= subtract_offset; m -= subtract_offset;
if (m<0) m=0;
if (m < 0) { m = 0; }
} }
return m; return m;
} }
EventDataType gLineChart::Maxy() EventDataType gLineChart::Maxy()
@ -129,16 +153,19 @@ EventDataType gLineChart::Maxy()
// Time Domain Line Chart // Time Domain Line Chart
void gLineChart::paint(gGraph &w, int left, int top, int width, int height) void gLineChart::paint(gGraph &w, int left, int top, int width, int height)
{ {
if (!m_visible) if (!m_visible) {
return; return;
}
if (!m_day) if (!m_day) {
return; return;
}
//if (!m_day->channelExists(m_code)) return; //if (!m_day->channelExists(m_code)) return;
if (width<0) if (width < 0) {
return; return;
}
// lines=w.lines(); // lines=w.lines();
EventDataType miny, maxy; EventDataType miny, maxy;
@ -162,6 +189,7 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
} else { } else {
miny = w.min_y, maxy = w.max_y; miny = w.min_y, maxy = w.max_y;
} }
w.roundY(miny, maxy); w.roundY(miny, maxy);
double xx = maxx - minx; double xx = maxx - minx;
@ -171,12 +199,15 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
EventDataType ymult = EventDataType(height - 3) / yy; // time to pixel conversion multiplier EventDataType ymult = EventDataType(height - 3) / yy; // time to pixel conversion multiplier
// Return on screwy min/max conditions // Return on screwy min/max conditions
if (xx<0) if (xx < 0) {
return; return;
}
if (yy <= 0) { if (yy <= 0) {
if (miny==0) if (miny == 0) {
return; return;
} }
}
EventDataType lastpx, lastpy; EventDataType lastpx, lastpy;
EventDataType px, py; EventDataType px, py;
@ -211,6 +242,7 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
int legendx = left + width; int legendx = left + width;
int codepoints; int codepoints;
//GLuint color; //GLuint color;
for (int gi = 0; gi < m_codes.size(); gi++) { for (int gi = 0; gi < m_codes.size(); gi++) {
ChannelID code = m_codes[gi]; ChannelID code = m_codes[gi];
@ -219,8 +251,10 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
//color=m_line_color.rgba(); //color=m_line_color.rgba();
codepoints = 0; codepoints = 0;
for (int svi = 0; svi < m_day->size(); svi++) { for (int svi = 0; svi < m_day->size(); svi++) {
Session *sess = (*m_day)[svi]; Session *sess = (*m_day)[svi];
if (!sess) { if (!sess) {
qWarning() << "gLineChart::Plot() NULL Session Record.. This should not happen"; qWarning() << "gLineChart::Plot() NULL Session Record.. This should not happen";
continue; continue;
@ -228,58 +262,74 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
drift = (sess->machine()->GetType() == MT_CPAP) ? clockdrift : 0; drift = (sess->machine()->GetType() == MT_CPAP) ? clockdrift : 0;
if (!sess->enabled()) continue; if (!sess->enabled()) { continue; }
schema::Channel ch = schema::channel[code]; schema::Channel ch = schema::channel[code];
bool fndbetter = false; bool fndbetter = false;
for (QList<schema::Channel *>::iterator l = ch.m_links.begin(); l != ch.m_links.end(); l++) { for (QList<schema::Channel *>::iterator l = ch.m_links.begin(); l != ch.m_links.end(); l++) {
schema::Channel *c = *l; schema::Channel *c = *l;
ci = (*m_day)[svi]->eventlist.find(c->id()); ci = (*m_day)[svi]->eventlist.find(c->id());
if (ci != (*m_day)[svi]->eventlist.end()) { if (ci != (*m_day)[svi]->eventlist.end()) {
fndbetter = true; fndbetter = true;
break; break;
} }
} }
if (!fndbetter) { if (!fndbetter) {
ci = (*m_day)[svi]->eventlist.find(code); ci = (*m_day)[svi]->eventlist.find(code);
if (ci==(*m_day)[svi]->eventlist.end()) continue;
if (ci == (*m_day)[svi]->eventlist.end()) { continue; }
} }
QVector<EventList *> &evec = ci.value(); QVector<EventList *> &evec = ci.value();
num_points = 0; num_points = 0;
for (int i=0;i<evec.size();i++)
for (int i = 0; i < evec.size(); i++) {
num_points += evec[i]->count(); num_points += evec[i]->count();
}
total_points += num_points; total_points += num_points;
codepoints += num_points; codepoints += num_points;
const int num_averages=20; // Max n umber of samples taken from samples per pixel for better min/max values const int num_averages =
20; // Max n umber of samples taken from samples per pixel for better min/max values
for (int n = 0; n < evec.size(); n++) { // for each segment for (int n = 0; n < evec.size(); n++) { // for each segment
EventList &el = *evec[n]; EventList &el = *evec[n];
accel = (el.type() == EVL_Waveform); // Turn on acceleration if this is a waveform. accel = (el.type() == EVL_Waveform); // Turn on acceleration if this is a waveform.
if (accel) { if (accel) {
sr = el.rate(); // Time distance between samples sr = el.rate(); // Time distance between samples
if (sr <= 0) { if (sr <= 0) {
qWarning() << "qLineChart::Plot() assert(sr>0)"; qWarning() << "qLineChart::Plot() assert(sr>0)";
continue; continue;
} }
} }
if (m_disable_accel) accel=false;
if (m_disable_accel) { accel = false; }
square_plot = m_square_plot; square_plot = m_square_plot;
if (accel || num_points > 20000) { // Don't square plot if too many points or waveform if (accel || num_points > 20000) { // Don't square plot if too many points or waveform
square_plot = false; square_plot = false;
} }
int siz = evec[n]->count(); int siz = evec[n]->count();
if (siz<=1) continue; // Don't bother drawing 1 point or less.
if (siz <= 1) { continue; } // Don't bother drawing 1 point or less.
x0 = el.time(0) + drift; x0 = el.time(0) + drift;
xL = el.time(siz - 1) + drift; xL = el.time(siz - 1) + drift;
if (maxx<x0) continue; if (maxx < x0) { continue; }
if (xL<minx) continue;
if (xL < minx) { continue; }
if (x0 > xL) { if (x0 > xL) {
if (siz == 2) { // this happens on CPAP if (siz == 2) { // this happens on CPAP
@ -296,6 +346,7 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
//assert(x1<x2); //assert(x1<x2);
} }
} }
if (accel) { if (accel) {
//x1=el.time(1); //x1=el.time(1);
@ -307,28 +358,34 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
double ZQ = ZR / XR; double ZQ = ZR / XR;
double ZW = ZR / (width * ZQ); double ZW = ZR / (width * ZQ);
visible_points += ZR * ZQ; visible_points += ZR * ZQ;
if (accel && n > 0) { if (accel && n > 0) {
sam = 1; sam = 1;
} }
if (ZW < num_averages) { if (ZW < num_averages) {
sam = 1; sam = 1;
accel = false; accel = false;
} else { } else {
sam = ZW / num_averages; sam = ZW / num_averages;
if (sam < 1) { if (sam < 1) {
sam = 1; sam = 1;
accel = false; accel = false;
} }
} }
// Prepare the min max y values if we still are accelerating this plot // Prepare the min max y values if we still are accelerating this plot
if (accel) { if (accel) {
for (int i = 0; i < width; i++) { for (int i = 0; i < width; i++) {
m_drawlist[i].setX(height); m_drawlist[i].setX(height);
m_drawlist[i].setY(0); m_drawlist[i].setY(0);
} }
minz = width; minz = width;
maxz = 0; maxz = 0;
} }
total_visible += visible_points; total_visible += visible_points;
} else { } else {
sam = 1; sam = 1;
@ -376,7 +433,8 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
// } else lines->setSize(1); // } else lines->setSize(1);
if (el.type() == EVL_Waveform) { // Waveform Plot if (el.type() == EVL_Waveform) { // Waveform Plot
if (idx > sam) idx-=sam; if (idx > sam) { idx -= sam; }
time = el.time(idx) + drift; time = el.time(idx) + drift;
double rate = double(sr) * double(sam); double rate = double(sr) * double(sam);
EventStoreType *ptr = el.rawData() + idx; EventStoreType *ptr = el.rawData() + idx;
@ -408,26 +466,33 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
// m_drawlist's index is the pixel index for the X pixel axis. // m_drawlist's index is the pixel index for the X pixel axis.
int z = round(px); // Hmmm... round may screw this up. int z = round(px); // Hmmm... round may screw this up.
if (z<minz) if (z < minz) {
minz = z; // minz=First pixel minz = z; // minz=First pixel
}
if (z>maxz) if (z > maxz) {
maxz = z; // maxz=Last pixel maxz = z; // maxz=Last pixel
}
if (minz < 0) { if (minz < 0) {
qDebug() << "gLineChart::Plot() minz<0 should never happen!! minz =" << minz; qDebug() << "gLineChart::Plot() minz<0 should never happen!! minz =" << minz;
minz = 0; minz = 0;
} }
if (maxz > max_drawlist_size) { if (maxz > max_drawlist_size) {
qDebug() << "gLineChart::Plot() maxz>max_drawlist_size!!!! maxz = " << maxz << " max_drawlist_size =" << max_drawlist_size; qDebug() << "gLineChart::Plot() maxz>max_drawlist_size!!!! maxz = " << maxz <<
" max_drawlist_size =" << max_drawlist_size;
maxz = max_drawlist_size; maxz = max_drawlist_size;
} }
// Update the Y pixel bounds. // Update the Y pixel bounds.
if (py<m_drawlist[z].x()) if (py < m_drawlist[z].x()) {
m_drawlist[z].setX(py); m_drawlist[z].setX(py);
if (py>m_drawlist[z].y()) }
if (py > m_drawlist[z].y()) {
m_drawlist[z].setY(py); m_drawlist[z].setY(py);
}
if (time > maxx) { if (time > maxx) {
done = true; done = true;
@ -435,10 +500,12 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
} }
} }
// Plot compressed accelerated vertex list // Plot compressed accelerated vertex list
if (maxz > width) { if (maxz > width) {
maxz = width; maxz = width;
} }
float ax1, ay1; float ax1, ay1;
QPoint *drl = m_drawlist + minz; QPoint *drl = m_drawlist + minz;
// Don't need to cap VertexBuffer here, as it's limited to max_drawlist_size anyway // Don't need to cap VertexBuffer here, as it's limited to max_drawlist_size anyway
@ -448,6 +515,7 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
int np = (maxz - minz) * 2; int np = (maxz - minz) * 2;
int j = lines->Max() - lines->cnt(); int j = lines->Max() - lines->cnt();
if (np < j) { if (np < j) {
for (int i = minz; i < maxz; i++, drl++) { for (int i = minz; i < maxz; i++, drl++) {
ax1 = drl->x(); ax1 = drl->x();
@ -497,10 +565,12 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
done = true; done = true;
break; break;
} }
if (lines->full())
if (lines->full()) {
break; break;
} }
} }
}
} else { } else {
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -516,6 +586,7 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
if (siz > 15) { if (siz > 15) {
for (; idx < siz; ++idx) { for (; idx < siz; ++idx) {
time = start + *tptr++; time = start + *tptr++;
if (time >= minx) { if (time >= minx) {
break; break;
} }
@ -544,8 +615,11 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
// Check if would overflow lines gVertexBuffer // Check if would overflow lines gVertexBuffer
int gs = siz << 1; int gs = siz << 1;
int j = lines->Max() - lines->cnt(); int j = lines->Max() - lines->cnt();
if (square_plot)
if (square_plot) {
gs <<= 1; gs <<= 1;
}
if (gs > j) { if (gs > j) {
qDebug() << "Would overflow line points.. increase default VertexBuffer size in gLineChart"; qDebug() << "Would overflow line points.. increase default VertexBuffer size in gLineChart";
siz = (j >> square_plot) ? 2 : 1; siz = (j >> square_plot) ? 2 : 1;
@ -554,6 +628,7 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
// Unrolling square plot outside of loop to gain a minor speed improvement. // Unrolling square plot outside of loop to gain a minor speed improvement.
EventStoreType *eptr = dptr + siz; EventStoreType *eptr = dptr + siz;
if (square_plot) { if (square_plot) {
for (; dptr < eptr; dptr++) { for (; dptr < eptr; dptr++) {
time = start + *tptr++; time = start + *tptr++;
@ -565,10 +640,10 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
// Horizontal lines are easy to cap // Horizontal lines are easy to cap
if (py == lastpy) { if (py == lastpy) {
// Cap px to left margin // Cap px to left margin
if (lastpx<xst) lastpx=xst; if (lastpx < xst) { lastpx = xst; }
// Cap px to right margin // Cap px to right margin
if (px>xst+width) px=xst+width; if (px > xst + width) { px = xst + width; }
lines->unsafe_add(lastpx, lastpy, px, lastpy, px, lastpy, px, py); lines->unsafe_add(lastpx, lastpy, px, lastpy, px, lastpy, px, py);
} else { } else {
@ -598,10 +673,10 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
// Horizontal lines are easy to cap // Horizontal lines are easy to cap
if (py == lastpy) { if (py == lastpy) {
// Cap px to left margin // Cap px to left margin
if (lastpx<xst) lastpx=xst; if (lastpx < xst) { lastpx = xst; }
// Cap px to right margin // Cap px to right margin
if (px>xst+width) px=xst+width; if (px > xst + width) { px = xst + width; }
lines->unsafe_add(lastpx, lastpy, px, py); lines->unsafe_add(lastpx, lastpy, px, py);
} else { } else {
@ -622,7 +697,7 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
} }
} }
if (done) break; if (done) { break; }
} }
} }
@ -642,10 +717,12 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
w.renderText(text, legendx, top - 4); w.renderText(text, legendx, top - 4);
int tp = top - 5 - bh / 2; int tp = top - 5 - bh / 2;
w.quads()->add(legendx-bw,tp+bh/2,legendx,tp+bh/2,legendx,tp-bh/2,legendx-bw,tp-bh/2,m_colors[gi].rgba()); w.quads()->add(legendx - bw, tp + bh / 2, legendx, tp + bh / 2, legendx, tp - bh / 2, legendx - bw,
tp - bh / 2, m_colors[gi].rgba());
legendx -= bw * 2; legendx -= bw * 2;
} }
} }
if (!total_points) { // No Data? if (!total_points) { // No Data?
if (m_report_empty) { if (m_report_empty) {
@ -681,11 +758,13 @@ AHIChart::~AHIChart()
void AHIChart::paint(gGraph &w, int left, int top, int width, int height) void AHIChart::paint(gGraph &w, int left, int top, int width, int height)
{ {
if (!m_visible) if (!m_visible) {
return; return;
}
if (!m_day) if (!m_day) {
return; return;
}
// Draw bounding box // Draw bounding box
gVertexBuffer *outlines = w.lines(); gVertexBuffer *outlines = w.lines();
@ -710,6 +789,7 @@ void AHIChart::paint(gGraph & w,int left, int top, int width, int height)
} else { } else {
miny = w.min_y, maxy = w.max_y; miny = w.min_y, maxy = w.max_y;
} }
w.roundY(miny, maxy); w.roundY(miny, maxy);
double xx = maxx - minx; double xx = maxx - minx;
@ -723,18 +803,23 @@ void AHIChart::paint(gGraph & w,int left, int top, int width, int height)
double lastpx, lastpy; double lastpx, lastpy;
double top1 = top + height; double top1 = top + height;
bool done = false; bool done = false;
//GLuint color=m_color.rgba(); //GLuint color=m_color.rgba();
for (int i = 0; i < m_time.size(); i++) { for (int i = 0; i < m_time.size(); i++) {
qint64 ti = m_time[i]; qint64 ti = m_time[i];
EventDataType v = m_data[i]; EventDataType v = m_data[i];
if (ti<minx) continue;
if (ti>maxx) done=true; if (ti < minx) { continue; }
if (ti > maxx) { done = true; }
if (first) { if (first) {
if (i > 0) { if (i > 0) {
ti = m_time[i - 1]; ti = m_time[i - 1];
v = m_data[i - 1]; v = m_data[i - 1];
i--; i--;
} }
px = left + (double(ti - minx) * xmult); px = left + (double(ti - minx) * xmult);
py = top1 - (double(v - miny) * ymult); py = top1 - (double(v - miny) * ymult);
first = false; first = false;
@ -743,10 +828,13 @@ void AHIChart::paint(gGraph & w,int left, int top, int width, int height)
py = top1 - (double(v - miny) * ymult); py = top1 - (double(v - miny) * ymult);
lines->add(px, py, lastpx, lastpy); lines->add(px, py, lastpx, lastpy);
} }
lastpx = px; lastpx = px;
lastpy = py; lastpy = py;
if (done) break;
if (done) { break; }
} }
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
float dpr = w.graphView()->devicePixelRatio(); float dpr = w.graphView()->devicePixelRatio();
lines->scissor(left * dpr, w.flipY(top + height + 2)*dpr, (width + 1)*dpr, (height + 1)*dpr); lines->scissor(left * dpr, w.flipY(top + height + 2)*dpr, (width + 1)*dpr, (height + 1)*dpr);
@ -763,7 +851,8 @@ void AHIChart::SetDay(Day *d)
m_maxy = 0; m_maxy = 0;
m_miny = 0; m_miny = 0;
if (!d) return; if (!d) { return; }
m_miny = 9999; m_miny = 9999;
QList<Session *>::iterator s; QList<Session *>::iterator s;
qint64 first = d->first(); qint64 first = d->first();
@ -771,6 +860,7 @@ void AHIChart::SetDay(Day *d)
qint64 f; qint64 f;
qint64 winsize = 30000; // 30 second windows qint64 winsize = 30000; // 30 second windows
for (qint64 ti = first; ti < last; ti += winsize) { for (qint64 ti = first; ti < last; ti += winsize) {
f = ti - 3600000L; f = ti - 3600000L;
//if (f<first) f=first; //if (f<first) f=first;
@ -781,58 +871,79 @@ void AHIChart::SetDay(Day *d)
qint64 clockdrift = (qint64(PROFILE.cpap->clockDrift()) * 1000L), drift = 0; qint64 clockdrift = (qint64(PROFILE.cpap->clockDrift()) * 1000L), drift = 0;
bool fnd = false; bool fnd = false;
for (s = d->begin(); s != d->end(); s++) { for (s = d->begin(); s != d->end(); s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) { continue; }
Session *sess = *s; Session *sess = *s;
if ((ti < sess->first()) || (f > sess->last())) continue;
if ((ti < sess->first()) || (f > sess->last())) { continue; }
drift = (sess->machine()->GetType() == MT_CPAP) ? clockdrift : 0; drift = (sess->machine()->GetType() == MT_CPAP) ? clockdrift : 0;
// Drop off suddenly outside of sessions // Drop off suddenly outside of sessions
//if (ti>sess->last()) continue; //if (ti>sess->last()) continue;
fnd = true; fnd = true;
if (sess->eventlist.contains(CPAP_Obstructive))
if (sess->eventlist.contains(CPAP_Obstructive)) {
el[0] = sess->eventlist[CPAP_Obstructive][0]; el[0] = sess->eventlist[CPAP_Obstructive][0];
else el[0]=NULL; } else { el[0] = NULL; }
if (sess->eventlist.contains(CPAP_Apnea))
if (sess->eventlist.contains(CPAP_Apnea)) {
el[1] = sess->eventlist[CPAP_Apnea][0]; el[1] = sess->eventlist[CPAP_Apnea][0];
else el[1]=NULL; } else { el[1] = NULL; }
if (sess->eventlist.contains(CPAP_Hypopnea))
if (sess->eventlist.contains(CPAP_Hypopnea)) {
el[2] = sess->eventlist[CPAP_Hypopnea][0]; el[2] = sess->eventlist[CPAP_Hypopnea][0];
else el[2]=NULL; } else { el[2] = NULL; }
if (sess->eventlist.contains(CPAP_ClearAirway))
if (sess->eventlist.contains(CPAP_ClearAirway)) {
el[3] = sess->eventlist[CPAP_ClearAirway][0]; el[3] = sess->eventlist[CPAP_ClearAirway][0];
else el[3]=NULL; } else { el[3] = NULL; }
if (sess->eventlist.contains(CPAP_NRI))
if (sess->eventlist.contains(CPAP_NRI)) {
el[4] = sess->eventlist[CPAP_NRI][0]; el[4] = sess->eventlist[CPAP_NRI][0];
else el[4]=NULL; } else { el[4] = NULL; }
int znt = 5; int znt = 5;
if (PROFILE.general->calculateRDI()) { if (PROFILE.general->calculateRDI()) {
if (sess->eventlist.contains(CPAP_RERA)) {// What about ExP?? if (sess->eventlist.contains(CPAP_RERA)) {// What about ExP??
el[5] = sess->eventlist[CPAP_RERA][0]; el[5] = sess->eventlist[CPAP_RERA][0];
znt++; znt++;
} else el[5]=NULL; } else { el[5] = NULL; }
} }
qint64 t; qint64 t;
for (int i = 0; i < znt; i++) { for (int i = 0; i < znt; i++) {
if (!el[i]) continue; if (!el[i]) { continue; }
for (quint32 j = 0; j < el[i]->count(); j++) { for (quint32 j = 0; j < el[i]->count(); j++) {
t = el[i]->time(j) + drift; t = el[i]->time(j) + drift;
if ((t >= f) && (t < ti)) { if ((t >= f) && (t < ti)) {
cnt++; cnt++;
} }
} }
} }
} }
if (!fnd) cnt=0;
double g=double(ti-f)/3600000.0;
if (g>0) ahi=cnt/g;
if (ahi<m_miny) m_miny=ahi; if (!fnd) { cnt = 0; }
if (ahi>m_maxy) m_maxy=ahi;
double g = double(ti - f) / 3600000.0;
if (g > 0) { ahi = cnt / g; }
if (ahi < m_miny) { m_miny = ahi; }
if (ahi > m_maxy) { m_maxy = ahi; }
m_time.append(ti); m_time.append(ti);
m_data.append(ahi); m_data.append(ahi);
} }
m_minx = first; m_minx = first;
m_maxx = last; m_maxx = last;
} }

View File

@ -69,7 +69,8 @@ class gLineChart:public Layer
\param square_plot Whether or not to use square plots (only effective for EVL_Event typed EventList data) \param square_plot Whether or not to use square plots (only effective for EVL_Event typed EventList data)
\param disable_accel Whether or not to disable acceleration for EVL_Waveform typed EventList data \param disable_accel Whether or not to disable acceleration for EVL_Waveform typed EventList data
*/ */
gLineChart(ChannelID code,const QColor col=QColor("black"), bool square_plot=false,bool disable_accel=false); gLineChart(ChannelID code, const QColor col = QColor("black"), bool square_plot = false,
bool disable_accel = false);
virtual ~gLineChart(); virtual ~gLineChart();
//! \brief The drawing code that fills the vertex buffers //! \brief The drawing code that fills the vertex buffers
@ -110,7 +111,7 @@ class gLineChart:public Layer
void addPlot(ChannelID code, QColor color, bool square) { m_codes.push_back(code); m_colors.push_back(color); m_enabled[code] = true; m_square.push_back(square); } void addPlot(ChannelID code, QColor color, bool square) { m_codes.push_back(code); m_colors.push_back(color); m_enabled[code] = true; m_square.push_back(square); }
//! \brief Returns true of the subplot 'code' is enabled. //! \brief Returns true of the subplot 'code' is enabled.
bool plotEnabled(ChannelID code) { if ((m_enabled.contains(code)) && m_enabled[code]) return true; else return false; } bool plotEnabled(ChannelID code) { if ((m_enabled.contains(code)) && m_enabled[code]) { return true; } else { return false; } }
//! \brief Enable or Disable the subplot identified by code. //! \brief Enable or Disable the subplot identified by code.
void setPlotEnabled(ChannelID code, bool b) { m_enabled[code] = b; } void setPlotEnabled(ChannelID code, bool b) { m_enabled[code] = b; }

View File

@ -35,15 +35,17 @@ gLineOverlayBar::~gLineOverlayBar()
void gLineOverlayBar::paint(gGraph &w, int left, int topp, int width, int height) void gLineOverlayBar::paint(gGraph &w, int left, int topp, int width, int height)
{ {
if (!m_visible) return; if (!m_visible) { return; }
if (!m_day) return;
if (!m_day) { return; }
gVertexBuffer *lines = w.lines(); gVertexBuffer *lines = w.lines();
int start_py = topp; int start_py = topp;
double xx = w.max_x - w.min_x; double xx = w.max_x - w.min_x;
double yy = w.max_y - w.min_y; double yy = w.max_y - w.min_y;
if (xx<=0) return;
if (xx <= 0) { return; }
float x1, x2; float x1, x2;
@ -62,9 +64,11 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
lines->setColor(m_flag_color); lines->setColor(m_flag_color);
points->setColor(m_flag_color); points->setColor(m_flag_color);
if (m_flt == FT_Span) { if (m_flt == FT_Span) {
m_flag_color.setAlpha(128); m_flag_color.setAlpha(128);
} }
EventStoreType raw; EventStoreType raw;
quint32 *tptr; quint32 *tptr;
@ -81,11 +85,16 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
// For each session, process it's eventlist // For each session, process it's eventlist
for (QList<Session *>::iterator s = m_day->begin(); s != m_day->end(); s++) { for (QList<Session *>::iterator s = m_day->begin(); s != m_day->end(); s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) { continue; }
cei = (*s)->eventlist.find(m_code); cei = (*s)->eventlist.find(m_code);
if (cei==(*s)->eventlist.end()) continue;
if (cei == (*s)->eventlist.end()) { continue; }
QVector<EventList *> &evlist = cei.value(); QVector<EventList *> &evlist = cei.value();
if (evlist.size()==0) continue;
if (evlist.size() == 0) { continue; }
drift = ((*s)->machine()->GetType() == MT_CPAP) ? clockdrift : 0; drift = ((*s)->machine()->GetType() == MT_CPAP) ? clockdrift : 0;
// Could loop through here, but nowhere uses more than one yet.. // Could loop through here, but nowhere uses more than one yet..
@ -102,8 +111,11 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
for (; dptr < eptr; dptr++) { for (; dptr < eptr; dptr++) {
X = stime + *tptr; X = stime + *tptr;
if (X >= w.min_x)
if (X >= w.min_x) {
break; break;
}
tptr++; tptr++;
} }
@ -115,21 +127,31 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
X = stime + *tptr++; X = stime + *tptr++;
raw = *dptr; raw = *dptr;
Y = X - (qint64(raw) * 1000.0L); // duration Y = X - (qint64(raw) * 1000.0L); // duration
if (Y > w.max_x)
if (Y > w.max_x) {
break; break;
}
x1 = double(width) / double(xx) * double(X - w.min_x) + left; x1 = double(width) / double(xx) * double(X - w.min_x) + left;
m_count++; m_count++;
m_sum += raw; m_sum += raw;
x2 = double(width) / double(xx) * double(Y - w.min_x) + left; x2 = double(width) / double(xx) * double(Y - w.min_x) + left;
if (int(x1)==int(x2)) if (int(x1) == int(x2)) {
x2 += 1; x2 += 1;
if (x2<left) }
x2=left;
if (x1>width+left) if (x2 < left) {
x1=width+left; x2 = left;
}
if (x1 > width + left) {
x1 = width + left;
}
quads->add(x2, start_py, x1, start_py, x1, start_py + height, x2, start_py + height,
m_flag_color.rgba());
quads->add(x2,start_py, x1,start_py, x1,start_py+height, x2,start_py+height,m_flag_color.rgba());
if (quads->full()) { if (quads->full()) {
verts_exceeded = true; verts_exceeded = true;
break; break;
@ -142,14 +164,19 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
for (; dptr < eptr; dptr++) { for (; dptr < eptr; dptr++) {
X = stime + *tptr++; //el.time(i); X = stime + *tptr++; //el.time(i);
raw = *dptr; //el.data(i); raw = *dptr; //el.data(i);
if (X > w.max_x)
if (X > w.max_x) {
break; break;
}
x1 = double(width) / double(xx) * double(X - w.min_x) + left; x1 = double(width) / double(xx) * double(X - w.min_x) + left;
m_count++; m_count++;
m_sum += raw; m_sum += raw;
if ((odt == ODT_Bars) || (xx < 3600000)) { if ((odt == ODT_Bars) || (xx < 3600000)) {
// show the fat dots in the middle // show the fat dots in the middle
points->add(x1, double(height) / double(yy)*double(-20 - w.min_y) + topp); points->add(x1, double(height) / double(yy)*double(-20 - w.min_y) + topp);
if (points->full()) { if (points->full()) {
verts_exceeded = true; verts_exceeded = true;
break; break;
@ -157,6 +184,7 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
} else { } else {
// thin lines down the bottom // thin lines down the bottom
lines->add(x1, start_py + 1, x1, start_py + 1 + 12); lines->add(x1, start_py + 1, x1, start_py + 1 + 12);
if (lines->full()) { if (lines->full()) {
verts_exceeded = true; verts_exceeded = true;
break; break;
@ -171,17 +199,22 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
for (; dptr < eptr; dptr++) { for (; dptr < eptr; dptr++) {
X = stime + *tptr++; X = stime + *tptr++;
raw = *dptr; raw = *dptr;
if (X > w.max_x)
if (X > w.max_x) {
break; break;
}
x1 = double(width) / double(xx) * double(X - w.min_x) + left; x1 = double(width) / double(xx) * double(X - w.min_x) + left;
m_count++; m_count++;
m_sum += raw; m_sum += raw;
int z = start_py + height; int z = start_py + height;
if ((odt == ODT_Bars) || (xx < 3600000)) { if ((odt == ODT_Bars) || (xx < 3600000)) {
z = top; z = top;
points->add(x1, top); points->add(x1, top);
lines->add(x1, top, x1, bottom); lines->add(x1, top, x1, bottom);
if (points->full()) { if (points->full()) {
verts_exceeded = true; verts_exceeded = true;
break; break;
@ -189,10 +222,12 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
} else { } else {
lines->add(x1, z, x1, z - 12); lines->add(x1, z, x1, z - 12);
} }
if (lines->full()) { if (lines->full()) {
verts_exceeded = true; verts_exceeded = true;
break; break;
} }
if (xx < (1800000)) { if (xx < (1800000)) {
GetTextExtent(m_label, x, y); GetTextExtent(m_label, x, y);
w.renderText(m_label, x1 - (x / 2), top - y + (3 * w.printScaleY())); w.renderText(m_label, x1 - (x / 2), top - y + (3 * w.printScaleY()));
@ -200,12 +235,16 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
} }
} }
if (verts_exceeded) if (verts_exceeded) {
break; break;
} }
if (verts_exceeded) }
if (verts_exceeded) {
break; break;
} }
}
if (verts_exceeded) { if (verts_exceeded) {
qWarning() << "exceeded maxverts in gLineOverlay::Plot()"; qWarning() << "exceeded maxverts in gLineOverlay::Plot()";
} }
@ -222,8 +261,9 @@ gLineOverlaySummary::~gLineOverlaySummary()
void gLineOverlaySummary::paint(gGraph &w, int left, int top, int width, int height) void gLineOverlaySummary::paint(gGraph &w, int left, int top, int width, int height)
{ {
if (!m_visible) return; if (!m_visible) { return; }
if (!m_day) return;
if (!m_day) { return; }
Q_UNUSED(width); Q_UNUSED(width);
@ -231,10 +271,12 @@ void gLineOverlaySummary::paint(gGraph & w,int left, int top, int width, int hei
float cnt = 0; float cnt = 0;
double sum = 0; double sum = 0;
bool isSpan = false; bool isSpan = false;
for (int i = 0; i < m_overlays.size(); i++) { for (int i = 0; i < m_overlays.size(); i++) {
cnt += m_overlays[i]->count(); cnt += m_overlays[i]->count();
sum += m_overlays[i]->sum(); sum += m_overlays[i]->sum();
if (m_overlays[i]->flagtype()==FT_Span) isSpan=true;
if (m_overlays[i]->flagtype() == FT_Span) { isSpan = true; }
} }
double val, first, last; double val, first, last;
@ -242,16 +284,22 @@ void gLineOverlaySummary::paint(gGraph & w,int left, int top, int width, int hei
// Calculate the session time. // Calculate the session time.
for (QList<Session *>::iterator s = m_day->begin(); s != m_day->end(); s++) { for (QList<Session *>::iterator s = m_day->begin(); s != m_day->end(); s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) { continue; }
first = (*s)->first(); first = (*s)->first();
last = (*s)->last(); last = (*s)->last();
if (last < w.min_x) continue;
if (first > w.max_x) continue;
if (first < w.min_x) if (last < w.min_x) { continue; }
if (first > w.max_x) { continue; }
if (first < w.min_x) {
first = w.min_x; first = w.min_x;
if (last > w.max_x) }
if (last > w.max_x) {
last = w.max_x; last = w.max_x;
}
time += last - first; time += last - first;
} }
@ -268,19 +316,27 @@ void gLineOverlaySummary::paint(gGraph & w,int left, int top, int width, int hei
//if (time<1) time=1; //if (time<1) time=1;
if (time>0) val=cnt/time; if (time > 0) { val = cnt / time; }
QString a=QObject::tr("Events")+"="+QString::number(cnt)+" "+QObject::tr("Duration")+" "+QString().sprintf("%02i:%02i:%02i",h,m,s)+", "+m_text+"="+QString::number(val,'f',2); QString a = QObject::tr("Events") + "=" + QString::number(cnt) + " " + QObject::tr("Duration") +
" " + QString().sprintf("%02i:%02i:%02i", h, m, s) + ", " + m_text + "=" + QString::number(val,
'f', 2);
if (isSpan) { if (isSpan) {
float sph; float sph;
if (!time) sph=0; else {
if (!time) { sph = 0; }
else {
sph = (100.0 / float(time)) * (sum / 3600.0); sph = (100.0 / float(time)) * (sum / 3600.0);
if (sph>100) sph=100;
if (sph > 100) { sph = 100; }
} }
a+=" "+QObject::tr("(\%%1 in events)").arg(sph,0,'f',2); // eg: %num of time in a span, like Periodic Breathing
a += " " + QObject::tr("(\%%1 in events)").arg(sph, 0, 'f',
2); // eg: %num of time in a span, like Periodic Breathing
} }
w.renderText(a, left + m_x, top + m_y); w.renderText(a, left + m_x, top + m_y);
} }

View File

@ -13,7 +13,8 @@
#include "gSegmentChart.h" #include "gSegmentChart.h"
gSegmentChart::gSegmentChart(GraphSegmentType type, QColor gradient_color, QColor outline_color) gSegmentChart::gSegmentChart(GraphSegmentType type, QColor gradient_color, QColor outline_color)
:Layer(NoChannel),m_graph_type(type),m_gradient_color(gradient_color),m_outline_color(outline_color) : Layer(NoChannel), m_graph_type(type), m_gradient_color(gradient_color),
m_outline_color(outline_color)
{ {
m_empty = true; m_empty = true;
addGLBuf(poly = new GLFloatBuffer(4000, GL_POLYGON)); addGLBuf(poly = new GLFloatBuffer(4000, GL_POLYGON));
@ -38,18 +39,23 @@ void gSegmentChart::SetDay(Day *d)
{ {
Layer::SetDay(d); Layer::SetDay(d);
m_total = 0; m_total = 0;
if (!m_day) return;
if (!m_day) { return; }
for (int c = 0; c < m_codes.size(); c++) { for (int c = 0; c < m_codes.size(); c++) {
m_values[c] = 0; m_values[c] = 0;
for (QList<Session *>::iterator s = m_day->begin(); s != m_day->end(); ++s) { for (QList<Session *>::iterator s = m_day->begin(); s != m_day->end(); ++s) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) { continue; }
int cnt = (*s)->count(m_codes[c]); int cnt = (*s)->count(m_codes[c]);
m_values[c] += cnt; m_values[c] += cnt;
m_total += cnt; m_total += cnt;
} }
} }
m_empty = true; m_empty = true;
for (int i = 0; i < m_codes.size(); i++) { for (int i = 0; i < m_codes.size(); i++) {
if (m_day->count(m_codes[i]) > 0) { if (m_day->count(m_codes[i]) > 0) {
m_empty = false; m_empty = false;
@ -65,8 +71,10 @@ bool gSegmentChart::isEmpty()
void gSegmentChart::paint(gGraph &w, int left, int top, int width, int height) void gSegmentChart::paint(gGraph &w, int left, int top, int width, int height)
{ {
if (!m_visible) return; if (!m_visible) { return; }
if (!m_day) return;
if (!m_day) { return; }
int start_px = left; int start_px = left;
int start_py = top; int start_py = top;
@ -88,6 +96,7 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height)
int xoffset = width / 2; int xoffset = width / 2;
int yoffset = height / 2; int yoffset = height / 2;
if (m_total == 0) { if (m_total == 0) {
QColor col = Qt::green; QColor col = Qt::green;
QString a = ":-)"; QString a = ":-)";
@ -106,10 +115,12 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height)
gVertexBuffer *quads = w.quads(); gVertexBuffer *quads = w.quads();
gVertexBuffer *lines2 = w.lines(); gVertexBuffer *lines2 = w.lines();
for (unsigned m = 0; m < size; m++) { for (unsigned m = 0; m < size; m++) {
data = m_values[m]; data = m_values[m];
if (data==0) continue; if (data == 0) { continue; }
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// Pie Chart // Pie Chart
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
@ -119,11 +130,13 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height)
// Draw Filling // Draw Filling
poly->add(start_px + xoffset, start_py + height - yoffset, m_gradient_color); poly->add(start_px + xoffset, start_py + height - yoffset, m_gradient_color);
for (q = sum; q < sum + j; q += step) { for (q = sum; q < sum + j; q += step) {
px = start_px + xoffset + sin(q * 2 * M_PI) * radius; px = start_px + xoffset + sin(q * 2 * M_PI) * radius;
py = start_py + height - (yoffset + cos(q * 2 * M_PI) * radius); py = start_py + height - (yoffset + cos(q * 2 * M_PI) * radius);
poly->add(px, py, col); poly->add(px, py, col);
} }
q = sum + j; q = sum + j;
px = start_px + xoffset + sin(q * 2 * M_PI) * radius; px = start_px + xoffset + sin(q * 2 * M_PI) * radius;
py = start_py + height - (yoffset + cos(q * 2 * M_PI) * radius); py = start_py + height - (yoffset + cos(q * 2 * M_PI) * radius);
@ -133,11 +146,13 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height)
// Draw the center point first // Draw the center point first
lines->add(start_px + xoffset, start_py + height - yoffset, m_outline_color); lines->add(start_px + xoffset, start_py + height - yoffset, m_outline_color);
} }
for (q = sum; q < sum + j; q += step) { for (q = sum; q < sum + j; q += step) {
px = start_px + xoffset + sin(q * 2 * M_PI) * radius; px = start_px + xoffset + sin(q * 2 * M_PI) * radius;
py = start_py + height - (yoffset + cos(q * 2 * M_PI) * radius); py = start_py + height - (yoffset + cos(q * 2 * M_PI) * radius);
lines->add(px, py, m_outline_color); lines->add(px, py, m_outline_color);
} }
double tpx = start_px + xoffset + sin((sum + (j / 2.0)) * 2 * M_PI) * (radius / 1.7); double tpx = start_px + xoffset + sin((sum + (j / 2.0)) * 2 * M_PI) * (radius / 1.7);
double tpy = start_py + height - (yoffset + cos((sum + (j / 2.0)) * 2 * M_PI) * (radius / 1.7)); double tpy = start_py + height - (yoffset + cos((sum + (j / 2.0)) * 2 * M_PI) * (radius / 1.7));
q = sum + j; q = sum + j;
@ -149,7 +164,8 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height)
QString a = m_names[m]; //QString::number(floor(100.0/m_total*data),'f',0)+"%"; QString a = m_names[m]; //QString::number(floor(100.0/m_total*data),'f',0)+"%";
int x, y; int x, y;
GetTextExtent(a, x, y); GetTextExtent(a, x, y);
w.renderText(a,tpx-(x/2.0),(tpy+y/2.0),0,Qt::black,defaultfont,false); // antialiasing looks like crap here.. w.renderText(a, tpx - (x / 2.0), (tpy + y / 2.0), 0, Qt::black, defaultfont,
false); // antialiasing looks like crap here..
} }
sum = q; sum = q;
@ -170,6 +186,7 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height)
if (!m_names[m].isEmpty()) { if (!m_names[m].isEmpty()) {
int px, py; int px, py;
GetTextExtent(m_names[m], px, py); GetTextExtent(m_names[m], px, py);
if (px + 5 < bw) { if (px + 5 < bw) {
w.renderText(m_names[m], (xp + bw / 2) - (px / 2), top + ((height / 2) - (py / 2)), 0, Qt::black); w.renderText(m_names[m], (xp + bw / 2) - (px / 2), top + ((height / 2) - (py / 2)), 0, Qt::black);
} }
@ -182,19 +199,22 @@ void gSegmentChart::paint(gGraph & w,int left, int top, int width, int height)
} else if (m_graph_type == GST_Line) { } else if (m_graph_type == GST_Line) {
QColor col = Qt::black; //m_colors[m % m_colors.size()]; QColor col = Qt::black; //m_colors[m % m_colors.size()];
float h = (top + height) - (float(data) * ymult); float h = (top + height) - (float(data) * ymult);
if (line_first) { if (line_first) {
line_first = false; line_first = false;
} else { } else {
lines->add(xp, line_last, xp + line_step, h, col); lines->add(xp, line_last, xp + line_step, h, col);
xp += line_step; xp += line_step;
} }
line_last = h; line_last = h;
} }
} }
} }
gTAPGraph::gTAPGraph(ChannelID code,GraphSegmentType gt, QColor gradient_color,QColor outline_color) gTAPGraph::gTAPGraph(ChannelID code, GraphSegmentType gt, QColor gradient_color,
QColor outline_color)
: gSegmentChart(gt, gradient_color, outline_color), m_code(code) : gSegmentChart(gt, gradient_color, outline_color), m_code(code)
{ {
m_colors.push_back(Qt::red); m_colors.push_back(Qt::red);
@ -207,7 +227,9 @@ void gTAPGraph::SetDay(Day *d)
{ {
Layer::SetDay(d); Layer::SetDay(d);
m_total = 0; m_total = 0;
if (!m_day) return;
if (!m_day) { return; }
QMap<EventStoreType, qint64> tap; QMap<EventStoreType, qint64> tap;
EventStoreType data = 0, lastval = 0; EventStoreType data = 0, lastval = 0;
@ -217,38 +239,47 @@ void gTAPGraph::SetDay(Day *d)
//bool changed; //bool changed;
EventDataType gain = 1, offset = 0; EventDataType gain = 1, offset = 0;
QHash<ChannelID, QVector<EventList *> >::iterator ei; QHash<ChannelID, QVector<EventList *> >::iterator ei;
for (QList<Session *>::iterator s=m_day->begin();s!=m_day->end();++s) {
if (!(*s)->enabled()) continue;
if ((ei=(*s)->eventlist.find(m_code))==(*s)->eventlist.end()) continue; for (QList<Session *>::iterator s = m_day->begin(); s != m_day->end(); ++s) {
if (!(*s)->enabled()) { continue; }
if ((ei = (*s)->eventlist.find(m_code)) == (*s)->eventlist.end()) { continue; }
for (int q = 0; q < ei.value().size(); q++) { for (int q = 0; q < ei.value().size(); q++) {
EventList &el = *(ei.value()[q]); EventList &el = *(ei.value()[q]);
lasttime = el.time(0); lasttime = el.time(0);
lastval = el.raw(0); lastval = el.raw(0);
if (rfirst) { if (rfirst) {
gain = el.gain(); gain = el.gain();
offset = el.offset(); offset = el.offset();
rfirst = false; rfirst = false;
} }
//first=true; //first=true;
//changed=false; //changed=false;
for (quint32 i = 1; i < el.count(); i++) { for (quint32 i = 1; i < el.count(); i++) {
data = el.raw(i); data = el.raw(i);
time = el.time(i); time = el.time(i);
if (lastval != data) { if (lastval != data) {
qint64 v = (time - lasttime); qint64 v = (time - lasttime);
if (tap.find(lastval) != tap.end()) { if (tap.find(lastval) != tap.end()) {
tap[lastval] += v; tap[lastval] += v;
} else { } else {
tap[lastval] = v; tap[lastval] = v;
} }
//changed=true; //changed=true;
lasttime = time; lasttime = time;
lastval = data; lastval = data;
} }
} }
if (time != lasttime) { if (time != lasttime) {
qint64 v = (time - lasttime); qint64 v = (time - lasttime);
if (tap.find(lastval) != tap.end()) { if (tap.find(lastval) != tap.end()) {
tap[data] += v; tap[data] += v;
} else { } else {
@ -257,6 +288,7 @@ void gTAPGraph::SetDay(Day *d)
} }
} }
} }
m_values.clear(); m_values.clear();
m_names.clear(); m_names.clear();
m_total = 0; m_total = 0;
@ -269,5 +301,6 @@ void gTAPGraph::SetDay(Day *d)
m_total += i.value() / 1000L; m_total += i.value() / 1000L;
m_names.push_back(QString::number(val, 'f', 2)); m_names.push_back(QString::number(val, 'f', 2));
} }
m_empty = m_values.size() == 0; m_empty = m_values.size() == 0;
} }

View File

@ -22,7 +22,8 @@ enum GraphSegmentType { GST_Pie, GST_CandleStick, GST_Line };
class gSegmentChart : public Layer class gSegmentChart : public Layer
{ {
public: public:
gSegmentChart(GraphSegmentType gt=GST_Pie, QColor gradient_color=Qt::white,QColor outline_color=Qt::black); gSegmentChart(GraphSegmentType gt = GST_Pie, QColor gradient_color = Qt::white,
QColor outline_color = Qt::black);
virtual ~gSegmentChart(); virtual ~gSegmentChart();
//! \brief The drawing code that fills the Vertex buffers //! \brief The drawing code that fills the Vertex buffers
@ -68,7 +69,8 @@ protected:
class gTAPGraph: public gSegmentChart class gTAPGraph: public gSegmentChart
{ {
public: public:
gTAPGraph(ChannelID code,GraphSegmentType gt=GST_CandleStick, QColor gradient_color=Qt::lightGray,QColor outline_color=Qt::black); gTAPGraph(ChannelID code, GraphSegmentType gt = GST_CandleStick,
QColor gradient_color = Qt::lightGray, QColor outline_color = Qt::black);
virtual ~gTAPGraph(); virtual ~gTAPGraph();
virtual void SetDay(Day *d); virtual void SetDay(Day *d);
protected: protected:

View File

@ -19,7 +19,8 @@ gStatsLine::gStatsLine(ChannelID code,QString label,QColor textcolor)
} }
void gStatsLine::paint(gGraph &w, int left, int top, int width, int height) void gStatsLine::paint(gGraph &w, int left, int top, int width, int height)
{ {
if (!m_visible) return; if (!m_visible) { return; }
//if (m_empty) return; //if (m_empty) return;
Q_UNUSED(height); Q_UNUSED(height);
@ -50,7 +51,9 @@ void gStatsLine::paint(gGraph & w, int left, int top, int width, int height)
void gStatsLine::SetDay(Day *d) void gStatsLine::SetDay(Day *d)
{ {
Layer::SetDay(d); Layer::SetDay(d);
if (!m_day) return;
if (!m_day) { return; }
m_min = d->Min(m_code); m_min = d->Min(m_code);
m_max = d->Max(m_code); m_max = d->Max(m_code);
m_avg = d->wavg(m_code); m_avg = d->wavg(m_code);

View File

@ -66,7 +66,9 @@ void SummaryChart::SetDay(Day * nullday)
int dn; int dn;
EventDataType tmp, tmp2, total; EventDataType tmp, tmp2, total;
ChannelID code; ChannelID code;
CPAPMode cpapmode=(CPAPMode)(int)PROFILE.calcSettingsMax(CPAP_Mode,MT_CPAP,PROFILE.FirstDay(MT_CPAP),PROFILE.LastDay(MT_CPAP)); CPAPMode cpapmode = (CPAPMode)(int)PROFILE.calcSettingsMax(CPAP_Mode, MT_CPAP,
PROFILE.FirstDay(MT_CPAP), PROFILE.LastDay(MT_CPAP));
if (m_label == STR_TR_Pressure) { if (m_label == STR_TR_Pressure) {
m_codes.clear(); m_codes.clear();
m_colors.clear(); m_colors.clear();
@ -76,9 +78,12 @@ void SummaryChart::SetDay(Day * nullday)
float perc = PROFILE.general->prefCalcPercentile() / 100.0; float perc = PROFILE.general->prefCalcPercentile() / 100.0;
int mididx = PROFILE.general->prefCalcMiddle(); int mididx = PROFILE.general->prefCalcMiddle();
SummaryType mid; SummaryType mid;
if (mididx==0) mid=ST_PERC;
if (mididx==1) mid=ST_WAVG; if (mididx == 0) { mid = ST_PERC; }
if (mididx==2) mid=ST_AVG;
if (mididx == 1) { mid = ST_WAVG; }
if (mididx == 2) { mid = ST_AVG; }
if (cpapmode >= MODE_ASV) { if (cpapmode >= MODE_ASV) {
addSlice(CPAP_EPAP, QColor("green"), ST_SETMIN); addSlice(CPAP_EPAP, QColor("green"), ST_SETMIN);
@ -105,6 +110,7 @@ void SummaryChart::SetDay(Day * nullday)
} }
m_goodcodes.resize(m_codes.size()); m_goodcodes.resize(m_codes.size());
for (int i = 0; i < m_codes.size(); i++) { for (int i = 0; i < m_codes.size(); i++) {
m_goodcodes[i] = false; m_goodcodes[i] = false;
} }
@ -112,30 +118,42 @@ void SummaryChart::SetDay(Day * nullday)
m_fday = 0; m_fday = 0;
qint64 tt, zt; qint64 tt, zt;
m_empty = true; m_empty = true;
if (m_graphtype == GT_SESSIONS) { if (m_graphtype == GT_SESSIONS) {
if (PROFILE.countDays(MT_CPAP,PROFILE.FirstDay(MT_CPAP), PROFILE.LastDay(MT_CPAP))==0) if (PROFILE.countDays(MT_CPAP, PROFILE.FirstDay(MT_CPAP), PROFILE.LastDay(MT_CPAP)) == 0) {
return; return;
} }
}
int suboffset; int suboffset;
SummaryType type; SummaryType type;
bool first = true; bool first = true;
for (QMap<QDate,QList<Day *> >::iterator d=PROFILE.daylist.begin();d!=PROFILE.daylist.end();d++) { for (QMap<QDate, QList<Day *> >::iterator d = PROFILE.daylist.begin(); d != PROFILE.daylist.end();
d++) {
tt = QDateTime(d.key(), QTime(0, 0, 0), Qt::UTC).toTime_t(); tt = QDateTime(d.key(), QTime(0, 0, 0), Qt::UTC).toTime_t();
dn = tt / 86400; dn = tt / 86400;
tt *= 1000L; tt *= 1000L;
if (!m_minx || tt<m_minx) m_minx=tt;
if (!m_maxx || tt>m_maxx) m_maxx=tt; if (!m_minx || tt < m_minx) { m_minx = tt; }
if (!m_maxx || tt > m_maxx) { m_maxx = tt; }
total = 0; total = 0;
bool fnd = false; bool fnd = false;
if (m_graphtype == GT_SESSIONS) { if (m_graphtype == GT_SESSIONS) {
for (int i=0;i<m_codes.size();i++) for (int i = 0; i < m_codes.size(); i++) {
m_goodcodes[i] = true; m_goodcodes[i] = true;
}
for (int i = 0; i < d.value().size(); i++) { // for each day for (int i = 0; i < d.value().size(); i++) { // for each day
day = d.value().at(i); day = d.value().at(i);
if (!day) continue;
if (day->machine_type()!=m_machinetype) continue; if (!day) { continue; }
if (day->machine_type() != m_machinetype) { continue; }
int ft = qint64(day->first()) / 1000L; int ft = qint64(day->first()) / 1000L;
ft += tz_offset; // convert to local time ft += tz_offset; // convert to local time
@ -144,7 +162,8 @@ void SummaryChart::SetDay(Day * nullday)
for (int s = 0; s < day->size(); s++) { for (int s = 0; s < day->size(); s++) {
Session *sess = (*day)[s]; Session *sess = (*day)[s];
if (!sess->enabled()) continue;
if (!sess->enabled()) { continue; }
tmp = sess->hours(); tmp = sess->hours();
m_values[dn][s] = tmp; m_values[dn][s] = tmp;
@ -161,12 +180,16 @@ void SummaryChart::SetDay(Day * nullday)
m_maxy = tmp2 + tmp; m_maxy = tmp2 + tmp;
first = false; first = false;
} else { } else {
if (tmp2 < m_miny) if (tmp2 < m_miny) {
m_miny = tmp2; m_miny = tmp2;
if (tmp2+tmp > m_maxy) }
if (tmp2 + tmp > m_maxy) {
m_maxy = tmp2 + tmp; m_maxy = tmp2 + tmp;
} }
} }
}
if (total > 0) { if (total > 0) {
m_days[dn] = day; m_days[dn] = day;
m_hours[dn] = total; m_hours[dn] = total;
@ -179,10 +202,12 @@ void SummaryChart::SetDay(Day * nullday)
suboffset = 0; suboffset = 0;
type = m_type[j]; type = m_type[j];
EventDataType typeval = m_typeval[j]; EventDataType typeval = m_typeval[j];
for (int i = 0; i < d.value().size(); i++) { // for each machine object for this day for (int i = 0; i < d.value().size(); i++) { // for each machine object for this day
day = d.value()[i]; day = d.value()[i];
CPAPMode mode = (CPAPMode)(int)day->settings_max(CPAP_Mode); CPAPMode mode = (CPAPMode)(int)day->settings_max(CPAP_Mode);
if (day->machine_type()!=m_machinetype) continue;
if (day->machine_type() != m_machinetype) { continue; }
bool hascode = //day->channelHasData(code) || bool hascode = //day->channelHasData(code) ||
type == ST_HOURS || type == ST_HOURS ||
@ -193,6 +218,7 @@ void SummaryChart::SetDay(Day * nullday)
if (code == CPAP_Pressure) { if (code == CPAP_Pressure) {
if ((cpapmode > MODE_CPAP) && (mode == MODE_CPAP)) { if ((cpapmode > MODE_CPAP) && (mode == MODE_CPAP)) {
hascode = false; hascode = false;
if ((type == ST_WAVG) || (type == ST_AVG) || ((type == ST_PERC) && (typeval == 0.5))) { if ((type == ST_WAVG) || (type == ST_AVG) || ((type == ST_PERC) && (typeval == 0.5))) {
type = ST_SETWAVG; type = ST_SETWAVG;
hascode = true; hascode = true;
@ -207,63 +233,129 @@ void SummaryChart::SetDay(Day * nullday)
//} //}
if (hascode) { if (hascode) {
m_days[dn] = day; m_days[dn] = day;
switch (type) { switch (type) {
case ST_AVG: tmp=day->avg(code); break; case ST_AVG:
case ST_SUM: tmp=day->sum(code); break; tmp = day->avg(code);
case ST_WAVG: tmp=day->wavg(code); break; break;
case ST_90P: tmp=day->p90(code); break;
case ST_PERC: tmp=day->percentile(code,typeval); break; case ST_SUM:
case ST_MIN: tmp=day->Min(code); break; tmp = day->sum(code);
case ST_MAX: tmp=day->Max(code); break; break;
case ST_CNT: tmp=day->count(code); break;
case ST_CPH: tmp=day->cph(code); break; case ST_WAVG:
case ST_SPH: tmp=day->sph(code); break; tmp = day->wavg(code);
case ST_HOURS: tmp=day->hours(); break; break;
case ST_SESSIONS: tmp=day->size(); break;
case ST_SETMIN: tmp=day->settings_min(code); break; case ST_90P:
case ST_SETMAX: tmp=day->settings_max(code); break; tmp = day->p90(code);
case ST_SETAVG: tmp=day->settings_avg(code); break; break;
case ST_SETWAVG: tmp=day->settings_wavg(code); break;
case ST_SETSUM: tmp=day->settings_sum(code); break; case ST_PERC:
tmp = day->percentile(code, typeval);
break;
case ST_MIN:
tmp = day->Min(code);
break;
case ST_MAX:
tmp = day->Max(code);
break;
case ST_CNT:
tmp = day->count(code);
break;
case ST_CPH:
tmp = day->cph(code);
break;
case ST_SPH:
tmp = day->sph(code);
break;
case ST_HOURS:
tmp = day->hours();
break;
case ST_SESSIONS:
tmp = day->size();
break;
case ST_SETMIN:
tmp = day->settings_min(code);
break;
case ST_SETMAX:
tmp = day->settings_max(code);
break;
case ST_SETAVG:
tmp = day->settings_avg(code);
break;
case ST_SETWAVG:
tmp = day->settings_wavg(code);
break;
case ST_SETSUM:
tmp = day->settings_sum(code);
break;
default: default:
tmp = 0; tmp = 0;
break; break;
} }
if (suboffset > 0) { if (suboffset > 0) {
tmp -= suboffset; tmp -= suboffset;
if (tmp<0) tmp=0;
if (tmp < 0) { tmp = 0; }
} }
total += tmp; total += tmp;
m_values[dn][j + 1] = tmp; m_values[dn][j + 1] = tmp;
if (tmp<m_miny) m_miny=tmp;
if (tmp>m_maxy) m_maxy=tmp; if (tmp < m_miny) { m_miny = tmp; }
if (tmp > m_maxy) { m_maxy = tmp; }
m_goodcodes[j] = true; m_goodcodes[j] = true;
fnd = true; fnd = true;
break; break;
} }
} }
} }
if (fnd) { if (fnd) {
if (!m_fday) m_fday=dn; if (!m_fday) { m_fday = dn; }
m_values[dn][0] = total; m_values[dn][0] = total;
m_hours[dn] = day->hours(); m_hours[dn] = day->hours();
if (m_graphtype == GT_BAR) { if (m_graphtype == GT_BAR) {
if (total<m_miny) m_miny=total; if (total < m_miny) { m_miny = total; }
if (total>m_maxy) m_maxy=total;
if (total > m_maxy) { m_maxy = total; }
} }
} }
} }
} }
m_empty = true; m_empty = true;
for (int i = 0; i < m_goodcodes.size(); i++) { for (int i = 0; i < m_goodcodes.size(); i++) {
if (m_goodcodes[i]) { if (m_goodcodes[i]) {
m_empty = false; m_empty = false;
break; break;
} }
} }
if (m_graphtype == GT_BAR) { if (m_graphtype == GT_BAR) {
m_miny = 0; m_miny = 0;
} }
// m_minx=qint64(QDateTime(PROFILE.FirstDay(),QTime(0,0,0),Qt::UTC).toTime_t())*1000L; // m_minx=qint64(QDateTime(PROFILE.FirstDay(),QTime(0,0,0),Qt::UTC).toTime_t())*1000L;
m_maxx = qint64(QDateTime(PROFILE.LastDay(), QTime(23, 59, 0), Qt::UTC).toTime_t()) * 1000L; m_maxx = qint64(QDateTime(PROFILE.LastDay(), QTime(23, 59, 0), Qt::UTC).toTime_t()) * 1000L;
m_physmaxy = m_maxy; m_physmaxy = m_maxy;
@ -278,17 +370,21 @@ QColor brighten(QColor color)
cg = color.green(); cg = color.green();
cb = color.blue(); cb = color.blue();
if (cr<64) cr=64; if (cr < 64) { cr = 64; }
if (cg<64) cg=64;
if (cb<64) cb=64; if (cg < 64) { cg = 64; }
if (cb < 64) { cb = 64; }
cr *= 2; cr *= 2;
cg *= 2; cg *= 2;
cb *= 2; cb *= 2;
if (cr>255) cr=255; if (cr > 255) { cr = 255; }
if (cg>255) cg=255;
if (cb>255) cb=255; if (cg > 255) { cg = 255; }
if (cb > 255) { cb = 255; }
return QColor(cr, cg, cb, 255); return QColor(cr, cg, cb, 255);
@ -296,7 +392,7 @@ QColor brighten(QColor color)
void SummaryChart::paint(gGraph &w, int left, int top, int width, int height) void SummaryChart::paint(gGraph &w, int left, int top, int width, int height)
{ {
if (!m_visible) return; if (!m_visible) { return; }
points->setSize(10); points->setSize(10);
@ -310,15 +406,18 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
if (graphtype == GT_POINTS) { if (graphtype == GT_POINTS) {
lines->setSize(4); lines->setSize(4);
} else } else {
lines->setSize(1.5); lines->setSize(1.5);
}
rtop = top; rtop = top;
gVertexBuffer *outlines2 = w.lines(); gVertexBuffer *outlines2 = w.lines();
// outlines2->setColor(Qt::black); // outlines2->setColor(Qt::black);
outlines2->add(left, top, left, top+height, left, top+height, left+width,top+height,QColor("black").rgba()); outlines2->add(left, top, left, top + height, left, top + height, left + width, top + height,
outlines2->add(left+width,top+height, left+width, top, left+width, top, left, top,QColor("black").rgba()); QColor("black").rgba());
outlines2->add(left + width, top + height, left + width, top, left + width, top, left, top,
QColor("black").rgba());
//if (outlines->full()) qDebug() << "WTF??? Outlines full in SummaryChart::paint()"; //if (outlines->full()) qDebug() << "WTF??? Outlines full in SummaryChart::paint()";
qint64 minx = w.min_x, maxx = w.max_x; qint64 minx = w.min_x, maxx = w.max_x;
@ -389,6 +488,7 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
points->setSize(5.0 * dpr); points->setSize(5.0 * dpr);
lastdaygood = true; lastdaygood = true;
for (int i = 0; i < numcodes; i++) { for (int i = 0; i < numcodes; i++) {
totalcounts[i] = 0; totalcounts[i] = 0;
@ -400,12 +500,14 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
} else { } else {
totalvalues[i] = 0; totalvalues[i] = 0;
} }
// Turn off legend display.. It will only display if it's turned back on during draw. // Turn off legend display.. It will only display if it's turned back on during draw.
goodcodes[i] = false; goodcodes[i] = false;
if (!m_goodcodes[i]) continue; if (!m_goodcodes[i]) { continue; }
lastX[i] = px; lastX[i] = px;
if (d != m_values.end() && d.value().contains(i + 1)) { if (d != m_values.end() && d.value().contains(i + 1)) {
tmp = d.value()[i + 1]; tmp = d.value()[i + 1];
@ -414,9 +516,12 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
lastdaygood = false; lastdaygood = false;
h = 0; h = 0;
} }
lastY[i] = top + height - 1 - h; lastY[i] = top + height - 1 - h;
} }
float compliance_hours = 0; float compliance_hours = 0;
if (PROFILE.cpap->showComplianceInfo()) { if (PROFILE.cpap->showComplianceInfo()) {
compliance_hours = PROFILE.cpap->complianceHours(); compliance_hours = PROFILE.cpap->complianceHours();
} }
@ -430,17 +535,21 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
short px2, py2; short px2, py2;
const qint64 ms_per_day = 86400000L; const qint64 ms_per_day = 86400000L;
for (qint64 Q = minx; Q <= maxx + ms_per_day; Q += ms_per_day) { for (qint64 Q = minx; Q <= maxx + ms_per_day; Q += ms_per_day) {
zd = Q / ms_per_day; zd = Q / ms_per_day;
d = m_values.find(zd); d = m_values.find(zd);
if (Q<minx) if (Q < minx) {
goto jumpnext; goto jumpnext;
}
if (d != m_values.end()) { if (d != m_values.end()) {
day = m_days[zd]; day = m_days[zd];
if (!m_hours.contains(zd))
if (!m_hours.contains(zd)) {
goto jumpnext; goto jumpnext;
}
hours = m_hours[zd]; hours = m_hours[zd];
@ -448,8 +557,10 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
//x1-=(barw/2.0); //x1-=(barw/2.0);
int x2 = px + barw; int x2 = px + barw;
if (x1<left) x1=left; if (x1 < left) { x1 = left; }
if (x2>left+width) x2=left+width;
if (x2 > left + width) { x2 = left + width; }
// if (x2<x1) // if (x2<x1)
// goto jumpnext; // goto jumpnext;
@ -457,10 +568,12 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
if (zd == hl_day) { if (zd == hl_day) {
QColor col = QColor("red"); QColor col = QColor("red");
col.setAlpha(64); col.setAlpha(64);
if (graphtype != GT_POINTS) { if (graphtype != GT_POINTS) {
quads->add(x1 - 1, top, x1 - 1, top + height, x2, top + height, x2, top, col.rgba()); quads->add(x1 - 1, top, x1 - 1, top + height, x2, top + height, x2, top, col.rgba());
} else { } else {
quads->add((x1+barw/2)-5,top,(x1+barw/2)-5,top+height,(x2-barw/2)+5,top+height,(x2-barw/2)+5,top,col.rgba()); quads->add((x1 + barw / 2) - 5, top, (x1 + barw / 2) - 5, top + height, (x2 - barw / 2) + 5,
top + height, (x2 - barw / 2) + 5, top, col.rgba());
} }
} }
@ -473,16 +586,19 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
if (zd == hl_day) { if (zd == hl_day) {
col = QColor("gold"); col = QColor("gold");
} }
GLuint col1 = col.rgba(); GLuint col1 = col.rgba();
GLuint col2 = brighten(col).rgba(); GLuint col2 = brighten(col).rgba();
//outlines->setColor(Qt::black); //outlines->setColor(Qt::black);
int np = d.value().size(); int np = d.value().size();
if (np > 0) { if (np > 0) {
for (int i = 0; i < goodcodes.size(); i++) { for (int i = 0; i < goodcodes.size(); i++) {
goodcodes[i] = true; goodcodes[i] = true;
} }
} }
for (j = 0; j < np; j++) { for (j = 0; j < np; j++) {
tmp2 = times.value()[j] - miny; tmp2 = times.value()[j] - miny;
py = top + height - (tmp2 * ymult); py = top + height - (tmp2 * ymult);
@ -493,12 +609,15 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
h = tmp * ymult; h = tmp * ymult;
quads->add(x1, py, x1, py - h, x2, py - h, x2, py, col1, col2); quads->add(x1, py, x1, py - h, x2, py - h, x2, py, col1, col2);
if (h > 0 && barw > 2) { if (h > 0 && barw > 2) {
outlines->add(x1, py, x1, py - h, x1, py - h, x2, py - h, QColor("black").rgba()); outlines->add(x1, py, x1, py - h, x1, py - h, x2, py - h, QColor("black").rgba());
outlines->add(x1, py, x2, py, x2, py, x2, py - h, QColor("black").rgba()); outlines->add(x1, py, x2, py, x2, py, x2, py - h, QColor("black").rgba());
} }
totalvalues[0] += hours * tmp; totalvalues[0] += hours * tmp;
} }
totalcounts[0] += hours; totalcounts[0] += hours;
totalvalues[1] += j; totalvalues[1] += j;
totalcounts[1]++; totalcounts[1]++;
@ -506,9 +625,12 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
total_hours += hours; total_hours += hours;
total_days++; total_days++;
} else { } else {
if (!d.value().contains(0)) if (!d.value().contains(0)) {
goto jumpnext; goto jumpnext;
}
total = d.value()[0]; total = d.value()[0];
//if (total>0) { //if (total>0) {
if (day) { if (day) {
EventDataType hours = m_hours[zd]; EventDataType hours = m_hours[zd];
@ -516,18 +638,24 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
total_hours += hours; total_hours += hours;
total_days++; total_days++;
} }
py = top + height; py = top + height;
//} //}
bool good; bool good;
SummaryType type; SummaryType type;
for (QHash<short, EventDataType>::iterator g = d.value().begin(); g != d.value().end(); g++) { for (QHash<short, EventDataType>::iterator g = d.value().begin(); g != d.value().end(); g++) {
short j = g.key(); short j = g.key();
if (!j) continue;
if (!j) { continue; }
j--; j--;
good = m_goodcodes[j]; good = m_goodcodes[j];
if (!good)
if (!good) {
continue; continue;
}
type = m_type[j]; type = m_type[j];
// code was actually used (to signal the display of the legend summary) // code was actually used (to signal the display of the legend summary)
@ -536,6 +664,7 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
tmp = g.value(); tmp = g.value();
QColor col = m_colors[j]; QColor col = m_colors[j];
if (type == ST_HOURS) { if (type == ST_HOURS) {
if (tmp < compliance_hours) { if (tmp < compliance_hours) {
col = QColor("#f04040"); col = QColor("#f04040");
@ -549,14 +678,17 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
//if (!tmp) continue; //if (!tmp) continue;
if ((type == ST_MAX) || (type == ST_SETMAX)) { if ((type == ST_MAX) || (type == ST_SETMAX)) {
if (totalvalues[j]<tmp) if (totalvalues[j] < tmp) {
totalvalues[j] = tmp; totalvalues[j] = tmp;
}
} else if ((type == ST_MIN) || (type == ST_SETMIN)) { } else if ((type == ST_MIN) || (type == ST_SETMIN)) {
if (totalvalues[j]>tmp) if (totalvalues[j] > tmp) {
totalvalues[j] = tmp; totalvalues[j] = tmp;
}
} else { } else {
totalvalues[j] += tmp * hours; totalvalues[j] += tmp * hours;
} }
//if (tmp) { //if (tmp) {
totalcounts[j] += hours; totalcounts[j] += hours;
//} //}
@ -569,11 +701,14 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
quads->add(x1, py, x1, py - h, col1); quads->add(x1, py, x1, py - h, col1);
quads->add(x2, py - h, x2, py, col2); quads->add(x2, py - h, x2, py, col2);
if (h > 0 && barw > 2) { if (h > 0 && barw > 2) {
outlines->add(x1, py, x1, py - h, x1, py - h, x2, py - h, QColor("black").rgba()); outlines->add(x1, py, x1, py - h, x1, py - h, x2, py - h, QColor("black").rgba());
outlines->add(x1, py, x2, py, x2, py, x2, py - h, QColor("black").rgba()); outlines->add(x1, py, x2, py, x2, py, x2, py - h, QColor("black").rgba());
if (outlines->full()) qDebug() << "WTF??? Outlines full in SummaryChart::paint()";
if (outlines->full()) { qDebug() << "WTF??? Outlines full in SummaryChart::paint()"; }
} // if (bar } // if (bar
py -= h; py -= h;
} else if (graphtype == GT_LINE) { // if (m_graphtype==GT_BAR } else if (graphtype == GT_LINE) { // if (m_graphtype==GT_BAR
GLuint col1 = col.rgba(); GLuint col1 = col.rgba();
@ -585,14 +720,17 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
if ((px2 - lastX[j]) > barw + 1) { if ((px2 - lastX[j]) > barw + 1) {
lastdaygood = false; lastdaygood = false;
} }
if (lastdaygood) { if (lastdaygood) {
if (lastY[j] != py2) { // vertical line if (lastY[j] != py2) { // vertical line
lines->add(lastX[j], lastY[j], px, py2, col2); lines->add(lastX[j], lastY[j], px, py2, col2);
} }
lines->add(px - 1, py2, px2 + 1, py2, col1); lines->add(px - 1, py2, px2 + 1, py2, col1);
} else { } else {
lines->add(x1 - 1, py2, x2 + 1, py2, col1); lines->add(x1 - 1, py2, x2 + 1, py2, col1);
} }
lastX[j] = px2; lastX[j] = px2;
lastY[j] = py2; lastY[j] = py2;
} else if (graphtype == GT_POINTS) { } else if (graphtype == GT_POINTS) {
@ -615,26 +753,35 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
} else { } else {
lines->add(px + barw / 2 - 1, py2, px + barw / 2 + 1, py2, col1); lines->add(px + barw / 2 - 1, py2, px + barw / 2 + 1, py2, col1);
} }
lastX[j] = px2; lastX[j] = px2;
lastY[j] = py2; lastY[j] = py2;
} }
} // for(QHash<short } // for(QHash<short
} }
lastdaygood = true; lastdaygood = true;
// if (Q>maxx+extra) break; // if (Q>maxx+extra) break;
} else { } else {
if (Q<maxx) if (Q < maxx) {
incompliant++; incompliant++;
}
lastdaygood = false; lastdaygood = false;
} }
jumpnext: jumpnext:
if (px>=left+width+barw)
if (px >= left + width + barw) {
break; break;
}
px += barw; px += barw;
daynum++; daynum++;
//lastQ=Q; //lastQ=Q;
} }
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
quads->scissor(left * dpr, w.flipY(top + height + 2)*dpr, (width)*dpr, (height + 1)*dpr); quads->scissor(left * dpr, w.flipY(top + height + 2)*dpr, (width)*dpr, (height + 1)*dpr);
lines->scissor(left * dpr, w.flipY(top + height + 2)*dpr, (width + 1)*dpr, (height + 1)*dpr); lines->scissor(left * dpr, w.flipY(top + height + 2)*dpr, (width + 1)*dpr, (height + 1)*dpr);
@ -657,40 +804,81 @@ jumpnext:
bool ishours = false; bool ishours = false;
int good = 0; int good = 0;
for (int j = 0; j < m_codes.size(); j++) { for (int j = 0; j < m_codes.size(); j++) {
if (!goodcodes[j]) continue; if (!goodcodes[j]) { continue; }
good++; good++;
SummaryType type = m_type[j]; SummaryType type = m_type[j];
ChannelID code = m_codes[j]; ChannelID code = m_codes[j];
EventDataType tval = m_typeval[j]; EventDataType tval = m_typeval[j];
switch (type) { switch (type) {
case ST_WAVG: b="Avg"; break; case ST_WAVG:
case ST_AVG: b="Avg"; break; b = "Avg";
case ST_90P: b="90%"; break;
case ST_PERC:
if (tval>=0.99) b="Max";
else if (tval==0.5) b="Med";
else b=QString("%1%").arg(tval*100.0,0,'f',0);
break; break;
case ST_AVG:
b = "Avg";
break;
case ST_90P:
b = "90%";
break;
case ST_PERC:
if (tval >= 0.99) { b = "Max"; }
else if (tval == 0.5) { b = "Med"; }
else { b = QString("%1%").arg(tval * 100.0, 0, 'f', 0); }
break;
//b=QString("%1%").arg(tval*100.0,0,'f',0); break; //b=QString("%1%").arg(tval*100.0,0,'f',0); break;
case ST_MIN: b="Min"; break; case ST_MIN:
case ST_MAX: b="Max"; break; b = "Min";
case ST_SETMIN: b="Min"; break; break;
case ST_SETMAX: b="Max"; break;
case ST_CPH: b=""; break; case ST_MAX:
case ST_SPH: b="%"; break; b = "Max";
case ST_HOURS: b=STR_UNIT_Hours; break; break;
case ST_SESSIONS: b="Sessions"; break;
case ST_SETMIN:
b = "Min";
break;
case ST_SETMAX:
b = "Max";
break;
case ST_CPH:
b = "";
break;
case ST_SPH:
b = "%";
break;
case ST_HOURS:
b = STR_UNIT_Hours;
break;
case ST_SESSIONS:
b = "Sessions";
break;
default: default:
b = ""; b = "";
break; break;
} }
a = schema::channel[code].label(); a = schema::channel[code].label();
if (a==w.title() && !b.isEmpty()) a=b; else a+=" "+b;
if (a == w.title() && !b.isEmpty()) { a = b; }
else { a += " " + b; }
QString val; QString val;
float f = 0; float f = 0;
if (totalcounts[j] > 0) { if (totalcounts[j] > 0) {
if ((type == ST_MIN) || (type == ST_MAX) || (type == ST_SETMIN) || (type == ST_SETMAX)) { if ((type == ST_MIN) || (type == ST_MAX) || (type == ST_SETMIN) || (type == ST_SETMAX)) {
f = totalvalues[j]; f = totalvalues[j];
@ -698,6 +886,7 @@ jumpnext:
f = totalvalues[j] / totalcounts[j]; f = totalvalues[j] / totalcounts[j];
} }
} }
if (type == ST_HOURS) { if (type == ST_HOURS) {
int h = f; int h = f;
int m = int(f * 60) % 60; int m = int(f * 60) % 60;
@ -706,6 +895,7 @@ jumpnext:
} else { } else {
val = QString::number(f, 'f', 2); val = QString::number(f, 'f', 2);
} }
a += "=" + val; a += "=" + val;
//GetTextExtent(a,x,y); //GetTextExtent(a,x,y);
//float wt=20*w.printScaleX(); //float wt=20*w.printScaleX();
@ -723,13 +913,15 @@ jumpnext:
// legendx-=bw/2; // legendx-=bw/2;
int tp = top - 5 - bh / 2; int tp = top - 5 - bh / 2;
w.quads()->add(legendx-bw,tp+bh/2,legendx,tp+bh/2,legendx,tp-bh/2,legendx-bw,tp-bh/2,m_colors[j].rgba()); w.quads()->add(legendx - bw, tp + bh / 2, legendx, tp + bh / 2, legendx, tp - bh / 2, legendx - bw,
tp - bh / 2, m_colors[j].rgba());
legendx -= bw * 2; legendx -= bw * 2;
//lines->add(px,py,px+20,py,m_colors[j]); //lines->add(px,py,px+20,py,m_colors[j]);
//lines->add(px,py+1,px+20,py+1,m_colors[j]); //lines->add(px,py+1,px+20,py+1,m_colors[j]);
} }
if ((m_graphtype == GT_BAR) && (good > 0)) { if ((m_graphtype == GT_BAR) && (good > 0)) {
if (m_type.size() > 1) { if (m_type.size() > 1) {
@ -750,9 +942,12 @@ jumpnext:
} }
}*/ }*/
a += "Days=" + QString::number(total_days, 'f', 0); a += "Days=" + QString::number(total_days, 'f', 0);
if (PROFILE.cpap->showComplianceInfo()) { if (PROFILE.cpap->showComplianceInfo()) {
if (ishours && incompliant > 0) { if (ishours && incompliant > 0) {
a+=" Low Usage Days="+QString::number(incompliant,'f',0)+" (%"+QString::number((1.0/daynum)*(total_days-incompliant)*100.0,'f',2)+" compliant, defined as >"+QString::number(compliance_hours,'f',1)+" hours)"; a += " Low Usage Days=" + QString::number(incompliant, 'f',
0) + " (%" + QString::number((1.0 / daynum) * (total_days - incompliant) * 100.0, 'f',
2) + " compliant, defined as >" + QString::number(compliance_hours, 'f', 1) + " hours)";
} }
} }
@ -763,13 +958,14 @@ jumpnext:
w.renderText(a, left, py + 1); w.renderText(a, left, py + 1);
} }
QString formatTime(EventDataType v, bool show_seconds=false, bool duration=false,bool show_12hr=false) QString formatTime(EventDataType v, bool show_seconds = false, bool duration = false,
bool show_12hr = false)
{ {
int h = int(v); int h = int(v);
if (!duration) { if (!duration) {
h %= 24; h %= 24;
} else show_12hr=false; } else { show_12hr = false; }
int m = int(v * 60) % 60; int m = int(v * 60) % 60;
int s = int(v * 3600) % 60; int s = int(v * 3600) % 60;
@ -779,16 +975,19 @@ QString formatTime(EventDataType v, bool show_seconds=false, bool duration=false
if (show_12hr) { if (show_12hr) {
h >= 12 ? pm[0] = 'p' : pm[0] = 'a'; h >= 12 ? pm[0] = 'p' : pm[0] = 'a';
h %= 12; h %= 12;
if (h==0) h=12;
if (h == 0) { h = 12; }
} else { } else {
pm[0] = 0; pm[0] = 0;
} }
if (show_seconds)
if (show_seconds) {
return QString().sprintf("%i:%02i:%02i%s", h, m, s, pm); return QString().sprintf("%i:%02i:%02i%s", h, m, s, pm);
else } else {
return QString().sprintf("%i:%02i%s", h, m, pm); return QString().sprintf("%i:%02i%s", h, m, pm);
} }
}
bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph) bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
{ {
@ -834,6 +1033,7 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event,gGraph * graph)
//QTime t2=dt2.time(); //QTime t2=dt2.time();
QDate dt = dt2.date(); QDate dt = dt2.date();
if (d != m_values.end()) { if (d != m_values.end()) {
day = m_days[zd]; day = m_days[zd];
@ -843,6 +1043,7 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event,gGraph * graph)
// Day * day=m_days[hl_day]; // Day * day=m_days[hl_day];
//EventDataType val; //EventDataType val;
QString val; QString val;
if (m_graphtype == GT_SESSIONS) { if (m_graphtype == GT_SESSIONS) {
if (m_type[0] == ST_HOURS) { if (m_type[0] == ST_HOURS) {
@ -851,8 +1052,10 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event,gGraph * graph)
int m = (t / 60) % 60; int m = (t / 60) % 60;
//int s=t % 60; //int s=t % 60;
val.sprintf("%02i:%02i", h, m); val.sprintf("%02i:%02i", h, m);
} else } else {
val = QString::number(d.value()[0], 'f', 2); val = QString::number(d.value()[0], 'f', 2);
}
z += "\r\n" + m_label + "=" + val; z += "\r\n" + m_label + "=" + val;
if (m_type[1] == ST_SESSIONS) { if (m_type[1] == ST_SESSIONS) {
@ -861,53 +1064,98 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event,gGraph * graph)
EventDataType v = m_times[zd][0]; EventDataType v = m_times[zd][0];
int lastt = m_times[zd].size() - 1; int lastt = m_times[zd].size() - 1;
if (lastt<0) lastt=0;
if (lastt < 0) { lastt = 0; }
z += "\r\nBedtime=" + formatTime(v, false, false, true); z += "\r\nBedtime=" + formatTime(v, false, false, true);
v = m_times[zd][lastt] + m_values[zd][lastt]; v = m_times[zd][lastt] + m_values[zd][lastt];
z += "\r\nWaketime=" + formatTime(v, false, false, true); z += "\r\nWaketime=" + formatTime(v, false, false, true);
} else } else if (m_graphtype == GT_BAR) {
if (m_graphtype==GT_BAR){
if (m_type[0] == ST_HOURS) { if (m_type[0] == ST_HOURS) {
int t = d.value()[0] * 3600.0; int t = d.value()[0] * 3600.0;
int h = t / 3600; int h = t / 3600;
int m = (t / 60) % 60; int m = (t / 60) % 60;
//int s=t % 60; //int s=t % 60;
val.sprintf("%02i:%02i", h, m); val.sprintf("%02i:%02i", h, m);
} else } else {
val = QString::number(d.value()[0], 'f', 2); val = QString::number(d.value()[0], 'f', 2);
}
z += "\r\n" + m_label + "=" + val; z += "\r\n" + m_label + "=" + val;
//z+="\r\nMode="+QString::number(day->settings_min("FlexSet"),'f',0); //z+="\r\nMode="+QString::number(day->settings_min("FlexSet"),'f',0);
} else { } else {
QString a; QString a;
for (int i = 0; i < m_type.size(); i++) { for (int i = 0; i < m_type.size(); i++) {
if (!m_goodcodes[i]) if (!m_goodcodes[i]) {
continue; continue;
if (!valhash.contains(i+1)) }
if (!valhash.contains(i + 1)) {
continue; continue;
}
EventDataType tval = m_typeval[i]; EventDataType tval = m_typeval[i];
switch (m_type[i]) { switch (m_type[i]) {
case ST_WAVG: a="W-avg"; break; case ST_WAVG:
case ST_AVG: a="Avg"; break; a = "W-avg";
case ST_90P: a="90%"; break;
case ST_PERC:
if (tval>=0.99) a="Max";
else if (tval==0.5) a="Med";
else a=QString("%1%").arg(tval*100.0,0,'f',0);
break; break;
case ST_MIN: a="Min"; break;
case ST_MAX: a="Max"; break; case ST_AVG:
case ST_CPH: a=""; break; a = "Avg";
case ST_SPH: a="%"; break; break;
case ST_HOURS: a=STR_UNIT_Hours; break;
case ST_SESSIONS: a="Sessions"; break; case ST_90P:
case ST_SETMIN: a="Min"; break; a = "90%";
case ST_SETMAX: a="Max"; break; break;
case ST_PERC:
if (tval >= 0.99) { a = "Max"; }
else if (tval == 0.5) { a = "Med"; }
else { a = QString("%1%").arg(tval * 100.0, 0, 'f', 0); }
break;
case ST_MIN:
a = "Min";
break;
case ST_MAX:
a = "Max";
break;
case ST_CPH:
a = "";
break;
case ST_SPH:
a = "%";
break;
case ST_HOURS:
a = STR_UNIT_Hours;
break;
case ST_SESSIONS:
a = "Sessions";
break;
case ST_SETMIN:
a = "Min";
break;
case ST_SETMAX:
a = "Max";
break;
default: default:
a = ""; a = "";
break; break;
} }
if (m_type[i] == ST_SESSIONS) { if (m_type[i] == ST_SESSIONS) {
val = QString::number(d.value()[i + 1], 'f', 0); val = QString::number(d.value()[i + 1], 'f', 0);
z += "\r\n" + a + "=" + val; z += "\r\n" + a + "=" + val;
@ -915,15 +1163,17 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event,gGraph * graph)
//if (day && (day->channelExists(m_codes[i]) || day->settingExists(m_codes[i]))) { //if (day && (day->channelExists(m_codes[i]) || day->settingExists(m_codes[i]))) {
schema::Channel &chan = schema::channel[m_codes[i]]; schema::Channel &chan = schema::channel[m_codes[i]];
EventDataType v; EventDataType v;
if (valhash.contains(i+1))
if (valhash.contains(i + 1)) {
v = valhash[i + 1]; v = valhash[i + 1];
else v=0; } else { v = 0; }
if (m_codes[i] == Journal_Weight) { if (m_codes[i] == Journal_Weight) {
val = weightString(v, PROFILE.general->unitSystem()); val = weightString(v, PROFILE.general->unitSystem());
} else { } else {
val = QString::number(v, 'f', 2); val = QString::number(v, 'f', 2);
} }
z += "\r\n" + chan.label() + " " + a + "=" + val; z += "\r\n" + chan.label() + " " + a + "=" + val;
//} //}
} }
@ -950,6 +1200,7 @@ bool SummaryChart::mousePressEvent(QMouseEvent * event,gGraph * graph)
//qDebug() << "Jump to daily view?"; //qDebug() << "Jump to daily view?";
return true; return true;
} }
Q_UNUSED(graph) Q_UNUSED(graph)
return false; return false;
} }
@ -970,6 +1221,7 @@ bool SummaryChart::mouseReleaseEvent(QMouseEvent * event,gGraph * graph)
if (hl_day < 0) { if (hl_day < 0) {
mouseMoveEvent(event, graph); mouseMoveEvent(event, graph);
} }
if (hl_day > 0) { if (hl_day > 0) {
QDateTime d = QDateTime::fromTime_t(hl_day * 86400).toUTC(); QDateTime d = QDateTime::fromTime_t(hl_day * 86400).toUTC();
mainwin->getDaily()->LoadDate(d.date()); mainwin->getDaily()->LoadDate(d.date());
@ -978,6 +1230,7 @@ bool SummaryChart::mouseReleaseEvent(QMouseEvent * event,gGraph * graph)
return true; return true;
} }
} }
Q_UNUSED(event) Q_UNUSED(event)
hl_day = -1; hl_day = -1;
graph->timedRedraw(2000); graph->timedRedraw(2000);

View File

@ -43,8 +43,7 @@ class SummaryChart:public Layer
virtual bool isEmpty() { return m_empty; } virtual bool isEmpty() { return m_empty; }
//! \brief Adds a layer to the summaryChart (When in Bar mode, it becomes culminative, eg, the AHI chart) //! \brief Adds a layer to the summaryChart (When in Bar mode, it becomes culminative, eg, the AHI chart)
void addSlice(ChannelID code, QColor color, SummaryType type, EventDataType tval=0.00f) void addSlice(ChannelID code, QColor color, SummaryType type, EventDataType tval = 0.00f) {
{
m_codes.push_back(code); m_codes.push_back(code);
m_colors.push_back(color); m_colors.push_back(color);
m_type.push_back(type); m_type.push_back(type);

View File

@ -71,7 +71,7 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
if (usepixmap) { if (usepixmap) {
// Unbind any previous texture // Unbind any previous texture
if (m_textureID) w.graphView()->deleteTexture(m_textureID); if (m_textureID) { w.graphView()->deleteTexture(m_textureID); }
m_image = QImage(width + 22, height + 4, QImage::Format_ARGB32_Premultiplied); m_image = QImage(width + 22, height + 4, QImage::Format_ARGB32_Premultiplied);
m_image.fill(Qt::transparent); m_image.fill(Qt::transparent);
@ -79,6 +79,7 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
painter.setPen(Qt::black); painter.setPen(Qt::black);
painter.setFont(*defaultfont); painter.setFont(*defaultfont);
} }
double px, py; double px, py;
int start_px = left; int start_px = left;
@ -86,10 +87,13 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
//int width=scrx-(w.GetLeftMargin()+w.GetRightMargin()); //int width=scrx-(w.GetLeftMargin()+w.GetRightMargin());
// float height=scry-(w.GetTopMargin()+w.GetBottomMargin()); // float height=scry-(w.GetTopMargin()+w.GetBottomMargin());
if (width<40) if (width < 40) {
return; return;
}
qint64 minx; qint64 minx;
qint64 maxx; qint64 maxx;
if (w.blockZoom()) { if (w.blockZoom()) {
minx = w.rmin_x; minx = w.rmin_x;
maxx = w.rmax_x; maxx = w.rmax_x;
@ -97,13 +101,16 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
minx = w.min_x; minx = w.min_x;
maxx = w.max_x; maxx = w.max_x;
} }
qint64 xx = maxx - minx; qint64 xx = maxx - minx;
if (xx<=0) return;
if (xx <= 0) { return; }
//Most of this could be precalculated when min/max is set.. //Most of this could be precalculated when min/max is set..
QString fd, tmpstr; QString fd, tmpstr;
int divmax, dividx; int divmax, dividx;
int fitmode; int fitmode;
if (xx >= 86400000L) { // Day if (xx >= 86400000L) { // Day
fd = "Mjj 00"; fd = "Mjj 00";
dividx = 0; dividx = 0;
@ -125,6 +132,7 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
divmax = divcnt; divmax = divcnt;
fitmode = 3; fitmode = 3;
} }
//if (divmax>divcnt) divmax=divcnt; //if (divmax>divcnt) divmax=divcnt;
int x, y; int x, y;
@ -140,24 +148,30 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
int fit_ticks = 0; int fit_ticks = 0;
int div = -1; int div = -1;
qint64 closest = 0, tmp, tmpft; qint64 closest = 0, tmp, tmpft;
for (int i = dividx; i < divmax; i++) { for (int i = dividx; i < divmax; i++) {
tmpft = xx / divisors[i]; tmpft = xx / divisors[i];
tmp = max_ticks - tmpft; tmp = max_ticks - tmpft;
if (tmp<0) continue;
if (tmp < 0) { continue; }
if (tmpft > closest) { // Find the closest scale to the number if (tmpft > closest) { // Find the closest scale to the number
closest = tmpft; // that will fit closest = tmpft; // that will fit
div = i; div = i;
fit_ticks = tmpft; fit_ticks = tmpft;
} }
} }
if (fit_ticks == 0) { if (fit_ticks == 0) {
qDebug() << "gXAxis::Plot() Couldn't fit ticks.. Too short?" << minx << maxx << xx; qDebug() << "gXAxis::Plot() Couldn't fit ticks.. Too short?" << minx << maxx << xx;
return; return;
} }
if ((div < 0) || (div > divcnt)) { if ((div < 0) || (div > divcnt)) {
qDebug() << "gXAxis::Plot() div out of bounds"; qDebug() << "gXAxis::Plot() div out of bounds";
return; return;
} }
qint64 step = divisors[div]; qint64 step = divisors[div];
//Align left minimum to divisor by losing precision //Align left minimum to divisor by losing precision
@ -179,10 +193,13 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
if (step >= 86400000) { if (step >= 86400000) {
qint64 i = step / 86400000L; // number of days qint64 i = step / 86400000L; // number of days
if (i>14) i/=2;
if (i<0) i=1; if (i > 14) { i /= 2; }
if (i < 0) { i = 1; }
num_minor_ticks = i; num_minor_ticks = i;
} else num_minor_ticks=10; } else { num_minor_ticks = 10; }
float xmult = double(width) / double(xx); float xmult = double(width) / double(xx);
float step_pixels = double(step / float(num_minor_ticks)) * xmult; float step_pixels = double(step / float(num_minor_ticks)) * xmult;
@ -199,23 +216,31 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
for (int i = 0; i < num_minor_ticks; i++) { for (int i = 0; i < num_minor_ticks; i++) {
py -= step_pixels; py -= step_pixels;
if (py<start_px) continue;
if (usepixmap) if (py < start_px) { continue; }
if (usepixmap) {
painter.drawLine(py - left + 20, 0, py - left + 20, mintop - top); painter.drawLine(py - left + 20, 0, py - left + 20, mintop - top);
else } else {
lines->add(py, top, py, mintop); lines->add(py, top, py, mintop);
} }
}
int ms, m, h, s, d; int ms, m, h, s, d;
qint64 j; qint64 j;
for (qint64 i = aligned_start; i < maxx; i += step) { for (qint64 i = aligned_start; i < maxx; i += step) {
px = (i - minx) * xmult; px = (i - minx) * xmult;
px += left; px += left;
if (usepixmap) { if (usepixmap) {
painter.drawLine(px - left + 20, 0, px - left + 20, majtop - top); painter.drawLine(px - left + 20, 0, px - left + 20, majtop - top);
} else lines->add(px,top,px,majtop); } else { lines->add(px, top, px, majtop); }
j = i; j = i;
if (!m_utcfix) j+=tz_offset;
if (!m_utcfix) { j += tz_offset; }
ms = j % 1000; ms = j % 1000;
m = (j / 60000L) % 60L; m = (j / 60000L) % 60L;
h = (j / 3600000L) % 24L; h = (j / 3600000L) % 24L;
@ -236,26 +261,34 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
} else if (fitmode == 1) { // minute } else if (fitmode == 1) { // minute
tmpstr = QString("%1:%2").arg(h, 2, 10, QChar('0')).arg(m, 2, 10, QChar('0')); tmpstr = QString("%1:%2").arg(h, 2, 10, QChar('0')).arg(m, 2, 10, QChar('0'));
} else if (fitmode == 2) { // second } else if (fitmode == 2) { // second
tmpstr=QString("%1:%2:%3").arg(h,2,10,QChar('0')).arg(m,2,10,QChar('0')).arg(s,2,10,QChar('0')); tmpstr = QString("%1:%2:%3").arg(h, 2, 10, QChar('0')).arg(m, 2, 10, QChar('0')).arg(s, 2, 10,
QChar('0'));
} else if (fitmode == 3) { // milli } else if (fitmode == 3) { // milli
tmpstr=QString("%1:%2:%3:%4").arg(h,2,10,QChar('0')).arg(m,2,10,QChar('0')).arg(s,2,10,QChar('0')).arg(ms,3,10,QChar('0')); tmpstr = QString("%1:%2:%3:%4").arg(h, 2, 10, QChar('0')).arg(m, 2, 10, QChar('0')).arg(s, 2, 10,
QChar('0')).arg(ms, 3, 10, QChar('0'));
} }
int tx = px - x / 2.0; int tx = px - x / 2.0;
if (m_utcfix) if (m_utcfix) {
tx += step_pixels / 2.0; tx += step_pixels / 2.0;
if ((tx+x)<(left+width)) {
if (!usepixmap) w.renderText(tmpstr,tx,texttop,0,Qt::black,defaultfont);
else painter.drawText(tx-left+20,texttop-top,tmpstr);
} }
if ((tx + x) < (left + width)) {
if (!usepixmap) { w.renderText(tmpstr, tx, texttop, 0, Qt::black, defaultfont); }
else { painter.drawText(tx - left + 20, texttop - top, tmpstr); }
}
py = px; py = px;
for (int j = 1; j < num_minor_ticks; j++) { for (int j = 1; j < num_minor_ticks; j++) {
py += step_pixels; py += step_pixels;
if (py>=left+width) break;
if (py >= left + width) { break; }
if (usepixmap) { if (usepixmap) {
painter.drawLine(py - left + 20, 0, py - left + 20, mintop - top); painter.drawLine(py - left + 20, 0, py - left + 20, mintop - top);
} else lines->add(py,top,py,mintop); } else { lines->add(py, top, py, mintop); }
} }
if (lines->full()) { if (lines->full()) {
@ -267,9 +300,11 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
if (usepixmap) { if (usepixmap) {
painter.end(); painter.end();
m_image = QGLWidget::convertToGLFormat(m_image); m_image = QGLWidget::convertToGLFormat(m_image);
m_textureID=w.graphView()->bindTexture(m_image,GL_TEXTURE_2D,GL_RGBA,QGLContext::NoBindOption); m_textureID = w.graphView()->bindTexture(m_image, GL_TEXTURE_2D, GL_RGBA,
QGLContext::NoBindOption);
} }
w.invalidate_xAxisImage = false; w.invalidate_xAxisImage = false;
} }

View File

@ -52,7 +52,7 @@ void gXGrid::paint(gGraph & w,int left,int top, int width, int height)
//EventDataType dy=maxy-miny; //EventDataType dy=maxy-miny;
if (height<0) return; if (height < 0) { return; }
static QString fd = "0"; static QString fd = "0";
GetTextExtent(fd, x, y); GetTextExtent(fd, x, y);
@ -62,24 +62,30 @@ void gXGrid::paint(gGraph & w,int left,int top, int width, int height)
double mxy = MAX(fabs(maxy), fabs(miny)); double mxy = MAX(fabs(maxy), fabs(miny));
double mny = miny; double mny = miny;
if (miny < 0) { if (miny < 0) {
mny = -mxy; mny = -mxy;
} }
double rxy = mxy - mny; double rxy = mxy - mny;
int myt; int myt;
bool fnd = false; bool fnd = false;
for (myt = max_yticks; myt >= 1; myt--) { for (myt = max_yticks; myt >= 1; myt--) {
float v = rxy / float(myt); float v = rxy / float(myt);
if (float(v) == int(v)) { if (float(v) == int(v)) {
fnd = true; fnd = true;
break; break;
} }
} }
if (fnd) max_yticks=myt;
if (fnd) { max_yticks = myt; }
else { else {
max_yticks = 2; max_yticks = 2;
} }
double yt = 1 / max_yticks; double yt = 1 / max_yticks;
double ymult = height / rxy; double ymult = height / rxy;
@ -92,6 +98,7 @@ void gXGrid::paint(gGraph & w,int left,int top, int width, int height)
qDebug() << "min_ytick error in gXGrid::paint() in" << w.title(); qDebug() << "min_ytick error in gXGrid::paint() in" << w.title();
return; return;
} }
if (min_ytick >= 1000000) { if (min_ytick >= 1000000) {
min_ytick = 100; min_ytick = 100;
} }
@ -99,17 +106,23 @@ void gXGrid::paint(gGraph & w,int left,int top, int width, int height)
stippled = w.backlines(); stippled = w.backlines();
lines = w.backlines(); lines = w.backlines();
for (double i = miny; i <= maxy + min_ytick - 0.00001; i += min_ytick) { for (double i = miny; i <= maxy + min_ytick - 0.00001; i += min_ytick) {
ty = (i - miny) * ymult; ty = (i - miny) * ymult;
h = top + height - ty; h = top + height - ty;
if (m_show_major_lines && (i > miny)) { if (m_show_major_lines && (i > miny)) {
stippled->add(left, h, left + width, h, m_major_color.rgba()); stippled->add(left, h, left + width, h, m_major_color.rgba());
} }
double z = (min_ytick / 4) * ymult; double z = (min_ytick / 4) * ymult;
double g = h; double g = h;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
g += z; g += z;
if (g>top+height) break;
if (g > top + height) { break; }
//if (vertcnt>=maxverts) { //if (vertcnt>=maxverts) {
// qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<miny << "MaxY =" << maxy << "min_ytick=" <<min_ytick; // qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<miny << "MaxY =" << maxy << "min_ytick=" <<min_ytick;
// break; // break;
@ -117,12 +130,15 @@ void gXGrid::paint(gGraph & w,int left,int top, int width, int height)
if (m_show_minor_lines) {// && (i > miny)) { if (m_show_minor_lines) {// && (i > miny)) {
stippled->add(left, g, left + width, g, m_minor_color.rgba()); stippled->add(left, g, left + width, g, m_minor_color.rgba());
} }
if (stippled->full()) { if (stippled->full()) {
break; break;
} }
} }
if (lines->full() || stippled->full()) { if (lines->full() || stippled->full()) {
qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<miny << "MaxY =" << maxy << "min_ytick=" <<min_ytick; qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<
miny << "MaxY =" << maxy << "min_ytick=" << min_ytick;
break; break;
} }
} }
@ -271,8 +287,10 @@ void gYAxis::paint(gGraph & w,int left,int top, int width, int height)
} }
*/ */
} else { } else {
if (height<0) return; if (height < 0) { return; }
if (height>2000) return;
if (height > 2000) { return; }
int labelW = 0; int labelW = 0;
EventDataType miny; EventDataType miny;
@ -290,6 +308,7 @@ void gYAxis::paint(gGraph & w,int left,int top, int width, int height)
miny = -MAX(fabs(miny), fabs(maxy)); miny = -MAX(fabs(miny), fabs(maxy));
} }
} }
w.roundY(miny, maxy); w.roundY(miny, maxy);
EventDataType dy = maxy - miny; EventDataType dy = maxy - miny;
@ -301,6 +320,7 @@ void gYAxis::paint(gGraph & w,int left,int top, int width, int height)
double mxy = MAX(fabs(maxy), fabs(miny)); double mxy = MAX(fabs(maxy), fabs(miny));
double mny = miny; double mny = miny;
if (miny < 0) { if (miny < 0) {
mny = -mxy; mny = -mxy;
} }
@ -309,14 +329,18 @@ void gYAxis::paint(gGraph & w,int left,int top, int width, int height)
int myt; int myt;
bool fnd = false; bool fnd = false;
for (myt = max_yticks; myt > 2; myt--) { for (myt = max_yticks; myt > 2; myt--) {
float v = rxy / float(myt); float v = rxy / float(myt);
if (v == int(v)) { if (v == int(v)) {
fnd = true; fnd = true;
break; break;
} }
} }
if (fnd) max_yticks=myt;
if (fnd) { max_yticks = myt; }
double yt = 1 / max_yticks; double yt = 1 / max_yticks;
double ymult = height / rxy; double ymult = height / rxy;
@ -336,14 +360,18 @@ void gYAxis::paint(gGraph & w,int left,int top, int width, int height)
qDebug() << "min_ytick error in gYAxis::paint() in" << w.title(); qDebug() << "min_ytick error in gYAxis::paint() in" << w.title();
return; return;
} }
if (min_ytick >= 1000000) { if (min_ytick >= 1000000) {
min_ytick = 100; min_ytick = 100;
} }
lines = w.backlines(); lines = w.backlines();
GLuint line_color = m_line_color.rgba(); GLuint line_color = m_line_color.rgba();
for (double i = miny; i <= maxy + min_ytick - 0.00001; i += min_ytick) { for (double i = miny; i <= maxy + min_ytick - 0.00001; i += min_ytick) {
ty = (i - miny) * ymult; ty = (i - miny) * ymult;
if (dy < 5) { if (dy < 5) {
fd = Format(i * m_yaxis_scale, 2); fd = Format(i * m_yaxis_scale, 2);
} else { } else {
@ -352,46 +380,60 @@ void gYAxis::paint(gGraph & w,int left,int top, int width, int height)
GetTextExtent(fd, x, y); // performance bottleneck.. GetTextExtent(fd, x, y); // performance bottleneck..
if (x>labelW) labelW=x; if (x > labelW) { labelW = x; }
h = top + height - ty; h = top + height - ty;
if (h<top) continue;
if (h < top) { continue; }
w.renderText(fd, left + width - 8 - x, (h + (y / 2.0)), 0, m_text_color, defaultfont); w.renderText(fd, left + width - 8 - x, (h + (y / 2.0)), 0, m_text_color, defaultfont);
lines->add(left + width - 4, h, left + width, h, line_color); lines->add(left + width - 4, h, left + width, h, line_color);
double z = (min_ytick / 4) * ymult; double z = (min_ytick / 4) * ymult;
double g = h; double g = h;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
g += z; g += z;
if (g>top+height) break;
if (g > top + height) { break; }
lines->add(left + width - 3, g, left + width, g, line_color); lines->add(left + width - 3, g, left + width, g, line_color);
if (lines->full()) { if (lines->full()) {
qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<miny << "MaxY =" << maxy << "min_ytick=" <<min_ytick; qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<
miny << "MaxY =" << maxy << "min_ytick=" << min_ytick;
break; break;
} }
} }
if (lines->full()) { if (lines->full()) {
qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<miny << "MaxY =" << maxy << "min_ytick=" <<min_ytick; qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<
miny << "MaxY =" << maxy << "min_ytick=" << min_ytick;
break; break;
} }
} }
} }
} }
const QString gYAxis::Format(EventDataType v, int dp) { const QString gYAxis::Format(EventDataType v, int dp)
{
return QString::number(v, 'f', dp); return QString::number(v, 'f', dp);
} }
bool gYAxis::mouseMoveEvent(QMouseEvent *event, gGraph *graph) bool gYAxis::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
{ {
if (!p_profile->appearance->graphTooltips()) if (!p_profile->appearance->graphTooltips()) {
return false; return false;
}
int x = event->x(); int x = event->x();
int y = event->y(); int y = event->y();
if (!graph->units().isEmpty()) { if (!graph->units().isEmpty()) {
graph->ToolTip(graph->units(), x, y - 20, 0); graph->ToolTip(graph->units(), x, y - 20, 0);
// graph->redraw(); // graph->redraw();
} }
return true; return true;
} }
@ -404,6 +446,7 @@ bool gYAxis::mouseDoubleClickEvent(QMouseEvent * event, gGraph * graph)
graph->setZoomY(z); graph->setZoomY(z);
qDebug() << "Mouse double clicked for" << graph->title() << z; qDebug() << "Mouse double clicked for" << graph->title() << z;
} }
Q_UNUSED(event); Q_UNUSED(event);
return false; return false;
} }
@ -420,11 +463,14 @@ const QString gYAxisTime::Format(EventDataType v, int dp)
h >= 12 ? pm[0] = 'p' : pm[0] = 'a'; h >= 12 ? pm[0] = 'p' : pm[0] = 'a';
h %= 12; h %= 12;
if (h==0) h=12;
if (h == 0) { h = 12; }
} else { } else {
pm[0] = 0; pm[0] = 0;
} }
if (dp>2) return QString().sprintf("%02i:%02i:%02i%s",h,m,s,pm);
if (dp > 2) { return QString().sprintf("%02i:%02i:%02i%s", h, m, s, pm); }
return QString().sprintf("%i:%02i%s", h, m, pm); return QString().sprintf("%i:%02i%s", h, m, pm);
} }

View File

@ -30,20 +30,32 @@ void RoundedRectangle(int x,int y,int w,int h,int radius,const QColor color)
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
glVertex2i(x + radius, y); glVertex2i(x + radius, y);
glVertex2i(x + w - radius, y); glVertex2i(x + w - radius, y);
for(float i=(float)M_PI*1.5f;i<M_PI*2;i+=0.1f)
for (float i = (float)M_PI * 1.5f; i < M_PI * 2; i += 0.1f) {
glVertex2f(x + w - radius + cos(i)*radius, y + radius + sin(i)*radius); glVertex2f(x + w - radius + cos(i)*radius, y + radius + sin(i)*radius);
}
glVertex2i(x + w, y + radius); glVertex2i(x + w, y + radius);
glVertex2i(x + w, y + h - radius); glVertex2i(x + w, y + h - radius);
for(float i=0;i<(float)M_PI*0.5f;i+=0.1f)
for (float i = 0; i < (float)M_PI * 0.5f; i += 0.1f) {
glVertex2f(x + w - radius + cos(i)*radius, y + h - radius + sin(i)*radius); glVertex2f(x + w - radius + cos(i)*radius, y + h - radius + sin(i)*radius);
}
glVertex2i(x + w - radius, y + h); glVertex2i(x + w - radius, y + h);
glVertex2i(x + radius, y + h); glVertex2i(x + radius, y + h);
for(float i=(float)M_PI*0.5f;i<M_PI;i+=0.1f)
for (float i = (float)M_PI * 0.5f; i < M_PI; i += 0.1f) {
glVertex2f(x + radius + cos(i)*radius, y + h - radius + sin(i)*radius); glVertex2f(x + radius + cos(i)*radius, y + h - radius + sin(i)*radius);
}
glVertex2i(x, y + h - radius); glVertex2i(x, y + h - radius);
glVertex2i(x, y + radius); glVertex2i(x, y + radius);
for(float i=(float)M_PI;i<M_PI*1.5f;i+=0.1f)
for (float i = (float)M_PI; i < M_PI * 1.5f; i += 0.1f) {
glVertex2f(x + radius + cos(i)*radius, y + radius + sin(i)*radius); glVertex2f(x + radius + cos(i)*radius, y + radius + sin(i)*radius);
}
glEnd(); glEnd();
glDisable(GL_BLEND); glDisable(GL_BLEND);
@ -59,14 +71,23 @@ void LinedRoundedRectangle(int x,int y,int w,int h,int radius,int lw,QColor colo
glLineWidth((GLfloat)lw); glLineWidth((GLfloat)lw);
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
for(float i=(float)M_PI;i<=1.5f*M_PI;i+=0.1f)
for (float i = (float)M_PI; i <= 1.5f * M_PI; i += 0.1f) {
glVertex2f(radius * cos(i) + x + radius, radius * sin(i) + y + radius); glVertex2f(radius * cos(i) + x + radius, radius * sin(i) + y + radius);
for(float i=1.5f*(float)M_PI;i<=2*M_PI; i+=0.1f) }
for (float i = 1.5f * (float)M_PI; i <= 2 * M_PI; i += 0.1f) {
glVertex2f(radius * cos(i) + x + w - radius, radius * sin(i) + y + radius); glVertex2f(radius * cos(i) + x + w - radius, radius * sin(i) + y + radius);
for(float i=0;i<=0.5f*M_PI; i+=0.1f) }
for (float i = 0; i <= 0.5f * M_PI; i += 0.1f) {
glVertex2f(radius * cos(i) + x + w - radius, radius * sin(i) + y + h - radius); glVertex2f(radius * cos(i) + x + w - radius, radius * sin(i) + y + h - radius);
for(float i=0.5f*(float)M_PI;i<=M_PI;i+=0.1f) }
for (float i = 0.5f * (float)M_PI; i <= M_PI; i += 0.1f) {
glVertex2f(radius * cos(i) + x + radius, radius * sin(i) + y + h - radius); glVertex2f(radius * cos(i) + x + radius, radius * sin(i) + y + h - radius);
}
glVertex2i(x, y + radius); glVertex2i(x, y + radius);
glEnd(); glEnd();

View File

@ -44,8 +44,10 @@ const QColor COLOR_Brown=QColor("brown");
const QColor COLOR_Text = Qt::black; const QColor COLOR_Text = Qt::black;
const QColor COLOR_Outline = Qt::black; const QColor COLOR_Outline = Qt::black;
const QColor COLOR_ALT_BG1=QColor(0xd8,0xff,0xd8,0xff); // Alternating Background Color 1 (Event Flags) const QColor COLOR_ALT_BG1 = QColor(0xd8, 0xff, 0xd8,
const QColor COLOR_ALT_BG2=COLOR_White; // Alternating Background Color 2 (Event Flags) 0xff); // Alternating Background Color 1 (Event Flags)
const QColor COLOR_ALT_BG2 =
COLOR_White; // Alternating Background Color 2 (Event Flags)
/*! \brief Draw an outline of a rounded rectangle /*! \brief Draw an outline of a rounded rectangle