Wireshark 2.9.0-477-g68ec514b The Wireshark network protocol analyzer

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

percent_bar_delegate.h
1 /* percent_bar_delegate.h
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
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
36 class PercentBarDelegate : public QStyledItemDelegate
37 {
38 Q_OBJECT
39
40 public:
41 PercentBarDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) { }
42
43 // Make sure QStyledItemDelegate::paint doesn't draw any text.
44 virtual QString displayText(const QVariant &, const QLocale &) const { return QString(); }
45
46 protected:
47 void paint(QPainter *painter, const QStyleOptionViewItem &option,
48 const QModelIndex &index) const;
49 QSize sizeHint(const QStyleOptionViewItem &option,
50 const QModelIndex &index) const;
51
52 };
53
54 #endif // PERCENTBARDELEGATE_H
55
56 /*
57 * Editor modelines
58 *
59 * Local Variables:
60 * c-basic-offset: 4
61 * tab-width: 8
62 * indent-tabs-mode: nil
63 * End:
64 *
65 * ex: set shiftwidth=4 tabstop=8 expandtab:
66 * :indentSize=4:tabSize=8:noTabs=true:
67 */
PercentBarDelegate
Definition: percent_bar_delegate.h:36
option
Definition: pcapng.c:148