玉兔远程控制 0.1.0-alpha.2
载入中...
搜索中...
未找到
Stats.cpp
1// Author: Kang Lin <kl222@126.com>
2#include "Stats.h"
3
4CStats::CStats(CParameterOperate *parent, const QString &szPrefix)
5 : CParameterOperate{parent}
6 , m_tmInterval(1)
7 , m_lastTime(QDateTime::currentDateTime())
8 , m_dbSendRate(0)
9 , m_dbReceiveRate(0)
10{
11 SetInterval();
12}
13
14QString CStats::Convertbytes(quint64 bytes)
15{
16 QString szBytes;
17 if(1024 >= bytes)
18 szBytes = QString::number(bytes) + " " + tr("B");
19 else if(1024* 1024 >= bytes)
20 szBytes = QString::number(bytes / 1024.0, 'f', 2) + " " + tr("KB");
21 else if(1024 * 1024 * 1024 >= bytes)
22 szBytes = QString::number(bytes / (1024.0 * 1024.0), 'f', 2) + " " + tr("MB");
23 else
24 szBytes = QString::number(bytes / (1024.0 * 1024.0 * 1024.0), 'f', 2) + " " + tr(" GB");
25 return szBytes;
26}
27
28QString CStats::TotalSends()
29{
30 return Convertbytes(GetTotalSends());
31}
32
33QString CStats::TotalReceives()
34{
35 return Convertbytes(GetTotalReceives());
36}
37
38quint64 CStats::GetTotalSends()
39{
40 return m_TotalSends;
41}
42
43quint64 CStats::GetTotalReceives()
44{
45 return m_TotalReceives;
46}
47
48void CStats::AddSends(quint64 size)
49{
50 m_TotalSends += size;
51}
52
53void CStats::AddReceives(quint64 size)
54{
55 m_TotalReceives += size;
56}
57
58QString CStats::SendRate()
59{
60 return Convertbytes(GetSendRate()) + "/" + tr("S");
61}
62
63QString CStats::ReceiveRate()
64{
65 return Convertbytes(GetReceiveRate()) + "/" + tr("S");
66}
67
69{
70 return m_dbSendRate;
71}
72
73double CStats::GetReceiveRate()
74{
75 return m_dbReceiveRate;
76}
77
79{
80 return m_tmInterval;
81}
82
83int CStats::SetInterval(int interval)
84{
85 if(m_tmInterval == interval)
86 return m_tmInterval;
87 int old = interval;
88 m_tmInterval = interval;
89 SetModified(true);
90 return old;
91}
92
93void CStats::slotCalculating()
94{
95 if(m_lastTime.secsTo(QDateTime::currentDateTime()) < m_tmInterval)
96 return;
97
98 m_dbSendRate = (double)(m_TotalSends - m_lastSends) / (double)m_tmInterval;
99 m_lastSends = m_TotalSends;
100 m_dbReceiveRate = (double)(m_TotalReceives - m_lastReceives) / (double)m_tmInterval;
101 m_lastReceives = m_TotalReceives;
102}
103
104int CStats::OnLoad(QSettings &set)
105{
106 return 0;
107}
108
109int CStats::OnSave(QSettings &set)
110{
111 return 0;
112}
操作参数接口。仅在插件内有效。
int SetModified(bool bModified=true)
在设置参数时,如果有修改,则调用。
int SetInterval(int interval=5)
Set interval.
Definition Stats.cpp:83
virtual double GetSendRate()
Send rate.
Definition Stats.cpp:68
int GetInterval()
Get interval.
Definition Stats.cpp:78