Skip to content
Permalink
Browse files

backport #34999

(cherry picked from commit 54daf1f)
  • Loading branch information
vcloarec authored and nyalldawson committed May 20, 2020
1 parent 9d92435 commit 2eb89da6dc370b6084608487d01315b9c71ea3d4
@@ -78,6 +78,9 @@ Qt3DCore::QEntity *QgsMeshLayer3DRenderer::createEntity( const Qgs3DMapSettings
if ( !mSymbol || !vl )
return nullptr;

if ( !mSymbol->isEnabled() )
return nullptr;

return new QgsMesh3DSymbolEntity( map, vl, *static_cast<QgsMesh3DSymbol *>( mSymbol.get() ) );
}

@@ -32,6 +32,7 @@ void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &co
elemDataProperties.setAttribute( QStringLiteral( "alt-clamping" ), Qgs3DUtils::altClampingToString( mAltClamping ) );
elemDataProperties.setAttribute( QStringLiteral( "height" ), mHeight );
elemDataProperties.setAttribute( QStringLiteral( "add-back-faces" ), mAddBackFaces ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
elemDataProperties.setAttribute( QStringLiteral( "renderer-3d-enabled" ), mEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
elem.appendChild( elemDataProperties );

QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
@@ -51,6 +52,7 @@ void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex
mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( QStringLiteral( "alt-clamping" ) ) );
mHeight = elemDataProperties.attribute( QStringLiteral( "height" ) ).toFloat();
mAddBackFaces = elemDataProperties.attribute( QStringLiteral( "add-back-faces" ) ).toInt();
mEnabled = elemDataProperties.attribute( QStringLiteral( "renderer-3d-enabled" ) ).toInt();

QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
mMaterial.readXml( elemMaterial );
@@ -59,3 +61,14 @@ void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex
if ( !elemDDP.isNull() )
mDataDefinedProperties.readXml( elemDDP, propertyDefinitions() );
}

bool QgsMesh3DSymbol::isEnabled() const
{
return mEnabled;
}

void QgsMesh3DSymbol::setEnabled( bool enabled )
{
mEnabled = enabled;
}

@@ -45,6 +45,20 @@ class _3D_EXPORT QgsMesh3DSymbol : public QgsAbstract3DSymbol
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;

/**
* Returns if the 3d rendering is enabled
*
* \since QGIS 3.10.7
*/
bool isEnabled() const;

/**
* Sets if the 3d rendering is enabled
*
* \since QGIS 3.10.7
*/
void setEnabled( bool enabled );

//! Returns method that determines altitude (whether to clamp to feature to terrain)
Qgs3DTypes::AltitudeClamping altitudeClamping() const { return mAltClamping; }
//! Sets method that determines altitude (whether to clamp to feature to terrain)
@@ -76,6 +90,7 @@ class _3D_EXPORT QgsMesh3DSymbol : public QgsAbstract3DSymbol
float mHeight = 0.0f; //!< Base height of triangles
QgsPhongMaterialSettings mMaterial; //!< Defines appearance of objects
bool mAddBackFaces = false;
bool mEnabled = true;
};


@@ -30,13 +30,14 @@ QgsMeshLayer3DRendererWidget::QgsMeshLayer3DRendererWidget( QgsMeshLayer *layer,
setPanelTitle( tr( "3D View" ) );

QVBoxLayout *layout = new QVBoxLayout( this );
chkEnabled = new QCheckBox( tr( "Enable 3D Renderer" ), this );
layout->addWidget( chkEnabled );
widgetMesh = new QgsMesh3DSymbolWidget( this );
layout->addWidget( widgetMesh );

connect( chkEnabled, &QCheckBox::clicked, this, &QgsMeshLayer3DRendererWidget::onEnabledClicked );
connect( widgetMesh, &QgsMesh3DSymbolWidget::changed, this, &QgsMeshLayer3DRendererWidget::widgetChanged );
layout->setContentsMargins( 0, 0, 0, 0 );
mChkEnabled = new QCheckBox( tr( "Enable 3D Renderer" ), this );
layout->addWidget( mChkEnabled );
mWidgetMesh = new QgsMesh3DSymbolWidget( this );
layout->addWidget( mWidgetMesh );

connect( mChkEnabled, &QCheckBox::clicked, this, &QgsMeshLayer3DRendererWidget::onEnabledClicked );
connect( mWidgetMesh, &QgsMesh3DSymbolWidget::changed, this, &QgsMeshLayer3DRendererWidget::widgetChanged );
}

