1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #ifndef KSTANDARDITEMMODEL_H
21 #define KSTANDARDITEMMODEL_H
23 #include "dolphin_export.h"
24 #include <kitemviews/kitemmodelbase.h>
31 * @brief Model counterpart for KStandardItemView.
33 * Allows to add items to the model in an easy way by the
34 * class KStandardItem.
38 class DOLPHIN_EXPORT KStandardItemModel
: public KItemModelBase
43 explicit KStandardItemModel(QObject
* parent
= 0);
44 ~KStandardItemModel() override
;
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. If the index is invalid, the item
53 void insertItem(int index
, KStandardItem
* item
);
56 * Changes the item on the index \a index to \a item.
57 * KStandardItemModel takes the ownership of the item. The
58 * old item gets deleted. If the index is invalid, the item
61 void changeItem(int index
, KStandardItem
* item
);
63 void removeItem(int index
);
64 KStandardItem
* item(int index
) const;
65 int index(const KStandardItem
* item
) const;
68 * Convenience method for insertItem(count(), item).
70 void appendItem(KStandardItem
* item
);
72 int count() const override
;
73 QHash
<QByteArray
, QVariant
> data(int index
) const override
;
74 bool setData(int index
, const QHash
<QByteArray
, QVariant
>& values
) override
;
75 QMimeData
* createMimeData(const KItemSet
& indexes
) const override
;
76 int indexForKeyboardSearch(const QString
& text
, int startFromIndex
= 0) const override
;
77 bool supportsDropping(int index
) const override
;
78 QString
roleDescription(const QByteArray
& role
) const override
;
79 QList
<QPair
<int, QVariant
> > groups() const override
;
84 * Is invoked after an item has been inserted and before the signal
85 * itemsInserted() gets emitted.
87 virtual void onItemInserted(int index
);
90 * Is invoked after an item or one of its roles has been changed and
91 * before the signal itemsChanged() gets emitted.
93 virtual void onItemChanged(int index
, const QSet
<QByteArray
>& changedRoles
);
96 * Is invoked after an item has been removed and before the signal
97 * itemsRemoved() gets emitted. The item \a removedItem has already
98 * been removed from the model and will get deleted after the
99 * execution of onItemRemoved().
101 virtual void onItemRemoved(int index
, KStandardItem
* removedItem
);
104 QList
<KStandardItem
*> m_items
;
105 QHash
<const KStandardItem
*, int> m_indexesForItems
;
107 friend class KStandardItem
;
108 friend class KStandardItemModelTest
; // For unit testing