Skip to content
Permalink
Browse files

Refine legend for point clouds using attribute based renderer by

showing attribute title in legend
  • Loading branch information
nyalldawson committed Dec 16, 2020
1 parent 7fac048 commit e844fbff73c2aef9873fd9f1223f88ec9716f554
@@ -169,6 +169,8 @@ QSet<QString> QgsPointCloudAttributeByRampRenderer::usedAttributes( const QgsPoi
QList<QgsLayerTreeModelLegendNode *> QgsPointCloudAttributeByRampRenderer::createLegendNodes( QgsLayerTreeLayer *nodeLayer )
{
QList<QgsLayerTreeModelLegendNode *> res;
res << new QgsSimpleLegendNode( nodeLayer, mAttribute );

switch ( mColorRampShader.colorRampType() )
{
case QgsColorRampShader::Interpolated:
@@ -1595,6 +1595,7 @@ QgsLayoutLegendNodeWidget::QgsLayoutLegendNodeWidget( QgsLayoutItemLegend *legen
case QgsLayerTreeModelLegendNode::ImageLegend:
case QgsLayerTreeModelLegendNode::WmsLegend:
case QgsLayerTreeModelLegendNode::DataDefinedSizeLegend:
case QgsLayerTreeModelLegendNode::ColorRampLegend:
mCustomSymbolCheckBox->hide();
break;

@@ -30,7 +30,8 @@
QgsColorRampShader,
QgsStyle,
QgsLayerTreeLayer,
QgsColorRampLegendNode
QgsColorRampLegendNode,
QgsSimpleLegendNode
)

from qgis.PyQt.QtCore import QDir, QSize, Qt
@@ -148,20 +149,23 @@ def testLegend(self):
layer = QgsPointCloudLayer(unitTestDataPath() + '/point_clouds/ept/sunshine-coast/ept.json', 'test', 'ept')
layer_tree_layer = QgsLayerTreeLayer(layer)
nodes = renderer.createLegendNodes(layer_tree_layer)
self.assertEqual(len(nodes), 1)
self.assertIsInstance(nodes[0], QgsColorRampLegendNode)
self.assertEqual(nodes[0].ramp().color1().name(), '#440154')
self.assertEqual(nodes[0].ramp().color2().name(), '#fde725')
self.assertEqual(len(nodes), 2)
self.assertIsInstance(nodes[0], QgsSimpleLegendNode)
self.assertEqual(nodes[0].data(Qt.DisplayRole), 'Intensity')
self.assertIsInstance(nodes[1], QgsColorRampLegendNode)
self.assertEqual(nodes[1].ramp().color1().name(), '#440154')
self.assertEqual(nodes[1].ramp().color2().name(), '#fde725')

shader = QgsColorRampShader(200, 600, ramp.clone())
shader.setClassificationMode(QgsColorRampShader.EqualInterval)
shader.setColorRampType(QgsColorRampShader.Exact)
shader.classifyColorRamp(classes=2)
renderer.setColorRampShader(shader)
nodes = renderer.createLegendNodes(layer_tree_layer)
self.assertEqual(len(nodes), 2)
self.assertEqual(nodes[0].data(Qt.DisplayRole), '200')
self.assertEqual(nodes[1].data(Qt.DisplayRole), '600')
self.assertEqual(len(nodes), 3)
self.assertEqual(nodes[0].data(Qt.DisplayRole), 'Intensity')
self.assertEqual(nodes[1].data(Qt.DisplayRole), '200')
self.assertEqual(nodes[2].data(Qt.DisplayRole), '600')

@unittest.skipIf('ept' not in QgsProviderRegistry.instance().providerList(), 'EPT provider not available')
def testRender(self):

0 comments on commit e844fbf

Please sign in to comment.
You can’t perform that action at this time.