From 70b29676b7b829db14a72c9f6522e17d6b2d67cc Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 18 Oct 2016 17:10:20 +0200 Subject: wlan_statistics_dialog (Qt): Fix display when there is no packets_ Make sure we don't pass an invalid value to PercentBarDelegate. Make sure PercentBarDelegate handles invalid values more gracefully. Change-Id: I18f07542be3432d0fcf5dff479eef2ea4d5e7931 Reviewed-on: https://code.wireshark.org/review/18276 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall --- ui/qt/percent_bar_delegate.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'ui/qt/percent_bar_delegate.cpp') diff --git a/ui/qt/percent_bar_delegate.cpp b/ui/qt/percent_bar_delegate.cpp index 31555aec38..2a8ea0b2f2 100644 --- a/ui/qt/percent_bar_delegate.cpp +++ b/ui/qt/percent_bar_delegate.cpp @@ -47,6 +47,16 @@ void PercentBarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op return; } + // If our value is out range our caller has a bug. Clamp the graph and + // Print the numeric value so that the bug is obvious. + QString pct_str = QString::number(value, 'f', 1); + if (value < 0) { + value = 0; + } + if (value > 100.0) { + value = 100.0; + } + if (QApplication::style()->objectName().contains("vista")) { // QWindowsVistaStyle::drawControl does this internally. Unfortunately there // doesn't appear to be a more general way to do this. @@ -80,7 +90,6 @@ void PercentBarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op painter->restore(); painter->save(); - QString pct_str = QString::number(value, 'f', 1); painter->setPen(text_color); painter->drawText(option.rect, Qt::AlignCenter, pct_str); painter->restore(); -- cgit v1.2.1