49 Q_FOREACH (
int id, order )
50 orderStr << QString::number(
id );
51 QString str = orderStr.isEmpty() ? QStringLiteral(
"empty" ) : orderStr.join( QStringLiteral(
"," ) );
60 int numNodes = lst.count();
69 QgsDebugMsg(
"Legend node order manipulation is invalid without existing legend" );
73 int numNodes = _originalLegendNodeCount( nodeLayer );
76 order.reserve( numNodes );
77 for (
int i = 0; i < numNodes; ++i )
84 QString orderStr = nodeLayer->
customProperty( QStringLiteral(
"legend/node-order" ) ).toString();
86 if ( orderStr.isEmpty() )
87 return _makeNodeOrder( nodeLayer );
89 if ( orderStr == QLatin1String(
"empty" ) )
92 int numNodes = _originalLegendNodeCount( nodeLayer );
95 Q_FOREACH (
const QString &item, orderStr.split(
',' ) )
98 int id = item.toInt( &ok );
99 if ( !ok || id < 0 || id >= numNodes )
100 return _makeNodeOrder( nodeLayer );
110 return nodeLayer->
customProperties().contains( QStringLiteral(
"legend/node-order" ) );
115 nodeLayer->
setCustomProperty(
"legend/label-" + QString::number( originalIndex ), newLabel );
120 return nodeLayer->
customProperty(
"legend/label-" + QString::number( originalIndex ) ).toString();
125 return nodeLayer->
customProperties().contains(
"legend/label-" + QString::number( originalIndex ) );
136 if ( !userLabel.isNull() )
145 QList<QgsLayerTreeModelLegendNode *> newOrder;
146 QSet<int> usedIndices;
147 Q_FOREACH (
int idx, order )
149 if ( usedIndices.contains( idx ) )
155 newOrder << nodes[idx];
160 for (
int i = 0; i < nodes.count(); ++i )
162 if ( !usedIndices.contains( i ) )
182 QList<QgsLayerTreeModelLegendNode *> nodes;
188 if ( nodeLayer->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toBool() )
205 if ( nodes.count() == 1 && nodes[0]->data( Qt::EditRole ).toString().isEmpty() )
206 nodes[0]->setEmbeddedInParent(
true );
234 QList<QgsLayerTreeModelLegendNode *> nodes;
243 if ( rasterItemList.isEmpty() )
249 int max_count = 1000;
251 for ( QgsLegendColorList::const_iterator itemIt = rasterItemList.constBegin();
252 itemIt != rasterItemList.constEnd(); ++itemIt, ++count )
256 if ( count == max_count )
258 QString label = tr(
"following %1 items\nnot displayed" ).arg( rasterItemList.size() - max_count );
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 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 null.
static void setLegendNodeUserLabel(QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel)
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)
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
Return list of keys stored in custom properties.
QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Return list of legend nodes to be used for a particular layer tree layer node.
QgsRasterDataProvider * dataProvider() override
virtual QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer)=0
Return 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.
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()
Return 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
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.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
QgsDefaultRasterLayerLegend(QgsRasterLayer *rl)
QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Return 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...
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.
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)
Set 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.