12#include <QDomDocument>
62 bool retval = bool(doc.setContent(xml));
64 QDomElement e = doc.documentElement();
73 for (e = root.firstChildElement(
"param"); !e.isNull(); e = e.nextSiblingElement(
"param")) {
74 QString name = e.attribute(
"name");
79 if (!e.hasAttribute(
"type")) {
80 d->properties[name] = QVariant(
value);
81 }
else if (e.attribute(
"type") ==
"bytearray") {
82 d->properties[name] = QVariant(QByteArray::fromBase64(
value.toLatin1()));
84 d->properties[name] =
value;
91 QMap<QString, QVariant>::ConstIterator it;
92 for (it =
d->properties.constBegin(); it !=
d->properties.constEnd(); ++it) {
93 if (
d->notSavedProperties.contains(it.key())) {
97 QDomElement e = doc.createElement(
"param");
98 e.setAttribute(
"name", QString(it.key().toLatin1()));
99 QString type =
"string";
100 QVariant
v = it.value();
102 if (
v.type() == QVariant::UserType &&
v.userType() == qMetaTypeId<KisCubicCurve>()) {
104 }
else if (
v.type() == QVariant::UserType &&
v.userType() == qMetaTypeId<KoColor>()) {
105 QDomDocument cdataDoc = QDomDocument(
"color");
106 QDomElement cdataRoot = cdataDoc.createElement(
"color");
107 cdataDoc.appendChild(cdataRoot);
109 text = cdataDoc.createCDATASection(cdataDoc.toString());
111 }
else if(
v.type() == QVariant::String ) {
112 text = doc.createCDATASection(
v.toString());
114 }
else if(
v.type() == QVariant::ByteArray ) {
115 text = doc.createTextNode(QString::fromLatin1(
v.toByteArray().toBase64()));
118 text = doc.createTextNode(
v.toString());
121 e.setAttribute(
"type", type);
129 QDomDocument doc = QDomDocument(
"params");
130 QDomElement root = doc.createElement(
"params");
131 doc.appendChild(root);
133 return doc.toString();
139 return d->properties.contains(name);
144 if (
d->properties.find(name) ==
d->properties.end()) {
145 d->properties.insert(name,
value);
147 d->properties[name] =
value;
153 if (
d->properties.constFind(name) ==
d->properties.constEnd()) {
156 value =
d->properties.value(name);
163 return d->properties.value(name, QVariant());
190 return (
float)
v.toDouble();
218 if (
v.type() == QVariant::UserType &&
v.userType() == qMetaTypeId<KisCubicCurve>()) {
233 case QVariant::UserType:
235 if (
v.userType() == qMetaTypeId<KoColor>()) {
240 case QVariant::String:
243 if (doc.setContent(
v.toString())) {
244 QDomElement e = doc.documentElement().firstChild().toElement();
252 QColor c(
v.toString());
260 case QVariant::Color:
262 QColor c =
v.value<QColor>();
284 QMap<QString, QVariant>::ConstIterator it;
285 for (it =
d->properties.constBegin(); it !=
d->properties.constEnd(); ++it) {
286 if (it->type() == QVariant::ByteArray) {
287 QByteArray ba = it->toByteArray();
289 if (ba.size() > 32) {
290 qDebug() << it.key() <<
" = " << QString(
"...skipped total %1 bytes...").arg(ba.size()) << it.value().typeName();
292 qDebug() << it.key() <<
" = " << it.value() << it.value().typeName();
295 qDebug() << it.key() <<
" = " << it.value() << it.value().typeName();
303 d->properties.clear();
308 d->notSavedProperties.insert(name);
313 return d->properties;
318 d->properties.remove(name);
323 return d->properties.keys();
328 const int prefixSize = prefix.size();
331 Q_FOREACH (
const QString &key, keys) {
332 if (key.startsWith(prefix)) {
339 if (!parentPrefix.isEmpty()) {
340 fullPrefix = parentPrefix +
"/" + prefix;
357 Q_FOREACH (
const QString &key, keys) {
369 static const QString key =
"__extractedFromPrefix";
375 QString result = string;
376 result.replace(
";",
"\\;");
377 result.replace(
"]",
"\\]");
378 result.replace(
">",
"\\>");
384 QString result = string;
385 result.replace(
"\\;",
";");
386 result.replace(
"\\]",
"]");
387 result.replace(
"\\>",
">");
394 escapedList.reserve(
value.size());
396 Q_FOREACH (
const QString &str,
value) {
411 int afterLastMatch = -1;
412 for (
int i = 0; i < joined.size(); i++) {
413 const bool lastChunk = i == joined.size() - 1;
414 const bool matchedSplitter = joined[i] ==
';' && (i == 0 || joined[i - 1] !=
'\\');
416 if (lastChunk || matchedSplitter) {
417 result <<
unescapeString(joined.mid(afterLastMatch, i - afterLastMatch +
int(lastChunk && !matchedSplitter)));
418 afterLastMatch = i + 1;
421 if (lastChunk && matchedSplitter) {
float value(const T *src, size_t ch)
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
static KoColor fromXML(const QDomElement &elt, const QString &channelDepthId)
KisSerializableConfigurationSP create(const QDomElement &e) override
~KisPropertiesConfigurationFactory() override
KisPropertiesConfigurationFactory()
KisSerializableConfigurationSP createDefault() override
void setPropertyNotSaved(const QString &name)
Marks a property that should not be saved by toXML.
static QString unescapeString(const QString &string)
void setPrefixedProperties(const QString &prefix, const KisPropertiesConfiguration *config)
void removeProperty(const QString &name)
QString getString(const QString &name, const QString &def=QString()) const
bool fromXML(const QString &xml, bool clear=true) override
void clearProperties()
Clear the map of properties.
virtual bool hasProperty(const QString &name) const
static QString escapeString(const QString &string)
virtual void setProperty(const QString &name, const QVariant &value)
static QString extractedPrefixKey()
QMap< QString, QVariant > properties
QSet< QString > notSavedProperties
bool getBool(const QString &name, bool def=false) const
KoColor getColor(const QString &name, const KoColor &color=KoColor()) const
getColor fetch the given property as a KoColor.
QStringList getStringList(const QString &name, const QStringList &defaultValue=QStringList()) const
KisCubicCurve getCubicCurve(const QString &name, const KisCubicCurve &curve=KisCubicCurve()) const
int getInt(const QString &name, int def=0) const
double getDouble(const QString &name, double def=0.0) const
QString toXML() const override
virtual bool compareTo(const KisPropertiesConfiguration *rhs) const
float getFloat(const QString &name, float def=0.0) const
KisPropertiesConfiguration()
void getPrefixedProperties(const QString &prefix, KisPropertiesConfiguration *config) const
virtual bool getProperty(const QString &name, QVariant &value) const
~KisPropertiesConfiguration() override
virtual QList< QString > getPropertiesKeys() const
KisPropertiesConfiguration & operator=(const KisPropertiesConfiguration &rhs)
virtual QMap< QString, QVariant > getProperties() const
T getPropertyLazy(const QString &name, const T &defaultValue) const
virtual void dump() const
static KoColorSpaceRegistry * instance()