Edge settings for polygons + GUI to configure edge rendering

This commit is contained in:
Martin Dobias 2019-04-05 15:16:34 +02:00
parent 28b349f04a
commit b5fec5872b
6 changed files with 250 additions and 78 deletions

View File

@ -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
};

View File

@ -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" ) ) );
}
}

View File

@ -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
};

View File

@ -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;

View File

@ -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;
}

View File

@ -7,17 +7,27 @@
<x>0</x>
<y>0</y>
<width>561</width>
<height>452</height>
<height>653</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="chkInvertNormals">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Invert normals (experimental)</string>
<string>Height</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsDoubleSpinBox" name="spinHeight">
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.000000000000000</double>
</property>
</widget>
</item>
@ -28,6 +38,53 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Extrusion</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsDoubleSpinBox" name="spinExtrusion">
<property name="maximum">
<double>99999.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QgsPropertyOverrideButton" name="btnExtrusionDD">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Altitude clamping</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cboAltClamping">
<item>
<property name="text">
<string>Absolute</string>
</property>
</item>
<item>
<property name="text">
<string>Relative</string>
</property>
</item>
<item>
<property name="text">
<string>Terrain</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
@ -49,57 +106,10 @@
</item>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cboAltClamping">
<item>
<property name="text">
<string>Absolute</string>
</property>
</item>
<item>
<property name="text">
<string>Relative</string>
</property>
</item>
<item>
<property name="text">
<string>Terrain</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsDoubleSpinBox" name="spinExtrusion">
<property name="maximum">
<double>99999.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Extrusion</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Altitude clamping</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QgsPropertyOverrideButton" name="btnExtrusionDD">
<property name="text">
<string>…</string>
<string>Culling mode</string>
</property>
</widget>
</item>
@ -122,10 +132,17 @@
</item>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<item row="5" column="0">
<widget class="QCheckBox" name="chkAddBackFaces">
<property name="text">
<string>Culling mode</string>
<string>Add back faces</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="chkInvertNormals">
<property name="text">
<string>Invert normals (experimental)</string>
</property>
</widget>
</item>
@ -139,21 +156,65 @@
<item row="8" column="0" colspan="3">
<widget class="QgsPhongMaterialWidget" name="widgetMaterial" native="true"/>
</item>
<item row="0" column="1">
<widget class="QgsDoubleSpinBox" name="spinHeight">
<property name="minimum">
<double>-99999.000000000000000</double>
<item row="9" column="0" colspan="3">
<widget class="QGroupBox" name="groupEdges">
<property name="title">
<string>Edges</string>
</property>
<property name="maximum">
<double>99999.000000000000000</double>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="chkAddBackFaces">
<property name="text">
<string>Add back faces</string>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="spinEdgeWidth">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string> px</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButton" name="btnEdgeColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
@ -175,6 +236,12 @@
<header>qgsphongmaterialwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>spinHeight</tabstop>