mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
Save and restore patch shapes for symbol nodes
This commit is contained in:
parent
8c94c9d9bf
commit
c4049c6439
@ -96,6 +96,24 @@ Miscellaneous utility functions for handling of map layer legend
|
||||
static QString legendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
|
||||
static bool hasLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
|
||||
|
||||
static void setLegendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsLegendPatchShape &shape );
|
||||
%Docstring
|
||||
Sets the legend patch ``shape`` for the legend node belonging to ``nodeLayer`` at the specified ``originalIndex``.
|
||||
|
||||
.. seealso:: :py:func:`legendNodePatchShape`
|
||||
|
||||
.. versionadded:: 3.14
|
||||
%End
|
||||
|
||||
static QgsLegendPatchShape legendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex );
|
||||
%Docstring
|
||||
Returns the legend patch shape for the legend node belonging to ``nodeLayer`` at the specified ``originalIndex``.
|
||||
|
||||
.. seealso:: :py:func:`setLegendNodePatchShape`
|
||||
|
||||
.. versionadded:: 3.14
|
||||
%End
|
||||
|
||||
static void applyLayerNodeProperties( QgsLayerTreeLayer *nodeLayer, QList<QgsLayerTreeModelLegendNode *> &nodes );
|
||||
%Docstring
|
||||
update according to layer node's custom properties (order of items, user labels for items)
|
||||
|
||||
@ -146,6 +146,27 @@ bool QgsMapLayerLegendUtils::hasLegendNodeUserLabel( QgsLayerTreeLayer *nodeLaye
|
||||
return nodeLayer->customProperties().contains( "legend/label-" + QString::number( originalIndex ) );
|
||||
}
|
||||
|
||||
void QgsMapLayerLegendUtils::setLegendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsLegendPatchShape &shape )
|
||||
{
|
||||
QDomDocument patchDoc;
|
||||
QDomElement patchElem = patchDoc.createElement( QStringLiteral( "patch" ) );
|
||||
shape.writeXml( patchElem, patchDoc, QgsReadWriteContext() );
|
||||
patchDoc.appendChild( patchElem );
|
||||
nodeLayer->setCustomProperty( "legend/patch-shape-" + QString::number( originalIndex ), patchDoc.toString() );
|
||||
}
|
||||
|
||||
QgsLegendPatchShape QgsMapLayerLegendUtils::legendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex )
|
||||
{
|
||||
QString patchDef = nodeLayer->customProperty( "legend/patch-shape-" + QString::number( originalIndex ) ).toString();
|
||||
if ( patchDef.isEmpty() )
|
||||
return QgsLegendPatchShape();
|
||||
|
||||
QDomDocument doc( QStringLiteral( "patch" ) );
|
||||
doc.setContent( patchDef );
|
||||
QgsLegendPatchShape shape;
|
||||
shape.readXml( doc.documentElement(), QgsReadWriteContext() );
|
||||
return shape;
|
||||
}
|
||||
|
||||
void QgsMapLayerLegendUtils::applyLayerNodeProperties( QgsLayerTreeLayer *nodeLayer, QList<QgsLayerTreeModelLegendNode *> &nodes )
|
||||
{
|
||||
@ -154,9 +175,17 @@ void QgsMapLayerLegendUtils::applyLayerNodeProperties( QgsLayerTreeLayer *nodeLa
|
||||
const auto constNodes = nodes;
|
||||
for ( QgsLayerTreeModelLegendNode *legendNode : constNodes )
|
||||
{
|
||||
QString userLabel = QgsMapLayerLegendUtils::legendNodeUserLabel( nodeLayer, i++ );
|
||||
QString userLabel = QgsMapLayerLegendUtils::legendNodeUserLabel( nodeLayer, i );
|
||||
if ( !userLabel.isNull() )
|
||||
legendNode->setUserLabel( userLabel );
|
||||
|
||||
if ( QgsSymbolLegendNode *symbolNode = dynamic_cast< QgsSymbolLegendNode * >( legendNode ) )
|
||||
{
|
||||
const QgsLegendPatchShape shape = QgsMapLayerLegendUtils::legendNodePatchShape( nodeLayer, i );
|
||||
symbolNode->setPatchShape( shape );
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
// handle user order of nodes
|
||||
|
||||
@ -29,6 +29,7 @@ class QgsPluginLayer;
|
||||
class QgsRasterLayer;
|
||||
class QgsReadWriteContext;
|
||||
class QgsVectorLayer;
|
||||
class QgsLegendPatchShape;
|
||||
|
||||
#include "qgis_core.h"
|
||||
|
||||
@ -102,6 +103,22 @@ class CORE_EXPORT QgsMapLayerLegendUtils
|
||||
static QString legendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
|
||||
static bool hasLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
|
||||
|
||||
/**
|
||||
* Sets the legend patch \a shape for the legend node belonging to \a nodeLayer at the specified \a originalIndex.
|
||||
*
|
||||
* \see legendNodePatchShape()
|
||||
* \since QGIS 3.14
|
||||
*/
|
||||
static void setLegendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsLegendPatchShape &shape );
|
||||
|
||||
/**
|
||||
* Returns the legend patch shape for the legend node belonging to \a nodeLayer at the specified \a originalIndex.
|
||||
*
|
||||
* \see setLegendNodePatchShape()
|
||||
* \since QGIS 3.14
|
||||
*/
|
||||
static QgsLegendPatchShape legendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex );
|
||||
|
||||
//! update according to layer node's custom properties (order of items, user labels for items)
|
||||
static void applyLayerNodeProperties( QgsLayerTreeLayer *nodeLayer, QList<QgsLayerTreeModelLegendNode *> &nodes );
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user