1 /* SPDX-FileCopyrightText: 2014 Jesper K. Pedersen <blackie@kde.org>
2 
3    SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "CategoryModel.h"
7 #include "ScreenInfo.h"
8 using namespace RemoteControl;
9 
CategoryModel(QObject * parent)10 CategoryModel::CategoryModel(QObject *parent)
11     : QAbstractListModel(parent)
12 {
13 }
14 
rowCount(const QModelIndex & parent) const15 int CategoryModel::rowCount(const QModelIndex &parent) const
16 {
17     Q_UNUSED(parent);
18     return m_categories.count();
19 }
20 
data(const QModelIndex & index,int role) const21 QVariant CategoryModel::data(const QModelIndex &index, int role) const
22 {
23     const Category &item = m_categories[index.row()];
24     if (role == NameRole)
25         return item.name;
26     else if (role == IconRole)
27         return item.icon;
28     else if (role == EnabledRole)
29         return item.enabled;
30     else if (role == TypeRole)
31         return item.viewType;
32     return {};
33 }
34 
roleNames() const35 RoleMap RemoteControl::CategoryModel::roleNames() const
36 {
37     return { { NameRole, "name" }, { IconRole, "icon" }, { EnabledRole, "enabled" }, { TypeRole, "type" } };
38 }
39 
setCategories(const QList<Category> & categories)40 void CategoryModel::setCategories(const QList<Category> &categories)
41 {
42     beginResetModel();
43     m_categories = categories;
44     endResetModel();
45     emit hasDataChanged();
46 }
47 
hasData() const48 bool CategoryModel::hasData() const
49 {
50     return rowCount(QModelIndex()) != 0;
51 }
52