1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-02-03 02:14:16 +00:00
qBittorrent/src/gui/properties/speedplotview.h

133 lines
3.5 KiB
C
Raw Normal View History

2014-08-25 15:58:48 +04:00
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Anton Lashkov <lenton_91@mail.ru>
*
* 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.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#pragma once
2014-08-25 15:58:48 +04:00
#ifndef Q_MOC_RUN
#include <boost/circular_buffer.hpp>
#endif
2014-08-25 15:58:48 +04:00
#include <QGraphicsView>
#include <QMap>
2014-08-25 15:58:48 +04:00
class QPen;
class SpeedPlotView final : public QGraphicsView
2014-08-25 15:58:48 +04:00
{
Q_OBJECT
2014-08-25 15:58:48 +04:00
public:
enum GraphID
{
UP = 0,
DOWN,
PAYLOAD_UP,
PAYLOAD_DOWN,
OVERHEAD_UP,
OVERHEAD_DOWN,
DHT_UP,
DHT_DOWN,
TRACKER_UP,
TRACKER_DOWN,
2017-10-26 10:10:30 +03:00
2014-08-25 15:58:48 +04:00
NB_GRAPHS
};
enum TimePeriod
{
MIN1 = 0,
MIN5,
MIN30,
2019-04-17 22:00:17 +07:00
HOUR6,
HOUR12,
HOUR24
2014-08-25 15:58:48 +04:00
};
struct PointData
{
qint64 x;
quint64 y[NB_GRAPHS];
};
explicit SpeedPlotView(QWidget *parent = nullptr);
2015-07-18 19:16:03 +03:00
void setGraphEnable(GraphID id, bool enable);
2019-04-17 22:00:17 +07:00
void setPeriod(TimePeriod period);
2015-07-18 19:16:03 +03:00
void pushPoint(const PointData &point);
2015-07-18 19:16:03 +03:00
void replot();
2014-08-25 15:58:48 +04:00
protected:
2017-10-26 10:10:30 +03:00
void paintEvent(QPaintEvent *event) override;
2014-08-25 15:58:48 +04:00
private:
class Averager
2015-07-18 19:16:03 +03:00
{
public:
Averager(int divider, boost::circular_buffer<PointData> &sink);
void push(const PointData &pointData);
bool isReady() const;
private:
const int m_divider;
boost::circular_buffer<PointData> &m_sink;
int m_counter;
PointData m_accumulator;
};
2014-08-25 15:58:48 +04:00
struct GraphProperties
{
GraphProperties();
2015-07-18 19:16:03 +03:00
GraphProperties(const QString &name, const QPen &pen, bool enable = false);
2014-08-25 15:58:48 +04:00
2016-03-20 12:31:10 +04:00
QString name;
QPen pen;
bool enable;
2014-08-25 15:58:48 +04:00
};
quint64 maxYValue();
2017-10-26 10:10:30 +03:00
boost::circular_buffer<PointData> &getCurrentData();
boost::circular_buffer<PointData> m_data5Min;
boost::circular_buffer<PointData> m_data30Min;
boost::circular_buffer<PointData> m_data6Hour;
2019-04-17 22:00:17 +07:00
boost::circular_buffer<PointData> m_data12Hour;
boost::circular_buffer<PointData> m_data24Hour;
boost::circular_buffer<PointData> *m_currentData;
Averager m_averager30Min;
Averager m_averager6Hour;
2019-04-17 22:00:17 +07:00
Averager m_averager12Hour;
Averager m_averager24Hour;
2015-07-18 19:16:03 +03:00
QMap<GraphID, GraphProperties> m_properties;
2014-08-25 15:58:48 +04:00
TimePeriod m_period;
int m_viewablePointsCount;
2014-08-25 15:58:48 +04:00
};