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

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
attributeentity.cpp
1 /*
2  Copyright (c) 2014 Christian Mollekopf <mollekopf@kolabsys.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 #include "attributeentity.h"
20 #include <QHash>
21 #include <QSet>
22 
23 using namespace Akonadi;
24 
25 struct Akonadi::AttributeEntity::Private
26 {
27  Private()
28  {}
29 
30  ~Private()
31  {
32  qDeleteAll(mAttributes);
33  }
34 
35  Private(const Private &other)
36  {
37  Q_FOREACH (Attribute *attr, other.mAttributes) {
38  mAttributes.insert(attr->type(), attr->clone());
39  }
40  mDeletedAttributes = other.mDeletedAttributes;
41  }
42 
43  QHash<QByteArray, Attribute *> mAttributes;
44  QSet<QByteArray> mDeletedAttributes;
45 };
46 
47 AttributeEntity::AttributeEntity()
48  : d_ptr(new Private)
49 {
50 
51 }
52 
53 AttributeEntity::AttributeEntity(const AttributeEntity &other)
54  : d_ptr(new Private)
55 {
56  operator=(other);
57 }
58 
59 AttributeEntity::~AttributeEntity()
60 {
61 
62 }
63 
64 Akonadi::AttributeEntity &Akonadi::AttributeEntity::operator=(const Akonadi::AttributeEntity &other)
65 {
66  QHash<QByteArray, Attribute *>::const_iterator it = other.d_ptr->mAttributes.constBegin();
67  for (; it != other.d_ptr->mAttributes.constEnd(); it++) {
68  d_ptr->mAttributes.insert(it.key(), it.value()->clone());
69  }
70  d_ptr->mDeletedAttributes = other.d_ptr->mDeletedAttributes;
71  return *this;
72 }
73 
74 void AttributeEntity::addAttribute(Attribute *attr)
75 {
76  if (d_ptr->mAttributes.contains(attr->type())) {
77  Attribute *existing = d_ptr->mAttributes.value(attr->type());
78  if (attr == existing) {
79  return;
80  }
81  d_ptr->mAttributes.remove(attr->type());
82  delete existing;
83  }
84  d_ptr->mAttributes.insert(attr->type(), attr);
85  d_ptr->mDeletedAttributes.remove(attr->type());
86 }
87 
88 void AttributeEntity::removeAttribute(const QByteArray &type)
89 {
90  d_ptr->mDeletedAttributes.insert(type);
91  delete d_ptr->mAttributes.take(type);
92 }
93 
94 bool AttributeEntity::hasAttribute(const QByteArray &type) const
95 {
96  return d_ptr->mAttributes.contains(type);
97 }
98 
99 Attribute::List AttributeEntity::attributes() const
100 {
101  return d_ptr->mAttributes.values();
102 }
103 
104 void Akonadi::AttributeEntity::clearAttributes()
105 {
106  Q_FOREACH (Attribute *attr, d_ptr->mAttributes) {
107  d_ptr->mDeletedAttributes.insert(attr->type());
108  delete attr;
109  }
110  d_ptr->mAttributes.clear();
111 }
112 
113 Attribute *AttributeEntity::attribute(const QByteArray &type) const
114 {
115  if (d_ptr->mAttributes.contains(type)) {
116  return d_ptr->mAttributes.value(type);
117  }
118  return 0;
119 }
120 
121 QSet<QByteArray> &AttributeEntity::removedAttributes() const
122 {
123  return d_ptr->mDeletedAttributes;
124 }
Akonadi::AttributeEntity::hasAttribute
bool hasAttribute() const
Returns whether the entity has an attribute of the requested type.
Definition: attributeentity.h:151
Akonadi::AttributeEntity::removeAttribute
void removeAttribute()
Removes and deletes the attribute of the requested type.
Definition: attributeentity.h:142
QByteArray
Akonadi::AttributeEntity::attributes
Attribute::List attributes() const
Returns a list of all attributes of the entity.
Definition: attributeentity.cpp:99
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:138
Akonadi::AttributeEntity
Parent class for entities that can have attributes.
Definition: attributeentity.h:40
QHash
QSet< QByteArray >
QList
QHash::const_iterator
Akonadi::AttributeEntity::clearAttributes
void clearAttributes()
Removes and deletes all attributes of the entity.
Definition: attributeentity.cpp:104
Akonadi::AttributeEntity::addAttribute
void addAttribute(Attribute *attribute)
Adds an attribute to the entity.
Definition: attributeentity.cpp:74
Akonadi::Attribute::clone
virtual Attribute * clone() const =0
Creates a copy of this attribute.
Akonadi::AttributeEntity::attribute
T * attribute() const
Returns the attribute of the requested type or 0 if it is not available.
Definition: attributeentity.h:124
Akonadi::Attribute::type
virtual QByteArray type() const =0
Returns the type of the attribute.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:02 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs 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

Search



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