Skip to content

Commit 31b1ffc

Browse files
committed
qt: Enhance TrafficGraphWidget with multi-timeframe support and data persistence
This commit significantly improves the network traffic graph widget with: 1. Multiple timeframe support - View traffic data across different time periods (5 minutes to 28 days) using an enhanced slider interface 2. Traffic data persistence - Save and restore traffic information between sessions, preserving historical traffic patterns 3. Interactive visualization features: - Logarithmic scale toggle (mouse click) for better visualization of varying traffic volumes - Interactive tooltips showing detailed traffic information at specific points - Yellow highlight indicators for selected data points 4. Smooth transitions between different time ranges with animated scaling These improvements allow users to better monitor and analyze network traffic patterns over time, which is especially useful for debugging connectivity issues or understanding network behavior under different conditions. The implementation includes proper thread-safety considerations and handles edge cases like time jumps or missing data appropriately.
1 parent 9522c30 commit 31b1ffc

File tree

6 files changed

+654
-126
lines changed

6 files changed

+654
-126
lines changed

src/qt/forms/debugwindow.ui

+13-14
Original file line numberDiff line numberDiff line change
@@ -665,20 +665,29 @@
665665
<item>
666666
<widget class="QSlider" name="sldGraphRange">
667667
<property name="minimum">
668-
<number>1</number>
668+
<number>0</number>
669669
</property>
670670
<property name="maximum">
671-
<number>288</number>
671+
<number>2400</number>
672+
</property>
673+
<property name="singleStep">
674+
<number>200</number>
672675
</property>
673676
<property name="pageStep">
674-
<number>12</number>
677+
<number>400</number>
675678
</property>
676679
<property name="value">
677-
<number>6</number>
680+
<number>0</number>
678681
</property>
679682
<property name="orientation">
680683
<enum>Qt::Horizontal</enum>
681684
</property>
685+
<property name="tickPosition">
686+
<enum>QSlider::TicksBelow</enum>
687+
</property>
688+
<property name="tickInterval">
689+
<number>200</number>
690+
</property>
682691
</widget>
683692
</item>
684693
<item>
@@ -694,16 +703,6 @@
694703
</property>
695704
</widget>
696705
</item>
697-
<item>
698-
<widget class="QPushButton" name="btnClearTrafficGraph">
699-
<property name="text">
700-
<string>&amp;Reset</string>
701-
</property>
702-
<property name="autoDefault">
703-
<bool>false</bool>
704-
</property>
705-
</widget>
706-
</item>
707706
</layout>
708707
</item>
709708
</layout>

src/qt/guiutil.h

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ namespace GUIUtil
246246
QString formatNiceTimeOffset(qint64 secs);
247247

248248
QString formatBytes(uint64_t bytes);
249+
QString formatBytesps(float bytes);
249250

250251
qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize = 4, qreal startPointSize = 14);
251252

src/qt/rpcconsole.cpp

+47-10
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
using util::Join;
5454

5555
const int CONSOLE_HISTORY = 50;
56-
const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
5756
const QSize FONT_RANGE(4, 40);
5857
const char fontSizeSettingsKey[] = "consoleFontSize";
5958

@@ -566,7 +565,6 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
566565
connect(ui->clearButton, &QAbstractButton::clicked, [this] { clear(); });
567566
connect(ui->fontBiggerButton, &QAbstractButton::clicked, this, &RPCConsole::fontBigger);
568567
connect(ui->fontSmallerButton, &QAbstractButton::clicked, this, &RPCConsole::fontSmaller);
569-
connect(ui->btnClearTrafficGraph, &QPushButton::clicked, ui->trafficGraph, &TrafficGraphWidget::clear);
570568

571569
// disable the wallet selector by default
572570
ui->WalletSelector->setVisible(false);
@@ -578,7 +576,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
578576
// based timer interface
579577
m_node.rpcSetTimerInterfaceIfUnset(rpcTimerInterface);
580578

581-
setTrafficGraphRange(INITIAL_TRAFFIC_GRAPH_MINS);
579+
setTrafficGraphRange(1); // 1 is the lowest setting (0 bumps up)
582580
updateDetailWidget();
583581

584582
consoleFontSize = settings.value(fontSizeSettingsKey, QFont().pointSize()).toInt();
@@ -1164,21 +1162,60 @@ void RPCConsole::scrollToEnd()
11641162
scrollbar->setValue(scrollbar->maximum());
11651163
}
11661164

