Skip to content

Commit 6232958

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 3e865ef commit 6232958

File tree

5 files changed

+567
-195
lines changed

5 files changed

+567
-195
lines changed

src/qt/forms/debugwindow.ui

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -841,19 +841,28 @@
841841
</size>
842842
</property>
843843
<property name="minimum">
844-
<number>1</number>
844+
<number>0</number>
845845
</property>
846846
<property name="maximum">
847-
<number>288</number>
847+
<number>2400</number>
848+
</property>
849+
<property name="singleStep">
850+
<number>200</number>
848851
</property>
849852
<property name="pageStep">
850-
<number>12</number>
853+
<number>400</number>
851854
</property>
852855
<property name="value">
853-
<number>6</number>
856+
<number>0</number>
854857
</property>
855858
<property name="orientation">
856859
<enum>Qt::Horizontal</enum>
860+
</property>
861+
<property name="tickPosition">
862+
<enum>QSlider::TicksBelow</enum>
863+
</property>
864+
<property name="tickInterval">
865+
<number>200</number>
857866
</property>
858867
</widget>
859868
</item>
@@ -870,16 +879,6 @@
870879
</property>
871880
</widget>
872881
</item>
873-
<item>
874-
<widget class="QPushButton" name="btnClearTrafficGraph">
875-
<property name="text">
876-
<string>&amp;Reset</string>
877-
</property>
878-
<property name="autoDefault">
879-
<bool>false</bool>
880-
</property>
881-
</widget>
882-
</item>
883882
</layout>
884883
</item>
885884
</layout>

src/qt/rpcconsole.cpp

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
using util::Join;
5656

5757
const int CONSOLE_HISTORY = 50;
58-
const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
5958
const QSize FONT_RANGE(4, 40);
6059
const char fontSizeSettingsKey[] = "consoleFontSize";
6160

@@ -576,7 +575,6 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
576575
connect(ui->clearButton, &QAbstractButton::clicked, [this] { clear(); });
577576
connect(ui->fontBiggerButton, &QAbstractButton::clicked, this, &RPCConsole::fontBigger);
578577
connect(ui->fontSmallerButton, &QAbstractButton::clicked, this, &RPCConsole::fontSmaller);
579-
connect(ui->btnClearTrafficGraph, &QPushButton::clicked, ui->trafficGraph, &TrafficGraphWidget::clear);
580578

581579
// disable the wallet selector by default
582580
ui->WalletSelector->setVisible(false);
@@ -588,7 +586,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
588586
// based timer interface
589587
m_node.rpcSetTimerInterfaceIfUnset(rpcTimerInterface);
590588

591-
setTrafficGraphRange(INITIAL_TRAFFIC_GRAPH_MINS);
589+
setTrafficGraphRange(1); // 1 is the lowest setting (0 bumps up)
592590
updateDetailWidget();
593591

594592
consoleFontSize = settings.value(fontSizeSettingsKey, QFont().pointSize()).toInt();
@@ -1256,21 +1254,60 @@ void RPCConsole::scrollToEnd()
12561254
scrollbar->setValue(scrollbar->maximum());
12571255
}
12581256

1259-
void RPCConsole::on_sldGraphRange_valueChanged(int value)
1257+
void RPCConsole::on_sldGraphRange_valueChanged(int slider_value)
12601258
{
1261-
const int multiplier = 5; // each position on the slider represents 5 min
1262-
int mins = value * multiplier;
1263-
setTrafficGraphRange(mins);
1259+
static int64_t last_click_time = 0;
1260+
static bool last_click_was_up = false;
1261+
unsigned int value = (slider_value + 100) / 200 + 1; // minimum of 1, 0 reserve for scale bump
1262+
if (!slider_in_use) {
1263+
// Avoid accidental boucing of direction
1264+
int64_t now = GetTimeMillis();
1265+
bool this_click_is_up = false;
1266+
bool bouncing = false;
1267+
if (slider_value > set_slider_value) this_click_is_up = true;
1268+
if (now - last_click_time < 250 && this_click_is_up != last_click_was_up) {
1269+
bouncing = true;
1270+
ui->sldGraphRange->blockSignals(true);
1271+
ui->sldGraphRange->setValue(set_slider_value);
1272+
ui->sldGraphRange->blockSignals(false);
1273+
}
1274+
last_click_time = now;
1275+
last_click_was_up = this_click_is_up;
1276+
set_slider_value = slider_value;
1277+
if (bouncing) return;
1278+
}
1279+
set_slider_value = slider_value;
1280+
setTrafficGraphRange(value);
12641281
}
12651282

1266-
void RPCConsole::setTrafficGraphRange(int mins)
1283+
void RPCConsole::setTrafficGraphRange(unsigned int value)
12671284
{
1268-
ui->trafficGraph->setGraphRange(std::chrono::minutes{mins});
1269-
ui->lblGraphRange->setText(GUIUtil::formatDurationStr(std::chrono::minutes{mins}));
1285+
std::chrono::minutes mins = ui->trafficGraph->setGraphRange(value);
1286+
if (value)
1287+
set_slider_value = (value - 1) * 200;
1288+
else {
1289+
// When bumping, calculate the proper slider position based on the traffic graph's new value
1290+
unsigned int new_graph_value = ui->trafficGraph->getCurrentRangeIndex() + 1; // +1 because the index is 0-based
1291+
set_slider_value = (new_graph_value - 1) * 200;
1292+
ui->sldGraphRange->blockSignals(true);
1293+
ui->sldGraphRange->setValue(set_slider_value);
1294+
ui->sldGraphRange->blockSignals(false);
1295+
}
1296+
ui->lblGraphRange->setText(GUIUtil::formatDurationStr(mins));
12701297
}
12711298

1299+
void RPCConsole::on_sldGraphRange_sliderReleased()
1300+
{
1301+
ui->sldGraphRange->setValue(set_slider_value);
1302+
slider_in_use = false;
1303+
}
1304+
1305+
void RPCConsole::on_sldGraphRange_sliderPressed() { slider_in_use = true; }
1306+
12721307
void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
12731308
{
1309+
if (!slider_in_use && ui->trafficGraph->GraphRangeBump())
1310+
setTrafficGraphRange(0); // bump it up
12741311
ui->lblBytesIn->setText(GUIUtil::formatBytes(totalBytesIn));
12751312
ui->lblBytesOut->setText(GUIUtil::formatBytes(totalBytesOut));
12761313
}

src/qt/rpcconsole.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ private Q_SLOTS:
9494
void on_openDebugLogfileButton_clicked();
9595
/** change the time range of the network traffic graph */
9696
void on_sldGraphRange_valueChanged(int value);
97+
void on_sldGraphRange_sliderReleased();
98+
void on_sldGraphRange_sliderPressed();
9799
/** update traffic statistics */
98100
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
99101
void resizeEvent(QResizeEvent *event) override;
@@ -152,7 +154,7 @@ public Q_SLOTS:
152154
} const ts;
153155

154156
void startExecutor();
155-
void setTrafficGraphRange(int mins);
157+
void setTrafficGraphRange(unsigned int value);
156158
void WriteCommandHistory();
157159

158160
enum ColumnWidths
@@ -189,6 +191,8 @@ public Q_SLOTS:
189191
QByteArray m_peer_widget_header_state;
190192
QByteArray m_banlist_widget_header_state;
191193
bool m_alternating_row_colors{false};
194+
bool slider_in_use{false};
195+
int set_slider_value{0};
192196

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

0 commit comments

Comments
 (0)