File indexing completed on 2024-04-28 09:45:57

0001 /*
0002     SPDX-FileCopyrightText: 2008, 2009, 2012 Rolf Eike Beer <kde@opensource.sf-tec.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 #include "KGpgExpandableNode.h"
0007 
0008 #include "kgpgsettings.h"
0009 #include "core/convert.h"
0010 #include "model/kgpgitemmodel.h"
0011 
0012 KGpgExpandableNode::KGpgExpandableNode(KGpgExpandableNode *parent)
0013     : KGpgNode(parent)
0014 {
0015     if (parent != nullptr)
0016         parent->children.append(this);
0017 }
0018 
0019 KGpgExpandableNode::~KGpgExpandableNode()
0020 {
0021     for (int i = children.count() - 1; i >= 0; i--)
0022         delete children[i];
0023 }
0024 
0025 KGpgNode *
0026 KGpgExpandableNode::getChild(const int index) const
0027 {
0028     return children.at(index);
0029 }
0030 
0031 int
0032 KGpgExpandableNode::getChildCount()
0033 {
0034     if (children.isEmpty())
0035         readChildren();
0036 
0037     return children.count();
0038 }
0039 
0040 bool
0041 KGpgExpandableNode::hasChildren() const
0042 {
0043     return !children.isEmpty();
0044 }
0045 
0046 bool
0047 KGpgExpandableNode::wasExpanded() const
0048 {
0049     return !children.isEmpty();
0050 }
0051 
0052 const
0053 KGpgNode::List &
0054 KGpgExpandableNode::getChildren() const
0055 {
0056     return children;
0057 }
0058 
0059 int
0060 KGpgExpandableNode::getChildIndex(KGpgNode *node) const
0061 {
0062     return children.indexOf(node);
0063 }
0064 
0065 void
0066 KGpgExpandableNode::deleteChild(KGpgNode *child)
0067 {
0068     children.removeAll(child);
0069 }