From 685ddbbf0a70657fd2b6fdc7c642536614b95e4b Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 15 Jul 2015 19:29:41 +0000 Subject: [PATCH] fixed a few bugs in statistics GUI. Still misses names and proper curve display git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8612 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/common/RSGraphWidget.h | 4 +- retroshare-gui/src/gui/statistics/BWGraph.cpp | 85 ++++++++++++++++--- retroshare-gui/src/gui/statistics/BWGraph.h | 2 + .../gui/statistics/BandwidthStatsWidget.cpp | 4 + 4 files changed, 81 insertions(+), 14 deletions(-) diff --git a/retroshare-gui/src/gui/common/RSGraphWidget.h b/retroshare-gui/src/gui/common/RSGraphWidget.h index 227fcd634..c1a32974c 100644 --- a/retroshare-gui/src/gui/common/RSGraphWidget.h +++ b/retroshare-gui/src/gui/common/RSGraphWidget.h @@ -118,7 +118,9 @@ class RSGraphWidget: public QFrame static const uint32_t RSGRAPH_FLAGS_LOG_SCALE_Y = 0x0002 ;// log scale in Y static const uint32_t RSGRAPH_FLAGS_ALWAYS_COLLECT = 0x0004 ;// keep collecting while not displayed static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_PLAIN = 0x0008 ;// use plain / line drawing style - static const uint32_t RSGRAPH_FLAGS_SHOW_LEGEND = 0x0010 ;// show legend in the graph + static const uint32_t RSGRAPH_FLAGS_SHOW_LEGEND = 0x0010 ;// show legend in the graph + static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_FLAT = 0x0020 ;// do not interpolate, and draw flat colored boxes + /** Bandwidth graph style. */ enum GraphStyle { diff --git a/retroshare-gui/src/gui/statistics/BWGraph.cpp b/retroshare-gui/src/gui/statistics/BWGraph.cpp index a7a8ca972..bd7b0e345 100644 --- a/retroshare-gui/src/gui/statistics/BWGraph.cpp +++ b/retroshare-gui/src/gui/statistics/BWGraph.cpp @@ -228,6 +228,23 @@ void BWGraphSource::convertTrafficClueToValues(const std::list& l } } +BWGraphSource::BWGraphSource() + : RSGraphSource() +{ + + _total_sent =0; + _total_recv =0; + + _friend_graph_type = GRAPH_TYPE_SUM; + _service_graph_type = GRAPH_TYPE_SUM; + + _current_selected_friend.clear() ; + _current_selected_service = 0; + _current_unit = UNIT_KILOBYTES; + _current_direction = DIRECTION_UP; + +} + void BWGraphSource::getValues(std::map& values) const { RsConfigDataRates totalRates; @@ -240,16 +257,30 @@ void BWGraphSource::getValues(std::map& values) const _total_recv += 1024 * totalRates.mRateIn * _update_period_msecs/1000.0f ; } -QString BWGraphSource::unitName() const { return tr("KB/s"); } +QString BWGraphSource::unitName() const { return (_current_unit == UNIT_KILOBYTES)?tr("KB/s"):QString(); } QString BWGraphSource::displayValue(float v) const { - if(v < 1000) - return QString::number(v,'f',2) + " B/s" ; - else if(v < 1000*1024) - return QString::number(v/1024.0,'f',2) + " KB/s" ; + if(_current_unit == UNIT_KILOBYTES) + { + if(v < 1000) + return QString::number(v,'f',2) + " B/s" ; + else if(v < 1000*1024) + return QString::number(v/1024.0,'f',2) + " KB/s" ; + else + return QString::number(v/(1024.0*1024),'f',2) + " MB/s" ; + } + else if(_current_unit == UNIT_COUNT) + { + if(v < 1000) + return QString::number(v,'f',0) ; + else if(v < 1000*1024) + return QString::number(v/1024.0,'f',1) + "k" ; + else + return QString::number(v/(1024.0*1024),'f',1) + "M" ; + } else - return QString::number(v/(1024.0*1024),'f',2) + " MB/s" ; + return QString() ; } QString BWGraphSource::legend(int i,float v) const @@ -279,29 +310,57 @@ void BWGraphSource::setSelector(int selector_type,int graph_type,const std::stri if(selector_type == SELECTOR_TYPE_FRIEND && (_friend_graph_type != graph_type || (graph_type == GRAPH_TYPE_SINGLE && selector_client_string != _current_selected_friend.toStdString()))) { - changed = true ; - _friend_graph_type = graph_type ; if(graph_type == GRAPH_TYPE_SINGLE) { RsPeerId ns(selector_client_string) ; if(!ns.isNull()) + { _current_selected_friend = ns ; + changed = true ; + _friend_graph_type = graph_type ; + } + else std::cerr << "(EE) Cannot set current friend to " << selector_client_string << ": unrecognized friend string." << std::endl; } + else + { + changed = true ; + _friend_graph_type = graph_type ; + } } - else if(selector_type == SELECTOR_TYPE_SERVICE && _service_graph_type != graph_type) + else if(selector_type == SELECTOR_TYPE_SERVICE + && (_service_graph_type != graph_type || (graph_type == GRAPH_TYPE_SINGLE && selector_client_string != QString::number(_current_selected_service,16).toStdString()))) { - changed = true ; - _service_graph_type = graph_type ; + if(graph_type == GRAPH_TYPE_SINGLE) + { + bool ok = false ; + int tmp = QString::fromStdString(selector_client_string).toInt() ; + + if(tmp > 0 && tmp < 0x10000) + { + _current_selected_service = tmp ; + + changed = true ; + _service_graph_type = graph_type ; + } + else + std::cerr << "(EE) Cannot set current service to " << selector_client_string << ": unrecognized service string." << std::endl; + + } + else + { + changed = true ; + _service_graph_type = graph_type ; + } } // now re-convert all traffic history into the appropriate curves - if(changed) - recomputeCurrentCurves() ; + if(changed) + recomputeCurrentCurves() ; } void BWGraphSource::setUnit(int unit) { diff --git a/retroshare-gui/src/gui/statistics/BWGraph.h b/retroshare-gui/src/gui/statistics/BWGraph.h index 41b7c5607..ce9f52981 100644 --- a/retroshare-gui/src/gui/statistics/BWGraph.h +++ b/retroshare-gui/src/gui/statistics/BWGraph.h @@ -13,6 +13,8 @@ public: std::list in_rstcl ; }; + BWGraphSource() ; + enum { SELECTOR_TYPE_FRIEND=0x00, SELECTOR_TYPE_SERVICE=0x01 }; enum { GRAPH_TYPE_SINGLE=0x00, GRAPH_TYPE_ALL=0x01, GRAPH_TYPE_SUM=0x02 }; enum { UNIT_KILOBYTES=0x00, UNIT_COUNT=0x01 }; diff --git a/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp b/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp index fef3f12c0..be0349403 100644 --- a/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp +++ b/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp @@ -22,6 +22,10 @@ BandwidthStatsWidget::BandwidthStatsWidget(QWidget *parent) ui.unit_CB->addItem(tr("KB/s")) ; ui.unit_CB->addItem(tr("Count")) ; + ui.bwgraph_BW->source()->setSelector(BWGraphSource::SELECTOR_TYPE_FRIEND,BWGraphSource::GRAPH_TYPE_SUM) ; + ui.bwgraph_BW->source()->setSelector(BWGraphSource::SELECTOR_TYPE_SERVICE,BWGraphSource::GRAPH_TYPE_SUM) ; + ui.bwgraph_BW->source()->setUnit(BWGraphSource::UNIT_KILOBYTES) ; + // Setup connections QObject::connect(ui.friend_CB ,SIGNAL(currentIndexChanged(int)),this, SLOT( updateFriendSelection(int))) ;