Skip to content
Permalink
Browse files

[FEATURE][layouts] Allow customisation of division and subdivision sy…

…mbol

as distinct symbols vs the scalebar line symbol

Allows for styling division and subdivision symbols in a different
way compared with the horizontal line symbol in a tick scalebar

Sponsored by SLYR
  • Loading branch information
nyalldawson committed May 6, 2020
1 parent 870b5e5 commit 8699f83d98337f9c62ff7ad1e5e2f43eb50b1131
@@ -12,5 +12,7 @@
QgsScaleBarRenderer.Flag.FlagUsesLabelHorizontalPlacement.__doc__ = "Renderer uses the QgsScaleBarSettings::labelHorizontalPlacement() setting"
QgsScaleBarRenderer.Flag.FlagUsesAlignment.__doc__ = "Renderer uses the QgsScaleBarSettings::alignment() setting"
QgsScaleBarRenderer.Flag.FlagUsesSubdivisions.__doc__ = "Renderer uses the scalebar subdivisions"
QgsScaleBarRenderer.Flag.__doc__ = 'Flags which control scalebar renderer behavior.\n\n.. versionadded:: 3.14\n\n' + '* ``FlagUsesLineSymbol``: ' + QgsScaleBarRenderer.Flag.FlagUsesLineSymbol.__doc__ + '\n' + '* ``FlagUsesFillSymbol``: ' + QgsScaleBarRenderer.Flag.FlagUsesFillSymbol.__doc__ + '\n' + '* ``FlagUsesAlternateFillSymbol``: ' + QgsScaleBarRenderer.Flag.FlagUsesAlternateFillSymbol.__doc__ + '\n' + '* ``FlagRespectsUnits``: ' + QgsScaleBarRenderer.Flag.FlagRespectsUnits.__doc__ + '\n' + '* ``FlagRespectsMapUnitsPerScaleBarUnit``: ' + QgsScaleBarRenderer.Flag.FlagRespectsMapUnitsPerScaleBarUnit.__doc__ + '\n' + '* ``FlagUsesUnitLabel``: ' + QgsScaleBarRenderer.Flag.FlagUsesUnitLabel.__doc__ + '\n' + '* ``FlagUsesSegments``: ' + QgsScaleBarRenderer.Flag.FlagUsesSegments.__doc__ + '\n' + '* ``FlagUsesLabelBarSpace``: ' + QgsScaleBarRenderer.Flag.FlagUsesLabelBarSpace.__doc__ + '\n' + '* ``FlagUsesLabelVerticalPlacement``: ' + QgsScaleBarRenderer.Flag.FlagUsesLabelVerticalPlacement.__doc__ + '\n' + '* ``FlagUsesLabelHorizontalPlacement``: ' + QgsScaleBarRenderer.Flag.FlagUsesLabelHorizontalPlacement.__doc__ + '\n' + '* ``FlagUsesAlignment``: ' + QgsScaleBarRenderer.Flag.FlagUsesAlignment.__doc__ + '\n' + '* ``FlagUsesSubdivisions``: ' + QgsScaleBarRenderer.Flag.FlagUsesSubdivisions.__doc__
QgsScaleBarRenderer.Flag.FlagUsesDivisionSymbol.__doc__ = "Renderer utilizes the scalebar division symbol (see QgsScaleBarSettings::divisionLineSymbol() )"
QgsScaleBarRenderer.Flag.FlagUsesSubdivisionSymbol.__doc__ = "Renderer utilizes the scalebar subdivision symbol (see QgsScaleBarSettings::subdivisionLineSymbol() )"
QgsScaleBarRenderer.Flag.__doc__ = 'Flags which control scalebar renderer behavior.\n\n.. versionadded:: 3.14\n\n' + '* ``FlagUsesLineSymbol``: ' + QgsScaleBarRenderer.Flag.FlagUsesLineSymbol.__doc__ + '\n' + '* ``FlagUsesFillSymbol``: ' + QgsScaleBarRenderer.Flag.FlagUsesFillSymbol.__doc__ + '\n' + '* ``FlagUsesAlternateFillSymbol``: ' + QgsScaleBarRenderer.Flag.FlagUsesAlternateFillSymbol.__doc__ + '\n' + '* ``FlagRespectsUnits``: ' + QgsScaleBarRenderer.Flag.FlagRespectsUnits.__doc__ + '\n' + '* ``FlagRespectsMapUnitsPerScaleBarUnit``: ' + QgsScaleBarRenderer.Flag.FlagRespectsMapUnitsPerScaleBarUnit.__doc__ + '\n' + '* ``FlagUsesUnitLabel``: ' + QgsScaleBarRenderer.Flag.FlagUsesUnitLabel.__doc__ + '\n' + '* ``FlagUsesSegments``: ' + QgsScaleBarRenderer.Flag.FlagUsesSegments.__doc__ + '\n' + '* ``FlagUsesLabelBarSpace``: ' + QgsScaleBarRenderer.Flag.FlagUsesLabelBarSpace.__doc__ + '\n' + '* ``FlagUsesLabelVerticalPlacement``: ' + QgsScaleBarRenderer.Flag.FlagUsesLabelVerticalPlacement.__doc__ + '\n' + '* ``FlagUsesLabelHorizontalPlacement``: ' + QgsScaleBarRenderer.Flag.FlagUsesLabelHorizontalPlacement.__doc__ + '\n' + '* ``FlagUsesAlignment``: ' + QgsScaleBarRenderer.Flag.FlagUsesAlignment.__doc__ + '\n' + '* ``FlagUsesSubdivisions``: ' + QgsScaleBarRenderer.Flag.FlagUsesSubdivisions.__doc__ + '\n' + '* ``FlagUsesDivisionSymbol``: ' + QgsScaleBarRenderer.Flag.FlagUsesDivisionSymbol.__doc__ + '\n' + '* ``FlagUsesSubdivisionSymbol``: ' + QgsScaleBarRenderer.Flag.FlagUsesSubdivisionSymbol.__doc__
# --
@@ -256,6 +256,7 @@ Sets the text ``format`` used for drawing text in the scalebar.
.. versionadded:: 3.2
%End


