File indexing completed on 2024-11-24 04:39:35
0001 /* 0002 This file is part of Contact Editor. 0003 0004 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "customfields_p.h" 0010 0011 CustomField::CustomField() 0012 : mType(TextType) 0013 , mScope(LocalScope) 0014 { 0015 } 0016 0017 CustomField::CustomField(const QString &key, const QString &title, Type type, Scope scope) 0018 : mKey(key) 0019 , mTitle(title) 0020 , mType(type) 0021 , mScope(scope) 0022 { 0023 } 0024 0025 CustomField CustomField::fromVariantMap(const QVariantMap &map, Scope scope) 0026 { 0027 return CustomField(map.value(QStringLiteral("key")).toString(), 0028 map.value(QStringLiteral("title")).toString(), 0029 stringToType(map.value(QStringLiteral("type")).toString()), 0030 scope); 0031 } 0032 0033 void CustomField::setKey(const QString &key) 0034 { 0035 mKey = key; 0036 } 0037 0038 QString CustomField::key() const 0039 { 0040 return mKey; 0041 } 0042 0043 void CustomField::setTitle(const QString &title) 0044 { 0045 mTitle = title; 0046 } 0047 0048 QString CustomField::title() const 0049 { 0050 return mTitle; 0051 } 0052 0053 void CustomField::setType(Type type) 0054 { 0055 mType = type; 0056 } 0057 0058 CustomField::Type CustomField::type() const 0059 { 0060 return mType; 0061 } 0062 0063 void CustomField::setScope(Scope scope) 0064 { 0065 mScope = scope; 0066 } 0067 0068 CustomField::Scope CustomField::scope() const 0069 { 0070 return mScope; 0071 } 0072 0073 void CustomField::setValue(const QString &value) 0074 { 0075 mValue = value; 0076 } 0077 0078 QString CustomField::value() const 0079 { 0080 return mValue; 0081 } 0082 0083 QVariantMap CustomField::toVariantMap() const 0084 { 0085 QVariantMap map; 0086 map.insert(QStringLiteral("key"), mKey); 0087 map.insert(QStringLiteral("title"), mTitle); 0088 map.insert(QStringLiteral("type"), typeToString(mType)); 0089 0090 return map; 0091 } 0092 0093 CustomField::Type CustomField::stringToType(const QString &type) 0094 { 0095 if (type == QLatin1StringView("text")) { 0096 return CustomField::TextType; 0097 } 0098 if (type == QLatin1StringView("numeric")) { 0099 return CustomField::NumericType; 0100 } 0101 if (type == QLatin1StringView("boolean")) { 0102 return CustomField::BooleanType; 0103 } 0104 if (type == QLatin1StringView("date")) { 0105 return CustomField::DateType; 0106 } 0107 if (type == QLatin1StringView("time")) { 0108 return CustomField::TimeType; 0109 } 0110 if (type == QLatin1StringView("datetime")) { 0111 return CustomField::DateTimeType; 0112 } 0113 if (type == QLatin1StringView("url")) { 0114 return CustomField::UrlType; 0115 } 0116 0117 return CustomField::TextType; 0118 } 0119 0120 QString CustomField::typeToString(CustomField::Type type) 0121 { 0122 switch (type) { 0123 case CustomField::TextType: 0124 default: 0125 return QStringLiteral("text"); 0126 case CustomField::NumericType: 0127 return QStringLiteral("numeric"); 0128 case CustomField::BooleanType: 0129 return QStringLiteral("boolean"); 0130 case CustomField::DateType: 0131 return QStringLiteral("date"); 0132 case CustomField::TimeType: 0133 return QStringLiteral("time"); 0134 case CustomField::DateTimeType: 0135 return QStringLiteral("datetime"); 0136 case CustomField::UrlType: 0137 return QStringLiteral("url"); 0138 } 0139 }