]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kstandarditemmodel.h
Fix several bookmark synchronization issues
[dolphin.git] / src / kitemviews / kstandarditemmodel.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 KSTANDARDITEMMODEL_H
21 #define KSTANDARDITEMMODEL_H
22
23 #include <libdolphin_export.h>
24 #include <kitemviews/kitemmodelbase.h>
25 #include <QHash>
26 #include <QList>
27
28 class KStandardItem;
29
30 /**
31 * @brief Model counterpart for KStandardItemView.
32 *
33 * Allows to add items to the model in an easy way by the
34 * class KStandardItem.
35 *
36 * @see KStandardItem
37 */
38 class LIBDOLPHINPRIVATE_EXPORT KStandardItemModel : public KItemModelBase
39 {
40 Q_OBJECT
41
42 public:
43 explicit KStandardItemModel(QObject* parent = 0);
44 virtual ~KStandardItemModel();
45
46 /**
47 * Inserts the item \a item at the index \a index. If the index
48 * is equal to the number of items of the model, the item
49 * gets appended as last element. KStandardItemModel takes
50 * the ownership of the item.
51 */
52 void insertItem(int index, KStandardItem* item);
53
54 /**
55 * Changes the item on the index \a index to \a item.
56 * KStandardItemModel takes the ownership of the item. The
57 * old item gets deleted.
58 */
59 void changeItem(int index, KStandardItem* item);
60
61 void removeItem(int index);
62 KStandardItem* item(int index) const;
63 int index(const KStandardItem* item) const;
64
65 /**
66 * Convenience method for insertItem(count(), item).
67 */
68 void appendItem(KStandardItem* item);
69
70 virtual int count() const;
71 virtual QHash<QByteArray, QVariant> data(int index) const;
72 virtual bool setData(int index, const QHash<QByteArray, QVariant>& values);
73 virtual QMimeData* createMimeData(const QSet<int>& indexes) const;
74 virtual int indexForKeyboardSearch(const QString& text, int startFromIndex = 0) const;
75 virtual bool supportsDropping(int index) const;
76 virtual QString roleDescription(const QByteArray& role) const;
77 virtual QList<QPair<int, QVariant> > groups() const;
78
79 protected:
80 /**
81 * Is invoked after an item has been inserted and before the signal
82 * itemsInserted() gets emitted.
83 */
84 virtual void onItemInserted(int index);
85
86 /**
87 * Is invoked after an item or one of its roles has been changed and
88 * before the signal itemsChanged() gets emitted.
89 */
90 virtual void onItemChanged(int index, const QSet<QByteArray>& changedRoles);
91
92 /**
93 * Is invoked after an item has been removed and before the signal
94 * itemsRemoved() gets emitted. The item \a removedItem has already
95 * been removed from the model and will get deleted after the
96 * execution of onItemRemoved().
97 */
98 virtual void onItemRemoved(int index, KStandardItem* removedItem);
99
100 private:
101 QList<KStandardItem*> m_items;
102 QHash<const KStandardItem*, int> m_indexesForItems;
103
104 friend class KStandardItem;
105 };
106
107 #endif
108
109