File indexing completed on 2024-06-23 04:42:35
0001 // SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com> 0002 // SPDX-License-Identifier: LGPL-2.1-or-later 0003 0004 #include "kalendar_debug.h" 0005 #include <Akonadi/ItemFetchJob> 0006 #include <Akonadi/ItemFetchScope> 0007 #include <KCalendarCore/Incidence> 0008 #include <QMetaEnum> 0009 #include <models/itemtagsmodel.h> 0010 0011 ItemTagsModel::ItemTagsModel(QObject *parent) 0012 : QAbstractListModel(parent) 0013 { 0014 } 0015 0016 Akonadi::Item ItemTagsModel::item() const 0017 { 0018 return m_item; 0019 } 0020 0021 void ItemTagsModel::setItem(Akonadi::Item item) 0022 { 0023 Q_EMIT layoutAboutToBeChanged(); 0024 m_item = item; 0025 Q_EMIT itemChanged(); 0026 Q_EMIT layoutChanged(); 0027 } 0028 0029 int ItemTagsModel::rowCount(const QModelIndex &parent) const 0030 { 0031 if (parent.isValid()) { 0032 return 0; 0033 } 0034 0035 return m_item.tags().count(); 0036 } 0037 0038 QVariant ItemTagsModel::data(const QModelIndex &idx, int role) const 0039 { 0040 if (!hasIndex(idx.row(), idx.column())) { 0041 return {}; 0042 } 0043 0044 const auto tag = m_item.tags().at(idx.row()); 0045 0046 switch (role) { 0047 case NameRole: 0048 return tag.name(); 0049 case IdRole: 0050 return tag.id(); 0051 default: 0052 qCWarning(KALENDAR_LOG) << "Unknown role for item tag:" << QMetaEnum::fromType<Roles>().valueToKey(role); 0053 return {}; 0054 } 0055 } 0056 0057 QHash<int, QByteArray> ItemTagsModel::roleNames() const 0058 { 0059 return { 0060 {NameRole, QByteArrayLiteral("name")}, 0061 {IdRole, QByteArrayLiteral("id")}, 0062 }; 0063 }