aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt
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
parentf184dff8763b4145fa786fe57d0ae541375e9dc0 (diff)
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')
-rw-r--r--ui/qt/percent_bar_delegate.cpp11
-rw-r--r--ui/qt/wlan_statistics_dialog.cpp7
2 files changed, 15 insertions, 3 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();
diff --git a/ui/qt/wlan_statistics_dialog.cpp b/ui/qt/wlan_statistics_dialog.cpp
index 4a3f18ccc9..b577a64f1f 100644
--- a/ui/qt/wlan_statistics_dialog.cpp
+++ b/ui/qt/wlan_statistics_dialog.cpp
@@ -127,10 +127,13 @@ public:
}
if (wlan_hdr->type != MGT_BEACON) packets_++;
}
- void draw(address *bssid, int num_packets _U_) {
- if(packets_){
+ void draw(address *bssid, int num_packets) {
+ if(packets_ && num_packets > 0) {
setData(col_pct_packets_, Qt::UserRole, QVariant::fromValue<double>(packets_ * 100.0 / num_packets));
setData(col_pct_retry_, Qt::UserRole, QVariant::fromValue<double>(retry_ * 100.0 / packets_));
+ } else {
+ setData(col_pct_packets_, Qt::UserRole, QVariant::fromValue<double>(0));
+ setData(col_pct_retry_, Qt::UserRole, QVariant::fromValue<double>(0));
}
setText(col_beacons_, QString::number(sent_));
setText(col_data_packets_, QString::number(received_));