Skip to content

Commit

Permalink
Add possibility for point cloud renderers to create checkable legend …
Browse files Browse the repository at this point in the history
…nodes

(not implemented for any renderers yet)
  • Loading branch information
nyalldawson authored and PeterPetrik committed Dec 3, 2020
1 parent 9bcdcf6 commit 91048d4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
14 changes: 14 additions & 0 deletions python/core/auto_generated/pointcloud/qgspointcloudrenderer.sip.in
Expand Up @@ -218,6 +218,20 @@ Calls to :py:func:`~QgsPointCloudRenderer.stopRender` must always be preceded by
the renderer should instead be cloned and :py:func:`~QgsPointCloudRenderer.startRender`/:py:func:`~QgsPointCloudRenderer.stopRender` called on the clone.

.. seealso:: :py:func:`startRender`
%End

virtual bool legendItemChecked( const QString &key );
%Docstring
Returns ``True`` if the legend item with the specified ``key`` is checked.

.. seealso:: :py:func:`checkLegendItem`
%End

virtual void checkLegendItem( const QString &key, bool state = true );
%Docstring
Called when the check state of the legend item with the specified ``key`` is changed.

.. seealso:: :py:func:`legendItemChecked`
%End

void setPointSize( double size );
Expand Down
28 changes: 27 additions & 1 deletion src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -27,6 +27,8 @@
#include "qgssymbollayerutils.h"
#include "qgsimageoperation.h"
#include "qgsvectorlayer.h"
#include "qgspointcloudlayer.h"
#include "qgspointcloudrenderer.h"
#include "qgsrasterrenderer.h"
#include "qgsexpressioncontextutils.h"
#include "qgsfeatureid.h"
Expand Down Expand Up @@ -974,6 +976,14 @@ QVariant QgsRasterSymbolLegendNode::data( int role ) const
if ( !mCheckable )
return QVariant();

if ( QgsPointCloudLayer *pclayer = qobject_cast<QgsPointCloudLayer *>( mLayerNode->layer() ) )
{
if ( !pclayer->renderer() )
return QVariant();

return pclayer->renderer()->legendItemChecked( mRuleKey ) ? Qt::Checked : Qt::Unchecked;
}

return QVariant();
}

Expand All @@ -990,7 +1000,23 @@ bool QgsRasterSymbolLegendNode::setData( const QVariant &value, int role )
if ( !mCheckable )
return false;

return false;
if ( QgsPointCloudLayer *pclayer = qobject_cast<QgsPointCloudLayer *>( mLayerNode->layer() ) )
{
if ( !pclayer->renderer() )
return false;

pclayer->renderer()->checkLegendItem( mRuleKey, value == Qt::Checked );

emit dataChanged();
pclayer->emitStyleChanged();

pclayer->triggerRepaint();
return true;
}
else
{
return false;
}
}


Expand Down
10 changes: 10 additions & 0 deletions src/core/pointcloud/qgspointcloudrenderer.cpp
Expand Up @@ -91,6 +91,16 @@ void QgsPointCloudRenderer::stopRender( QgsPointCloudRenderContext & )
#endif
}

bool QgsPointCloudRenderer::legendItemChecked( const QString & )
{
return false;
}

void QgsPointCloudRenderer::checkLegendItem( const QString &, bool )
{

}

double QgsPointCloudRenderer::maximumScreenError() const
{
return mMaximumScreenError;
Expand Down
14 changes: 14 additions & 0 deletions src/core/pointcloud/qgspointcloudrenderer.h
Expand Up @@ -290,6 +290,20 @@ class CORE_EXPORT QgsPointCloudRenderer
*/
virtual void stopRender( QgsPointCloudRenderContext &context );

/**
* Returns TRUE if the legend item with the specified \a key is checked.
*
* \see checkLegendItem()
*/
virtual bool legendItemChecked( const QString &key );

/**
* Called when the check state of the legend item with the specified \a key is changed.
*
* \see legendItemChecked()
*/
virtual void checkLegendItem( const QString &key, bool state = true );

/**
* Sets the point \a size. Point size units are specified via setPointSizeUnit().
* \see pointSize()
Expand Down

0 comments on commit 91048d4

Please sign in to comment.