Skip to content
Permalink
Browse files

Fully hook up dummy renderer

  • Loading branch information
nyalldawson committed Nov 12, 2020
1 parent 2753b56 commit 551cbe14d1a63768c6525400be8b94570e86efbc
@@ -102,15 +102,21 @@ QgsPointCloudLayerProperties::QgsPointCloudLayerProperties( QgsPointCloudLayer *
restoreOptionsBaseUi( title );
}

#include "qgspointcloudrenderer.h"

void QgsPointCloudLayerProperties::apply()
{
mMetadataWidget->acceptMetadata();

// TODO -- move to proper widget classes!
mLayer->setCustomProperty( QStringLiteral( "pcAttribute" ), mAttributeComboBox->currentAttribute() );
mLayer->setCustomProperty( QStringLiteral( "pcMin" ), mMinZSpin->value() );
mLayer->setCustomProperty( QStringLiteral( "pcMax" ), mMaxZSpin->value() );
mLayer->setCustomProperty( QStringLiteral( "pcRamp" ), mBtnColorRamp->colorRampName().isEmpty() ? QStringLiteral( "Viridis" ) : mBtnColorRamp->colorRampName() );

std::unique_ptr< QgsDummyPointCloudRenderer > renderer = qgis::make_unique< QgsDummyPointCloudRenderer >();
renderer->setAttribute( mAttributeComboBox->currentAttribute() );
renderer->setZMin( mMinZSpin->value() );
renderer->setZMax( mMaxZSpin->value() );
renderer->setColorRamp( mBtnColorRamp->colorRamp() );
mLayer->setRenderer( renderer.release() );

mLayer->triggerRepaint();
}

@@ -142,11 +148,13 @@ void QgsPointCloudLayerProperties::syncToLayer()
connect( mInformationTextBrowser, &QTextBrowser::anchorClicked, this, &QgsPointCloudLayerProperties::urlClicked );

// TODO -- move to proper widget classes!
mAttributeComboBox->setAttribute( mLayer->customProperty( QStringLiteral( "pcAttribute" ), QStringLiteral( "Z" ) ).toString() );
mMinZSpin->setValue( mLayer->customProperty( QStringLiteral( "pcMin" ), 400 ).toInt() );
mMaxZSpin->setValue( mLayer->customProperty( QStringLiteral( "pcMax" ), 600 ).toInt() );
mBtnColorRamp->setColorRampFromName( mLayer->customProperty( QStringLiteral( "pcRamp" ), QStringLiteral( "Viridis" ) ).toString() );
mBtnColorRamp->setColorRampName( mLayer->customProperty( QStringLiteral( "pcRamp" ), QStringLiteral( "Viridis" ) ).toString() );
if ( QgsDummyPointCloudRenderer *renderer = dynamic_cast< QgsDummyPointCloudRenderer * >( mLayer->renderer() ) )
{
mAttributeComboBox->setAttribute( renderer->attribute() );
mMinZSpin->setValue( renderer->zMin() );
mMaxZSpin->setValue( renderer->zMax() );
mBtnColorRamp->setColorRamp( renderer->colorRamp() );
}
}


@@ -137,21 +137,6 @@ bool QgsPointCloudLayer::readSymbology( const QDomNode &node, QString &errorMess
if ( categories.testFlag( CustomProperties ) )
readCustomProperties( node, QStringLiteral( "variable" ) );

// hack for now !!
if ( categories.testFlag( Symbology ) )
{
const QDomElement elemRenderer = elem.firstChildElement( QStringLiteral( "renderer" ) );
if ( elemRenderer.isNull() )
{
errorMessage = tr( "Missing <renderer> tag" );
// return false;
}
setCustomProperty( QStringLiteral( "pcMin" ), elemRenderer.attribute( QStringLiteral( "pcMin" ), QStringLiteral( "400" ) ).toInt() );
setCustomProperty( QStringLiteral( "pcMax" ), elemRenderer.attribute( QStringLiteral( "pcMax" ), QStringLiteral( "600" ) ).toInt() );
setCustomProperty( QStringLiteral( "pcRamp" ), elemRenderer.attribute( QStringLiteral( "pcRamp" ), QStringLiteral( "Viridis" ) ) );
setCustomProperty( QStringLiteral( "pcAttribute" ), elemRenderer.attribute( QStringLiteral( "pcAttribute" ), QStringLiteral( "Z" ) ) );
}

return true;
}

