1 /*  This file is part of the KDE project
2     Copyright (C) 2006 Michael Larouche <michael.larouche@kdemail.net>
3                   2007 Kevin Ottens <ervin@kde.org>
4 
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License version 2 as published by the Free Software Foundation.
8 
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13 
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 
19 */
20 #include "kdevicelistitem_p.h"
21 
22 #include <solid/device.h>
23 
24 class KDeviceListItem::Private
25 {
26 public:
Private()27     Private() : parent(nullptr) {}
28 
~Private()29     ~Private()
30     {
31         qDeleteAll(children);
32     }
33 
34     Solid::Device device;
35     KDeviceListItem *parent;
36 
37     QList<KDeviceListItem *> children;
38 };
39 
KDeviceListItem()40 KDeviceListItem::KDeviceListItem()
41     : d(new Private)
42 {
43 }
44 
~KDeviceListItem()45 KDeviceListItem::~KDeviceListItem()
46 {
47     delete d;
48 }
49 
child(int row)50 KDeviceListItem *KDeviceListItem::child(int row)
51 {
52     return d->children.value(row);
53 }
54 
children()55 QList<KDeviceListItem *> KDeviceListItem::children()
56 {
57     return d->children;
58 }
59 
indexOf(KDeviceListItem * child) const60 int KDeviceListItem::indexOf(KDeviceListItem *child) const
61 {
62     return d->children.indexOf(child);
63 }
64 
childCount() const65 int KDeviceListItem::childCount() const
66 {
67     return d->children.count();
68 }
69 
row() const70 int KDeviceListItem::row() const
71 {
72     if (d->parent) {
73         return d->parent->indexOf(const_cast<KDeviceListItem *>(this));
74     } else {
75         return 0;
76     }
77 }
78 
setParent(KDeviceListItem * parent)79 void KDeviceListItem::setParent(KDeviceListItem *parent)
80 {
81     if (d->parent) {
82         d->parent->removeChild(this);
83     }
84 
85     d->parent = parent;
86 
87     if (d->parent) {
88         d->parent->appendChild(this);
89     }
90 }
91 
parent()92 KDeviceListItem *KDeviceListItem::parent()
93 {
94     return d->parent;
95 }
96 
setDevice(const Solid::Device & device)97 void KDeviceListItem::setDevice(const Solid::Device &device)
98 {
99     d->device = device;
100 }
101 
device()102 Solid::Device &KDeviceListItem::device()
103 {
104     return d->device;
105 }
106 
appendChild(KDeviceListItem * child)107 void KDeviceListItem::appendChild(KDeviceListItem *child)
108 {
109     d->children.append(child);
110 }
111 
removeChild(KDeviceListItem * child)112 void KDeviceListItem::removeChild(KDeviceListItem *child)
113 {
114     d->children.removeAll(child);
115 }
116