1167-
void RPCConsole::on_sldGraphRange_valueChanged(int value)
1165+
void RPCConsole::on_sldGraphRange_valueChanged(int slider_value)
11681166
{
1169-
const int multiplier = 5; // each position on the slider represents 5 min
1170-
int mins = value * multiplier;
1171-
setTrafficGraphRange(mins);
1167+
static int64_t last_click_time = 0;
1168+
static bool last_click_was_up = false;
1169+
unsigned int value = (slider_value + 100) / 200 + 1; // minimum of 1, 0 reserve for scale bump
1170+
if (!slider_in_use) {
1171+
// Avoid accidental boucing of direction
1172+
int64_t now = GetTimeMillis();
1173+
bool this_click_is_up = false;
1174+
bool bouncing = false;
1175+
if (slider_value > set_slider_value) this_click_is_up = true;
1176+
if (now - last_click_time < 250 && this_click_is_up != last_click_was_up) {
1177+
bouncing = true;
1178+
ui->sldGraphRange->blockSignals(true);
1179+
ui->sldGraphRange->setValue(set_slider_value);
1180+
ui->sldGraphRange->blockSignals(false);
1181+
}
1182+
last_click_time = now;
1183+
last_click_was_up = this_click_is_up;
1184+
set_slider_value = slider_value;
1185+
if (bouncing) return;
1186+
}
1187+
set_slider_value = slider_value;
1188+
setTrafficGraphRange(value);
11721189
}
11731190

1174-
void RPCConsole::setTrafficGraphRange(int mins)
1191+
void RPCConsole::setTrafficGraphRange(unsigned int value)
11751192
{
1176-
ui->trafficGraph->setGraphRange(std::chrono::minutes{mins});
1177-
ui->lblGraphRange->setText(GUIUtil::formatDurationStr(std::chrono::minutes{mins}));
1193+
std::chrono::minutes mins = ui->trafficGraph->setGraphRange(value);
1194+
if (value)
1195+
set_slider_value = (value - 1) * 200;
1196+
else {
1197+
// When bumping, calculate the proper slider position based on the traffic graph's new value
1198+
unsigned int new_graph_value = ui->trafficGraph->getCurrentRangeIndex() + 1; // +1 because the index is 0-based
1199+
set_slider_value = (new_graph_value - 1) * 200;
1200+
ui->sldGraphRange->blockSignals(true);
1201+
ui->sldGraphRange->setValue(set_slider_value);
1202+
ui->sldGraphRange->blockSignals(false);
1203+
}
1204+
ui->lblGraphRange->setText(GUIUtil::formatDurationStr(mins));
11781205
}
11791206

1207+
void RPCConsole::on_sldGraphRange_sliderReleased()
1208+
{
1209+
ui->sldGraphRange->setValue(set_slider_value);
1210+
slider_in_use = false;
1211+
}
1212+
1213+
void RPCConsole::on_sldGraphRange_sliderPressed() { slider_in_use = true; }
1214+
11801215
void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
11811216
{
1217+
if (!slider_in_use && ui->trafficGraph->GraphRangeBump())
1218+
setTrafficGraphRange(0); // bump it up
11821219
ui->lblBytesIn->setText(GUIUtil::formatBytes(totalBytesIn));
11831220
ui->lblBytesOut->setText(GUIUtil::formatBytes(totalBytesOut));
11841221
}

src/qt/rpcconsole.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ private Q_SLOTS:
9090
void on_openDebugLogfileButton_clicked();
9191
/** change the time range of the network traffic graph */
9292
void on_sldGraphRange_valueChanged(int value);
93+
void on_sldGraphRange_sliderReleased();
94+
void on_sldGraphRange_sliderPressed();
9395
/** update traffic statistics */
9496
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
9597
void resizeEvent(QResizeEvent *event) override;
@@ -146,7 +148,7 @@ public Q_SLOTS:
146148
} const ts;
147149

148150
void startExecutor();
149-
void setTrafficGraphRange(int mins);
151+
void setTrafficGraphRange(unsigned int value);
150152

151153
enum ColumnWidths
152154
{
@@ -177,6 +179,8 @@ public Q_SLOTS:
177179
bool m_is_executing{false};
178180
QByteArray m_peer_widget_header_state;
179181
QByteArray m_banlist_widget_header_state;
182+
bool slider_in_use{false};
183+
int set_slider_value{0};
180184

181185
/** Update UI with latest network info from model. */
182186
void updateNetworkState();

0 commit comments

Comments
 (0)