Made each Graph a QObject for individual timers. Fixes overview highlighter bug, but slows things a bit :(

This commit is contained in:
Mark Watkins 2011-10-28 15:12:19 +10:00
parent b4a59896aa
commit b046bb907d
5 changed files with 79 additions and 33 deletions

View File

@ -833,7 +833,12 @@ gGraph::gGraph(gGraphView *graphview,QString title,int height,short group) :
m_quad->forceAntiAlias(true);
f_miny=f_maxy=0;
m_forceMinY=m_forceMaxY=false;
timer=new QTimer(graphview);
connect(timer,SIGNAL(timeout()),SLOT(Timeout()));
}
//gGraph::gGraph()
//{
//}
gGraph::~gGraph()
{
for (int i=0;i<m_layers.size();i++) {
@ -842,8 +847,29 @@ gGraph::~gGraph()
}
m_layers.clear();
delete m_quad;
timer->stop();
disconnect(timer,0,0,0);
delete timer;
}
void gGraph::Trigger(int ms)
{
if (timer->isActive()) timer->stop();
timer->setSingleShot(true);
timer->start(ms);
}
void gGraph::Timeout()
{
deselect();
m_graphview->timedRedraw(0);
}
void gGraph::deselect()
{
for (QVector<Layer *>::iterator l=m_layers.begin();l!=m_layers.end();l++) {
(*l)->deselect();
}
}
bool gGraph::isEmpty()
{
bool empty=true;
@ -1030,7 +1056,10 @@ void gGraph::AddLayer(Layer * l,LayerPosition position, short width, short heigh
m_layers.push_back(l);
}
void gGraph::redraw() { m_graphview->updateGL(); }
void gGraph::timedRedraw(int ms) { m_graphview->timedRedraw(ms); }
void gGraph::timedRedraw(int ms)
{
m_graphview->timedRedraw(ms);
}
void gGraph::mouseMoveEvent(QMouseEvent * event)
{
@ -1577,6 +1606,9 @@ gGraphView::gGraphView(QWidget *parent, gGraphView * shared) :
quads->forceAntiAlias(true);
setFocusPolicy(Qt::StrongFocus);
m_showsplitter=true;
timer=new QTimer(this);
connect(timer,SIGNAL(timeout()),SLOT(TimedRefresh()));
}
gGraphView::~gGraphView()
{
@ -1595,6 +1627,9 @@ gGraphView::~gGraphView()
if (m_scrollbar) {
this->disconnect(SIGNAL(sliderMoved(int)),this);
}
disconnect(timer,0,0,0);
timer->stop();
delete timer;
}
void gGraphView::DrawTextQue()
{
@ -2309,7 +2344,11 @@ void gGraphView::TimedRefresh()
}
void gGraphView::timedRedraw(int ms)
{
QTimer::singleShot(ms,this,SLOT(TimedRefresh()));
if (timer->isActive())
timer->stop();
timer->setSingleShot(true);
timer->start(ms);
//QTimer::singleShot(ms,this,SLOT(TimedRefresh()));
}
void gGraphView::resetLayout()
{

View File

@ -134,6 +134,8 @@ public:
const ChannelID & code() { return m_code; }
virtual bool isEmpty();
virtual void deselect() { }
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; }
@ -250,13 +252,17 @@ protected slots:
void timerDone();
};
class gGraph
class gGraph:public QObject
{
Q_OBJECT
public:
friend class gGraphView;
//gGraph();
gGraph(gGraphView * graphview=NULL, QString title="",int height=100,short group=0);
virtual ~gGraph();
void deselect();
void Trigger(int ms);
void setVisible(bool b) { m_visible=b; }
bool visible() { return m_visible; }
@ -328,6 +334,7 @@ public:
short left,right,top,bottom; // dirty magin hacks..
QRect m_lastbounds;
QTimer * timer;
protected:
//void invalidate();
@ -359,6 +366,10 @@ protected:
Day * m_day;
GLBuffer * m_quad;
bool m_forceMinY,m_forceMaxY;
signals:
protected slots:
void Timeout();
};
class gGraphView : public QGLWidget
@ -391,6 +402,7 @@ public:
gGraph *m_selected_graph;
gToolTip * m_tooltip;
QTimer * timer;
void AddTextQue(QString & text, short x, short y, float angle=0.0, QColor color=Qt::black, QFont * font=defaultfont);
int horizTravel() { return m_horiz_travel; }

