4Q_DECLARE_METATYPE(CSecurityLevel::Levels)
9 , m_lastTime(QDateTime::currentDateTime())
16QString CStats::Convertbytes(quint64 bytes)
19 if((1 << 10) >= bytes)
20 szBytes = QString::number(bytes) +
" " + tr(
"B");
21 else if((1 << 20) >= bytes)
22 szBytes = QString::number((qreal)bytes / (1 << 10),
'f', 2) +
" " + tr(
"KB");
23 else if((1 << 30) >= bytes)
24 szBytes = QString::number((qreal)bytes / (1 << 20),
'f', 2) +
" " + tr(
"MB");
26 szBytes = QString::number((qreal)bytes / (1 << 30),
'f', 2) +
" " + tr(
"GB");
30QString CStats::TotalSends()
32 return Convertbytes(GetTotalSends());
35QString CStats::TotalReceives()
37 return Convertbytes(GetTotalReceives());
40quint64 CStats::GetTotalSends()
45quint64 CStats::GetTotalReceives()
47 return m_TotalReceives;
50void CStats::AddSends(quint64 size)
57void CStats::AddReceives(quint64 size)
59 m_TotalReceives += size;
60 if(GetReceiveRate() <= 0)
64QString CStats::SendRate()
69QString CStats::ReceiveRate()
71 return Convertbytes(GetReceiveRate()) +
"/" + tr(
"S");
79double CStats::GetReceiveRate()
81 return m_dbReceiveRate;
91 if(m_tmInterval == interval)
94 m_tmInterval = interval;
101 qint64 interval = m_lastTime.msecsTo(QDateTime::currentDateTime());
104 m_dbSendRate = (double)(m_TotalSends - m_lastSends) * 1000 / interval;
105 m_dbReceiveRate = (double)(m_TotalReceives - m_lastReceives) * 1000 / interval;
109 m_lastSends = m_TotalSends;
110 m_lastReceives = m_TotalReceives;
111 m_lastTime = QDateTime::currentDateTime();
115int CStats::OnLoad(QSettings &set)
120int CStats::OnSave(QSettings &set)
125CSecurityLevel::CSecurityLevel(Levels level, QObject* parent)
131CSecurityLevel::~CSecurityLevel()
134CSecurityLevel::Levels CSecurityLevel::GetLevel()
const
139QString CSecurityLevel::GetString()
const
141 return GetString(GetLevel());
144QColor CSecurityLevel::GetColor()
const
146 return GetColor(GetLevel());
149QString CSecurityLevel::GetUnicodeIcon()
const
151 return GetUnicodeIcon(GetLevel());
154QIcon CSecurityLevel::GetIcon()
const
156 return GetIcon(GetLevel());
159QString CSecurityLevel::GetString(
const Levels &level)
162 if(Level::SecureChannel & level) {
163 if(!szSecurity.isEmpty())
165 szSecurity += tr(
"Secure channel");
167 if(Level::Authentication & level) {
168 if(!szSecurity.isEmpty())
170 szSecurity += tr(
"Authentication");
173 if(Level::Proxy & level) {
174 if(!szNormal.isEmpty())
176 szNormal += tr(
"Proxy");
178 if(Level::Gateway & level) {
179 if(!szNormal.isEmpty())
181 szNormal += tr(
"Gateway");
183 if(Level::Redirect & level) {
184 if(!szNormal.isEmpty())
186 szNormal += tr(
"Redirect");
189 if(level & Level::No)
192 if(level == Level::SecureMask)
193 return tr(
"Secure") +
": " + szSecurity;
194 if(Level::SecureMask & level) {
195 QString szMsg = tr(
"Normal") +
": " + szSecurity;
196 if(!szNormal.isEmpty()) {
197 if(!szSecurity.isEmpty())
223QString CSecurityLevel::GetUnicodeIcon(
const Levels &level)
225 if(Level::No & level)
227 if(level == Level::SecureMask)
229 if(Level::SecureMask & level) {
231 if(Level::SecureChannel & level)
233 else if(Level::Authentication & level)
240QColor CSecurityLevel::GetColor(
const Levels &level)
242 if(Level::No & level)
244 if(level == Level::SecureMask)
245 return Qt::GlobalColor::green;
246 if(Level::SecureMask & level)
247 return Qt::GlobalColor::yellow;
248 return Qt::GlobalColor::red;
251QIcon CSecurityLevel::GetIcon(
const Levels &level)
253 if(Level::No & level)
255 if(level == Level::SecureMask)
256 return QIcon::fromTheme(
"lock");
257 if(Level::SecureMask & level)
258 return QIcon::fromTheme(
"dialog-warning");
259 return QIcon::fromTheme(
"unlock");
int SetModified(bool bModified=true)
在设置参数时,如果有修改,则调用。
virtual void slotCalculating()
Calculating
int SetInterval(int interval=1)
Set interval.
void sigDataChanged()
当数据发生变化时触发,用于通知用户实时调用 slotCalculating 进行计算。
virtual double GetSendRate()
Send rate.
int GetInterval()
Get interval.