Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
tree_model_helpers.h
Go to the documentation of this file.
1
12#ifndef TREE_MODEL_HELPERS_H
13#define TREE_MODEL_HELPERS_H
14
15#include <config.h>
17
18#include <QAbstractItemModel>
19
23template <typename Item>
25{
26public:
31 ModelHelperTreeItem(Item* parent)
32 : parent_(parent)
33 {
34 }
35
40 {
41 for (int row = 0; row < childItems_.count(); row++)
42 {
44 }
45
46 childItems_.clear();
47 }
48
57
66
72 void insertChild(int row, Item* child)
73 {
75 }
76
81 void removeChild(int row)
82 {
84 childItems_.removeAt(row);
85 }
86
92 Item* child(int row)
93 {
95 }
96
101 int childCount() const
102 {
103 return static_cast<int>(childItems_.count());
104 }
105
110 int row()
111 {
112 if (parent_)
113 {
114 return static_cast<int>(parent_->childItems_.indexOf(VariantPointer<Item>::asQVariant((Item *)this)));
115 }
116
117 return 0;
118 }
119
124 Item* parentItem() {return parent_; }
125
126protected:
128 Item* parent_;
129
131 QList<QVariant> childItems_;
132};
133
134#endif // TREE_MODEL_HELPERS_H
Base class to inherit basic tree item from.
Definition tree_model_helpers.h:25
void prependChild(Item *child)
Prepends a child item to the beginning of the children list.
Definition tree_model_helpers.h:62
void appendChild(Item *child)
Appends a child item to the end of the children list.
Definition tree_model_helpers.h:53
Item * parent_
Definition tree_model_helpers.h:128
void removeChild(int row)
Removes and deletes the child item at the specified row.
Definition tree_model_helpers.h:81
virtual ~ModelHelperTreeItem()
Destroys the ModelHelperTreeItem and its children.
Definition tree_model_helpers.h:39
void insertChild(int row, Item *child)
Inserts a child item at the specified row.
Definition tree_model_helpers.h:72
ModelHelperTreeItem(Item *parent)
Constructs a new ModelHelperTreeItem.
Definition tree_model_helpers.h:31
Item * parentItem()
Retrieves the parent item.
Definition tree_model_helpers.h:124
int childCount() const
Gets the total number of child items.
Definition tree_model_helpers.h:101
QList< QVariant > childItems_
Definition tree_model_helpers.h:131
Item * child(int row)
Retrieves the child item at the specified row.
Definition tree_model_helpers.h:92
int row()
Gets the row index of this item relative to its parent.
Definition tree_model_helpers.h:110
A template utility class for converting between pointers and QVariant objects.
Definition variant_pointer.h:23
static T * asPtr(QVariant v)
Converts a QVariant containing a void pointer back to a typed pointer.
Definition variant_pointer.h:31