Skip to content
Permalink
Browse files

Edge settings for polygons + GUI to configure edge rendering

  • Loading branch information
wonder-sk committed Apr 9, 2019
1 parent 28b349f commit b5fec5872b348020006a1533cf3048138725dc39
@@ -116,6 +116,48 @@ Returns whether also triangles facing the other side will be created. Useful if
Sets whether also triangles facing the other side will be created. Useful if input data have inconsistent order of vertices

.. versionadded:: 3.2
%End

bool edgesEnabled() const;
%Docstring
Returns whether edge highlighting is enabled

.. versionadded:: 3.8
%End

void setEdgesEnabled( bool enabled );
%Docstring
Sets whether edge highlighting is enabled

.. versionadded:: 3.8
%End

float edgeWidth() const;
%Docstring
Returns width of edge lines (in pixels)

.. versionadded:: 3.8
%End

void setEdgeWidth( float width );
%Docstring
Sets width of edge lines (in pixels)

.. versionadded:: 3.8
%End

QColor edgeColor() const;
%Docstring
Returns edge lines color

.. versionadded:: 3.8
%End

void setEdgeColor( const QColor &color );
%Docstring
Sets edge lines color

.. versionadded:: 3.8
%End

};
@@ -16,6 +16,7 @@
#include "qgspolygon3dsymbol.h"

#include "qgs3dutils.h"
#include "qgssymbollayerutils.h"

QgsAbstract3DSymbol *QgsPolygon3DSymbol::clone() const
{
@@ -45,6 +46,12 @@ void QgsPolygon3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext
QDomElement elemDDP = doc.createElement( QStringLiteral( "data-defined-properties" ) );
mDataDefinedProperties.writeXml( elemDDP, propertyDefinitions() );
elem.appendChild( elemDDP );

QDomElement elemEdges = doc.createElement( QStringLiteral( "edges" ) );
elemEdges.setAttribute( QStringLiteral( "enabled" ), mEdgesEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
elemEdges.setAttribute( QStringLiteral( "width" ), mEdgeWidth );
elemEdges.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mEdgeColor ) );
elem.appendChild( elemEdges );
}

void QgsPolygon3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
@@ -66,4 +73,12 @@ void QgsPolygon3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteCon
QDomElement elemDDP = elem.firstChildElement( QStringLiteral( "data-defined-properties" ) );
if ( !elemDDP.isNull() )
mDataDefinedProperties.readXml( elemDDP, propertyDefinitions() );

QDomElement elemEdges = elem.firstChildElement( QStringLiteral( "edges" ) );
if ( !elemEdges.isNull() )
{
mEdgesEnabled = elemEdges.attribute( QStringLiteral( "enabled" ) ).toInt();
mEdgeWidth = elemEdges.attribute( QStringLiteral( "width" ) ).toFloat();
mEdgeColor = QgsSymbolLayerUtils::decodeColor( elemEdges.attribute( QStringLiteral( "color" ) ) );
}
}
@@ -92,6 +92,42 @@ class _3D_EXPORT QgsPolygon3DSymbol : public QgsAbstract3DSymbol
*/
void setAddBackFaces( bool add ) { mAddBackFaces = add; }

/**
* Returns whether edge highlighting is enabled
* \since QGIS 3.8
*/
bool edgesEnabled() const { return mEdgesEnabled; }

/**
* Sets whether edge highlighting is enabled
* \since QGIS 3.8
*/
void setEdgesEnabled( bool enabled ) { mEdgesEnabled = enabled; }

/**
* Returns width of edge lines (in pixels)
* \since QGIS 3.8
*/
float edgeWidth() const { return mEdgeWidth; }

/**
* Sets width of edge lines (in pixels)
* \since QGIS 3.8
*/
void setEdgeWidth( float width ) { mEdgeWidth = width; }

/**
* Returns edge lines color
* \since QGIS 3.8
*/
QColor edgeColor() const { return mEdgeColor; }

/**
* Sets edge lines color
* \since QGIS 3.8
*/
void setEdgeColor( const QColor &color ) { mEdgeColor = color; }

private:
//! how to handle altitude of vector features
Qgs3DTypes::AltitudeClamping mAltClamping = Qgs3DTypes::AltClampRelative;
@@ -104,6 +140,10 @@ class _3D_EXPORT QgsPolygon3DSymbol : public QgsAbstract3DSymbol
Qgs3DTypes::CullingMode mCullingMode = Qgs3DTypes::NoCulling; //!< Front/back culling mode
bool mInvertNormals = false;
bool mAddBackFaces = false;

