]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kstandarditem.cpp
Port to QDebug*. KVBox--
[dolphin.git] / src / kitemviews / kstandarditem.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
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. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "kstandarditem.h"
21
22 #include <QDebug>
23 #include "kstandarditemmodel.h"
24
25 KStandardItem::KStandardItem(KStandardItem* parent) :
26 m_parent(parent),
27 m_children(),
28 m_model(0),
29 m_data()
30 {
31 }
32
33 KStandardItem::KStandardItem(const QString& text, KStandardItem* parent) :
34 m_parent(parent),
35 m_children(),
36 m_model(0),
37 m_data()
38 {
39 setText(text);
40 }
41
42 KStandardItem::KStandardItem(const QString& icon, const QString& text, KStandardItem* parent) :
43 m_parent(parent),
44 m_children(),
45 m_model(0),
46 m_data()
47 {
48 setIcon(icon);
49 setText(text);
50 }
51
52 KStandardItem::KStandardItem(const KStandardItem& item) :
53 m_parent(item.m_parent),
54 m_children(item.m_children),
55 m_model(item.m_model),
56 m_data(item.m_data)
57 {
58 }
59
60 KStandardItem::~KStandardItem()
61 {
62 }
63
64 void KStandardItem::setText(const QString& text)
65 {
66 setDataValue("text", text);
67 }
68
69 QString KStandardItem::text() const
70 {
71 return m_data["text"].toString();
72 }
73
74 void KStandardItem::setIcon(const QString& icon)
75 {
76 setDataValue("iconName", icon);
77 }
78
79 QString KStandardItem::icon() const
80 {
81 return m_data["iconName"].toString();
82 }
83
84 void KStandardItem::setIconOverlays(const QStringList& overlays)
85 {
86 setDataValue("iconOverlays", overlays);
87 }
88
89 QStringList KStandardItem::iconOverlays() const
90 {
91 return m_data["iconOverlays"].toStringList();
92 }
93
94 void KStandardItem::setGroup(const QString& group)
95 {
96 setDataValue("group", group);
97 }
98
99 QString KStandardItem::group() const
100 {
101 return m_data["group"].toString();
102 }
103
104 void KStandardItem::setDataValue(const QByteArray& role, const QVariant& value)
105 {
106 const QVariant previous = m_data.value(role);
107 if (previous == value) {
108 return;
109 }
110
111 m_data.insert(role, value);
112 onDataValueChanged(role, value, previous);
113
114 if (m_model) {
115 const int index = m_model->index(this);
116 QSet<QByteArray> changedRoles;
117 changedRoles.insert(role);
118 m_model->onItemChanged(index, changedRoles);
119 emit m_model->itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles);
120 }
121 }
122
123 QVariant KStandardItem::dataValue(const QByteArray& role) const
124 {
125 return m_data[role];
126 }
127
128 void KStandardItem::setParent(KStandardItem* parent)
129 {
130 // TODO: not implemented yet
131 m_parent = parent;
132 }
133
134 KStandardItem* KStandardItem::parent() const
135 {
136 return m_parent;
137 }
138
139 void KStandardItem::setData(const QHash<QByteArray, QVariant>& values)
140 {
141 const QHash<QByteArray, QVariant> previous = m_data;
142 m_data = values;
143 onDataChanged(values, previous);
144 }
145
146 QHash<QByteArray, QVariant> KStandardItem::data() const
147 {
148 return m_data;
149 }
150
151 QList<KStandardItem*> KStandardItem::children() const
152 {
153 return m_children;
154 }
155
156 void KStandardItem::onDataValueChanged(const QByteArray& role,
157 const QVariant& current,
158 const QVariant& previous)
159 {
160 Q_UNUSED(role);
161 Q_UNUSED(current);
162 Q_UNUSED(previous);
163 }
164
165 void KStandardItem::onDataChanged(const QHash<QByteArray, QVariant>& current,
166 const QHash<QByteArray, QVariant>& previous)
167 {
168 Q_UNUSED(current);
169 Q_UNUSED(previous);
170 }
171