Akonadi Contacts

customfields.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "customfields_p.h"
10
11CustomField::CustomField()
12 : mType(TextType)
13 , mScope(LocalScope)
14{
15}
16
17CustomField::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
25CustomField 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
33void CustomField::setKey(const QString &key)
34{
35 mKey = key;
36}
37
38QString CustomField::key() const
39{
40 return mKey;
41}
42
43void CustomField::setTitle(const QString &title)
44{
45 mTitle = title;
46}
47
48QString CustomField::title() const
49{
50 return mTitle;
51}
52
53void CustomField::setType(Type type)
54{
55 mType = type;
56}
57
58CustomField::Type CustomField::type() const
59{
60 return mType;
61}
62
63void CustomField::setScope(Scope scope)
64{
65 mScope = scope;
66}
67
68CustomField::Scope CustomField::scope() const
69{
70 return mScope;
71}
72
73void CustomField::setValue(const QString &value)
74{
75 mValue = value;
76}
77
78QString CustomField::value() const
79{
80 return mValue;
81}
82
83QVariantMap 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
93CustomField::Type CustomField::stringToType(const QString &type)
94{
95 if (type == QLatin1StringView("text")) {
96 return CustomField::TextType;
97 }
98 if (type == QLatin1StringView("numeric")) {
99 return CustomField::NumericType;
100 }
101 if (type == QLatin1StringView("boolean")) {
102 return CustomField::BooleanType;
103 }
104 if (type == QLatin1StringView("date")) {
105 return CustomField::DateType;
106 }
107 if (type == QLatin1StringView("time")) {
108 return CustomField::TimeType;
109 }
110 if (type == QLatin1StringView("datetime")) {
111 return CustomField::DateTimeType;
112 }
113 if (type == QLatin1StringView("url")) {
114 return CustomField::UrlType;
115 }
116
117 return CustomField::TextType;
118}
119
120QString 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}
Type type(const QSqlDatabase &db)
char * toString(const EngineQuery &query)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:20 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.