Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Profile Tool] Introduce custom tolerance for vector layers #59215

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,52 @@ Sets the feature extrusion height.
the :py:func:`~QgsVectorLayerElevationProperties.zScale` factor is NOT applied to extrusion heights.

.. seealso:: :py:func:`extrusionHeight`
%End

bool customToleranceEnabled() const;
%Docstring
Returns ``True`` if custom tolerance is enabled.

.. seealso:: :py:func:`setCustomToleranceEnabled`

.. seealso:: :py:func:`customTolerance`
%End

void setCustomToleranceEnabled( bool enabled );
%Docstring
Sets whether custom tolerance is ``enabled``.

.. seealso:: :py:func:`customToleranceEnabled`

.. seealso:: :py:func:`setCustomTolerance`
%End

double customTolerance() const;
%Docstring
Returns the feature custom tolerance.

.. warning::

custom tolerance is only applied if :py:func:`~QgsVectorLayerElevationProperties.customToleranceEnabled` is ``True``.

If enabled, the profile generator will use this tolerance instead of the one
defined in the elevation profile widget.

.. seealso:: :py:func:`setCustomTolerance`
%End

void setCustomTolerance( double tolerance );
%Docstring
Sets the feature custom tolerance.

.. warning::

custom tolerance is only applied if :py:func:`~QgsVectorLayerElevationProperties.customToleranceEnabled` is ``True``.

If enabled, the profile generator will use this tolerance instead of the one
defined in the elevation profile widget.

.. seealso:: :py:func:`customTolerance`
%End

bool respectLayerSymbology() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,52 @@ Sets the feature extrusion height.
the :py:func:`~QgsVectorLayerElevationProperties.zScale` factor is NOT applied to extrusion heights.

.. seealso:: :py:func:`extrusionHeight`
%End

bool customToleranceEnabled() const;
%Docstring
Returns ``True`` if custom tolerance is enabled.

.. seealso:: :py:func:`setCustomToleranceEnabled`

.. seealso:: :py:func:`customTolerance`
%End

void setCustomToleranceEnabled( bool enabled );
%Docstring
Sets whether custom tolerance is ``enabled``.

.. seealso:: :py:func:`customToleranceEnabled`

.. seealso:: :py:func:`setCustomTolerance`
%End

double customTolerance() const;
%Docstring
Returns the feature custom tolerance.

.. warning::

custom tolerance is only applied if :py:func:`~QgsVectorLayerElevationProperties.customToleranceEnabled` is ``True``.

If enabled, the profile generator will use this tolerance instead of the one
defined in the elevation profile widget.

.. seealso:: :py:func:`setCustomTolerance`
%End

void setCustomTolerance( double tolerance );
%Docstring
Sets the feature custom tolerance.

.. warning::

custom tolerance is only applied if :py:func:`~QgsVectorLayerElevationProperties.customToleranceEnabled` is ``True``.

If enabled, the profile generator will use this tolerance instead of the one
defined in the elevation profile widget.

.. seealso:: :py:func:`customTolerance`
%End

