24#include <QDomDocument>
28using namespace Qt::StringLiterals;
39 tabString.fill(
'\t', tabs );
41 if ( QMetaType::Type::QStringList == mValue.userType() )
43 const QStringList sl = mValue.toStringList();
45 for (
const auto &
string : sl )
60 QDomElement subkeyElement = keyNode.toElement();
63 QString typeString = subkeyElement.attribute( u
"type"_s );
65 if ( typeString.isNull() )
67 QgsDebugError( u
"null ``type'' attribute for %1"_s.arg( keyNode.nodeName() ) );
77 QMetaType::Type type =
static_cast<QMetaType::Type
>( QMetaType::fromName( typeString.toLocal8Bit().constData() ).id() );
88 case QMetaType::Type::UnknownType:
89 QgsDebugError( u
"invalid value type %1 .. "_s.arg( typeString ) );
92 case QMetaType::Type::QVariantMap:
96 case QMetaType::Type::QVariantList:
100 case QMetaType::Type::QString:
101 mValue = subkeyElement.text();
104 case QMetaType::Type::QStringList:
107 QDomNodeList values = keyNode.childNodes();
110 QStringList valueStringList;
112 while ( i < values.count() )
114 if (
"value" == values.item( i ).nodeName() )
117 valueStringList.append( values.item( i ).firstChild().nodeValue() );
121 QgsDebugError( u
"non <value> element ``%1'' in string list"_s.arg( values.item( i ).nodeName() ) );
127 mValue = valueStringList;
131 case QMetaType::Type::QFont:
135 case QMetaType::Type::QPixmap:
139 case QMetaType::Type::QBrush:
143 case QMetaType::Type::QRect:
147 case QMetaType::Type::QSize:
151 case QMetaType::Type::QColor:
155 case QMetaType::Type::QPalette:
159 case QMetaType::Type::QPoint:
163 case QMetaType::Type::QImage:
167 case QMetaType::Type::Int:
168 mValue = QVariant( subkeyElement.text() ).toInt();
171 case QMetaType::Type::UInt:
172 mValue = QVariant( subkeyElement.text() ).toUInt();
175 case QMetaType::Type::Bool:
176 mValue = QVariant( subkeyElement.text() ).toBool();
179 case QMetaType::Type::Double:
180 mValue = QVariant( subkeyElement.text() ).toDouble();
183 case QMetaType::Type::QByteArray:
184 mValue = QVariant( subkeyElement.text() ).toByteArray();
187 case QMetaType::Type::QPolygon:
191 case QMetaType::Type::QRegion:
195 case QMetaType::Type::QBitmap:
199 case QMetaType::Type::QCursor:
203 case QMetaType::Type::QBitArray:
207 case QMetaType::Type::QKeySequence:
211 case QMetaType::Type::QPen:
216 case QVariant::LongLong :
217 value_ = QVariant( subkeyElement.text() ).toLongLong();
220 case QVariant::ULongLong :
221 value_ = QVariant( subkeyElement.text() ).toULongLong();
225 QgsDebugError( u
"unsupported value type %1 .. not properly translated to QVariant"_s.arg( typeString ) );
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(); i != sl.end(); ++i )
252 QDomElement stringListElement = document.createElement( u
"value"_s );
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 );
271 QDomElement valueElement = document.createElement( nodeName );
274 valueElement.setAttribute( u
"type"_s, mValue.typeName() );
280 if ( QMetaType::Type::QStringList == mValue.userType() )
282 QStringList sl = mValue.toStringList();
284 for ( QStringList::iterator i = sl.begin(); i != sl.end(); ++i )
286 QDomElement stringListElement = document.createElement( u
"value"_s );
287 QDomText valueText = document.createTextNode( *i );
288 stringListElement.appendChild( valueText );
290 valueElement.appendChild( stringListElement );
296 QDomText valueText = document.createTextNode( mValue.toString() );
297 valueElement.appendChild( valueText );
300 keyElement.appendChild( valueElement );
320 if ( !foundQgsProperty )
326 return foundQgsProperty->
value();
334 tabString.fill(
'\t', tabs );
339 tabString.fill(
'\t', tabs );
341 if ( !mProperties.isEmpty() )
343 QHashIterator< QString, QgsProjectProperty * > i( mProperties );
344 while ( i.hasNext() )
346 if ( i.next().value()->isValue() )
350 if ( QMetaType::Type::QStringList == propertyValue->
value().userType() )
353 propertyValue->
dump( tabs + 1 );
357 QgsDebugMsgLevel( u
"%1key: <%2> value: %3"_s.arg( tabString, i.key(), propertyValue->
value().toString() ), 4 );
363 i.value()->dump( tabs + 1 );
367 qDebug(
"<%s>",
name().toUtf8().constData() );
368 if ( i.value()->isValue() )
370 qDebug(
" <%s>", i.key().toUtf8().constData() );
373 if ( i.value()->isValue() )
375 qDebug(
" </%s>", i.key().toUtf8().constData() );
377 qDebug(
"</%s>",
name().toUtf8().constData() );
386 QDomNodeList subkeys = keyNode.childNodes();
387 bool hasModernProperties =
false;
388 for (
int i = 0; i < subkeys.count(); i++ )
390 const QDomNode subkey = subkeys.item( i );
391 if ( subkey.nodeName() ==
"properties"_L1
392 && subkey.hasAttributes()
396 subkey.toElement().hasAttribute( u
"name"_s ) )
398 hasModernProperties =
true;
402 for (
int i = 0; i < subkeys.count(); i++ )
404 const QDomNode subkey = subkeys.item( i );
407 if ( subkey.nodeName() ==
"properties"_L1
408 && subkey.hasAttributes()
412 subkey.toElement().hasAttribute( u
"name"_s ) )
414 name = subkey.toElement().attribute( u
"name"_s );
418 if ( hasModernProperties )
422 name = subkey.nodeName();
428 if ( subkey.hasAttributes()
432 subkey.toElement().hasAttribute( u
"type"_s ) )
435 delete mProperties.take(
name );
468 QDomElement keyElement = document.createElement(
"properties" );
469 keyElement.toElement().setAttribute( u
"name"_s, nodeName );
471 if ( !mProperties.isEmpty() )
473 auto keys = mProperties.keys();
474 std::sort( keys.begin(), keys.end() );
476 for (
const auto &key : std::as_const( keys ) )
478 if ( !mProperties.value( key )->writeXml( key, keyElement, document ) )
483 element.appendChild( keyElement );
488 const bool isRootProperties = element == document.documentElement();
489 QDomElement keyElement;
490 if ( isRootProperties )
492 keyElement = document.documentElement().firstChildElement( u
"properties"_s );
496 keyElement = document.createElement( nodeName );
499 if ( !mProperties.isEmpty() )
501 auto keys = mProperties.keys();
502 std::sort( keys.begin(), keys.end() );
504 for (
const auto &key : std::as_const( keys ) )
506 if ( !mProperties.value( key )->writeXml( key, keyElement, document ) )
511 if ( !isRootProperties )
513 element.appendChild( keyElement );
523 QHashIterator< QString, QgsProjectProperty * > i( mProperties );
524 while ( i.hasNext() )
527 if ( i.next().value()->isLeaf() )
529 entries.append( i.key() );
537 QHashIterator< QString, QgsProjectProperty * > i( mProperties );
538 while ( i.hasNext() )
541 if ( !i.next().value()->isLeaf() )
543 entries.append( i.key() );
555 else if ( 1 ==
count() )
557 QHashIterator< QString, QgsProjectProperty * > i( mProperties );
559 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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
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)