QgsLineSymbol *lineSymbol() const;
%Docstring
Returns the line symbol used to render the scalebar (only used for some scalebar types).
@@ -264,6 +265,10 @@ Ownership is not transferred.

.. seealso:: :py:func:`setLineSymbol`

.. seealso:: :py:func:`divisionLineSymbol`

.. seealso:: :py:func:`subdivisionLineSymbol`

.. versionadded:: 3.14
%End

@@ -274,6 +279,68 @@ transferred to the scalebar.

.. seealso:: :py:func:`lineSymbol`

.. seealso:: :py:func:`setDivisionLineSymbol`

.. seealso:: :py:func:`setSubdivisionLineSymbol`

.. versionadded:: 3.14
%End

QgsLineSymbol *divisionLineSymbol() const;
%Docstring
Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).

Ownership is not transferred.

.. seealso:: :py:func:`setDivisionLineSymbol`

.. seealso:: :py:func:`lineSymbol`

.. seealso:: :py:func:`subdivisionLineSymbol`

.. versionadded:: 3.14
%End

void setDivisionLineSymbol( QgsLineSymbol *symbol /Transfer/ );
%Docstring
Sets the line ``symbol`` used to render the scalebar divisions (only used for some scalebar types). Ownership of ``symbol`` is
transferred to the scalebar.

.. seealso:: :py:func:`divisionLineSymbol`

.. seealso:: :py:func:`setLineSymbol`

.. seealso:: :py:func:`setSubdivisionLineSymbol`

.. versionadded:: 3.14
%End

QgsLineSymbol *subdivisionLineSymbol() const;
%Docstring
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).

Ownership is not transferred.

.. seealso:: :py:func:`setSubdivisionLineSymbol`

.. seealso:: :py:func:`lineSymbol`

.. seealso:: :py:func:`divisionLineSymbol`

.. versionadded:: 3.14
%End

void setSubdivisionLineSymbol( QgsLineSymbol *symbol /Transfer/ );
%Docstring
Sets the line ``symbol`` used to render the scalebar subdivisions (only used for some scalebar types). Ownership of ``symbol`` is
transferred to the scalebar.

.. seealso:: :py:func:`subdivisionLineSymbol`

.. seealso:: :py:func:`setLineSymbol`

.. seealso:: :py:func:`setDivisionLineSymbol`

.. versionadded:: 3.14
%End

@@ -50,6 +50,8 @@ custom labeling.
FlagUsesLabelHorizontalPlacement,
FlagUsesAlignment,
FlagUsesSubdivisions,
FlagUsesDivisionSymbol,
FlagUsesSubdivisionSymbol,
};
typedef QFlags<QgsScaleBarRenderer::Flag> Flags;

@@ -454,6 +454,10 @@ Ownership is not transferred.

.. seealso:: :py:func:`setLineSymbol`

.. seealso:: :py:func:`divisionLineSymbol`

.. seealso:: :py:func:`subdivisionLineSymbol`

.. versionadded:: 3.14
%End

@@ -464,6 +468,68 @@ transferred to the scalebar.

.. seealso:: :py:func:`lineSymbol`

.. seealso:: :py:func:`setDivisionLineSymbol`

.. seealso:: :py:func:`setSubdivisionLineSymbol`

.. versionadded:: 3.14
%End

QgsLineSymbol *divisionLineSymbol() const;
%Docstring
Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).

Ownership is not transferred.

.. seealso:: :py:func:`setDivisionLineSymbol`

.. seealso:: :py:func:`lineSymbol`

.. seealso:: :py:func:`subdivisionLineSymbol`

.. versionadded:: 3.14
%End

void setDivisionLineSymbol( QgsLineSymbol *symbol /Transfer/ );
%Docstring
Sets the line ``symbol`` used to render the scalebar divisions (only used for some scalebar types). Ownership of ``symbol`` is
transferred to the scalebar.

.. seealso:: :py:func:`divisionLineSymbol`

.. seealso:: :py:func:`setLineSymbol`

.. seealso:: :py:func:`setSubdivisionLineSymbol`

.. versionadded:: 3.14
%End

QgsLineSymbol *subdivisionLineSymbol() const;
%Docstring
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).

Ownership is not transferred.

.. seealso:: :py:func:`setSubdivisionLineSymbol`

.. seealso:: :py:func:`lineSymbol`

.. seealso:: :py:func:`divisionLineSymbol`

.. versionadded:: 3.14
%End

void setSubdivisionLineSymbol( QgsLineSymbol *symbol /Transfer/ );
%Docstring
Sets the line ``symbol`` used to render the scalebar subdivisions (only used for some scalebar types). Ownership of ``symbol`` is
transferred to the scalebar.

.. seealso:: :py:func:`subdivisionLineSymbol`

.. seealso:: :py:func:`setLineSymbol`

.. seealso:: :py:func:`setDivisionLineSymbol`

.. versionadded:: 3.14
%End

@@ -1118,6 +1118,8 @@ bool QgsCompositionConverter::readScaleBarXml( QgsLayoutItemScaleBar *layoutItem
lineSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral( "penColor" ), QStringLiteral( "#000000" ) ) ) );
}
lineSymbol->changeSymbolLayer( 0, lineSymbolLayer.release() );
layoutItem->setDivisionLineSymbol( lineSymbol->clone() );
layoutItem->setSubdivisionLineSymbol( lineSymbol->clone() );
layoutItem->setLineSymbol( lineSymbol.release() );

//font color
@@ -194,6 +194,26 @@ void QgsLayoutItemScaleBar::setLineSymbol( QgsLineSymbol *symbol )
mSettings.setLineSymbol( symbol );
}

QgsLineSymbol *QgsLayoutItemScaleBar::divisionLineSymbol() const
{
return mSettings.divisionLineSymbol();
}

void QgsLayoutItemScaleBar::setDivisionLineSymbol( QgsLineSymbol *symbol )
{
mSettings.setDivisionLineSymbol( symbol );
}

QgsLineSymbol *QgsLayoutItemScaleBar::subdivisionLineSymbol() const
{
return mSettings.subdivisionLineSymbol();
}

void QgsLayoutItemScaleBar::setSubdivisionLineSymbol( QgsLineSymbol *symbol )
{
mSettings.setSubdivisionLineSymbol( symbol );
}

