mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-09-28 22:59:38 -04:00
improved RSGraph class. Used it for Turtle statistics and bandwidth statistics as well
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7612 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
bd96859704
commit
8c1bf3cf8d
16 changed files with 267 additions and 145 deletions
|
@ -20,6 +20,7 @@
|
|||
****************************************************************/
|
||||
|
||||
#include "BwCtrlWindow.h"
|
||||
#include "gui/common/RSGraphWidget.h"
|
||||
#include "ui_BwCtrlWindow.h"
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
|
@ -37,14 +38,21 @@
|
|||
#include <QPainter>
|
||||
#include <limits>
|
||||
|
||||
class BWListDelegate: public QAbstractItemDelegate
|
||||
{
|
||||
public:
|
||||
BWListDelegate(QObject *parent=0);
|
||||
virtual ~BWListDelegate();
|
||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
|
||||
};
|
||||
|
||||
BWListDelegate::BWListDelegate(QObject *parent) : QAbstractItemDelegate(parent)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
BWListDelegate::~BWListDelegate(void)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void BWListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
|
||||
|
@ -163,31 +171,25 @@ QSize BWListDelegate::sizeHint(const QStyleOptionViewItem & /*option*/, const QM
|
|||
return QSize(50,17);
|
||||
}
|
||||
|
||||
|
||||
BwCtrlWindow::BwCtrlWindow(QWidget *parent)
|
||||
: RsAutoUpdatePage(1000,parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
|
||||
BWDelegate = new BWListDelegate();
|
||||
bwTreeWidget->setItemDelegate(BWDelegate);
|
||||
|
||||
/* Set header resize modes and initial section sizes Peer TreeView*/
|
||||
/* Set header resize modes and initial section sizes Peer TreeView*/
|
||||
QHeaderView * _header = bwTreeWidget->header () ;
|
||||
_header->resizeSection ( COLUMN_RSNAME, 170 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
BwCtrlWindow::~BwCtrlWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BwCtrlWindow::updateDisplay()
|
||||
{
|
||||
|
||||
/* do nothing if locked, or not visible */
|
||||
if (RsAutoUpdatePage::eventsLocked() == true)
|
||||
{
|
||||
|
@ -205,12 +207,7 @@ void BwCtrlWindow::updateDisplay()
|
|||
return;
|
||||
}
|
||||
|
||||
RsAutoUpdatePage::lockAllEvents();
|
||||
|
||||
//std::cerr << "BwCtrlWindow::update()" << std::endl;
|
||||
updateBandwidth();
|
||||
|
||||
RsAutoUpdatePage::unlockAllEvents() ;
|
||||
}
|
||||
|
||||
void BwCtrlWindow::updateBandwidth()
|
||||
|
@ -223,7 +220,7 @@ void BwCtrlWindow::updateBandwidth()
|
|||
std::map<RsPeerId, RsConfigDataRates> rateMap;
|
||||
std::map<RsPeerId, RsConfigDataRates>::iterator it;
|
||||
|
||||
rsConfig->getTotalBandwidthRates(totalRates);
|
||||
rsConfig->getTotalBandwidthRates(totalRates);
|
||||
rsConfig->getAllBandwidthRates(rateMap);
|
||||
|
||||
/* insert */
|
||||
|
@ -231,8 +228,6 @@ void BwCtrlWindow::updateBandwidth()
|
|||
peerTreeWidget->addTopLevelItem(item);
|
||||
peerTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
updateGraph(totalRates.mRateIn,totalRates.mRateOut);
|
||||
|
||||
/* do Totals */
|
||||
item -> setData(COLUMN_PEERID, Qt::DisplayRole, tr("TOTALS"));
|
||||
item -> setData(COLUMN_RSNAME, Qt::DisplayRole, tr("Totals"));
|
||||
|
@ -369,10 +364,4 @@ void BwCtrlWindow::updateBandwidth()
|
|||
}
|
||||
}
|
||||
|
||||
/** Adds new data to the graph. */
|
||||
void BwCtrlWindow::updateGraph(qreal bytesRead, qreal bytesWritten)
|
||||
{
|
||||
/* Graph only cares about kilobytes */
|
||||
frmGraph->addPoints(bytesRead/*/1024.0*/, bytesWritten/*/1024.0*/);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
#ifndef RSBWCTRL_WINDOW_H
|
||||
#define RSBWCTRL_WINDOW_H
|
||||
|
||||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
|
@ -22,11 +19,14 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <QAbstractItemDelegate>
|
||||
|
||||
#include "RsAutoUpdatePage.h"
|
||||
#include "gui/common/RSGraphWidget.h"
|
||||
#include "ui_BwCtrlWindow.h"
|
||||
|
||||
// Defines for download list list columns
|
||||
|
@ -48,47 +48,22 @@
|
|||
|
||||
class QModelIndex;
|
||||
class QPainter;
|
||||
class BWListDelegate ;
|
||||
|
||||
class BWListDelegate: public QAbstractItemDelegate {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BWListDelegate(QObject *parent=0);
|
||||
~BWListDelegate();
|
||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
|
||||
|
||||
private:
|
||||
|
||||
public slots:
|
||||
|
||||
signals:
|
||||
};
|
||||
|
||||
class BwCtrlWindow : public RsAutoUpdatePage, public Ui::BwCtrlWindow {
|
||||
class BwCtrlWindow : public RsAutoUpdatePage, public Ui::BwCtrlWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
BwCtrlWindow(QWidget *parent = 0);
|
||||
~BwCtrlWindow();
|
||||
|
||||
void updateBandwidth();
|
||||
void updateBandwidth();
|
||||
|
||||
public slots:
|
||||
virtual void updateDisplay() ;
|
||||
virtual void updateDisplay() ;
|
||||
|
||||
/** Adds new data to the graph */
|
||||
void updateGraph(qreal bytesRead, qreal bytesWritten);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
|
||||
BWListDelegate *BWDelegate;
|
||||
BWListDelegate *BWDelegate;
|
||||
|
||||
};
|
||||
|
||||
#endif // RSBWCTRL_WINDOW_H
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
<widget class="GraphFrame" name="frmGraph">
|
||||
<widget class="BWGraph" name="frmGraph" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
|
@ -99,12 +99,6 @@
|
|||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::NoContextMenu</enum>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -112,9 +106,9 @@
|
|||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>GraphFrame</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>gui/graphframe.h</header>
|
||||
<class>BWGraph</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>gui/statistics/bwgraph.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
|
|
@ -695,10 +695,3 @@ void DhtWindow::getDHTStatus()
|
|||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/** Adds new data to the graph. */
|
||||
void DhtWindow::updateGraph(qreal rsDHT, qreal allDHT)
|
||||
{
|
||||
// ui.frmGraph->addPoints(rsDHT, allDHT);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,8 +42,6 @@ public:
|
|||
public slots:
|
||||
virtual void updateDisplay() ;
|
||||
|
||||
void updateGraph(qreal rsDHT, qreal allDHT);
|
||||
|
||||
protected:
|
||||
//void changeEvent(QEvent *e);
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui {
|
||||
|
|
|
@ -242,7 +242,6 @@ void TurtleRouterStatistics::updateDisplay()
|
|||
//updateTunnelRequests(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
||||
_tst_CW->updateTunnelStatistics(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
||||
_tst_CW->update();
|
||||
updateTunnelGraph();
|
||||
}
|
||||
|
||||
QString TurtleRouterStatistics::getPeerName(const RsPeerId &peer_id)
|
||||
|
@ -355,17 +354,3 @@ void TurtleRouterStatisticsWidget::resizeEvent(QResizeEvent *event)
|
|||
QWidget::resizeEvent(event);
|
||||
update();
|
||||
}
|
||||
|
||||
void TurtleRouterStatistics::updateTunnelGraph()
|
||||
{
|
||||
TurtleTrafficStatisticsInfo info ;
|
||||
rsTurtle->getTrafficStatistics(info) ;
|
||||
|
||||
updateGraph(info.tr_up_Bps,info.tr_dn_Bps,info.data_dn_Bps,info.data_up_Bps,info.unknown_updn_Bps);
|
||||
}
|
||||
|
||||
void TurtleRouterStatistics::updateGraph(qreal bytesTrup, qreal bytesTrdown, qreal bytesDatadown, qreal bytesDataup, qreal bytesunknownupdn)
|
||||
{
|
||||
/* Graph only cares about kilobytes */
|
||||
frmGraph->addPoints(bytesTrup/1024.0, bytesTrdown/1024.0, bytesDatadown/1024.0, bytesDataup/1024.0, bytesunknownupdn/1024.0 );
|
||||
}
|
||||
|
|
|
@ -31,28 +31,23 @@ class TurtleRouterStatisticsWidget ;
|
|||
|
||||
class TurtleRouterStatistics: public RsAutoUpdatePage, public Ui::TurtleRouterStatistics
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TurtleRouterStatistics(QWidget *parent = NULL) ;
|
||||
~TurtleRouterStatistics();
|
||||
|
||||
// Cache for peer names.
|
||||
static QString getPeerName(const RsPeerId& peer_id) ;
|
||||
|
||||
public slots:
|
||||
void updateTunnelGraph();
|
||||
void updateGraph(qreal bytesTrup, qreal bytesTrdown, qreal bytesDatadown, qreal bytesDataup, qreal bytesunknownupdn);
|
||||
public:
|
||||
TurtleRouterStatistics(QWidget *parent = NULL) ;
|
||||
~TurtleRouterStatistics();
|
||||
|
||||
// Cache for peer names.
|
||||
static QString getPeerName(const RsPeerId& peer_id) ;
|
||||
|
||||
private:
|
||||
|
||||
void processSettings(bool bLoad);
|
||||
bool m_bProcessSettings;
|
||||
private:
|
||||
|
||||
virtual void updateDisplay() ;
|
||||
void processSettings(bool bLoad);
|
||||
bool m_bProcessSettings;
|
||||
|
||||
TurtleRouterStatisticsWidget *_tst_CW ;
|
||||
virtual void updateDisplay() ;
|
||||
|
||||
TurtleRouterStatisticsWidget *_tst_CW ;
|
||||
} ;
|
||||
|
||||
class TurtleRouterStatisticsWidget: public QWidget
|
||||
|
|
|
@ -47,8 +47,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>638</width>
|
||||
<height>255</height>
|
||||
<width>640</width>
|
||||
<height>248</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
|
@ -59,7 +59,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="GraphFrameTunnel" name="frmGraph">
|
||||
<widget class="TurtleGraph" name="frmGraph" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
|
@ -74,12 +74,6 @@
|
|||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::NoContextMenu</enum>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -90,9 +84,9 @@
|
|||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>GraphFrameTunnel</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>gui/graphframetunnel.h</header>
|
||||
<class>TurtleGraph</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>gui/statistics/turtlegraph.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
|
45
retroshare-gui/src/gui/statistics/bwgraph.h
Normal file
45
retroshare-gui/src/gui/statistics/bwgraph.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
|
||||
#include "retroshare/rsconfig.h"
|
||||
#include <gui/common/RSGraphWidget.h>
|
||||
|
||||
class BWGraphSource: public RSGraphSource
|
||||
{
|
||||
public:
|
||||
virtual void getValues(std::map<std::string,float>& values) const
|
||||
{
|
||||
RsConfigDataRates totalRates;
|
||||
rsConfig->getTotalBandwidthRates(totalRates);
|
||||
|
||||
values.insert(std::make_pair(std::string("Bytes in"),(float)totalRates.mRateIn)) ;
|
||||
values.insert(std::make_pair(std::string("Bytes out"),(float)totalRates.mRateOut)) ;
|
||||
}
|
||||
|
||||
virtual QString unitName() const { return tr("KB/s"); }
|
||||
};
|
||||
|
||||
class BWGraph: public RSGraphWidget
|
||||
{
|
||||
public:
|
||||
BWGraph(QWidget *parent)
|
||||
: RSGraphWidget(parent)
|
||||
{
|
||||
BWGraphSource *src = new BWGraphSource() ;
|
||||
|
||||
src->setCollectionTimeLimit(30*60*1000) ; // 30 mins
|
||||
src->setCollectionTimePeriod(1000) ; // collect every second
|
||||
src->start() ;
|
||||
|
||||
addSource(src) ;
|
||||
|
||||
setTimeScale(1.0f) ; // 1 pixels per second of time.
|
||||
setScaleParams(2) ;
|
||||
|
||||
resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ;
|
||||
resetFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ;
|
||||
|
||||
setFlags(RSGRAPH_FLAGS_SHOW_LEGEND) ;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -26,26 +26,56 @@
|
|||
#include <QApplication>
|
||||
#include <gui/common/RSGraphWidget.h>
|
||||
|
||||
#define HOR_SPC 2 /** Space between data points */
|
||||
#define SCALE_WIDTH 75 /** Width of the scale */
|
||||
#define MINUSER_SCALE 2000 /** 2000 users is the minimum scale */
|
||||
#define SCROLL_STEP 4 /** Horizontal change on graph update */
|
||||
#include <retroshare/rsdht.h>
|
||||
#include <retroshare/rsconfig.h>
|
||||
#include "dhtgraph.h"
|
||||
|
||||
#define BACK_COLOR Qt::white
|
||||
#define SCALE_COLOR Qt::black
|
||||
#define GRID_COLOR Qt::black
|
||||
#define RSDHT_COLOR Qt::magenta
|
||||
#define ALLDHT_COLOR Qt::yellow
|
||||
class DHTGraphSource: public RSGraphSource
|
||||
{
|
||||
public:
|
||||
virtual int n_values() const
|
||||
{
|
||||
return 1 ;
|
||||
}
|
||||
virtual void getValues(std::map<std::string,float>& values) const
|
||||
{
|
||||
RsConfigNetStatus config;
|
||||
rsConfig->getConfigNetStatus(config);
|
||||
|
||||
if (config.DHTActive && config.netDhtOk)
|
||||
{
|
||||
values.insert(std::make_pair(std::string("RS Net size"),(float)config.netDhtRsNetSize)) ;
|
||||
//values.insert(std::make_pair(std::string("GLobal Net size"),(float)config.netDhtNetSize)) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
values.insert(std::make_pair(std::string("RS Net size"),0.0f)) ;
|
||||
//values.insert(std::make_pair(std::string("GLobal Net size"),0.0f)) ;
|
||||
}
|
||||
}
|
||||
|
||||
virtual QString unitName() const { return tr("users"); }
|
||||
};
|
||||
|
||||
#define FONT_SIZE 11
|
||||
|
||||
class DhtGraph : public RSGraphWidget
|
||||
{
|
||||
public:
|
||||
DhtGraph(QWidget *parent = 0);
|
||||
public:
|
||||
DhtGraph(QWidget *parent = 0)
|
||||
: RSGraphWidget(parent)
|
||||
{
|
||||
DHTGraphSource *src = new DHTGraphSource() ;
|
||||
|
||||
/** Show the respective lines and counters. */
|
||||
bool _showRSDHT;
|
||||
bool _showALLDHT;
|
||||
src->setCollectionTimeLimit(30*60*1000) ; // 30 mins
|
||||
src->setCollectionTimePeriod(1000) ; // collect every second
|
||||
src->start() ;
|
||||
|
||||
addSource(src) ;
|
||||
|
||||
setTimeScale(1.0f) ; // 1 pixels per second of time.
|
||||
setScaleParams(0) ;
|
||||
|
||||
resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ;
|
||||
setFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
54
retroshare-gui/src/gui/statistics/turtlegraph.h
Normal file
54
retroshare-gui/src/gui/statistics/turtlegraph.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#pragma once
|
||||
|
||||
#include "retroshare/rsturtle.h"
|
||||
#include <gui/common/RSGraphWidget.h>
|
||||
|
||||
class TurtleGraphSource: public RSGraphSource
|
||||
{
|
||||
public:
|
||||
virtual void getValues(std::map<std::string,float>& values) const
|
||||
{
|
||||
TurtleTrafficStatisticsInfo info ;
|
||||
rsTurtle->getTrafficStatistics(info) ;
|
||||
|
||||
values.insert(std::make_pair(QObject::tr("TR up").toStdString(),(float)info.tr_up_Bps)) ;
|
||||
values.insert(std::make_pair(QObject::tr("TR dn").toStdString(),(float)info.tr_dn_Bps)) ;
|
||||
values.insert(std::make_pair(QObject::tr("Data up").toStdString(),(float)info.data_up_Bps)) ;
|
||||
values.insert(std::make_pair(QObject::tr("Data dn").toStdString(),(float)info.data_dn_Bps)) ;
|
||||
values.insert(std::make_pair(QObject::tr("Data forward").toStdString(),(float)info.unknown_updn_Bps)) ;
|
||||
}
|
||||
|
||||
virtual QString displayValue(float v) const
|
||||
{
|
||||
if(v < 1000)
|
||||
return QString::number(v,'g',2) + " B/s" ;
|
||||
else if(v < 1000*1024)
|
||||
return QString::number(v/1024.0,'g',2) + " KB/s" ;
|
||||
else
|
||||
return QString::number(v/(1024.0*1024),'g',2) + " MB/s" ;
|
||||
}
|
||||
};
|
||||
|
||||
class TurtleGraph: public RSGraphWidget
|
||||
{
|
||||
public:
|
||||
TurtleGraph(QWidget *parent)
|
||||
: RSGraphWidget(parent)
|
||||
{
|
||||
TurtleGraphSource *src = new TurtleGraphSource() ;
|
||||
|
||||
src->setCollectionTimeLimit(30*60*1000) ; // 30 mins
|
||||
src->setCollectionTimePeriod(1000) ; // collect every second
|
||||
src->start() ;
|
||||
|
||||
addSource(src) ;
|
||||
|
||||
setTimeScale(1.0f) ; // 1 pixels per second of time.
|
||||
setScaleParams(2) ;
|
||||
|
||||
resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ;
|
||||
resetFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue