Skip to content

Commit b5fec58

Browse files
committed
Edge settings for polygons + GUI to configure edge rendering
1 parent 28b349f commit b5fec58

File tree

6 files changed

+240
-68
lines changed

6 files changed

+240
-68
lines changed

python/3d/auto_generated/symbols/qgspolygon3dsymbol.sip.in

+42
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,48 @@ Returns whether also triangles facing the other side will be created. Useful if
116116
Sets whether also triangles facing the other side will be created. Useful if input data have inconsistent order of vertices
117117

118118
.. versionadded:: 3.2
119+
%End
120+
121+
bool edgesEnabled() const;
122+
%Docstring
123+
Returns whether edge highlighting is enabled
124+
125+
.. versionadded:: 3.8
126+
%End
127+
128+
void setEdgesEnabled( bool enabled );
129+
%Docstring
130+
Sets whether edge highlighting is enabled
131+
132+
.. versionadded:: 3.8
133+
%End
134+
135+
float edgeWidth() const;
136+
%Docstring
137+
Returns width of edge lines (in pixels)
138+
139+
.. versionadded:: 3.8
140+
%End
141+
142+
void setEdgeWidth( float width );
143+
%Docstring
144+
Sets width of edge lines (in pixels)
145+
146+
.. versionadded:: 3.8
147+
%End
148+
149+
QColor edgeColor() const;
150+
%Docstring
151+
Returns edge lines color
152+
153+
.. versionadded:: 3.8
154+
%End
155+
156+
void setEdgeColor( const QColor &color );
157+
%Docstring
158+
Sets edge lines color
159+
160+
.. versionadded:: 3.8
119161
%End
120162

121163
};

src/3d/symbols/qgspolygon3dsymbol.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "qgspolygon3dsymbol.h"
1717

1818
#include "qgs3dutils.h"
19+
#include "qgssymbollayerutils.h"
1920

2021
QgsAbstract3DSymbol *QgsPolygon3DSymbol::clone() const
2122
{
@@ -45,6 +46,12 @@ void QgsPolygon3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext
4546
QDomElement elemDDP = doc.createElement( QStringLiteral( "data-defined-properties" ) );
4647
mDataDefinedProperties.writeXml( elemDDP, propertyDefinitions() );
4748
elem.appendChild( elemDDP );
49+
50+
QDomElement elemEdges = doc.createElement( QStringLiteral( "edges" ) );
51+
elemEdges.setAttribute( QStringLiteral( "enabled" ), mEdgesEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
52+
elemEdges.setAttribute( QStringLiteral( "width" ), mEdgeWidth );
53+
elemEdges.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mEdgeColor ) );
54+
elem.appendChild( elemEdges );
4855
}
4956

5057
void QgsPolygon3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
@@ -66,4 +73,12 @@ void QgsPolygon3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteCon
6673
QDomElement elemDDP = elem.firstChildElement( QStringLiteral( "data-defined-properties" ) );
6774
if ( !elemDDP.isNull() )
6875
mDataDefinedProperties.readXml( elemDDP, propertyDefinitions() );
76+
77+
QDomElement elemEdges = elem.firstChildElement( QStringLiteral( "edges" ) );
78+
if ( !elemEdges.isNull() )
79+
{
80+
mEdgesEnabled = elemEdges.attribute( QStringLiteral( "enabled" ) ).toInt();
81+
mEdgeWidth = elemEdges.attribute( QStringLiteral( "width" ) ).toFloat();
82+
mEdgeColor = QgsSymbolLayerUtils::decodeColor( elemEdges.attribute( QStringLiteral( "color" ) ) );
83+
}
6984
}

src/3d/symbols/qgspolygon3dsymbol.h

+40
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,42 @@ class _3D_EXPORT QgsPolygon3DSymbol : public QgsAbstract3DSymbol
9292
*/
9393
void setAddBackFaces( bool add ) { mAddBackFaces = add; }
9494

