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(
"," ) );
80 int numNodes = lst.count();
89 QgsDebugMsg( QStringLiteral(
"Legend node order manipulation is invalid without existing legend" ) );
93 int numNodes = _originalLegendNodeCount( nodeLayer );
96 order.reserve( numNodes );
97 for (
int i = 0; i < numNodes; ++i )
104 QString orderStr = nodeLayer->
customProperty( QStringLiteral(
"legend/node-order" ) ).toString();
106 if ( orderStr.isEmpty() )
107 return _makeNodeOrder( nodeLayer );
109 if ( orderStr == QLatin1String(
"empty" ) )
112 int numNodes = _originalLegendNodeCount( nodeLayer );
115 const auto constSplit = orderStr.split(
',' );
116 for (
const QString &item : constSplit )
119 int id = item.toInt( &ok );
120 if ( !ok || id < 0 || id >= numNodes )
121 return _makeNodeOrder( nodeLayer );
131 return nodeLayer->
customProperties().contains( QStringLiteral(
"legend/node-order" ) );
136 nodeLayer->
setCustomProperty(
"legend/label-" + QString::number( originalIndex ), newLabel );
141 return nodeLayer->
customProperty(
"legend/label-" + QString::number( originalIndex ) ).toString();
146 return nodeLayer->
customProperties().contains(
"legend/label-" + QString::number( originalIndex ) );
154 const auto constNodes = nodes;
158 if ( !userLabel.isNull() )
167 QList<QgsLayerTreeModelLegendNode *> newOrder;
168 QSet<int> usedIndices;
169 const auto constOrder = order;
170 for (
int idx : constOrder )
172 if ( usedIndices.contains( idx ) )
174 QgsDebugMsg( QStringLiteral(
"invalid node order. ignoring." ) );
178 newOrder << nodes[idx];
183 for (
int i = 0; i < nodes.count(); ++i )
185 if ( !usedIndices.contains( i ) )
205 QList<QgsLayerTreeModelLegendNode *> nodes;
211 if ( nodeLayer->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toBool() )
223 if ( i.dataDefinedSizeLegendSettings() )
228 if ( mTextOnSymbolEnabled && mTextOnSymbolContent.contains( i.ruleKey() ) )
237 if ( nodes.count() == 1 && nodes[0]->data( Qt::EditRole ).toString().isEmpty() )
238 nodes[0]->setEmbeddedInParent(
true );
256 mTextOnSymbolEnabled =
false;
258 mTextOnSymbolContent.clear();
260 QDomElement tosElem = elem.firstChildElement( QStringLiteral(
"text-on-symbol" ) );
261 if ( !tosElem.isNull() )
263 mTextOnSymbolEnabled =
true;
264 QDomElement tosFormatElem = tosElem.firstChildElement( QStringLiteral(
"text-style" ) );
265 mTextOnSymbolTextFormat.
readXml( tosFormatElem, context );
266 QDomElement tosContentElem = tosElem.firstChildElement( QStringLiteral(
"content" ) );
267 QDomElement tosContentItemElem = tosContentElem.firstChildElement( QStringLiteral(
"item" ) );
268 while ( !tosContentItemElem.isNull() )
270 mTextOnSymbolContent.insert( tosContentItemElem.attribute( QStringLiteral(
"key" ) ), tosContentItemElem.attribute( QStringLiteral(
"value" ) ) );
271 tosContentItemElem = tosContentItemElem.nextSiblingElement( QStringLiteral(
"item" ) );
278 QDomElement elem = doc.createElement( QStringLiteral(
"legend" ) );
279 elem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"default-vector" ) );
281 if ( mTextOnSymbolEnabled )
283 QDomElement tosElem = doc.createElement( QStringLiteral(
"text-on-symbol" ) );
284 QDomElement tosFormatElem = mTextOnSymbolTextFormat.
writeXml( doc, context );
285 tosElem.appendChild( tosFormatElem );
286 QDomElement tosContentElem = doc.createElement( QStringLiteral(
"content" ) );
287 for (
auto it = mTextOnSymbolContent.constBegin(); it != mTextOnSymbolContent.constEnd(); ++it )
289 QDomElement tosContentItemElem = doc.createElement( QStringLiteral(
"item" ) );
290 tosContentItemElem.setAttribute( QStringLiteral(
"key" ), it.key() );
291 tosContentItemElem.setAttribute( QStringLiteral(
"value" ), it.value() );
292 tosContentElem.appendChild( tosContentItemElem );
294 tosElem.appendChild( tosContentElem );
295 elem.appendChild( tosElem );
313 QList<QgsLayerTreeModelLegendNode *> nodes;
322 if ( rasterItemList.isEmpty() )
328 int max_count = 1000;
330 for ( QgsLegendColorList::const_iterator itemIt = rasterItemList.constBegin();
331 itemIt != rasterItemList.constEnd(); ++itemIt, ++count )
335 if ( count == max_count )
337 QString label = tr(
"following %1 items\nnot displayed" ).arg( rasterItemList.size() - max_count );
356 QList<QgsLayerTreeModelLegendNode *> nodes;
370 else if ( indexScalar.
isValid() )
372 else if ( indexVector.
isValid() )
387 for (
const QPair< QString, QColor > &item : qgis::as_const( items ) )
The class is used as a container of context for various read/write operations on other objects...
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
static void setLegendNodeOrder(QgsLayerTreeLayer *nodeLayer, const QList< int > &order)
QgsVectorLayerFeatureCounter * countSymbolFeatures()
Count features for symbols.
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
This class is a composition of two QSettings instances:
QgsMapLayerLegend * legend() const
Can be nullptr.
static void setLegendNodeUserLabel(QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
virtual QList< QgsLayerTreeModelLegendNode *> legendItems(QgsLayerTreeLayer *nodeLayer) const
Returns list of legend nodes for the diagram.
Default legend implementation for mesh layers.
Represents a mesh renderer settings for scalar datasets.
Implementation of legend node interface for displaying raster legend entries.
Produces legend node with a marker symbol.
static QList< int > legendNodeOrder(QgsLayerTreeLayer *nodeLayer)
void setTextOnSymbolLabel(const QString &label)
Sets label of text to be shown on top of the symbol.
Default legend implementation for raster layers.
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
virtual bool supportsLegendGraphic() const
Returns whether the provider supplies a legend graphic.
static bool hasLegendNodeOrder(QgsLayerTreeLayer *nodeLayer)
QgsDefaultVectorLayerLegend(QgsVectorLayer *vl)
Implementation of legend node interface for displaying WMS legend entries.
QgsMeshRendererScalarSettings scalarSettings(int groupIndex) const
Returns renderer settings.
int group() const
Returns a group index.
QStringList customProperties() const
Returns list of keys stored in custom properties.
static QgsMapLayerLegend * defaultMeshLegend(QgsMeshLayer *ml)
Create new legend implementation for mesh layer.
QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Returns list of legend nodes to be used for a particular layer tree layer node.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
QgsMeshDatasetIndex activeVectorDataset() const
Returns active vector dataset.
Represents all mesh renderer settings.
virtual QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer)=0
Returns list of legend nodes to be used for a particular layer tree layer node.
static QString legendNodeUserLabel(QgsLayerTreeLayer *nodeLayer, int originalIndex)
QgsMapLayerLegend(QObject *parent=nullptr)
Constructor for QgsMapLayerLegend.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
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...
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const override
Returns legend symbology items if provided by renderer.
QgsFeatureRenderer * renderer()
Returns renderer.
static bool hasLegendNodeUserLabel(QgsLayerTreeLayer *nodeLayer, int originalIndex)
Implementation of legend node interface for displaying arbitrary label with icon. ...
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
void rendererChanged()
Signal emitted when renderer is changed.
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Returns list of legend nodes to be used for a particular layer tree layer node.
const QgsDiagramRenderer * diagramRenderer() const
QgsColorRampShader colorRampShader() const
Returns color ramp shader function.
void setTextOnSymbolTextFormat(const QgsTextFormat &format)
Sets format of text to be shown on top of the symbol.
static QgsMapLayerLegend * defaultVectorLegend(QgsVectorLayer *vl)
Create new legend implementation for vector layer.
Base class for providing data for QgsMeshLayer.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
QList< QPair< QString, QColor > > QgsLegendColorList
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
void itemsChanged()
Emitted when existing items/nodes got invalid and should be replaced by new ones. ...
static QgsMapLayerLegend * defaultRasterLegend(QgsRasterLayer *rl)
Create new legend implementation for raster layer.
static void applyLayerNodeProperties(QgsLayerTreeLayer *nodeLayer, QList< QgsLayerTreeModelLegendNode *> &nodes)
update according to layer node's custom properties (order of items, user labels for items) ...
QgsDefaultRasterLayerLegend(QgsRasterLayer *rl)
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Returns list of legend nodes to be used for a particular layer tree layer node.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
bool isValid() const
Returns whether index is valid, ie at least groups is set.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads configuration from a DOM element previously written by writeXml()
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes configuration to a DOM element, to be used later with readXml()
Container for all settings relating to text rendering.
Default legend implementation for vector layers.
QgsLegendColorList legendSymbologyItems() const
Returns a list with classification items (Text and color)
Represents a vector layer which manages a vector based data sets.
QgsDefaultMeshLayerLegend(QgsMeshLayer *ml)
Creates an instance for the given mesh layer.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from a DOM element previously written by writeXml()
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
virtual void setUserLabel(const QString &userLabel)
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...
Layer tree node points to a map layer.
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.
QgsMeshDatasetIndex activeScalarDataset() const
Returns active scalar dataset.