bool respectLayerSymbology() const;
Expand Down
7 changes: 6 additions & 1 deletion src/app/vector/qgsvectorelevationpropertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ QgsVectorElevationPropertiesWidget::QgsVectorElevationPropertiesWidget( QgsVecto
mOffsetZSpinBox->setClearValue( 0 );
mScaleZSpinBox->setClearValue( 1 );
mExtrusionSpinBox->setClearValue( 0 );
mToleranceSpinBox->setClearValue( 0 );

mLineStyleButton->setSymbolType( Qgis::SymbolType::Line );
mFillStyleButton->setSymbolType( Qgis::SymbolType::Fill );
Expand Down Expand Up @@ -77,6 +78,7 @@ QgsVectorElevationPropertiesWidget::QgsVectorElevationPropertiesWidget( QgsVecto
connect( mElevationLimitSpinBox, qOverload<double >( &QDoubleSpinBox::valueChanged ), this, &QgsVectorElevationPropertiesWidget::onChanged );
connect( mExtrusionSpinBox, qOverload<double >( &QDoubleSpinBox::valueChanged ), this, &QgsVectorElevationPropertiesWidget::onChanged );
connect( mExtrusionGroupBox, &QGroupBox::toggled, this, &QgsVectorElevationPropertiesWidget::onChanged );
connect( mToleranceSpinBox, qOverload<double >( &QDoubleSpinBox::valueChanged ), this, &QgsVectorElevationPropertiesWidget::onChanged );
connect( mComboClamping, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsVectorElevationPropertiesWidget::onChanged );
connect( mComboBinding, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsVectorElevationPropertiesWidget::onChanged );
connect( mComboClamping, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsVectorElevationPropertiesWidget::clampingChanged );
Expand Down Expand Up @@ -156,6 +158,8 @@ void QgsVectorElevationPropertiesWidget::syncToLayer( QgsMapLayer *layer )
mElevationLimitSpinBox->setValue( props->elevationLimit() );
mExtrusionGroupBox->setChecked( props->extrusionEnabled() );
mExtrusionSpinBox->setValue( props->extrusionHeight() );
mToleranceGroupBox->setChecked( props->customToleranceEnabled() );
mToleranceSpinBox->setValue( props->customTolerance() );
mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( static_cast< int >( props->type() ) ) );
switch ( props->type() )
{
Expand Down Expand Up @@ -235,6 +239,8 @@ void QgsVectorElevationPropertiesWidget::apply()
props->setBinding( static_cast< Qgis::AltitudeBinding >( mComboBinding->currentData().toInt() ) );
props->setExtrusionEnabled( mExtrusionGroupBox->isChecked() );
props->setExtrusionHeight( mExtrusionSpinBox->value() );
props->setCustomToleranceEnabled( mToleranceGroupBox->isChecked() );
props->setCustomTolerance( mToleranceSpinBox->value() );
if ( mElevationLimitSpinBox->value() != mElevationLimitSpinBox->clearValue() )
props->setElevationLimit( mElevationLimitSpinBox->value() );
else
Expand Down Expand Up @@ -500,4 +506,3 @@ QString QgsVectorElevationPropertiesWidgetFactory::layerPropertiesPagePositionHi
{
return QStringLiteral( "mOptsPage_Metadata" );
}

34 changes: 34 additions & 0 deletions src/core/vector/qgsvectorlayerelevationproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ QDomElement QgsVectorLayerElevationProperties::writeXml( QDomElement &parentElem

element.setAttribute( QStringLiteral( "extrusionEnabled" ), mEnableExtrusion ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
element.setAttribute( QStringLiteral( "extrusion" ), qgsDoubleToString( mExtrusionHeight ) );
element.setAttribute( QStringLiteral( "customToleranceEnabled" ), mEnableCustomTolerance ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
element.setAttribute( QStringLiteral( "customTolerance" ), qgsDoubleToString( mCustomTolerance ) );
element.setAttribute( QStringLiteral( "clamping" ), qgsEnumValueToKey( mClamping ) );
element.setAttribute( QStringLiteral( "binding" ), qgsEnumValueToKey( mBinding ) );
element.setAttribute( QStringLiteral( "type" ), qgsEnumValueToKey( mType ) );
Expand Down Expand Up @@ -92,6 +94,8 @@ bool QgsVectorLayerElevationProperties::readXml( const QDomElement &element, con
mType = qgsEnumKeyToValue( elevationElement.attribute( QStringLiteral( "type" ) ), Qgis::VectorProfileType::IndividualFeatures );
mEnableExtrusion = elevationElement.attribute( QStringLiteral( "extrusionEnabled" ), QStringLiteral( "0" ) ).toInt();
mExtrusionHeight = elevationElement.attribute( QStringLiteral( "extrusion" ), QStringLiteral( "0" ) ).toDouble();
mEnableCustomTolerance = elevationElement.attribute( QStringLiteral( "customToleranceEnabled" ), QStringLiteral( "0" ) ).toInt();
mCustomTolerance = elevationElement.attribute( QStringLiteral( "customTolerance" ), QStringLiteral( "0" ) ).toDouble();
mSymbology = qgsEnumKeyToValue( elevationElement.attribute( QStringLiteral( "symbology" ) ), Qgis::ProfileSurfaceSymbology::Line );
if ( elevationElement.hasAttribute( QStringLiteral( "elevationLimit" ) ) )
mElevationLimit = elevationElement.attribute( QStringLiteral( "elevationLimit" ) ).toDouble();
Expand Down Expand Up @@ -134,6 +138,9 @@ void QgsVectorLayerElevationProperties::setDefaultsFromLayer( QgsMapLayer *layer
mEnableExtrusion = false;
mExtrusionHeight = 0;

mEnableCustomTolerance = false;
mCustomTolerance = 0;

mDataDefinedProperties.clear();

mBinding = Qgis::AltitudeBinding::Centroid;
Expand All @@ -156,6 +163,8 @@ QgsVectorLayerElevationProperties *QgsVectorLayerElevationProperties::clone() co
res->setType( mType );
res->setExtrusionEnabled( mEnableExtrusion );
res->setExtrusionHeight( mExtrusionHeight );
res->setCustomToleranceEnabled( mEnableCustomTolerance );
res->setCustomTolerance( mCustomTolerance );
res->setProfileLineSymbol( mProfileLineSymbol->clone() );
res->setProfileFillSymbol( mProfileFillSymbol->clone() );
res->setProfileMarkerSymbol( mProfileMarkerSymbol->clone() );
Expand Down Expand Up @@ -227,6 +236,11 @@ QString QgsVectorLayerElevationProperties::htmlSummary() const
}
}

if ( mEnableCustomTolerance )
{
properties << tr( "CustomTolerance: %1" ).arg( mCustomTolerance );
}

properties << tr( "Scale: %1" ).arg( mZScale );

return QStringLiteral( "<li>%1</li>" ).arg( properties.join( QLatin1String( "</li><li>" ) ) );
Expand Down Expand Up @@ -304,6 +318,26 @@ void QgsVectorLayerElevationProperties::setExtrusionHeight( double height )
emit profileGenerationPropertyChanged();
}

void QgsVectorLayerElevationProperties::setCustomTolerance( double tolerance )
{
if ( mCustomTolerance == tolerance )
return;

mCustomTolerance = tolerance;
emit changed();
emit profileGenerationPropertyChanged();
}

void QgsVectorLayerElevationProperties::setCustomToleranceEnabled( bool enabled )
{
if ( mEnableCustomTolerance == enabled )
return;

mEnableCustomTolerance = enabled;
emit changed();
emit profileGenerationPropertyChanged();
}

void QgsVectorLayerElevationProperties::setRespectLayerSymbology( bool enabled )
{
if ( mRespectLayerSymbology == enabled )
Expand Down
42 changes: 42 additions & 0 deletions src/core/vector/qgsvectorlayerelevationproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,46 @@ class CORE_EXPORT QgsVectorLayerElevationProperties : public QgsMapLayerElevatio
*/
void setExtrusionHeight( double height );

/**
* Returns TRUE if custom tolerance is enabled.
*
* \see setCustomToleranceEnabled()
* \see customTolerance()
*/
bool customToleranceEnabled() const { return mEnableCustomTolerance; }

/**
* Sets whether custom tolerance is \a enabled.
*
* \see customToleranceEnabled()
* \see setCustomTolerance()
*/
void setCustomToleranceEnabled( bool enabled );

/**
* Returns the feature custom tolerance.
*
* \warning custom tolerance is only applied if customToleranceEnabled() is TRUE.
*
* If enabled, the profile generator will use this tolerance instead of the one
* defined in the elevation profile widget.
*
* \see setCustomTolerance()
*/
double customTolerance() const { return mCustomTolerance; }

/**
* Sets the feature custom tolerance.
*
* \warning custom tolerance is only applied if customToleranceEnabled() is TRUE.
*
* If enabled, the profile generator will use this tolerance instead of the one
* defined in the elevation profile widget.
*
* \see customTolerance()
*/
void setCustomTolerance( double tolerance );

/**
* Returns TRUE if layer symbology should be respected when rendering elevation profile plots.
*
Expand Down Expand Up @@ -313,6 +353,8 @@ class CORE_EXPORT QgsVectorLayerElevationProperties : public QgsMapLayerElevatio

bool mEnableExtrusion = false;
double mExtrusionHeight = 0;
bool mEnableCustomTolerance = false;
double mCustomTolerance = 0;

std::unique_ptr< QgsLineSymbol > mProfileLineSymbol;
std::unique_ptr< QgsFillSymbol > mProfileFillSymbol;
Expand Down
Loading