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 ) );
40 QgsDebugMsg( QString(
"%1%2" ).arg( tabString ).arg( value_.toString() ) );
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() ) );
114 value_ = valueStringList;
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 );
301 if ( ! mProperties.isEmpty() )
303 QHashIterator < QString, QgsProperty* > i( mProperties );
304 while ( i.hasNext() )
306 if ( i.next().value()->isValue() )
310 if ( QVariant::StringList == propertyValue->
value().type() )
312 QgsDebugMsg( QString(
"%1key: <%2> value:" ).arg( tabString ).arg( i.key() ) );
313 propertyValue->
dump( tabs + 1 );
317 QgsDebugMsg( QString(
"%1key: <%2> value: %3" ).arg( tabString ).arg( i.key() ).arg( propertyValue->
value().toString() ) );
325 .arg( dynamic_cast<QgsPropertyKey*>( i.value() )->
name() ) );
326 i.value()->dump( tabs + 1 );
330 qDebug(
"<%s>",
name().toUtf8().constData() );
331 if ( i.value()->isValue() )
333 qDebug(
" <%s>", i.key().toUtf8().constData() );
336 if ( i.value()->isValue() )
338 qDebug(
" </%s>", i.key().toUtf8().constData() );
340 qDebug(
"</%s>",
name().toUtf8().constData() );
352 QDomNodeList subkeys = keyNode.childNodes();
354 while ( i < subkeys.count() )
359 if ( subkeys.item( i ).hasAttributes() &&
360 subkeys.item( i ).isElement() &&
361 subkeys.item( i ).toElement().hasAttribute(
"type" ) )
363 delete mProperties.take( subkeys.item( i ).nodeName() );
366 QDomNode subkey = subkeys.item( i );
368 if ( !mProperties[subkeys.item( i ).nodeName()]->readXML( subkey ) )
370 QgsDebugMsg( QString(
"unable to parse key value %1" ).arg( subkeys.item( i ).nodeName() ) );
376 addKey( subkeys.item( i ).nodeName() );
378 QDomNode subkey = subkeys.item( i );
380 if ( !mProperties[subkeys.item( i ).nodeName()]->readXML( subkey ) )
382 QgsDebugMsg( QString(
"unable to parse subkey %1" ).arg( subkeys.item( i ).nodeName() ) );
402 QDomElement keyElement = document.createElement( nodeName );
404 if ( ! mProperties.isEmpty() )
406 QHashIterator < QString, QgsProperty* > i( mProperties );
407 while ( i.hasNext() )
410 if ( !i.value()->writeXML( i.key(), keyElement, document ) )
417 element.appendChild( keyElement );
429 QHashIterator < QString, QgsProperty* > i( mProperties );
430 while ( i.hasNext() )
433 if ( i.next().value()->isLeaf() )
435 entries.append( i.key() );
445 QHashIterator < QString, QgsProperty* > i( mProperties );
446 while ( i.hasNext() )
449 if ( !i.next().value()->isLeaf() )
451 entries.append( i.key() );
463 else if ( 1 ==
count() )
465 QHashIterator < QString, QgsProperty* > i( mProperties );
467 if ( i.hasNext() && i.next().value()->isValue() )