21#include "tagmodel_p.h"
23#include <akonadi/tagattribute.h>
25#include <KLocalizedString>
30TagModel::TagModel(
Monitor *recorder, QObject *parent)
31 : QAbstractItemModel(parent)
32 , d_ptr(new TagModelPrivate(this))
38TagModel::TagModel(
Monitor *recorder, TagModelPrivate *dd, QObject *parent)
39 : QAbstractItemModel(parent)
51int TagModel::columnCount(
const QModelIndex &parent)
const
53 if (parent.isValid() && parent.column() != 0) {
60int TagModel::rowCount(
const QModelIndex &parent)
const
64 Tag::Id parentTagId = 0;
65 if (parent.isValid()) {
66 parentTagId = d->mChildTags[parent.internalId()].at(parent.row()).id();
69 return d->mChildTags[parentTagId].count();
72QVariant TagModel::headerData(
int section, Qt::Orientation orientation,
int role)
const
74 if (orientation == Qt::Vertical) {
78 if (role == Qt::DisplayRole) {
85 return QAbstractItemModel::headerData(section, orientation, role);
88QVariant TagModel::data(
const QModelIndex &index,
int role)
const
92 const Tag tag = d->tagForIndex(index);
106 return QVariant::fromValue(tag.parent());
108 return QVariant::fromValue(tag);
109 case Qt::DecorationRole: {
112 return QIcon::fromTheme(attr->
iconName());
122QModelIndex TagModel::index(
int row,
int column,
const QModelIndex &parent)
const
127 if (parent.isValid()) {
128 const Tag parentTag = d->tagForIndex(parent);
129 parentId = parentTag.
id();
132 const Tag::List &children = d->mChildTags.value(parentId);
133 if (row >= children.count()) {
134 return QModelIndex();
137 return createIndex(row, column, (
int) parentId);
140QModelIndex TagModel::parent(
const QModelIndex &child)
const
144 if (!child.isValid()) {
145 return QModelIndex();
148 const qint64 parentId = child.internalId();
149 return d->indexForTag(parentId);
152Qt::ItemFlags TagModel::flags(
const QModelIndex &index)
const
156 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
159bool TagModel::insertColumns(
int,
int,
const QModelIndex &)
164bool TagModel::insertRows(
int,
int,
const QModelIndex &)
169bool TagModel::removeColumns(
int,
int,
const QModelIndex &)
174bool TagModel::removeRows(
int,
int,
const QModelIndex &)
179#include "moc_tagmodel.cpp"
Monitors an item or collection for changes.
Attribute that stores the properties that are used to display a tag.
QString iconName() const
Returns the icon name of the icon returned by icon().
Id id() const
Returns the unique identifier of the tag.
FreeBusyManager::Singleton.