Wireshark  4.3.0
The Wireshark network protocol analyzer
percent_bar_delegate.h
Go to the documentation of this file.
1 
10 #ifndef PERCENTBARDELEGATE_H
11 #define PERCENTBARDELEGATE_H
12 
13 /*
14  * @file Percent bar delegate.
15  *
16  * QStyledItemDelegate subclass that will draw a percentage value and a
17  * single-item bar chart for the specified value.
18  *
19  * This is intended to be used in QTreeWidgets to show percentage values.
20  * To use it, first call setItemDelegate:
21  *
22  * myTreeWidget()->setItemDelegateForColumn(col_pct_, new PercentBarDelegate());
23  *
24  * Then, for each QTreeWidgetItem, set a double value using setData:
25  *
26  * setData(col_pct_, Qt::UserRole, QVariant::fromValue<double>(packets_ * 100.0 / num_packets));
27  *
28  * If the item data cannot be converted to a valid double value or if its
29  * text string is non-empty then it will be rendered normally (i.e. the
30  * percent text and bar will not be drawn). This lets you mix normal and
31  * percent bar rendering between rows.
32  */
33 
34 #include <QStyledItemDelegate>
35 
36 class PercentBarDelegate : public QStyledItemDelegate
37 {
38 public:
39  PercentBarDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) { }
40 
41  // Make sure QStyledItemDelegate::paint doesn't draw any text.
42  virtual QString displayText(const QVariant &, const QLocale &) const { return QString(); }
43 
44 protected:
45  void paint(QPainter *painter, const QStyleOptionViewItem &option,
46  const QModelIndex &index) const;
47  QSize sizeHint(const QStyleOptionViewItem &option,
48  const QModelIndex &index) const;
49 
50 };
51 
52 #endif // PERCENTBARDELEGATE_H
Definition: percent_bar_delegate.h:37