diff --git a/python/core/auto_generated/qgslayernotesutils.sip.in b/python/core/auto_generated/qgslayernotesutils.sip.in index a2a779e4a9a..6b36ec05a07 100644 --- a/python/core/auto_generated/qgslayernotesutils.sip.in +++ b/python/core/auto_generated/qgslayernotesutils.sip.in @@ -23,7 +23,7 @@ Contains utility functions for working with layer notes. %End public: - static QString layerNotes( QgsMapLayer *layer ); + static QString layerNotes( const QgsMapLayer *layer ); %Docstring Returns the notes for the specified ``layer``. @@ -35,7 +35,7 @@ The returned string is a HTML formatted set of user notations for the layer. Sets the ``notes`` for the specified ``layer``, where ``notes`` is a HTML formatted string. %End - static bool layerHasNotes( QgsMapLayer *layer ); + static bool layerHasNotes( const QgsMapLayer *layer ); %Docstring Returns ``True`` if the specified ``layer`` has notes available. %End diff --git a/python/core/auto_generated/qgsmaplayer.sip.in b/python/core/auto_generated/qgsmaplayer.sip.in index 414925b8cb0..dec957030bd 100644 --- a/python/core/auto_generated/qgsmaplayer.sip.in +++ b/python/core/auto_generated/qgsmaplayer.sip.in @@ -108,6 +108,7 @@ This is the base class for all map layer types (vector, raster). Temporal, Legend, Elevation, + Notes, AllStyleCategories }; typedef QFlags StyleCategories; diff --git a/src/core/qgslayernotesutils.cpp b/src/core/qgslayernotesutils.cpp index 26932a11efe..af1e8098e43 100644 --- a/src/core/qgslayernotesutils.cpp +++ b/src/core/qgslayernotesutils.cpp @@ -16,7 +16,7 @@ #include "qgslayernotesutils.h" #include "qgsmaplayer.h" -QString QgsLayerNotesUtils::layerNotes( QgsMapLayer *layer ) +QString QgsLayerNotesUtils::layerNotes( const QgsMapLayer *layer ) { if ( !layer ) return nullptr; @@ -35,7 +35,7 @@ void QgsLayerNotesUtils::setLayerNotes( QgsMapLayer *layer, const QString ¬es layer->setCustomProperty( QStringLiteral( "userNotes" ), notes ); } -bool QgsLayerNotesUtils::layerHasNotes( QgsMapLayer *layer ) +bool QgsLayerNotesUtils::layerHasNotes( const QgsMapLayer *layer ) { if ( !layer ) return false; diff --git a/src/core/qgslayernotesutils.h b/src/core/qgslayernotesutils.h index 3b7329453bf..f4581051022 100644 --- a/src/core/qgslayernotesutils.h +++ b/src/core/qgslayernotesutils.h @@ -37,7 +37,7 @@ class CORE_EXPORT QgsLayerNotesUtils * * The returned string is a HTML formatted set of user notations for the layer. */ - static QString layerNotes( QgsMapLayer *layer ); + static QString layerNotes( const QgsMapLayer *layer ); /** * Sets the \a notes for the specified \a layer, where \a notes is a HTML formatted string. @@ -47,7 +47,7 @@ class CORE_EXPORT QgsLayerNotesUtils /** * Returns TRUE if the specified \a layer has notes available. */ - static bool layerHasNotes( QgsMapLayer *layer ); + static bool layerHasNotes( const QgsMapLayer *layer ); /** * Removes any notes for the specified \a layer. diff --git a/src/core/qgsmaplayer.cpp b/src/core/qgsmaplayer.cpp index c8e169bedd9..2d4b5b7ca90 100644 --- a/src/core/qgsmaplayer.cpp +++ b/src/core/qgsmaplayer.cpp @@ -60,6 +60,7 @@ #include "qgsmaplayertemporalproperties.h" #include "qgsmaplayerelevationproperties.h" #include "qgsprovidermetadata.h" +#include "qgslayernotesutils.h" QString QgsMapLayer::extensionPropertyType( QgsMapLayer::PropertyType type ) { @@ -621,6 +622,12 @@ void QgsMapLayer::writeCommonStyle( QDomElement &layerElement, QDomDocument &doc properties->writeXml( layerElement, document, context ); } + if ( categories.testFlag( Notes ) && QgsLayerNotesUtils::layerHasNotes( this ) ) + { + QDomElement notesElem = document.createElement( QStringLiteral( "userNotes" ) ); + notesElem.setAttribute( QStringLiteral( "value" ), QgsLayerNotesUtils::layerNotes( this ) ); + layerElement.appendChild( notesElem ); + } // custom properties if ( categories.testFlag( CustomProperties ) ) @@ -1750,6 +1757,16 @@ void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsRea if ( QgsMapLayerElevationProperties *properties = elevationProperties() ) properties->readXml( layerElement.toElement(), context ); } + + if ( categories.testFlag( Notes ) ) + { + const QDomElement notesElem = layerElement.firstChildElement( QStringLiteral( "userNotes" ) ); + if ( !notesElem.isNull() ) + { + const QString notes = notesElem.attribute( QStringLiteral( "value" ) ); + QgsLayerNotesUtils::setLayerNotes( this, notes ); + } + } } QUndoStack *QgsMapLayer::undoStack() diff --git a/src/core/qgsmaplayer.h b/src/core/qgsmaplayer.h index 9af1653770b..0c0ecd178a9 100644 --- a/src/core/qgsmaplayer.h +++ b/src/core/qgsmaplayer.h @@ -183,8 +183,9 @@ class CORE_EXPORT QgsMapLayer : public QObject Temporal = 1 << 14, //!< Temporal properties (since QGIS 3.14) Legend = 1 << 15, //!< Legend settings (since QGIS 3.16) Elevation = 1 << 16, //!< Elevation settings (since QGIS 3.18) + Notes = 1 << 17, //!< Layer user notes (since QGIS 3.20) AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions | - MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation, + MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes, }; Q_ENUM( StyleCategory ) Q_DECLARE_FLAGS( StyleCategories, StyleCategory ) diff --git a/src/gui/qgsmaplayerstylecategoriesmodel.cpp b/src/gui/qgsmaplayerstylecategoriesmodel.cpp index 9195fcfacbb..e18e8026b58 100644 --- a/src/gui/qgsmaplayerstylecategoriesmodel.cpp +++ b/src/gui/qgsmaplayerstylecategoriesmodel.cpp @@ -286,6 +286,17 @@ QVariant QgsMapLayerStyleCategoriesModel::data( const QModelIndex &index, int ro } break; + case QgsMapLayer::StyleCategory::Notes: + switch ( role ) + { + case Qt::DisplayRole: + case Qt::ToolTipRole: + return tr( "Notes" ); + case Qt::DecorationRole: + return QIcon(); // TODO + } + break; + case QgsMapLayer::StyleCategory::AllStyleCategories: switch ( role ) {