Skip to content

Commit 8699f83

Browse files
committedMay 7, 2020
[FEATURE][layouts] Allow customisation of division and subdivision symbol
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
1 parent 870b5e5 commit 8699f83

18 files changed

+566
-85
lines changed
 

‎python/core/auto_additions/qgsscalebarrenderer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
QgsScaleBarRenderer.Flag.FlagUsesLabelHorizontalPlacement.__doc__ = "Renderer uses the QgsScaleBarSettings::labelHorizontalPlacement() setting"
1313
QgsScaleBarRenderer.Flag.FlagUsesAlignment.__doc__ = "Renderer uses the QgsScaleBarSettings::alignment() setting"
1414
QgsScaleBarRenderer.Flag.FlagUsesSubdivisions.__doc__ = "Renderer uses the scalebar subdivisions"
15-
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__
15+
QgsScaleBarRenderer.Flag.FlagUsesDivisionSymbol.__doc__ = "Renderer utilizes the scalebar division symbol (see QgsScaleBarSettings::divisionLineSymbol() )"
16+
QgsScaleBarRenderer.Flag.FlagUsesSubdivisionSymbol.__doc__ = "Renderer utilizes the scalebar subdivision symbol (see QgsScaleBarSettings::subdivisionLineSymbol() )"
17+
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__
1618
# --

‎python/core/auto_generated/layout/qgslayoutitemscalebar.sip.in

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ Sets the text ``format`` used for drawing text in the scalebar.
256256
.. versionadded:: 3.2
257257
%End
258258

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

265266
.. seealso:: :py:func:`setLineSymbol`
266267

268+
.. seealso:: :py:func:`divisionLineSymbol`
269+
270+
.. seealso:: :py:func:`subdivisionLineSymbol`
271+
267272
.. versionadded:: 3.14
268273
%End
269274

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

275280
.. seealso:: :py:func:`lineSymbol`
276281

282+
.. seealso:: :py:func:`setDivisionLineSymbol`
283+
284+
.. seealso:: :py:func:`setSubdivisionLineSymbol`
285+
286+
.. versionadded:: 3.14
287+
%End
288+
289+
QgsLineSymbol *divisionLineSymbol() const;
290+
%Docstring
291+
Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).
292+
293+
Ownership is not transferred.
294+
295+
.. seealso:: :py:func:`setDivisionLineSymbol`
296+
297+
.. seealso:: :py:func:`lineSymbol`
298+
299+
.. seealso:: :py:func:`subdivisionLineSymbol`
300+
301+
.. versionadded:: 3.14
302+
%End
303+
304+
void setDivisionLineSymbol( QgsLineSymbol *symbol /Transfer/ );
305+
%Docstring
306+
Sets the line ``symbol`` used to render the scalebar divisions (only used for some scalebar types). Ownership of ``symbol`` is
307+
transferred to the scalebar.
308+
309+
.. seealso:: :py:func:`divisionLineSymbol`
310+
311+
.. seealso:: :py:func:`setLineSymbol`
312+
313+
.. seealso:: :py:func:`setSubdivisionLineSymbol`
314+
315+
.. versionadded:: 3.14
316+
%End
317+
318+
QgsLineSymbol *subdivisionLineSymbol() const;
319+
%Docstring
320+
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
321+
322+
Ownership is not transferred.
323+
324+
.. seealso:: :py:func:`setSubdivisionLineSymbol`
325+
326+
.. seealso:: :py:func:`lineSymbol`
327+
328+
.. seealso:: :py:func:`divisionLineSymbol`
329+
330+
.. versionadded:: 3.14
331+
%End
332+
333+
void setSubdivisionLineSymbol( QgsLineSymbol *symbol /Transfer/ );
334+
%Docstring
335+
Sets the line ``symbol`` used to render the scalebar subdivisions (only used for some scalebar types). Ownership of ``symbol`` is
336+
transferred to the scalebar.
337+
338+
.. seealso:: :py:func:`subdivisionLineSymbol`
339+
340+
.. seealso:: :py:func:`setLineSymbol`
341+
342+
.. seealso:: :py:func:`setDivisionLineSymbol`
343+
277344
.. versionadded:: 3.14
278345
%End
279346

