2 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef KSTANDARDITEMMODEL_H
8 #define KSTANDARDITEMMODEL_H
10 #include "dolphin_export.h"
11 #include "kitemviews/kitemmodelbase.h"
19 * @brief Model counterpart for KStandardItemListView.
21 * Allows to add items to the model in an easy way by the
22 * class KStandardItem.
26 class DOLPHIN_EXPORT KStandardItemModel
: public KItemModelBase
31 explicit KStandardItemModel(QObject
* parent
= nullptr);
32 ~KStandardItemModel() override
;
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
41 void insertItem(int index
, KStandardItem
* item
);
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
49 void changeItem(int index
, KStandardItem
* item
);
51 void removeItem(int index
);
52 KStandardItem
* item(int index
) const;
53 int index(const KStandardItem
* item
) const;
56 * Convenience method for insertItem(count(), item).
58 void appendItem(KStandardItem
* item
);
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
;
72 * Is invoked after an item has been inserted and before the signal
73 * itemsInserted() gets emitted.
75 virtual void onItemInserted(int index
);
78 * Is invoked after an item or one of its roles has been changed and
79 * before the signal itemsChanged() gets emitted.
81 virtual void onItemChanged(int index
, const QSet
<QByteArray
>& changedRoles
);
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().
89 virtual void onItemRemoved(int index
, KStandardItem
* removedItem
);
92 QList
<KStandardItem
*> m_items
;
93 QHash
<const KStandardItem
*, int> m_indexesForItems
;
95 friend class KStandardItem
;
96 friend class KStandardItemModelTest
; // For unit testing