]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kstandarditem.cpp
Merge branch 'Applications/18.04'
[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 #include "kstandarditemmodel.h"
22
23 KStandardItem::KStandardItem(KStandardItem* parent) :
24 m_parent(parent),
25 m_children(),
26 m_model(nullptr),
27 m_data()
28 {
29 }
30
31 KStandardItem::KStandardItem(const QString& text, KStandardItem* parent) :
32 m_parent(parent),
33 m_children(),
34 m_model(nullptr),
35 m_data()
36 {
37 setText(text);
38 }
39
40 KStandardItem::KStandardItem(const QString& icon, const QString& text, KStandardItem* parent) :
41 m_parent(parent),
42 m_children(),
43 m_model(nullptr),
44 m_data()
45 {
46 setIcon(icon);
47 setText(text);
48 }
49
50 KStandardItem::KStandardItem(const KStandardItem& item) :
51 m_parent(item.m_parent),
52 m_children(item.m_children),
53 m_model(item.m_model),
54 m_data(item.m_data)
55 {
56 }
57
58 KStandardItem::~KStandardItem()
59 {
60 }
61
62 void KStandardItem::setText(const QString& text)
63 {
64 setDataValue("text", text);
65 }
66
67 QString KStandardItem::text() const
68 {
69 return m_data["text"].toString();
70 }
71
72 void KStandardItem::setIcon(const QString& icon)
73 {
74 setDataValue("iconName", icon);
75 }
76
77 QString KStandardItem::icon() const
78 {
79 return m_data["iconName"].toString();
80 }
81
82 void KStandardItem::setIconOverlays(const QStringList& overlays)
83 {
84 setDataValue("iconOverlays", overlays);
85 }
86
87 QStringList KStandardItem::iconOverlays() const
88 {
89 return m_data["iconOverlays"].toStringList();
90 }
91
92 void KStandardItem::setGroup(const QString& group)
93 {
94 setDataValue("group", group);
95 }
96
97 QString KStandardItem::group() const
98 {
99 return m_data["group"].toString();
100 }
101
102 void KStandardItem::setDataValue(const QByteArray& role, const QVariant& value)
103 {
104 const QVariant previous = m_data.value(role);
105 if (previous == value) {
106 return;
107 }
108
109 m_data.insert(role, value);
110 onDataValueChanged(role, value, previous);
111
112 if (m_model) {
113 const int index = m_model->index(this);
114 QSet<QByteArray> changedRoles;
115 changedRoles.insert(role);
116 m_model->onItemChanged(index, changedRoles);
117 emit m_model->itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles);
118 }
119 }
120
121 QVariant KStandardItem::dataValue(const QByteArray& role) const
122 {
123 return m_data[role];
124 }
125
126 void KStandardItem::setParent(KStandardItem* parent)
127 {
128 // TODO: not implemented yet
129 m_parent = parent;
130 }
131
132 KStandardItem* KStandardItem::parent() const
133 {
134 return m_parent;
135 }
136
137 void KStandardItem::setData(const QHash<QByteArray, QVariant>& values)
138 {
139 const QHash<QByteArray, QVariant> previous = m_data;
140 m_data = values;
141 onDataChanged(values, previous);
142 }
143
144 QHash<QByteArray, QVariant> KStandardItem::data() const
145 {
146 return m_data;
147 }
148
149 QList<KStandardItem*> KStandardItem::children() const
150 {
151 return m_children;
152 }
153
154 void KStandardItem::onDataValueChanged(const QByteArray& role,
155 const QVariant& current,
156 const QVariant& previous)
157 {
158 Q_UNUSED(role);
159 Q_UNUSED(current);
160 Q_UNUSED(previous);
161 }
162
163 void KStandardItem::onDataChanged(const QHash<QByteArray, QVariant>& current,
164 const QHash<QByteArray, QVariant>& previous)
165 {
166 Q_UNUSED(current);
167 Q_UNUSED(previous);
168 }
169