Skip to content
Permalink
Browse files

Allow changing point cloud 2d renderer through widget

  • Loading branch information
nyalldawson committed Nov 16, 2020
1 parent 1951489 commit 38bc3c6dc86f5b921cd229feb4480d9422893b42
@@ -207,7 +207,7 @@ void QgsPointCloudRgbRenderer::renderBlock( const QgsPointCloudBlock *block, Qgs
QgsPointCloudRenderer *QgsPointCloudRgbRenderer::create( QDomElement &element, const QgsReadWriteContext & )
{
std::unique_ptr< QgsPointCloudRgbRenderer > r = qgis::make_unique< QgsPointCloudRgbRenderer >();
r->setPenWidth( element.attribute( QStringLiteral( "penwidth" ), QStringLiteral( "5" ) ).toInt() );
r->setPenWidth( element.attribute( QStringLiteral( "penwidth" ), QStringLiteral( "1" ) ).toInt() );

r->setRedAttribute( element.attribute( QStringLiteral( "red" ), QStringLiteral( "Red" ) ) );
r->setGreenAttribute( element.attribute( QStringLiteral( "green" ), QStringLiteral( "Green" ) ) );
@@ -19,6 +19,7 @@
#include "qgssymbolwidgetcontext.h"
#include "qgspointcloudrendererwidget.h"
#include "qgspointcloudlayer.h"
#include "qgspointcloudrenderer.h"

static bool _initRenderer( const QString &name, QgsPointCloudRendererWidgetFunc f, const QString &iconName = QString() )
{
@@ -75,8 +76,7 @@ QgsPointCloudRendererPropertiesWidget::QgsPointCloudRendererPropertiesWidget( Qg

cboRenderers->setCurrentIndex( -1 ); // set no current renderer

// connect layer opacity slider and spin box
//connect( cboRenderers, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPointCloudRendererPropertiesWidget::rendererChanged );
connect( cboRenderers, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPointCloudRendererPropertiesWidget::rendererChanged );

connect( mBlendModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );
connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );
@@ -101,13 +101,98 @@ void QgsPointCloudRendererPropertiesWidget::syncToLayer( QgsMapLayer *layer )
mBlockChangedSignal = true;
mOpacityWidget->setOpacity( mLayer->opacity() );
mBlendModeComboBox->setBlendMode( mLayer->blendMode() );

if ( mLayer->renderer() )
{
// set current renderer from layer
QString rendererName = mLayer->renderer()->type();

int rendererIdx = cboRenderers->findData( rendererName );
cboRenderers->setCurrentIndex( rendererIdx );

// no renderer found... this mustn't happen
Q_ASSERT( rendererIdx != -1 && "there must be a renderer!" );
}

mBlockChangedSignal = false;
}

void QgsPointCloudRendererPropertiesWidget::apply()
{
mLayer->setOpacity( mOpacityWidget->opacity() );
mLayer->setBlendMode( mBlendModeComboBox->blendMode() );

if ( mActiveWidget )
mLayer->setRenderer( mActiveWidget->renderer() );
else if ( !cboRenderers->currentData().toString().isEmpty() )
{
QDomElement elem;
mLayer->setRenderer( QgsApplication::pointCloudRendererRegistry()->rendererMetadata( cboRenderers->currentData().toString() )->createRenderer( elem, QgsReadWriteContext() ) );
}
}

void QgsPointCloudRendererPropertiesWidget::rendererChanged()
{
if ( cboRenderers->currentIndex() == -1 )
{
QgsDebugMsg( QStringLiteral( "No current item -- this should never happen!" ) );
return;
}

QString rendererName = cboRenderers->currentData().toString();

//Retrieve the previous renderer: from the old active widget if possible, otherwise from the layer
std::unique_ptr< QgsPointCloudRenderer > oldRenderer;
if ( mActiveWidget && mActiveWidget->renderer() )
{
oldRenderer.reset( mActiveWidget->renderer()->clone() );
}
else
{
oldRenderer.reset( mLayer->renderer()->clone() );
}

// get rid of old active widget (if any)
if ( mActiveWidget )
{
stackedWidget->removeWidget( mActiveWidget );

delete mActiveWidget;
mActiveWidget = nullptr;
}

QgsPointCloudRendererWidget *w = nullptr;
QgsPointCloudRendererAbstractMetadata *m = QgsApplication::pointCloudRendererRegistry()->rendererMetadata( rendererName );
if ( m )
w = m->createRendererWidget( mLayer, mStyle, oldRenderer.get() );
oldRenderer.reset();

if ( w )
{
// instantiate the widget and set as active
mActiveWidget = w;
stackedWidget->addWidget( mActiveWidget );
stackedWidget->setCurrentWidget( mActiveWidget );
if ( mActiveWidget->renderer() )
{
if ( mMapCanvas || mMessageBar )
{
QgsSymbolWidgetContext context;
context.setMapCanvas( mMapCanvas );
context.setMessageBar( mMessageBar );
mActiveWidget->setContext( context );
}
}
connect( mActiveWidget, &QgsPanelWidget::widgetChanged, this, &QgsPointCloudRendererPropertiesWidget::widgetChanged );
connect( mActiveWidget, &QgsPanelWidget::showPanel, this, &QgsPointCloudRendererPropertiesWidget::openPanel );
w->setDockMode( dockMode() );
}
else
{
// set default "no edit widget available" page
stackedWidget->setCurrentWidget( pageNoWidget );
}
emitWidgetChanged();
}

void QgsPointCloudRendererPropertiesWidget::emitWidgetChanged()
@@ -59,6 +59,8 @@ class GUI_EXPORT QgsPointCloudRendererPropertiesWidget : public QgsMapLayerConfi

private slots:

void rendererChanged();

void emitWidgetChanged();

private:

0 comments on commit 38bc3c6

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