LeechCraft  %{LEECHCRAFT_VERSION}
Modular cross-platform feature rich live environment.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
treeitem.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #include "treeitem.h"
31 #include <QStringList>
32 #include <QDebug>
33 
34 using namespace LeechCraft::Util;
35 
37 : Parent_ (parent)
38 {
39  Data_ [Qt::DisplayRole] = data.toVector ();
40 }
41 
43 {
44  qDeleteAll (Children_);
45 }
46 
48 {
49  Children_.append (child);
50 }
51 
53 {
54  Children_.prepend (child);
55 }
56 
57 void TreeItem::InsertChild (int index, TreeItem *child)
58 {
59  Children_.insert (index, child);
60 }
61 
62 int TreeItem::ChildPosition (const TreeItem *child) const
63 {
64  return Children_.indexOf (const_cast<TreeItem*> (child));
65 }
66 
67 void TreeItem::RemoveChild (int child)
68 {
69  delete Children_.takeAt (child);
70 }
71 
72 TreeItem* TreeItem::Child (int row) const
73 {
74  return Children_.value (row);
75 }
76 
78 {
79  return Children_.count ();
80 }
81 
82 int TreeItem::ColumnCount (int role) const
83 {
84  return Data_ [role].count ();
85 }
86 
87 QVariant TreeItem::Data (int column, int role) const
88 {
89  return Data_ [role].value (column);
90 }
91 
92 void TreeItem::ModifyData (int column, const QVariant& data, int role)
93 {
94  if (Data_ [role].size () <= column)
95  Data_ [role].resize (column + 1);
96  Data_ [role] [column] = data;
97 }
98 
99 const TreeItem* TreeItem::Parent () const
100 {
101  return Parent_;
102 }
103 
105 {
106  return Parent_;
107 }
108 
109 int TreeItem::Row () const
110 {
111  if (Parent_)
112  return Parent_->Children_.indexOf (const_cast<TreeItem*> (this));
113  return 0;
114 }
115 
116 QDebug operator<< (QDebug dbg, const LeechCraft::Util::TreeItem& item)
117 {
118  dbg.nospace () << "{ TreeItem| Parent:"
119  << item.Parent ();
120  dbg.nospace () << "; Children:"
121  << item.ChildCount ();
122  dbg.nospace () << "; Data[0]:"
123  << (item.ColumnCount () ? item.Data (0) : QString ("<no columns>"))
124  << "}";
125  return dbg.space ();
126 }
127 
128 QDebug operator<< (QDebug dbg, const LeechCraft::Util::TreeItem* const pitem)
129 {
130  dbg.nospace () << "TreeItem @ "
131  << static_cast<const void* const> (pitem)
132  << ";";
133  if (pitem)
134  dbg << *pitem;
135  return dbg.space ();
136 }
137 
UTIL_MODELS_API void AppendChild(TreeItem *)
Definition: treeitem.cpp:47
UTIL_MODELS_API void InsertChild(int, TreeItem *)
Definition: treeitem.cpp:57
UTIL_MODELS_API ~TreeItem()
Definition: treeitem.cpp:42
UTIL_MODELS_API int ChildPosition(const TreeItem *) const
Definition: treeitem.cpp:62
UTIL_MODELS_API const TreeItem * Parent() const
Definition: treeitem.cpp:99
QDebug operator<<(QDebug dbg, const LeechCraft::Util::TreeItem &item)
Definition: treeitem.cpp:116
UTIL_MODELS_API int ChildCount() const
Definition: treeitem.cpp:77
UTIL_MODELS_API void ModifyData(int, const QVariant &, int=Qt::DisplayRole)
Definition: treeitem.cpp:92
UTIL_MODELS_API int Row() const
Definition: treeitem.cpp:109
UTIL_MODELS_API void RemoveChild(int)
Definition: treeitem.cpp:67
UTIL_MODELS_API void PrependChild(TreeItem *)
Definition: treeitem.cpp:52
UTIL_MODELS_API QVariant Data(int, int=Qt::DisplayRole) const
Definition: treeitem.cpp:87
UTIL_MODELS_API int ColumnCount(int=Qt::DisplayRole) const
Definition: treeitem.cpp:82
UTIL_MODELS_API TreeItem * Child(int) const
Definition: treeitem.cpp:72
UTIL_MODELS_API TreeItem(const QList< QVariant > &, TreeItem *parent=0)
Definition: treeitem.cpp:36