Changeset View
Changeset View
Standalone View
Standalone View
src/qt/trafficgraphwidget.cpp
// Copyright (c) 2011-2015 The Bitcoin Core developers | // Copyright (c) 2011-2015 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "trafficgraphwidget.h" | #include "trafficgraphwidget.h" | ||||
#include "clientmodel.h" | #include "clientmodel.h" | ||||
#include "interfaces/node.h" | |||||
#include <QColor> | #include <QColor> | ||||
#include <QPainter> | #include <QPainter> | ||||
#include <QTimer> | #include <QTimer> | ||||
#include <cmath> | #include <cmath> | ||||
#define DESIRED_SAMPLES 800 | #define DESIRED_SAMPLES 800 | ||||
#define XMARGIN 10 | #define XMARGIN 10 | ||||
#define YMARGIN 10 | #define YMARGIN 10 | ||||
TrafficGraphWidget::TrafficGraphWidget(QWidget *parent) | TrafficGraphWidget::TrafficGraphWidget(QWidget *parent) | ||||
: QWidget(parent), timer(0), fMax(0.0f), nMins(0), vSamplesIn(), | : QWidget(parent), timer(0), fMax(0.0f), nMins(0), vSamplesIn(), | ||||
vSamplesOut(), nLastBytesIn(0), nLastBytesOut(0), clientModel(0) { | vSamplesOut(), nLastBytesIn(0), nLastBytesOut(0), clientModel(0) { | ||||
timer = new QTimer(this); | timer = new QTimer(this); | ||||
connect(timer, SIGNAL(timeout()), SLOT(updateRates())); | connect(timer, SIGNAL(timeout()), SLOT(updateRates())); | ||||
} | } | ||||
void TrafficGraphWidget::setClientModel(ClientModel *model) { | void TrafficGraphWidget::setClientModel(ClientModel *model) { | ||||
clientModel = model; | clientModel = model; | ||||
if (model) { | if (model) { | ||||
nLastBytesIn = model->getTotalBytesRecv(); | nLastBytesIn = model->node().getTotalBytesRecv(); | ||||
nLastBytesOut = model->getTotalBytesSent(); | nLastBytesOut = model->node().getTotalBytesSent(); | ||||
} | } | ||||
} | } | ||||
int TrafficGraphWidget::getGraphRangeMins() const { | int TrafficGraphWidget::getGraphRangeMins() const { | ||||
return nMins; | return nMins; | ||||
} | } | ||||
void TrafficGraphWidget::paintPath(QPainterPath &path, QQueue<float> &samples) { | void TrafficGraphWidget::paintPath(QPainterPath &path, QQueue<float> &samples) { | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if (!vSamplesOut.empty()) { | ||||
painter.setPen(Qt::red); | painter.setPen(Qt::red); | ||||
painter.drawPath(p); | painter.drawPath(p); | ||||
} | } | ||||
} | } | ||||
void TrafficGraphWidget::updateRates() { | void TrafficGraphWidget::updateRates() { | ||||
if (!clientModel) return; | if (!clientModel) return; | ||||
quint64 bytesIn = clientModel->getTotalBytesRecv(), | quint64 bytesIn = clientModel->node().getTotalBytesRecv(), | ||||
bytesOut = clientModel->getTotalBytesSent(); | bytesOut = clientModel->node().getTotalBytesSent(); | ||||
float inRate = | float inRate = | ||||
(bytesIn - nLastBytesIn) / 1024.0f * 1000 / timer->interval(); | (bytesIn - nLastBytesIn) / 1024.0f * 1000 / timer->interval(); | ||||
float outRate = | float outRate = | ||||
(bytesOut - nLastBytesOut) / 1024.0f * 1000 / timer->interval(); | (bytesOut - nLastBytesOut) / 1024.0f * 1000 / timer->interval(); | ||||
vSamplesIn.push_front(inRate); | vSamplesIn.push_front(inRate); | ||||
vSamplesOut.push_front(outRate); | vSamplesOut.push_front(outRate); | ||||
nLastBytesIn = bytesIn; | nLastBytesIn = bytesIn; | ||||
nLastBytesOut = bytesOut; | nLastBytesOut = bytesOut; | ||||
Show All 28 Lines | |||||
void TrafficGraphWidget::clear() { | void TrafficGraphWidget::clear() { | ||||
timer->stop(); | timer->stop(); | ||||
vSamplesOut.clear(); | vSamplesOut.clear(); | ||||
vSamplesIn.clear(); | vSamplesIn.clear(); | ||||
fMax = 0.0f; | fMax = 0.0f; | ||||
if (clientModel) { | if (clientModel) { | ||||
nLastBytesIn = clientModel->getTotalBytesRecv(); | nLastBytesIn = clientModel->node().getTotalBytesRecv(); | ||||
nLastBytesOut = clientModel->getTotalBytesSent(); | nLastBytesOut = clientModel->node().getTotalBytesSent(); | ||||
} | } | ||||
timer->start(); | timer->start(); | ||||
} | } |