@@ -231,17 +216,6 @@ bool QgsPointCloudLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QStr

( void )writeStyle( node, doc, errorMessage, context, categories );

// hack for now !!
if ( categories.testFlag( Symbology ) )
{
QDomElement elemRenderer = doc.createElement( QStringLiteral( "renderer" ) );
elemRenderer.setAttribute( QStringLiteral( "pcMin" ), customProperty( QStringLiteral( "pcMin" ), 400 ).toInt() );
elemRenderer.setAttribute( QStringLiteral( "pcMax" ), customProperty( QStringLiteral( "pcMax" ), 600 ).toInt() );
elemRenderer.setAttribute( QStringLiteral( "pcRamp" ), customProperty( QStringLiteral( "pcRamp" ), QStringLiteral( "Viridis" ) ).toString() );
elemRenderer.setAttribute( QStringLiteral( "pcAttribute" ), customProperty( QStringLiteral( "pcAttribute" ), QStringLiteral( "Z" ) ).toString() );
elem.appendChild( elemRenderer );
}

return true;
}

@@ -33,17 +33,6 @@ QgsPointCloudLayerRenderer::QgsPointCloudLayerRenderer( QgsPointCloudLayer *laye
: QgsMapLayerRenderer( layer->id(), &context )
, mLayer( layer )
{

#if 0
// TODO: use config from layer
mConfig.setPenWidth( context.convertToPainterUnits( 1, QgsUnitTypes::RenderUnit::RenderMillimeters ) );
// good range for 26850_12580.laz
mConfig.setZMin( layer->customProperty( QStringLiteral( "pcMin" ), 400 ).toInt() );
mConfig.setZMax( layer->customProperty( QStringLiteral( "pcMax" ), 600 ).toInt() );
mConfig.setColorRamp( QgsStyle::defaultStyle()->colorRamp( layer->customProperty( QStringLiteral( "pcRamp" ), QStringLiteral( "Viridis" ) ).toString() ) );
mConfig.setAttribute( layer->customProperty( QStringLiteral( "pcAttribute" ), QStringLiteral( "Z" ) ).toString() );
#endif

// TODO: we must not keep pointer to mLayer (it's dangerous) - we must copy anything we need for rendering
// or use some locking to prevent read/write from multiple threads
if ( !mLayer || !mLayer->dataProvider() || !mLayer->dataProvider()->index() || !mLayer->renderer() )
@@ -64,6 +53,7 @@ bool QgsPointCloudLayerRenderer::render()

QgsPointCloudRenderContext context( *renderContext(), mScale, mOffset );

mRenderer->startRender( context );

mAttributes.push_back( QgsPointCloudAttribute( QStringLiteral( "X" ), QgsPointCloudAttribute::Int32 ) );
mAttributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Y" ), QgsPointCloudAttribute::Int32 ) );
@@ -56,7 +56,7 @@ QgsPointCloudRenderer *QgsPointCloudRenderer::load( QDomElement &element, const
std::unique_ptr< QgsPointCloudRenderer > r( m->createRenderer( element, context ) );
return r.release();
#endif
return new QgsDummyPointCloudRenderer();
return QgsDummyPointCloudRenderer::create( element, context );
}

QSet<QString> QgsPointCloudRenderer::usedAttributes( const QgsPointCloudRenderContext & ) const
@@ -88,6 +88,12 @@ void QgsPointCloudRenderer::stopRender( QgsPointCloudRenderContext & )

#include "qgscolorramp.h"
#include "qgspointcloudblock.h"
#include "qgsstyle.h"

QgsDummyPointCloudRenderer::QgsDummyPointCloudRenderer()
{
mColorRamp.reset( QgsStyle::defaultStyle()->colorRamp( QStringLiteral( "Viridis" ) ) );
}

QgsPointCloudRenderer *QgsDummyPointCloudRenderer::clone() const
{
@@ -187,11 +193,41 @@ void QgsDummyPointCloudRenderer::renderBlock( const QgsPointCloudBlock *block, Q
context.incrementPointsRendered( rendered );
}

#include "qgssymbollayerutils.h"


QgsPointCloudRenderer *QgsDummyPointCloudRenderer::create( QDomElement &element, const QgsReadWriteContext & )
{
std::unique_ptr< QgsDummyPointCloudRenderer > r = qgis::make_unique< QgsDummyPointCloudRenderer >();

r->setAttribute( element.attribute( QStringLiteral( "attribute" ) ) );
r->setZMin( element.attribute( QStringLiteral( "min" ), QStringLiteral( "0" ) ).toDouble() );
r->setZMax( element.attribute( QStringLiteral( "max" ), QStringLiteral( "100" ) ).toDouble() );
r->setPenWidth( element.attribute( QStringLiteral( "penwidth" ), QStringLiteral( "5" ) ).toInt() );

QDomElement sourceColorRampElem = element.firstChildElement( QStringLiteral( "colorramp" ) );
if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral( "name" ) ) == QLatin1String( "[source]" ) )
{
r->setColorRamp( QgsSymbolLayerUtils::loadColorRamp( sourceColorRampElem ) );
}

return r.release();
}

QDomElement QgsDummyPointCloudRenderer::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
{
Q_UNUSED( context )
// create empty renderer element
QDomElement rendererElem = doc.createElement( QStringLiteral( "renderer" ) );

rendererElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "dummy" ) );
rendererElem.setAttribute( QStringLiteral( "penwidth" ), mPenWidth );
rendererElem.setAttribute( QStringLiteral( "min" ), mZMin );
rendererElem.setAttribute( QStringLiteral( "max" ), mZMax );
rendererElem.setAttribute( QStringLiteral( "attribute" ), mAttribute );

QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QStringLiteral( "[source]" ), mColorRamp.get(), doc );
rendererElem.appendChild( colorRampElem );

return rendererElem;
}

@@ -266,3 +302,4 @@ void QgsDummyPointCloudRenderer::setAttribute( const QString &attribute )
{
mAttribute = attribute;
}

@@ -193,13 +193,20 @@ class CORE_EXPORT QgsDummyPointCloudRenderer : public QgsPointCloudRenderer
{
public:

QgsDummyPointCloudRenderer();

QgsPointCloudRenderer *clone() const override;
void renderBlock( const QgsPointCloudBlock *block, QgsPointCloudRenderContext &context ) override;
QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
void startRender( QgsPointCloudRenderContext &context ) override;
void stopRender( QgsPointCloudRenderContext &context ) override;
QSet< QString > usedAttributes( const QgsPointCloudRenderContext &context ) const override;

/**
* Creates a dummy renderer from an XML \a element.
*/
static QgsPointCloudRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;

//! Returns z min
double zMin() const;
//! Sets z min
@@ -230,8 +237,8 @@ class CORE_EXPORT QgsDummyPointCloudRenderer : public QgsPointCloudRenderer
void setAttribute( const QString &attribute );

private:
double mZMin = 0, mZMax = 0;
QString mAttribute;
double mZMin = 0, mZMax = 100;
QString mAttribute = "Z";
int mPenWidth = 1;
int mPainterPenWidth = 1;
std::unique_ptr<QgsColorRamp> mColorRamp;

0 comments on commit 551cbe1

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