1 /* This file is part of the KDE project
2 Copyright (C) 2005 Daniel Teske <teske@squorn.de>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) version 3.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>
18 #include "treeitem_p.h"
20 #include <QtCore/QVector>
22 TreeItem::TreeItem(const KBookmark
& bk
, TreeItem
* parent
)
23 : mparent(parent
), mbk(bk
)
34 TreeItem
* TreeItem::child(int row
)
38 if(row
< 0 || row
>= children
.count())
40 return children
.at(row
);
43 int TreeItem::childCount()
47 return children
.count();
50 TreeItem
* TreeItem::parent() const
55 void TreeItem::insertChildren(int first
, int last
)
57 // Find child number last
58 KBookmarkGroup parent
= bookmark().toGroup();
59 KBookmark child
= parent
.first();
60 for(int j
=0; j
< last
; ++j
)
61 child
= parent
.next(child
);
67 children
.insert(i
, new TreeItem(child
, this));
68 child
= parent
.previous(child
);
74 void TreeItem::deleteChildren(int first
, int last
)
76 QList
<TreeItem
*>::iterator firstIt
, lastIt
, it
;
77 firstIt
= children
.begin() + first
;
78 lastIt
= children
.begin() + last
+ 1;
79 for( it
= firstIt
; it
!= lastIt
; ++it
)
83 children
.erase(firstIt
, lastIt
);
86 KBookmark
TreeItem::bookmark() const
91 void TreeItem::initChildren()
96 KBookmarkGroup parent
= mbk
.toGroup();
97 for(KBookmark child
= parent
.first(); child
.hasParent(); child
= parent
.next(child
) )
99 TreeItem
* item
= new TreeItem(child
, this);
100 children
.append(item
);
105 TreeItem
* TreeItem::treeItemForBookmark(const KBookmark
& bk
)
107 if(bk
.address() == mbk
.address())
109 QString commonParent
= KBookmark::commonParent(bk
.address(), mbk
.address());
110 if(commonParent
== mbk
.address()) //mbk is a parent of bk
112 QList
<TreeItem
*>::const_iterator it
, end
;
113 end
= children
.constEnd();
114 for( it
= children
.constBegin(); it
!= end
; ++it
)
116 KBookmark child
= (*it
)->bookmark();
117 if( KBookmark::commonParent(child
.address(), bk
.address()) == child
.address())
118 return (*it
)->treeItemForBookmark(bk
);
126 return parent()->treeItemForBookmark(bk
);
130 // kate: space-indent on; indent-width 4; replace-tabs on;