mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Added a graphframe to Bandwidth Control Window and Turtle Router Statistics Dialog
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7500 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
6085ccd43f
commit
29a11b021e
@ -239,6 +239,7 @@ 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)
|
||||
@ -306,8 +307,8 @@ void TurtleRouterStatisticsWidget::updateTunnelStatistics(const std::vector<std:
|
||||
oy += celly ;
|
||||
|
||||
painter.drawText(ox,oy+celly,tr("Turtle router traffic")+":") ; oy += celly*2 ;
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("Tunnel requests Up")+"\t: " + speedString(info.tr_up_Bps) ) ; oy += celly ;
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("Tunnel requests Dn")+"\t: " + speedString(info.tr_dn_Bps) ) ; oy += celly ;
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("Tunnel requests Up")+"\t: " + speedString(info.tr_up_Bps) ) ; oy += celly ;
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("Incoming file data")+"\t: " + speedString(info.data_dn_Bps) ) ; oy += celly ;
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("Outgoing file data")+"\t: " + speedString(info.data_up_Bps) ) ; oy += celly ;
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("Forwarded data ")+"\t: " + speedString(info.unknown_updn_Bps) ) ; oy += celly ;
|
||||
@ -351,3 +352,17 @@ 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 );
|
||||
}
|
||||
|
@ -40,6 +40,11 @@ class TurtleRouterStatistics: public RsAutoUpdatePage, public Ui::TurtleRouterSt
|
||||
// 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);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void processSettings(bool bLoad);
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>611</width>
|
||||
<height>408</height>
|
||||
<height>513</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -20,6 +20,9 @@
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QScrollArea" name="_tunnel_statistics_F">
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
@ -35,15 +38,50 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>593</width>
|
||||
<height>390</height>
|
||||
<height>289</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="GraphFrameTunnel" name="frmGraph">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<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>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>GraphFrameTunnel</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>gui/graphframetunnel.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -283,6 +283,9 @@ void BwCtrlWindow::updateBandwidth()
|
||||
/* insert */
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||
peerTreeWidget->addTopLevelItem(item);
|
||||
peerTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
updateGraph(totalRates.mRateIn,totalRates.mRateOut);
|
||||
|
||||
/* do Totals */
|
||||
item -> setData(COLUMN_PEERID, Qt::DisplayRole, tr("TOTALS"));
|
||||
@ -420,5 +423,10 @@ void BwCtrlWindow::updateBandwidth()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Adds new data to the graph. */
|
||||
void BwCtrlWindow::updateGraph(qreal bytesRead, qreal bytesWritten)
|
||||
{
|
||||
/* Graph only cares about kilobytes */
|
||||
ui->frmGraph->addPoints(bytesRead/*/1024.0*/, bytesWritten/*/1024.0*/);
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,8 @@ public:
|
||||
|
||||
public slots:
|
||||
void update();
|
||||
/** Adds new data to the graph */
|
||||
void updateGraph(qreal bytesRead, qreal bytesWritten);
|
||||
|
||||
protected:
|
||||
//void changeEvent(QEvent *e);
|
||||
|
@ -15,74 +15,109 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeWidget" name="bwTreeWidget">
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
<widget class="QTreeWidget" name="bwTreeWidget">
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>ID</string>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>ID</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>In (KB/s)</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>InMax (KB/s)</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>InQueue</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>InAllocated (KB/s)</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Allocated Sent</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Out (KB/s)</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>OutMax (KB/s)</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>OutQueue</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>OutAllowed (KB/s)</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Allowed Recvd</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
<widget class="GraphFrame" name="frmGraph">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>In (KB/s)</string>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>InMax (KB/s)</string>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::NoContextMenu</enum>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>InQueue</string>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>InAllocated (KB/s)</string>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Allocated Sent</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Out (KB/s)</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>OutMax (KB/s)</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>OutQueue</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>OutAllowed (KB/s)</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Allowed Recvd</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>GraphFrame</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>gui/graphframe.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
384
retroshare-gui/src/gui/graphframetunnel.cpp
Normal file
384
retroshare-gui/src/gui/graphframetunnel.cpp
Normal file
@ -0,0 +1,384 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2006-2007, crypton
|
||||
* Copyright (c) 2006, Matt Edman, Justin Hipple
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "graphframetunnel.h"
|
||||
|
||||
|
||||
/** Default contructor */
|
||||
GraphFrameTunnel::GraphFrameTunnel(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
/* Create Graph Frame related objects */
|
||||
_tunnelrequestdownData = new QList<qreal>();
|
||||
_tunnelrequestupData = new QList<qreal>();
|
||||
_incomingfileData = new QList<qreal>();
|
||||
_outgoingfileData = new QList<qreal>();
|
||||
_forwardedData = new QList<qreal>();
|
||||
|
||||
_painter = new QPainter();
|
||||
_graphStyle = SolidLine;
|
||||
|
||||
/* Initialize graph values */
|
||||
_tunnelrequestdownData->prepend(0);
|
||||
_tunnelrequestupData->prepend(0);
|
||||
_incomingfileData->prepend(0);
|
||||
_outgoingfileData->prepend(0);
|
||||
_forwardedData->prepend(0);
|
||||
|
||||
_maxPoints = getNumPoints();
|
||||
_showTrdown = true;
|
||||
_showTrup = true;
|
||||
_showIncoming = true;
|
||||
_showOutgoing = true;
|
||||
_showForwarded = true;
|
||||
_maxValue = MIN_SCALE;
|
||||
}
|
||||
|
||||
/** Default destructor */
|
||||
GraphFrameTunnel::~GraphFrameTunnel()
|
||||
{
|
||||
delete _painter;
|
||||
delete _tunnelrequestdownData;
|
||||
delete _tunnelrequestupData;
|
||||
delete _incomingfileData;
|
||||
delete _outgoingfileData;
|
||||
delete _forwardedData;
|
||||
}
|
||||
|
||||
/** Gets the width of the desktop, which is the maximum number of points
|
||||
* we can plot in the graph. */
|
||||
int
|
||||
GraphFrameTunnel::getNumPoints()
|
||||
{
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
int width = desktop->width();
|
||||
return width;
|
||||
}
|
||||
|
||||
/** Adds new data points to the graph. */
|
||||
void
|
||||
GraphFrameTunnel::addPoints(qreal trup, qreal trdown, qreal datadown,qreal dataup, qreal forwardupdown)
|
||||
{
|
||||
/* If maximum number of points plotted, remove oldest */
|
||||
if (_tunnelrequestupData->size() == _maxPoints) {
|
||||
_tunnelrequestdownData->removeLast();
|
||||
_tunnelrequestupData->removeLast();
|
||||
_incomingfileData->removeLast();
|
||||
_outgoingfileData->removeLast();
|
||||
_forwardedData->removeLast();
|
||||
}
|
||||
|
||||
/* Add the points to their respective lists */
|
||||
_tunnelrequestupData->prepend(trup);
|
||||
_tunnelrequestdownData->prepend(trdown);
|
||||
_incomingfileData->prepend(datadown);
|
||||
_outgoingfileData->prepend(dataup);
|
||||
_forwardedData->prepend(forwardupdown);
|
||||
|
||||
/* Add to the total counters */
|
||||
/* These are not the real total values, but should be close enough. */
|
||||
_totalTrup += GRAPH_REFRESH_RATE * trup / 1000;
|
||||
_totalTrdown += GRAPH_REFRESH_RATE * trdown / 1000;
|
||||
_totalInFileData += GRAPH_REFRESH_RATE * datadown / 1000;
|
||||
_totalOutgoingFileData += GRAPH_REFRESH_RATE * dataup / 1000;
|
||||
_totalForwardedData += GRAPH_REFRESH_RATE * forwardupdown / 1000;
|
||||
|
||||
/* Check for a new maximum value */
|
||||
if (trup > _maxValue) _maxValue = trup;
|
||||
if (trdown > _maxValue) _maxValue = trdown;
|
||||
if (datadown > _maxValue) _maxValue = datadown;
|
||||
if (dataup > _maxValue) _maxValue = dataup;
|
||||
if (forwardupdown > _maxValue) _maxValue = forwardupdown;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
/** Clears the graph. */
|
||||
void
|
||||
GraphFrameTunnel::resetGraph()
|
||||
{
|
||||
_tunnelrequestupData->clear();
|
||||
_tunnelrequestdownData->clear();
|
||||
_incomingfileData->clear();
|
||||
_outgoingfileData->clear();
|
||||
_forwardedData->clear();
|
||||
|
||||
_tunnelrequestdownData->prepend(0);
|
||||
_tunnelrequestupData->prepend(0);
|
||||
_incomingfileData->prepend(0);
|
||||
_outgoingfileData->prepend(0);
|
||||
_forwardedData->prepend(0);
|
||||
|
||||
_maxValue = MIN_SCALE;
|
||||
|
||||
_totalTrup = 0;
|
||||
_totalTrdown = 0;
|
||||
_totalInFileData = 0;
|
||||
_totalOutgoingFileData = 0;
|
||||
_totalForwardedData = 0;
|
||||
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
/** Toggles display of respective graph lines and counters. */
|
||||
void
|
||||
GraphFrameTunnel::setShowCounters(bool showTrdown, bool showTrup, bool showIncoming, bool showOutgoing)
|
||||
{
|
||||
_showTrdown = showTrdown;
|
||||
_showTrup = showTrup;
|
||||
_showIncoming = showIncoming;
|
||||
_showOutgoing = showOutgoing;
|
||||
this->update();
|
||||
}
|
||||
|
||||
/** Overloads default QWidget::paintEvent. Draws the actual
|
||||
* bandwidth graph. */
|
||||
void
|
||||
GraphFrameTunnel::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
/* Set current graph dimensions */
|
||||
_rec = this->frameRect();
|
||||
|
||||
/* Start the painter */
|
||||
_painter->begin(this);
|
||||
|
||||
/* We want antialiased lines and text */
|
||||
_painter->setRenderHint(QPainter::Antialiasing);
|
||||
_painter->setRenderHint(QPainter::TextAntialiasing);
|
||||
|
||||
/* Fill in the background */
|
||||
_painter->fillRect(_rec, QBrush(BACK_COLOR));
|
||||
_painter->drawRect(_rec);
|
||||
|
||||
/* Paint the scale */
|
||||
paintScale();
|
||||
/* Plot the send/receive data */
|
||||
paintData();
|
||||
/* Paint the send/recv totals */
|
||||
paintTotals();
|
||||
|
||||
/* Stop the painter */
|
||||
_painter->end();
|
||||
}
|
||||
|
||||
/** Paints an integral and an outline of that integral for each data set (send
|
||||
* and/or receive) that is to be displayed. The integrals will be drawn first,
|
||||
* followed by the outlines, since we want the area of overlapping integrals
|
||||
* to blend, but not the outlines of those integrals. */
|
||||
void
|
||||
GraphFrameTunnel::paintData()
|
||||
{
|
||||
//QVector<QPointF> recvPoints, sendPoints;
|
||||
QVector<QPointF> trdownPoints, trupPoints, infilePoints, outfilePoints, forwardedPoints;
|
||||
|
||||
/* Convert the bandwidth data points to graph points */
|
||||
trdownPoints = pointsFromData( _tunnelrequestupData);
|
||||
trupPoints = pointsFromData( _tunnelrequestdownData);
|
||||
infilePoints = pointsFromData(_incomingfileData);
|
||||
outfilePoints = pointsFromData(_outgoingfileData);
|
||||
forwardedPoints = pointsFromData(_forwardedData);
|
||||
|
||||
if (_graphStyle == AreaGraph) {
|
||||
/* Plot the bandwidth data as area graphs */
|
||||
if (_showTrdown)
|
||||
paintIntegral(trdownPoints, TRDOWN_COLOR, 0.6);
|
||||
if (_showTrup)
|
||||
paintIntegral(trupPoints, TRUP_COLOR, 0.4);
|
||||
|
||||
paintIntegral(infilePoints, INFILEDATA_COLOR, 0.6);
|
||||
paintIntegral(outfilePoints, OUTFILEDATA_COLOR, 0.4);
|
||||
//paintIntegral(forwardedPoints, FORWARDED_COLOR, 0.6);
|
||||
}
|
||||
|
||||
/* Plot the bandwidth as solid lines. If the graph style is currently an
|
||||
* area graph, we end up outlining the integrals. */
|
||||
if (_showTrdown)
|
||||
paintLine(trdownPoints, TRDOWN_COLOR);
|
||||
if (_showTrup)
|
||||
paintLine(trupPoints, TRUP_COLOR);
|
||||
|
||||
paintLine(infilePoints, INFILEDATA_COLOR);
|
||||
paintLine(outfilePoints, OUTFILEDATA_COLOR);
|
||||
//paintLine(forwardedPoints, FORWARDED_COLOR);
|
||||
}
|
||||
|
||||
/** Returns a list of points on the bandwidth graph based on the supplied set
|
||||
* of send or receive values. */
|
||||
QVector<QPointF>
|
||||
GraphFrameTunnel::pointsFromData(QList<qreal>* list)
|
||||
{
|
||||
QVector<QPointF> points;
|
||||
int x = _rec.width();
|
||||
int y = _rec.height();
|
||||
qreal scale = (y - (y/10)) / _maxValue;
|
||||
qreal currValue;
|
||||
|
||||
/* Translate all data points to points on the graph frame */
|
||||
points << QPointF(x, y);
|
||||
for (int i = 0; i < list->size(); i++) {
|
||||
currValue = y - (list->at(i) * scale);
|
||||
if (x - SCROLL_STEP < SCALE_WIDTH) {
|
||||
points << QPointF(SCALE_WIDTH, currValue);
|
||||
break;
|
||||
}
|
||||
points << QPointF(x, currValue);
|
||||
x -= SCROLL_STEP;
|
||||
}
|
||||
points << QPointF(SCALE_WIDTH, y);
|
||||
return points;
|
||||
}
|
||||
|
||||
/** Plots an integral using the data points in <b>points</b>. The area will be
|
||||
* filled in using <b>color</b> and an alpha-blending level of <b>alpha</b>
|
||||
* (default is opaque). */
|
||||
void
|
||||
GraphFrameTunnel::paintIntegral(QVector<QPointF> points, QColor color, qreal alpha)
|
||||
{
|
||||
/* Save the current brush, plot the integral, and restore the old brush */
|
||||
QBrush oldBrush = _painter->brush();
|
||||
color.setAlphaF(alpha);
|
||||
_painter->setBrush(QBrush(color));
|
||||
_painter->drawPolygon(points.data(), points.size());
|
||||
_painter->setBrush(oldBrush);
|
||||
}
|
||||
|
||||
/** Iterates the input list and draws a line on the graph in the appropriate
|
||||
* color. */
|
||||
void
|
||||
GraphFrameTunnel::paintLine(QVector<QPointF> points, QColor color, Qt::PenStyle lineStyle)
|
||||
{
|
||||
/* Save the current brush, plot the line, and restore the old brush */
|
||||
QPen oldPen = _painter->pen();
|
||||
_painter->setPen(QPen(color, lineStyle));
|
||||
_painter->drawPolyline(points.data(), points.size());
|
||||
_painter->setPen(oldPen);
|
||||
}
|
||||
|
||||
/** Paints selected total indicators on the graph. */
|
||||
void
|
||||
GraphFrameTunnel::paintTotals()
|
||||
{
|
||||
int x = SCALE_WIDTH + FONT_SIZE, y = 0;
|
||||
int rowHeight = FONT_SIZE;
|
||||
|
||||
#if !defined(Q_WS_MAC)
|
||||
/* On Mac, we don't need vertical spacing between the text rows. */
|
||||
rowHeight += 5;
|
||||
#endif
|
||||
|
||||
/* If total received is selected */
|
||||
if (_showTrdown) {
|
||||
y = rowHeight;
|
||||
_painter->setPen(TRDOWN_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Tunnel requests Down: ") + totalToStr(_totalTrdown) +
|
||||
" ("+tr("%1 KB/s").arg(_tunnelrequestdownData->first(), 0, 'f', 2)+")");
|
||||
}
|
||||
|
||||
/* If total sent is selected */
|
||||
if (_showTrup) {
|
||||
y += rowHeight;
|
||||
_painter->setPen(TRUP_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Tunnel requests Up: ") + totalToStr(_totalTrup) +
|
||||
" ("+tr("%1 KB/s").arg(_tunnelrequestupData->first(), 0, 'f', 2)+")");
|
||||
}
|
||||
|
||||
/* If total received is selected */
|
||||
if (_showIncoming) {
|
||||
y += rowHeight;
|
||||
_painter->setPen(INFILEDATA_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Incoming file data: ") + totalToStr(_totalInFileData) +
|
||||
" ("+tr("%1 KB/s").arg(_incomingfileData->first(), 0, 'f', 2)+")");
|
||||
}
|
||||
|
||||
/* If total sent is selected */
|
||||
if (_showOutgoing) {
|
||||
y += rowHeight;
|
||||
_painter->setPen(OUTFILEDATA_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Outgoing file data: ") + totalToStr(_totalOutgoingFileData) +
|
||||
" ("+tr("%1 KB/s").arg(_outgoingfileData->first(), 0, 'f', 2)+")");
|
||||
}
|
||||
|
||||
/* If total sent is selected */
|
||||
/*if (_showForwarded) {
|
||||
y += rowHeight;
|
||||
_painter->setPen(FORWARDED_COLOR);
|
||||
_painter->drawText(x, y,
|
||||
tr("Forwarded data: ") + totalToStr(_totalOutgoingFileData) +
|
||||
" ("+tr("%1 KB/s").arg(_outgoingfileData->first(), 0, 'f', 2)+")");
|
||||
}*/
|
||||
}
|
||||
|
||||
/** Returns a formatted string with the correct size suffix. */
|
||||
QString
|
||||
GraphFrameTunnel::totalToStr(qreal total)
|
||||
{
|
||||
/* Determine the correct size suffix */
|
||||
if (total < 1024) {
|
||||
/* Use KB suffix */
|
||||
return tr("%1 KB").arg(total, 0, 'f', 2);
|
||||
} else if (total < 1048576) {
|
||||
/* Use MB suffix */
|
||||
return tr("%1 MB").arg(total/1024.0, 0, 'f', 2);
|
||||
} else {
|
||||
/* Use GB suffix */
|
||||
return tr("%1 GB").arg(total/1048576.0, 0, 'f', 2);
|
||||
}
|
||||
}
|
||||
|
||||
/** Paints the scale on the graph. */
|
||||
void
|
||||
GraphFrameTunnel::paintScale()
|
||||
{
|
||||
qreal markStep = _maxValue * .25;
|
||||
int top = _rec.y();
|
||||
int bottom = _rec.height();
|
||||
qreal paintStep = (bottom - (bottom/10)) / 4;
|
||||
|
||||
/* Draw the other marks in their correctly scaled locations */
|
||||
qreal scale;
|
||||
qreal pos;
|
||||
for (int i = 1; i < 5; i++) {
|
||||
pos = bottom - (i * paintStep);
|
||||
scale = i * markStep;
|
||||
_painter->setPen(SCALE_COLOR);
|
||||
_painter->drawText(QPointF(5, pos+FONT_SIZE),
|
||||
tr("%1 KB/s").arg(scale, 0, 'f', 2));
|
||||
_painter->setPen(GRID_COLOR);
|
||||
_painter->drawLine(QPointF(SCALE_WIDTH, pos),
|
||||
QPointF(_rec.width(), pos));
|
||||
}
|
||||
|
||||
/* Draw vertical separator */
|
||||
_painter->drawLine(SCALE_WIDTH, top, SCALE_WIDTH, bottom);
|
||||
}
|
||||
|
143
retroshare-gui/src/gui/graphframetunnel.h
Normal file
143
retroshare-gui/src/gui/graphframetunnel.h
Normal file
@ -0,0 +1,143 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2006-2007, crypton
|
||||
* Copyright (c) 2006, Matt Edman, Justin Hipple
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
|
||||
#ifndef _GRAPHFRAMETUNNEL_H
|
||||
#define _GRAPHFRAMETUNNEL_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QFrame>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QList>
|
||||
|
||||
#define HOR_SPC 2 /** Space between data points */
|
||||
#define SCALE_WIDTH 75 /** Width of the scale */
|
||||
#define MIN_SCALE 10 /** 10 kB/s is the minimum scale */
|
||||
#define SCROLL_STEP 4 /** Horizontal change on graph update */
|
||||
|
||||
#define BACK_COLOR Qt::black
|
||||
#define SCALE_COLOR Qt::green
|
||||
#define GRID_COLOR Qt::darkGreen
|
||||
#define TRDOWN_COLOR Qt::cyan
|
||||
#define TRUP_COLOR Qt::yellow
|
||||
#define INFILEDATA_COLOR Qt::magenta
|
||||
#define OUTFILEDATA_COLOR Qt::blue
|
||||
#define FORWARDED_COLOR qt::red
|
||||
|
||||
#define FONT_SIZE 11
|
||||
|
||||
/** Redraw graph every BWGRAPH_REFRESH_RATE ms **/
|
||||
#define GRAPH_REFRESH_RATE 5113
|
||||
|
||||
|
||||
class GraphFrameTunnel : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** Bandwidth graph style. */
|
||||
enum GraphStyle {
|
||||
SolidLine = 0, /**< Plot bandwidth as solid lines. */
|
||||
AreaGraph /**< Plot bandwidth as alpha blended area graphs. */
|
||||
};
|
||||
|
||||
/** Default Constructor */
|
||||
GraphFrameTunnel(QWidget *parent = 0);
|
||||
/** Default Destructor */
|
||||
~GraphFrameTunnel();
|
||||
|
||||
/** Add data points. */
|
||||
void addPoints(qreal trup, qreal trdown, qreal datadown,qreal dataup, qreal forwardupdown );
|
||||
/** Clears the graph. */
|
||||
void resetGraph();
|
||||
/** Toggles display of data counters. */
|
||||
void setShowCounters(bool showTrdown, bool showTrup, bool showIncoming, bool showOutgoing);
|
||||
/** Sets the graph style used to display bandwidth data. */
|
||||
void setGraphStyle(GraphStyle style) { _graphStyle = style; }
|
||||
|
||||
protected:
|
||||
/** Overloaded QWidget::paintEvent() */
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
/** Gets the width of the desktop, the max # of points. */
|
||||
int getNumPoints();
|
||||
|
||||
/** Paints an integral and an outline of that integral for each data set
|
||||
* (send and/or receive) that is to be displayed. */
|
||||
void paintData();
|
||||
/** Paints the send/receive totals. */
|
||||
void paintTotals();
|
||||
/** Paints the scale in the graph. */
|
||||
void paintScale();
|
||||
/** Returns a formatted string representation of total. */
|
||||
QString totalToStr(qreal total);
|
||||
/** Returns a list of points on the bandwidth graph based on the supplied set
|
||||
* of send or receive values. */
|
||||
QVector<QPointF> pointsFromData(QList<qreal>* list);
|
||||
/** Paints a line with the data in <b>points</b>. */
|
||||
void paintLine(QVector<QPointF> points, QColor color,
|
||||
Qt::PenStyle lineStyle = Qt::SolidLine);
|
||||
/** Paints an integral using the supplied data. */
|
||||
void paintIntegral(QVector<QPointF> points, QColor color, qreal alpha = 1.0);
|
||||
|
||||
/** Style with which the bandwidth data will be graphed. */
|
||||
GraphStyle _graphStyle;
|
||||
/** A QPainter object that handles drawing the various graph elements. */
|
||||
QPainter* _painter;
|
||||
/** Holds the tunnel request down data points. */
|
||||
QList<qreal> *_tunnelrequestdownData;
|
||||
/** Holds the tunnel request up data points. */
|
||||
QList<qreal> *_tunnelrequestupData;
|
||||
/** Holds the incoming file data points. */
|
||||
QList<qreal> *_incomingfileData;
|
||||
/** Holds the outgoin file data points. */
|
||||
QList<qreal> *_outgoingfileData;
|
||||
/** Holds the received data points. */
|
||||
QList<qreal> *_forwardedData;
|
||||
|
||||
|
||||
/** The current dimensions of the graph. */
|
||||
QRect _rec;
|
||||
/** The maximum data value plotted. */
|
||||
qreal _maxValue;
|
||||
/** The maximum number of points to store. */
|
||||
int _maxPoints;
|
||||
/** The total data sent/recv. */
|
||||
|
||||
qreal _totalTrup;
|
||||
qreal _totalTrdown;
|
||||
qreal _totalInFileData;
|
||||
qreal _totalOutgoingFileData;
|
||||
qreal _totalForwardedData;
|
||||
|
||||
/** Show the respective lines and counters. */
|
||||
bool _showTrdown;
|
||||
bool _showTrup;
|
||||
bool _showIncoming;
|
||||
bool _showOutgoing;
|
||||
bool _showForwarded;
|
||||
};
|
||||
|
||||
#endif
|
@ -165,39 +165,6 @@ void GlobalRouterStatisticsWidget::updateContent()
|
||||
// draw...
|
||||
int ox=5,oy=5 ;
|
||||
|
||||
painter.setFont(times_f) ;
|
||||
painter.drawText(ox,oy+celly,tr("Pending packets")+":" + QString::number(cache_infos.size())) ; oy += celly*2 ;
|
||||
|
||||
painter.setFont(monospace_f) ;
|
||||
|
||||
static const QString status_string[5] = { "UNKN", "PEND","SENT","ACKN","DEAD" } ;
|
||||
time_t now = time(NULL) ;
|
||||
std::map<QString, std::vector<QString> > tos ;
|
||||
|
||||
for(uint32_t i=0;i<cache_infos.size();++i)
|
||||
{
|
||||
QString packet_string ;
|
||||
packet_string += QString("Id=")+QString::number(cache_infos[i].mid,16) ;
|
||||
packet_string += tr(" by ")+QString::fromStdString(cache_infos[i].local_origin.toStdString()) ;
|
||||
packet_string += tr(" size=")+QString::number(cache_infos[i].data_size) ;
|
||||
packet_string += tr(" Status ")+status_string[cache_infos[i].status % 6] ;
|
||||
packet_string += " "+QString::number(now - cache_infos[i].time_stamp) + tr(" secs ago");
|
||||
|
||||
tos[ QString::fromStdString(cache_infos[i].destination.toStdString()) ].push_back(packet_string) ;
|
||||
}
|
||||
|
||||
for(std::map<QString,std::vector<QString> >::const_iterator it(tos.begin());it!=tos.end();++it)
|
||||
{
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("To: ")+it->first ) ; oy += celly ;
|
||||
|
||||
for(uint32_t i=0;i<it->second.size();++i)
|
||||
{
|
||||
painter.drawText(ox+4*cellx,oy+celly,it->second[i] ) ;
|
||||
oy += celly ;
|
||||
}
|
||||
}
|
||||
|
||||
oy += celly ;
|
||||
|
||||
painter.setFont(times_f) ;
|
||||
painter.drawText(ox,oy+celly,tr("Managed keys")+":" + QString::number(matrix_info.published_keys.size())) ; oy += celly*2 ;
|
||||
@ -248,6 +215,41 @@ void GlobalRouterStatisticsWidget::updateContent()
|
||||
oy += celly ;
|
||||
}
|
||||
|
||||
oy += celly ;
|
||||
|
||||
painter.setFont(times_f) ;
|
||||
painter.drawText(ox,oy+celly,tr("Pending packets")+":" + QString::number(cache_infos.size())) ; oy += celly*2 ;
|
||||
|
||||
painter.setFont(monospace_f) ;
|
||||
|
||||
static const QString status_string[5] = { "UNKN", "PEND","SENT","ACKN","DEAD" } ;
|
||||
time_t now = time(NULL) ;
|
||||
std::map<QString, std::vector<QString> > tos ;
|
||||
|
||||
for(uint32_t i=0;i<cache_infos.size();++i)
|
||||
{
|
||||
QString packet_string ;
|
||||
packet_string += QString("Id=")+QString::number(cache_infos[i].mid,16) ;
|
||||
packet_string += tr(" by ")+QString::fromStdString(cache_infos[i].local_origin.toStdString()) ;
|
||||
packet_string += tr(" size=")+QString::number(cache_infos[i].data_size) ;
|
||||
packet_string += tr(" Status ")+status_string[cache_infos[i].status % 6] ;
|
||||
packet_string += " "+QString::number(now - cache_infos[i].time_stamp) + tr(" secs ago");
|
||||
|
||||
tos[ QString::fromStdString(cache_infos[i].destination.toStdString()) ].push_back(packet_string) ;
|
||||
}
|
||||
|
||||
for(std::map<QString,std::vector<QString> >::const_iterator it(tos.begin());it!=tos.end();++it)
|
||||
{
|
||||
painter.drawText(ox+2*cellx,oy+celly,tr("To: ")+it->first ) ; oy += celly ;
|
||||
|
||||
for(uint32_t i=0;i<it->second.size();++i)
|
||||
{
|
||||
painter.drawText(ox+4*cellx,oy+celly,it->second[i] ) ;
|
||||
oy += celly ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
oy += celly ;
|
||||
oy += celly ;
|
||||
|
||||
|
@ -323,6 +323,7 @@ HEADERS += rshare.h \
|
||||
gui/NetworkDialog.h \
|
||||
gui/GenCertDialog.h \
|
||||
gui/graphframe.h \
|
||||
gui/graphframetunnel.h \
|
||||
gui/linetypes.h \
|
||||
gui/mainpagestack.h \
|
||||
gui/MainWindow.h \
|
||||
@ -657,6 +658,7 @@ SOURCES += main.cpp \
|
||||
gui/GenCertDialog.cpp \
|
||||
gui/NetworkDialog.cpp \
|
||||
gui/graphframe.cpp \
|
||||
gui/graphframetunnel.cpp \
|
||||
gui/mainpagestack.cpp \
|
||||
gui/MainWindow.cpp \
|
||||
gui/NetworkView.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user