3434
3535SpeedPlotView::SpeedPlotView (QWidget *parent)
3636 : QGraphicsView(parent)
37+ , m_data5Min(MIN5_BUF_SIZE )
38+ , m_data30Min(MIN30_BUF_SIZE )
39+ , m_data6Hour(HOUR6_BUF_SIZE )
3740 , m_viewablePointsCount(MIN5_SEC )
3841 , m_counter30Min(-1 )
3942 , m_counter6Hour(-1 )
@@ -67,26 +70,6 @@ SpeedPlotView::SpeedPlotView(QWidget *parent)
6770 greenPen.setStyle (Qt::DotLine);
6871 m_properties[TRACKER_UP ] = GraphProperties (tr (" Tracker Upload" ), bluePen);
6972 m_properties[TRACKER_DOWN ] = GraphProperties (tr (" Tracker Download" ), greenPen);
70-
71- initBuffers (MIN5_BUF_SIZE , m_xData5Min, m_yData5Min);
72- initBuffers (MIN30_BUF_SIZE , m_xData30Min, m_yData30Min);
73- initBuffers (HOUR6_BUF_SIZE , m_xData6Hour, m_yData6Hour);
74- }
75-
76- void SpeedPlotView::initBuffers (int capacity, boost::circular_buffer<uint> &xBuffer,
77- QMap<SpeedPlotView::GraphID, boost::circular_buffer<int > > &yBuffers)
78- {
79- xBuffer = boost::circular_buffer<uint>(capacity);
80- yBuffers[UP ] = boost::circular_buffer<int >(capacity);
81- yBuffers[DOWN ] = boost::circular_buffer<int >(capacity);
82- yBuffers[PAYLOAD_UP ] = boost::circular_buffer<int >(capacity);
83- yBuffers[PAYLOAD_DOWN ] = boost::circular_buffer<int >(capacity);
84- yBuffers[OVERHEAD_UP ] = boost::circular_buffer<int >(capacity);
85- yBuffers[OVERHEAD_DOWN ] = boost::circular_buffer<int >(capacity);
86- yBuffers[DHT_UP ] = boost::circular_buffer<int >(capacity);
87- yBuffers[DHT_DOWN ] = boost::circular_buffer<int >(capacity);
88- yBuffers[TRACKER_UP ] = boost::circular_buffer<int >(capacity);
89- yBuffers[TRACKER_DOWN ] = boost::circular_buffer<int >(capacity);
9073}
9174
9275void SpeedPlotView::setGraphEnable (GraphID id, bool enable)
@@ -95,35 +78,32 @@ void SpeedPlotView::setGraphEnable(GraphID id, bool enable)
9578 this ->viewport ()->update ();
9679}
9780
98- void SpeedPlotView::pushXPoint (uint x )
81+ void SpeedPlotView::pushPoint (SpeedPlotView::PointData point )
9982{
100- ++m_counter30Min;
101- m_counter30Min %= 3 ;
102- ++m_counter6Hour;
103- m_counter6Hour %= 6 ;
83+ m_counter30Min = (m_counter30Min + 1 ) % 3 ;
84+ m_counter6Hour = (m_counter6Hour + 1 ) % 6 ;
10485
105- m_xData5Min.push_back (x);
106-
107- if (m_counter30Min == 0 )
108- m_xData30Min.push_back (x);
109-
110- if (m_counter6Hour == 0 )
111- m_xData6Hour.push_back (x);
112- }
86+ m_data5Min.push_back (point);
11387
114- void SpeedPlotView::pushYPoint (GraphID id, int y)
115- {
116- m_yData5Min[id].push_back (y);
117-
118- if (m_counter30Min == 0 )
119- m_yData30Min[id].push_back (y);
120- else
121- m_yData30Min[id].back () = (m_yData30Min[id].back () * m_counter30Min + y) / (m_counter30Min + 1 );
88+ if (m_counter30Min == 0 ) {
89+ m_data30Min.push_back (point);
90+ }
91+ else {
92+ m_data30Min.back ().x = (m_data30Min.back ().x * m_counter30Min + point.x ) / (m_counter30Min + 1 );
93+ for (int id = UP ; id < NB_GRAPHS ; ++id) {
94+ m_data30Min.back ().y [id] = (m_data30Min.back ().y [id] * m_counter30Min + point.y [id]) / (m_counter30Min + 1 );
95+ }
96+ }
12297
123- if (m_counter6Hour == 0 )
124- m_yData6Hour[id].push_back (y);
125- else
126- m_yData6Hour[id].back () = (m_yData6Hour[id].back () * m_counter6Hour + y) / (m_counter6Hour + 1 );
98+ if (m_counter6Hour == 0 ) {
99+ m_data6Hour.push_back (point);
100+ }
101+ else {
102+ m_data6Hour.back ().x = (m_data6Hour.back ().x * m_counter6Hour + point.x ) / (m_counter6Hour + 1 );
103+ for (int id = UP ; id < NB_GRAPHS ; ++id) {
104+ m_data6Hour.back ().y [id] = (m_data6Hour.back ().y [id] * m_counter6Hour + point.y [id]) / (m_counter6Hour + 1 );
105+ }
106+ }
127107}
128108
129109void SpeedPlotView::setViewableLastPoints (TimePeriod period)
@@ -156,49 +136,33 @@ void SpeedPlotView::replot()
156136 this ->viewport ()->update ();
157137}
158138
159- boost::circular_buffer<uint > &SpeedPlotView::getCurrentXData ()
139+ boost::circular_buffer<SpeedPlotView::PointData > &SpeedPlotView::getCurrentData ()
160140{
161141 switch (m_period) {
162142 default :
163143 case SpeedPlotView::MIN1 :
164144 case SpeedPlotView::MIN5 :
165- return m_xData5Min ;
145+ return m_data5Min ;
166146 case SpeedPlotView::MIN30 :
167- return m_xData30Min ;
147+ return m_data30Min ;
168148 case SpeedPlotView::HOUR6 :
169- return m_xData6Hour;
170- }
171- }
172-
173- QMap<SpeedPlotView::GraphID, boost::circular_buffer<int > > &SpeedPlotView::getCurrentYData ()
174- {
175- switch (m_period) {
176- default :
177- case SpeedPlotView::MIN1 :
178- case SpeedPlotView::MIN5 :
179- return m_yData5Min;
180- case SpeedPlotView::MIN30 :
181- return m_yData30Min;
182- case SpeedPlotView::HOUR6 :
183- return m_yData6Hour;
149+ return m_data6Hour;
184150 }
185151}
186152
187153int SpeedPlotView::maxYValue ()
188154{
189- QMap<GraphID, boost::circular_buffer<int > > &yData = getCurrentYData ();
155+ boost::circular_buffer<PointData> &queue = getCurrentData ();
190156
191157 int maxYValue = 0 ;
192- for (QMap<GraphID, boost::circular_buffer< int > >::const_iterator it = yData. begin (); it != yData. end () ; ++it ) {
158+ for (int id = UP ; id < NB_GRAPHS ; ++id ) {
193159
194- if (!m_properties[it. key ( )].m_enable )
160+ if (!m_properties[static_cast <GraphID>(id )].m_enable )
195161 continue ;
196162
197- const boost::circular_buffer<int > &queue = it.value ();
198-
199163 for (int i = queue.size () - 1 , j = 0 ; i >= 0 && j <= m_viewablePointsCount; --i, ++j) {
200- if (queue[i] > maxYValue)
201- maxYValue = queue[i];
164+ if (queue[i]. y [id] > maxYValue)
165+ maxYValue = queue[i]. y [id] ;
202166 }
203167 }
204168
@@ -269,25 +233,24 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
269233 double yMultiplier = (maxY == 0 ) ? 0.0 : double (rect.height ()) / maxY;
270234 double xTickSize = double (rect.width ()) / m_viewablePointsCount;
271235
272- QMap<GraphID, boost::circular_buffer<int > > &yData = getCurrentYData ();
236+ boost::circular_buffer<PointData> &queue = getCurrentData ();
273237
274- for (QMap<GraphID, boost::circular_buffer< int > >::const_iterator it = yData. begin (); it != yData. end () ; ++it ) {
238+ for (int id = UP ; id < NB_GRAPHS ; ++id ) {
275239
276- if (!m_properties[it. key ( )].m_enable )
240+ if (!m_properties[static_cast <GraphID>(id )].m_enable )
277241 continue ;
278242
279- const boost::circular_buffer<int > &queue = it.value ();
280243 QVector<QPoint> points;
281244
282245 for (int i = queue.size () - 1 , j = 0 ; i >= 0 && j <= m_viewablePointsCount; --i, ++j) {
283246
284247 int new_x = rect.right () - j * xTickSize;
285- int new_y = rect.bottom () - queue[i] * yMultiplier;
248+ int new_y = rect.bottom () - queue[i]. y [id] * yMultiplier;
286249
287250 points.push_back (QPoint (new_x, new_y));
288251 }
289252
290- painter.setPen (m_properties[it. key ( )].m_pen );
253+ painter.setPen (m_properties[static_cast <GraphID>(id )].m_pen );
291254 painter.drawPolyline (points.data (), points.size ());
292255 }
293256
0 commit comments