chalk

kis_filter_configuration.cpp
1/*
2 * Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#include "kis_filter.h"
19
20#include <kdebug.h>
21#include <tqdom.h>
22#include <tqstring.h>
23
24#include "kis_filter_registry.h"
25#include "kis_transaction.h"
26#include "kis_undo_adapter.h"
27#include "kis_painter.h"
28#include "kis_selection.h"
29#include "kis_id.h"
30#include "kis_canvas_subject.h"
31#include "kis_progress_display_interface.h"
32#include "kis_types.h"
33#include "kis_filter_config_widget.h"
34
35
37{
38 m_name = rhs.m_name;
39 m_version = rhs.m_version;
40 m_properties = rhs.m_properties;
41}
42
43void KisFilterConfiguration::fromXML(const TQString & s )
44{
45 m_properties.clear();
46
47 TQDomDocument doc;
48 doc.setContent( s );
49 TQDomElement e = doc.documentElement();
50 TQDomNode n = e.firstChild();
51
52 m_name = e.attribute("name");
53 m_version = e.attribute("version").toInt();
54
55 while (!n.isNull()) {
56 // We don't nest elements in filter configuration. For now...
57 TQDomElement e = n.toElement();
58 TQString name;
59 TQString type;
60 TQString value;
61
62 if (!e.isNull()) {
63 if (e.tagName() == "property") {
64 name = e.attribute("name");
65 type = e.attribute("type");
66 value = e.text();
67 // XXX Convert the variant pro-actively to the right type?
68 m_properties[name] = TQVariant(value);
69 }
70 }
71 n = n.nextSibling();
72 }
73 //dump();
74}
75
77{
78 TQDomDocument doc = TQDomDocument("filterconfig");
79 TQDomElement root = doc.createElement( "filterconfig" );
80 root.setAttribute( "name", m_name );
81 root.setAttribute( "version", m_version );
82
83 doc.appendChild( root );
84
85 TQStringVariantMap::Iterator it;
86 for ( it = m_properties.begin(); it != m_properties.end(); ++it ) {
87 TQDomElement e = doc.createElement( "property" );
88 e.setAttribute( "name", it.key().latin1() );
89 TQVariant v = it.data();
90 e.setAttribute( "type", v.typeName() );
91 TQString s = v.asString();
92 TQDomText text = doc.createCDATASection(v.asString() ); // XXX: Unittest this!
93 e.appendChild(text);
94 root.appendChild(e);
95 }
96
97 return doc.toString();
98}
99
100const TQString & KisFilterConfiguration::name() const
101{
102 return m_name;
103}
104
106{
107 return m_version;
108}
109
110void KisFilterConfiguration::setProperty(const TQString & name, const TQVariant & value)
111{
112 if ( m_properties.find( name ) == m_properties.end() ) {
113 m_properties.insert( name, value );
114 }
115 else {
116 m_properties[name] = value;
117 }
118}
119
120bool KisFilterConfiguration::getProperty(const TQString & name, TQVariant & value)
121{
122 if ( m_properties.find( name ) == m_properties.end() ) {
123 return false;
124 }
125 else {
126 value = m_properties[name];
127 return true;
128 }
129}
130
131TQVariant KisFilterConfiguration::getProperty(const TQString & name)
132{
133 if ( m_properties.find( name ) == m_properties.end() ) {
134 return TQVariant();
135 }
136 else {
137 return m_properties[name];
138 }
139}
140
141
142int KisFilterConfiguration::getInt(const TQString & name, int def)
143{
144 TQVariant v = getProperty(name);
145 if (v.isValid())
146 return v.asInt();
147 else
148 return def;
149
150}
151
152double KisFilterConfiguration::getDouble(const TQString & name, double def)
153{
154 TQVariant v = getProperty(name);
155 if (v.isValid())
156 return v.asDouble();
157 else
158 return def;
159}
160
161bool KisFilterConfiguration::getBool(const TQString & name, bool def)
162{
163 TQVariant v = getProperty(name);
164 if (v.isValid())
165 return v.asBool();
166 else
167 return def;
168}
169
170TQString KisFilterConfiguration::getString(const TQString & name, TQString def)
171{
172 TQVariant v = getProperty(name);
173 if (v.isValid())
174 return v.asString();
175 else
176 return def;
177}
178
179void KisFilterConfiguration::dump()
180{
181 TQStringVariantMap::Iterator it;
182 for ( it = m_properties.begin(); it != m_properties.end(); ++it ) {
183 }
184
185}
const TQString & name() const
Get the unique, language independent name of the filter.
virtual void setProperty(const TQString &name, const TQVariant &value)
Set the property with name to value.
virtual bool getProperty(const TQString &name, TQVariant &value)
Set value to the value associated with property name.
TQ_INT32 version() const
Get the version of the filter that has created this config.
KisFilterConfiguration(const TQString &name, TQ_INT32 version)
Create a new filter config.
virtual TQString toString()
Create a serialized version of this filter config.
virtual void fromXML(const TQString &)
Fill the filter configuration object from the XML encoded representation in s.