‎python/core/auto_generated/scalebar/qgsscalebarrenderer.sip.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ custom labeling.
5050
FlagUsesLabelHorizontalPlacement,
5151
FlagUsesAlignment,
5252
FlagUsesSubdivisions,
53+
FlagUsesDivisionSymbol,
54+
FlagUsesSubdivisionSymbol,
5355
};
5456
typedef QFlags<QgsScaleBarRenderer::Flag> Flags;
5557

‎python/core/auto_generated/scalebar/qgsscalebarsettings.sip.in

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ Ownership is not transferred.
454454

455455
.. seealso:: :py:func:`setLineSymbol`
456456

457+
.. seealso:: :py:func:`divisionLineSymbol`
458+
459+
.. seealso:: :py:func:`subdivisionLineSymbol`
460+
457461
.. versionadded:: 3.14
458462
%End
459463

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

465469
.. seealso:: :py:func:`lineSymbol`
466470

471+
.. seealso:: :py:func:`setDivisionLineSymbol`
472+
473+
.. seealso:: :py:func:`setSubdivisionLineSymbol`
474+
475+
.. versionadded:: 3.14
476+
%End
477+
478+
QgsLineSymbol *divisionLineSymbol() const;
479+
%Docstring
480+
Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).
481+
482+
Ownership is not transferred.
483+
484+
.. seealso:: :py:func:`setDivisionLineSymbol`
485+
486+
.. seealso:: :py:func:`lineSymbol`
487+
488+
.. seealso:: :py:func:`subdivisionLineSymbol`
489+
490+
.. versionadded:: 3.14
491+
%End
492+
493+
void setDivisionLineSymbol( QgsLineSymbol *symbol /Transfer/ );
494+
%Docstring
495+
Sets the line ``symbol`` used to render the scalebar divisions (only used for some scalebar types). Ownership of ``symbol`` is
496+
transferred to the scalebar.
497+
498+
.. seealso:: :py:func:`divisionLineSymbol`
499+
500+
.. seealso:: :py:func:`setLineSymbol`
501+
502+
.. seealso:: :py:func:`setSubdivisionLineSymbol`
503+
504+
.. versionadded:: 3.14
505+
%End
506+
507+
QgsLineSymbol *subdivisionLineSymbol() const;
508+
%Docstring
509+
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
510+
511+
Ownership is not transferred.
512+
513+
.. seealso:: :py:func:`setSubdivisionLineSymbol`
514+
515+
.. seealso:: :py:func:`lineSymbol`
516+
517+
.. seealso:: :py:func:`divisionLineSymbol`
518+
519+
.. versionadded:: 3.14
520+
%End
521+
522+
void setSubdivisionLineSymbol( QgsLineSymbol *symbol /Transfer/ );
523+
%Docstring
524+
Sets the line ``symbol`` used to render the scalebar subdivisions (only used for some scalebar types). Ownership of ``symbol`` is
525+
transferred to the scalebar.
526+
527+
.. seealso:: :py:func:`subdivisionLineSymbol`
528+
529+
.. seealso:: :py:func:`setLineSymbol`
530+
531+
.. seealso:: :py:func:`setDivisionLineSymbol`
532+
467533
.. versionadded:: 3.14
468534
%End
469535

‎src/core/layout/qgscompositionconverter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,8 @@ bool QgsCompositionConverter::readScaleBarXml( QgsLayoutItemScaleBar *layoutItem
11181118
lineSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral( "penColor" ), QStringLiteral( "#000000" ) ) ) );
11191119
}
11201120
lineSymbol->changeSymbolLayer( 0, lineSymbolLayer.release() );
1121+
layoutItem->setDivisionLineSymbol( lineSymbol->clone() );
1122+
layoutItem->setSubdivisionLineSymbol( lineSymbol->clone() );
11211123
layoutItem->setLineSymbol( lineSymbol.release() );
11221124

11231125
//font color

‎src/core/layout/qgslayoutitemscalebar.cpp

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,26 @@ void QgsLayoutItemScaleBar::setLineSymbol( QgsLineSymbol *symbol )
194194
mSettings.setLineSymbol( symbol );
195195
}
196196

