24#include <QDomDocument>
37 tabString.fill(
'\t', tabs );
39 if ( QMetaType::Type::QStringList == mValue.userType() )
41 const QStringList sl = mValue.toStringList();
43 for (
const auto &
string : sl )
58 QDomElement subkeyElement = keyNode.toElement();
61 QString typeString = subkeyElement.attribute( u
"type"_s );
63 if ( typeString.isNull() )
65 QgsDebugError( u
"null ``type'' attribute for %1"_s.arg( keyNode.nodeName() ) );
75 QMetaType::Type type =
static_cast<QMetaType::Type
>( QMetaType::fromName( typeString.toLocal8Bit().constData() ).id() );
86 case QMetaType::Type::UnknownType:
87 QgsDebugError( u
"invalid value type %1 .. "_s.arg( typeString ) );
90 case QMetaType::Type::QVariantMap:
94 case QMetaType::Type::QVariantList:
98 case QMetaType::Type::QString:
99 mValue = subkeyElement.text();
102 case QMetaType::Type::QStringList:
105 QDomNodeList values = keyNode.childNodes();
108 QStringList valueStringList;
110 while ( i < values.count() )
112 if (
"value" == values.item( i ).nodeName() )
115 valueStringList.append( values.item( i ).firstChild().nodeValue() );
119 QgsDebugError( u
"non <value> element ``%1'' in string list"_s.arg( values.item( i ).nodeName() ) );
125 mValue = valueStringList;
129 case QMetaType::Type::QFont:
133 case QMetaType::Type::QPixmap:
137 case QMetaType::Type::QBrush:
141 case QMetaType::Type::QRect:
145 case QMetaType::Type::QSize:
149 case QMetaType::Type::QColor:
153 case QMetaType::Type::QPalette:
157 case QMetaType::Type::QPoint:
161 case QMetaType::Type::QImage:
165 case QMetaType::Type::Int:
166 mValue = QVariant( subkeyElement.text() ).toInt();
169 case QMetaType::Type::UInt:
170 mValue = QVariant( subkeyElement.text() ).toUInt();
173 case QMetaType::Type::Bool:
174 mValue = QVariant( subkeyElement.text() ).toBool();
177 case QMetaType::Type::Double:
178 mValue = QVariant( subkeyElement.text() ).toDouble();
181 case QMetaType::Type::QByteArray:
182 mValue = QVariant( subkeyElement.text() ).toByteArray();
185 case QMetaType::Type::QPolygon:
189 case QMetaType::Type::QRegion:
193 case QMetaType::Type::QBitmap:
197 case QMetaType::Type::QCursor:
201 case QMetaType::Type::QBitArray :
205 case QMetaType::Type::QKeySequence :
209 case QMetaType::Type::QPen :
214 case QVariant::LongLong :
215 value_ = QVariant( subkeyElement.text() ).toLongLong();
218 case QVariant::ULongLong :
219 value_ = QVariant( subkeyElement.text() ).toULongLong();
223 QgsDebugError( u
"unsupported value type %1 .. not properly translated to QVariant"_s.arg( typeString ) );
233 QDomElement &keyElement,
234 QDomDocument &document )
236 QDomElement valueElement = document.createElement( u
"properties"_s );
239 valueElement.setAttribute( u
"name"_s, nodeName );
240 valueElement.setAttribute( u
"type"_s, mValue.typeName() );
246 if ( QMetaType::Type::QStringList == mValue.userType() )
248 QStringList sl = mValue.toStringList();
250 for ( QStringList::iterator i = sl.begin();
254 QDomElement stringListElement = document.createElement( u
"value"_s );
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 )
292 return foundQgsProperty->
value();
300 tabString.fill(
'\t', tabs );
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 ( QMetaType::Type::QStringList == propertyValue->
value().userType() )
319 propertyValue->
dump( tabs + 1 );
323 QgsDebugMsgLevel( u
"%1key: <%2> value: %3"_s.arg( tabString, i.key(), propertyValue->
value().toString() ), 4 );
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() )
362 const QDomNode subkey = subkeys.item( i );
365 if ( subkey.nodeName() ==
"properties"_L1 &&
366 subkey.hasAttributes() &&
367 subkey.isElement() &&
368 subkey.toElement().hasAttribute( u
"name"_s ) )
369 name = subkey.toElement().attribute( u
"name"_s );
371 name = subkey.nodeName();
376 if ( subkey.hasAttributes() &&
377 subkey.isElement() &&
378 subkey.toElement().hasAttribute( u
"type"_s ) )
382 delete mProperties.take(
name );
416 QDomElement keyElement = document.createElement(
"properties" );
417 keyElement.toElement().setAttribute( u
"name"_s, nodeName );
419 if ( ! mProperties.isEmpty() )
421 auto keys = mProperties.keys();
422 std::sort( keys.begin(), keys.end() );
424 for (
const auto &key : std::as_const( keys ) )
426 if ( !mProperties.value( key )->writeXml( key, keyElement, document ) )
431 element.appendChild( keyElement );
439 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
440 while ( i.hasNext() )
443 if ( i.next().value()->isLeaf() )
445 entries.append( i.key() );
453 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
454 while ( i.hasNext() )
457 if ( !i.next().value()->isLeaf() )
459 entries.append( i.key() );
471 else if ( 1 ==
count() )
473 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
475 if ( i.hasNext() && i.next().value()->isValue() )
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
bool isLeaf() const override
Returns true if property is a leaf node.
QString name() const
The name of the property is used as identifier.
QgsProjectPropertyKey(const QString &name=QString())
Create a new QgsProjectPropertyKey with the specified identifier.
void dump(int tabs=0) const override
Dumps out the keys and values.
virtual void clearKeys()
Deletes any sub-nodes from the property.
bool writeXml(const QString &nodeName, QDomElement &element, QDomDocument &document) override
Writes the property hierarchy to a specified DOM element.
void subkeyList(QStringList &entries) const
Returns any sub-keys contained by this property which themselves contain other keys.
void setName(const QString &name)
The name of the property is used as identifier.
QgsProjectPropertyKey * addKey(const QString &keyName)
Adds the specified property key as a sub-key.
~QgsProjectPropertyKey() override
QVariant value() const override
If this key has a value, it will be stored by its name in its properties.
void entryList(QStringList &entries) const
Returns any sub-keys contained by this property that do not contain other keys.
int count() const
Returns the number of sub-keys contained by this property.
bool readXml(const QDomNode &keyNode) override
Restores the property hierarchy from a specified DOM node.
Project property value node, contains a QgsProjectPropertyKey's value.
bool writeXml(const QString &nodeName, QDomElement &element, QDomDocument &document) override
Writes the property hierarchy to a specified DOM element.
QVariant value() const override
Returns the node's value.
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.
virtual QVariant value() const =0
Returns the node's value.
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)