]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kstandarditem.h
Summary: Fixes crash when hiding devices
[dolphin.git] / src / kitemviews / kstandarditem.h
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 #ifndef KSTANDARDITEM_H
21 #define KSTANDARDITEM_H
22
23 #include "dolphin_export.h"
24
25 #include <QByteArray>
26 #include <QHash>
27 #include <QObject>
28 #include <QVariant>
29
30 class KStandardItemModel;
31
32 /**
33 * @brief Represents and item of KStandardItemModel.
34 *
35 * Provides setter- and getter-methods for the most commonly
36 * used roles. It is possible to assign values for custom
37 * roles by using setDataValue().
38 */
39 class DOLPHIN_EXPORT KStandardItem : public QObject
40 {
41 Q_OBJECT
42 public:
43 explicit KStandardItem(KStandardItem* parent = nullptr);
44 explicit KStandardItem(const QString& text, KStandardItem* parent = nullptr);
45 KStandardItem(const QString& icon, const QString& text, KStandardItem* parent = nullptr);
46 virtual ~KStandardItem();
47
48 /**
49 * Sets the text for the "text"-role.
50 */
51 void setText(const QString& text);
52 QString text() const;
53
54 /**
55 * Sets the icon for the "iconName"-role.
56 */
57 void setIcon(const QString& icon);
58 QString icon() const;
59
60 void setIconOverlays(const QStringList& overlays);
61 QStringList iconOverlays() const;
62
63 /**
64 * Sets the group for the "group"-role.
65 */
66 void setGroup(const QString& group);
67 QString group() const;
68
69 void setDataValue(const QByteArray& role, const QVariant& value);
70 QVariant dataValue(const QByteArray& role) const;
71
72 void setData(const QHash<QByteArray, QVariant>& values);
73 QHash<QByteArray, QVariant> data() const;
74
75 protected:
76 virtual void onDataValueChanged(const QByteArray& role,
77 const QVariant& current,
78 const QVariant& previous);
79
80 virtual void onDataChanged(const QHash<QByteArray, QVariant>& current,
81 const QHash<QByteArray, QVariant>& previous);
82
83 private:
84 KStandardItemModel* m_model;
85
86 QHash<QByteArray, QVariant> m_data;
87
88 friend class KStandardItemModel;
89 };
90
91 #endif
92
93