mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
(optionally) Store layer notes in QML/QLR and allow copying/pasting
when copying styles between layers Sponsored by Alta Ehf
This commit is contained in:
parent
7ec1abb725
commit
f5449a1fe9
@ -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
|
||||
|
@ -108,6 +108,7 @@ This is the base class for all map layer types (vector, raster).
|
||||
Temporal,
|
||||
Legend,
|
||||
Elevation,
|
||||
Notes,
|
||||
AllStyleCategories
|
||||
};
|
||||
typedef QFlags<QgsMapLayer::StyleCategory> StyleCategories;
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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()
|
||||
|
@ -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 )
|
||||
|
@ -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 )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user