From b046bb907d119e098f9c8b88327b6e2234f96f73 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Fri, 28 Oct 2011 15:12:19 +1000 Subject: [PATCH] Made each Graph a QObject for individual timers. Fixes overview highlighter bug, but slows things a bit :( --- Graphs/gGraphView.cpp | 43 ++++++++++++++++++++++++++++++++++++++-- Graphs/gGraphView.h | 14 ++++++++++++- Graphs/gSummaryChart.cpp | 22 +++++++++++++------- Graphs/gSummaryChart.h | 25 +++-------------------- Graphs/gYAxis.h | 8 +++++++- 5 files changed, 79 insertions(+), 33 deletions(-) diff --git a/Graphs/gGraphView.cpp b/Graphs/gGraphView.cpp index 5b9d5c19..f4d1a385 100644 --- a/Graphs/gGraphView.cpp +++ b/Graphs/gGraphView.cpp @@ -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;istop(); + 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::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() { diff --git a/Graphs/gGraphView.h b/Graphs/gGraphView.h index ddb36cf9..8190dc06 100644 --- a/Graphs/gGraphView.h +++ b/Graphs/gGraphView.h @@ -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; } diff --git a/Graphs/gSummaryChart.cpp b/Graphs/gSummaryChart.cpp index fa695982..e26f3e47 100644 --- a/Graphs/gSummaryChart.cpp +++ b/Graphs/gSummaryChart.cpp @@ -56,7 +56,6 @@ void SummaryChart::SetDay(Day * nullday) if (!m_minx || ttm_maxx) m_maxx=tt; - total=0; bool fnd=false; for (int j=0;jTrigger(2000); + QHash >::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; diff --git a/Graphs/gSummaryChart.h b/Graphs/gSummaryChart.h index 301d5b29..66c3de48 100644 --- a/Graphs/gSummaryChart.h +++ b/Graphs/gSummaryChart.h @@ -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 diff --git a/Graphs/gYAxis.h b/Graphs/gYAxis.h index 924b3358..834634d3 100644 --- a/Graphs/gYAxis.h +++ b/Graphs/gYAxis.h @@ -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) + } };