File indexing completed on 2024-07-21 03:39:45

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 void FieldGroup::setParams(const ParameterMap &params)
0082 {
0083     d->mParamMap = params;
0084 }
0085 
0086 ParameterMap FieldGroup::params() const
0087 {
0088     return d->mParamMap;
0089 }
0090 
0091 bool FieldGroup::operator==(const FieldGroup &other) const
0092 {
0093     return (d->mParamMap == other.d->mParamMap) && (d->fieldGroupName == other.fieldGroupName()) && (d->value == other.value());
0094 }
0095 
0096 bool FieldGroup::operator!=(const FieldGroup &other) const
0097 {
0098     return !(other == *this);
0099 }
0100 
0101 FieldGroup &FieldGroup::operator=(const FieldGroup &other)
0102 {
0103     if (this != &other) {
0104         d = other.d;
0105     }
0106 
0107     return *this;
0108 }
0109 
0110 QString FieldGroup::toString() const
0111 {
0112     QString str = QLatin1String("FieldGroup {\n");
0113     str += QStringLiteral("    FieldGroupName: %1 Value %2\n").arg(d->fieldGroupName).arg(d->value);
0114     str += d->mParamMap.toString();
0115     str += QLatin1String("}\n");
0116     return str;
0117 }
0118 
0119 QDataStream &KContacts::operator<<(QDataStream &s, const FieldGroup &fieldGroup)
0120 {
0121     return s << fieldGroup.d->mParamMap << fieldGroup.d->fieldGroupName << fieldGroup.d->value;
0122 }
0123 
0124 QDataStream &KContacts::operator>>(QDataStream &s, FieldGroup &fieldGroup)
0125 {
0126     s >> fieldGroup.d->mParamMap >> fieldGroup.d->fieldGroupName >> fieldGroup.d->value;
0127     return s;
0128 }