Kerberos: add kerberos_inject_longterm_key() helper function
[wireshark-sm.git] / ui / qt / models / tree_model_helpers.h
blob5734b66001c5a5282ff6d776b77e7844958cefad
1 /** @file
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
15 #include <config.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
24 public:
25 ModelHelperTreeItem(Item* parent)
26 : parent_(parent)
30 virtual ~ModelHelperTreeItem()
32 for (int row = 0; row < childItems_.count(); row++)
34 delete VariantPointer<Item>::asPtr(childItems_.value(row));
37 childItems_.clear();
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);
62 Item* child(int row)
64 return VariantPointer<Item>::asPtr(childItems_.value(row));
67 int childCount() const
69 return static_cast<int>(childItems_.count());
72 int row()
74 if (parent_)
76 return static_cast<int>(parent_->childItems_.indexOf(VariantPointer<Item>::asQVariant((Item *)this)));
79 return 0;
82 Item* parentItem() {return parent_; }
84 protected:
85 Item* parent_;
86 QList<QVariant> childItems_;
89 #endif // TREE_MODEL_HELPERS_H