Skip to content

Commit

Permalink
Edge settings for polygons + GUI to configure edge rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Apr 9, 2019
1 parent 28b349f commit b5fec58
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 68 deletions.
42 changes: 42 additions & 0 deletions python/3d/auto_generated/symbols/qgspolygon3dsymbol.sip.in
Expand Up @@ -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

};
Expand Down
15 changes: 15 additions & 0 deletions src/3d/symbols/qgspolygon3dsymbol.cpp
Expand Up @@ -16,6 +16,7 @@
#include "qgspolygon3dsymbol.h"

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

QgsAbstract3DSymbol *QgsPolygon3DSymbol::clone() const
{
Expand Down Expand Up @@ -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 )
Expand All @@ -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" ) ) );
}
}
40 changes: 40 additions & 0 deletions src/3d/symbols/qgspolygon3dsymbol.h
Expand Up @@ -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;
Expand All @@ -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
};


Expand Down
11 changes: 4 additions & 7 deletions src/3d/symbols/qgspolygon3dsymbol_p.cpp
Expand Up @@ -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
};

Expand All @@ -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() ) );
Expand Down Expand Up @@ -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;

Expand Down
11 changes: 11 additions & 0 deletions src/app/3d/qgspolygon3dsymbolwidget.cpp
Expand Up @@ -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 )
Expand All @@ -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
Expand All @@ -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.