krita
kis_filter_configuration.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "kis_filter.h"
00019
00020 #include <kdebug.h>
00021 #include <qdom.h>
00022 #include <qstring.h>
00023
00024 #include "kis_filter_registry.h"
00025 #include "kis_transaction.h"
00026 #include "kis_undo_adapter.h"
00027 #include "kis_painter.h"
00028 #include "kis_selection.h"
00029 #include "kis_id.h"
00030 #include "kis_canvas_subject.h"
00031 #include "kis_progress_display_interface.h"
00032 #include "kis_types.h"
00033 #include "kis_filter_config_widget.h"
00034
00035
00036 KisFilterConfiguration::KisFilterConfiguration(const KisFilterConfiguration & rhs)
00037 {
00038 m_name = rhs.m_name;
00039 m_version = rhs.m_version;
00040 m_properties = rhs.m_properties;
00041 }
00042
00043 void KisFilterConfiguration::fromXML(const QString & s )
00044 {
00045 m_properties.clear();
00046
00047 QDomDocument doc;
00048 doc.setContent( s );
00049 QDomElement e = doc.documentElement();
00050 QDomNode n = e.firstChild();
00051
00052 m_name = e.attribute("name");
00053 m_version = e.attribute("version").toInt();
00054
00055 while (!n.isNull()) {
00056
00057 QDomElement e = n.toElement();
00058 QString name;
00059 QString type;
00060 QString value;
00061
00062 if (!e.isNull()) {
00063 if (e.tagName() == "property") {
00064 name = e.attribute("name");
00065 type = e.attribute("type");
00066 value = e.text();
00067
00068 m_properties[name] = QVariant(value);
00069 }
00070 }
00071 n = n.nextSibling();
00072 }
00073
00074 }
00075
00076 QString KisFilterConfiguration::toString()
00077 {
00078 QDomDocument doc = QDomDocument("filterconfig");
00079 QDomElement root = doc.createElement( "filterconfig" );
00080 root.setAttribute( "name", m_name );
00081 root.setAttribute( "version", m_version );
00082
00083 doc.appendChild( root );
00084
00085 QMap<QString, QVariant>::Iterator it;
00086 for ( it = m_properties.begin(); it != m_properties.end(); ++it ) {
00087 QDomElement e = doc.createElement( "property" );
00088 e.setAttribute( "name", it.key().latin1() );
00089 QVariant v = it.data();
00090 e.setAttribute( "type", v.typeName() );
00091 QString s = v.asString();
00092 QDomText text = doc.createCDATASection(v.asString() );
00093 e.appendChild(text);
00094 root.appendChild(e);
00095 }
00096
00097 return doc.toString();
00098 }
00099
00100 const QString & KisFilterConfiguration::name() const
00101 {
00102 return m_name;
00103 }
00104
00105 Q_INT32 KisFilterConfiguration::version() const
00106 {
00107 return m_version;
00108 }
00109
00110 void KisFilterConfiguration::setProperty(const QString & name, const QVariant & value)
00111 {
00112 if ( m_properties.find( name ) == m_properties.end() ) {
00113 m_properties.insert( name, value );
00114 }
00115 else {
00116 m_properties[name] = value;
00117 }
00118 }
00119
00120 bool KisFilterConfiguration::getProperty(const QString & name, QVariant & value)
00121 {
00122 if ( m_properties.find( name ) == m_properties.end() ) {
00123 return false;
00124 }
00125 else {
00126 value = m_properties[name];
00127 return true;
00128 }
00129 }
00130
00131 QVariant KisFilterConfiguration::getProperty(const QString & name)
00132 {
00133 if ( m_properties.find( name ) == m_properties.end() ) {
00134 return QVariant();
00135 }
00136 else {
00137 return m_properties[name];
00138 }
00139 }
00140
00141
00142 int KisFilterConfiguration::getInt(const QString & name, int def)
00143 {
00144 QVariant v = getProperty(name);
00145 if (v.isValid())
00146 return v.asInt();
00147 else
00148 return def;
00149
00150 }
00151
00152 double KisFilterConfiguration::getDouble(const QString & name, double def)
00153 {
00154 QVariant v = getProperty(name);
00155 if (v.isValid())
00156 return v.asDouble();
00157 else
00158 return def;
00159 }
00160
00161 bool KisFilterConfiguration::getBool(const QString & name, bool def)
00162 {
00163 QVariant v = getProperty(name);
00164 if (v.isValid())
00165 return v.asBool();
00166 else
00167 return def;
00168 }
00169
00170 QString KisFilterConfiguration::getString(const QString & name, QString def)
00171 {
00172 QVariant v = getProperty(name);
00173 if (v.isValid())
00174 return v.asString();
00175 else
00176 return def;
00177 }
00178
00179 void KisFilterConfiguration::dump()
00180 {
00181 QMap<QString, QVariant>::Iterator it;
00182 for ( it = m_properties.begin(); it != m_properties.end(); ++it ) {
00183 }
00184
00185 }
|