19#include "moc_qgsvectorlayerelevationproperties.cpp" 
   35  setDefaultProfileLineSymbol( color );
 
   36  setDefaultProfileFillSymbol( color );
 
   37  setDefaultProfileMarkerSymbol( color );
 
 
   52  QDomElement element = document.createElement( QStringLiteral( 
"elevation" ) );
 
   55  element.setAttribute( QStringLiteral( 
"extrusionEnabled" ), mEnableExtrusion ? QStringLiteral( 
"1" ) : QStringLiteral( 
"0" ) );
 
   56  element.setAttribute( QStringLiteral( 
"extrusion" ), 
qgsDoubleToString( mExtrusionHeight ) );
 
   57  element.setAttribute( QStringLiteral( 
"customToleranceEnabled" ), mEnableCustomTolerance ? QStringLiteral( 
"1" ) : QStringLiteral( 
"0" ) );
 
   58  if ( mCustomTolerance != 0 )
 
   59    element.setAttribute( QStringLiteral( 
"customTolerance" ), 
qgsDoubleToString( mCustomTolerance ) );
 
   60  element.setAttribute( QStringLiteral( 
"clamping" ), 
qgsEnumValueToKey( mClamping ) );
 
   61  element.setAttribute( QStringLiteral( 
"binding" ), 
qgsEnumValueToKey( mBinding ) );
 
   63  element.setAttribute( QStringLiteral( 
"symbology" ), 
qgsEnumValueToKey( mSymbology ) );
 
   64  if ( !std::isnan( mElevationLimit ) )
 
   65    element.setAttribute( QStringLiteral( 
"elevationLimit" ), 
qgsDoubleToString( mElevationLimit ) );
 
   67  element.setAttribute( QStringLiteral( 
"respectLayerSymbol" ), mRespectLayerSymbology ? QStringLiteral( 
"1" ) : QStringLiteral( 
"0" ) );
 
   68  element.setAttribute( QStringLiteral( 
"showMarkerSymbolInSurfacePlots" ), mShowMarkerSymbolInSurfacePlots ? QStringLiteral( 
"1" ) : QStringLiteral( 
"0" ) );
 
   70  QDomElement profileLineSymbolElement = document.createElement( QStringLiteral( 
"profileLineSymbol" ) );
 
   72  element.appendChild( profileLineSymbolElement );
 
   74  QDomElement profileFillSymbolElement = document.createElement( QStringLiteral( 
"profileFillSymbol" ) );
 
   76  element.appendChild( profileFillSymbolElement );
 
   78  QDomElement profileMarkerSymbolElement = document.createElement( QStringLiteral( 
"profileMarkerSymbol" ) );
 
   80  element.appendChild( profileMarkerSymbolElement );
 
   82  parentElement.appendChild( element );
 
 
   88  const QDomElement elevationElement = element.firstChildElement( QStringLiteral( 
"elevation" ) ).toElement();
 
   89  if ( elevationElement.isNull() )
 
   97  mEnableExtrusion = elevationElement.attribute( QStringLiteral( 
"extrusionEnabled" ), QStringLiteral( 
"0" ) ).toInt();
 
   98  mExtrusionHeight = elevationElement.attribute( QStringLiteral( 
"extrusion" ), QStringLiteral( 
"0" ) ).toDouble();
 
   99  mEnableCustomTolerance = elevationElement.attribute( QStringLiteral( 
"customToleranceEnabled" ), QStringLiteral( 
"0" ) ).toInt();
 
  100  mCustomTolerance = elevationElement.attribute( QStringLiteral( 
"customTolerance" ), QStringLiteral( 
"0" ) ).toDouble();
 
  102  if ( elevationElement.hasAttribute( QStringLiteral( 
"elevationLimit" ) ) )
 
  103    mElevationLimit = elevationElement.attribute( QStringLiteral( 
"elevationLimit" ) ).toDouble();
 
  105    mElevationLimit = std::numeric_limits< double >::quiet_NaN();
 
  107  mShowMarkerSymbolInSurfacePlots = elevationElement.attribute( QStringLiteral( 
"showMarkerSymbolInSurfacePlots" ), QStringLiteral( 
"0" ) ).toInt();
 
  109  mRespectLayerSymbology = elevationElement.attribute( QStringLiteral( 
"respectLayerSymbol" ), QStringLiteral( 
"1" ) ).toInt();
 
  113  const QDomElement profileLineSymbolElement = elevationElement.firstChildElement( QStringLiteral( 
"profileLineSymbol" ) ).firstChildElement( QStringLiteral( 
"symbol" ) );
 
  114  mProfileLineSymbol = QgsSymbolLayerUtils::loadSymbol< QgsLineSymbol >( profileLineSymbolElement, context );
 
  115  if ( !mProfileLineSymbol )
 
  116    setDefaultProfileLineSymbol( color );
 
  118  const QDomElement profileFillSymbolElement = elevationElement.firstChildElement( QStringLiteral( 
"profileFillSymbol" ) ).firstChildElement( QStringLiteral( 
"symbol" ) );
 
  119  mProfileFillSymbol = QgsSymbolLayerUtils::loadSymbol< QgsFillSymbol >( profileFillSymbolElement, context );
 
  120  if ( !mProfileFillSymbol )
 
  121    setDefaultProfileFillSymbol( color );
 
  123  const QDomElement profileMarkerSymbolElement = elevationElement.firstChildElement( QStringLiteral( 
"profileMarkerSymbol" ) ).firstChildElement( QStringLiteral( 
"symbol" ) );
 
  124  mProfileMarkerSymbol = QgsSymbolLayerUtils::loadSymbol< QgsMarkerSymbol >( profileMarkerSymbolElement, context );
 
  125  if ( !mProfileMarkerSymbol )
 
  126    setDefaultProfileMarkerSymbol( color );
 
 
  133  QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layer );
 
  140  mEnableExtrusion = 