View File

@ -56,7 +56,6 @@ void SummaryChart::SetDay(Day * nullday)
if (!m_minx || tt<m_minx) m_minx=tt;
if (!m_maxx || tt>m_maxx) m_maxx=tt;
total=0;
bool fnd=false;
for (int j=0;j<m_codes.size();j++) {
@ -428,10 +427,12 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event)
{
hl_day=zd;
graph->Trigger(2000);
QHash<int,QHash<short,EventDataType> >::iterator d=m_values.find(hl_day);
x+=gYAxis::Margin+gGraphView::titleWidth; //graph->m_marginleft+
int y=event->y()+rtop-15;
QDateTime dt1=QDateTime::fromTime_t(hl_day*86400).toLocalTime();
//QDateTime dt1=QDateTime::fromTime_t(hl_day*86400).toLocalTime();
QDateTime dt2=QDateTime::fromTime_t(hl_day*86400).toUTC();
//QTime t1=dt1.time();
@ -488,8 +489,11 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event)
} else {
QString z=dt.toString(Qt::SystemLocaleShortDate)+"\r\nNo Data";
graph->ToolTip(z,x,y-10,2200);
return true;
}
}
return false;
}
@ -505,7 +509,9 @@ bool SummaryChart::mousePressEvent(QMouseEvent * event)
bool SummaryChart::keyPressEvent(QKeyEvent * event)
{
Q_UNUSED(event)
//qDebug() << "Summarychart Keypress";
return false;
}
#include "mainwindow.h"
@ -513,11 +519,13 @@ extern MainWindow *mainwin;
bool SummaryChart::mouseReleaseEvent(QMouseEvent * event)
{
if (event->modifiers() & Qt::ShiftModifier) {
QDateTime d=QDateTime::fromTime_t(hl_day*86400).toUTC();
mainwin->getDaily()->LoadDate(d.date());
mainwin->JumpDaily();
//qDebug() << "Jump to daily view?" << d;
return true;
if (hl_day>0) {
QDateTime d=QDateTime::fromTime_t(hl_day*86400).toUTC();
mainwin->getDaily()->LoadDate(d.date());
mainwin->JumpDaily();
//qDebug() << "Jump to daily view?" << d;
return true;
}
}
Q_UNUSED(event)
hl_day=-1;

View File

@ -23,7 +23,9 @@ class SummaryChart:public Layer
virtual void SetDay(Day * day=NULL);
virtual bool isEmpty() { return m_empty; }
void addSlice(ChannelID code, QColor color, SummaryType type) { m_codes.push_back(code); m_colors.push_back(color); m_type.push_back(type); }
void deselect() { hl_day=-1; }
virtual void deselect() {
hl_day=-1;
}
void setMachineType(MachineType type) { m_machinetype=type; }
MachineType machineType() { return m_machinetype; }
protected:
@ -56,28 +58,7 @@ class SummaryChart:public Layer
virtual bool mouseMoveEvent(QMouseEvent * event);
virtual bool mousePressEvent(QMouseEvent * event);
virtual bool mouseReleaseEvent(QMouseEvent * event);
};
/*
class AHIChart:public gBarChart
{
public:
AHIChart(Profile *profile);
virtual void SetDay(Day * day);
};
class UsageChart:public gBarChart
{
public:
UsageChart(Profile *profile);
virtual void SetDay(Day * day);
};
class AvgChart:public gBarChart
{
public:
AvgChart(Profile *profile);
virtual void SetDay(Day * day);
};*/
#endif // GBARCHART_H

View File

@ -13,7 +13,13 @@ class gYSpacer:public Layer
{
public:
gYSpacer(int spacer=20);
virtual void paint(gGraph & w,int left,int top, int width, int height) {w=w; left=left; top=top; width=width; height=height; }
virtual void paint(gGraph & w,int left,int top, int width, int height) {
Q_UNUSED(w)
Q_UNUSED(left)
Q_UNUSED(top)
Q_UNUSED(width)
Q_UNUSED(height)
}
};