]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kstandarditem.cpp
Fix selection rect after porting from QFontMetrics::width()
[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 QObject(parent),
25 m_model(nullptr),
26 m_data()
27 {
28 }
29
30 KStandardItem::KStandardItem(const QString& text, KStandardItem* parent) :
31 QObject(parent),
32 m_model(nullptr),
33 m_data()
34 {
35 setText(text);
36 }
37
38 KStandardItem::KStandardItem(const QString& icon, const QString& text, KStandardItem* parent) :
39 QObject(parent),
40 m_model(nullptr),
41 m_data()
42 {
43 setIcon(icon);
44 setText(text);
45 }
46
47 KStandardItem::~KStandardItem()
48 {
49 }
50
51 void KStandardItem::setText(const QString& text)
52 {
53 setDataValue("text", text);
54 }
55
56 QString KStandardItem::text() const
57 {
58 return m_data["text"].toString();
59 }
60
61 void KStandardItem::setIcon(const QString& icon)
62 {
63 setDataValue("iconName", icon);
64 }
65
66 QString KStandardItem::icon() const
67 {
68 return m_data["iconName"].toString();
69 }
70
71 void KStandardItem::setIconOverlays(const QStringList& overlays)
72 {
73 setDataValue("iconOverlays", overlays);
74 }
75
76 QStringList KStandardItem::iconOverlays() const
77 {
78 return m_data["iconOverlays"].toStringList();
79 }
80
81 void KStandardItem::setGroup(const QString& group)
82 {
83 setDataValue("group", group);
84 }
85
86 QString KStandardItem::group() const
87 {
88 return m_data["group"].toString();
89 }
90
91 void KStandardItem::setDataValue(const QByteArray& role, const QVariant& value)
92 {
93 const QVariant previous = m_data.value(role);
94 if (previous == value) {
95 return;
96 }
97
98 m_data.insert(role, value);
99 onDataValueChanged(role, value, previous);
100
101 if (m_model) {
102 const int index = m_model->index(this);
103 QSet<QByteArray> changedRoles;
104 changedRoles.insert(role);
105 m_model->onItemChanged(index, changedRoles);
106 emit m_model->itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles);
107 }
108 }
109
110 QVariant KStandardItem::dataValue(const QByteArray& role) const
111 {
112 return m_data[role];
113 }
114
115 void KStandardItem::setData(const QHash<QByteArray, QVariant>& values)
116 {
117 const QHash<QByteArray, QVariant> previous = m_data;
118 m_data = values;
119 onDataChanged(values, previous);
120 }
121
122 QHash<QByteArray, QVariant> KStandardItem::data() const
123 {
124 return m_data;
125 }
126
127 void KStandardItem::onDataValueChanged(const QByteArray& role,
128 const QVariant& current,
129 const QVariant& previous)
130 {
131 Q_UNUSED(role)
132 Q_UNUSED(current)
133 Q_UNUSED(previous)
134 }
135
136 void KStandardItem::onDataChanged(const QHash<QByteArray, QVariant>& current,
137 const QHash<QByteArray, QVariant>& previous)
138 {
139 Q_UNUSED(current)
140 Q_UNUSED(previous)
141 }
142