| 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>
16#include <ui/qt/utils/variant_pointer.h>
17
18#include <QAbstractItemModel>
19
20//Base class to inherit basic tree item from
21 template <typename Item>
22 class ModelHelperTreeItem
23{
24 public:
25 ModelHelperTreeItem(Item* parent)
26 : parent_(parent)
27 {
28 }
29
30 virtual ~ModelHelperTreeItem()
31 {
32 for (int row = 0; row < childItems_.count(); row++)
33 {
34 delete VariantPointer<Item>::asPtr(childItems_.value(row));
35 }
36
37 childItems_.clear();
38 }
39
40 void appendChild(Item* child)
41 {
42 childItems_.append(VariantPointer<Item>::asQVariant(child));
43 }
44
45 void prependChild(Item* child)
46 {
47 childItems_.prepend(VariantPointer<Item>::asQVariant(child));
48 }
49
50
51 void insertChild(int row, Item* child)
52 {
53 childItems_.insert(row, VariantPointer<Item>::asQVariant(child));
54 }
55
56 void removeChild(int row)
57 {
58 delete VariantPointer<Item>::asPtr(childItems_.value(row));
59 childItems_.removeAt(row);
60 }
61
62 Item* child(int row)
63 {
64 return VariantPointer<Item>::asPtr(childItems_.value(row));
65 }
66
67 int childCount() const
68 {
69 return static_cast<int>(childItems_.count());
70 }
71
72 int row()
73 {
74 if (parent_)
75 {
76 return static_cast<int>(parent_->childItems_.indexOf(VariantPointer<Item>::asQVariant((Item *)this)));
77 }
78
79 return 0;
80 }
81
82 Item* parentItem() {return parent_; }
83
84 protected:
85 Item* parent_;
86 QList<QVariant> childItems_;
87};
88
89#endif // TREE_MODEL_HELPERS_H
ModelHelperTreeItem
Definition tree_model_helpers.h:23
VariantPointer
Definition variant_pointer.h:20
variant_pointer.h