summaryrefslogtreecommitdiff
path: root/ui/qt/percent_bar_delegate.cpp
diff options
context:
space:
mode:
authorAlexis La Goutte <alexis.lagoutte@gmail.com>2016-10-18 17:10:20 +0200
committerRoland Knall <rknall@gmail.com>2016-10-30 08:48:43 +0000
commit70b29676b7b829db14a72c9f6522e17d6b2d67cc (patch)
treec1592350ac41b8251912e94aa68ab17377f8da0b /ui/qt/percent_bar_delegate.cpp
parentf184dff8763b4145fa786fe57d0ae541375e9dc0 (diff)
downloadwireshark-70b29676b7b829db14a72c9f6522e17d6b2d67cc.tar.gz
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 <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt/percent_bar_delegate.cpp')
-rw-r--r--ui/qt/percent_bar_delegate.cpp11
1 files changed, 10 insertions, 1 deletions
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();