KIO
kdevicelistitem.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE project 00002 Copyright (C) 2006 Michael Larouche <michael.larouche@kdemail.net> 00003 2007 Kevin Ottens <ervin@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 00019 */ 00020 #include "kdevicelistitem_p.h" 00021 00022 #include <solid/device.h> 00023 00024 class KDeviceListItem::Private 00025 { 00026 public: 00027 Private() : parent(0) {} 00028 00029 ~Private() 00030 { 00031 qDeleteAll(children); 00032 } 00033 00034 Solid::Device device; 00035 KDeviceListItem *parent; 00036 00037 QList<KDeviceListItem*> children; 00038 }; 00039 00040 KDeviceListItem::KDeviceListItem() 00041 : d(new Private) 00042 { 00043 } 00044 00045 KDeviceListItem::~KDeviceListItem() 00046 { 00047 delete d; 00048 } 00049 00050 KDeviceListItem *KDeviceListItem::child(int row) 00051 { 00052 return d->children.value(row); 00053 } 00054 00055 QList<KDeviceListItem*> KDeviceListItem::children() 00056 { 00057 return d->children; 00058 } 00059 00060 int KDeviceListItem::indexOf(KDeviceListItem *child) const 00061 { 00062 return d->children.indexOf(child); 00063 } 00064 00065 int KDeviceListItem::childCount() const 00066 { 00067 return d->children.count(); 00068 } 00069 00070 int KDeviceListItem::row() const 00071 { 00072 if (d->parent) { 00073 return d->parent->indexOf(const_cast<KDeviceListItem*>(this)); 00074 } else { 00075 return 0; 00076 } 00077 } 00078 00079 void KDeviceListItem::setParent(KDeviceListItem *parent) 00080 { 00081 if (d->parent) { 00082 d->parent->removeChild(this); 00083 } 00084 00085 d->parent = parent; 00086 00087 if (d->parent) { 00088 d->parent->appendChild(this); 00089 } 00090 } 00091 00092 KDeviceListItem *KDeviceListItem::parent() 00093 { 00094 return d->parent; 00095 } 00096 00097 void KDeviceListItem::setDevice(const Solid::Device &device) 00098 { 00099 d->device = device; 00100 } 00101 00102 Solid::Device &KDeviceListItem::device() 00103 { 00104 return d->device; 00105 } 00106 00107 void KDeviceListItem::appendChild(KDeviceListItem *child) 00108 { 00109 d->children.append(child); 00110 } 00111 00112 void KDeviceListItem::removeChild(KDeviceListItem *child) 00113 { 00114 d->children.removeAll(child); 00115 }