Skip to content

Commit

Permalink
Add no labels option
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 29, 2023
1 parent 2d10520 commit bb5cfb8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion python/core/auto_additions/qgis.py
Expand Up @@ -2257,11 +2257,12 @@
# --
Qgis.GraduatedMethod.baseClass = Qgis
# monkey patching scoped based enum
Qgis.PlotAxisSuffixPlacement.NoLabels.__doc__ = "Do not place suffixes"
Qgis.PlotAxisSuffixPlacement.EveryLabel.__doc__ = "Place suffix after every value label"
Qgis.PlotAxisSuffixPlacement.FirstLabel.__doc__ = "Place suffix after the first label value only"
Qgis.PlotAxisSuffixPlacement.LastLabel.__doc__ = "Place suffix after the last label value only"
Qgis.PlotAxisSuffixPlacement.FirstAndLastLabels.__doc__ = "Place suffix after the first and last label values only"
Qgis.PlotAxisSuffixPlacement.__doc__ = 'Placement options for suffixes in the labels for axis of plots.\n\n.. versionadded:: 3.32\n\n' + '* ``EveryLabel``: ' + Qgis.PlotAxisSuffixPlacement.EveryLabel.__doc__ + '\n' + '* ``FirstLabel``: ' + Qgis.PlotAxisSuffixPlacement.FirstLabel.__doc__ + '\n' + '* ``LastLabel``: ' + Qgis.PlotAxisSuffixPlacement.LastLabel.__doc__ + '\n' + '* ``FirstAndLastLabels``: ' + Qgis.PlotAxisSuffixPlacement.FirstAndLastLabels.__doc__
Qgis.PlotAxisSuffixPlacement.__doc__ = 'Placement options for suffixes in the labels for axis of plots.\n\n.. versionadded:: 3.32\n\n' + '* ``NoLabels``: ' + Qgis.PlotAxisSuffixPlacement.NoLabels.__doc__ + '\n' + '* ``EveryLabel``: ' + Qgis.PlotAxisSuffixPlacement.EveryLabel.__doc__ + '\n' + '* ``FirstLabel``: ' + Qgis.PlotAxisSuffixPlacement.FirstLabel.__doc__ + '\n' + '* ``LastLabel``: ' + Qgis.PlotAxisSuffixPlacement.LastLabel.__doc__ + '\n' + '* ``FirstAndLastLabels``: ' + Qgis.PlotAxisSuffixPlacement.FirstAndLastLabels.__doc__
# --
Qgis.PlotAxisSuffixPlacement.baseClass = Qgis
# monkey patching scoped based enum
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -1322,6 +1322,7 @@ The development version

enum class PlotAxisSuffixPlacement
{
NoLabels,
EveryLabel,
FirstLabel,
LastLabel,
Expand Down
17 changes: 16 additions & 1 deletion src/core/plot/qgsplot.cpp
Expand Up @@ -85,7 +85,7 @@ bool QgsPlotAxis::readXml( const QDomElement &element, const QgsReadWriteContext
mLabelInterval = element.attribute( QStringLiteral( "labelInterval" ) ).toDouble();

mLabelSuffix = element.attribute( QStringLiteral( "suffix" ) );
mSuffixPlacement = qgsEnumKeyToValue( element.attribute( QStringLiteral( "suffixPlacement" ) ), Qgis::PlotAxisSuffixPlacement::EveryLabel );
mSuffixPlacement = qgsEnumKeyToValue( element.attribute( QStringLiteral( "suffixPlacement" ) ), Qgis::PlotAxisSuffixPlacement::NoLabels );

const QDomElement numericFormatElement = element.firstChildElement( QStringLiteral( "numericFormat" ) );
mNumericFormat.reset( QgsApplication::numericFormatRegistry()->createFromXml( numericFormatElement, context ) );
Expand Down Expand Up @@ -265,6 +265,9 @@ void Qgs2DPlot::render( QgsRenderContext &context )
QString text = mYAxis.numericFormat()->formatDouble( currentY, numericContext );
switch ( mYAxis.labelSuffixPlacement() )
{
case Qgis::PlotAxisSuffixPlacement::NoLabels:
break;

case Qgis::PlotAxisSuffixPlacement::EveryLabel:
text += yAxisSuffix;
break;
Expand Down Expand Up @@ -372,6 +375,9 @@ void Qgs2DPlot::render( QgsRenderContext &context )
QString text = mXAxis.numericFormat()->formatDouble( currentX, numericContext );
switch ( mXAxis.labelSuffixPlacement() )
{
case Qgis::PlotAxisSuffixPlacement::NoLabels:
break;

case Qgis::PlotAxisSuffixPlacement::EveryLabel:
text += xAxisSuffix;
break;
Expand Down Expand Up @@ -408,6 +414,9 @@ void Qgs2DPlot::render( QgsRenderContext &context )
QString text = mYAxis.numericFormat()->formatDouble( currentY, numericContext );
switch ( mYAxis.labelSuffixPlacement() )
{
case Qgis::PlotAxisSuffixPlacement::NoLabels:
break;

case Qgis::PlotAxisSuffixPlacement::EveryLabel:
text += yAxisSuffix;
break;
Expand Down Expand Up @@ -506,6 +515,9 @@ QRectF Qgs2DPlot::interiorPlotArea( QgsRenderContext &context ) const
QString text = mXAxis.numericFormat()->formatDouble( currentX, numericContext );
switch ( mXAxis.labelSuffixPlacement() )
{
case Qgis::PlotAxisSuffixPlacement::NoLabels:
break;

case Qgis::PlotAxisSuffixPlacement::EveryLabel:
text += xAxisSuffix;
break;
Expand Down Expand Up @@ -543,6 +555,9 @@ QRectF Qgs2DPlot::interiorPlotArea( QgsRenderContext &context ) const
{
switch ( mYAxis.labelSuffixPlacement() )
{
case Qgis::PlotAxisSuffixPlacement::NoLabels:
break;

case Qgis::PlotAxisSuffixPlacement::EveryLabel:
thisLabelWidth += yAxisSuffixWidth;
break;
Expand Down
1 change: 1 addition & 0 deletions src/core/qgis.h
Expand Up @@ -2233,6 +2233,7 @@ class CORE_EXPORT Qgis
*/
enum class PlotAxisSuffixPlacement
{
NoLabels, //!< Do not place suffixes
EveryLabel, //!< Place suffix after every value label
FirstLabel, //!< Place suffix after the first label value only
LastLabel, //!< Place suffix after the last label value only
Expand Down

0 comments on commit bb5cfb8

Please sign in to comment.