Skip to content

Commit 5c6b3d5

Browse files
committed
Merge #524: Replace int with std::chrono in for the timer->setInterval() argument
f7a19ef qt,refactor: Use std::chrono in TrafficGraphWidget class (Shashwat) Pull request description: The PR is a follow-up to #517 - It addresses the change suggested in [this](#517 (review)) comment. - This PR changes the type of `msecsPerSample` from **int** to **std::chrono::minutes** and makes other relevant subsequent changes that were limited to the **trafficgraphwidget** file. ACKs for top commit: RandyMcMillan: tACK f7a19ef hebasto: ACK f7a19ef promag: Code review ACK f7a19ef. Tree-SHA512: 5094ba894f3051fc99148cb8f408fc6f9d6571188673dcb7bf24366cdfb3eaf6d4e41083685d578ad2a9fbe31cc491a5f3fa9b7c9ab6eb90e4dc1356f89ae18a
2 parents 5152002 + f7a19ef commit 5c6b3d5

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/qt/rpcconsole.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
#include <QTimer>
5555
#include <QVariant>
5656

57+
#include <chrono>
58+
5759
const int CONSOLE_HISTORY = 50;
5860
const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
5961
const QSize FONT_RANGE(4, 40);
@@ -1140,7 +1142,7 @@ void RPCConsole::on_sldGraphRange_valueChanged(int value)
11401142

11411143
void RPCConsole::setTrafficGraphRange(int mins)
11421144
{
1143-
ui->trafficGraph->setGraphRangeMins(mins);
1145+
ui->trafficGraph->setGraphRange(std::chrono::minutes{mins});
11441146
ui->lblGraphRange->setText(GUIUtil::formatDurationStr(std::chrono::minutes{mins}));
11451147
}
11461148

src/qt/trafficgraphwidget.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <QColor>
1212
#include <QTimer>
1313

14+
#include <chrono>
1415
#include <cmath>
1516

1617
#define DESIRED_SAMPLES 800
@@ -22,7 +23,6 @@ TrafficGraphWidget::TrafficGraphWidget(QWidget *parent) :
2223
QWidget(parent),
2324
timer(nullptr),
2425
fMax(0.0f),
25-
nMins(0),
2626
vSamplesIn(),
2727
vSamplesOut(),
2828
nLastBytesIn(0),
@@ -42,10 +42,7 @@ void TrafficGraphWidget::setClientModel(ClientModel *model)
4242
}
4343
}
4444

45-
int TrafficGraphWidget::getGraphRangeMins() const
46-
{
47-
return nMins;
48-
}
45+
std::chrono::minutes TrafficGraphWidget::getGraphRange() const { return m_range; }
4946

5047
void TrafficGraphWidget::paintPath(QPainterPath &path, QQueue<float> &samples)
5148
{
@@ -153,12 +150,12 @@ void TrafficGraphWidget::updateRates()
153150
update();
154151
}
155152

156-
void TrafficGraphWidget::setGraphRangeMins(int mins)
153+
void TrafficGraphWidget::setGraphRange(std::chrono::minutes new_range)
157154
{
158-
nMins = mins;
159-
int msecsPerSample = nMins * 60 * 1000 / DESIRED_SAMPLES;
155+
m_range = new_range;
156+
const auto msecs_per_sample{std::chrono::duration_cast<std::chrono::milliseconds>(m_range) / DESIRED_SAMPLES};
160157
timer->stop();
161-
timer->setInterval(msecsPerSample);
158+
timer->setInterval(msecs_per_sample);
162159

163160
clear();
164161
}

src/qt/trafficgraphwidget.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <QWidget>
99
#include <QQueue>
1010

11+
#include <chrono>
12+
1113
class ClientModel;
1214

1315
QT_BEGIN_NAMESPACE
@@ -22,22 +24,22 @@ class TrafficGraphWidget : public QWidget
2224
public:
2325
explicit TrafficGraphWidget(QWidget *parent = nullptr);
2426
void setClientModel(ClientModel *model);
25-
int getGraphRangeMins() const;
27+
std::chrono::minutes getGraphRange() const;
2628

2729
protected:
2830
void paintEvent(QPaintEvent *) override;
2931

3032
public Q_SLOTS:
3133
void updateRates();
32-
void setGraphRangeMins(int mins);
34+
void setGraphRange(std::chrono::minutes new_range);
3335
void clear();
3436

3537
private:
3638
void paintPath(QPainterPath &path, QQueue<float> &samples);
3739

3840
QTimer *timer;
3941
float fMax;
40-
int nMins;
42+
std::chrono::minutes m_range{0};
4143
QQueue<float> vSamplesIn;
4244
QQueue<float> vSamplesOut;
4345
quint64 nLastBytesIn;

0 commit comments

Comments
 (0)