Code cleanup - removed old graphing engine files, added new GLbuffer class for multithread prep

This commit is contained in:
Mark Watkins 2011-08-31 03:22:54 +10:00
parent d6a11894ed
commit 076589cb3b
34 changed files with 362 additions and 2028 deletions

View File

@ -21,7 +21,7 @@ gBarChart::~gBarChart()
delete Xaxis;
}
void gBarChart::paint(gGraphWindow & w,int left, int top, int width, int height)
void gBarChart::paint(gGraph & w,int left, int top, int width, int height)
{
if (!m_visible) return;
// if (!data) return;

View File

@ -16,7 +16,7 @@ class gBarChart:public Layer
gBarChart(ChannelID code=EmptyChannel,QColor col=QColor("blue"),Qt::Orientation o=Qt::Horizontal);
virtual ~gBarChart();
virtual void paint(gGraphWindow & w,int left, int top, int width, int height);
virtual void paint(gGraph & w,int left, int top, int width, int height);
protected:
Qt::Orientation m_orientation;

View File

@ -91,9 +91,15 @@ void gFlagsGroup::paint(gGraph &w, int left, int top, int width, int height)
gFlagsLine::gFlagsLine(ChannelID code,QColor flag_color,QString label,bool always_visible,FlagType flt)
:Layer(code),m_label(label),m_always_visible(always_visible),m_flt(flt),m_flag_color(flag_color)
{
quads=new GLBuffer(flag_color,2048,GL_QUADS);
lines=new GLBuffer(flag_color,2048,GL_LINES);
quads->setAntiAlias(true);
lines->setAntiAlias(true);
}
gFlagsLine::~gFlagsLine()
{
delete lines;
delete quads;
}
void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
{
@ -116,21 +122,10 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
double xmult=width/xx;
qint32 vertcnt=0;
GLshort * vertarray=vertex_array[0];
qint32 quadcnt=0;
GLshort * quadarray=vertex_array[1];
if (!vertarray || !quadarray) {
qWarning() << "vertarray/quadarray==NULL";
return;
}
// Draw text label
float x,y;
GetTextExtent(m_label,x,y);
//w.qglColor(Qt::black);
//w.renderText(start_px-x-10,(scry-line_top)-(line_h/2)+(y/2),m_label);
//DrawText(w,m_label);
w.renderText(m_label,left-x-10,top+(height/2)+(y/2));
float x1,x2;
@ -150,23 +145,14 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
if (X > maxx) break;
x1=(X - minx) * xmult + left;
if (m_flt==FT_Bar) {
vertarray[vertcnt++]=x1;
vertarray[vertcnt++]=bartop;
vertarray[vertcnt++]=x1;
vertarray[vertcnt++]=bottom;
if (vertcnt>maxverts) { verts_exceeded=true; break; }
lines->add(x1,bartop,x1,bottom);
if (lines->full()) { verts_exceeded=true; break; }
} else if (m_flt==FT_Span) {
x2=(Y-minx)*xmult+left;
//w1=x2-x1;
quadarray[quadcnt++]=x1;
quadarray[quadcnt++]=bartop;
quadarray[quadcnt++]=x1;
quadarray[quadcnt++]=bottom;
quadarray[quadcnt++]=x2;
quadarray[quadcnt++]=bottom;
quadarray[quadcnt++]=x2;
quadarray[quadcnt++]=bartop;
if (quadcnt>maxverts) { verts_exceeded=true; break; }
quads->add(x1,bartop,x1,bottom);
quads->add(x2,bottom,x2,bartop);
if (quads->full()) { verts_exceeded=true; break; }
}
}
}
@ -176,7 +162,10 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
// glScissor(left,top,width,height);
//glEnable(GL_SCISSOR_TEST);
glEnableClientState(GL_VERTEX_ARRAY);
quads->draw();
lines->draw();
/*glEnableClientState(GL_VERTEX_ARRAY);
bool antialias=pref["UseAntiAliasing"].toBool();
if (antialias) {
@ -201,6 +190,6 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
glDisable(GL_BLEND);
}
glDisableClientState(GL_VERTEX_ARRAY);
*/
//glDisable(GL_SCISSOR_TEST);
}

View File

@ -31,6 +31,8 @@ class gFlagsLine:public Layer
int total_lines,line_num;
FlagType m_flt;
QColor m_flag_color;
GLBuffer *quads, *lines;
};
class gFlagsGroup:public LayerGroup

View File