void QgsMeshLayer3DRendererWidget::setLayer( QgsMeshLayer *layer )
@@ -48,6 +49,7 @@ void QgsMeshLayer3DRendererWidget::setLayer( QgsMeshLayer *layer )
{
QgsMeshLayer3DRenderer *meshRenderer = static_cast<QgsMeshLayer3DRenderer *>( r );
setRenderer( meshRenderer );
mWidgetMesh->setEnabled( meshRenderer->symbol()->isEnabled() );
}
else
{
@@ -58,33 +60,23 @@ void QgsMeshLayer3DRendererWidget::setLayer( QgsMeshLayer *layer )
void QgsMeshLayer3DRendererWidget::setRenderer( const QgsMeshLayer3DRenderer *renderer )
{
mRenderer.reset( renderer ? renderer->clone() : nullptr );

whileBlocking( chkEnabled )->setChecked( ( bool )mRenderer );

whileBlocking( mChkEnabled )->setChecked( renderer ? renderer->symbol()->isEnabled() : false );
if ( mRenderer && mRenderer->symbol() && mRenderer->symbol()->type() == QLatin1String( "mesh" ) )
{
whileBlocking( widgetMesh )->setSymbol( *static_cast<const QgsMesh3DSymbol *>( mRenderer->symbol() ), nullptr );
whileBlocking( mWidgetMesh )->setSymbol( *static_cast<const QgsMesh3DSymbol *>( mRenderer->symbol() ), nullptr );
}
else
{
whileBlocking( widgetMesh )->setSymbol( QgsMesh3DSymbol(), nullptr );
whileBlocking( mWidgetMesh )->setSymbol( QgsMesh3DSymbol(), nullptr );
}
}

QgsMeshLayer3DRenderer *QgsMeshLayer3DRendererWidget::renderer()
{
if ( chkEnabled->isChecked() )
{
QgsMesh3DSymbol *sym = new QgsMesh3DSymbol( widgetMesh->symbol() );
QgsMeshLayer3DRenderer *r = new QgsMeshLayer3DRenderer( sym );
r->setLayer( qobject_cast<QgsMeshLayer *>( mLayer ) );
mRenderer.reset( r );
}
else
{
mRenderer.reset();
}

QgsMesh3DSymbol *sym = new QgsMesh3DSymbol( mWidgetMesh->symbol() );
sym->setEnabled( mChkEnabled->isChecked() );
mRenderer.reset( new QgsMeshLayer3DRenderer( sym ) );
mRenderer->setLayer( qobject_cast<QgsMeshLayer *>( mLayer ) );
return mRenderer.get();
}

@@ -96,6 +88,6 @@ void QgsMeshLayer3DRendererWidget::apply()

void QgsMeshLayer3DRendererWidget::onEnabledClicked()
{
widgetMesh->setEnabled( chkEnabled->isChecked() );
mWidgetMesh->setEnabled( mChkEnabled->isChecked() );
emit widgetChanged();
}
@@ -49,8 +49,8 @@ class QgsMeshLayer3DRendererWidget : public QgsMapLayerConfigWidget
void onEnabledClicked();

private:
QCheckBox *chkEnabled = nullptr;
QgsMesh3DSymbolWidget *widgetMesh = nullptr;
QCheckBox *mChkEnabled = nullptr;
QgsMesh3DSymbolWidget *mWidgetMesh = nullptr;
std::unique_ptr<QgsMeshLayer3DRenderer> mRenderer;
};

0 comments on commit 2eb89da

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