00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <kdebug.h>
00020 #include <qdom.h>
00021 #include <QString>
00022
00023 #include "KoProperties.h"
00024
00025 KoProperties::KoProperties(const KoProperties & rhs)
00026 : m_properties( rhs.m_properties )
00027 {
00028 }
00029
00030 void KoProperties::load(const QString & s)
00031 {
00032 m_properties.clear();
00033
00034 QDomDocument doc;
00035 doc.setContent( s );
00036 QDomElement e = doc.documentElement();
00037 QDomNode n = e.firstChild();
00038
00039 while (!n.isNull()) {
00040
00041 QDomElement e = n.toElement();
00042 if (!e.isNull()) {
00043 if (e.tagName() == "property") {
00044 const QString name = e.attribute("name");
00045 const QString type = e.attribute("type");
00046 const QString value = e.text();
00047
00048 m_properties[name] = QVariant(value);
00049 }
00050 }
00051 n = n.nextSibling();
00052 }
00053 }
00054
00055 QString KoProperties::store()
00056 {
00057 QDomDocument doc = QDomDocument("filterconfig");
00058 QDomElement root = doc.createElement( "filterconfig" );
00059
00060 doc.appendChild( root );
00061
00062 QMap<QString, QVariant>::Iterator it;
00063 for ( it = m_properties.begin(); it != m_properties.end(); ++it ) {
00064 QDomElement e = doc.createElement( "property" );
00065 e.setAttribute( "name", QString(it.key().toLatin1()) );
00066 QVariant v = it.value();
00067 e.setAttribute( "type", v.typeName() );
00068 QString s = v.toString();
00069 QDomText text = doc.createCDATASection(v.toString() );
00070 e.appendChild(text);
00071 root.appendChild(e);
00072 }
00073
00074 return doc.toString();
00075 }
00076
00077
00078 void KoProperties::setProperty(const QString & name, const QVariant & value)
00079 {
00080
00081 m_properties.insert( name, value );
00082 }
00083
00084 bool KoProperties::getProperty(const QString & name, QVariant & value) const
00085 {
00086 QMap<QString, QVariant>::const_iterator it = m_properties.find( name );
00087 if ( it == m_properties.end() ) {
00088 return false;
00089 }
00090 else {
00091 value = *it;
00092 return true;
00093 }
00094 }
00095
00096 QVariant KoProperties::getProperty(const QString & name) const
00097 {
00098 return m_properties.value( name, QVariant() );
00099 }
00100
00101
00102 int KoProperties::getInt(const QString & name, int def) const
00103 {
00104 const QVariant v = getProperty(name);
00105 if (v.isValid())
00106 return v.toInt();
00107 else
00108 return def;
00109
00110 }
00111
00112 double KoProperties::getDouble(const QString & name, double def) const
00113 {
00114 const QVariant v = getProperty(name);
00115 if (v.isValid())
00116 return v.toDouble();
00117 else
00118 return def;
00119 }
00120
00121 bool KoProperties::getBool(const QString & name, bool def) const
00122 {
00123 const QVariant v = getProperty(name);
00124 if (v.isValid())
00125 return v.toBool();
00126 else
00127 return def;
00128 }
00129
00130 QString KoProperties::getString(const QString & name, const QString & def) const
00131 {
00132 const QVariant v = getProperty(name);
00133 if (v.isValid())
00134 return v.toString();
00135 else
00136 return def;
00137 }
00138
00139 void KoProperties::dump()
00140 {
00141 QMap<QString, QVariant>::Iterator it;
00142 for ( it = m_properties.begin(); it != m_properties.end(); ++it ) {
00143
00144 }
00145 }