]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kstandarditemmodel.h
Configurable Show hidden files and folders last toggle
[dolphin.git] / src / kitemviews / kstandarditemmodel.h
1 /*
2 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef KSTANDARDITEMMODEL_H
8 #define KSTANDARDITEMMODEL_H
9
10 #include "dolphin_export.h"
11 #include "kitemviews/kitemmodelbase.h"
12
13 #include <QHash>
14 #include <QList>
15
16 class KStandardItem;
17
18 /**
19 * @brief Model counterpart for KStandardItemListView.
20 *
21 * Allows to add items to the model in an easy way by the
22 * class KStandardItem.
23 *
24 * @see KStandardItem
25 */
26 class DOLPHIN_EXPORT KStandardItemModel : public KItemModelBase
27 {
28 Q_OBJECT
29
30 public:
31 explicit KStandardItemModel(QObject* parent = nullptr);
32 ~KStandardItemModel() override;
33
34 /**
35 * Inserts the item \a item at the index \a index. If the index
36 * is equal to the number of items of the model, the item
37 * gets appended as last element. KStandardItemModel takes
38 * the ownership of the item. If the index is invalid, the item
39 * gets deleted.
40 */
41 void insertItem(int index, KStandardItem* item);
42
43 /**
44 * Changes the item on the index \a index to \a item.
45 * KStandardItemModel takes the ownership of the item. The
46 * old item gets deleted. If the index is invalid, the item
47 * gets deleted.
48 */
49 void changeItem(int index, KStandardItem* item);
50
51 void removeItem(int index);
52 KStandardItem* item(int index) const;
53 int index(const KStandardItem* item) const;
54
55 /**
56 * Convenience method for insertItem(count(), item).
57 */
58 void appendItem(KStandardItem* item);
59
60 int count() const override;
61 QHash<QByteArray, QVariant> data(int index) const override;
62 bool setData(int index, const QHash<QByteArray, QVariant>& values) override;
63 QMimeData* createMimeData(const KItemSet& indexes) const override;
64 int indexForKeyboardSearch(const QString& text, int startFromIndex = 0) const override;
65 bool supportsDropping(int index) const override;
66 QString roleDescription(const QByteArray& role) const override;
67 QList<QPair<int, QVariant> > groups() const override;
68
69 virtual void clear();
70 protected:
71 /**
72 * Is invoked after an item has been inserted and before the signal
73 * itemsInserted() gets emitted.
74 */
75 virtual void onItemInserted(int index);
76
77 /**
78 * Is invoked after an item or one of its roles has been changed and
79 * before the signal itemsChanged() gets emitted.
80 */
81 virtual void onItemChanged(int index, const QSet<QByteArray>& changedRoles);
82
83 /**
84 * Is invoked after an item has been removed and before the signal
85 * itemsRemoved() gets emitted. The item \a removedItem has already
86 * been removed from the model and will get deleted after the
87 * execution of onItemRemoved().
88 */
89 virtual void onItemRemoved(int index, KStandardItem* removedItem);
90
91 private:
92 QList<KStandardItem*> m_items;
93 QHash<const KStandardItem*, int> m_indexesForItems;
94
95 friend class KStandardItem;
96 friend class KStandardItemModelTest; // For unit testing
97 };
98
99 #endif
100
101