Krita

InfoObject.cpp
1 /*
2  * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 #include "InfoObject.h"
7 
8 #include <kis_properties_configuration.h>
9 
10 struct InfoObject::Private {
11  Private() {}
12 
13  KisPropertiesConfigurationSP properties;
14 };
15 
16 InfoObject::InfoObject(KisPropertiesConfigurationSP configuration)
17  : QObject(0)
18  , d(new Private)
19 {
20  d->properties = configuration;
21 }
22 
23 InfoObject::InfoObject(QObject *parent)
24  : QObject(parent)
25  , d(new Private)
26 {
27  d->properties = new KisPropertiesConfiguration();
28 }
29 
30 InfoObject::~InfoObject()
31 {
32  delete d;
33 }
34 
35 bool InfoObject::operator==(const InfoObject &other) const
36 {
37  return (d->properties == other.d->properties);
38 }
39 
40 bool 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, proprertyMap.keys()) {
63  d->properties->setProperty(key, proprertyMap[key]);
64  }
65 }
66 
67 void InfoObject::setProperty(const QString &key, QVariant value)
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 
86 KisPropertiesConfigurationSP InfoObject::configuration() const
87 {
88  return d->properties;
89 }
90 
91 
bool isValid() const const
InfoObject wrap a properties map.
Definition: InfoObject.h:19
QVariant fromValue(const T &value)
T value() const const
void setProperty(const QString &key, QVariant value)
set the property identified by key to value
Definition: InfoObject.cpp:67
QVariant property(const QString &key)
return the value for the property identified by key, or None if there is no such key.
Definition: InfoObject.cpp:72
int userType() const const
QVariant::Type type() const const
void setProperties(QMap< QString, QVariant > propertyMap)
Add all properties in the propertyMap to this InfoObject.
Definition: InfoObject.cpp:60
QList< Key > keys() const const
QMap< QString, QVariant > properties() const
Return all properties this InfoObject manages.
Definition: InfoObject.cpp:45
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Sep 28 2022 04:09:30 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.