File indexing completed on 2025-01-19 12:45:15
0001 /* This file is part of the KDE project 0002 Copyright (C) 2006 Michael Larouche <michael.larouche@kdemail.net> 0003 2007 Kevin Ottens <ervin@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License version 2 as published by the Free Software Foundation. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 0019 */ 0020 #include "kdevicelistitem_p.h" 0021 0022 #include <solid/device.h> 0023 0024 class KDeviceListItem::Private 0025 { 0026 public: 0027 Private() : parent(nullptr) {} 0028 0029 ~Private() 0030 { 0031 qDeleteAll(children); 0032 } 0033 0034 Solid::Device device; 0035 KDeviceListItem *parent; 0036 0037 QList<KDeviceListItem *> children; 0038 }; 0039 0040 KDeviceListItem::KDeviceListItem() 0041 : d(new Private) 0042 { 0043 } 0044 0045 KDeviceListItem::~KDeviceListItem() 0046 { 0047 delete d; 0048 } 0049 0050 KDeviceListItem *KDeviceListItem::child(int row) 0051 { 0052 return d->children.value(row); 0053 } 0054 0055 QList<KDeviceListItem *> KDeviceListItem::children() 0056 { 0057 return d->children; 0058 } 0059 0060 int KDeviceListItem::indexOf(KDeviceListItem *child) const 0061 { 0062 return d->children.indexOf(child); 0063 } 0064 0065 int KDeviceListItem::childCount() const 0066 { 0067 return d->children.count(); 0068 } 0069 0070 int KDeviceListItem::row() const 0071 { 0072 if (d->parent) { 0073 return d->parent->indexOf(const_cast<KDeviceListItem *>(this)); 0074 } else { 0075 return 0; 0076 } 0077 } 0078 0079 void KDeviceListItem::setParent(KDeviceListItem *parent) 0080 { 0081 if (d->parent) { 0082 d->parent->removeChild(this); 0083 } 0084 0085 d->parent = parent; 0086 0087 if (d->parent) { 0088 d->parent->appendChild(this); 0089 } 0090 } 0091 0092 KDeviceListItem *KDeviceListItem::parent() 0093 { 0094 return d->parent; 0095 } 0096 0097 void KDeviceListItem::setDevice(const Solid::Device &device) 0098 { 0099 d->device = device; 0100 } 0101 0102 Solid::Device &KDeviceListItem::device() 0103 { 0104 return d->device; 0105 } 0106 0107 void KDeviceListItem::appendChild(KDeviceListItem *child) 0108 { 0109 d->children.append(child); 0110 } 0111 0112 void KDeviceListItem::removeChild(KDeviceListItem *child) 0113 { 0114 d->children.removeAll(child); 0115 }