21 #include <QDomDocument>
22 #include <QStringList>
24 static const char *
const ident_ =
"$Id$";
30 tabString.fill(
'\t', tabs );
32 if ( QVariant::StringList ==
value_.type() )
34 QStringList sl =
value_.toStringList();
36 for ( QStringList::const_iterator i = sl.begin(); i != sl.end(); ++i )
38 QgsDebugMsg( QString(
"%1[%2] " ).arg( tabString ).arg( *i ) );
52 QDomElement subkeyElement = keyNode.toElement();
55 QString typeString = subkeyElement.attribute(
"type" );
57 if ( QString::null == typeString )
59 QgsDebugMsg( QString(
"null ``type'' attribute for %1" ).arg( keyNode.nodeName() ) );
69 QVariant::Type type = QVariant::nameToType( typeString.toLocal8Bit().constData() );
80 case QVariant::Invalid:
81 QgsDebugMsg( QString(
"invalid value type %1 .. " ).arg( typeString ) );
92 case QVariant::String:
93 value_ = subkeyElement.text();
96 case QVariant::StringList:
99 QDomNodeList values = keyNode.childNodes();
102 QStringList valueStringList;
104 while ( i < values.count() )
106 if (
"value" == values.item( i ).nodeName() )
108 valueStringList.append( values.item( i ).firstChild().nodeValue() );
112 QgsDebugMsg( QString(
"non <value> element ``%1'' in string list" ).arg( values.item( i ).nodeName() ) );
126 case QVariant::Pixmap:
130 case QVariant::Brush:
142 case QVariant::Color:
146 case QVariant::Palette:
150 case QVariant::Point:
154 case QVariant::Image:
159 value_ = QVariant( subkeyElement.text() ).toInt();
163 value_ = QVariant( subkeyElement.text() ).toUInt();
167 value_ = QVariant( subkeyElement.text() ).toBool();
170 case QVariant::Double:
171 value_ = QVariant( subkeyElement.text() ).toDouble();
174 case QVariant::ByteArray:
175 value_ = QVariant( subkeyElement.text() ).toByteArray();
178 case QVariant::Polygon:
182 case QVariant::Region:
186 case QVariant::Bitmap:
190 case QVariant::Cursor:
194 case QVariant::BitArray :
195 QgsDebugMsg(
"no support for QVariant::BitArray" );
198 case QVariant::KeySequence :
199 QgsDebugMsg(
"no support for QVariant::KeySequence" );
219 QgsDebugMsg( QString(
"unsupported value type %1 .. not propertly translated to QVariant" ).arg( typeString ) );
231 QDomElement & keyElement,
232 QDomDocument & document )
234 QDomElement valueElement = document.createElement( nodeName );
237 valueElement.setAttribute(
"type",
value_.typeName() );
244 if ( QVariant::StringList ==
value_.type() )
246 QStringList sl =
value_.toStringList();
248 for ( QStringList::iterator i = sl.begin();
252 QDomElement stringListElement = document.createElement(
"value" );
253 QDomText valueText = document.createTextNode( *i );
254 stringListElement.appendChild( valueText );
256 valueElement.appendChild( stringListElement );
261 QDomText valueText = document.createTextNode(
value_.toString() );
262 valueElement.appendChild( valueText );
265 keyElement.appendChild( valueElement );
286 if ( !foundQgsProperty )
292 return foundQgsProperty->
value();
300 tabString.fill(
'\t', tabs );
305 tabString.fill(
'\t', tabs );
309 QHashIterator < QString, QgsProperty* > i(
mProperties );
310 while ( i.hasNext() )
312 if ( i.next().value()->isValue() )
317 if ( QVariant::StringList == propertyValue->
value().type() )
319 QgsDebugMsg( QString(
"%1key: <%2> value:" ).arg( tabString ).arg( i.key() ) );
320 propertyValue->
dump( tabs + 1 );
324 QgsDebugMsg( QString(
"%1key: <%2> value: %3" ).arg( tabString ).arg( i.key() ).arg( propertyValue->
value().toString() ) );
332 .arg( dynamic_cast<QgsPropertyKey*>( i.value() )->
name() ) );
333 i.value()->dump( tabs + 1 );
357 QDomNodeList subkeys = keyNode.childNodes();
359 while ( i < subkeys.count() )
364 if ( subkeys.item( i ).hasAttributes() &&
365 subkeys.item( i ).isElement() &&
366 subkeys.item( i ).toElement().hasAttribute(
"type" ) )
368 delete mProperties.take( subkeys.item( i ).nodeName() );
371 QDomNode subkey = subkeys.item( i );
373 if ( !
mProperties[subkeys.item( i ).nodeName()]->readXML( subkey ) )
375 QgsDebugMsg( QString(
"unable to parse key value %1" ).arg( subkeys.item( i ).nodeName() ) );
381 addKey( subkeys.item( i ).nodeName() );
383 QDomNode subkey = subkeys.item( i );
385 if ( !
mProperties[subkeys.item( i ).nodeName()]->readXML( subkey ) )
387 QgsDebugMsg( QString(
"unable to parse subkey %1" ).arg( subkeys.item( i ).nodeName() ) );
407 QDomElement keyElement = document.createElement( nodeName );
411 QHashIterator < QString, QgsProperty* > i(
mProperties );
412 while ( i.hasNext() )
415 if ( !i.value()->writeXML( i.key(), keyElement, document ) )
422 element.appendChild( keyElement );
434 QHashIterator < QString, QgsProperty* > i(
mProperties );
435 while ( i.hasNext() )
438 if ( i.next().value()->isLeaf() )
440 entries.append( i.key() );
450 QHashIterator < QString, QgsProperty* > i(
mProperties );
451 while ( i.hasNext() )
454 if ( !i.next().value()->isLeaf() )
456 entries.append( i.key() );
468 else if ( 1 ==
count() )
470 QHashIterator < QString, QgsProperty* > i(
mProperties );
472 if ( i.hasNext() && i.next().value()->isValue() )