QgsFillSymbol *QgsLayoutItemScaleBar::fillSymbol() const
{
return mSettings.fillSymbol();
@@ -813,6 +833,22 @@ bool QgsLayoutItemScaleBar::writePropertiesToElement( QDomElement &composerScale
lineSymbol.appendChild( symbolElem );
composerScaleBarElem.appendChild( lineSymbol );

QDomElement divisionSymbol = doc.createElement( QStringLiteral( "divisionLineSymbol" ) );
const QDomElement divisionSymbolElem = QgsSymbolLayerUtils::saveSymbol( QString(),
mSettings.divisionLineSymbol(),
doc,
rwContext );
divisionSymbol.appendChild( divisionSymbolElem );
composerScaleBarElem.appendChild( divisionSymbol );

QDomElement subdivisionSymbol = doc.createElement( QStringLiteral( "subdivisionLineSymbol" ) );
const QDomElement subdivisionSymbolElem = QgsSymbolLayerUtils::saveSymbol( QString(),
mSettings.subdivisionLineSymbol(),
doc,
rwContext );
subdivisionSymbol.appendChild( subdivisionSymbolElem );
composerScaleBarElem.appendChild( subdivisionSymbol );

QDomElement fillSymbol1Elem = doc.createElement( QStringLiteral( "fillSymbol1" ) );
const QDomElement symbol1Elem = QgsSymbolLayerUtils::saveSymbol( QString(),
mSettings.fillSymbol(),
@@ -860,6 +896,35 @@ bool QgsLayoutItemScaleBar::readPropertiesFromElement( const QDomElement &itemEl
foundLineSymbol = true;
}
}
QDomElement divisionSymbolElem = itemElem.firstChildElement( QStringLiteral( "divisionLineSymbol" ) );
if ( !divisionSymbolElem.isNull() )
{
QDomElement symbolElem = divisionSymbolElem.firstChildElement( QStringLiteral( "symbol" ) );
std::unique_ptr< QgsLineSymbol > lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
if ( lineSymbol )
{
mSettings.setDivisionLineSymbol( lineSymbol.release() );
}
}
else if ( foundLineSymbol )
{
mSettings.setDivisionLineSymbol( mSettings.lineSymbol()->clone() );
}
QDomElement subdivisionSymbolElem = itemElem.firstChildElement( QStringLiteral( "subdivisionLineSymbol" ) );
if ( !subdivisionSymbolElem.isNull() )
{
QDomElement symbolElem = subdivisionSymbolElem.firstChildElement( QStringLiteral( "symbol" ) );
std::unique_ptr< QgsLineSymbol > lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
if ( lineSymbol )
{
mSettings.setSubdivisionLineSymbol( lineSymbol.release() );
}
}
else if ( foundLineSymbol )
{
mSettings.setSubdivisionLineSymbol( mSettings.lineSymbol()->clone() );
}

if ( !foundLineSymbol )
{
// old project compatibility
@@ -901,7 +966,9 @@ bool QgsLayoutItemScaleBar::readPropertiesFromElement( const QDomElement &itemEl
dataDefinedProperties().setProperty( QgsLayoutObject::ScalebarLineColor, QgsProperty() );

lineSymbol->changeSymbolLayer( 0, lineSymbolLayer.release() );
mSettings.setLineSymbol( lineSymbol.release() );
mSettings.setLineSymbol( lineSymbol->clone() );
mSettings.setDivisionLineSymbol( lineSymbol->clone() );
mSettings.setSubdivisionLineSymbol( lineSymbol.release() );
}

mSettings.setUnitLabel( itemElem.attribute( QStringLiteral( "unitLabel" ) ) );
@@ -224,12 +224,15 @@ class CORE_EXPORT QgsLayoutItemScaleBar: public QgsLayoutItem
*/
void setTextFormat( const QgsTextFormat &format );


/**
* Returns the line symbol used to render the scalebar (only used for some scalebar types).
*
* Ownership is not transferred.
*
* \see setLineSymbol()
* \see divisionLineSymbol()
* \see subdivisionLineSymbol()
* \since QGIS 3.14
*/
QgsLineSymbol *lineSymbol() const;
@@ -239,10 +242,58 @@ class CORE_EXPORT QgsLayoutItemScaleBar: public QgsLayoutItem
* transferred to the scalebar.
*
* \see lineSymbol()
* \see setDivisionLineSymbol()
* \see setSubdivisionLineSymbol()
* \since QGIS 3.14
*/
void setLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );

/**
* Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).
*
* Ownership is not transferred.
*
* \see setDivisionLineSymbol()
* \see lineSymbol()
* \see subdivisionLineSymbol()
* \since QGIS 3.14
*/
QgsLineSymbol *divisionLineSymbol() const;

/**
* Sets the line \a symbol used to render the scalebar divisions (only used for some scalebar types). Ownership of \a symbol is
* transferred to the scalebar.
*
* \see divisionLineSymbol()
* \see setLineSymbol()
* \see setSubdivisionLineSymbol()
* \since QGIS 3.14
*/
void setDivisionLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );

/**
* Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
*
* Ownership is not transferred.
*
* \see setSubdivisionLineSymbol()
* \see lineSymbol()
* \see divisionLineSymbol()
* \since QGIS 3.14
*/
QgsLineSymbol *subdivisionLineSymbol() const;

/**
* Sets the line \a symbol used to render the scalebar subdivisions (only used for some scalebar types). Ownership of \a symbol is
* transferred to the scalebar.
*
* \see subdivisionLineSymbol()
* \see setLineSymbol()
* \see setDivisionLineSymbol()
* \since QGIS 3.14
*/
void setSubdivisionLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );

/**
* Returns the primary fill symbol used to render the scalebar (only used for some scalebar types).
*
@@ -82,6 +82,8 @@ class CORE_EXPORT QgsScaleBarRenderer
FlagUsesLabelHorizontalPlacement = 1 << 8, //!< Renderer uses the QgsScaleBarSettings::labelHorizontalPlacement() setting
FlagUsesAlignment = 1 << 9, //!< Renderer uses the QgsScaleBarSettings::alignment() setting
FlagUsesSubdivisions = 1 << 10, //!< Renderer uses the scalebar subdivisions
FlagUsesDivisionSymbol = 1 << 11, //!< Renderer utilizes the scalebar division symbol (see QgsScaleBarSettings::divisionLineSymbol() )
FlagUsesSubdivisionSymbol = 1 << 12, //!< Renderer utilizes the scalebar subdivision symbol (see QgsScaleBarSettings::subdivisionLineSymbol() )
};
Q_DECLARE_FLAGS( Flags, Flag )

0 comments on commit 8699f83

Please sign in to comment.
You can’t perform that action at this time.