Browse Source

Merge pull request #5277 from Chocobo1/circular

Minor refactor
adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
57dac8d5f7
  1. 14
      src/base/bittorrent/private/speedmonitor.cpp
  2. 10
      src/base/bittorrent/private/speedmonitor.h
  3. 2
      src/gui/search/searchwidget.cpp

14
src/base/bittorrent/private/speedmonitor.cpp

@ -27,17 +27,21 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include <QList>
#include "speedmonitor.h" #include "speedmonitor.h"
SpeedMonitor::SpeedMonitor()
: m_speedSamples(MAX_SAMPLES)
{
}
void SpeedMonitor::addSample(const SpeedSample &sample) void SpeedMonitor::addSample(const SpeedSample &sample)
{ {
m_speedSamples.push_back(sample); if (m_speedSamples.size() >= MAX_SAMPLES) {
m_sum += sample;
if (m_speedSamples.size() > MAX_SAMPLES) {
m_sum -= m_speedSamples.front(); m_sum -= m_speedSamples.front();
m_speedSamples.pop_front();
} }
m_speedSamples.push_back(sample);
m_sum += sample;
} }
SpeedSampleAvg SpeedMonitor::average() const SpeedSampleAvg SpeedMonitor::average() const

10
src/base/bittorrent/private/speedmonitor.h

@ -30,7 +30,11 @@
#ifndef SPEEDMONITOR_H #ifndef SPEEDMONITOR_H
#define SPEEDMONITOR_H #define SPEEDMONITOR_H
template<typename T> class QList; #ifndef Q_MOC_RUN
#include <boost/circular_buffer.hpp>
#endif
#include <QtGlobal>
template<typename T> template<typename T>
struct Sample struct Sample
@ -71,13 +75,15 @@ typedef Sample<qreal> SpeedSampleAvg;
class SpeedMonitor class SpeedMonitor
{ {
public: public:
SpeedMonitor();
void addSample(const SpeedSample &sample); void addSample(const SpeedSample &sample);
SpeedSampleAvg average() const; SpeedSampleAvg average() const;
void reset(); void reset();
private: private:
static const int MAX_SAMPLES = 30; static const int MAX_SAMPLES = 30;
QList<SpeedSample> m_speedSamples; boost::circular_buffer<SpeedSample> m_speedSamples;
SpeedSample m_sum; SpeedSample m_sum;
}; };

2
src/gui/search/searchwidget.cpp

@ -129,7 +129,7 @@ void SearchWidget::fillCatCombobox()
QList<QStrPair> tmpList; QList<QStrPair> tmpList;
foreach (const QString &cat, m_searchEngine->supportedCategories()) foreach (const QString &cat, m_searchEngine->supportedCategories())
tmpList << qMakePair(SearchEngine::categoryFullName(cat), cat); tmpList << qMakePair(SearchEngine::categoryFullName(cat), cat);
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (l.first < r.first); } ); std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); });
foreach (const QStrPair &p, tmpList) { foreach (const QStrPair &p, tmpList) {
qDebug("Supported category: %s", qPrintable(p.second)); qDebug("Supported category: %s", qPrintable(p.second));

Loading…
Cancel
Save