Skip to content

Commit c0b9aff

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 976318c commit c0b9aff

File tree

6 files changed

+676
-128
lines changed

6 files changed

+676
-128
lines changed

src/qt/forms/debugwindow.ui

Lines changed: 13 additions & 14 deletions
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>200</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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 31 additions & 10 deletions
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();
@@ -1166,21 +1164,44 @@ void RPCConsole::scrollToEnd()
11661164

11671165
void RPCConsole::on_sldGraphRange_valueChanged(int value)
11681166
{
1169-
const int multiplier = 5; // each position on the slider represents 5 min
1170-
int mins = value * multiplier;
1171-
setTrafficGraphRange(mins);
1167+
setTrafficGraphRange((value + 100) / 200 + 1);
11721168
}
11731169

1174-
void RPCConsole::setTrafficGraphRange(int mins)
1170+
void RPCConsole::setTrafficGraphRange(int value)
11751171
{
1176-
ui->trafficGraph->setGraphRange(std::chrono::minutes{mins});
1172+
int mins = ui->trafficGraph->setGraphRange(value);
1173+
if (value)
1174+
m_set_slider_value = (value - 1) * 200;
1175+
else {
1176+
// When bumping, calculate the proper slider position based on the traffic graph's new value
1177+
unsigned int new_graph_value = ui->trafficGraph->getCurrentRangeIndex() + 1; // +1 because the index is 0-based
1178+
m_set_slider_value = (new_graph_value - 1) * 200;
1179+
ui->sldGraphRange->blockSignals(true);
1180+
ui->sldGraphRange->setValue(m_set_slider_value);
1181+
ui->sldGraphRange->blockSignals(false);
1182+
}
11771183
ui->lblGraphRange->setText(GUIUtil::formatDurationStr(std::chrono::minutes{mins}));
11781184
}
11791185

1186+
void RPCConsole::on_sldGraphRange_sliderReleased()
1187+
{
1188+
ui->sldGraphRange->setValue(m_set_slider_value);
1189+
m_slider_in_use = false;
1190+
}
1191+
1192+
void RPCConsole::on_sldGraphRange_sliderPressed() { m_slider_in_use = true; }
1193+
11801194
void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
11811195
{
1182-
ui->lblBytesIn->setText(GUIUtil::formatBytes(totalBytesIn));
1183-
ui->lblBytesOut->setText(GUIUtil::formatBytes(totalBytesOut));
1196+
if (!m_slider_in_use && ui->trafficGraph->GraphRangeBump())
1197+
setTrafficGraphRange(0); // bump it up
1198+
1199+
// Add baseline values to the current node values
1200+
quint64 totalIn = totalBytesIn + ui->trafficGraph->getBaselineBytesRecv();
1201+
quint64 totalOut = totalBytesOut + ui->trafficGraph->getBaselineBytesSent();
1202+
1203+
ui->lblBytesIn->setText(GUIUtil::formatBytes(totalIn));
1204+
ui->lblBytesOut->setText(GUIUtil::formatBytes(totalOut));
11841205
}
11851206

11861207
void RPCConsole::updateDetailWidget()

src/qt/rpcconsole.h

Lines changed: 6 additions & 3 deletions
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,10 +148,9 @@ public Q_SLOTS:
146148
} const ts;
147149

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

151-
enum ColumnWidths
152-
{
153+
enum ColumnWidths {
153154
ADDRESS_COLUMN_WIDTH = 200,
154155
SUBVERSION_COLUMN_WIDTH = 150,
155156
PING_COLUMN_WIDTH = 80,
@@ -177,6 +178,8 @@ public Q_SLOTS:
177178
bool m_is_executing{false};
178179
QByteArray m_peer_widget_header_state;
179180
QByteArray m_banlist_widget_header_state;
181+
bool m_slider_in_use{false};
182+
int m_set_slider_value{0};
180183

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

0 commit comments

Comments
 (0)