@ -1,5 +1,132 @@
#include <cmath>
#include <QFontMetrics>
#include "gGraphView.h"
#include "SleepLib/profiles.h"
bool _graph_init=false;
QFont * defaultfont=NULL;
QFont * mediumfont=NULL;
QFont * bigfont=NULL;
bool evil_intel_graphics_chip=false;
// Must be called from a thread inside the application.
void InitGraphs()
{
if (!_graph_init) {
defaultfont=new QFont("Sans Serif",10);
mediumfont=new QFont("Sans Serif",11);
bigfont=new QFont("Serif",35);
defaultfont->setStyleHint(QFont::SansSerif,QFont::OpenGLCompatible);
mediumfont->setStyleHint(QFont::SansSerif,QFont::OpenGLCompatible);
bigfont->setStyleHint(QFont::Serif ,QFont::OpenGLCompatible);
_graph_init=true;
}
}
void DoneGraphs()
{
if (_graph_init) {
delete defaultfont;
delete bigfont;
delete mediumfont;
_graph_init=false;
}
}
void GetTextExtent(QString text, float & width, float & height, QFont *font)
{
QFontMetrics fm(*font);
//QRect r=fm.tightBoundingRect(text);
width=fm.width(text); //fm.width(text);
height=fm.xHeight()+2; //fm.ascent();
}
GLBuffer::GLBuffer(QColor color,int max,int type)
:m_color(color), m_max(max), m_type(type)
{
m_scissor=false;
buffer=new GLshort [max+8];
m_cnt=0;
m_size=1;
}
GLBuffer::~GLBuffer()
{
delete [] buffer;
}
void GLBuffer::add(GLshort s)
{
if (m_cnt<m_max) {
buffer[m_cnt++]=s;
} else {
qDebug() << "GLBuffer overflow";
}
}
void GLBuffer::add(GLshort x, GLshort y)
{
if (m_cnt<m_max+2) {
buffer[m_cnt++]=x;
buffer[m_cnt++]=y;
} else {
qDebug() << "GLBuffer overflow";
}
}
void GLBuffer::add(GLshort x1, GLshort y1, GLshort x2, GLshort y2)
{
if (m_cnt<m_max+4) {
buffer[m_cnt++]=x1;
buffer[m_cnt++]=y1;
buffer[m_cnt++]=x2;
buffer[m_cnt++]=y2;
} else {
qDebug() << "GLBuffer overflow";
}
}
void GLBuffer::draw()
{
if (m_cnt>0) {
bool antialias=pref["UseAntiAliasing"].toBool() && m_antialias;
float size=m_size;
if (antialias) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (m_type==GL_LINES) {
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
size+=0.5;
}
}
if (m_type==GL_LINES) {
glLineWidth(size);
} else if (m_type==GL_POINTS) {
glPointSize(size);
}
if (m_scissor) {
glScissor(s1,s2,s3,s4);
glEnable(GL_SCISSOR_TEST);
}
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_SHORT, 0, buffer);
glColor4ub(m_color.red(),m_color.green(),m_color.blue(),m_color.alpha());
glDrawArrays(m_type, 0, m_cnt >> 1);
glDisableClientState(GL_VERTEX_ARRAY);
//qDebug() << "I Drawed" << m_cnt << "vertices";
m_cnt=0;
if (m_scissor) {
glDisable(GL_SCISSOR_TEST);
m_scissor=false;
}
if (antialias) {
if (m_type==GL_LINES) {
glDisable(GL_LINE_SMOOTH);
}
glDisable(GL_BLEND);
}
}
}
Layer::Layer(ChannelID code)
{
@ -178,7 +305,7 @@ bool gGraph::isEmpty()
}
return empty;
}
void gGraph::invalidate()
/*void gGraph::invalidate()
{ // this may not be necessary, as scrollbar & resize issues a full redraw..
//m_lastbounds.setWidth(m_graphview->width());
@ -213,7 +340,7 @@ void gGraph::repaint()
m_graphview->updateGL();
}
}
*/
void gGraph::qglColor(QColor col)
{
m_graphview->qglColor(col);
@ -697,6 +824,10 @@ void gGraph::SetMaxY(EventDataType v)
{
max_y=v;
}
void gGraph::DrawStaticText(QStaticText & text, short x, short y)
{
m_graphview->DrawStaticText(text,x,y);
}
// Sets a new Min & Max X clipping, refreshing the graph and all it's layers.
void gGraph::SetXBounds(qint64 minx, qint64 maxx)
@ -781,6 +912,7 @@ void gGraphView::DrawTextQue()
void gGraphView::AddTextQue(QString & text, short x, short y, float angle, QColor & color, QFont * font)
{
text_mutex.lock();
if (m_textque_items>=textque_max) {
DrawTextQue();
}
@ -792,6 +924,14 @@ void gGraphView::AddTextQue(QString & text, short x, short y, float angle, QColo
q.color=color;
q.font=font;
m_textque_items++;
text_mutex.unlock();
}
void gGraphView::DrawStaticText(QStaticText & text, short x, short y)
{
// don't use this for multithread
QPainter painter(this);
painter.drawStaticText(x,y,text);
painter.end();
}
void gGraphView::AddGraph(gGraph *g,short group)
@ -936,9 +1076,13 @@ void gGraphView::resizeGL(int w, int h)
void gGraphView::paintGL()
{
if (width()<=0) return;
if (height()<=0) return;
QTime time;
time.start();
glClearColor(255,255,255,255);
//glClearDepth(1);
glClear(GL_COLOR_BUFFER_BIT);// | GL_DEPTH_BUFFER_BIT);
@ -946,16 +1090,16 @@ void gGraphView::paintGL()
//glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
/*glBegin(GL_QUADS);
glColor4f(1.0,1.0,1.0,1.0); // Gradient start
glVertex2f(0, height());
glVertex2f(0, 0);
glColor4f(0.7,0.7,1.0,1.0); // Gradient End
//glColor4f(0.9,0.9,0.9,1.0); // Gradient End
glVertex2f(width(), 0);
glVertex2f(width(), height());
glEnd();
glEnd();*/
float px=titleWidth-m_offsetX;
float py=-m_offsetY;
@ -978,6 +1122,8 @@ void gGraphView::paintGL()
m_graphs[i]->paint(px,py,width()-titleWidth,h);
glColor4f(0,0,0,1);
//if (i<numgraphs-1) {
// draw the splitter handle
glBegin(GL_QUADS);
glColor4f(.5,.5,.5,1.0);
glVertex2f(0,py+h);
@ -1010,6 +1156,7 @@ void gGraphView::paintGL()
//glDisable(GL_DEPTH_TEST);
swapBuffers(); // Dump to screen.
qDebug() << "Graph Draw" << time.elapsed() << "ms";
}
// For manual scrolling

View File

@ -5,16 +5,56 @@
#include <QScrollBar>
#include <QResizeEvent>
#include <SleepLib/day.h>
#include <QMutex>
#include <Graphs/glcommon.h>
#define MIN(a,b) (((a)<(b)) ? (a) : (b));
#define MAX(a,b) (((a)<(b)) ? (b) : (a));
enum FlagType { FT_Bar, FT_Dot, FT_Span };
void InitGraphs();
void DoneGraphs();
extern QFont * defaultfont;
extern QFont * mediumfont;
extern QFont * bigfont;
void GetTextExtent(QString text, float & width, float & height, QFont *font=defaultfont);
class gGraphView;
class gGraph;
const int textque_max=512;
class GLBuffer
{
public:
GLBuffer(QColor color,int max=2048,int type=GL_LINES);
~GLBuffer();
void add(GLshort s);
void add(GLshort x, GLshort y);
void add(GLshort x1, GLshort y1, GLshort x2, GLshort y2);
void scissor(GLshort x1, GLshort y1, GLshort x2, GLshort y2) { s1=x1; s2=y1; s3=x2; s4=y2; m_scissor=true; }
void draw();
inline GLshort & operator [](int i) { return buffer[i]; }
void reset() { m_cnt=0; }
int max() { return m_max; }
int cnt() { return m_cnt; }
bool full() { return m_cnt>=m_max; }
void setSize(float f) { m_size=f; }
void setAntiAlias(bool b) { m_antialias=b; }
protected:
QColor m_color;
GLshort * buffer;
int m_type; // type (GL_LINES, GL_QUADS, etc)
int m_max;
int m_cnt; // cnt
float m_size;
int s1,s2,s3,s4;
bool m_scissor;
bool m_antialias;
};
struct TextQue
{
@ -136,7 +176,7 @@ public:
QString title() { return m_title; }
virtual void repaint(); // Repaint individual graph..
//virtual void repaint(); // Repaint individual graph..
virtual void ResetBounds();
virtual void SetXBounds(qint64 minx, qint64 maxx);
@ -163,10 +203,10 @@ public:
short group() { return m_group; }
void setGroup(short group) { m_group=group; }
void DrawTextQue();
void DrawStaticText(QStaticText & text, short x, short y);
protected:
virtual void paint(int originX, int originY, int width, int height);
void invalidate();
//void invalidate();
virtual void wheelEvent(QWheelEvent * event);
virtual void mouseMoveEvent(QMouseEvent * event);
@ -227,6 +267,7 @@ public:
gGraph *m_selected_graph;
void AddTextQue(QString & text, short x, short y, float angle, QColor & color, QFont * font);
void DrawStaticText(QStaticText & text, short x, short y);
int horizTravel() { return m_horiz_travel; }
void DrawTextQue();
@ -236,6 +277,7 @@ public:
void updateScrollBar();
void updateScale(); // update scale & Scrollbar
void setEmptyText(QString s) { m_emptytext=s; }
QMutex text_mutex;
protected:

View File

@ -16,9 +16,13 @@ gLineChart::gLineChart(ChannelID code,QColor col,bool square_plot, bool disable_
{
m_line_color=col;
m_report_empty=false;
lines=new GLBuffer(col,40000,GL_LINES);
lines->setAntiAlias(true);
}
gLineChart::~gLineChart()
{
delete lines;
}
@ -123,13 +127,6 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
width--;
height-=2;
qint32 vertcnt=0;
GLshort * vertarray=vertex_array[0];
if (vertarray==NULL){
qWarning() << "VertArray==NULL";
return;
}
int num_points=0;
int visible_points=0;
int total_points=0;
@ -324,12 +321,9 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
// ay1=(m_drawlist[i-1].y()+m_drawlist[i].y()+m_drawlist[i+1].y())/3.0;
ax1=m_drawlist[i].x();
ay1=m_drawlist[i].y();
vertarray[vertcnt++]=xst+i;
vertarray[vertcnt++]=yst-ax1;
vertarray[vertcnt++]=xst+i;
vertarray[vertcnt++]=yst-ay1;
lines->add(xst+i,yst-ax1,xst+i,yst-ay1);
if (vertcnt>=maxverts) break;
if (lines->full()) break;
}
} else { // Zoomed in Waveform
@ -356,12 +350,9 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
firstpx=false;
continue;
}
vertarray[vertcnt++]=lastpx;
vertarray[vertcnt++]=lastpy;
vertarray[vertcnt++]=px;
vertarray[vertcnt++]=py;
lines->add(lastpx,lastpy,px,py);
if (vertcnt>=maxverts) {
if (lines->full()) {
done=true;
break;
}
@ -402,21 +393,15 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
firstpx=false;
} else {
if (square_plot) {
vertarray[vertcnt++]=lastpx;
vertarray[vertcnt++]=lastpy;
vertarray[vertcnt++]=px;
vertarray[vertcnt++]=lastpy;
vertarray[vertcnt++]=px;
vertarray[vertcnt++]=lastpy;
lines->add(lastpx,lastpy,px,lastpy);
lines->add(px,lastpy);
} else {
vertarray[vertcnt++]=lastpx;
vertarray[vertcnt++]=lastpy;
lines->add(lastpx,lastpy);
}
vertarray[vertcnt++]=px;
vertarray[vertcnt++]=py;
lines->add(px,py);
if (vertcnt>=maxverts) {
if (lines->full()) {
done=true;
break;
}
@ -445,57 +430,8 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
//DrawText(w,msg,left+(width/2.0)-(x/2.0),scry-w.GetBottomMargin()-height/2.0+y/2.0,0,Qt::gray,bigfont);
}
} else {
/*QString b;
long j=vertcnt/2;
if (accel) j/=2;
b.sprintf("%i %i %i %li",visible_points,sam,num_points,j);
float x,y;
GetTextExtent(b,x,y);
DrawText(b,scrx-w.GetRightMargin()-x-15,scry-w.GetBottomMargin()-10); */
// Crop to inside the margins.
int h1=top+height;
int h2=height;
if (h1<0) {
h2=h1+height;
h1=0;
lines->scissor(left,w.flipY(top+height+2),width+1,height+1);
lines->draw();
}
glScissor(left,w.flipY(top+height+2),width+1,height+1);
glEnable(GL_SCISSOR_TEST);
/*w.qglColor(Qt::black);
glBegin(GL_QUADS);
glVertex2i(0,0);
glVertex2i(2000,0);
glVertex2i(2000,1200);
glVertex2i(0,1200);
glEnd(); */
glDisable(GL_DEPTH_TEST);
bool antialias=pref["UseAntiAliasing"].toBool();
glDisable(GL_TEXTURE_2D);
if (antialias) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glLineWidth (1.5);
} else glLineWidth(1);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_SHORT, 0, vertarray);
w.qglColor(m_line_color);
glDrawArrays(GL_LINES, 0, vertcnt>>1);
glDisableClientState(GL_VERTEX_ARRAY);
if (antialias) {
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
}
glDisable(GL_SCISSOR_TEST);
}
glFlush();
}

