68 Q_FOREACH (
int id, order )
69 orderStr << QString::number(
id );
70 QString str = orderStr.isEmpty() ? QStringLiteral(
"empty" ) : orderStr.join( QStringLiteral(
"," ) );
79 int numNodes = lst.count();
88 QgsDebugMsg( QStringLiteral(
"Legend node order manipulation is invalid without existing legend" ) );
92 int numNodes = _originalLegendNodeCount( nodeLayer );
95 order.reserve( numNodes );
96 for (
int i = 0; i < numNodes; ++i )
103 QString orderStr = nodeLayer->
customProperty( QStringLiteral(
"legend/node-order" ) ).toString();
105 if ( orderStr.isEmpty() )
106 return _makeNodeOrder( nodeLayer );
108 if ( orderStr == QLatin1String(
"empty" ) )
111 int numNodes = _originalLegendNodeCount( nodeLayer );
114 Q_FOREACH (
const QString &item, orderStr.split(
',' ) )
117 int id = item.toInt( &ok );
118 if ( !ok || id < 0 || id >= numNodes )
119 return _makeNodeOrder( nodeLayer );
129 return nodeLayer->
customProperties().contains( QStringLiteral(
"legend/node-order" ) );
134 nodeLayer->
setCustomProperty(
"legend/label-" + QString::number( originalIndex ), newLabel );
139 return nodeLayer->
customProperty(
"legend/label-" + QString::number( originalIndex ) ).toString();
144 return nodeLayer->
customProperties().contains(
"legend/label-" + QString::number( originalIndex ) );
155 if ( !userLabel.isNull() )
164 QList<QgsLayerTreeModelLegendNode *> newOrder;
165 QSet<int> usedIndices;
166 Q_FOREACH (
int idx, order )
168 if ( usedIndices.contains( idx ) )
170 QgsDebugMsg( QStringLiteral(
"invalid node order. ignoring." ) );
174 newOrder << nodes[idx];
179 for (
int i = 0; i < nodes.count(); ++i )
181 if ( !usedIndices.contains( i ) )
201 QList<QgsLayerTreeModelLegendNode *> nodes;
207 if ( nodeLayer->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toBool() )
223 if ( mTextOnSymbolEnabled && mTextOnSymbolContent.contains( i.
ruleKey() ) )
232 if ( nodes.count() == 1 && nodes[0]->data( Qt::EditRole ).toString().isEmpty() )
233 nodes[0]->setEmbeddedInParent(
true );
250 mTextOnSymbolEnabled =
false;
252 mTextOnSymbolContent.clear();
254 QDomElement tosElem = elem.firstChildElement( QStringLiteral(
"text-on-symbol" ) );
255 if ( !tosElem.isNull() )
257 mTextOnSymbolEnabled =
true;
258 QDomElement tosFormatElem = tosElem.firstChildElement( QStringLiteral(
"text-style" ) );
259 mTextOnSymbolTextFormat.
readXml( tosFormatElem, context );
260 QDomElement tosContentElem = tosElem.firstChildElement( QStringLiteral(
"content" ) );
261 QDomElement tosContentItemElem = tosContentElem.firstChildElement( QStringLiteral(
"item" ) );
262 while ( !tosContentItemElem.isNull() )
264 mTextOnSymbolContent.insert( tosContentItemElem.attribute( QStringLiteral(
"key" ) ), tosContentItemElem.attribute( QStringLiteral(
"value" ) ) );
265 tosContentItemElem = tosContentItemElem.nextSiblingElement( QStringLiteral(
"item" ) );
272 QDomElement elem = doc.createElement( QStringLiteral(
"legend" ) );
273 elem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"default-vector" ) );
275 if ( mTextOnSymbolEnabled )
277 QDomElement tosElem = doc.createElement( QStringLiteral(
"text-on-symbol" ) );
278 QDomElement tosFormatElem = mTextOnSymbolTextFormat.
writeXml( doc, context );
279 tosElem.appendChild( tosFormatElem );
280 QDomElement tosContentElem = doc.createElement( QStringLiteral(
"content" ) );
281 for (
auto it = mTextOnSymbolContent.constBegin(); it != mTextOnSymbolContent.constEnd(); ++it )
283 QDomElement tosContentItemElem = doc.createElement( QStringLiteral(
"item" ) );
284 tosContentItemElem.setAttribute( QStringLiteral(
"key" ), it.key() );
285 tosContentItemElem.setAttribute( QStringLiteral(
"value" ), it.value() );
286 tosContentElem.appendChild( tosContentItemElem );
288 tosElem.appendChild( tosContentElem );
289 elem.appendChild( tosElem );
307 QList<QgsLayerTreeModelLegendNode *> nodes;
316 if ( rasterItemList.isEmpty() )
322 int max_count = 1000;
324 for ( QgsLegendColorList::const_iterator itemIt = rasterItemList.constBegin();
325 itemIt != rasterItemList.constEnd(); ++itemIt, ++count )
329 if ( count == max_count )
331 QString label = tr(
"following %1 items\nnot displayed" ).arg( rasterItemList.size() - max_count );
350 QList<QgsLayerTreeModelLegendNode *> nodes;
364 else if ( indexScalar.
isValid() )
366 else if ( indexVector.
isValid() )
381 for (
const QPair< QString, QColor > &item : qgis::as_const( items ) )
virtual bool supportsLegendGraphic() const
Returns whether the provider supplies a legend graphic.
The class is used as a container of context for various read/write operations on other objects...
QgsMeshRendererScalarSettings scalarSettings(int groupIndex) const
Returns renderer settings.
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
static void setLegendNodeOrder(QgsLayerTreeLayer *nodeLayer, const QList< int > &order)
QgsVectorLayerFeatureCounter * countSymbolFeatures()
Count features for symbols.
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
This class is a composition of two QSettings instances:
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...
static void setLegendNodeUserLabel(QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel)
QgsMapLayer * layer() const
Returns the map layer associated with this node.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
Default legend implementation for mesh layers.
QStringList customProperties() const
Returns list of keys stored in custom properties.
Represents a mesh renderer settings for scalar datasets.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
Implementation of legend node interface for displaying raster legend entries.
Produces legend node with a marker symbol.
static QList< int > legendNodeOrder(QgsLayerTreeLayer *nodeLayer)
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
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...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static bool hasLegendNodeOrder(QgsLayerTreeLayer *nodeLayer)
QgsDefaultVectorLayerLegend(QgsVectorLayer *vl)
Implementation of legend node interface for displaying WMS legend entries.
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 layer's data provider.
virtual QList< QgsLayerTreeModelLegendNode * > legendItems(QgsLayerTreeLayer *nodeLayer) const
Returns list of legend nodes for the diagram.
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.
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
QgsColorRampShader colorRampShader() const
Returns color ramp shader function.
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.
void rendererChanged()
Signal emitted when renderer is changed.
static void applyLayerNodeProperties(QgsLayerTreeLayer *nodeLayer, QList< QgsLayerTreeModelLegendNode * > &nodes)
update according to layer node's custom properties (order of items, user labels for items) ...
QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Returns list of legend nodes to be used for a particular layer tree layer node.
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.
QgsMapLayerLegend * legend() const
Can be null.
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. ...
const QgsDiagramRenderer * diagramRenderer() const
static QgsMapLayerLegend * defaultRasterLegend(QgsRasterLayer *rl)
Create new legend implementation for raster layer.
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
QgsDefaultRasterLayerLegend(QgsRasterLayer *rl)
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
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...
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads configuration from a DOM element previously written by writeXml()
QgsMeshDatasetIndex activeVectorDataset() const
Returns active vector dataset.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
int group() const
Returns a group index.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes configuration to a DOM element, to be used later with readXml()
QString ruleKey() const
Returns unique identifier of the rule for identification of the item within renderer.
Container for all settings relating to text rendering.
Default legend implementation for vector layers.
QgsMeshDatasetIndex activeScalarDataset() const
Returns active scalar dataset.
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()
QgsDataDefinedSizeLegend * dataDefinedSizeLegendSettings() const
Returns extra information for data-defined size legend rendering.
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.