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 ) );
48 QDomElement subkeyElement = keyNode.toElement();
51 QString typeString = subkeyElement.attribute(
"type" );
53 if ( QString::null == typeString )
55 QgsDebugMsg( QString(
"null ``type'' attribute for %1" ).arg( keyNode.nodeName() ) );
65 QVariant::Type type = QVariant::nameToType( typeString.toLocal8Bit().constData() );
76 case QVariant::Invalid:
77 QgsDebugMsg( QString(
"invalid value type %1 .. " ).arg( typeString ) );
88 case QVariant::String:
89 value_ = subkeyElement.text();
92 case QVariant::StringList:
95 QDomNodeList values = keyNode.childNodes();
98 QStringList valueStringList;
100 while ( i < values.count() )
102 if (
"value" == values.item( i ).nodeName() )
104 valueStringList.append( values.item( i ).firstChild().nodeValue() );
108 QgsDebugMsg( QString(
"non <value> element ``%1'' in string list" ).arg( values.item( i ).nodeName() ) );
122 case QVariant::Pixmap:
126 case QVariant::Brush:
138 case QVariant::Color:
142 case QVariant::Palette:
146 case QVariant::Point:
150 case QVariant::Image:
155 value_ = QVariant( subkeyElement.text() ).toInt();
159 value_ = QVariant( subkeyElement.text() ).toUInt();
163 value_ = QVariant( subkeyElement.text() ).toBool();
166 case QVariant::Double:
167 value_ = QVariant( subkeyElement.text() ).toDouble();
170 case QVariant::ByteArray:
171 value_ = QVariant( subkeyElement.text() ).toByteArray();
174 case QVariant::Polygon:
178 case QVariant::Region:
182 case QVariant::Bitmap:
186 case QVariant::Cursor:
190 case QVariant::BitArray :
191 QgsDebugMsg(
"no support for QVariant::BitArray" );
194 case QVariant::KeySequence :
195 QgsDebugMsg(
"no support for QVariant::KeySequence" );
215 QgsDebugMsg( QString(
"unsupported value type %1 .. not propertly translated to QVariant" ).arg( typeString ) );
227 QDomElement & keyElement,
228 QDomDocument & document )
230 QDomElement valueElement = document.createElement( nodeName );
233 valueElement.setAttribute(
"type",
value_.typeName() );
240 if ( QVariant::StringList ==
value_.type() )
242 QStringList sl =
value_.toStringList();
244 for ( QStringList::iterator i = sl.begin();
248 QDomElement stringListElement = document.createElement(
"value" );
249 QDomText valueText = document.createTextNode( *i );
250 stringListElement.appendChild( valueText );
252 valueElement.appendChild( stringListElement );
257 QDomText valueText = document.createTextNode(
value_.toString() );
258 valueElement.appendChild( valueText );
261 keyElement.appendChild( valueElement );
280 if ( !foundQgsProperty )
286 return foundQgsProperty->
value();
294 tabString.fill(
'\t', tabs );
299 tabString.fill(
'\t', tabs );
303 QHashIterator < QString, QgsProperty* > i(
mProperties );
304 while ( i.hasNext() )
306 if ( i.next().value()->isValue() )
311 if ( QVariant::StringList == propertyValue->
value().type() )
313 QgsDebugMsg( QString(
"%1key: <%2> value:" ).arg( tabString ).arg( i.key() ) );
314 propertyValue->
dump( tabs + 1 );
318 QgsDebugMsg( QString(
"%1key: <%2> value: %3" ).arg( tabString ).arg( i.key() ).arg( propertyValue->
value().toString() ) );
326 .arg( dynamic_cast<QgsPropertyKey*>( i.value() )->
name() ) );
327 i.value()->dump( tabs + 1 );
331 qDebug(
"<%s>",
name().toUtf8().constData() );
332 if ( i.value()->isValue() )
334 qDebug(
" <%s>", i.key().toUtf8().constData() );
337 if ( i.value()->isValue() )
339 qDebug(
" </%s>", i.key().toUtf8().constData() );
341 qDebug(
"</%s>",
name().toUtf8().constData() );
353 QDomNodeList subkeys = keyNode.childNodes();
355 while ( i < subkeys.count() )
360 if ( subkeys.item( i ).hasAttributes() &&
361 subkeys.item( i ).isElement() &&
362 subkeys.item( i ).toElement().hasAttribute(
"type" ) )
364 delete mProperties.take( subkeys.item( i ).nodeName() );
367 QDomNode subkey = subkeys.item( i );
369 if ( !
mProperties[subkeys.item( i ).nodeName()]->readXML( subkey ) )
371 QgsDebugMsg( QString(
"unable to parse key value %1" ).arg( subkeys.item( i ).nodeName() ) );
377 addKey( subkeys.item( i ).nodeName() );
379 QDomNode subkey = subkeys.item( i );
381 if ( !
mProperties[subkeys.item( i ).nodeName()]->readXML( subkey ) )
383 QgsDebugMsg( QString(
"unable to parse subkey %1" ).arg( subkeys.item( i ).nodeName() ) );
403 QDomElement keyElement = document.createElement( nodeName );
407 QHashIterator < QString, QgsProperty* > i(
mProperties );
408 while ( i.hasNext() )
411 if ( !i.value()->writeXML( i.key(), keyElement, document ) )
418 element.appendChild( keyElement );
430 QHashIterator < QString, QgsProperty* > i(
mProperties );
431 while ( i.hasNext() )
434 if ( i.next().value()->isLeaf() )
436 entries.append( i.key() );
446 QHashIterator < QString, QgsProperty* > i(
mProperties );
447 while ( i.hasNext() )
450 if ( !i.next().value()->isLeaf() )
452 entries.append( i.key() );
464 else if ( 1 ==
count() )
466 QHashIterator < QString, QgsProperty* > i(
mProperties );
468 if ( i.hasNext() && i.next().value()->isValue() )