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 <libdolphin_export.h> |
24 | |
25 | #include <QByteArray> |
26 | #include <QHash> |
27 | #include <QIcon> |
28 | #include <QList> |
29 | #include <QVariant> |
30 | |
31 | class KStandardItemModel; |
32 | |
33 | /** |
34 | * @brief Represents and item of KStandardItemModel. |
35 | * |
36 | * Provides setter- and getter-methods for the most commonly |
37 | * used roles. It is possible to assign values for custom |
38 | * roles by using setDataValue(). |
39 | */ |
40 | class LIBDOLPHINPRIVATE_EXPORT KStandardItem |
41 | { |
42 | |
43 | public: |
44 | explicit KStandardItem(KStandardItem* parent = 0); |
45 | explicit KStandardItem(const QString& text, KStandardItem* parent = 0); |
46 | KStandardItem(const QString& icon, const QString& text, KStandardItem* parent = 0); |
47 | KStandardItem(const KStandardItem& item); |
48 | virtual ~KStandardItem(); |
49 | |
50 | /** |
51 | * Sets the text for the "text"-role. |
52 | */ |
53 | void setText(const QString& text); |
54 | QString text() const; |
55 | |
56 | /** |
57 | * Sets the icon for the "iconName"-role. |
58 | */ |
59 | void setIcon(const QString& icon); |
60 | QString icon() const; |
61 | |
62 | void setIconOverlays(const QStringList& overlays); |
63 | QStringList iconOverlays() const; |
64 | |
65 | /** |
66 | * Sets the group for the "group"-role. |
67 | */ |
68 | void setGroup(const QString& group); |
69 | QString group() const; |
70 | |
71 | void setDataValue(const QByteArray& role, const QVariant& value); |
72 | QVariant dataValue(const QByteArray& role) const; |
73 | |
74 | void setParent(KStandardItem* parent); |
75 | KStandardItem* parent() const; |
76 | |
77 | void setData(const QHash<QByteArray, QVariant>& values); |
78 | QHash<QByteArray, QVariant> data() const; |
79 | |
80 | QList<KStandardItem*> children() const; |
81 | |
82 | protected: |
83 | virtual void onDataValueChanged(const QByteArray& role, |
84 | const QVariant& current, |
85 | const QVariant& previous); |
86 | |
87 | virtual void onDataChanged(const QHash<QByteArray, QVariant>& current, |
88 | const QHash<QByteArray, QVariant>& previous); |
89 | |
90 | private: |
91 | KStandardItem* m_parent; |
92 | QList<KStandardItem*> m_children; |
93 | KStandardItemModel* m_model; |
94 | |
95 | QHash<QByteArray, QVariant> m_data; |
96 | |
97 | friend class KStandardItemModel; |
98 | }; |
99 | |
100 | #endif |
101 | |
102 | |
103 | |