]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemmodelbase.cpp
Fix selection rect after porting from QFontMetrics::width()
[dolphin.git] / src / kitemviews / kitemmodelbase.cpp
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * Based on the Itemviews NG project from Trolltech Labs *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #include "kitemmodelbase.h"
23
24 KItemModelBase::KItemModelBase(QObject* parent) :
25 QObject(parent),
26 m_groupedSorting(false),
27 m_sortRole(),
28 m_sortOrder(Qt::AscendingOrder)
29 {
30 }
31
32 KItemModelBase::KItemModelBase(const QByteArray& sortRole, QObject* parent) :
33 QObject(parent),
34 m_groupedSorting(false),
35 m_sortRole(sortRole),
36 m_sortOrder(Qt::AscendingOrder)
37 {
38 }
39
40 KItemModelBase::~KItemModelBase()
41 {
42 }
43
44 bool KItemModelBase::setData(int index, const QHash<QByteArray, QVariant> &values)
45 {
46 Q_UNUSED(index)
47 Q_UNUSED(values)
48 return false;
49 }
50
51 void KItemModelBase::setGroupedSorting(bool grouped)
52 {
53 if (m_groupedSorting != grouped) {
54 m_groupedSorting = grouped;
55 onGroupedSortingChanged(grouped);
56 emit groupedSortingChanged(grouped);
57 }
58 }
59
60 bool KItemModelBase::groupedSorting() const
61 {
62 return m_groupedSorting;
63 }
64
65 void KItemModelBase::setSortRole(const QByteArray& role, bool resortItems)
66 {
67 if (role != m_sortRole) {
68 const QByteArray previous = m_sortRole;
69 m_sortRole = role;
70 onSortRoleChanged(role, previous, resortItems);
71 emit sortRoleChanged(role, previous);
72 }
73 }
74
75 QByteArray KItemModelBase::sortRole() const
76 {
77 return m_sortRole;
78 }
79
80 void KItemModelBase::setSortOrder(Qt::SortOrder order)
81 {
82 if (order != m_sortOrder) {
83 const Qt::SortOrder previous = m_sortOrder;
84 m_sortOrder = order;
85 onSortOrderChanged(order, previous);
86 emit sortOrderChanged(order, previous);
87 }
88 }
89
90 QString KItemModelBase::roleDescription(const QByteArray& role) const
91 {
92 return role;
93 }
94
95 QList<QPair<int, QVariant> > KItemModelBase::groups() const
96 {
97 return QList<QPair<int, QVariant> >();
98 }
99
100 bool KItemModelBase::setExpanded(int index, bool expanded)
101 {
102 Q_UNUSED(index)
103 Q_UNUSED(expanded)
104 return false;
105 }
106
107 bool KItemModelBase::isExpanded(int index) const
108 {
109 Q_UNUSED(index)
110 return false;
111 }
112
113 bool KItemModelBase::isExpandable(int index) const
114 {
115 Q_UNUSED(index)
116 return false;
117 }
118
119 int KItemModelBase::expandedParentsCount(int index) const
120 {
121 Q_UNUSED(index)
122 return 0;
123 }
124
125 QMimeData* KItemModelBase::createMimeData(const KItemSet& indexes) const
126 {
127 Q_UNUSED(indexes)
128 return nullptr;
129 }
130
131 int KItemModelBase::indexForKeyboardSearch(const QString& text, int startFromIndex) const
132 {
133 Q_UNUSED(text)
134 Q_UNUSED(startFromIndex)
135 return -1;
136 }
137
138 bool KItemModelBase::supportsDropping(int index) const
139 {
140 Q_UNUSED(index)
141 return false;
142 }
143
144 QString KItemModelBase::blacklistItemDropEventMimeType() const
145 {
146 return QStringLiteral("application/x-dolphin-blacklist-drop");
147 }
148
149 void KItemModelBase::onGroupedSortingChanged(bool current)
150 {
151 Q_UNUSED(current)
152 }
153
154 void KItemModelBase::onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems)
155 {
156 Q_UNUSED(current)
157 Q_UNUSED(previous)
158 Q_UNUSED(resortItems)
159 }
160
161 void KItemModelBase::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
162 {
163 Q_UNUSED(current)
164 Q_UNUSED(previous)
165 }
166
167 QUrl KItemModelBase::url(int index) const
168 {
169 return data(index).value("url").toUrl();
170 }
171
172 bool KItemModelBase::isDir(int index) const
173 {
174 return data(index).value("isDir").toBool();
175 }
176
177 QUrl KItemModelBase::directory() const
178 {
179 return QUrl();
180 }