197+
QgsLineSymbol *QgsLayoutItemScaleBar::divisionLineSymbol() const
198+
{
199+
return mSettings.divisionLineSymbol();
200+
}
201+
202+
void QgsLayoutItemScaleBar::setDivisionLineSymbol( QgsLineSymbol *symbol )
203+
{
204+
mSettings.setDivisionLineSymbol( symbol );
205+
}
206+
207+
QgsLineSymbol *QgsLayoutItemScaleBar::subdivisionLineSymbol() const
208+
{
209+
return mSettings.subdivisionLineSymbol();
210+
}
211+
212+
void QgsLayoutItemScaleBar::setSubdivisionLineSymbol( QgsLineSymbol *symbol )
213+
{
214+
mSettings.setSubdivisionLineSymbol( symbol );
215+
}
216+
197217
QgsFillSymbol *QgsLayoutItemScaleBar::fillSymbol() const
198218
{
199219
return mSettings.fillSymbol();
@@ -813,6 +833,22 @@ bool QgsLayoutItemScaleBar::writePropertiesToElement( QDomElement &composerScale
813833
lineSymbol.appendChild( symbolElem );
814834
composerScaleBarElem.appendChild( lineSymbol );
815835

836+
QDomElement divisionSymbol = doc.createElement( QStringLiteral( "divisionLineSymbol" ) );
837+
const QDomElement divisionSymbolElem = QgsSymbolLayerUtils::saveSymbol( QString(),
838+
mSettings.divisionLineSymbol(),
839+
doc,
840+
rwContext );
841+
divisionSymbol.appendChild( divisionSymbolElem );
842+
composerScaleBarElem.appendChild( divisionSymbol );
843+
844+
QDomElement subdivisionSymbol = doc.createElement( QStringLiteral( "subdivisionLineSymbol" ) );
845+
const QDomElement subdivisionSymbolElem = QgsSymbolLayerUtils::saveSymbol( QString(),
846+
mSettings.subdivisionLineSymbol(),
847+
doc,
848+
rwContext );
849+
subdivisionSymbol.appendChild( subdivisionSymbolElem );
850+
composerScaleBarElem.appendChild( subdivisionSymbol );
851+
816852
QDomElement fillSymbol1Elem = doc.createElement( QStringLiteral( "fillSymbol1" ) );
817853
const QDomElement symbol1Elem = QgsSymbolLayerUtils::saveSymbol( QString(),
818854
mSettings.fillSymbol(),
@@ -860,6 +896,35 @@ bool QgsLayoutItemScaleBar::readPropertiesFromElement( const QDomElement &itemEl
860896
foundLineSymbol = true;
861897
}
862898
}
899+
QDomElement divisionSymbolElem = itemElem.firstChildElement( QStringLiteral( "divisionLineSymbol" ) );
900+
if ( !divisionSymbolElem.isNull() )
901+
{
902+
QDomElement symbolElem = divisionSymbolElem.firstChildElement( QStringLiteral( "symbol" ) );
903+
std::unique_ptr< QgsLineSymbol > lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
904+
if ( lineSymbol )
905+
{
906+
mSettings.setDivisionLineSymbol( lineSymbol.release() );
907+
}
908+
}
909+
else if ( foundLineSymbol )
910+
{
911+
mSettings.setDivisionLineSymbol( mSettings.lineSymbol()->clone() );
912+
}
913+
QDomElement subdivisionSymbolElem = itemElem.firstChildElement( QStringLiteral( "subdivisionLineSymbol" ) );
914+
if ( !subdivisionSymbolElem.isNull() )
915+
{
916+
QDomElement symbolElem = subdivisionSymbolElem.firstChildElement( QStringLiteral( "symbol" ) );
917+
std::unique_ptr< QgsLineSymbol > lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
918+
if ( lineSymbol )
919+
{
920+
mSettings.setSubdivisionLineSymbol( lineSymbol.release() );
921+
}
922+
}
923+
else if ( foundLineSymbol )
924+
{
925+
mSettings.setSubdivisionLineSymbol( mSettings.lineSymbol()->clone() );
926+
}
927+
863928
if ( !foundLineSymbol )
864929
{
865930
// old project compatibility
@@ -901,7 +966,9 @@ bool QgsLayoutItemScaleBar::readPropertiesFromElement( const QDomElement &itemEl
901966
dataDefinedProperties().setProperty( QgsLayoutObject::ScalebarLineColor, QgsProperty() );
902967

903968
lineSymbol->changeSymbolLayer( 0, lineSymbolLayer.release() );
904-
mSettings.setLineSymbol( lineSymbol.release() );
969+
mSettings.setLineSymbol( lineSymbol->clone() );
970+
mSettings.setDivisionLineSymbol( lineSymbol->clone() );
971+
mSettings.setSubdivisionLineSymbol( lineSymbol.release() );
905972
}
906973

907974
mSettings.setUnitLabel( itemElem.attribute( QStringLiteral( "unitLabel" ) ) );

‎src/core/layout/qgslayoutitemscalebar.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,15 @@ class CORE_EXPORT QgsLayoutItemScaleBar: public QgsLayoutItem
224224
*/
225225
void setTextFormat( const QgsTextFormat &format );
226226

227+
227228
/**
228229
* Returns the line symbol used to render the scalebar (only used for some scalebar types).
229230
*
230231
* Ownership is not transferred.
231232
*
232233
* \see setLineSymbol()
234+
* \see divisionLineSymbol()
235+
* \see subdivisionLineSymbol()
233236
* \since QGIS 3.14
234237
*/
235238
QgsLineSymbol *lineSymbol() const;
@@ -239,10 +242,58 @@ class CORE_EXPORT QgsLayoutItemScaleBar: public QgsLayoutItem
239242
* transferred to the scalebar.
240243
*
241244
* \see lineSymbol()
245+
* \see setDivisionLineSymbol()
246+
* \see setSubdivisionLineSymbol()
242247
* \since QGIS 3.14
243248
*/
244249
void setLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
245250

251+
/**
252+
* Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).
253+
*
254+
* Ownership is not transferred.
255+
*
256+
* \see setDivisionLineSymbol()
257+
* \see lineSymbol()
258+
* \see subdivisionLineSymbol()
259+
* \since QGIS 3.14
260+
*/
261+
QgsLineSymbol *divisionLineSymbol() const;
262+
263+
/**
264+
* Sets the line \a symbol used to render the scalebar divisions (only used for some scalebar types). Ownership of \a symbol is
265+
* transferred to the scalebar.
266+
*
267+
* \see divisionLineSymbol()
268+
* \see setLineSymbol()
269+
* \see setSubdivisionLineSymbol()
270+
* \since QGIS 3.14
271+
*/
272+
void setDivisionLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
273+
274+
/**
275+
* Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
276+
*
277+
* Ownership is not transferred.
278+
*
279+
* \see setSubdivisionLineSymbol()
280+
* \see lineSymbol()
281+
* \see divisionLineSymbol()
282+
* \since QGIS 3.14
283+
*/
284+
QgsLineSymbol *subdivisionLineSymbol() const;
285+
286+
/**
287+
* Sets the line \a symbol used to render the scalebar subdivisions (only used for some scalebar types). Ownership of \a symbol is
288+
* transferred to the scalebar.
289+
*
290+
* \see subdivisionLineSymbol()
291+
* \see setLineSymbol()
292+
* \see setDivisionLineSymbol()
293+
* \since QGIS 3.14
294+
*/
295+
void setSubdivisionLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
296+
246297
/**
247298
* Returns the primary fill symbol used to render the scalebar (only used for some scalebar types).
248299
*

‎src/core/scalebar/qgsscalebarrenderer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class CORE_EXPORT QgsScaleBarRenderer
8282
FlagUsesLabelHorizontalPlacement = 1 << 8, //!< Renderer uses the QgsScaleBarSettings::labelHorizontalPlacement() setting
8383
FlagUsesAlignment = 1 << 9, //!< Renderer uses the QgsScaleBarSettings::alignment() setting
8484
FlagUsesSubdivisions = 1 << 10, //!< Renderer uses the scalebar subdivisions
85+
FlagUsesDivisionSymbol = 1 << 11, //!< Renderer utilizes the scalebar division symbol (see QgsScaleBarSettings::divisionLineSymbol() )
86+
FlagUsesSubdivisionSymbol = 1 << 12, //!< Renderer utilizes the scalebar subdivision symbol (see QgsScaleBarSettings::subdivisionLineSymbol() )
8587
};
8688
Q_DECLARE_FLAGS( Flags, Flag )
8789

0 commit comments

Comments
 (0)
Please sign in to comment.