3 * Utility template classes for basic tree model functionality
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #ifndef TREE_MODEL_HELPERS_H
13 #define TREE_MODEL_HELPERS_H
16 #include <ui/qt/utils/variant_pointer.h>
18 #include <QAbstractItemModel>
20 //Base class to inherit basic tree item from
21 template <typename Item
>
22 class ModelHelperTreeItem
25 ModelHelperTreeItem(Item
* parent
)
30 virtual ~ModelHelperTreeItem()
32 for (int row
= 0; row
< childItems_
.count(); row
++)
34 delete VariantPointer
<Item
>::asPtr(childItems_
.value(row
));
40 void appendChild(Item
* child
)
42 childItems_
.append(VariantPointer
<Item
>::asQVariant(child
));
45 void prependChild(Item
* child
)
47 childItems_
.prepend(VariantPointer
<Item
>::asQVariant(child
));
51 void insertChild(int row
, Item
* child
)
53 childItems_
.insert(row
, VariantPointer
<Item
>::asQVariant(child
));
56 void removeChild(int row
)
58 delete VariantPointer
<Item
>::asPtr(childItems_
.value(row
));
59 childItems_
.removeAt(row
);
64 return VariantPointer
<Item
>::asPtr(childItems_
.value(row
));
67 int childCount() const
69 return static_cast<int>(childItems_
.count());
76 return static_cast<int>(parent_
->childItems_
.indexOf(VariantPointer
<Item
>::asQVariant((Item
*)this)));
82 Item
* parentItem() {return parent_
; }
86 QList
<QVariant
> childItems_
;
89 #endif // TREE_MODEL_HELPERS_H