21 #include <QDomDocument> 22 #include <QStringList> 34 tabString.fill(
'\t', tabs );
36 if ( QVariant::StringList == mValue.type() )
38 const QStringList sl = mValue.toStringList();
40 for (
const auto &
string : sl )
42 QgsDebugMsg( QStringLiteral(
"%1[%2] " ).arg( tabString,
string ) );
47 QgsDebugMsg( QStringLiteral(
"%1%2" ).arg( tabString, mValue.toString() ) );
55 QDomElement subkeyElement = keyNode.toElement();
58 QString typeString = subkeyElement.attribute( QStringLiteral(
"type" ) );
60 if ( typeString.isNull() )
62 QgsDebugMsg( QStringLiteral(
"null ``type'' attribute for %1" ).arg( keyNode.nodeName() ) );
72 QVariant::Type type = QVariant::nameToType( typeString.toLocal8Bit().constData() );
83 case QVariant::Invalid:
84 QgsDebugMsg( QStringLiteral(
"invalid value type %1 .. " ).arg( typeString ) );
88 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Map" ) );
92 QgsDebugMsg( QStringLiteral(
"no support for QVariant::List" ) );
95 case QVariant::String:
96 mValue = subkeyElement.text();
99 case QVariant::StringList:
102 QDomNodeList values = keyNode.childNodes();
105 QStringList valueStringList;
107 while ( i < values.count() )
109 if (
"value" == values.item( i ).nodeName() )
112 valueStringList.append( values.item( i ).firstChild().nodeValue() );
116 QgsDebugMsg( QStringLiteral(
"non <value> element ``%1'' in string list" ).arg( values.item( i ).nodeName() ) );
122 mValue = valueStringList;
127 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Font" ) );
130 case QVariant::Pixmap:
131 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Pixmap" ) );
134 case QVariant::Brush:
135 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Brush" ) );
139 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Rect" ) );
143 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Size" ) );
146 case QVariant::Color:
147 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Color" ) );
150 case QVariant::Palette:
151 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Palette" ) );
154 case QVariant::Point:
155 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Point" ) );
158 case QVariant::Image:
159 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Image" ) );
163 mValue = QVariant( subkeyElement.text() ).toInt();
167 mValue = QVariant( subkeyElement.text() ).toUInt();
171 mValue = QVariant( subkeyElement.text() ).toBool();
174 case QVariant::Double:
175 mValue = QVariant( subkeyElement.text() ).toDouble();
178 case QVariant::ByteArray:
179 mValue = QVariant( subkeyElement.text() ).toByteArray();
182 case QVariant::Polygon:
183 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Polygon" ) );
186 case QVariant::Region:
187 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Region" ) );
190 case QVariant::Bitmap:
191 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Bitmap" ) );
194 case QVariant::Cursor:
195 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Cursor" ) );
198 case QVariant::BitArray :
199 QgsDebugMsg( QStringLiteral(
"no support for QVariant::BitArray" ) );
202 case QVariant::KeySequence :
203 QgsDebugMsg( QStringLiteral(
"no support for QVariant::KeySequence" ) );
207 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Pen" ) );
210 #if 0 // Currently unsupported variant types 211 case QVariant::LongLong :
212 value_ = QVariant( subkeyElement.text() ).toLongLong();
215 case QVariant::ULongLong :
216 value_ = QVariant( subkeyElement.text() ).toULongLong();
221 QgsDebugMsg( QStringLiteral(
"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( QStringLiteral(
"type" ), mValue.typeName() );
244 if ( QVariant::StringList == mValue.type() )
246 QStringList sl = mValue.toStringList();
248 for ( QStringList::iterator i = sl.begin();
252 QDomElement stringListElement = document.createElement( QStringLiteral(
"value" ) );
253 QDomText valueText = document.createTextNode( *i );
254 stringListElement.appendChild( valueText );
256 valueElement.appendChild( stringListElement );
261 QDomText valueText = document.createTextNode( mValue.toString() );
262 valueElement.appendChild( valueText );
265 keyElement.appendChild( valueElement );
284 if ( !foundQgsProperty )
286 QgsDebugMsg( QStringLiteral(
"key has null child" ) );
290 return foundQgsProperty->
value();
298 tabString.fill(
'\t', tabs );
300 QgsDebugMsg( QStringLiteral(
"%1name: %2" ).arg( tabString,
name() ) );
303 tabString.fill(
'\t', tabs );
305 if ( ! mProperties.isEmpty() )
307 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
308 while ( i.hasNext() )
310 if ( i.next().value()->isValue() )
314 if ( QVariant::StringList == propertyValue->
value().type() )
316 QgsDebugMsg( QStringLiteral(
"%1key: <%2> value:" ).arg( tabString, i.key() ) );
317 propertyValue->
dump( tabs + 1 );
321 QgsDebugMsg( QStringLiteral(
"%1key: <%2> value: %3" ).arg( tabString, i.key(), propertyValue->
value().toString() ) );
326 QgsDebugMsg( QStringLiteral(
"%1key: <%2> subkey: <%3>" )
330 i.value()->dump( tabs + 1 );
334 qDebug(
"<%s>",
name().toUtf8().constData() );
335 if ( i.value()->isValue() )
337 qDebug(
" <%s>", i.key().toUtf8().constData() );
340 if ( i.value()->isValue() )
342 qDebug(
" </%s>", i.key().toUtf8().constData() );
344 qDebug(
"</%s>",
name().toUtf8().constData() );
356 QDomNodeList subkeys = keyNode.childNodes();
358 while ( i < subkeys.count() )
363 if ( subkeys.item( i ).hasAttributes() &&
364 subkeys.item( i ).isElement() &&
365 subkeys.item( i ).toElement().hasAttribute( QStringLiteral(
"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( QStringLiteral(
"unable to parse key value %1" ).arg( subkeys.item( i ).nodeName() ) );
380 addKey( subkeys.item( i ).nodeName() );
382 QDomNode subkey = subkeys.item( i );
384 if ( !mProperties[subkeys.item( i ).nodeName()]->readXml( subkey ) )
386 QgsDebugMsg( QStringLiteral(
"unable to parse subkey %1" ).arg( subkeys.item( i ).nodeName() ) );
406 QDomElement keyElement = document.createElement( nodeName );
408 if ( ! mProperties.isEmpty() )
410 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
411 while ( i.hasNext() )
414 if ( !i.value()->writeXml( i.key(), keyElement, document ) )
421 element.appendChild( keyElement );
429 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
430 while ( i.hasNext() )
433 if ( i.next().value()->isLeaf() )
435 entries.append( i.key() );
443 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
444 while ( i.hasNext() )
447 if ( !i.next().value()->isLeaf() )
449 entries.append( i.key() );
461 else if ( 1 ==
count() )
463 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
465 if ( i.hasNext() && i.next().value()->isValue() )
QgsProjectPropertyKey(const QString &name=QString())
Create a new QgsProjectPropertyKey with the specified identifier.
QVariant value() const override
Returns the node's value.
virtual QVariant value() const =0
Returns the node's value.
QgsProjectPropertyKey * addKey(const QString &keyName)
Adds the specified property key as a sub-key.
void entryList(QStringList &entries) const
Returns any sub-keys contained by this property that do not contain other keys.
Project property value node, contains a QgsProjectPropertyKey's value.
void dump(int tabs=0) const override
Dumps out the keys and values.
QString name() const
The name of the property is used as identifier.
QVariant value() const override
If this key has a value, it will be stored by its name in its properties.
int count() const
Returns the number of sub-keys contained by this property.
virtual void clearKeys()
Deletes any sub-nodes from the property.
void dump(int tabs=0) const override
Dumps out the keys and values.
bool readXml(const QDomNode &keyNode) override
Restores the property hierarchy from a specified DOM node.
Project property key node.
bool writeXml(const QString &nodeName, QDomElement &element, QDomDocument &document) override
Writes the property hierarchy to a specified DOM element.
~QgsProjectPropertyKey() override
An Abstract Base Class for QGIS project property hierarchys.
void subkeyList(QStringList &entries) const
Returns any sub-keys contained by this property which themselves contain other keys.
bool readXml(const QDomNode &keyNode) override
Restores the property hierarchy from a specified DOM node.
bool isLeaf() const override
Returns true if property is a leaf node.
void setName(const QString &name)
The name of the property is used as identifier.
bool writeXml(const QString &nodeName, QDomElement &element, QDomDocument &document) override
Writes the property hierarchy to a specified DOM element.