MauiKit Calendar

itemtagsmodel.cpp
1// SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#include "kalendar_debug.h"
5#include <Akonadi/ItemFetchJob>
6#include <Akonadi/ItemFetchScope>
7#include <KCalendarCore/Incidence>
8#include <QMetaEnum>
9#include <models/itemtagsmodel.h>
10
11ItemTagsModel::ItemTagsModel(QObject *parent)
12 : QAbstractListModel(parent)
13{
14}
15
16Akonadi::Item ItemTagsModel::item() const
17{
18 return m_item;
19}
20
21void ItemTagsModel::setItem(Akonadi::Item item)
22{
24 m_item = item;
25 Q_EMIT itemChanged();
27}
28
29int ItemTagsModel::rowCount(const QModelIndex &parent) const
30{
31 if (parent.isValid()) {
32 return 0;
33 }
34
35 return m_item.tags().count();
36}
37
38QVariant ItemTagsModel::data(const QModelIndex &idx, int role) const
39{
40 if (!hasIndex(idx.row(), idx.column())) {
41 return {};
42 }
43
44 const auto tag = m_item.tags().at(idx.row());
45
46 switch (role) {
47 case NameRole:
48 return tag.name();
49 case IdRole:
50 return tag.id();
51 default:
52 qCWarning(KALENDAR_LOG) << "Unknown role for item tag:" << QMetaEnum::fromType<Roles>().valueToKey(role);
53 return {};
54 }
55}
56
57QHash<int, QByteArray> ItemTagsModel::roleNames() const
58{
59 return {
60 {NameRole, QByteArrayLiteral("name")},
61 {IdRole, QByteArrayLiteral("id")},
62 };
63}
bool hasIndex(int row, int column, const QModelIndex &parent) const const
void layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
void layoutChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
QMetaEnum fromType()
const char * valueToKey(int value) const const
int column() const const
int row() const const
Q_EMITQ_EMIT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:07:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.