View File

@ -32,6 +32,7 @@ protected:
bool m_square_plot;
bool m_disable_accel;
QColor m_line_color;
GLBuffer * lines;
};
#endif // GLINECHART_H

View File

@ -8,13 +8,22 @@
#include "SleepLib/profiles.h"
#include "gLineOverlay.h"
gLineOverlayBar::gLineOverlayBar(ChannelID code,QColor col,QString label,FlagType flt)
:Layer(code),m_label(label),m_flt(flt)
gLineOverlayBar::gLineOverlayBar(ChannelID code,QColor color,QString label,FlagType flt)
:Layer(code),m_flag_color(color),m_label(label),m_flt(flt)
{
m_flag_color=col;
points=new GLBuffer(color,2048,GL_POINTS);
points->setSize(4);
quads=new GLBuffer(color,2048,GL_QUADS);
lines=new GLBuffer(color,2048,GL_LINES);
points->setAntiAlias(true);
quads->setAntiAlias(true);
lines->setAntiAlias(true);
}
gLineOverlayBar::~gLineOverlayBar()
{
delete lines;
delete quads;
delete points;
}
void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int height)
@ -22,10 +31,7 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
if (!m_visible) return;
if (!m_day) return;
//int start_px=w.GetLeftMargin();
int start_py=topp;
//int width=scrx-(w.GetLeftMargin()+w.GetRightMargin());
//int height=scry-(w.GetTopMargin()+w.GetBottomMargin());
double xx=w.max_x-w.min_x;
double yy=w.max_y-w.min_y;
@ -39,7 +45,7 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
// glScissor(left,topp,width,height);
// glEnable(GL_SCISSOR_TEST);
qint32 vertcnt=0;
/*qint32 vertcnt=0;
GLshort * vertarray=vertex_array[0];
qint32 pointcnt=0;
GLshort * pointarray=vertex_array[1];
@ -48,7 +54,7 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
if (!vertarray || !quadarray || !pointarray) {
qWarning() << "VertArray/quadarray/pointarray==NULL";
return;
}
}*/
float bottom=start_py+height-25, top=start_py+25;
@ -85,30 +91,21 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
if (x2<left) x2=left;
if (x1>width+left) x1=width+left;
//double w1=x2-x1;
quadarray[quadcnt++]=x1;
quadarray[quadcnt++]=start_py;
quadarray[quadcnt++]=x2;
quadarray[quadcnt++]=start_py;
quadarray[quadcnt++]=x2;
quadarray[quadcnt++]=start_py+height;
quadarray[quadcnt++]=x1;
quadarray[quadcnt++]=start_py+height;
if (quadcnt>=maxverts) { verts_exceeded=true; break; }
quads->add(x1,start_py,x2,start_py);
quads->add(x2,start_py+height,x1,start_py+height);
if (quads->full()) { verts_exceeded=true; break; }
} else if (m_flt==FT_Dot) {
//if (pref["AlwaysShowOverlayBars"].toBool()) {
if (pref["AlwaysShowOverlayBars"].toBool() || (xx<3600000.0)) {
// show the fat dots in the middle
pointarray[pointcnt++]=x1;
pointarray[pointcnt++]=double(height)/double(yy)*double(-20-w.min_y)+topp;
if (pointcnt>=maxverts) { verts_exceeded=true; break; }
points->add(x1,double(height)/double(yy)*double(-20-w.min_y)+topp);
if (points->full()) { verts_exceeded=true; break; }
} else {
// thin lines down the bottom
vertarray[vertcnt++]=x1;
vertarray[vertcnt++]=start_py+1;
vertarray[vertcnt++]=x1;
vertarray[vertcnt++]=start_py+1+12;
if (vertcnt>=maxverts) { verts_exceeded=true; break; }
lines->add(x1,start_py+1);
lines->add(x1,start_py+1+12);
if (lines->full()) { verts_exceeded=true; break; }
}
} else if (m_flt==FT_Bar) {
@ -116,25 +113,18 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
if (pref["AlwaysShowOverlayBars"].toBool() || (xx<3600000)) {
z=top;
pointarray[pointcnt++]=x1;
pointarray[pointcnt++]=top; //z+2;
vertarray[vertcnt++]=x1;
vertarray[vertcnt++]=top;
vertarray[vertcnt++]=x1;
vertarray[vertcnt++]=bottom;
if (pointcnt>=maxverts) { verts_exceeded=true; break; }
points->add(x1,top);
lines->add(x1,top);
lines->add(x1,bottom);
if (points->full()) { verts_exceeded=true; break; }
} else {
vertarray[vertcnt++]=x1;
vertarray[vertcnt++]=z;
vertarray[vertcnt++]=x1;
vertarray[vertcnt++]=z-12;
lines->add(x1,z);
lines->add(x1,z-12);
}
if (vertcnt>=maxverts) { verts_exceeded=true; break; }
if (lines->full()) { verts_exceeded=true; break; }
if (xx<(1800000)) {
GetTextExtent(m_label,x,y);
//DrawText(w,m_label,x1-(x/2),scry-(start_py+height-30+y));
w.renderText(m_label,x1-(x/2),top-y+3);
//w.renderText(x1-(x/2),scry-(start_py+height-30+y),label);
}
}
@ -153,23 +143,11 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glLineWidth (1.5);
} else glLineWidth (1);
glEnableClientState(GL_VERTEX_ARRAY);
w.qglColor(m_flag_color);
if (quadcnt>0) {
glVertexPointer(2, GL_SHORT, 0, quadarray);
glDrawArrays(GL_QUADS, 0, quadcnt>>1);
}
if (vertcnt>0) {
glVertexPointer(2, GL_SHORT, 0, vertarray);
glDrawArrays(GL_LINES, 0, vertcnt>>1);
}
if (pointcnt>0) {
glPointSize(4);
glVertexPointer(2, GL_SHORT, 0, pointarray);
glDrawArrays(GL_POINTS, 0, pointcnt>>1);
}
glDisableClientState(GL_VERTEX_ARRAY);
quads->draw();
lines->draw();
//glPointSize(4);
points->draw();
if (antialias) {
glDisable(GL_LINE_SMOOTH);

View File

@ -23,6 +23,8 @@ class gLineOverlayBar:public Layer
QColor m_flag_color;
QString m_label;
FlagType m_flt;
GLBuffer *points,*quads, *lines;
};
#endif // GLINEOVERLAY_H

View File

