]>
cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kstandarditemmodel.cpp
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 #include "kstandarditemmodel.h"
21 #include "kstandarditem.h"
23 KStandardItemModel::KStandardItemModel(QObject
* parent
) :
24 KItemModelBase(parent
),
30 KStandardItemModel::~KStandardItemModel()
34 void KStandardItemModel::insertItem(int index
, KStandardItem
* item
)
36 if (!m_indexesForItems
.contains(item
) && !item
->m_model
) {
37 m_items
.insert(index
, item
);
38 m_indexesForItems
.insert(item
, index
);
40 // TODO: no hierarchical items are handled yet
42 emit
itemsInserted(KItemRangeList() << KItemRange(index
, 1));
46 void KStandardItemModel::appendItem(KStandardItem
*item
)
48 insertItem(m_items
.count(), item
);
51 void KStandardItemModel::removeItem(KStandardItem
* item
)
53 const int index
= m_indexesForItems
.value(item
, -1);
55 m_items
.removeAt(index
);
56 m_indexesForItems
.remove(item
);
58 // TODO: no hierarchical items are handled yet
62 KStandardItem
* KStandardItemModel::item(int index
) const
64 if (index
< 0 || index
>= m_items
.count()) {
67 return m_items
[index
];
70 int KStandardItemModel::index(const KStandardItem
* item
) const
72 return m_indexesForItems
.value(item
, -1);
75 int KStandardItemModel::count() const
77 return m_items
.count();
80 QHash
<QByteArray
, QVariant
> KStandardItemModel::data(int index
) const
82 const KStandardItem
* item
= m_items
[index
];
86 return QHash
<QByteArray
, QVariant
>();
89 bool KStandardItemModel::setData(int index
, const QHash
<QByteArray
, QVariant
>& values
)
92 if (index
< 0 || index
>= count()) {
99 QMimeData
* KStandardItemModel::createMimeData(const QSet
<int>& indexes
) const
105 int KStandardItemModel::indexForKeyboardSearch(const QString
& text
, int startFromIndex
) const
108 Q_UNUSED(startFromIndex
);
112 bool KStandardItemModel::supportsDropping(int index
) const
118 QString
KStandardItemModel::roleDescription(const QByteArray
& role
) const
124 QList
<QPair
<int, QVariant
> > KStandardItemModel::groups() const
126 QList
<QPair
<int, QVariant
> > groups
;
128 const QByteArray role
= sortRole();
129 bool isFirstGroupValue
= true;
131 const int maxIndex
= count() - 1;
132 for (int i
= 0; i
<= maxIndex
; ++i
) {
133 const QString newGroupValue
= m_items
.at(i
)->dataValue(role
).toString();
134 if (newGroupValue
!= groupValue
|| isFirstGroupValue
) {
135 groupValue
= newGroupValue
;
136 groups
.append(QPair
<int, QVariant
>(i
, newGroupValue
));
137 isFirstGroupValue
= false;
144 #include "kstandarditemmodel.moc"