1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

minor code cleanup

This commit is contained in:
Dubslow 2015-01-18 13:57:51 -06:00
parent 5429e50bd0
commit 44921db440
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
2 changed files with 8 additions and 7 deletions

View File

@ -137,13 +137,14 @@ void FileTransferWidget::onFileTransferInfo(ToxFile file)
qreal bytesPerSec = static_cast<int>(static_cast<qreal>(deltaBytes) / deltaSecs);
// calculate mean
meanData[(meanIndex++) % FTW_MEAN_PERIODES] = bytesPerSec;
meanData[meanIndex] = bytesPerSec;
meanIndex = (meanIndex + 1) % TRANSFER_ROLLING_AVG_COUNT;
qreal meanBytesPerSec = 0.0;
for(size_t i = 0; i < FTW_MEAN_PERIODES; ++i)
for(size_t i = 0; i < TRANSFER_ROLLING_AVG_COUNT; ++i)
meanBytesPerSec += meanData[i];
meanBytesPerSec /= qMin(meanIndex, static_cast<size_t>(FTW_MEAN_PERIODES));
meanBytesPerSec /= qMin(static_cast<size_t>(meanIndex), static_cast<size_t>(TRANSFER_ROLLING_AVG_COUNT));
// update UI
if(meanBytesPerSec > 0)
@ -209,7 +210,7 @@ void FileTransferWidget::onFileTransferPaused(ToxFile file)
// reset mean
meanIndex = 0;
for(size_t i=0; i<FTW_MEAN_PERIODES; ++i)
for(size_t i=0; i<TRANSFER_ROLLING_AVG_COUNT; ++i)
meanData[i] = 0.0;
setStyleSheet(Style::getStylesheet(":/ui/fileTransferInstance/grey.css"));

View File

@ -22,7 +22,6 @@
#include "../chatlinecontent.h"
#include "../../corestructs.h"
#define FTW_MEAN_PERIODES 4
namespace Ui {
class FileTransferWidget;
@ -66,8 +65,9 @@ private:
QTime lastTick;
qint64 lastBytesSent = 0;
qreal meanData[FTW_MEAN_PERIODES] = {0.0};
size_t meanIndex = 0;
static const uint8_t TRANSFER_ROLLING_AVG_COUNT = 4;
uint8_t meanIndex = 0;
qreal meanData[TRANSFER_ROLLING_AVG_COUNT] = {0.0};
};
#endif // FILETRANSFERWIDGET_H