95+
/**
96+
* Returns whether edge highlighting is enabled
97+
* \since QGIS 3.8
98+
*/
99+
bool edgesEnabled() const { return mEdgesEnabled; }
100+
101+
/**
102+
* Sets whether edge highlighting is enabled
103+
* \since QGIS 3.8
104+
*/
105+
void setEdgesEnabled( bool enabled ) { mEdgesEnabled = enabled; }
106+
107+
/**
108+
* Returns width of edge lines (in pixels)
109+
* \since QGIS 3.8
110+
*/
111+
float edgeWidth() const { return mEdgeWidth; }
112+
113+
/**
114+
* Sets width of edge lines (in pixels)
115+
* \since QGIS 3.8
116+
*/
117+
void setEdgeWidth( float width ) { mEdgeWidth = width; }
118+
119+
/**
120+
* Returns edge lines color
121+
* \since QGIS 3.8
122+
*/
123+
QColor edgeColor() const { return mEdgeColor; }
124+
125+
/**
126+
* Sets edge lines color
127+
* \since QGIS 3.8
128+
*/
129+
void setEdgeColor( const QColor &color ) { mEdgeColor = color; }
130+
95131
private:
96132
//! how to handle altitude of vector features
97133
Qgs3DTypes::AltitudeClamping mAltClamping = Qgs3DTypes::AltClampRelative;
@@ -104,6 +140,10 @@ class _3D_EXPORT QgsPolygon3DSymbol : public QgsAbstract3DSymbol
104140
Qgs3DTypes::CullingMode mCullingMode = Qgs3DTypes::NoCulling; //!< Front/back culling mode
105141
bool mInvertNormals = false;
106142
bool mAddBackFaces = false;
143+
144+
bool mEdgesEnabled = false; //!< Whether to highlight edges
145+
float mEdgeWidth = 1.f; //!< Width of edges in pixels
146+
QColor mEdgeColor = Qt::black; //!< Color of edge lines
107147
};
108148

109149

src/3d/symbols/qgspolygon3dsymbol_p.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ class QgsPolygon3DSymbolHandler : public QgsFeature3DHandler
7070
PolygonData outNormal; //!< Features that are not selected
7171
PolygonData outSelected; //!< Features that are selected
7272

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

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

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

173170
// add entity for edges
174-
if ( addEdges && !outEdges.indexes.isEmpty() )
171+
if ( mSymbol.edgesEnabled() && !outEdges.indexes.isEmpty() )
175172
{
176173
QgsLineMaterial *mat = new QgsLineMaterial;
177-
mat->setLineColor( edgeColor );
178-
mat->setLineWidth( edgeWidth );
174+
mat->setLineColor( mSymbol.edgeColor() );
175+
mat->setLineWidth( mSymbol.edgeWidth() );
179176

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

src/app/3d/qgspolygon3dsymbolwidget.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ QgsPolygon3DSymbolWidget::QgsPolygon3DSymbolWidget( QWidget *parent )
3737
connect( widgetMaterial, &QgsPhongMaterialWidget::changed, this, &QgsPolygon3DSymbolWidget::changed );
3838
connect( btnHeightDD, &QgsPropertyOverrideButton::changed, this, &QgsPolygon3DSymbolWidget::changed );
3939
connect( btnExtrusionDD, &QgsPropertyOverrideButton::changed, this, &QgsPolygon3DSymbolWidget::changed );
40+
connect( groupEdges, &QGroupBox::clicked, this, &QgsPolygon3DSymbolWidget::changed );
41+
connect( btnEdgeColor, &QgsColorButton::colorChanged, this, &QgsPolygon3DSymbolWidget::changed );
42+
connect( spinEdgeWidth, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsPolygon3DSymbolWidget::changed );
4043
}
4144

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

5356
btnHeightDD->init( QgsAbstract3DSymbol::PropertyHeight, symbol.dataDefinedProperties(), QgsAbstract3DSymbol::propertyDefinitions(), layer, true );
5457
btnExtrusionDD->init( QgsAbstract3DSymbol::PropertyExtrusionHeight, symbol.dataDefinedProperties(), QgsAbstract3DSymbol::propertyDefinitions(), layer, true );
58+
59+
groupEdges->setChecked( symbol.edgesEnabled() );
60+
spinEdgeWidth->setValue( symbol.edgeWidth() );
61+
btnEdgeColor->setColor( symbol.edgeColor() );
5562
}
5663

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

81+
sym.setEdgesEnabled( groupEdges->isChecked() );
82+
sym.setEdgeWidth( spinEdgeWidth->value() );
83+
sym.setEdgeColor( btnEdgeColor->color() );
84+
7485
return sym;
7586
}

0 commit comments

Comments
 (0)