From b5fec5872b348020006a1533cf3048138725dc39 Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Fri, 5 Apr 2019 15:16:34 +0200 Subject: [PATCH] Edge settings for polygons + GUI to configure edge rendering --- .../symbols/qgspolygon3dsymbol.sip.in | 42 ++++ src/3d/symbols/qgspolygon3dsymbol.cpp | 15 ++ src/3d/symbols/qgspolygon3dsymbol.h | 40 ++++ src/3d/symbols/qgspolygon3dsymbol_p.cpp | 11 +- src/app/3d/qgspolygon3dsymbolwidget.cpp | 11 + src/ui/3d/polygon3dsymbolwidget.ui | 209 ++++++++++++------ 6 files changed, 250 insertions(+), 78 deletions(-) diff --git a/python/3d/auto_generated/symbols/qgspolygon3dsymbol.sip.in b/python/3d/auto_generated/symbols/qgspolygon3dsymbol.sip.in index 991d609e5ce..e8a1a9e5150 100644 --- a/python/3d/auto_generated/symbols/qgspolygon3dsymbol.sip.in +++ b/python/3d/auto_generated/symbols/qgspolygon3dsymbol.sip.in @@ -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 }; diff --git a/src/3d/symbols/qgspolygon3dsymbol.cpp b/src/3d/symbols/qgspolygon3dsymbol.cpp index 9a60c8d2345..efc097d235b 100644 --- a/src/3d/symbols/qgspolygon3dsymbol.cpp +++ b/src/3d/symbols/qgspolygon3dsymbol.cpp @@ -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" ) ) ); + } } diff --git a/src/3d/symbols/qgspolygon3dsymbol.h b/src/3d/symbols/qgspolygon3dsymbol.h index cd17fd208f5..52e0d769413 100644 --- a/src/3d/symbols/qgspolygon3dsymbol.h +++ b/src/3d/symbols/qgspolygon3dsymbol.h @@ -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 }; diff --git a/src/3d/symbols/qgspolygon3dsymbol_p.cpp b/src/3d/symbols/qgspolygon3dsymbol_p.cpp index 72774870d1a..2e95513748e 100644 --- a/src/3d/symbols/qgspolygon3dsymbol_p.cpp +++ b/src/3d/symbols/qgspolygon3dsymbol_p.cpp @@ -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( 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; diff --git a/src/app/3d/qgspolygon3dsymbolwidget.cpp b/src/app/3d/qgspolygon3dsymbolwidget.cpp index ec28e7a9987..d8f8277d32a 100644 --- a/src/app/3d/qgspolygon3dsymbolwidget.cpp +++ b/src/app/3d/qgspolygon3dsymbolwidget.cpp @@ -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( &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; } diff --git a/src/ui/3d/polygon3dsymbolwidget.ui b/src/ui/3d/polygon3dsymbolwidget.ui index 50284e65e2e..e9d4729d509 100644 --- a/src/ui/3d/polygon3dsymbolwidget.ui +++ b/src/ui/3d/polygon3dsymbolwidget.ui @@ -7,17 +7,27 @@ 0 0 561 - 452 + 653 Form - - - + + + - Invert normals (experimental) + Height + + + + + + + -99999.000000000000000 + + + 99999.000000000000000 @@ -28,6 +38,53 @@ + + + + Extrusion + + + + + + + 99999.000000000000000 + + + + + + + + + + + + + + Altitude clamping + + + + + + + + Absolute + + + + + Relative + + + + + Terrain + + + + @@ -49,57 +106,10 @@ - - - - - Absolute - - - - - Relative - - - - - Terrain - - - - - - + + - Height - - - - - - - 99999.000000000000000 - - - - - - - Extrusion - - - - - - - Altitude clamping - - - - - - - + Culling mode @@ -122,10 +132,17 @@ - - + + - Culling mode + Add back faces + + + + + + + Invert normals (experimental) @@ -139,21 +156,65 @@ - - - - -99999.000000000000000 + + + + Edges - - 99999.000000000000000 - - - - - - - Add back faces + + true + + + + + + 1 + 0 + + + + Width + + + + + + + + 1 + 0 + + + + px + + + + + + + Color + + + + + + + + 0 + 0 + + + + + 120 + 0 + + + + + @@ -175,6 +236,12 @@
qgsphongmaterialwidget.h
1 + + QgsColorButton + QToolButton +
qgscolorbutton.h
+ 1 +
spinHeight