File indexing completed on 2024-04-28 15:39:41

0001 // SPDX-FileCopyrightText: 2014-2022 Jesper K. Pedersen <blackie@kde.org>
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 #include "CategoryModel.h"
0006 #include "ScreenInfo.h"
0007 using namespace RemoteControl;
0008 
0009 CategoryModel::CategoryModel(QObject *parent)
0010     : QAbstractListModel(parent)
0011 {
0012 }
0013 
0014 int CategoryModel::rowCount(const QModelIndex &parent) const
0015 {
0016     Q_UNUSED(parent);
0017     return m_categories.count();
0018 }
0019 
0020 QVariant CategoryModel::data(const QModelIndex &index, int role) const
0021 {
0022     const Category &item = m_categories[index.row()];
0023     if (role == NameRole)
0024         return item.name;
0025     else if (role == IconRole)
0026         return item.icon;
0027     else if (role == EnabledRole)
0028         return item.enabled;
0029     else if (role == TypeRole)
0030         return item.viewType;
0031     return {};
0032 }
0033 
0034 RoleMap RemoteControl::CategoryModel::roleNames() const
0035 {
0036     return { { NameRole, "name" }, { IconRole, "icon" }, { EnabledRole, "enabled" }, { TypeRole, "type" } };
0037 }
0038 
0039 void CategoryModel::setCategories(const QList<Category> &categories)
0040 {
0041     beginResetModel();
0042     m_categories = categories;
0043     endResetModel();
0044     Q_EMIT hasDataChanged();
0045 }
0046 
0047 bool CategoryModel::hasData() const
0048 {
0049     return rowCount(QModelIndex()) != 0;
0050 }
0051 
0052 #include "moc_CategoryModel.cpp"