@ -28,7 +28,7 @@ const QString & gTimeYAxis::Format(double v)
gSessionTime::gSessionTime(ChannelID code,QColor col,Qt::Orientation o)
:gLayer(code),m_orientation(o)
:Layer(code),m_orientation(o)
{
color.clear();
color.push_back(col);
@ -40,7 +40,7 @@ gSessionTime::~gSessionTime()
delete Xaxis;
}
void gSessionTime::Plot(gGraphWindow & w,float scrx,float scry)
void gSessionTime::paint(gGraph & w,int left, int top, int width, int height)
{
if (!m_visible) return;
/*if (!data) return;

View File

@ -7,7 +7,7 @@
#ifndef GSESSIONTIME_H
#define GSESSIONTIME_H
#include "graphlayer.h"
#include "gGraphView.h"
#include "gXAxis.h"
#include "gYAxis.h"
@ -20,13 +20,13 @@ public:
};
class gSessionTime:public gLayer
class gSessionTime:public Layer
{
public:
gSessionTime(ChannelID=EmptyChannel,QColor col=QColor("blue"),Qt::Orientation o=Qt::Horizontal);
virtual ~gSessionTime();
virtual void Plot(gGraphWindow & w,float scrx,float scry);
virtual void paint(gGraph & w,int left,int top, int width, int height);
protected:
Qt::Orientation m_orientation;

View File

@ -1,83 +0,0 @@
// This can die.
#include "gSplitter.h"
#include "graphwindow.h"
#include <QDebug>
gSplitter::gSplitter(QWidget *parent) :
QSplitter(parent)
{
z_timer=new QTimer(this);
//timer=NULL;
// icnt=0;
}
gSplitter::gSplitter(Qt::Orientation orientation, QWidget *parent) :
QSplitter(orientation,parent)
{
// icnt=0;
this->connect(this,SIGNAL(splitterMoved(int,int)),SLOT(mySplitterMoved(int,int)));
z_timer=new QTimer(this);
}
gSplitter::~gSplitter()
{
delete z_timer;
this->disconnect(SLOT(mySplitterMoved(int,int)));
// timer->stop();
}
void gSplitter::mySplitterMoved (int pos, int index)
{
if (z_timer->isActive()) z_timer->stop();
z_pos=pos;
z_index=index;
//this->setUpdatesEnabled(true);
if (gGraphWindow *w=qobject_cast<gGraphWindow *>(widget(index-1))) {
int s=sizes().at(index-1);
//w->resizeGL(w->width(),pos);
//w->updateGL();
//w->updateGL();
//w->paintGL();
}
if (gGraphWindow *w=qobject_cast<gGraphWindow *>(widget(index))) {
int s=sizes().at(index);
//w->resizeGL(w->width(),s);
//w->updateGL();
//w->paintGL();
}
qDebug() << ++icnt;
z_timer->singleShot(50,this,SLOT(doUpdateGraph()));
tm.start();
}
void gSplitter::doUpdateGraph()
{
if (tm.elapsed()<50)
return;
//this->setUpdatesEnabled(true);
if (gGraphWindow *w=qobject_cast<gGraphWindow *>(widget(z_index-1))) {
//qDebug() << icnt << "Height" << w->height() << z_index << z_pos << w->Title();
int s=sizes().at(z_index-1);
QSize n(w->width(),s);
QSize o(w->width(),s);
//QResizeEvent e(n,o);
//w->resizeEvent(&e);
//w->resizeGL(w->width(),s);
//w->paintGL();
}
if (gGraphWindow *w=qobject_cast<gGraphWindow *>(widget(z_index))) {
qDebug() << icnt << "Height" << w->height() << z_index << z_pos << w->Title();
int s=sizes().at(z_index);
w->resizeGL(w->width(),s);
w->paintGL();
}
//timer->stop();
icnt=0;
// QSplitter::resizeEvent(&event);
}

View File

@ -1,30 +0,0 @@
#ifndef GSPLITTER_H
#define GSPLITTER_H
#include <QSplitter>
#include <QResizeEvent>
#include <QTime>
#include <QTimer>
class gSplitter : public QSplitter
{
Q_OBJECT
public:
explicit gSplitter(QWidget *parent = 0);
explicit gSplitter(Qt::Orientation orientation, QWidget *parent = 0);
virtual ~gSplitter();
signals:
public slots:
void mySplitterMoved(int pos, int index);
void doUpdateGraph();
protected:
QTimer * z_timer;
int z_pos,z_index;
int icnt;
QTime tm;
};
#endif // GSPLITTER_H

View File

@ -13,35 +13,27 @@ void gStatsLine::paint(gGraph & w, int left, int top, int width, int height)
float x,y;
m_text=m_label;
GetTextExtent(m_text,x,y);
// GetTextExtent(m_text,x,y);
int z=(width+gYAxis::Margin)/5;
int p=left-gYAxis::Margin;
top+=8+y;
w.renderText(m_text,p,top,0,m_textcolor);
top+=4;
w.DrawStaticText(st_label,p,top);
//w.renderText(m_text,p,top,0,m_textcolor);
p+=z;
m_text="Min="+QString::number(m_min,'f',2);
GetTextExtent(m_text,x,y);
w.renderText(m_text,p,top,0,m_textcolor);
w.DrawStaticText(st_min,p,top);
p+=z;
m_text="Avg="+QString::number(m_avg,'f',2);
GetTextExtent(m_text,x,y);
w.renderText(m_text,p,top,0,m_textcolor);
w.DrawStaticText(st_avg,p,top);
p+=z;
m_text="90%="+QString::number(m_p90,'f',2);
GetTextExtent(m_text,x,y);
w.renderText(m_text,p,top,0,m_textcolor);
w.DrawStaticText(st_p90,p,top);
p+=z;
m_text="Max="+QString::number(m_max,'f',2);
GetTextExtent(m_text,x,y);
w.renderText(m_text,p,top,0,m_textcolor);
// GetTextExtent(m_text,m_tx,m_ty);
w.DrawStaticText(st_max,p,top);
}
@ -55,7 +47,11 @@ void gStatsLine::SetDay(Day *d)
m_avg=d->wavg(m_code);
m_p90=d->p90(m_code);
m_text.clear();
st_label.setText(m_label);
st_min.setText("Min="+QString::number(m_min,'f',2));
st_max.setText("Max="+QString::number(m_max,'f',2));
st_avg.setText("Avg="+QString::number(m_avg,'f',2));
st_p90.setText("90%="+QString::number(m_p90,'f',2));
// m_stext.setText(m_text);
// m_empty=true;

View File

@ -19,7 +19,7 @@ protected:
EventDataType m_min,m_max,m_avg,m_p90;
QString m_label;
QString m_text;
QStaticText m_stext;
QStaticText st_label,st_min,st_max,st_avg,st_p90;
float m_tx,m_ty;
};

View File

@ -1,30 +0,0 @@
// This can die. titles are now handled by gGraphView.
/*
gTitle (Graph Title) Implementation
Copyright (c)2011 Mark Watkins <jedimark@users.sourceforge.net>
License: GPL
*/
#include "gTitle.h"
gTitle::gTitle(const QString & _title,QColor color,QFont font)
:gLayer(EmptyChannel),m_title(_title),m_color(color),m_font(font)
{
}
gTitle::~gTitle()
{
}
void gTitle::Plot(gGraphWindow & w,float scrx,float scry)
{
if (!m_visible) return;
scrx=scrx;
float width,height;
GetTextExtent(m_title,width,height);
int xp=(height/2)+17;
//if (m_alignment==wxALIGN_RIGHT) xp=scrx-4-height;
int j=scry/2-w.GetTopMargin();
DrawText(w,m_title,xp,j,90.0,m_color,&m_font);
}

View File

@ -1,26 +0,0 @@
/********************************************************************
gTitle (Graph Title) Header
Copyright (c)2011 Mark Watkins <jedimark@users.sourceforge.net>
License: GPL
*********************************************************************/
#ifndef GTITLE_H
#define GTITLE_H
#include "graphlayer.h"
class gTitle:public gLayer
{
public:
gTitle(const QString & _title,QColor color=QColor("black"),QFont font=QFont());
virtual ~gTitle();
virtual void Plot(gGraphWindow & w,float scrx,float scry);
static const int Margin=20;
protected:
QString m_title;
QColor m_color;
QFont m_font;
};
#endif // GTITLE_H

View File

@ -28,9 +28,12 @@ gXAxis::gXAxis(QColor col,bool fadeout)
QTime t2=d.toUTC().time();
tz_offset=t2.secsTo(t1)/60L;
tz_offset*=60000L;
vertarray=new GLBuffer(m_line_color);
}
gXAxis::~gXAxis()
{
delete vertarray;
}
void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
{
@ -118,12 +121,12 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
qint64 aligned_start=minx/step;
aligned_start*=step;
qint32 vertcnt=0;
GLshort * vertarray=vertex_array[0];
//qint32 vertcnt=0;
/*GLshort * vertarray=vertex_array[0];
if (vertarray==NULL) {
qWarning() << "VertArray==NULL";
return;
}
} */
while (aligned_start<minx) {
aligned_start+=step;
@ -135,19 +138,15 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
for (int i=0;i<10;i++) {
py-=step_pixels;
if (py<start_px) continue;
vertarray[vertcnt++]=py;
vertarray[vertcnt++]=top;
vertarray[vertcnt++]=py;
vertarray[vertcnt++]=top+4;
vertarray->add(py,top);
vertarray->add(py,top+4);
}
w.qglColor(Qt::black);
for (qint64 i=aligned_start;i<maxx;i+=step) {
px=double(i-minx)*xmult;
px+=left;
vertarray[vertcnt++]=px;
vertarray[vertcnt++]=top;
vertarray[vertcnt++]=px;
vertarray[vertcnt++]=top+6;
vertarray->add(px,top);
vertarray->add(px,top+6);
qint64 j=i+tz_offset;
int ms=j % 1000;
int m=(j/60000L) % 60L;
@ -173,27 +172,23 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
for (int j=1;j<10;j++) {
py+=step_pixels;
if (py>=left+width) break;
vertarray[vertcnt++]=py;
vertarray[vertcnt++]=top;
vertarray[vertcnt++]=py;
vertarray[vertcnt++]=top+4;
if (vertcnt>=maxverts) {
break;
}
vertarray->add(py,top);
vertarray->add(py,top+4);
}
if (vertcnt>=maxverts) {
if (vertarray->full()) {
qWarning() << "maxverts exceeded in gXAxis::Plot()";
break;
}
}
glEnableClientState(GL_VERTEX_ARRAY);
glLineWidth(1);
vertarray->draw();
/* glEnableClientState(GL_VERTEX_ARRAY);
w.qglColor(Qt::black);
glVertexPointer(2, GL_SHORT, 0, vertarray);
glDrawArrays(GL_LINES, 0, vertcnt>>1);
glDisableClientState(GL_VERTEX_ARRAY); // deactivate vertex arrays after drawing
glDisableClientState(GL_VERTEX_ARRAY); // deactivate vertex arrays after drawing*/
/* if (m_fadeout) {

View File

@ -38,5 +38,6 @@ class gXAxis:public Layer
QColor m_minor_color;
bool m_fadeout;
qint64 tz_offset;
GLBuffer * vertarray;
};
#endif // GXAXIS_H

View File

@ -19,9 +19,14 @@ gXGrid::gXGrid(QColor col)
m_minor_color=QColor(220,220,220,64);
m_show_major_lines=true;
m_show_minor_lines=true;
majorvert=new GLBuffer(m_major_color);
minorvert=new GLBuffer(m_minor_color);
}
gXGrid::~gXGrid()
{
delete minorvert;
delete majorvert;
}
void gXGrid::paint(gGraph & w,int left,int top, int width, int height)
{
@ -90,7 +95,7 @@ void gXGrid::paint(gGraph & w,int left,int top, int width, int height)
float ty,h;
qint32 vertcnt=0;
/*qint32 vertcnt=0;
GLshort * vertarray=(GLshort *)vertex_array[0];
qint32 minorvertcnt=0;
GLshort * minorvertarray=(GLshort *)vertex_array[1];
@ -100,7 +105,7 @@ void gXGrid::paint(gGraph & w,int left,int top, int width, int height)
if ((vertarray==NULL) || (minorvertarray==NULL) || (majorvertarray==NULL)) {
qWarning() << "gXGrid::Paint() VertArray==NULL";
return;
}
} */
if (min_ytick<=0) {
qDebug() << "min_ytick error in gXGrid::paint()";
@ -111,55 +116,48 @@ void gXGrid::paint(gGraph & w,int left,int top, int width, int height)
}
double q=((maxy-(miny+(min_ytick/2.0)))/min_ytick)*4;
if (q>=maxverts) {
qDebug() << "Would exeed maxverts. Should be another two bounds exceeded messages after this. (I can do a minor optimisation by disabling the other checks if this turns out to be consistent)" << q << maxverts;
}
//if (q>=maxverts) {
// qDebug() << "Would exeed maxverts. Should be another two bounds exceeded messages after this. (I can do a minor optimisation by disabling the other checks if this turns out to be consistent)" << q << maxverts;
//}
for (double i=miny; i<=maxy+min_ytick-0.00001; i+=min_ytick) {
ty=(i - miny) * ymult;
h=top+height-ty;
if (m_show_major_lines && (i > miny)) {
majorvertarray[majorvertcnt++]=left;
majorvertarray[majorvertcnt++]=h;
majorvertarray[majorvertcnt++]=left+width;
majorvertarray[majorvertcnt++]=h;
majorvert->add(left,h);
majorvert->add(left+width,h);
}
double z=(min_ytick/4)*ymult;
double g=h;
for (int i=0;i<3;i++) {
g+=z;
if (g>top+height) break;
if (vertcnt>=maxverts) {
qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<miny << "MaxY =" << maxy << "min_ytick=" <<min_ytick;
break;
}
//if (vertcnt>=maxverts) {
// qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<miny << "MaxY =" << maxy << "min_ytick=" <<min_ytick;
// break;
// }
if (m_show_minor_lines) {// && (i > miny)) {
minorvertarray[minorvertcnt++]=left;
minorvertarray[minorvertcnt++]=g;
minorvertarray[minorvertcnt++]=left+width;
minorvertarray[minorvertcnt++]=g;
minorvert->add(left,g);
minorvert->add(left+width,g);
}
if (minorvertcnt>=maxverts) {
if (minorvert->full()) {
break;
}
}
if ((majorvertcnt>=maxverts)||(minorvertcnt>=maxverts)) {
if (majorvert->full() || minorvert->full()) {
qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<miny << "MaxY =" << maxy << "min_ytick=" <<min_ytick;
break;
}
}
if (vertcnt>=maxverts) {
qWarning() << "gXGrid tickers and display should be corrupted, because something dumb is happening in " << w.title() << "graph";
return;
}
// Draw the lines & ticks
// Turn on blending??
glEnableClientState(GL_VERTEX_ARRAY);
glLineWidth(1);
majorvert->draw();
minorvert->draw();
/*
glEnableClientState(GL_VERTEX_ARRAY);
w.qglColor(m_minor_color);
glVertexPointer(2, GL_SHORT, 0, minorvertarray);
glDrawArrays(GL_LINES, 0, minorvertcnt>>1);
@ -167,6 +165,7 @@ void gXGrid::paint(gGraph & w,int left,int top, int width, int height)
glVertexPointer(2, GL_SHORT, 0, majorvertarray);
glDrawArrays(GL_LINES, 0, majorvertcnt>>1);
glDisableClientState(GL_VERTEX_ARRAY); // deactivate vertex arrays after drawing
*/
}
@ -176,13 +175,13 @@ gYAxis::gYAxis(QColor col)
{
m_line_color=col;
m_text_color=col;
//m_major_color=QColor(190,190,190,64);
//m_minor_color=QColor(220,220,220,64);
m_yaxis_scale=1;
vertarray=new GLBuffer(m_line_color);
}
gYAxis::~gYAxis()
{
delete vertarray;
}
void gYAxis::paint(gGraph & w,int left,int top, int width, int height)
{
@ -269,7 +268,7 @@ void gYAxis::paint(gGraph & w,int left,int top, int width, int height)
float ty,h;
qint32 vertcnt=0;
/*qint32 vertcnt=0;
GLshort * vertarray=(GLshort *)vertex_array[0];
qint32 minorvertcnt=0;
GLshort * minorvertarray=(GLshort *)vertex_array[1];
@ -279,7 +278,7 @@ void gYAxis::paint(gGraph & w,int left,int top, int width, int height)
if ((vertarray==NULL) || (minorvertarray==NULL) || (majorvertarray==NULL)) {
qWarning() << "gYAxis::Plot() VertArray==NULL";
return;
}
} */
if (min_ytick<=0) {
qDebug() << "min_ytick error in gYAxis::Plot()";
@ -290,9 +289,9 @@ void gYAxis::paint(gGraph & w,int left,int top, int width, int height)
}
double q=((maxy-(miny+(min_ytick/2.0)))/min_ytick)*4;
if (q>=maxverts) {
/*if (q>=maxverts) {
qDebug() << "Would exeed maxverts. Should be another two bounds exceeded messages after this. (I can do a minor optimisation by disabling the other checks if this turns out to be consistent)" << q << maxverts;
}
}*/
w.qglColor(m_text_color);
for (double i=miny; i<=maxy+min_ytick-0.00001; i+=min_ytick) {
@ -305,44 +304,36 @@ void gYAxis::paint(gGraph & w,int left,int top, int width, int height)
//DrawText(w,fd,left+width-8-x,(h+(y/2.0)),0,m_text_color);
w.renderText(fd,left+width-8-x,(h+(y/2.0)),0,m_text_color);
vertarray[vertcnt++]=left+width-4;
vertarray[vertcnt++]=h;
vertarray[vertcnt++]=left+width;
vertarray[vertcnt++]=h;
vertarray->add(left+width-4,h);
vertarray->add(left+width,h);
double z=(min_ytick/4)*ymult;
double g=h;
for (int i=0;i<3;i++) {
g+=z;
if (g>top+height) break;
vertarray[vertcnt++]=left+width-3;
vertarray[vertcnt++]=g;
vertarray[vertcnt++]=left+width;
vertarray[vertcnt++]=g;
if (vertcnt>=maxverts) {
vertarray->add(left+width-3,g);
vertarray->add(left+width,g);
if (vertarray->full()) {
qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<miny << "MaxY =" << maxy << "min_ytick=" <<min_ytick;
break;
}
}
if (vertcnt>=maxverts) {
if (vertarray->full()) {
qWarning() << "vertarray bounds exceeded in gYAxis for " << w.title() << "graph" << "MinY =" <<miny << "MaxY =" << maxy << "min_ytick=" <<min_ytick;
break;
}
}
if (vertcnt>=maxverts) {
qWarning() << "yAxis tickers and display should be corrupted, because something dumb is happening in " << w.title() << "graph";
return;
}
vertarray->draw();
// Draw the lines & ticks
// Turn on blending??
glEnableClientState(GL_VERTEX_ARRAY);
/*glEnableClientState(GL_VERTEX_ARRAY);
glLineWidth(1);
w.qglColor(m_line_color);
glVertexPointer(2, GL_SHORT, 0, vertarray);
glDrawArrays(GL_LINES, 0, vertcnt>>1);
glDisableClientState(GL_VERTEX_ARRAY); // deactivate vertex arrays after drawing
glDisableClientState(GL_VERTEX_ARRAY); // deactivate vertex arrays after drawing */
}

View File

@ -13,7 +13,7 @@ class gYSpacer:public Layer
{
public:
gYSpacer(int spacer=20);
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) {w=w; left=left; top=top; width=width; height=height; }
};
@ -33,6 +33,7 @@ protected:
bool m_show_minor_lines;
QColor m_major_color;
QColor m_minor_color;
GLBuffer * minorvert, * majorvert;
};
class gYAxis:public Layer
@ -63,7 +64,7 @@ class gYAxis:public Layer
QColor m_line_color;
QColor m_text_color;
GLBuffer * vertarray;
};
#endif // GYAXIS_H

View File

@ -4,156 +4,8 @@
License: GPL
*/
#include <QApplication>
#include <QFontMetrics>
#include <QMessageBox>
#include <QDebug>
#include <math.h>
#include <cmath>
#include "glcommon.h"
#include "SleepLib/profiles.h"
#include <QFile>
bool _graph_init=false;
QFont * defaultfont=NULL;
QFont * mediumfont=NULL;
QFont * bigfont=NULL;
GLshort * vertex_array[num_vert_arrays]={0};
bool evil_intel_graphics_chip=false;
// Must be called from a thread inside the application.
void InitGraphs()
{
if (!_graph_init) {
defaultfont=new QFont("Sans Serif",10);
mediumfont=new QFont("Sans Serif",11);
bigfont=new QFont("Serif",35);
defaultfont->setStyleHint(QFont::SansSerif,QFont::OpenGLCompatible);
mediumfont->setStyleHint(QFont::SansSerif,QFont::OpenGLCompatible);
bigfont->setStyleHint(QFont::Serif ,QFont::OpenGLCompatible);
for (int i=0;i<num_vert_arrays;i++) {
// The extra 8 vertexes are important..
GLshort *a=(GLshort *)calloc(maxverts+8,sizeof(GLshort));
vertex_array[i]=a;
}
_graph_init=true;
}
}
void DoneGraphs()
{
if (_graph_init) {
delete defaultfont;
delete bigfont;
delete mediumfont;
for (int i=0;i<num_vert_arrays;i++) {
free(vertex_array[i]);
}
_graph_init=false;
}
}
void GetTextExtent(QString text, float & width, float & height, QFont *font)
{
QFontMetrics fm(*font);
//QRect r=fm.tightBoundingRect(text);
width=fm.width(text); //fm.width(text);
height=fm.xHeight()+2; //fm.ascent();
}
inline void RDrawText(QPainter & painter, QString text, int x, int y, float angle, QColor color,QFont *font)
{
//QFontMetrics fm(*font);
float w,h;
//GetTextExtent(text,w,h,font);
//int a=fm.overlinePos(); //ascent();
//LinedRoundedRectangle(x,wid.GetScrY()-y,w,h,0,1,QColor("black"));
if (!font) {
QMessageBox::critical(NULL,"Critical Error","Font Problem. Forgot to call GraphInit()? Have to abort");
exit(-1);
}
// glEnable(GL_TEXTURE_2D);
// glDisable(GL_DEPTH_TEST);
painter.setFont(*font);
//color=Qt::black;
painter.setPen(color);
painter.setBrush(QBrush(color));
painter.setOpacity(1);
// painter.setCompositionMode(QPainter::CompositionMode_);
if (angle==0) {
painter.drawText(x,y,text);
} else {
GetTextExtent(text, w, h, font);
painter.translate(floor(x),floor(y));
painter.rotate(-angle);
painter.drawText(floor(-w/2.0),floor(-h/2.0),text);
painter.rotate(+angle);
painter.translate(floor(-x),floor(-y));
}
}
struct TextBuffer
{
QString text;
int x,y;
float angle;
QColor color;
QFont *font;
TextBuffer() { x=0; y=0; }
TextBuffer(QString _text, int _x, int _y, float _angle, QColor _color,QFont *_font) {
text=_text; x=_x; y=_y; angle=_angle; color=_color; font=_font;
}
};
QVector<TextBuffer> TextQue;
QVector<TextBuffer> TextQueRot;
void DrawTextQueue(gGraphWindow & wid)
{
//glFlush();
for (int i=0;i<TextQue.size();i++) {
TextBuffer & t=TextQue[i];
wid.qglColor(t.color);
wid.renderText(t.x,wid.GetScrY()-t.y,0,t.text,*t.font);
//RDrawText(painter,t.text,t.x,t.y,t.angle,t.color,t.font);
//delete TextQue[i];
}
if (wid.parentWidget()!=0) {
QPainter painter(&wid);
painter.setRenderHint(QPainter::HighQualityAntialiasing,true);
// TODO.. Prerotate the 90degree stuff here and keep the matrix for all of these..
for (int i=0;i<TextQueRot.size();i++) {
TextBuffer & t=TextQueRot[i];
RDrawText(painter,t.text,t.x,t.y,t.angle,t.color,t.font);
//delete TextQueRot[i];
}
painter.end();
}
TextQueRot.clear();
TextQue.clear();
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
}
// I bet this slows things down craploads.. should probably skip the vector and use a preallocated textbuffer array.
void DrawText(gGraphWindow &wid,QString text, int x, int y, float angle, QColor color,QFont *font)
{
if (angle!=0) {
TextQueRot.push_back(TextBuffer(text,x,y,angle,color,font));
} else {
//TextQue.push_back(TextBuffer(text,x,y,0,color,font));
//wid.qglColor(color);
//wid.renderText(x,wid.GetScrY()-y,0,text,*font);
QPainter painter(&wid);
painter.setRenderHint(QPainter::TextAntialiasing,true);
RDrawText(painter,text,x,y,0,color,font);
painter.end();
}
}
void RoundedRectangle(int x,int y,int w,int h,int radius,const QColor color)
{

View File

@ -7,27 +7,8 @@
#ifndef GLCOMMON_H
#define GLCOMMON_H
#include <QFont>
#include <QColor>
#include <QtOpenGL/qgl.h>
#include "Graphs/graphwindow.h"
void InitGraphs();
void DoneGraphs();
extern QFont * defaultfont;
extern QFont * mediumfont;
extern QFont * bigfont;
const int num_vert_arrays=4;
const qint32 maxverts=65536*4; // Resolution dependant..
extern GLshort *vertex_array[num_vert_arrays];
class gGraphWindow;
void GetTextExtent(QString text, float & width, float & height, QFont *font=defaultfont);
void DrawText(gGraphWindow &wid, QString text, int x, int y, float angle=0, QColor color=Qt::black,QFont *font=defaultfont);
void DrawTextQueue(gGraphWindow & wid);
#include <QColor>
void LinedRoundedRectangle(int x,int y,int w,int h,int radius,int lw,QColor color);
void RoundedRectangle(int x,int y,int w,int h,int radius,const QColor color);

View File

@ -1,137 +0,0 @@
// This file is Scheduled for destruction..
/*
gLayer Implementation
Copyright (c)2011 Mark Watkins <jedimark@users.sourceforge.net>
License: GPL
*/
#include "graphlayer.h"
gLayer::gLayer(ChannelID code,QString title)
:m_code(code),m_title(title)
{
m_visible = true;
m_movable = false;
//color.push_back(QColor("red"));
//color.push_back(QColor("green"));
m_day=NULL;
m_miny=m_maxy=0;
m_minx=m_maxx=0;
}
gLayer::~gLayer()
{
}
void gLayer::SetDay(Day * d)
{
m_day=d;
if (!d) return;
m_minx=d->first(m_code);
m_maxx=d->last(m_code);
m_miny=d->min(m_code);
m_maxy=d->max(m_code);
}
bool gLayer::isEmpty()
{
if (m_day && (m_day->count(m_code)!=0))
return false;
return true;
}
gLayerGroup::gLayerGroup():gLayer(EmptyChannel)
{
}
gLayerGroup::~gLayerGroup()
{
}
bool gLayerGroup::isEmpty()
{
bool empty=true;
for (int i=0;i<layers.size();i++) {
if (layers[i]->isEmpty()) {
empty=false;
break;
}
}
return empty;
}
void gLayerGroup::SetDay(Day * d)
{
for (int i=0;i<layers.size();i++) {
layers[i]->SetDay(d);
}
m_day=d;
}
void gLayerGroup::AddLayer(gLayer *l)
{
layers.push_back(l);
}
qint64 gLayerGroup::Minx()
{
bool first=true;
qint64 m=0,t;
for (int i=0;i<layers.size();i++) {
t=layers[i]->Minx();
if (!t) continue;
if (first) {
m=t;
first=false;
} else
if (m>t) m=t;
}
return m;
}
qint64 gLayerGroup::Maxx()
{
bool first=true;
qint64 m=0,t;
for (int i=0;i<layers.size();i++) {
t=layers[i]->Maxx();
if (!t) continue;
if (first) {
m=t;
first=false;
} else
if (m<t) m=t;
}
return m;
}
EventDataType gLayerGroup::Miny()
{
bool first=true;
EventDataType m=0,t;
for (int i=0;i<layers.size();i++) {
t=layers[i]->Miny();
if (t==layers[i]->Minx()) continue;
if (first) {
m=t;
first=false;
} else {
if (m>t) m=t;
}
}
return m;
}
EventDataType gLayerGroup::Maxy()
{
bool first=true;
EventDataType m=0,t;
for (int i=0;i<layers.size();i++) {
t=layers[i]->Maxy();
if (t==layers[i]->Miny()) continue;
if (first) {
m=t;
first=false;
} else
if (m<t) m=t;
}
return m;
}

View File

@ -1,68 +0,0 @@
/*
gLayer Headers
Copyright (c)2011 Mark Watkins <jedimark@users.sourceforge.net>
License: GPL
*/
#ifndef GRAPHLAYER_H
#define GRAPHLAYER_H
#include <QString>
#include "SleepLib/day.h"
#include "graphwindow.h"
enum FlagType { FT_Bar, FT_Dot, FT_Span };
class gGraphWindow;
class gLayer
{
public:
gLayer(ChannelID code=EmptyChannel,QString title="");
virtual ~gLayer();
virtual void Plot(gGraphWindow & w,float scrx,float scry)=0;
//QVector<QColor> color;
virtual void SetDay(Day * d);
virtual void SetCode(ChannelID c) { m_code=c; }
virtual qint64 Minx() { if (m_day) return m_day->first(); return m_minx; }
virtual qint64 Maxx() { if (m_day) return m_day->last(); return m_maxx; }
virtual EventDataType Miny() { return m_miny; }
virtual EventDataType Maxy() { return m_maxy; }
virtual void setMinY(EventDataType val) { m_miny=val; }
virtual void setMaxY(EventDataType val) { m_maxy=val; }
virtual void setMinX(qint64 val) { m_minx=val; }
virtual void setMaxX(qint64 val) { m_maxx=val; }
virtual void setVisible(bool v) { m_visible=v; }
virtual bool isVisible() { return m_visible; }
virtual bool isEmpty();
inline const ChannelID & code() { return m_code; }
protected:
Day *m_day;
bool m_visible;
bool m_movable;
qint64 m_minx,m_maxx;
EventDataType m_miny,m_maxy;
ChannelID m_code;
QString m_title;
};
class gLayerGroup:public gLayer
{
public:
gLayerGroup();
virtual ~gLayerGroup();
virtual void AddLayer(gLayer *l);
virtual qint64 Minx();
virtual qint64 Maxx();
virtual EventDataType Miny();
virtual EventDataType Maxy();
virtual bool isEmpty();
virtual void SetDay(Day * d);
protected:
QVector<gLayer *> layers;
};
#endif // GRAPHLAYER_H

File diff suppressed because it is too large Load Diff

View File

@ -1,171 +0,0 @@
/*
gGraphWindow Headers
Copyright (c)2011 Mark Watkins <jedimark@users.sourceforge.net>
License: GPL
*/
#ifndef GRAPHWINDOW_H
#define GRAPHWINDOW_H
#include<QVBoxLayout>
#include <QGLContext>
#include <QGLWidget>
#include <QSplitter>
#include <QDateTime>
#include <QList>
using namespace std;
#include "graphlayer.h"
#include "glcommon.h"
#define MIN(a,b) (((a)<(b)) ? (a) : (b));
#define MAX(a,b) (((a)<(b)) ? (b) : (a));
class gLayer;
class gGraphWindow : public QGLWidget
{
Q_OBJECT
public:
//explicit gGraphWindow(QWidget *parent, const QString & title, QGLContext * context,Qt::WindowFlags f=0);
explicit gGraphWindow(QWidget *parent, const QString & title, QGLWidget * shared,Qt::WindowFlags f=0);
virtual ~gGraphWindow();
signals:
public slots:
public:
QBitmap * RenderBitmap(int width,int height);
virtual void paintGL();
virtual void resizeGL(int width, int height);
//virtual void OnMouseWheel(wxMouseEvent &event);
virtual void mouseMoveEvent(QMouseEvent * event);
virtual void mousePressEvent(QMouseEvent * event);
virtual void mouseReleaseEvent(QMouseEvent * event);
virtual void mouseDoubleClickEvent(QMouseEvent * event);
virtual void keyPressEvent(QKeyEvent * event);
//virtual void OnMouseRightDClick(wxMouseEvent * event);
virtual void OnMouseLeftDown(QMouseEvent * event);
virtual void OnMouseLeftRelease (QMouseEvent * event);
virtual void OnMouseRightDown(QMouseEvent * event);
virtual void OnMouseRightRelease(QMouseEvent * event);
int GetScrX(void) const { return m_scrX; }
int GetScrY(void) const { return m_scrY; }
// For mouse to screen use only.. work in OpenGL points where possible
const QString & Title(void ) { return m_title; }
void SetMargins(int top, int right, int bottom, int left); // OpenGL width of each corners margin
int GetTopMargin(void) const { return m_marginTop; }
int GetBottomMargin(void) const { return m_marginBottom; }
int GetLeftMargin(void) const { return m_marginLeft; }
int GetRightMargin(void) const { return m_marginRight; }
void SetTopMargin(int i) { m_marginTop=i; }
void SetBottomMargin(int i) { m_marginBottom=i; }
void SetLeftMargin(int i) { m_marginLeft=i; }
void SetRightMargin(int i) { m_marginRight=i; }
inline int Width() { return m_scrX-m_marginLeft-m_marginRight; } // Width of OpenGL main drawing area
inline int Height() { return m_scrY-m_marginTop-m_marginBottom; } // Height of ""...
void LinkZoom(gGraphWindow *g) { link_zoom.push_back(g); } // Linking graphs changes zoom behaviour..
virtual qint64 MinX();
virtual qint64 MaxX();
virtual EventDataType MinY();
virtual EventDataType MaxY();
virtual void SetMinX(qint64 v);
virtual void SetMaxX(qint64 v);
virtual void SetMinY(EventDataType v);
virtual void SetMaxY(EventDataType v);
virtual void ResetBounds();
virtual void SetXBounds(qint64 minx, qint64 maxx);
virtual void ZoomX(double mult,int origin_px);
virtual void ZoomXPixels(int x1, int x2); // Zoom between two selected points on screen
virtual void ZoomXPixels(int x1,int x2,qint64 &rx1,qint64 &rx2);
virtual void MoveX(int i); // Move x bounds by i Pixels
virtual void MoveX(int i,qint64 &min, qint64 & max);
inline int x2p(qint64 x) {
double xx=max_x-min_x;
double wid=Width();
double w=((wid/xx)*double(x-min_x));
return w+GetLeftMargin();
}
inline qint64 p2x(int px) {
double xx=max_x-min_x;
double wx=px-GetLeftMargin();
double ww=wx/Width();
return min_x+(xx*ww);
}
inline int y2p(EventDataType y) {
double yy=max_y-min_y;
double h=(Height()/yy)*double(y-min_y);
return h+GetBottomMargin();
}
inline EventDataType p2y(int py) {
double yy=max_y-min_y;
double hy=py-GetBottomMargin();
double hh=hy/Height();
return min_y+(yy*hh);
}
void Render(int scrx,int scry);
void AddLayer(gLayer *l);
qint64 max_x,min_x,max_y,min_y;
qint64 rmax_x,rmin_x,rmax_y,rmin_y;
void SetBlockZoom(bool b) { m_block_zoom=b; }
bool BlockZoom() { return m_block_zoom; }
QGLContext *gl_context;
void SetGradientBackground(bool b) { m_gradient_background=b; }
bool GradientBackground() { return m_gradient_background; }
bool isEmpty();
void SetSplitter(QVBoxLayout *s) { splitter=s; }
bool isDraggingGraph() { return m_dragGraph; }
void setScry(int h) { m_scrY=h; }
protected:
void updateSelectionTime(qint64 span);
//virtual void resizeEvent(QResizeEvent *);
void initializeGL();
QVBoxLayout *splitter;
QList<gGraphWindow *>link_zoom;
bool m_block_zoom;
bool m_drag_foobar;
bool m_dragGraph;
double m_foobar_pos,m_foobar_moved;
bool m_gradient_background;
QList<gLayer *> layers;
QString m_title;
int m_scrX;
int m_scrY;
QPoint m_mouseLClick,m_mouseRClick,m_mouseRClick_start;
int m_marginTop, m_marginRight, m_marginBottom, m_marginLeft;
QRect m_mouseRBrect,m_mouseRBlast;
bool m_mouseLDown,m_mouseRDown,m_datarefresh;
gLayer *foobar;
gLayer *xaxis;
gLayer *yaxis;
gLayer *gtitle;
QDateTime ti;
gLayer *lastlayer;
};
#endif // GRAPHWINDOW_H

View File

@ -26,12 +26,7 @@ public:
void AddWaveform(qint64 start, unsigned char * data, int recs, qint64 duration);
void AddWaveform(qint64 start, char * data, int recs, qint64 duration);
inline const int & count() {
if (m_count>m_data.size()) {
int i=0;
}
return m_count;
}
inline const int & count() { return m_count; }
void setCount(int count) { m_count=count; }
inline EventStoreType raw(int i) { return m_data[i]; }

View File

@ -40,8 +40,6 @@ SOURCES += main.cpp\
SleepLib/event.cpp \
SleepLib/session.cpp \
SleepLib/day.cpp \
Graphs/graphwindow.cpp \
Graphs/graphlayer.cpp \
Graphs/gLineChart.cpp \
Graphs/gLineOverlay.cpp \
Graphs/gFooBar.cpp \
@ -49,12 +47,10 @@ SOURCES += main.cpp\
Graphs/gYAxis.cpp \
Graphs/gFlagsLine.cpp \
Graphs/glcommon.cpp \
Graphs/gTitle.cpp \
Graphs/gBarChart.cpp \
Graphs/gSegmentChart.cpp \
Graphs/gSessionTime.cpp \
qextserialport/qextserialport.cpp \
Graphs/gSplitter.cpp \
preferencesdialog.cpp \
Graphs/gGraphView.cpp \
Graphs/gStatsLine.cpp
@ -89,8 +85,6 @@ HEADERS += \
SleepLib/machine_common.h \
SleepLib/session.h \
SleepLib/day.h \
Graphs/graphwindow.h \
Graphs/graphlayer.h \
Graphs/gLineChart.h \
Graphs/gLineOverlay.h \
Graphs/gFooBar.h \
@ -98,7 +92,6 @@ HEADERS += \
Graphs/gYAxis.h \
Graphs/gFlagsLine.h \
Graphs/glcommon.h \
Graphs/gTitle.h \
Graphs/gBarChart.h \
Graphs/gSegmentChart.h\
Graphs/gSessionTime.h \
@ -107,7 +100,6 @@ HEADERS += \
qextserialport/qextserialport_global.h \
qextserialport/qextserialport.h \
qextserialport/qextserialenumerator.h \
Graphs/gSplitter.h \
preferencesdialog.h \
Graphs/gGraphView.h \
Graphs/gStatsLine.h

View File

@ -59,7 +59,7 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
ui->graphMainArea->setAutoFillBackground(false);
GraphView=new gGraphView(ui->graphMainArea);
GraphView=new gGraphView(ui->graphMainArea,shared);
GraphView->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
scrollbar=new MyScrollBar(ui->graphMainArea);
@ -574,12 +574,6 @@ Daily::~Daily()
delete ui;
}
void Daily::resizeEvent (QResizeEvent * event)
{
//const QSize &size=event->size();
// splitter->setMinimumWidth(size.width()-280);
}
void Daily::ReloadGraphs()
{
QDate d=profile->LastDay();
@ -757,8 +751,8 @@ void Daily::Load(QDate date)
"<body leftmargin=0 rightmargin=0 topmargin=0 marginwidth=0 marginheight=0>"
"<table cellspacing=0 cellpadding=2 border=0 width='100%'>\n";
QString tmp;
const int gwwidth=240;
const int gwheight=100;
//const int gwwidth=240;
//const int gwheight=100;
UpdateOXIGraphs(oxi);
UpdateCPAPGraphs(cpap);
UpdateEventsTree(ui->treeWidget,cpap);
@ -781,7 +775,7 @@ void Daily::Load(QDate date)
//RedrawGraphs();
QString epr,modestr;
float iap90,eap90;
//float iap90,eap90;
CPAPMode mode=MODE_UNKNOWN;
PRTypes pr;
QString a;
@ -1116,6 +1110,7 @@ Session * Daily::GetJournalSession(QDate date) // Get the first journal session
}
void Daily::on_EnergySlider_sliderMoved(int position)
{
position=position;
//Session *s=GetJournalSession(previous_date);
//if (!s)
// s=CreateJournalSession(previous_date);

View File

@ -12,6 +12,7 @@
#include <QAction>
#include <QWidget>
#include <QTreeWidget>
#include <QHBoxLayout>
#include <QLabel>
#include <QtOpenGL/QGLContext>
#include <QScrollBar>
@ -58,7 +59,6 @@ private slots:
void on_JournalNotesUnderline_clicked();
void ShowHideGraphs();
protected:
virtual void resizeEvent (QResizeEvent * event);
private:
Session * CreateJournalSession(QDate date);

View File

@ -275,7 +275,7 @@ void Oximetry::on_RunButton_toggled(bool checked)
//CONTROL->ResetBounds();
qint64 d=session->length();
// qint64 d=session->length();
// if (d<=30000)
// return;
if (ev_pulse->count()>1 && (ev_spo2->count()>1))
@ -437,8 +437,6 @@ void Oximetry::onReadyRead()
port->read(bytes.data(), bytes.size());
int i=0;
bool redraw_pulse,redraw_spo2;
redraw_pulse=redraw_spo2=false;
while (i<bytes.size()) {
if (bytes[i]&0x80) {
EventDataType d=bytes[i+1] & 0x7f;
@ -446,8 +444,8 @@ void Oximetry::onReadyRead()
//qDebug() << d;
i+=3;
} else {
if (UpdatePulse(bytes[i])) redraw_pulse=true;
if (UpdateSPO2(bytes[i+1])) redraw_spo2=true;
UpdatePulse(bytes[i]);
UpdateSPO2(bytes[i+1]);
i+=2;
}
}
@ -455,12 +453,7 @@ void Oximetry::onReadyRead()
if ((ev_plethy->count()<=2) || (ev_pulse->count()<=2) || (ev_spo2->count()<=2)) {
GraphView->updateScale();
}
GraphView->updateGL(); // damn...
/*PLETHY->updateGL();
if (redraw_pulse)
PULSE->updateGL();
if (redraw_spo2)
SPO2->updateGL(); */
GraphView->updateGL();
}
void Oximetry::onDsrChanged(bool status) // Doesn't work for CMS50's

View File

@ -9,7 +9,7 @@
#include <QWidget>
#include <QGLContext>
#include <QHBoxLayout>
#include <QSplitter>
#include <qextserialport/qextserialport.h>