Akonadi Contacts

customfields.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2010 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "customfields_p.h"
10 
11 CustomField::CustomField()
12  : mType(TextType)
13  , mScope(LocalScope)
14 {
15 }
16 
17 CustomField::CustomField(const QString &key, const QString &title, Type type, Scope scope)
18  : mKey(key)
19  , mTitle(title)
20  , mType(type)
21  , mScope(scope)
22 {
23 }
24 
25 CustomField CustomField::fromVariantMap(const QVariantMap &map, Scope scope)
26 {
27  return CustomField(map.value(QStringLiteral("key")).toString(),
28  map.value(QStringLiteral("title")).toString(),
29  stringToType(map.value(QStringLiteral("type")).toString()),
30  scope);
31 }
32 
33 void CustomField::setKey(const QString &key)
34 {
35  mKey = key;
36 }
37 
38 QString CustomField::key() const
39 {
40  return mKey;
41 }
42 
43 void CustomField::setTitle(const QString &title)
44 {
45  mTitle = title;
46 }
47 
48 QString CustomField::title() const
49 {
50  return mTitle;
51 }
52 
53 void CustomField::setType(Type type)
54 {
55  mType = type;
56 }
57 
58 CustomField::Type CustomField::type() const
59 {
60  return mType;
61 }
62 
63 void CustomField::setScope(Scope scope)
64 {
65  mScope = scope;
66 }
67 
68 CustomField::Scope CustomField::scope() const
69 {
70  return mScope;
71 }
72 
73 void CustomField::setValue(const QString &value)
74 {
75  mValue = value;
76 }
77 
78 QString CustomField::value() const
79 {
80  return mValue;
81 }
82 
83 QVariantMap CustomField::toVariantMap() const
84 {
85  QVariantMap map;
86  map.insert(QStringLiteral("key"), mKey);
87  map.insert(QStringLiteral("title"), mTitle);
88  map.insert(QStringLiteral("type"), typeToString(mType));
89 
90  return map;
91 }
92 
93 CustomField::Type CustomField::stringToType(const QString &type)
94 {
95  if (type == QLatin1String("text")) {
96  return CustomField::TextType;
97  }
98  if (type == QLatin1String("numeric")) {
99  return CustomField::NumericType;
100  }
101  if (type == QLatin1String("boolean")) {
102  return CustomField::BooleanType;
103  }
104  if (type == QLatin1String("date")) {
105  return CustomField::DateType;
106  }
107  if (type == QLatin1String("time")) {
108  return CustomField::TimeType;
109  }
110  if (type == QLatin1String("datetime")) {
111  return CustomField::DateTimeType;
112  }
113  if (type == QLatin1String("url")) {
114  return CustomField::UrlType;
115  }
116 
117  return CustomField::TextType;
118 }
119 
120 QString CustomField::typeToString(CustomField::Type type)
121 {
122  switch (type) {
123  case CustomField::TextType:
124  default:
125  return QStringLiteral("text");
126  case CustomField::NumericType:
127  return QStringLiteral("numeric");
128  case CustomField::BooleanType:
129  return QStringLiteral("boolean");
130  case CustomField::DateType:
131  return QStringLiteral("date");
132  case CustomField::TimeType:
133  return QStringLiteral("time");
134  case CustomField::DateTimeType:
135  return QStringLiteral("datetime");
136  case CustomField::UrlType:
137  return QStringLiteral("url");
138  }
139 }
QString & insert(int position, QChar ch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.