62 Q_FOREACH (
int id, order )
63 orderStr << QString::number(
id );
64 QString str = orderStr.isEmpty() ? QStringLiteral(
"empty" ) : orderStr.join( QStringLiteral(
"," ) );
73 int numNodes = lst.count();
82 QgsDebugMsg(
"Legend node order manipulation is invalid without existing legend" );
86 int numNodes = _originalLegendNodeCount( nodeLayer );
89 order.reserve( numNodes );
90 for (
int i = 0; i < numNodes; ++i )
97 QString orderStr = nodeLayer->
customProperty( QStringLiteral(
"legend/node-order" ) ).toString();
99 if ( orderStr.isEmpty() )
100 return _makeNodeOrder( nodeLayer );
102 if ( orderStr == QLatin1String(
"empty" ) )
105 int numNodes = _originalLegendNodeCount( nodeLayer );
108 Q_FOREACH (
const QString &item, orderStr.split(
',' ) )
111 int id = item.toInt( &ok );
112 if ( !ok || id < 0 || id >= numNodes )
113 return _makeNodeOrder( nodeLayer );
123 return nodeLayer->
customProperties().contains( QStringLiteral(
"legend/node-order" ) );
128 nodeLayer->
setCustomProperty(
"legend/label-" + QString::number( originalIndex ), newLabel );
133 return nodeLayer->
customProperty(
"legend/label-" + QString::number( originalIndex ) ).toString();
138 return nodeLayer->
customProperties().contains(
"legend/label-" + QString::number( originalIndex ) );
149 if ( !userLabel.isNull() )
158 QList<QgsLayerTreeModelLegendNode *> newOrder;
159 QSet<int> usedIndices;
160 Q_FOREACH (
int idx, order )
162 if ( usedIndices.contains( idx ) )
168 newOrder << nodes[idx];
173 for (
int i = 0; i < nodes.count(); ++i )
175 if ( !usedIndices.contains( i ) )
195 QList<QgsLayerTreeModelLegendNode *> nodes;
201 if ( nodeLayer->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toBool() )
217 if ( mTextOnSymbolEnabled && mTextOnSymbolContent.contains( i.
ruleKey() ) )
226 if ( nodes.count() == 1 && nodes[0]->data( Qt::EditRole ).toString().isEmpty() )
227 nodes[0]->setEmbeddedInParent(
true );
244 mTextOnSymbolEnabled =
false;
246 mTextOnSymbolContent.clear();
248 QDomElement tosElem = elem.firstChildElement( QStringLiteral(
"text-on-symbol" ) );
249 if ( !tosElem.isNull() )
251 mTextOnSymbolEnabled =
true;
252 QDomElement tosFormatElem = tosElem.firstChildElement( QStringLiteral(
"text-style" ) );
253 mTextOnSymbolTextFormat.
readXml( tosFormatElem, context );
254 QDomElement tosContentElem = tosElem.firstChildElement( QStringLiteral(
"content" ) );
255 QDomElement tosContentItemElem = tosContentElem.firstChildElement( QStringLiteral(
"item" ) );
256 while ( !tosContentItemElem.isNull() )
258 mTextOnSymbolContent.insert( tosContentItemElem.attribute( QStringLiteral(
"key" ) ), tosContentItemElem.attribute( QStringLiteral(
"value" ) ) );
259 tosContentItemElem = tosContentItemElem.nextSiblingElement( QStringLiteral(
"item" ) );
266 QDomElement elem = doc.createElement( QStringLiteral(
"legend" ) );
267 elem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"default-vector" ) );
269 if ( mTextOnSymbolEnabled )
271 QDomElement tosElem = doc.createElement( QStringLiteral(
"text-on-symbol" ) );
272 QDomElement tosFormatElem = mTextOnSymbolTextFormat.
writeXml( doc, context );
273 tosElem.appendChild( tosFormatElem );
274 QDomElement tosContentElem = doc.createElement( QStringLiteral(
"content" ) );
275 for (
auto it = mTextOnSymbolContent.constBegin(); it != mTextOnSymbolContent.constEnd(); ++it )
277 QDomElement tosContentItemElem = doc.createElement( QStringLiteral(
"item" ) );
278 tosContentItemElem.setAttribute( QStringLiteral(
"key" ), it.key() );
279 tosContentItemElem.setAttribute( QStringLiteral(
"value" ), it.value() );
280 tosContentElem.appendChild( tosContentItemElem );
282 tosElem.appendChild( tosContentElem );
283 elem.appendChild( tosElem );
301 QList<QgsLayerTreeModelLegendNode *> nodes;
310 if ( rasterItemList.isEmpty() )
316 int max_count = 1000;
318 for ( QgsLegendColorList::const_iterator itemIt = rasterItemList.constBegin();
319 itemIt != rasterItemList.constEnd(); ++itemIt, ++count )
323 if ( count == max_count )
325 QString label = tr(
"following %1 items\nnot displayed" ).arg( rasterItemList.size() - max_count );
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.
QString ruleKey() const
Returns unique identifier of the rule for identification of the item within renderer.
This class is a composition of two QSettings instances:
QgsMapLayerLegend * legend() const
Can be null.
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.
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.
QStringList customProperties() const
Returns list of keys stored in custom properties.
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 * > 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.
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...
QgsFeatureRenderer * renderer()
Returns renderer.
static bool hasLegendNodeUserLabel(QgsLayerTreeLayer *nodeLayer, int originalIndex)
Implementation of legend node interface for displaying arbitrary label with icon. ...
void rendererChanged()
Signal emitted when renderer is changed.
const QgsDiagramRenderer * diagramRenderer() const
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.
QgsMapLayer * layer() const
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) ...
QgsDataDefinedSizeLegend * dataDefinedSizeLegendSettings() const
Returns extra information for data-defined size legend rendering.
QgsDefaultRasterLayerLegend(QgsRasterLayer *rl)
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()
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.
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.