File indexing completed on 2024-04-28 15:39:55
0001 /* SPDX-FileCopyrightText: 2003-2020 Jesper K. Pedersen <blackie@kde.org> 0002 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 #include "CategoryItem.h" 0006 0007 #include <QList> 0008 0009 DB::CategoryItem::~CategoryItem() 0010 { 0011 for (QList<CategoryItem *>::ConstIterator it = mp_subcategories.constBegin(); it != mp_subcategories.constEnd(); ++it) { 0012 delete *it; 0013 } 0014 } 0015 0016 DB::CategoryItem *DB::CategoryItem::clone() const 0017 { 0018 CategoryItem *result = new CategoryItem(mp_name); 0019 for (QList<CategoryItem *>::ConstIterator it = mp_subcategories.constBegin(); it != mp_subcategories.constEnd(); ++it) { 0020 result->mp_subcategories.append((*it)->clone()); 0021 } 0022 return result; 0023 } 0024 0025 bool DB::CategoryItem::isDescendentOf(const QString &child, const QString &parent) const 0026 { 0027 for (QList<CategoryItem *>::ConstIterator it = mp_subcategories.begin(); it != mp_subcategories.end(); ++it) { 0028 if (mp_name == parent) { 0029 if ((*it)->hasChild(child)) 0030 return true; 0031 } else { 0032 if ((*it)->isDescendentOf(child, parent)) 0033 return true; 0034 } 0035 } 0036 return false; 0037 } 0038 0039 bool DB::CategoryItem::hasChild(const QString &child) const 0040 { 0041 if (mp_name == child) 0042 return true; 0043 0044 for (const CategoryItem *subcategory : qAsConst(mp_subcategories)) { 0045 if (subcategory->hasChild(child)) 0046 return true; 0047 } 0048 return false; 0049 } 0050 0051 // vi:expandtab:tabstop=4 shiftwidth=4: