24#include <QDomDocument>
28using namespace Qt::StringLiterals;
40 tabString.fill(
'\t', tabs );
42 if ( QMetaType::Type::QStringList == mValue.userType() )
44 const QStringList sl = mValue.toStringList();
46 for (
const auto &
string : sl )
61 QDomElement subkeyElement = keyNode.toElement();
64 QString typeString = subkeyElement.attribute( u
"type"_s );
66 if ( typeString.isNull() )
68 QgsDebugError( u
"null ``type'' attribute for %1"_s.arg( keyNode.nodeName() ) );
78 QMetaType::Type type =
static_cast<QMetaType::Type
>( QMetaType::fromName( typeString.toLocal8Bit().constData() ).id() );
89 case QMetaType::Type::UnknownType:
90 QgsDebugError( u
"invalid value type %1 .. "_s.arg( typeString ) );
93 case QMetaType::Type::QVariantMap:
97 case QMetaType::Type::QVariantList:
101 case QMetaType::Type::QString:
102 mValue = subkeyElement.text();
105 case QMetaType::Type::QStringList:
108 QDomNodeList values = keyNode.childNodes();
111 QStringList valueStringList;
113 while ( i < values.count() )
115 if (
"value" == values.item( i ).nodeName() )
118 valueStringList.append( values.item( i ).firstChild().nodeValue() );
122 QgsDebugError( u
"non <value> element ``%1'' in string list"_s.arg( values.item( i ).nodeName() ) );
128 mValue = valueStringList;
132 case QMetaType::Type::QFont:
136 case QMetaType::Type::QPixmap:
140 case QMetaType::Type::QBrush:
144 case QMetaType::Type::QRect:
148 case QMetaType::Type::QSize:
152 case QMetaType::Type::QColor:
156 case QMetaType::Type::QPalette:
160 case QMetaType::Type::QPoint:
164 case QMetaType::Type::QImage:
168 case QMetaType::Type::Int:
169 mValue = QVariant( subkeyElement.text() ).toInt();
172 case QMetaType::Type::UInt:
173 mValue = QVariant( subkeyElement.text() ).toUInt();
176 case QMetaType::Type::Bool:
177 mValue = QVariant( subkeyElement.text() ).toBool();
180 case QMetaType::Type::Double:
181 mValue = QVariant( subkeyElement.text() ).toDouble();
184 case QMetaType::Type::QByteArray:
185 mValue = QVariant( subkeyElement.text() ).toByteArray();
188 case QMetaType::Type::QPolygon:
192 case QMetaType::Type::QRegion:
196 case QMetaType::Type::QBitmap:
200 case QMetaType::Type::QCursor:
204 case QMetaType::Type::QBitArray :
208 case QMetaType::Type::QKeySequence :
212 case QMetaType::Type::QPen :
217 case QVariant::LongLong :
218 value_ = QVariant( subkeyElement.text() ).toLongLong();
221 case QVariant::ULongLong :
222 value_ = QVariant( subkeyElement.text() ).toULongLong();
226 QgsDebugError( u
"unsupported value type %1 .. not properly translated to QVariant"_s.arg( typeString ) );
236 QDomElement &keyElement,
237 QDomDocument &document )
239 QDomElement valueElement = document.createElement( u
"properties"_s );
242 valueElement.setAttribute( u
"name"_s, nodeName );
243 valueElement.setAttribute( u
"type"_s, mValue.typeName() );
249 if ( QMetaType::Type::QStringList == mValue.userType() )
251 QStringList sl = mValue.toStringList();
253 for ( QStringList::iterator i = sl.begin();
257 QDomElement stringListElement = document.createElement( u
"value"_s );
258 QDomText valueText = document.createTextNode( *i );
259 stringListElement.appendChild( valueText );
261 valueElement.appendChild( stringListElement );
266 QDomText valueText = document.createTextNode( mValue.toString() );
267 valueElement.appendChild( valueText );
270 keyElement.appendChild( valueElement );
289 if ( !foundQgsProperty )
295 return foundQgsProperty->
value();
303 tabString.fill(
'\t', tabs );
308 tabString.fill(
'\t', tabs );
310 if ( ! mProperties.isEmpty() )
312 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
313 while ( i.hasNext() )
315 if ( i.next().value()->isValue() )
319 if ( QMetaType::Type::QStringList == propertyValue->
value().userType() )
322 propertyValue->
dump( tabs + 1 );
326 QgsDebugMsgLevel( u
"%1key: <%2> value: %3"_s.arg( tabString, i.key(), propertyValue->
value().toString() ), 4 );
335 i.value()->dump( tabs + 1 );
339 qDebug(
"<%s>",
name().toUtf8().constData() );
340 if ( i.value()->isValue() )
342 qDebug(
" <%s>", i.key().toUtf8().constData() );
345 if ( i.value()->isValue() )
347 qDebug(
" </%s>", i.key().toUtf8().constData() );
349 qDebug(
"</%s>",
name().toUtf8().constData() );
361 QDomNodeList subkeys = keyNode.childNodes();
363 while ( i < subkeys.count() )
365 const QDomNode subkey = subkeys.item( i );
368 if ( subkey.nodeName() ==
"properties"_L1 &&
369 subkey.hasAttributes() &&
370 subkey.isElement() &&
371 subkey.toElement().hasAttribute( u
"name"_s ) )
372 name = subkey.toElement().attribute( u
"name"_s );
374 name = subkey.nodeName();
379 if ( subkey.hasAttributes() &&
380 subkey.isElement() &&
381 subkey.toElement().hasAttribute( u
"type"_s ) )
385 delete mProperties.take(
name );
419 QDomElement keyElement = document.createElement(
"properties" );
420 keyElement.toElement().setAttribute( u
"name"_s, nodeName );
422 if ( ! mProperties.isEmpty() )
424 auto keys = mProperties.keys();
425 std::sort( keys.begin(), keys.end() );
427 for (
const auto &key : std::as_const( keys ) )
429 if ( !mProperties.value( key )->writeXml( key, keyElement, document ) )
434 element.appendChild( keyElement );
442 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
443 while ( i.hasNext() )
446 if ( i.next().value()->isLeaf() )
448 entries.append( i.key() );
456 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
457 while ( i.hasNext() )
460 if ( !i.next().value()->isLeaf() )
462 entries.append( i.key() );
474 else if ( 1 ==
count() )
476 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
478 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)