2
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
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 or (at your option)
7
* version 3 of the License.
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, see <http://www.gnu.org/licenses/>.
18
#include "IconModels.h"
22
#include "gui/DatabaseIcons.h"
24
DefaultIconModel::DefaultIconModel(QObject* parent)
25
: QAbstractListModel(parent)
29
int DefaultIconModel::rowCount(const QModelIndex& parent) const
31
if (!parent.isValid()) {
32
return databaseIcons()->count();
38
QVariant DefaultIconModel::data(const QModelIndex& index, int role) const
40
if (!index.isValid()) {
44
Q_ASSERT(index.row() < databaseIcons()->count());
46
if (role == Qt::DecorationRole) {
47
return databaseIcons()->icon(index.row(), IconSize::Medium);
53
CustomIconModel::CustomIconModel(QObject* parent)
54
: QAbstractListModel(parent)
58
void CustomIconModel::setIcons(const QHash<QUuid, QPixmap>& icons, const QList<QUuid>& iconsOrder)
63
m_iconsOrder = iconsOrder;
64
Q_ASSERT(m_icons.count() == m_iconsOrder.count());
69
int CustomIconModel::rowCount(const QModelIndex& parent) const
71
if (!parent.isValid()) {
72
return m_icons.size();
78
QVariant CustomIconModel::data(const QModelIndex& index, int role) const
80
if (!index.isValid()) {
84
if (role == Qt::DecorationRole) {
85
QUuid uuid = uuidFromIndex(index);
86
return m_icons.value(uuid);
92
QUuid CustomIconModel::uuidFromIndex(const QModelIndex& index) const
94
Q_ASSERT(index.isValid());
96
return m_iconsOrder.value(index.row());
99
QModelIndex CustomIconModel::indexFromUuid(const QUuid& uuid) const
101
int idx = m_iconsOrder.indexOf(uuid);
103
return index(idx, 0);