File indexing completed on 2024-04-21 14:54:33

0001 /*
0002     This file is part of the KContacts framework.
0003     SPDX-FileCopyrightText: 2016-2019 Laurent Montel <montel@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "fieldgroup.h"
0009 #include "parametermap_p.h"
0010 
0011 #include <QDataStream>
0012 #include <QStringList>
0013 
0014 using namespace KContacts;
0015 
0016 class Q_DECL_HIDDEN FieldGroup::Private : public QSharedData
0017 {
0018 public:
0019     Private()
0020     {
0021     }
0022 
0023     Private(const Private &other)
0024         : QSharedData(other)
0025     {
0026         mParamMap = other.mParamMap;
0027         fieldGroupName = other.fieldGroupName;
0028         value = other.value;
0029     }
0030 
0031     ParameterMap mParamMap;
0032     QString fieldGroupName;
0033     QString value;
0034 };
0035 
0036 FieldGroup::FieldGroup()
0037     : d(new Private)
0038 {
0039 }
0040 
0041 FieldGroup::FieldGroup(const FieldGroup &other)
0042     : d(other.d)
0043 {
0044 }
0045 
0046 FieldGroup::FieldGroup(const QString &FieldGroupName)
0047     : d(new Private)
0048 {
0049     d->fieldGroupName = FieldGroupName;
0050 }
0051 
0052 FieldGroup::~FieldGroup()
0053 {
0054 }
0055 
0056 void FieldGroup::setFieldGroupName(const QString &fieldGroup)
0057 {
0058     d->fieldGroupName = fieldGroup;
0059 }
0060 
0061 QString FieldGroup::fieldGroupName() const
0062 {
0063     return d->fieldGroupName;
0064 }
0065 
0066 bool FieldGroup::isValid() const
0067 {
0068     return !d->fieldGroupName.isEmpty();
0069 }
0070 
0071 void FieldGroup::setValue(const QString &value)
0072 {
0073     d->value = value;
0074 }
0075 
0076 QString FieldGroup::value() const
0077 {
0078     return d->value;
0079 }
0080 
0081 #if KCONTACTS_BUILD_DEPRECATED_SINCE(5, 88)
0082 void FieldGroup::setParameters(const QMap<QString, QStringList> &params)
0083 {
0084     d->mParamMap = ParameterMap::fromQMap(params);
0085 }
0086 #endif
0087 
0088 #if KCONTACTS_BUILD_DEPRECATED_SINCE(5, 88)
0089 QMap<QString, QStringList> FieldGroup::parameters() const
0090 {
0091     return d->mParamMap.toQMap();
0092 }
0093 #endif
0094 
0095 void FieldGroup::setParams(const ParameterMap &params)
0096 {
0097     d->mParamMap = params;
0098 }
0099 
0100 ParameterMap FieldGroup::params() const
0101 {
0102     return d->mParamMap;
0103 }
0104 
0105 bool FieldGroup::operator==(const FieldGroup &other) const
0106 {
0107     return (d->mParamMap == other.d->mParamMap) && (d->fieldGroupName == other.fieldGroupName()) && (d->value == other.value());
0108 }
0109 
0110 bool FieldGroup::operator!=(const FieldGroup &other) const
0111 {
0112     return !(other == *this);
0113 }
0114 
0115 FieldGroup &FieldGroup::operator=(const FieldGroup &other)
0116 {
0117     if (this != &other) {
0118         d = other.d;
0119     }
0120 
0121     return *this;
0122 }
0123 
0124 QString FieldGroup::toString() const
0125 {
0126     QString str = QLatin1String("FieldGroup {\n");
0127     str += QStringLiteral("    FieldGroupName: %1 Value %2\n").arg(d->fieldGroupName).arg(d->value);
0128     str += d->mParamMap.toString();
0129     str += QLatin1String("}\n");
0130     return str;
0131 }
0132 
0133 QDataStream &KContacts::operator<<(QDataStream &s, const FieldGroup &fieldGroup)
0134 {
0135     return s << fieldGroup.d->mParamMap << fieldGroup.d->fieldGroupName << fieldGroup.d->value;
0136 }
0137 
0138 QDataStream &KContacts::operator>>(QDataStream &s, FieldGroup &fieldGroup)
0139 {
0140     s >> fieldGroup.d->mParamMap >> fieldGroup.d->fieldGroupName >> fieldGroup.d->value;
0141     return s;
0142 }