Krita

InfoObject.cpp
1/*
2 * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#include "InfoObject.h"
7
8#include <kis_properties_configuration.h>
9
10struct InfoObject::Private {
11 Private() {}
12
13 KisPropertiesConfigurationSP properties;
14};
15
16InfoObject::InfoObject(KisPropertiesConfigurationSP configuration)
17 : QObject(0)
18 , d(new Private)
19{
20 d->properties = configuration;
21}
22
23InfoObject::InfoObject(QObject *parent)
24 : QObject(parent)
25 , d(new Private)
26{
27 d->properties = new KisPropertiesConfiguration();
28}
29
30InfoObject::~InfoObject()
31{
32 delete d;
33}
34
35bool InfoObject::operator==(const InfoObject &other) const
36{
37 return (d->properties == other.d->properties);
38}
39
40bool InfoObject::operator!=(const InfoObject &other) const
41{
42 return !(operator==(other));
43}
44
46{
47 QMap<QString, QVariant> map = d->properties->getProperties();
48
49 for (const QString &key : map.keys()) {
50 QVariant v = map.value(key);
51
52 if (v.isValid() && v.type() == QVariant::UserType && v.userType() == qMetaTypeId<KoColor>()) {
53 map[key] = QVariant::fromValue(v.value<KoColor>().toXML());
54 }
55 }
56
57 return map;
58}
59
61{
62 Q_FOREACH(const QString & key, propertyMap.keys()) {
63 d->properties->setProperty(key, propertyMap[key]);
64 }
65}
66
68{
69 d->properties->setProperty(key, value);
70}
71
73{
74 QVariant v;
75 if (d->properties->hasProperty(key)) {
76 d->properties->getProperty(key, v);
77
78 if (v.isValid() && v.type() == QVariant::UserType && v.userType() == qMetaTypeId<KoColor>()) {
79 return QVariant::fromValue(v.value<KoColor>().toXML());
80 }
81 }
82
83 return v;
84}
85
86KisPropertiesConfigurationSP InfoObject::configuration() const
87{
88 return d->properties;
89}
90
91
InfoObject wrap a properties map.
Definition InfoObject.h:20
void setProperty(const QString &key, QVariant value)
set the property identified by key to value
QVariant property(const QString &key)
return the value for the property identified by key, or None if there is no such key.
QMap< QString, QVariant > properties() const
Return all properties this InfoObject manages.
void setProperties(QMap< QString, QVariant > propertyMap)
Add all properties in the propertyMap to this InfoObject.
QList< Key > keys() const const
Type type() const const
QVariant fromValue(T &&value)
bool isValid() const const
int userType() const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.