21 #include "tagmodel_p.h"
23 #include <akonadi/tagattribute.h>
25 #include <KLocalizedString>
28 using namespace Akonadi;
31 TagModel::TagModel(
Monitor *recorder, QObject *parent):
32 QAbstractItemModel(parent),
33 d_ptr(new TagModelPrivate(this))
39 TagModel::TagModel(
Monitor *recorder, TagModelPrivate *dd, QObject *parent):
40 QAbstractItemModel(parent),
52 int TagModel::columnCount(
const QModelIndex &parent )
const
54 if (parent.isValid() && parent.column() != 0) {
61 int TagModel::rowCount(
const QModelIndex &parent)
const
65 Tag::Id parentTagId = 0;
66 if (parent.isValid()) {
67 parentTagId = d->mChildTags[parent.internalId()].at(parent.row()).
id();
70 return d->mChildTags[parentTagId].count();
73 QVariant TagModel::headerData(
int section, Qt::Orientation orientation,
int role)
const
75 if (orientation == Qt::Vertical) {
79 if (role == Qt::DisplayRole) {
86 return QAbstractItemModel::headerData(section, orientation, role);
89 QVariant TagModel::data(
const QModelIndex &index,
int role)
const
93 const Tag tag = d->tagForIndex(index);
107 return QVariant::fromValue(tag.parent());
109 return QVariant::fromValue(tag);
110 case Qt::DecorationRole: {
113 return QIcon::fromTheme(attr->
iconName());
123 QModelIndex TagModel::index(
int row,
int column,
const QModelIndex &parent)
const
128 if (parent.isValid()) {
129 const Tag parentTag = d->tagForIndex(parent);
130 parentId = parentTag.
id();
133 const Tag::List &children = d->mChildTags.value(parentId);
134 if (row >= children.count()) {
135 return QModelIndex();
138 return createIndex(row, column, (
int) parentId);
141 QModelIndex TagModel::parent(
const QModelIndex &child)
const
145 if (!child.isValid()) {
146 return QModelIndex();
149 const qint64 parentId = child.internalId();
150 return d->indexForTag(parentId);
153 Qt::ItemFlags TagModel::flags(
const QModelIndex &index)
const
157 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
160 bool TagModel::insertColumns(
int,
int,
const QModelIndex&)
165 bool TagModel::insertRows(
int,
int,
const QModelIndex&)
170 bool TagModel::removeColumns(
int,
int,
const QModelIndex&)
175 bool TagModel::removeRows(
int,
int,
const QModelIndex&)
180 #include "moc_tagmodel.cpp"
Id id() const
Returns the unique identifier of the tag.
QString iconName() const
Returns the icon name of the icon returned by icon().
Attribute * attribute(const QByteArray &name) const
Returns the attribute of the given type name if available, 0 otherwise.
Attribute that stores the properties that are used to display a tag.
Monitors an item or collection for changes.