false;
 
  141  mExtrusionHeight = 0;
 
  147  mCustomTolerance = 0;
 
 
  165  auto res = std::make_unique< QgsVectorLayerElevationProperties >( 
nullptr );
 
  166  res->setClamping( mClamping );
 
  167  res->setBinding( mBinding );
 
  168  res->setType( mType );
 
  169  res->setExtrusionEnabled( mEnableExtrusion );
 
  170  res->setExtrusionHeight( mExtrusionHeight );
 
  171  res->setCustomToleranceEnabled( mEnableCustomTolerance );
 
  172  res->setCustomTolerance( mCustomTolerance );
 
  173  res->setProfileLineSymbol( mProfileLineSymbol->clone() );
 
  174  res->setProfileFillSymbol( mProfileFillSymbol->clone() );
 
  175  res->setProfileMarkerSymbol( mProfileMarkerSymbol->clone() );
 
  176  res->setRespectLayerSymbology( mRespectLayerSymbology );
 
  177  res->setProfileSymbology( mSymbology );
 
  178  res->setElevationLimit( mElevationLimit );
 
  179  res->setShowMarkerSymbolInSurfacePlots( mShowMarkerSymbolInSurfacePlots );
 
  180  res->copyCommonProperties( 
this );
 
  181  return res.release();
 
 
  186  QStringList properties;
 
  191      properties << tr( 
"Clamped to Terrain" );
 
  194      properties << tr( 
"Relative to Terrain" );
 
  197      properties << tr( 
"Absolute" );
 
  218    properties << tr( 
"Offset: %1" ).arg( 
mZOffset );
 
  221  if ( mEnableExtrusion )
 
  240      properties << tr( 
"Extrusion: %1" ).arg( mExtrusionHeight );
 
  244  if ( mEnableCustomTolerance )
 
  246    properties << tr( 
"CustomTolerance: %1" ).arg( mCustomTolerance );
 
  249  properties << tr( 
"Scale: %1" ).arg( 
mZScale );
 
  251  return QStringLiteral( 
"<li>%1</li>" ).arg( properties.join( QLatin1String( 
"</li><li>" ) ) );
 
 
  308  if ( mEnableExtrusion == enabled )
 
  311  mEnableExtrusion = enabled;
 
 
  318  if ( mExtrusionHeight == height )
 
  321  mExtrusionHeight = height;
 
 
  328  if ( mCustomTolerance == tolerance )
 
  331  mCustomTolerance = tolerance;
 
 
  338  if ( mEnableCustomTolerance == enabled )
 
  341  mEnableCustomTolerance = enabled;
 
 
  348  if ( mRespectLayerSymbology == enabled )
 
  351  mRespectLayerSymbology = enabled;
 
 
  358  return mProfileLineSymbol.get();
 
 
  363  mProfileLineSymbol.reset( symbol );
 
 
  370  return mProfileFillSymbol.get();
 
 
  375  mProfileFillSymbol.reset( symbol );
 
 
  382  return mProfileMarkerSymbol.get();
 
 
  387  mProfileMarkerSymbol.reset( symbol );
 
 
  394  if ( mSymbology == symbology )
 
  397  mSymbology = symbology;
 
 
  404  return mElevationLimit;
 
 
  412  mElevationLimit = limit;
 
 
  419  if ( show == mShowMarkerSymbolInSurfacePlots )
 
  422  mShowMarkerSymbolInSurfacePlots = show;
 
 
  427void QgsVectorLayerElevationProperties::setDefaultProfileLineSymbol( 
const QColor &color )
 
  429  auto profileLineLayer = std::make_unique< QgsSimpleLineSymbolLayer >( color, 0.6 );
 
  430  mProfileLineSymbol = std::make_unique< QgsLineSymbol>( 
QgsSymbolLayerList( { profileLineLayer.release() } ) );
 
  433void QgsVectorLayerElevationProperties::setDefaultProfileMarkerSymbol( 
const QColor &color )
 
  436  profileMarkerLayer->setColor( color );
 
  437  profileMarkerLayer->setStrokeWidth( 0.2 );
 
  438  profileMarkerLayer->setStrokeColor( color.darker( 140 ) );
 
  439  mProfileMarkerSymbol = std::make_unique< QgsMarkerSymbol>( 
QgsSymbolLayerList( { profileMarkerLayer.release() } ) );
 
  442void QgsVectorLayerElevationProperties::setDefaultProfileFillSymbol( 
const QColor &color )
 
  444  auto profileFillLayer = std::make_unique< QgsSimpleFillSymbolLayer >( color );
 
  445  profileFillLayer->setStrokeWidth( 0.2 );
 
  446  profileFillLayer->setStrokeColor( color.darker( 140 ) );
 
  447  mProfileFillSymbol = std::make_unique< QgsFillSymbol>( 
QgsSymbolLayerList( { profileFillLayer.release() } ) );
 
AltitudeClamping
Altitude clamping.
@ Relative
Elevation is relative to terrain height (final elevation = terrain elevation + feature elevation)
@ Terrain
Elevation is clamped to terrain (final elevation = terrain elevation)
@ Absolute
Elevation is taken directly from feature and is independent of terrain height (final elevation = feat...
@ Invalid
Invalid (not set) property.
@ Field
Field based property.
@ Expression
Expression based property.
AltitudeBinding
Altitude binding.
@ Centroid
Clamp just centroid of feature.
VectorProfileType
Types of elevation profiles to generate for vector sources.
@ IndividualFeatures
Treat each feature as an individual object (eg buildings)
ProfileSurfaceSymbology
Surface symbology type for elevation profile plots.
@ Line
The elevation surface will be rendered using a line symbol.
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
QColor fetchRandomStyleColor() const
Returns a random color for use with a new symbol style (e.g.
QgsRange which stores a range of double values.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
A line symbol type, for rendering LineString and MultiLineString geometries.
Base class for storage of map layer elevation properties.
QgsPropertyCollection mDataDefinedProperties
Property collection for data defined elevation settings.
void writeCommonProperties(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context)
Writes common class properties to a DOM element, to be used later with readXml().
void profileGenerationPropertyChanged()
Emitted when any of the elevation properties which relate solely to generation of elevation profiles ...
void readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common class properties from a DOM element previously written by writeXml().
void changed()
Emitted when any of the elevation properties have changed.
void profileRenderingPropertyChanged()
Emitted when any of the elevation properties which relate solely to presentation of elevation results...
@ ExtrusionHeight
Extrusion height.
Base class for all map layer types.
A marker symbol type, for rendering Point and MultiPoint geometries.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
void clear() final
Removes all properties from the collection.
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
QString expressionString() const
Returns the expression used for the property value.
Qgis::PropertyType propertyType() const
Returns the property type.
QString field() const
Returns the current field name the property references.
A container for the context for various read/write operations on objects.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
Vector layer specific subclass of QgsMapLayerElevationProperties.
QString htmlSummary() const override
Returns a HTML formatted summary of the properties.
void setCustomToleranceEnabled(bool enabled)
Sets whether custom tolerance is enabled.
void setDefaultsFromLayer(QgsMapLayer *layer) override
Sets default properties based on sensible choices for the given map layer.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the elevation properties from a DOM element previously written by writeXml().
void setCustomTolerance(double tolerance)
Sets the feature custom tolerance.
QgsFillSymbol * profileFillSymbol() const
Returns the symbol used to render polygons for the layer in elevation profile plots.
void setProfileFillSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to render polygons for the layer in elevation profile plots.
void setExtrusionHeight(double height)
Sets the feature extrusion height.
void setShowMarkerSymbolInSurfacePlots(bool show)
Sets whether the marker symbol should also be shown in continuous surface plots.
void setBinding(Qgis::AltitudeBinding binding)
Sets the altitude binding method, which determines how altitude is bound to individual vertices in fe...
QDomElement writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) override
Writes the properties to a DOM element, to be used later with readXml().
Qgis::VectorProfileType type() const
Returns the type of profile the layer represents.
double elevationLimit() const
Returns the elevation limit, which is used when profileSymbology() is Qgis::ProfileSurfaceSymbology::...
~QgsVectorLayerElevationProperties() override
QgsDoubleRange calculateZRange(QgsMapLayer *layer) const override
Attempts to calculate the overall elevation or z range for the specified layer, using the settings de...
QgsLineSymbol * profileLineSymbol() const
Returns the symbol used to render lines for the layer in elevation profile plots.
void setProfileSymbology(Qgis::ProfileSurfaceSymbology symbology)
Sets the symbology option used to render the vector profile in elevation profile plots.
void setProfileMarkerSymbol(QgsMarkerSymbol *symbol)
Sets the marker symbol used to render points for the layer in elevation profile plots.
void setExtrusionEnabled(bool enabled)
Sets whether extrusion is enabled.
void setType(Qgis::VectorProfileType type)
Sets the type of profile the layer represents.
QgsVectorLayerElevationProperties * clone() const override
Creates a clone of the properties.
Qgis::AltitudeClamping clamping() const
Returns the altitude clamping method, which dictates how feature heights are interpreted with respect...
QgsVectorLayerElevationProperties(QObject *parent)
Constructor for QgsVectorLayerElevationProperties, with the specified parent object.
bool showByDefaultInElevationProfilePlots() const override
Returns true if the layer should be visible by default in newly created elevation profile plots.
QgsMarkerSymbol * profileMarkerSymbol() const
Returns the symbol used to render points for the layer in elevation profile plots.
Qgis::AltitudeBinding binding() const
Returns the altitude binding method, which determines how altitude is bound to individual vertices in...
void setProfileLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render lines for the layer in elevation profile plots.
bool isVisibleInZRange(const QgsDoubleRange &range, QgsMapLayer *layer=nullptr) const override
Returns true if the layer should be visible and rendered for the specified z range.
bool hasElevation() const override
Returns true if the layer has an elevation or z component.
void setRespectLayerSymbology(bool enabled)
Sets whether layer symbology should be respected when rendering elevation profile plots.
void setElevationLimit(double limit)
Sets the elevation limit, which is used when profileSymbology() is Qgis::ProfileSurfaceSymbology::Fil...
void setClamping(Qgis::AltitudeClamping clamping)
Sets the altitude clamping method, which dictates how feature heights are interpreted with respect to...
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE Qgis::WkbType wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QList< QgsSymbolLayer * > QgsSymbolLayerList