21 #include <QDomDocument>
22 #include <QStringList>
27 tabString.fill(
'\t', tabs );
29 if ( QVariant::StringList ==
value_.type() )
31 QStringList sl =
value_.toStringList();
33 for ( QStringList::const_iterator i = sl.begin(); i != sl.end(); ++i )
35 QgsDebugMsg( QString(
"%1[%2] " ).arg( tabString ).arg( *i ) );
49 QDomElement subkeyElement = keyNode.toElement();
52 QString typeString = subkeyElement.attribute(
"type" );
54 if ( QString::null == typeString )
56 QgsDebugMsg( QString(
"null ``type'' attribute for %1" ).arg( keyNode.nodeName() ) );
66 QVariant::Type type = QVariant::nameToType( typeString.toLocal8Bit().constData() );
77 case QVariant::Invalid:
78 QgsDebugMsg( QString(
"invalid value type %1 .. " ).arg( typeString ) );
89 case QVariant::String:
90 value_ = subkeyElement.text();
93 case QVariant::StringList:
96 QDomNodeList values = keyNode.childNodes();
99 QStringList valueStringList;
101 while ( i < values.count() )
103 if (
"value" == values.item( i ).nodeName() )
105 valueStringList.append( values.item( i ).firstChild().nodeValue() );
109 QgsDebugMsg( QString(
"non <value> element ``%1'' in string list" ).arg( values.item( i ).nodeName() ) );
123 case QVariant::Pixmap:
127 case QVariant::Brush:
139 case QVariant::Color:
143 case QVariant::Palette:
147 case QVariant::Point:
151 case QVariant::Image:
156 value_ = QVariant( subkeyElement.text() ).toInt();
160 value_ = QVariant( subkeyElement.text() ).toUInt();
164 value_ = QVariant( subkeyElement.text() ).toBool();
167 case QVariant::Double:
168 value_ = QVariant( subkeyElement.text() ).toDouble();
171 case QVariant::ByteArray:
172 value_ = QVariant( subkeyElement.text() ).toByteArray();
175 case QVariant::Polygon:
179 case QVariant::Region:
183 case QVariant::Bitmap:
187 case QVariant::Cursor:
191 case QVariant::BitArray :
192 QgsDebugMsg(
"no support for QVariant::BitArray" );
195 case QVariant::KeySequence :
196 QgsDebugMsg(
"no support for QVariant::KeySequence" );
216 QgsDebugMsg( QString(
"unsupported value type %1 .. not propertly translated to QVariant" ).arg( typeString ) );
228 QDomElement & keyElement,
229 QDomDocument & document )
231 QDomElement valueElement = document.createElement( nodeName );
234 valueElement.setAttribute(
"type",
value_.typeName() );
241 if ( QVariant::StringList ==
value_.type() )
243 QStringList sl =
value_.toStringList();
245 for ( QStringList::iterator i = sl.begin();
249 QDomElement stringListElement = document.createElement(
"value" );
250 QDomText valueText = document.createTextNode( *i );
251 stringListElement.appendChild( valueText );
253 valueElement.appendChild( stringListElement );
258 QDomText valueText = document.createTextNode(
value_.toString() );
259 valueElement.appendChild( valueText );
262 keyElement.appendChild( valueElement );
283 if ( !foundQgsProperty )
289 return foundQgsProperty->
value();
297 tabString.fill(
'\t', tabs );
302 tabString.fill(
'\t', tabs );
306 QHashIterator < QString, QgsProperty* > i(
mProperties );
307 while ( i.hasNext() )
309 if ( i.next().value()->isValue() )
314 if ( QVariant::StringList == propertyValue->
value().type() )
316 QgsDebugMsg( QString(
"%1key: <%2> value:" ).arg( tabString ).arg( i.key() ) );
317 propertyValue->
dump( tabs + 1 );
321 QgsDebugMsg( QString(
"%1key: <%2> value: %3" ).arg( tabString ).arg( i.key() ).arg( propertyValue->
value().toString() ) );
329 .arg( dynamic_cast<QgsPropertyKey*>( i.value() )->
name() ) );
330 i.value()->dump( tabs + 1 );
354 QDomNodeList subkeys = keyNode.childNodes();
356 while ( i < subkeys.count() )
361 if ( subkeys.item( i ).hasAttributes() &&
362 subkeys.item( i ).isElement() &&
363 subkeys.item( i ).toElement().hasAttribute(
"type" ) )
365 delete mProperties.take( subkeys.item( i ).nodeName() );
368 QDomNode subkey = subkeys.item( i );
370 if ( !
mProperties[subkeys.item( i ).nodeName()]->readXML( subkey ) )
372 QgsDebugMsg( QString(
"unable to parse key value %1" ).arg( subkeys.item( i ).nodeName() ) );
378 addKey( subkeys.item( i ).nodeName() );
380 QDomNode subkey = subkeys.item( i );
382 if ( !
mProperties[subkeys.item( i ).nodeName()]->readXML( subkey ) )
384 QgsDebugMsg( QString(
"unable to parse subkey %1" ).arg( subkeys.item( i ).nodeName() ) );
404 QDomElement keyElement = document.createElement( nodeName );
408 QHashIterator < QString, QgsProperty* > i(
mProperties );
409 while ( i.hasNext() )
412 if ( !i.value()->writeXML( i.key(), keyElement, document ) )
419 element.appendChild( keyElement );
431 QHashIterator < QString, QgsProperty* > i(
mProperties );
432 while ( i.hasNext() )
435 if ( i.next().value()->isLeaf() )
437 entries.append( i.key() );
447 QHashIterator < QString, QgsProperty* > i(
mProperties );
448 while ( i.hasNext() )
451 if ( !i.next().value()->isLeaf() )
453 entries.append( i.key() );
465 else if ( 1 ==
count() )
467 QHashIterator < QString, QgsProperty* > i(
mProperties );
469 if ( i.hasNext() && i.next().value()->isValue() )