• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.13.3 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
tagmodel.cpp
1 /*
2  Copyright (c) 2014 Daniel Vrátil <dvratil@redhat.com>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "tagmodel.h"
21 #include "tagmodel_p.h"
22 
23 #include <akonadi/tagattribute.h>
24 
25 #include <KLocalizedString>
26 #include <QIcon>
27 
28 using namespace Akonadi;
29 
30 
31 TagModel::TagModel(Monitor *recorder, QObject *parent):
32  QAbstractItemModel(parent),
33  d_ptr(new TagModelPrivate(this))
34 {
35  Q_D(TagModel);
36  d->init(recorder);
37 }
38 
39 TagModel::TagModel(Monitor *recorder, TagModelPrivate *dd, QObject *parent):
40  QAbstractItemModel(parent),
41  d_ptr(dd)
42 {
43  Q_D(TagModel);
44  d->init(recorder);
45 }
46 
47 TagModel::~TagModel()
48 {
49  delete d_ptr;
50 }
51 
52 int TagModel::columnCount( const QModelIndex &parent ) const
53 {
54  if (parent.isValid() && parent.column() != 0) {
55  return 0;
56  }
57 
58  return 1;
59 }
60 
61 int TagModel::rowCount(const QModelIndex &parent) const
62 {
63  Q_D(const TagModel);
64 
65  Tag::Id parentTagId = 0;
66  if (parent.isValid()) {
67  parentTagId = d->mChildTags[parent.internalId()].at(parent.row()).id();
68  }
69 
70  return d->mChildTags[parentTagId].count();
71 }
72 
73 QVariant TagModel::headerData(int section, Qt::Orientation orientation, int role) const
74 {
75  if (orientation == Qt::Vertical) {
76  return QVariant();
77  }
78 
79  if (role == Qt::DisplayRole) {
80  switch (section) {
81  case 0:
82  return i18n("Tag");
83  }
84  }
85 
86  return QAbstractItemModel::headerData(section, orientation, role);
87 }
88 
89 QVariant TagModel::data(const QModelIndex &index, int role) const
90 {
91  Q_D(const TagModel);
92 
93  const Tag tag = d->tagForIndex(index);
94  if (!tag.isValid()) {
95  return QVariant();
96  }
97 
98  switch (role) {
99  case Qt::DisplayRole: // fall-through
100  case NameRole:
101  return tag.name();
102  case IdRole:
103  return tag.id();
104  case GIDRole:
105  return tag.gid();
106  case ParentRole:
107  return QVariant::fromValue(tag.parent());
108  case TagRole:
109  return QVariant::fromValue(tag);
110  case Qt::DecorationRole: {
111  TagAttribute *attr = tag.attribute<TagAttribute>();
112  if (attr) {
113  return QIcon::fromTheme(attr->iconName());
114  } else {
115  return QVariant();
116  }
117  }
118  }
119 
120  return QVariant();
121 }
122 
123 QModelIndex TagModel::index(int row, int column, const QModelIndex &parent) const
124 {
125  Q_D(const TagModel);
126 
127  qint64 parentId = 0;
128  if (parent.isValid()) {
129  const Tag parentTag = d->tagForIndex(parent);
130  parentId = parentTag.id();
131  }
132 
133  const Tag::List &children = d->mChildTags.value(parentId);
134  if (row >= children.count()) {
135  return QModelIndex();
136  }
137 
138  return createIndex(row, column, (int) parentId);
139 }
140 
141 QModelIndex TagModel::parent(const QModelIndex &child) const
142 {
143  Q_D(const TagModel);
144 
145  if (!child.isValid()) {
146  return QModelIndex();
147  }
148 
149  const qint64 parentId = child.internalId();
150  return d->indexForTag(parentId);
151 }
152 
153 Qt::ItemFlags TagModel::flags(const QModelIndex &index) const
154 {
155  Q_UNUSED(index);
156 
157  return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
158 }
159 
160 bool TagModel::insertColumns(int, int, const QModelIndex&)
161 {
162  return false;
163 }
164 
165 bool TagModel::insertRows(int, int, const QModelIndex&)
166 {
167  return false;
168 }
169 
170 bool TagModel::removeColumns(int, int, const QModelIndex&)
171 {
172  return false;
173 }
174 
175 bool TagModel::removeRows(int, int, const QModelIndex&)
176 {
177  return false;
178 }
179 
180 #include "moc_tagmodel.cpp"
Akonadi::Tag::id
Id id() const
Returns the unique identifier of the tag.
Definition: tag.cpp:131
Akonadi::TagAttribute::iconName
QString iconName() const
Returns the icon name of the icon returned by icon().
Definition: tagattribute.cpp:66
Akonadi::AttributeEntity::attribute
Attribute * attribute(const QByteArray &name) const
Returns the attribute of the given type name if available, 0 otherwise.
Definition: attributeentity.cpp:113
Akonadi::TagAttribute
Attribute that stores the properties that are used to display a tag.
Definition: tagattribute.h:38
Akonadi::Monitor
Monitors an item or collection for changes.
Definition: monitor.h:75
Akonadi::Tag
An Akonadi Tag.
Definition: tag.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 08:03:56 by doxygen 1.8.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.13.3 API Reference

Skip menu "kdepimlibs-4.13.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal