Skip to content

Commit

Permalink
Move label overrun settings to QgsLabelLineSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 17, 2020
1 parent b31d315 commit 844e9a3
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 66 deletions.
66 changes: 66 additions & 0 deletions python/core/auto_generated/labeling/qgslabellinesettings.sip.in
Expand Up @@ -182,6 +182,72 @@ This setting controls whether to place direction symbols to the left/right, abov
.. seealso:: :py:func:`directionSymbolPlacement`

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

double overrunDistance() const;
%Docstring
Returns the distance which labels are allowed to overrun past the start or end of line features.

.. seealso:: :py:func:`setOverrunDistance`

.. seealso:: :py:func:`overrunDistanceUnit`

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

void setOverrunDistance( double distance );
%Docstring
Sets the ``distance`` which labels are allowed to overrun past the start or end of line features.

.. seealso:: :py:func:`overrunDistance`

.. seealso:: :py:func:`overrunDistanceUnit`

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

QgsUnitTypes::RenderUnit overrunDistanceUnit() const;
%Docstring
Returns the units for label overrun distance.

.. seealso:: :py:func:`setOverrunDistanceUnit`

.. seealso:: :py:func:`overrunDistance`

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

void setOverrunDistanceUnit( const QgsUnitTypes::RenderUnit &unit );
%Docstring
Sets the ``unit`` for label overrun distance.

.. seealso:: :py:func:`overrunDistanceUnit`

.. seealso:: :py:func:`overrunDistance`

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

QgsMapUnitScale overrunDistanceMapUnitScale() const;
%Docstring
Returns the map unit scale for label overrun distance.

.. seealso:: :py:func:`setOverrunDistanceMapUnitScale`

.. seealso:: :py:func:`overrunDistance`

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

void setOverrunDistanceMapUnitScale( const QgsMapUnitScale &scale );
%Docstring
Sets the map unit ``scale`` for label overrun distance.

.. seealso:: :py:func:`overrunDistanceMapUnitScale`

.. seealso:: :py:func:`overrunDistance`

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

};
Expand Down
17 changes: 10 additions & 7 deletions python/core/auto_generated/labeling/qgspallabeling.sip.in
Expand Up @@ -433,12 +433,6 @@ Sets the polygon placement ``flags``, which dictate how polygon labels can be pl

QgsMapUnitScale repeatDistanceMapUnitScale;

double overrunDistance;

QgsUnitTypes::RenderUnit overrunDistanceUnit;

QgsMapUnitScale overrunDistanceMapUnitScale;

QuadrantPosition quadOffset;

double xOffset;
Expand Down Expand Up @@ -487,13 +481,16 @@ Sets the polygon placement ``flags``, which dictate how polygon labels can be pl
%Property( name = obstacleType, get = _getObstacleType, set = _setObstacleType )
%Property( name = placementFlags, get = _getLinePlacementFlags, set = _setLinePlacementFlags )
%Property( name = mergeLines, get = _getMergeLines, set = _setMergeLines )

%Property( name = addDirectionSymbol, get = _getAddDirectionSymbol, set = _setAddDirectionSymbol )
%Property( name = leftDirectionSymbol, get = _getLeftDirectionSymbol, set = _setLeftDirectionSymbol )
%Property( name = rightDirectionSymbol, get = _getRightDirectionSymbol, set = _setRightDirectionSymbol )
%Property( name = reverseDirectionSymbol, get = _getReverseDirectionSymbol, set = _setReverseDirectionSymbol )
%Property( name = placeDirectionSymbol, get = _getPlaceDirectionSymbol, set = _setPlaceDirectionSymbol )

%Property( name = overrunDistance, get = _getOverrunDistance, set = _setOverrunDistance )
%Property( name = overrunDistanceUnit, get = _getOverrunDistanceUnit, set = _setOverrunDistanceUnit )
%Property( name = overrunDistanceMapUnitScale, get = _getOverrunDistanceMapUnitScale, set = _setOverrunDistanceMapUnitScale )

bool _limitNumLabels() const;
void _setLimitNumLabels( bool limit );
int _maxNumLabels() const;
Expand All @@ -520,6 +517,12 @@ Sets the polygon placement ``flags``, which dictate how polygon labels can be pl
void _setReverseDirectionSymbol( bool reverse );
DirectionSymbols _getPlaceDirectionSymbol() const;
void _setPlaceDirectionSymbol( DirectionSymbols placement );
double _getOverrunDistance() const;
void _setOverrunDistance( double distance );
QgsUnitTypes::RenderUnit _getOverrunDistanceUnit() const;
void _setOverrunDistanceUnit( QgsUnitTypes::RenderUnit unit );
QgsMapUnitScale _getOverrunDistanceMapUnitScale() const;
void _setOverrunDistanceMapUnitScale( const QgsMapUnitScale &scale );

double zIndex;

Expand Down
10 changes: 6 additions & 4 deletions src/core/labeling/qgslabellinesettings.cpp
Expand Up @@ -31,8 +31,10 @@ void QgsLabelLineSettings::updateDataDefinedProperties( const QgsPropertyCollect
mPlacementFlags = QgsLabelingUtils::decodeLinePlacementFlags( dataDefinedLineArrangement );
}
}
}




if ( properties.isActive( QgsPalLayerSettings::OverrunDistance ) )
{
context.setOriginalValueVariable( mOverrunDistance );
mOverrunDistance = properties.valueAsDouble( QgsPalLayerSettings::OverrunDistance, context, mOverrunDistance );
}
}
53 changes: 53 additions & 0 deletions src/core/labeling/qgslabellinesettings.h
Expand Up @@ -19,6 +19,8 @@
#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgslabeling.h"
#include "qgsunittypes.h"
#include "qgsmapunitscale.h"
#include <QString>

class QgsPropertyCollection;
Expand Down Expand Up @@ -182,6 +184,54 @@ class CORE_EXPORT QgsLabelLineSettings
*/
void setDirectionSymbolPlacement( DirectionSymbolPlacement placement ) { mPlaceDirectionSymbol = placement; }

/**
* Returns the distance which labels are allowed to overrun past the start or end of line features.
* \see setOverrunDistance()
* \see overrunDistanceUnit()
* \see overrunDistanceMapUnitScale()
*/
double overrunDistance() const { return mOverrunDistance; }

/**
* Sets the \a distance which labels are allowed to overrun past the start or end of line features.
* \see overrunDistance()
* \see overrunDistanceUnit()
* \see overrunDistanceMapUnitScale()
*/
void setOverrunDistance( double distance ) { mOverrunDistance = distance; }

/**
* Returns the units for label overrun distance.
* \see setOverrunDistanceUnit()
* \see overrunDistance()
* \see overrunDistanceMapUnitScale()
*/
QgsUnitTypes::RenderUnit overrunDistanceUnit() const {return mOverrunDistanceUnit; }

/**
* Sets the \a unit for label overrun distance.
* \see overrunDistanceUnit()
* \see overrunDistance()
* \see overrunDistanceMapUnitScale()
*/
void setOverrunDistanceUnit( const QgsUnitTypes::RenderUnit &unit ) { mOverrunDistanceUnit = unit;}

/**
* Returns the map unit scale for label overrun distance.
* \see setOverrunDistanceMapUnitScale()
* \see overrunDistance()
* \see overrunDistanceUnit()
*/
QgsMapUnitScale overrunDistanceMapUnitScale() const { return mOverrunDistanceMapUnitScale; }

/**
* Sets the map unit \a scale for label overrun distance.
* \see overrunDistanceMapUnitScale()
* \see overrunDistance()
* \see overrunDistanceUnit()
*/
void setOverrunDistanceMapUnitScale( const QgsMapUnitScale &scale ) { mOverrunDistanceMapUnitScale = scale; }

private:
QgsLabeling::LinePlacementFlags mPlacementFlags = QgsLabeling::LinePlacementFlag::AboveLine | QgsLabeling::LinePlacementFlag::MapOrientation;
bool mMergeLines = false;
Expand All @@ -190,6 +240,9 @@ class CORE_EXPORT QgsLabelLineSettings
QString mRightDirectionSymbol = QString( '>' );
bool mReverseDirectionSymbol = false;
DirectionSymbolPlacement mPlaceDirectionSymbol = DirectionSymbolPlacement::SymbolLeftRight;
double mOverrunDistance = 0;
QgsUnitTypes::RenderUnit mOverrunDistanceUnit = QgsUnitTypes::RenderMillimeters;
QgsMapUnitScale mOverrunDistanceMapUnitScale;
};

#endif // QGSLABELLINESETTINGS_H
26 changes: 9 additions & 17 deletions src/core/labeling/qgspallabeling.cpp
Expand Up @@ -326,9 +326,6 @@ QgsPalLayerSettings &QgsPalLayerSettings::operator=( const QgsPalLayerSettings &
repeatDistance = s.repeatDistance;
repeatDistanceUnit = s.repeatDistanceUnit;
repeatDistanceMapUnitScale = s.repeatDistanceMapUnitScale;
overrunDistance = s.overrunDistance;
overrunDistanceUnit = s.overrunDistanceUnit;
overrunDistanceMapUnitScale = s.overrunDistanceMapUnitScale;

// rendering
scaleVisibility = s.scaleVisibility;
Expand Down Expand Up @@ -1042,9 +1039,9 @@ void QgsPalLayerSettings::readXml( const QDomElement &elem, const QgsReadWriteCo
repeatDistanceMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( placementElem.attribute( QStringLiteral( "repeatDistanceMapUnitScale" ) ) );
}

overrunDistance = placementElem.attribute( QStringLiteral( "overrunDistance" ), QStringLiteral( "0" ) ).toDouble();
overrunDistanceUnit = QgsUnitTypes::decodeRenderUnit( placementElem.attribute( QStringLiteral( "overrunDistanceUnit" ) ) );
overrunDistanceMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( placementElem.attribute( QStringLiteral( "overrunDistanceMapUnitScale" ) ) );
mLineSettings.setOverrunDistance( placementElem.attribute( QStringLiteral( "overrunDistance" ), QStringLiteral( "0" ) ).toDouble() );
mLineSettings.setOverrunDistanceUnit( QgsUnitTypes::decodeRenderUnit( placementElem.attribute( QStringLiteral( "overrunDistanceUnit" ) ) ) );
mLineSettings.setOverrunDistanceMapUnitScale( QgsSymbolLayerUtils::decodeMapUnitScale( placementElem.attribute( QStringLiteral( "overrunDistanceMapUnitScale" ) ) ) );

geometryGenerator = placementElem.attribute( QStringLiteral( "geometryGenerator" ) );
geometryGeneratorEnabled = placementElem.attribute( QStringLiteral( "geometryGeneratorEnabled" ) ).toInt();
Expand Down Expand Up @@ -1192,9 +1189,9 @@ QDomElement QgsPalLayerSettings::writeXml( QDomDocument &doc, const QgsReadWrite
placementElem.setAttribute( QStringLiteral( "repeatDistance" ), repeatDistance );
placementElem.setAttribute( QStringLiteral( "repeatDistanceUnits" ), QgsUnitTypes::encodeUnit( repeatDistanceUnit ) );
placementElem.setAttribute( QStringLiteral( "repeatDistanceMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( repeatDistanceMapUnitScale ) );
placementElem.setAttribute( QStringLiteral( "overrunDistance" ), overrunDistance );
placementElem.setAttribute( QStringLiteral( "overrunDistanceUnit" ), QgsUnitTypes::encodeUnit( overrunDistanceUnit ) );
placementElem.setAttribute( QStringLiteral( "overrunDistanceMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( overrunDistanceMapUnitScale ) );
placementElem.setAttribute( QStringLiteral( "overrunDistance" ), mLineSettings.overrunDistance() );
placementElem.setAttribute( QStringLiteral( "overrunDistanceUnit" ), QgsUnitTypes::encodeUnit( mLineSettings.overrunDistanceUnit() ) );
placementElem.setAttribute( QStringLiteral( "overrunDistanceMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( mLineSettings.overrunDistanceMapUnitScale() ) );

placementElem.setAttribute( QStringLiteral( "geometryGenerator" ), geometryGenerator );
placementElem.setAttribute( QStringLiteral( "geometryGeneratorEnabled" ), geometryGeneratorEnabled );
Expand Down Expand Up @@ -2423,16 +2420,11 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
}
}

// data defined overrun distance
double overrunDistanceEval = overrunDistance;
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::OverrunDistance ) )
{
context.expressionContext().setOriginalValueVariable( overrunDistanceEval );
overrunDistanceEval = mDataDefinedProperties.valueAsDouble( QgsPalLayerSettings::OverrunDistance, context.expressionContext(), overrunDistanceEval );
}
// overrun distance
double overrunDistanceEval = lineSettings.overrunDistance();
if ( !qgsDoubleNear( overrunDistanceEval, 0.0 ) )
{
overrunDistanceEval = context.convertToMapUnits( overrunDistanceEval, overrunDistanceUnit, overrunDistanceMapUnitScale );
overrunDistanceEval = context.convertToMapUnits( overrunDistanceEval, lineSettings.overrunDistanceUnit(), lineSettings.overrunDistanceMapUnitScale() );
}

// we smooth out the overrun label extensions by 1 mm, to avoid little jaggies right at the start or end of the lines
Expand Down
35 changes: 10 additions & 25 deletions src/core/labeling/qgspallabeling.h
Expand Up @@ -703,30 +703,6 @@ class CORE_EXPORT QgsPalLayerSettings
*/
QgsMapUnitScale repeatDistanceMapUnitScale;

/**
* Distance which labels are allowed to overrun past the start or end of line features.
* \see overrunDistanceUnit
* \see repeatDistanceMapUnitScale
* \since QGIS 3.10
*/
double overrunDistance = 0;

/**
* Units for label overrun distance.
* \see overrunDistance
* \see overrunDistanceMapUnitScale
* \since QGIS 3.10
*/
QgsUnitTypes::RenderUnit overrunDistanceUnit = QgsUnitTypes::RenderMillimeters;

/**
* Map unit scale for label overrun distance.
* \see overrunDistance
* \see overrunDistanceUnit
* \since QGIS 3.10
*/
QgsMapUnitScale overrunDistanceMapUnitScale;

/**
* Sets the quadrant in which to offset labels from feature.
*/
Expand Down Expand Up @@ -865,12 +841,15 @@ class CORE_EXPORT QgsPalLayerSettings
SIP_PROPERTY( name = obstacleType, get = _getObstacleType, set = _setObstacleType )
SIP_PROPERTY( name = placementFlags, get = _getLinePlacementFlags, set = _setLinePlacementFlags )
SIP_PROPERTY( name = mergeLines, get = _getMergeLines, set = _setMergeLines )

SIP_PROPERTY( name = addDirectionSymbol, get = _getAddDirectionSymbol, set = _setAddDirectionSymbol )
SIP_PROPERTY( name = leftDirectionSymbol, get = _getLeftDirectionSymbol, set = _setLeftDirectionSymbol )
SIP_PROPERTY( name = rightDirectionSymbol, get = _getRightDirectionSymbol, set = _setRightDirectionSymbol )
SIP_PROPERTY( name = reverseDirectionSymbol, get = _getReverseDirectionSymbol, set = _setReverseDirectionSymbol )
SIP_PROPERTY( name = placeDirectionSymbol, get = _getPlaceDirectionSymbol, set = _setPlaceDirectionSymbol )

SIP_PROPERTY( name = overrunDistance, get = _getOverrunDistance, set = _setOverrunDistance )
SIP_PROPERTY( name = overrunDistanceUnit, get = _getOverrunDistanceUnit, set = _setOverrunDistanceUnit )
SIP_PROPERTY( name = overrunDistanceMapUnitScale, get = _getOverrunDistanceMapUnitScale, set = _setOverrunDistanceMapUnitScale )
#endif

///@cond PRIVATE
Expand Down Expand Up @@ -902,6 +881,12 @@ class CORE_EXPORT QgsPalLayerSettings
DirectionSymbols _getPlaceDirectionSymbol() const { return static_cast< DirectionSymbols>( mLineSettings.directionSymbolPlacement() ); }
void _setPlaceDirectionSymbol( DirectionSymbols placement ) { mLineSettings.setDirectionSymbolPlacement( static_cast< QgsLabelLineSettings::DirectionSymbolPlacement>( placement ) ); }
Q_NOWARN_DEPRECATED_POP
double _getOverrunDistance() const { return mLineSettings.overrunDistance(); }
void _setOverrunDistance( double distance ) { mLineSettings.setOverrunDistance( distance ); }
QgsUnitTypes::RenderUnit _getOverrunDistanceUnit() const { return mLineSettings.overrunDistanceUnit(); }
void _setOverrunDistanceUnit( QgsUnitTypes::RenderUnit unit ) { mLineSettings.setOverrunDistanceUnit( unit ); }
QgsMapUnitScale _getOverrunDistanceMapUnitScale() const { return mLineSettings.overrunDistanceMapUnitScale(); }
void _setOverrunDistanceMapUnitScale( const QgsMapUnitScale &scale ) { mLineSettings.setOverrunDistanceMapUnitScale( scale ); }
///@endcond

//! Z-Index of label, where labels with a higher z-index are rendered on top of labels with a lower z-index
Expand Down
12 changes: 6 additions & 6 deletions src/gui/labeling/qgslabelinggui.cpp
Expand Up @@ -345,9 +345,9 @@ void QgsLabelingGui::setLayer( QgsMapLayer *mapLayer )
mRepeatDistanceUnitWidget->setUnit( mSettings.repeatDistanceUnit );
mRepeatDistanceUnitWidget->setMapUnitScale( mSettings.repeatDistanceMapUnitScale );

mOverrunDistanceSpinBox->setValue( mSettings.overrunDistance );
mOverrunDistanceUnitWidget->setUnit( mSettings.overrunDistanceUnit );
mOverrunDistanceUnitWidget->setMapUnitScale( mSettings.overrunDistanceMapUnitScale );
mOverrunDistanceSpinBox->setValue( mSettings.lineSettings().overrunDistance() );
mOverrunDistanceUnitWidget->setUnit( mSettings.lineSettings().overrunDistanceUnit() );
mOverrunDistanceUnitWidget->setMapUnitScale( mSettings.lineSettings().overrunDistanceMapUnitScale() );

mPrioritySlider->setValue( mSettings.priority );
mChkNoObstacle->setChecked( mSettings.obstacleSettings().isObstacle() );
Expand Down Expand Up @@ -557,9 +557,9 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.repeatDistanceUnit = mRepeatDistanceUnitWidget->unit();
lyr.repeatDistanceMapUnitScale = mRepeatDistanceUnitWidget->getMapUnitScale();

lyr.overrunDistance = mOverrunDistanceSpinBox->value();
lyr.overrunDistanceUnit = mOverrunDistanceUnitWidget->unit();
lyr.overrunDistanceMapUnitScale = mOverrunDistanceUnitWidget->getMapUnitScale();
lyr.lineSettings().setOverrunDistance( mOverrunDistanceSpinBox->value() );
lyr.lineSettings().setOverrunDistanceUnit( mOverrunDistanceUnitWidget->unit() );
lyr.lineSettings().setOverrunDistanceMapUnitScale( mOverrunDistanceUnitWidget->getMapUnitScale() );

lyr.priority = mPrioritySlider->value();

Expand Down

0 comments on commit 844e9a3

Please sign in to comment.