23#include <QDomDocument>
36 tabString.fill(
'\t', tabs );
38 if ( QMetaType::Type::QStringList == mValue.userType() )
40 const QStringList sl = mValue.toStringList();
42 for (
const auto &
string : sl )
49 QgsDebugMsgLevel( QStringLiteral(
"%1%2" ).arg( tabString, mValue.toString() ), 4 );
57 QDomElement subkeyElement = keyNode.toElement();
60 QString typeString = subkeyElement.attribute( QStringLiteral(
"type" ) );
62 if ( typeString.isNull() )
64 QgsDebugError( QStringLiteral(
"null ``type'' attribute for %1" ).arg( keyNode.nodeName() ) );
74#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
75 QMetaType::Type type =
static_cast<QMetaType::Type
>( QMetaType::type( typeString.toLocal8Bit().constData() ) );
77 QMetaType::Type type =
static_cast<QMetaType::Type
>( QMetaType::fromName( typeString.toLocal8Bit().constData() ).id() );
89 case QMetaType::Type::UnknownType:
90 QgsDebugError( QStringLiteral(
"invalid value type %1 .. " ).arg( typeString ) );
93 case QMetaType::Type::QVariantMap:
94 QgsDebugError( QStringLiteral(
"no support for QVariant::Map" ) );
97 case QMetaType::Type::QVariantList:
98 QgsDebugError( QStringLiteral(
"no support for QVariant::List" ) );
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( QStringLiteral(
"non <value> element ``%1'' in string list" ).arg( values.item( i ).nodeName() ) );
128 mValue = valueStringList;
132 case QMetaType::Type::QFont:
133 QgsDebugError( QStringLiteral(
"no support for QVariant::Font" ) );
136 case QMetaType::Type::QPixmap:
137 QgsDebugError( QStringLiteral(
"no support for QVariant::Pixmap" ) );
140 case QMetaType::Type::QBrush:
141 QgsDebugError( QStringLiteral(
"no support for QVariant::Brush" ) );
144 case QMetaType::Type::QRect:
145 QgsDebugError( QStringLiteral(
"no support for QVariant::Rect" ) );
148 case QMetaType::Type::QSize:
149 QgsDebugError( QStringLiteral(
"no support for QVariant::Size" ) );
152 case QMetaType::Type::QColor:
153 QgsDebugError( QStringLiteral(
"no support for QVariant::Color" ) );
156 case QMetaType::Type::QPalette:
157 QgsDebugError( QStringLiteral(
"no support for QVariant::Palette" ) );
160 case QMetaType::Type::QPoint:
161 QgsDebugError( QStringLiteral(
"no support for QVariant::Point" ) );
164 case QMetaType::Type::QImage:
165 QgsDebugError( QStringLiteral(
"no support for QVariant::Image" ) );
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:
189 QgsDebugError( QStringLiteral(
"no support for QVariant::Polygon" ) );
192 case QMetaType::Type::QRegion:
193 QgsDebugError( QStringLiteral(
"no support for QVariant::Region" ) );
196 case QMetaType::Type::QBitmap:
197 QgsDebugError( QStringLiteral(
"no support for QVariant::Bitmap" ) );
200 case QMetaType::Type::QCursor:
201 QgsDebugError( QStringLiteral(
"no support for QVariant::Cursor" ) );
204 case QMetaType::Type::QBitArray :
205 QgsDebugError( QStringLiteral(
"no support for QVariant::BitArray" ) );
208 case QMetaType::Type::QKeySequence :
209 QgsDebugError( QStringLiteral(
"no support for QVariant::KeySequence" ) );
212 case QMetaType::Type::QPen :
213 QgsDebugError( QStringLiteral(
"no support for QVariant::Pen" ) );
217 case QVariant::LongLong :
218 value_ = QVariant( subkeyElement.text() ).toLongLong();
221 case QVariant::ULongLong :
222 value_ = QVariant( subkeyElement.text() ).toULongLong();
226 QgsDebugError( QStringLiteral(
"unsupported value type %1 .. not properly translated to QVariant" ).arg( typeString ) );
236 QDomElement &keyElement,
237 QDomDocument &document )
239 QDomElement valueElement = document.createElement( nodeName );
242 valueElement.setAttribute( QStringLiteral(
"type" ), 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( QStringLiteral(
"value" ) );
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() )
321 QgsDebugMsgLevel( QStringLiteral(
"%1key: <%2> value:" ).arg( tabString, i.key() ), 4 );
322 propertyValue->
dump( tabs + 1 );
326 QgsDebugMsgLevel( QStringLiteral(
"%1key: <%2> value: %3" ).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() )
368 if ( subkeys.item( i ).hasAttributes() &&
369 subkeys.item( i ).isElement() &&
370 subkeys.item( i ).toElement().hasAttribute( QStringLiteral(
"type" ) ) )
373 delete mProperties.take( subkeys.item( i ).nodeName() );
376 QDomNode subkey = subkeys.item( i );
378 if ( !mProperties[subkeys.item( i ).nodeName()]->readXml( subkey ) )
380 QgsDebugError( QStringLiteral(
"unable to parse key value %1" ).arg( subkeys.item( i ).nodeName() ) );
385 addKey( subkeys.item( i ).nodeName() );
387 QDomNode subkey = subkeys.item( i );
389 if ( !mProperties[subkeys.item( i ).nodeName()]->readXml( subkey ) )
391 QgsDebugError( QStringLiteral(
"unable to parse subkey %1" ).arg( subkeys.item( i ).nodeName() ) );
411 QDomElement keyElement = document.createElement( nodeName );
413 if ( ! mProperties.isEmpty() )
415 auto keys = mProperties.keys();
416 std::sort( keys.begin(), keys.end() );
418 for (
const auto &key : std::as_const( keys ) )
420 if ( !mProperties.value( key )->writeXml( key, keyElement, document ) )
425 element.appendChild( keyElement );
433 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
434 while ( i.hasNext() )
437 if ( i.next().value()->isLeaf() )
439 entries.append( i.key() );
447 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
448 while ( i.hasNext() )
451 if ( !i.next().value()->isLeaf() )
453 entries.append( i.key() );
465 else if ( 1 ==
count() )
467 QHashIterator < QString, QgsProjectProperty * > i( mProperties );
469 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)
Adds a message to the log instance (and creates it if necessary).
Project property key node.
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.
An Abstract Base Class for QGIS project property hierarchys.
virtual QVariant value() const =0
Returns the node's value.
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)