QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsmaplayerlegend.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaplayerlegend.cpp
3  --------------------------------------
4  Date : July 2014
5  Copyright : (C) 2014 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsmaplayerlegend.h"
17 
18 #include "qgssettings.h"
19 #include "qgslayertree.h"
21 #include "qgsmeshlayer.h"
22 #include "qgspluginlayer.h"
23 #include "qgsrasterlayer.h"
24 #include "qgsrenderer.h"
25 #include "qgsvectorlayer.h"
26 #include "qgsdiagramrenderer.h"
27 #include "qgssymbollayerutils.h"
28 
30  : QObject( parent )
31 {
32 }
33 
34 void QgsMapLayerLegend::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
35 {
36  Q_UNUSED( elem )
37  Q_UNUSED( context )
38 }
39 
40 QDomElement QgsMapLayerLegend::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
41 {
42  Q_UNUSED( doc )
43  Q_UNUSED( context )
44  return QDomElement();
45 }
46 
48 {
49  return new QgsDefaultVectorLayerLegend( vl );
50 }
51 
53 {
54  return new QgsDefaultRasterLayerLegend( rl );
55 }
56 
58 {
59  return new QgsDefaultMeshLayerLegend( ml );
60 }
61 
62 // -------------------------------------------------------------------------
63 
64 
65 void QgsMapLayerLegendUtils::setLegendNodeOrder( QgsLayerTreeLayer *nodeLayer, const QList<int> &order )
66 {
67  QStringList orderStr;
68  const auto constOrder = order;
69  for ( int id : constOrder )
70  orderStr << QString::number( id );
71  QString str = orderStr.isEmpty() ? QStringLiteral( "empty" ) : orderStr.join( QStringLiteral( "," ) );
72 
73  nodeLayer->setCustomProperty( QStringLiteral( "legend/node-order" ), str );
74 }
75 
76 static int _originalLegendNodeCount( QgsLayerTreeLayer *nodeLayer )
77 {
78  // this is not particularly efficient way of finding out number of legend nodes
79  QList<QgsLayerTreeModelLegendNode *> lst = nodeLayer->layer()->legend()->createLayerTreeModelLegendNodes( nodeLayer );
80  int numNodes = lst.count();
81  qDeleteAll( lst );
82  return numNodes;
83 }
84 
85 static QList<int> _makeNodeOrder( QgsLayerTreeLayer *nodeLayer )
86 {
87  if ( !nodeLayer->layer() || !nodeLayer->layer()->legend() )
88  {
89  QgsDebugMsg( QStringLiteral( "Legend node order manipulation is invalid without existing legend" ) );
90  return QList<int>();
91  }
92 
93  int numNodes = _originalLegendNodeCount( nodeLayer );
94 
95  QList<int> order;
96  order.reserve( numNodes );
97  for ( int i = 0; i < numNodes; ++i )
98  order << i;
99  return order;
100 }
101 
103 {
104  QString orderStr = nodeLayer->customProperty( QStringLiteral( "legend/node-order" ) ).toString();
105 
106  if ( orderStr.isEmpty() )
107  return _makeNodeOrder( nodeLayer );
108 
109  if ( orderStr == QLatin1String( "empty" ) )
110  return QList<int>();
111 
112  int numNodes = _originalLegendNodeCount( nodeLayer );
113 
114  QList<int> lst;
115  const auto constSplit = orderStr.split( ',' );
116  for ( const QString &item : constSplit )
117  {
118  bool ok;
119  int id = item.toInt( &ok );
120  if ( !ok || id < 0 || id >= numNodes )
121  return _makeNodeOrder( nodeLayer );
122 
123  lst << id;
124  }
125 
126  return lst;
127 }
128 
130 {
131  return nodeLayer->customProperties().contains( QStringLiteral( "legend/node-order" ) );
132 }
133 
134 void QgsMapLayerLegendUtils::setLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel )
135 {
136  nodeLayer->setCustomProperty( "legend/label-" + QString::number( originalIndex ), newLabel );
137 }
138 
139 QString QgsMapLayerLegendUtils::legendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex )
140 {
141  return nodeLayer->customProperty( "legend/label-" + QString::number( originalIndex ) ).toString();
142 }
143 
145 {
146  return nodeLayer->customProperties().contains( "legend/label-" + QString::number( originalIndex ) );
147 }
148 
150 {
151  QDomDocument patchDoc;
152  QDomElement patchElem = patchDoc.createElement( QStringLiteral( "patch" ) );
153  shape.writeXml( patchElem, patchDoc, QgsReadWriteContext() );
154  patchDoc.appendChild( patchElem );
155  nodeLayer->setCustomProperty( "legend/patch-shape-" + QString::number( originalIndex ), patchDoc.toString() );
156 }
157 
159 {
160  QString patchDef = nodeLayer->customProperty( "legend/patch-shape-" + QString::number( originalIndex ) ).toString();
161  if ( patchDef.isEmpty() )
162  return QgsLegendPatchShape();
163 
164  QDomDocument doc( QStringLiteral( "patch" ) );
165  doc.setContent( patchDef );
166  QgsLegendPatchShape shape;
167  shape.readXml( doc.documentElement(), QgsReadWriteContext() );
168  return shape;
169 }
170 
171 void QgsMapLayerLegendUtils::setLegendNodeSymbolSize( QgsLayerTreeLayer *nodeLayer, int originalIndex, QSizeF size )
172 {
173  if ( size.isValid() )
174  nodeLayer->setCustomProperty( "legend/symbol-size-" + QString::number( originalIndex ), QgsSymbolLayerUtils::encodeSize( size ) );
175  else
176  nodeLayer->removeCustomProperty( "legend/symbol-size-" + QString::number( originalIndex ) );
177 }
178 
180 {
181  const QString size = nodeLayer->customProperty( "legend/symbol-size-" + QString::number( originalIndex ) ).toString();
182  if ( size.isEmpty() )
183  return QSizeF();
184  else
185  return QgsSymbolLayerUtils::decodeSize( size );
186 }
187 
188 void QgsMapLayerLegendUtils::setLegendNodeCustomSymbol( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsSymbol *symbol )
189 {
190  if ( symbol )
191  {
192  QDomDocument doc;
193  QgsReadWriteContext rwContext;
194  rwContext.setPathResolver( QgsProject::instance()->pathResolver() );
195  QDomElement elem = QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "custom symbol" ), symbol, doc, rwContext );
196  doc.appendChild( elem );
197  nodeLayer->setCustomProperty( "legend/custom-symbol-" + QString::number( originalIndex ), doc.toString() );
198  }
199  else
200  nodeLayer->removeCustomProperty( "legend/custom-symbol-" + QString::number( originalIndex ) );
201 }
202 
204 {
205  const QString symbolDef = nodeLayer->customProperty( "legend/custom-symbol-" + QString::number( originalIndex ) ).toString();
206  if ( symbolDef.isEmpty() )
207  return nullptr;
208 
209  QDomDocument doc;
210  doc.setContent( symbolDef );
211  const QDomElement elem = doc.documentElement();
212 
213  QgsReadWriteContext rwContext;
214  rwContext.setPathResolver( QgsProject::instance()->pathResolver() );
215 
216  return QgsSymbolLayerUtils::loadSymbol( elem, rwContext );
217 }
218 
219 void QgsMapLayerLegendUtils::setLegendNodeColumnBreak( QgsLayerTreeLayer *nodeLayer, int originalIndex, bool columnBreakBeforeNode )
220 {
221  if ( columnBreakBeforeNode )
222  nodeLayer->setCustomProperty( "legend/column-break-" + QString::number( originalIndex ), QStringLiteral( "1" ) );
223  else
224  nodeLayer->removeCustomProperty( "legend/column-break-" + QString::number( originalIndex ) );
225 }
226 
228 {
229  return nodeLayer->customProperty( "legend/column-break-" + QString::number( originalIndex ) ).toInt();
230 }
231 
232 void QgsMapLayerLegendUtils::applyLayerNodeProperties( QgsLayerTreeLayer *nodeLayer, QList<QgsLayerTreeModelLegendNode *> &nodes )
233 {
234  // handle user labels
235  int i = 0;
236  const auto constNodes = nodes;
237  for ( QgsLayerTreeModelLegendNode *legendNode : constNodes )
238  {
239  QString userLabel = QgsMapLayerLegendUtils::legendNodeUserLabel( nodeLayer, i );
240  if ( !userLabel.isNull() )
241  legendNode->setUserLabel( userLabel );
242 
243  if ( QgsSymbolLegendNode *symbolNode = dynamic_cast< QgsSymbolLegendNode * >( legendNode ) )
244  {
246  symbolNode->setPatchShape( shape );
247 
248  symbolNode->setCustomSymbol( QgsMapLayerLegendUtils::legendNodeCustomSymbol( nodeLayer, i ) );
249  }
250 
251  const QSizeF userSize = QgsMapLayerLegendUtils::legendNodeSymbolSize( nodeLayer, i );
252  if ( userSize.isValid() )
253  {
254  legendNode->setUserPatchSize( userSize );
255  }
256 
257  if ( legendNodeColumnBreak( nodeLayer, i ) )
258  legendNode->setColumnBreak( true );
259 
260  i++;
261  }
262 
263  // handle user order of nodes
265  {
266  QList<int> order = QgsMapLayerLegendUtils::legendNodeOrder( nodeLayer );
267 
268  QList<QgsLayerTreeModelLegendNode *> newOrder;
269  QSet<int> usedIndices;
270  const auto constOrder = order;
271  for ( int idx : constOrder )
272  {
273  if ( usedIndices.contains( idx ) )
274  {
275  QgsDebugMsg( QStringLiteral( "invalid node order. ignoring." ) );
276  return;
277  }
278 
279  newOrder << nodes[idx];
280  usedIndices << idx;
281  }
282 
283  // delete unused nodes
284  for ( int i = 0; i < nodes.count(); ++i )
285  {
286  if ( !usedIndices.contains( i ) )
287  delete nodes[i];
288  }
289 
290  nodes = newOrder;
291  }
292 
293 }
294 
295 // -------------------------------------------------------------------------
296 
297 
299  : mLayer( vl )
300 {
302 }
303 
304 QList<QgsLayerTreeModelLegendNode *> QgsDefaultVectorLayerLegend::createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer )
305 {
306  QList<QgsLayerTreeModelLegendNode *> nodes;
307 
308  QgsFeatureRenderer *r = mLayer->renderer();
309  if ( !r )
310  return nodes;
311 
312  if ( nodeLayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toBool() )
313  mLayer->countSymbolFeatures();
314 
315  QgsSettings settings;
316  if ( settings.value( QStringLiteral( "qgis/showLegendClassifiers" ), false ).toBool() && !r->legendClassificationAttribute().isEmpty() )
317  {
318  nodes.append( new QgsSimpleLegendNode( nodeLayer, r->legendClassificationAttribute() ) );
319  }
320 
321  const auto constLegendSymbolItems = r->legendSymbolItems();
322  for ( const QgsLegendSymbolItem &i : constLegendSymbolItems )
323  {
324  if ( i.dataDefinedSizeLegendSettings() )
325  nodes << new QgsDataDefinedSizeLegendNode( nodeLayer, *i.dataDefinedSizeLegendSettings() );
326  else
327  {
328  QgsSymbolLegendNode *legendNode = new QgsSymbolLegendNode( nodeLayer, i );
329  if ( mTextOnSymbolEnabled && mTextOnSymbolContent.contains( i.ruleKey() ) )
330  {
331  legendNode->setTextOnSymbolLabel( mTextOnSymbolContent.value( i.ruleKey() ) );
332  legendNode->setTextOnSymbolTextFormat( mTextOnSymbolTextFormat );
333  }
334  nodes << legendNode;
335  }
336  }
337 
338  if ( nodes.count() == 1 && nodes[0]->data( Qt::EditRole ).toString().isEmpty() )
339  nodes[0]->setEmbeddedInParent( true );
340 
341 
342  if ( mLayer->diagramsEnabled() )
343  {
344  const auto constLegendItems = mLayer->diagramRenderer()->legendItems( nodeLayer );
345  for ( QgsLayerTreeModelLegendNode *i : constLegendItems )
346  {
347  nodes.append( i );
348  }
349  }
350 
351 
352  return nodes;
353 }
354 
355 void QgsDefaultVectorLayerLegend::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
356 {
357  mTextOnSymbolEnabled = false;
358  mTextOnSymbolTextFormat = QgsTextFormat();
359  mTextOnSymbolContent.clear();
360 
361  QDomElement tosElem = elem.firstChildElement( QStringLiteral( "text-on-symbol" ) );
362  if ( !tosElem.isNull() )
363  {
364  mTextOnSymbolEnabled = true;
365  QDomElement tosFormatElem = tosElem.firstChildElement( QStringLiteral( "text-style" ) );
366  mTextOnSymbolTextFormat.readXml( tosFormatElem, context );
367  QDomElement tosContentElem = tosElem.firstChildElement( QStringLiteral( "content" ) );
368  QDomElement tosContentItemElem = tosContentElem.firstChildElement( QStringLiteral( "item" ) );
369  while ( !tosContentItemElem.isNull() )
370  {
371  mTextOnSymbolContent.insert( tosContentItemElem.attribute( QStringLiteral( "key" ) ), tosContentItemElem.attribute( QStringLiteral( "value" ) ) );
372  tosContentItemElem = tosContentItemElem.nextSiblingElement( QStringLiteral( "item" ) );
373  }
374  }
375 }
376 
377 QDomElement QgsDefaultVectorLayerLegend::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
378 {
379  QDomElement elem = doc.createElement( QStringLiteral( "legend" ) );
380  elem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "default-vector" ) );
381 
382  if ( mTextOnSymbolEnabled )
383  {
384  QDomElement tosElem = doc.createElement( QStringLiteral( "text-on-symbol" ) );
385  QDomElement tosFormatElem = mTextOnSymbolTextFormat.writeXml( doc, context );
386  tosElem.appendChild( tosFormatElem );
387  QDomElement tosContentElem = doc.createElement( QStringLiteral( "content" ) );
388  for ( auto it = mTextOnSymbolContent.constBegin(); it != mTextOnSymbolContent.constEnd(); ++it )
389  {
390  QDomElement tosContentItemElem = doc.createElement( QStringLiteral( "item" ) );
391  tosContentItemElem.setAttribute( QStringLiteral( "key" ), it.key() );
392  tosContentItemElem.setAttribute( QStringLiteral( "value" ), it.value() );
393  tosContentElem.appendChild( tosContentItemElem );
394  }
395  tosElem.appendChild( tosContentElem );
396  elem.appendChild( tosElem );
397  }
398 
399  return elem;
400 }
401 
402 
403 // -------------------------------------------------------------------------
404 
405 
407  : mLayer( rl )
408 {
410 }
411 
412 QList<QgsLayerTreeModelLegendNode *> QgsDefaultRasterLayerLegend::createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer )
413 {
414  QList<QgsLayerTreeModelLegendNode *> nodes;
415 
416  // temporary solution for WMS. Ideally should be done with a delegate.
417  if ( mLayer->dataProvider() && mLayer->dataProvider()->supportsLegendGraphic() )
418  {
419  nodes << new QgsWmsLegendNode( nodeLayer );
420  }
421 
422  QgsLegendColorList rasterItemList = mLayer->legendSymbologyItems();
423  if ( rasterItemList.isEmpty() )
424  return nodes;
425 
426  // Paletted raster may have many colors, for example UInt16 may have 65536 colors
427  // and it is very slow, so we limit max count
428  int count = 0;
429  int max_count = 1000;
430 
431  for ( QgsLegendColorList::const_iterator itemIt = rasterItemList.constBegin();
432  itemIt != rasterItemList.constEnd(); ++itemIt, ++count )
433  {
434  nodes << new QgsRasterSymbolLegendNode( nodeLayer, itemIt->second, itemIt->first );
435 
436  if ( count == max_count )
437  {
438  QString label = tr( "following %1 items\nnot displayed" ).arg( rasterItemList.size() - max_count );
439  nodes << new QgsSimpleLegendNode( nodeLayer, label );
440  break;
441  }
442  }
443 
444  return nodes;
445 }
446 
447 // -------------------------------------------------------------------------
448 
450  : mLayer( ml )
451 {
453 }
454 
455 QList<QgsLayerTreeModelLegendNode *> QgsDefaultMeshLayerLegend::createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer )
456 {
457  QList<QgsLayerTreeModelLegendNode *> nodes;
458 
459  QgsMeshDataProvider *provider = mLayer->dataProvider();
460  if ( !provider )
461  return nodes;
462 
463  QgsMeshRendererSettings rendererSettings = mLayer->rendererSettings();
464 
465  int indexScalar = rendererSettings.activeScalarDatasetGroup();
466  int indexVector = rendererSettings.activeVectorDatasetGroup();
467 
468  QString name;
469  if ( indexScalar > -1 && indexVector > -1 && indexScalar != indexVector )
470  name = QString( "%1 / %2" ).arg( provider->datasetGroupMetadata( indexScalar ).name(), provider->datasetGroupMetadata( indexVector ).name() );
471  else if ( indexScalar > -1 )
472  name = provider->datasetGroupMetadata( indexScalar ).name();
473  else if ( indexVector > -1 )
474  name = provider->datasetGroupMetadata( indexVector ).name();
475  else
476  {
477  // neither contours nor vectors get rendered - no legend needed
478  return nodes;
479  }
480 
481  nodes << new QgsSimpleLegendNode( nodeLayer, name );
482 
483  if ( indexScalar > -1 )
484  {
485  QgsMeshRendererScalarSettings settings = rendererSettings.scalarSettings( indexScalar );
486  QgsLegendColorList items;
487  settings.colorRampShader().legendSymbologyItems( items );
488  for ( const QPair< QString, QColor > &item : qgis::as_const( items ) )
489  {
490  nodes << new QgsRasterSymbolLegendNode( nodeLayer, item.second, item.first );
491  }
492  }
493 
494  return nodes;
495 }
QgsMapLayerLegendUtils::setLegendNodePatchShape
static void setLegendNodePatchShape(QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsLegendPatchShape &shape)
Sets the legend patch shape for the legend node belonging to nodeLayer at the specified originalIndex...
Definition: qgsmaplayerlegend.cpp:149
QgsDefaultVectorLayerLegend::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads configuration from a DOM element previously written by writeXml()
Definition: qgsmaplayerlegend.cpp:355
QgsReadWriteContext::setPathResolver
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
Definition: qgsreadwritecontext.cpp:52
QgsVectorLayer::diagramsEnabled
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
Definition: qgsvectorlayer.cpp:738
QgsMapLayerLegendUtils::applyLayerNodeProperties
static void applyLayerNodeProperties(QgsLayerTreeLayer *nodeLayer, QList< QgsLayerTreeModelLegendNode * > &nodes)
update according to layer node's custom properties (order of items, user labels for items)
Definition: qgsmaplayerlegend.cpp:232
QgsDefaultVectorLayerLegend
Definition: qgsmaplayerlegend.h:199
qgsrasterlayer.h
qgslayertreemodellegendnode.h
QgsMeshRendererSettings
Definition: qgsmeshrenderersettings.h:590
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:174
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsMapLayerLegendUtils::legendNodeColumnBreak
static bool legendNodeColumnBreak(QgsLayerTreeLayer *nodeLayer, int originalIndex)
Returns whether a forced column break should occur before the node.
Definition: qgsmaplayerlegend.cpp:227
QgsMapLayerLegend::defaultMeshLegend
static QgsMapLayerLegend * defaultMeshLegend(QgsMeshLayer *ml)
Create new legend implementation for mesh layer.
Definition: qgsmaplayerlegend.cpp:57
QgsSimpleLegendNode
Definition: qgslayertreemodellegendnode.h:497
qgssymbollayerutils.h
QgsMapLayerLegend
Definition: qgsmaplayerlegend.h:45
QgsMapLayerLegend::writeXml
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
Definition: qgsmaplayerlegend.cpp:40
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:458
QgsLayerTreeModelLegendNode::setUserPatchSize
virtual void setUserPatchSize(QSizeF size)
Sets the user (overridden) size for the legend node.
Definition: qgslayertreemodellegendnode.h:110
QgsMapLayerLegendUtils::setLegendNodeColumnBreak
static void setLegendNodeColumnBreak(QgsLayerTreeLayer *nodeLayer, int originalIndex, bool columnBreakBeforeNode)
Sets whether a forced column break should occur before the node.
Definition: qgsmaplayerlegend.cpp:219
QgsDefaultMeshLayerLegend::createLayerTreeModelLegendNodes
QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Returns list of legend nodes to be used for a particular layer tree layer node.
Definition: qgsmaplayerlegend.cpp:455
QgsFeatureRenderer::legendSymbolItems
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
Definition: qgsrenderer.cpp:353
QgsSettings
Definition: qgssettings.h:61
QgsMapLayerLegend::createLayerTreeModelLegendNodes
virtual QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer)=0
Returns list of legend nodes to be used for a particular layer tree layer node.
QgsSymbol
Definition: qgssymbol.h:63
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsVectorLayer::diagramRenderer
const QgsDiagramRenderer * diagramRenderer() const
Definition: qgsvectorlayer.h:875
QgsDataDefinedSizeLegendNode
Definition: qgslayertreemodellegendnode.h:640
QgsDefaultRasterLayerLegend
Definition: qgsmaplayerlegend.h:267
QgsMapLayer::legend
QgsMapLayerLegend * legend() const
Can be nullptr.
Definition: qgsmaplayer.cpp:1792
QgsRasterLayer::legendSymbologyItems
QgsLegendColorList legendSymbologyItems() const
Returns a list with classification items (Text and color)
Definition: qgsrasterlayer.cpp:288
QgsFeatureRenderer::legendClassificationAttribute
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
Definition: qgsrenderer.h:354
QgsLegendPatchShape
Definition: qgslegendpatchshape.h:30
QgsRasterDataProvider::supportsLegendGraphic
virtual bool supportsLegendGraphic() const
Returns whether the provider supplies a legend graphic.
Definition: qgsrasterdataprovider.h:275
QgsMeshLayer::rendererSettings
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
Definition: qgsmeshlayer.cpp:263
QgsTextFormat
Definition: qgstextformat.h:38
QgsLegendSymbolItem
Definition: qgslegendsymbolitem.h:36
QgsMapLayerLegendUtils::setLegendNodeOrder
static void setLegendNodeOrder(QgsLayerTreeLayer *nodeLayer, const QList< int > &order)
Definition: qgsmaplayerlegend.cpp:65
QgsMeshRendererSettings::activeScalarDatasetGroup
int activeScalarDatasetGroup() const
Returns the active scalar dataset group.
Definition: qgsmeshrenderersettings.cpp:509
QgsColorRampShader::legendSymbologyItems
void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const override
Returns legend symbology items if provided by renderer.
Definition: qgscolorrampshader.cpp:489
QgsMeshRendererSettings::scalarSettings
QgsMeshRendererScalarSettings scalarSettings(int groupIndex) const
Returns renderer settings.
Definition: qgsmeshrenderersettings.h:624
QgsDefaultMeshLayerLegend::QgsDefaultMeshLayerLegend
QgsDefaultMeshLayerLegend(QgsMeshLayer *ml)
Creates an instance for the given mesh layer.
Definition: qgsmaplayerlegend.cpp:449
QgsDiagramRenderer::legendItems
virtual QList< QgsLayerTreeModelLegendNode * > legendItems(QgsLayerTreeLayer *nodeLayer) const
Returns list of legend nodes for the diagram.
Definition: qgsdiagramrenderer.cpp:923
QgsMeshRendererScalarSettings::colorRampShader
QgsColorRampShader colorRampShader() const
Returns color ramp shader function.
Definition: qgsmeshrenderersettings.cpp:81
QgsDefaultVectorLayerLegend::writeXml
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes configuration to a DOM element, to be used later with readXml()
Definition: qgsmaplayerlegend.cpp:377
QgsMeshRendererSettings::activeVectorDatasetGroup
int activeVectorDatasetGroup() const
Returns the active vector dataset group.
Definition: qgsmeshrenderersettings.cpp:519
QgsMeshLayer
Definition: qgsmeshlayer.h:94
QgsMapLayerLegend::defaultVectorLegend
static QgsMapLayerLegend * defaultVectorLegend(QgsVectorLayer *vl)
Create new legend implementation for vector layer.
Definition: qgsmaplayerlegend.cpp:47
QgsLayerTreeLayer
Definition: qgslayertreelayer.h:43
QgsMeshDataProvider
Definition: qgsmeshdataprovider.h:351
QgsMapLayerLegendUtils::setLegendNodeCustomSymbol
static void setLegendNodeCustomSymbol(QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsSymbol *symbol)
Sets a custom legend symbol size for the legend node belonging to nodeLayer at the specified original...
Definition: qgsmaplayerlegend.cpp:188
QgsWmsLegendNode
Definition: qgslayertreemodellegendnode.h:593
QgsSymbolLayerUtils::loadSymbol
static QgsSymbol * loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
Definition: qgssymbollayerutils.cpp:1041
QgsDefaultRasterLayerLegend::QgsDefaultRasterLayerLegend
QgsDefaultRasterLayerLegend(QgsRasterLayer *rl)
Definition: qgsmaplayerlegend.cpp:406
QgsTextFormat::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
Definition: qgstextformat.cpp:279
qgsrenderer.h
QgsRasterLayer
Definition: qgsrasterlayer.h:72
QgsMapLayerLegendUtils::hasLegendNodeOrder
static bool hasLegendNodeOrder(QgsLayerTreeLayer *nodeLayer)
Definition: qgsmaplayerlegend.cpp:129
QgsMapLayerLegend::QgsMapLayerLegend
QgsMapLayerLegend(QObject *parent=nullptr)
Constructor for QgsMapLayerLegend.
Definition: qgsmaplayerlegend.cpp:29
QgsLayerTreeLayer::layer
QgsMapLayer * layer() const
Returns the map layer associated with this node.
Definition: qgslayertreelayer.h:74
qgslayertree.h
qgsdiagramrenderer.h
QgsLayerTreeModelLegendNode::setEmbeddedInParent
virtual void setEmbeddedInParent(bool embedded)
Definition: qgslayertreemodellegendnode.h:85
QgsMapLayer::rendererChanged
void rendererChanged()
Signal emitted when renderer is changed.
QgsMeshDatasetGroupMetadata::name
QString name() const
Returns name of the dataset group.
Definition: qgsmeshdataset.cpp:164
QgsSymbolLayerUtils::encodeSize
static QString encodeSize(QSizeF size)
Encodes a QSizeF to a string.
Definition: qgssymbollayerutils.cpp:494
QgsWms::legendNode
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
Definition: qgswmsgetlegendgraphics.cpp:358
QgsMapLayerLegendUtils::legendNodeOrder
static QList< int > legendNodeOrder(QgsLayerTreeLayer *nodeLayer)
Definition: qgsmaplayerlegend.cpp:102
QgsLayerTreeNode::customProperties
QStringList customProperties() const
Returns list of keys stored in custom properties.
Definition: qgslayertreenode.cpp:203
qgsmeshlayer.h
qgsvectorlayer.h
QgsMapLayerLegend::defaultRasterLegend
static QgsMapLayerLegend * defaultRasterLegend(QgsRasterLayer *rl)
Create new legend implementation for raster layer.
Definition: qgsmaplayerlegend.cpp:52
QgsMapLayerLegendUtils::setLegendNodeUserLabel
static void setLegendNodeUserLabel(QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel)
Definition: qgsmaplayerlegend.cpp:134
QgsMeshRendererScalarSettings
Definition: qgsmeshrenderersettings.h:94
QgsDefaultMeshLayerLegend
Definition: qgsmaplayerlegend.h:286
QgsLayerTreeModelLegendNode::setUserLabel
virtual void setUserLabel(const QString &userLabel)
Definition: qgslayertreemodellegendnode.h:88
QgsMapLayerLegendUtils::legendNodePatchShape
static QgsLegendPatchShape legendNodePatchShape(QgsLayerTreeLayer *nodeLayer, int originalIndex)
Returns the legend patch shape for the legend node belonging to nodeLayer at the specified originalIn...
Definition: qgsmaplayerlegend.cpp:158
QgsFeatureRenderer
Definition: qgsrenderer.h:102
QgsLayerTreeNode::setCustomProperty
void setCustomProperty(const QString &key, const QVariant &value)
Sets a custom property for the node. Properties are stored in a map and saved in project file.
Definition: qgslayertreenode.cpp:180
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsLayerTreeNode::customProperty
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer. Properties are stored in a map and saved in project file.
Definition: qgslayertreenode.cpp:189
QgsMapLayerLegend::itemsChanged
void itemsChanged()
Emitted when existing items/nodes got invalid and should be replaced by new ones.
QgsDefaultVectorLayerLegend::createLayerTreeModelLegendNodes
QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Returns list of legend nodes to be used for a particular layer tree layer node.
Definition: qgsmaplayerlegend.cpp:304
qgssettings.h
QgsMapLayerLegendUtils::setLegendNodeSymbolSize
static void setLegendNodeSymbolSize(QgsLayerTreeLayer *nodeLayer, int originalIndex, QSizeF size)
Sets the legend symbol size for the legend node belonging to nodeLayer at the specified originalIndex...
Definition: qgsmaplayerlegend.cpp:171
QgsLegendColorList
QList< QPair< QString, QColor > > QgsLegendColorList
Definition: qgsrasterlayer.h:49
QgsMapLayerLegendUtils::legendNodeUserLabel
static QString legendNodeUserLabel(QgsLayerTreeLayer *nodeLayer, int originalIndex)
Definition: qgsmaplayerlegend.cpp:139
qgsmaplayerlegend.h
qgspluginlayer.h
QgsVectorLayer::countSymbolFeatures
QgsVectorLayerFeatureCounter * countSymbolFeatures(bool storeSymbolFids=false)
Count features for symbols.
Definition: qgsvectorlayer.cpp:766
QgsDefaultRasterLayerLegend::createLayerTreeModelLegendNodes
QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Returns list of legend nodes to be used for a particular layer tree layer node.
Definition: qgsmaplayerlegend.cpp:412
QgsRasterSymbolLegendNode
Definition: qgslayertreemodellegendnode.h:559
QgsMapLayerLegendUtils::legendNodeCustomSymbol
static QgsSymbol * legendNodeCustomSymbol(QgsLayerTreeLayer *nodeLayer, int originalIndex)
Returns the custom legend symbol for the legend node belonging to nodeLayer at the specified original...
Definition: qgsmaplayerlegend.cpp:203
QgsSymbolLegendNode
Definition: qgslayertreemodellegendnode.h:283
QgsMapLayerLegendUtils::hasLegendNodeUserLabel
static bool hasLegendNodeUserLabel(QgsLayerTreeLayer *nodeLayer, int originalIndex)
Definition: qgsmaplayerlegend.cpp:144
QgsLayerTreeNode::removeCustomProperty
void removeCustomProperty(const QString &key)
Remove a custom property from layer. Properties are stored in a map and saved in project file.
Definition: qgslayertreenode.cpp:194
QgsLegendPatchShape::writeXml
void writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
Definition: qgslegendpatchshape.cpp:200
QgsMapLayerLegendUtils::legendNodeSymbolSize
static QSizeF legendNodeSymbolSize(QgsLayerTreeLayer *nodeLayer, int originalIndex)
Returns the legend node symbol size for the legend node belonging to nodeLayer at the specified origi...
Definition: qgsmaplayerlegend.cpp:179
QgsTextFormat::writeXml
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
Definition: qgstextformat.cpp:423
QgsSymbolLayerUtils::saveSymbol
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
Definition: qgssymbollayerutils.cpp:1180
QgsSymbolLayerUtils::decodeSize
static QSizeF decodeSize(const QString &string)
Decodes a QSizeF from a string.
Definition: qgssymbollayerutils.cpp:499
QgsMeshDatasetSourceInterface::datasetGroupMetadata
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.
QgsDefaultVectorLayerLegend::QgsDefaultVectorLayerLegend
QgsDefaultVectorLayerLegend(QgsVectorLayer *vl)
Definition: qgsmaplayerlegend.cpp:298
QgsMeshLayer::dataProvider
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
Definition: qgsmeshlayer.cpp:147
QgsLegendPatchShape::readXml
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Read settings from a DOM element.
Definition: qgslegendpatchshape.cpp:193
QgsRasterLayer::dataProvider
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Definition: qgsrasterlayer.cpp:233
QgsMapLayerLegend::readXml
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from a DOM element previously written by writeXml()
Definition: qgsmaplayerlegend.cpp:34
QgsVectorLayer::renderer
QgsFeatureRenderer * renderer()
Returns renderer.
Definition: qgsvectorlayer.h:881
QgsLayerTreeModelLegendNode::setColumnBreak
virtual void setColumnBreak(bool breakBeforeNode)
Sets whether a forced column break should occur before the node.
Definition: qgslayertreemodellegendnode.h:118
QgsLayerTreeModelLegendNode
Definition: qgslayertreemodellegendnode.h:50