23 #include <QDomDocument> 24 #include <QStringList> 36 tabString.fill(
'\t', tabs );
38 if ( QVariant::StringList == mValue.type() )
40 const QStringList sl = mValue.toStringList();
42 for (
const auto &
string : sl )
44 QgsDebugMsg( QStringLiteral(
"%1[%2] " ).arg( tabString,
string ) );
49 QgsDebugMsg( QStringLiteral(
"%1%2" ).arg( tabString, mValue.toString() ) );
57 QDomElement subkeyElement = keyNode.toElement();
60 QString typeString = subkeyElement.attribute( QStringLiteral(
"type" ) );
62 if ( typeString.isNull() )
64 QgsDebugMsg( QStringLiteral(
"null ``type'' attribute for %1" ).arg( keyNode.nodeName() ) );
74 QVariant::Type type = QVariant::nameToType( typeString.toLocal8Bit().constData() );
85 case QVariant::Invalid:
86 QgsDebugMsg( QStringLiteral(
"invalid value type %1 .. " ).arg( typeString ) );
90 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Map" ) );
94 QgsDebugMsg( QStringLiteral(
"no support for QVariant::List" ) );
97 case QVariant::String:
98 mValue = subkeyElement.text();
101 case QVariant::StringList:
104 QDomNodeList values = keyNode.childNodes();
107 QStringList valueStringList;
109 while ( i < values.count() )
111 if (
"value" == values.item( i ).nodeName() )
114 valueStringList.append( values.item( i ).firstChild().nodeValue() );
118 QgsDebugMsg( QStringLiteral(
"non <value> element ``%1'' in string list" ).arg( values.item( i ).nodeName() ) );
124 mValue = valueStringList;
129 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Font" ) );
132 case QVariant::Pixmap:
133 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Pixmap" ) );
136 case QVariant::Brush:
137 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Brush" ) );
141 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Rect" ) );
145 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Size" ) );
148 case QVariant::Color:
149 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Color" ) );
152 case QVariant::Palette:
153 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Palette" ) );
156 case QVariant::Point:
157 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Point" ) );
160 case QVariant::Image:
161 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Image" ) );
165 mValue = QVariant( subkeyElement.text() ).toInt();
169 mValue = QVariant( subkeyElement.text() ).toUInt();
173 mValue = QVariant( subkeyElement.text() ).toBool();
176 case QVariant::Double:
177 mValue = QVariant( subkeyElement.text() ).toDouble();
180 case QVariant::ByteArray:
181 mValue = QVariant( subkeyElement.text() ).toByteArray();
184 case QVariant::Polygon:
185 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Polygon" ) );
188 case QVariant::Region:
189 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Region" ) );
192 case QVariant::Bitmap:
193 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Bitmap" ) );
196 case QVariant::Cursor:
197 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Cursor" ) );
200 case QVariant::BitArray :
201 QgsDebugMsg( QStringLiteral(
"no support for QVariant::BitArray" ) );
204 case QVariant::KeySequence :
205 QgsDebugMsg( QStringLiteral(
"no support for QVariant::KeySequence" ) );
209 QgsDebugMsg( QStringLiteral(
"no support for QVariant::Pen" ) );
212 #if 0 // Currently unsupported variant types 213 case QVariant::LongLong :
214 value_ = QVariant( subkeyElement.text() ).toLongLong();
217 case QVariant::ULongLong :
218 value_ = QVariant( subkeyElement.text() ).toULongLong();
223 QgsDebugMsg( QStringLiteral(
"unsupported value type %1 .. not propertly translated to QVariant" ).arg( typeString ) );
233 QDomElement &keyElement,
234 QDomDocument &document )
236 QDomElement valueElement = document.createElement( nodeName );
239 valueElement.setAttribute( QStringLiteral(
"type" ), mValue.typeName() );
246 if ( QVariant::StringList == mValue.type() )
248 QStringList sl = mValue.toStringList();
250 for ( QStringList::iterator i = sl.begin();
254 QDomElement stringListElement = document.createElement( QStringLiteral(
"value" ) );
255 QDomText valueText = document.createTextNode( *i );
256 stringListElement.appendChild( valueText );
258 valueElement.appendChild( stringListElement );
263 QDomText valueText = document.createTextNode( mValue.toString() );
264 valueElement.appendChild( valueText );
267 keyElement.appendChild( valueElement );
286 if ( !foundQgsProperty )
288 QgsDebugMsg( QStringLiteral(
"key has null child" ) );
292 return foundQgsProperty->
value();
300 tabString.fill(
'\t', tabs );
302 QgsDebugMsg( QStringLiteral(
"%1name: %2" ).arg( tabString,
name() ) );
305 tabString.fill(
'\t', tabs );
307 if ( ! mProperties.isEmpty() )
309 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
310 while ( i.hasNext() )
312 if ( i.next().value()->isValue() )
316 if ( QVariant::StringList == propertyValue->
value().type() )
318 QgsDebugMsg( QStringLiteral(
"%1key: <%2> value:" ).arg( tabString, i.key() ) );
319 propertyValue->
dump( tabs + 1 );
323 QgsDebugMsg( QStringLiteral(
"%1key: <%2> value: %3" ).arg( tabString, i.key(), propertyValue->
value().toString() ) );
328 QgsDebugMsg( QStringLiteral(
"%1key: <%2> subkey: <%3>" )
332 i.value()->dump( tabs + 1 );
336 qDebug(
"<%s>",
name().toUtf8().constData() );
337 if ( i.value()->isValue() )
339 qDebug(
" <%s>", i.key().toUtf8().constData() );
342 if ( i.value()->isValue() )
344 qDebug(
" </%s>", i.key().toUtf8().constData() );
346 qDebug(
"</%s>",
name().toUtf8().constData() );
358 QDomNodeList subkeys = keyNode.childNodes();
360 while ( i < subkeys.count() )
365 if ( subkeys.item( i ).hasAttributes() &&
366 subkeys.item( i ).isElement() &&
367 subkeys.item( i ).toElement().hasAttribute( QStringLiteral(
"type" ) ) )
370 delete mProperties.take( subkeys.item( i ).nodeName() );
373 QDomNode subkey = subkeys.item( i );
375 if ( !mProperties[subkeys.item( i ).nodeName()]->readXml( subkey ) )
377 QgsDebugMsg( QStringLiteral(
"unable to parse key value %1" ).arg( subkeys.item( i ).nodeName() ) );
382 addKey( subkeys.item( i ).nodeName() );
384 QDomNode subkey = subkeys.item( i );
386 if ( !mProperties[subkeys.item( i ).nodeName()]->readXml( subkey ) )
388 QgsDebugMsg( QStringLiteral(
"unable to parse subkey %1" ).arg( subkeys.item( i ).nodeName() ) );
408 QDomElement keyElement = document.createElement( nodeName );
410 if ( ! mProperties.isEmpty() )
412 auto keys = mProperties.keys();
413 std::sort( keys.begin(), keys.end() );
415 for (
const auto &key : qgis::as_const( keys ) )
417 if ( !mProperties.value( key )->writeXml( key, keyElement, document ) )
422 element.appendChild( keyElement );
430 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
431 while ( i.hasNext() )
434 if ( i.next().value()->isLeaf() )
436 entries.append( i.key() );
444 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
445 while ( i.hasNext() )
448 if ( !i.next().value()->isLeaf() )
450 entries.append( i.key() );
462 else if ( 1 ==
count() )
464 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
466 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.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
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.