bool mEdgesEnabled = false; //!< Whether to highlight edges
float mEdgeWidth = 1.f; //!< Width of edges in pixels
QColor mEdgeColor = Qt::black; //!< Color of edge lines
};


@@ -70,9 +70,6 @@ class QgsPolygon3DSymbolHandler : public QgsFeature3DHandler
PolygonData outNormal; //!< Features that are not selected
PolygonData outSelected; //!< Features that are selected

bool addEdges = true; //!< TODO: should go to polygon symbol
QColor edgeColor = QColor( 0, 0, 0 ); //!< TODO: go to polygon symbol
float edgeWidth = 2; //!< TODO: go to polygon symbol
QgsLineVertexData outEdges; //!< When highlighting edges, this holds data for vertex/index buffer
};

@@ -89,7 +86,7 @@ bool QgsPolygon3DSymbolHandler::prepare( const Qgs3DRenderContext &context, QSet

void QgsPolygon3DSymbolHandler::processPolygon( QgsPolygon *polyClone, QgsFeatureId fid, float height, bool hasDDExtrusion, float extrusionHeight, const Qgs3DRenderContext &context, PolygonData &out )
{
if ( addEdges )
if ( mSymbol.edgesEnabled() )
{
// add edges before the polygon gets the Z values modified because addLineString() does its own altitude handling
outEdges.addLineString( *static_cast<const QgsLineString *>( polyClone->exteriorRing() ) );
@@ -171,11 +168,11 @@ void QgsPolygon3DSymbolHandler::finalize( Qt3DCore::QEntity *parent, const Qgs3D
makeEntity( parent, context, outSelected, true );

// add entity for edges
if ( addEdges && !outEdges.indexes.isEmpty() )
if ( mSymbol.edgesEnabled() && !outEdges.indexes.isEmpty() )
{
QgsLineMaterial *mat = new QgsLineMaterial;
mat->setLineColor( edgeColor );
mat->setLineWidth( edgeWidth );
mat->setLineColor( mSymbol.edgeColor() );
mat->setLineWidth( mSymbol.edgeWidth() );

Qt3DCore::QEntity *entity = new Qt3DCore::QEntity;

@@ -37,6 +37,9 @@ QgsPolygon3DSymbolWidget::QgsPolygon3DSymbolWidget( QWidget *parent )
connect( widgetMaterial, &QgsPhongMaterialWidget::changed, this, &QgsPolygon3DSymbolWidget::changed );
connect( btnHeightDD, &QgsPropertyOverrideButton::changed, this, &QgsPolygon3DSymbolWidget::changed );
connect( btnExtrusionDD, &QgsPropertyOverrideButton::changed, this, &QgsPolygon3DSymbolWidget::changed );
connect( groupEdges, &QGroupBox::clicked, this, &QgsPolygon3DSymbolWidget::changed );
connect( btnEdgeColor, &QgsColorButton::colorChanged, this, &QgsPolygon3DSymbolWidget::changed );
connect( spinEdgeWidth, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsPolygon3DSymbolWidget::changed );
}

void QgsPolygon3DSymbolWidget::setSymbol( const QgsPolygon3DSymbol &symbol, QgsVectorLayer *layer )
@@ -52,6 +55,10 @@ void QgsPolygon3DSymbolWidget::setSymbol( const QgsPolygon3DSymbol &symbol, QgsV

btnHeightDD->init( QgsAbstract3DSymbol::PropertyHeight, symbol.dataDefinedProperties(), QgsAbstract3DSymbol::propertyDefinitions(), layer, true );
btnExtrusionDD->init( QgsAbstract3DSymbol::PropertyExtrusionHeight, symbol.dataDefinedProperties(), QgsAbstract3DSymbol::propertyDefinitions(), layer, true );

groupEdges->setChecked( symbol.edgesEnabled() );
spinEdgeWidth->setValue( symbol.edgeWidth() );
btnEdgeColor->setColor( symbol.edgeColor() );
}

QgsPolygon3DSymbol QgsPolygon3DSymbolWidget::symbol() const
@@ -71,5 +78,9 @@ QgsPolygon3DSymbol QgsPolygon3DSymbolWidget::symbol() const
ddp.setProperty( QgsAbstract3DSymbol::PropertyExtrusionHeight, btnExtrusionDD->toProperty() );
sym.setDataDefinedProperties( ddp );

sym.setEdgesEnabled( groupEdges->isChecked() );
sym.setEdgeWidth( spinEdgeWidth->value() );
sym.setEdgeColor( btnEdgeColor->color() );

return sym;
}

0 comments on commit b5fec58

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