File tree 3 files changed +14
-13
lines changed
3 files changed +14
-13
lines changed Original file line number Diff line number Diff line change 54
54
#include < QTimer>
55
55
#include < QVariant>
56
56
57
+ #include < chrono>
58
+
57
59
const int CONSOLE_HISTORY = 50 ;
58
60
const int INITIAL_TRAFFIC_GRAPH_MINS = 30 ;
59
61
const QSize FONT_RANGE (4 , 40 );
@@ -1140,7 +1142,7 @@ void RPCConsole::on_sldGraphRange_valueChanged(int value)
1140
1142
1141
1143
void RPCConsole::setTrafficGraphRange (int mins)
1142
1144
{
1143
- ui->trafficGraph ->setGraphRangeMins ( mins);
1145
+ ui->trafficGraph ->setGraphRange (std::chrono::minutes{ mins} );
1144
1146
ui->lblGraphRange ->setText (GUIUtil::formatDurationStr (std::chrono::minutes{mins}));
1145
1147
}
1146
1148
Original file line number Diff line number Diff line change 11
11
#include < QColor>
12
12
#include < QTimer>
13
13
14
+ #include < chrono>
14
15
#include < cmath>
15
16
16
17
#define DESIRED_SAMPLES 800
@@ -22,7 +23,6 @@ TrafficGraphWidget::TrafficGraphWidget(QWidget *parent) :
22
23
QWidget(parent),
23
24
timer(nullptr ),
24
25
fMax(0 .0f ),
25
- nMins(0 ),
26
26
vSamplesIn(),
27
27
vSamplesOut(),
28
28
nLastBytesIn(0 ),
@@ -42,10 +42,7 @@ void TrafficGraphWidget::setClientModel(ClientModel *model)
42
42
}
43
43
}
44
44
45
- int TrafficGraphWidget::getGraphRangeMins () const
46
- {
47
- return nMins;
48
- }
45
+ std::chrono::minutes TrafficGraphWidget::getGraphRange () const { return m_range; }
49
46
50
47
void TrafficGraphWidget::paintPath (QPainterPath &path, QQueue<float > &samples)
51
48
{
@@ -153,12 +150,12 @@ void TrafficGraphWidget::updateRates()
153
150
update ();
154
151
}
155
152
156
- void TrafficGraphWidget::setGraphRangeMins ( int mins )
153
+ void TrafficGraphWidget::setGraphRange (std::chrono::minutes new_range )
157
154
{
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} ;
160
157
timer->stop ();
161
- timer->setInterval (msecsPerSample );
158
+ timer->setInterval (msecs_per_sample );
162
159
163
160
clear ();
164
161
}
Original file line number Diff line number Diff line change 8
8
#include < QWidget>
9
9
#include < QQueue>
10
10
11
+ #include < chrono>
12
+
11
13
class ClientModel ;
12
14
13
15
QT_BEGIN_NAMESPACE
@@ -22,22 +24,22 @@ class TrafficGraphWidget : public QWidget
22
24
public:
23
25
explicit TrafficGraphWidget (QWidget *parent = nullptr );
24
26
void setClientModel (ClientModel *model);
25
- int getGraphRangeMins () const ;
27
+ std::chrono::minutes getGraphRange () const ;
26
28
27
29
protected:
28
30
void paintEvent (QPaintEvent *) override ;
29
31
30
32
public Q_SLOTS:
31
33
void updateRates ();
32
- void setGraphRangeMins ( int mins );
34
+ void setGraphRange (std::chrono::minutes new_range );
33
35
void clear ();
34
36
35
37
private:
36
38
void paintPath (QPainterPath &path, QQueue<float > &samples);
37
39
38
40
QTimer *timer;
39
41
float fMax ;
40
- int nMins ;
42
+ std::chrono::minutes m_range{ 0 } ;
41
43
QQueue<float > vSamplesIn;
42
44
QQueue<float > vSamplesOut;
43
45
quint64 nLastBytesIn;
You can’t perform that action at this time.
0 commit comments