File indexing completed on 2024-05-12 15:59:05

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 #include "InfoObject.h"
0007 
0008 #include <kis_properties_configuration.h>
0009 
0010 struct InfoObject::Private {
0011     Private() {}
0012 
0013     KisPropertiesConfigurationSP properties;
0014 };
0015 
0016 InfoObject::InfoObject(KisPropertiesConfigurationSP configuration)
0017     : QObject(0)
0018     , d(new Private)
0019 {
0020     d->properties = configuration;
0021 }
0022 
0023 InfoObject::InfoObject(QObject *parent)
0024     : QObject(parent)
0025     , d(new Private)
0026 {
0027     d->properties = new KisPropertiesConfiguration();
0028 }
0029 
0030 InfoObject::~InfoObject()
0031 {
0032     delete d;
0033 }
0034 
0035 bool InfoObject::operator==(const InfoObject &other) const
0036 {
0037     return (d->properties == other.d->properties);
0038 }
0039 
0040 bool InfoObject::operator!=(const InfoObject &other) const
0041 {
0042     return !(operator==(other));
0043 }
0044 
0045 QMap<QString, QVariant> InfoObject::properties() const
0046 {
0047     QMap<QString, QVariant> map = d->properties->getProperties();
0048 
0049     for (const QString &key : map.keys()) {
0050         QVariant v = map.value(key);
0051 
0052         if (v.isValid() && v.type() == QVariant::UserType && v.userType() == qMetaTypeId<KoColor>()) {
0053             map[key] = QVariant::fromValue(v.value<KoColor>().toXML());
0054         }
0055     }
0056 
0057     return map;
0058 }
0059 
0060 void InfoObject::setProperties(QMap<QString, QVariant> proprertyMap)
0061 {
0062     Q_FOREACH(const QString & key, proprertyMap.keys()) {
0063         d->properties->setProperty(key, proprertyMap[key]);
0064     }
0065 }
0066 
0067 void InfoObject::setProperty(const QString &key, QVariant value)
0068 {
0069     d->properties->setProperty(key, value);
0070 }
0071 
0072 QVariant InfoObject::property(const QString &key)
0073 {
0074     QVariant v;
0075     if (d->properties->hasProperty(key)) {
0076         d->properties->getProperty(key, v);
0077 
0078         if (v.isValid() && v.type() == QVariant::UserType && v.userType() == qMetaTypeId<KoColor>()) {
0079             return QVariant::fromValue(v.value<KoColor>().toXML());
0080         }
0081     }
0082 
0083     return v;
0084 }
0085 
0086 KisPropertiesConfigurationSP InfoObject::configuration() const
0087 {
0088     return d->properties;
0089 }
0090 
0091