| Wireshark 4.7.3 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
percent_bar_delegate.h
Go to the documentation of this file.
1
9
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
39 class PercentBarDelegate : public QStyledItemDelegate
40{
41 public:
46 PercentBarDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) { }
47
52 virtual QString displayText(const QVariant &, const QLocale &) const override { return QString(); }
53
54 protected:
61 void paint(QPainter *painter, const QStyleOptionViewItem &option,
62 const QModelIndex &index) const override;
63
70 QSize sizeHint(const QStyleOptionViewItem &option,
71 const QModelIndex &index) const override;
72
73};
74
75#endif // PERCENTBARDELEGATE_H
PercentBarDelegate::displayText
virtual QString displayText(const QVariant &, const QLocale &) const override
Return empty string to ensure QStyledItemDelegate::paint doesn't draw any text.
Definition percent_bar_delegate.h:52
PercentBarDelegate::PercentBarDelegate
PercentBarDelegate(QWidget *parent=0)
Constructs a PercentBarDelegate.
Definition percent_bar_delegate.h:46
PercentBarDelegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Returns the size hint for the percentage bar item.
Definition percent_bar_delegate.cpp:88
PercentBarDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Renders the percentage bar using the given painter and style option.
Definition percent_bar_delegate.cpp:20