Skip to content
Permalink
Browse files

Cleanup scalebar widget enabling code by adding flags to QgsScaleBarR…

…enderer

subclasses, so that the subclass itself can indicate what settings
it respects and we can avoid all the hardcoded logic in the configuration
widget
  • Loading branch information
nyalldawson committed Mar 22, 2020
1 parent 4079878 commit b63018520eaae34f714f3a64ceeafa43bb77abc9
Showing with 185 additions and 39 deletions.
  1. +15 −0 python/core/auto_additions/qgsscalebarrenderer.py
  2. +2 −0 python/core/auto_generated/scalebar/qgsdoubleboxscalebarrenderer.sip.in
  3. +2 −0 python/core/auto_generated/scalebar/qgshollowscalebarrenderer.sip.in
  4. +2 −0 python/core/auto_generated/scalebar/qgsnumericscalebarrenderer.sip.in
  5. +27 −0 python/core/auto_generated/scalebar/qgsscalebarrenderer.sip.in
  6. +2 −0 python/core/auto_generated/scalebar/qgssingleboxscalebarrenderer.sip.in
  7. +3 −1 python/core/auto_generated/scalebar/qgssteppedlinescalebarrenderer.sip.in
  8. +2 −0 python/core/auto_generated/scalebar/qgsticksscalebarrenderer.sip.in
  9. +14 −0 src/core/scalebar/qgsdoubleboxscalebarrenderer.cpp
  10. +1 −0 src/core/scalebar/qgsdoubleboxscalebarrenderer.h
  11. +14 −0 src/core/scalebar/qgshollowscalebarrenderer.cpp
  12. +1 −0 src/core/scalebar/qgshollowscalebarrenderer.h
  13. +5 −0 src/core/scalebar/qgsnumericscalebarrenderer.cpp
  14. +1 −0 src/core/scalebar/qgsnumericscalebarrenderer.h
  15. +5 −0 src/core/scalebar/qgsscalebarrenderer.cpp
  16. +29 −0 src/core/scalebar/qgsscalebarrenderer.h
  17. +14 −0 src/core/scalebar/qgssingleboxscalebarrenderer.cpp
  18. +1 −0 src/core/scalebar/qgssingleboxscalebarrenderer.h
  19. +12 −0 src/core/scalebar/qgssteppedlinescalebarrenderer.cpp
  20. +2 −1 src/core/scalebar/qgssteppedlinescalebarrenderer.h
  21. +12 −0 src/core/scalebar/qgsticksscalebarrenderer.cpp
  22. +1 −0 src/core/scalebar/qgsticksscalebarrenderer.h
  23. +18 −37 src/gui/layout/qgslayoutscalebarwidget.cpp
@@ -0,0 +1,15 @@
# The following has been generated automatically from src/core/scalebar/qgsscalebarrenderer.h
# monkey patching scoped based enum
QgsScaleBarRenderer.Flag.FlagUsesLineSymbol.__doc__ = "Renderer utilises the scalebar line symbol (see QgsScaleBarSettings::lineSymbol() )"
QgsScaleBarRenderer.Flag.FlagUsesFillSymbol.__doc__ = "Renderer utilises the scalebar fill symbol (see QgsScaleBarSettings::fillSymbol() )"
QgsScaleBarRenderer.Flag.FlagUsesAlternateFillSymbol.__doc__ = "Renderer utilises the alternate scalebar fill symbol (see QgsScaleBarSettings::alternateFillSymbol() )"
QgsScaleBarRenderer.Flag.FlagRespectsUnits.__doc__ = "Renderer respects the QgsScaleBarSettings::units() setting"
QgsScaleBarRenderer.Flag.FlagRespectsMapUnitsPerScaleBarUnit.__doc__ = "Renderer respects the QgsScaleBarSettings::mapUnitsPerScaleBarUnit() setting"
QgsScaleBarRenderer.Flag.FlagUsesUnitLabel.__doc__ = "Renderer uses the QgsScaleBarSettings::unitLabel() setting"
QgsScaleBarRenderer.Flag.FlagUsesSegments.__doc__ = "Renderer uses the scalebar segments"
QgsScaleBarRenderer.Flag.FlagUsesLabelBarSpace.__doc__ = "Renderer uses the QgsScaleBarSettings::labelBarSpace() setting"
QgsScaleBarRenderer.Flag.FlagUsesLabelVerticalPlacement.__doc__ = "Renderer uses the QgsScaleBarSettings::labelVerticalPlacement() setting"
QgsScaleBarRenderer.Flag.FlagUsesLabelHorizontalPlacement.__doc__ = "Renderer uses the QgsScaleBarSettings::labelHorizontalPlacement() setting"
QgsScaleBarRenderer.Flag.FlagUsesAlignment.__doc__ = "Renderer uses the QgsScaleBarSettings::alignment() setting"
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__
# --
@@ -30,6 +30,8 @@ Constructor for QgsDoubleBoxScaleBarRenderer.

virtual QString visibleName() const;

virtual Flags flags() const;

virtual int sortKey() const;

virtual QgsDoubleBoxScaleBarRenderer *clone() const /Factory/;
@@ -31,6 +31,8 @@ Constructor for QgsHollowScaleBarRenderer.

virtual QString visibleName() const;

virtual Flags flags() const;

virtual int sortKey() const;

virtual QgsHollowScaleBarRenderer *clone() const /Factory/;
@@ -32,6 +32,8 @@ Constructor for QgsNumericScaleBarRenderer.

virtual int sortKey() const;

virtual Flags flags() const;

virtual QgsNumericScaleBarRenderer *clone() const /Factory/;


@@ -36,6 +36,23 @@ custom labeling.

};

enum class Flag
{
FlagUsesLineSymbol,
FlagUsesFillSymbol,
FlagUsesAlternateFillSymbol,
FlagRespectsUnits,
FlagRespectsMapUnitsPerScaleBarUnit,
FlagUsesUnitLabel,
FlagUsesSegments,
FlagUsesLabelBarSpace,
FlagUsesLabelVerticalPlacement,
FlagUsesLabelHorizontalPlacement,
FlagUsesAlignment,
};
typedef QFlags<QgsScaleBarRenderer::Flag> Flags;


QgsScaleBarRenderer();
%Docstring
Constructor for QgsScaleBarRenderer.
@@ -61,6 +78,13 @@ Returns the unique ID for this renderer.
%Docstring
Returns the user friendly, translated name for the renderer.

.. versionadded:: 3.14
%End

virtual Flags flags() const;
%Docstring
Returns the scalebar rendering flags, which dictates the renderer's behavior.

.. versionadded:: 3.14
%End

@@ -161,6 +185,9 @@ Returns a list of widths of each segment of the scalebar.

};

QFlags<QgsScaleBarRenderer::Flag> operator|(QgsScaleBarRenderer::Flag f1, QFlags<QgsScaleBarRenderer::Flag> f2);


/************************************************************************
* This file has been generated automatically from *
* *
@@ -33,6 +33,8 @@ Constructor for QgsSingleBoxScaleBarRenderer.

virtual int sortKey() const;

virtual Flags flags() const;

virtual QgsSingleBoxScaleBarRenderer *clone() const /Factory/;


@@ -32,7 +32,9 @@ Constructor for QgsSteppedLineScaleBarRenderer.

virtual int sortKey() const;

virtual QgsSteppedLineScaleBarRenderer* clone() const /Factory/;
virtual Flags flags() const;

virtual QgsSteppedLineScaleBarRenderer *clone() const /Factory/;


virtual void draw( QgsRenderContext &context,
@@ -39,6 +39,8 @@ Constructor for QgsTicksScaleBarRenderer.

virtual int sortKey() const;

virtual Flags flags() const;

virtual QgsTicksScaleBarRenderer *clone() const /Factory/;


@@ -31,6 +31,20 @@ QString QgsDoubleBoxScaleBarRenderer::visibleName() const
return QObject::tr( "Double Box" );
}

QgsScaleBarRenderer::Flags QgsDoubleBoxScaleBarRenderer::flags() const
{
return Flag::FlagUsesLineSymbol |
Flag::FlagUsesFillSymbol |
Flag::FlagUsesAlternateFillSymbol |
Flag::FlagRespectsUnits |
Flag::FlagRespectsMapUnitsPerScaleBarUnit |
Flag::FlagUsesUnitLabel |
Flag::FlagUsesSegments |
Flag::FlagUsesLabelBarSpace |
Flag::FlagUsesLabelVerticalPlacement |
Flag::FlagUsesLabelHorizontalPlacement;
}

int QgsDoubleBoxScaleBarRenderer::sortKey() const
{
return 2;
@@ -38,6 +38,7 @@ class CORE_EXPORT QgsDoubleBoxScaleBarRenderer: public QgsScaleBarRenderer

QString id() const override;
QString visibleName() const override;
Flags flags() const override;
int sortKey() const override;
QgsDoubleBoxScaleBarRenderer *clone() const override SIP_FACTORY;

@@ -32,6 +32,20 @@ QString QgsHollowScaleBarRenderer::visibleName() const
return QObject::tr( "Hollow" );
}

QgsScaleBarRenderer::Flags QgsHollowScaleBarRenderer::flags() const
{
return Flag::FlagUsesLineSymbol |
Flag::FlagUsesFillSymbol |
Flag::FlagUsesAlternateFillSymbol |
Flag::FlagRespectsUnits |
Flag::FlagRespectsMapUnitsPerScaleBarUnit |
Flag::FlagUsesUnitLabel |
Flag::FlagUsesSegments |
Flag::FlagUsesLabelBarSpace |
Flag::FlagUsesLabelVerticalPlacement |
Flag::FlagUsesLabelHorizontalPlacement;
}

int QgsHollowScaleBarRenderer::sortKey() const
{
return 8;
@@ -39,6 +39,7 @@ class CORE_EXPORT QgsHollowScaleBarRenderer: public QgsScaleBarRenderer

QString id() const override;
QString visibleName() const override;
Flags flags() const override;
int sortKey() const override;
QgsHollowScaleBarRenderer *clone() const override SIP_FACTORY;

@@ -36,6 +36,11 @@ int QgsNumericScaleBarRenderer::sortKey() const
return 9;
}

QgsScaleBarRenderer::Flags QgsNumericScaleBarRenderer::flags() const
{
return Flag::FlagUsesAlignment;
}

QgsNumericScaleBarRenderer *QgsNumericScaleBarRenderer::clone() const
{
return new QgsNumericScaleBarRenderer( *this );
@@ -39,6 +39,7 @@ class CORE_EXPORT QgsNumericScaleBarRenderer: public QgsScaleBarRenderer
QString id() const override;
QString visibleName() const override;
int sortKey() const override;
Flags flags() const override;
QgsNumericScaleBarRenderer *clone() const override SIP_FACTORY;

void draw( QgsRenderContext &context,
@@ -145,6 +145,11 @@ void QgsScaleBarRenderer::drawDefaultLabels( QgsRenderContext &context, const Qg
painter->restore();
}

QgsScaleBarRenderer::Flags QgsScaleBarRenderer::flags() const
{
return nullptr;
}

int QgsScaleBarRenderer::sortKey() const
{
return 100;
@@ -64,6 +64,26 @@ class CORE_EXPORT QgsScaleBarRenderer

};

/**
* Flags which control scalebar renderer behavior.
* \since QGIS 3.14
*/
enum class Flag
{
FlagUsesLineSymbol = 1 << 0, //!< Renderer utilises the scalebar line symbol (see QgsScaleBarSettings::lineSymbol() )
FlagUsesFillSymbol = 1 << 1, //!< Renderer utilises the scalebar fill symbol (see QgsScaleBarSettings::fillSymbol() )
FlagUsesAlternateFillSymbol = 1 << 2, //!< Renderer utilises the alternate scalebar fill symbol (see QgsScaleBarSettings::alternateFillSymbol() )
FlagRespectsUnits = 1 << 3, //!< Renderer respects the QgsScaleBarSettings::units() setting
FlagRespectsMapUnitsPerScaleBarUnit = 1 << 4, //!< Renderer respects the QgsScaleBarSettings::mapUnitsPerScaleBarUnit() setting
FlagUsesUnitLabel = 1 << 5, //!< Renderer uses the QgsScaleBarSettings::unitLabel() setting
FlagUsesSegments = 1 << 6, //!< Renderer uses the scalebar segments
FlagUsesLabelBarSpace = 1 << 7, //!< Renderer uses the QgsScaleBarSettings::labelBarSpace() setting
FlagUsesLabelVerticalPlacement = 1 << 8, //!< Renderer uses the QgsScaleBarSettings::labelVerticalPlacement() setting
FlagUsesLabelHorizontalPlacement = 1 << 8, //!< Renderer uses the QgsScaleBarSettings::labelHorizontalPlacement() setting
FlagUsesAlignment = 1 << 9, //!< Renderer uses the QgsScaleBarSettings::alignment() setting
};
Q_DECLARE_FLAGS( Flags, Flag )

/**
* Constructor for QgsScaleBarRenderer.
*/
@@ -88,6 +108,13 @@ class CORE_EXPORT QgsScaleBarRenderer
*/
virtual QString visibleName() const = 0;

/**
* Returns the scalebar rendering flags, which dictates the renderer's behavior.
*
* \since QGIS 3.14
*/
virtual Flags flags() const;

/**
* Returns a sorting key value, where renderers with a lower sort key will be shown earlier in lists.
*
@@ -177,4 +204,6 @@ class CORE_EXPORT QgsScaleBarRenderer

};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsScaleBarRenderer::Flags )

#endif //QGSSCALEBARRENDERER_H
@@ -36,6 +36,20 @@ int QgsSingleBoxScaleBarRenderer::sortKey() const
return 1;
}

QgsScaleBarRenderer::Flags QgsSingleBoxScaleBarRenderer::flags() const
{
return Flag::FlagUsesLineSymbol |
Flag::FlagUsesFillSymbol |
Flag::FlagUsesAlternateFillSymbol |
Flag::FlagRespectsUnits |
Flag::FlagRespectsMapUnitsPerScaleBarUnit |
Flag::FlagUsesUnitLabel |
Flag::FlagUsesSegments |
Flag::FlagUsesLabelBarSpace |
Flag::FlagUsesLabelVerticalPlacement |
Flag::FlagUsesLabelHorizontalPlacement;
}

QgsSingleBoxScaleBarRenderer *QgsSingleBoxScaleBarRenderer::clone() const
{
return new QgsSingleBoxScaleBarRenderer( *this );
@@ -40,6 +40,7 @@ class CORE_EXPORT QgsSingleBoxScaleBarRenderer: public QgsScaleBarRenderer
QString id() const override;
QString visibleName() const override;
int sortKey() const override;
Flags flags() const override;
QgsSingleBoxScaleBarRenderer *clone() const override SIP_FACTORY;

void draw( QgsRenderContext &context,
@@ -36,6 +36,18 @@ int QgsSteppedLineScaleBarRenderer::sortKey() const
return 7;
}

QgsScaleBarRenderer::Flags QgsSteppedLineScaleBarRenderer::flags() const
{
return Flag::FlagUsesLineSymbol |
Flag::FlagRespectsUnits |
Flag::FlagRespectsMapUnitsPerScaleBarUnit |
Flag::FlagUsesUnitLabel |
Flag::FlagUsesSegments |
Flag::FlagUsesLabelBarSpace |
Flag::FlagUsesLabelVerticalPlacement |
Flag::FlagUsesLabelHorizontalPlacement;
}

QgsSteppedLineScaleBarRenderer *QgsSteppedLineScaleBarRenderer::clone() const
{
return new QgsSteppedLineScaleBarRenderer( *this );
@@ -39,7 +39,8 @@ class CORE_EXPORT QgsSteppedLineScaleBarRenderer: public QgsScaleBarRenderer
QString id() const override;
QString visibleName() const override;
int sortKey() const override;
QgsSteppedLineScaleBarRenderer* clone() const override SIP_FACTORY;
Flags flags() const override;
QgsSteppedLineScaleBarRenderer *clone() const override SIP_FACTORY;

void draw( QgsRenderContext &context,
const QgsScaleBarSettings &settings,
@@ -69,6 +69,18 @@ int QgsTicksScaleBarRenderer::sortKey() const
return 6;
}

QgsScaleBarRenderer::Flags QgsTicksScaleBarRenderer::flags() const
{
return Flag::FlagUsesLineSymbol |
Flag::FlagRespectsUnits |
Flag::FlagRespectsMapUnitsPerScaleBarUnit |
Flag::FlagUsesUnitLabel |
Flag::FlagUsesSegments |
Flag::FlagUsesLabelBarSpace |
Flag::FlagUsesLabelVerticalPlacement |
Flag::FlagUsesLabelHorizontalPlacement;
}

QgsTicksScaleBarRenderer *QgsTicksScaleBarRenderer::clone() const
{
return new QgsTicksScaleBarRenderer( * this );
@@ -46,6 +46,7 @@ class CORE_EXPORT QgsTicksScaleBarRenderer: public QgsScaleBarRenderer
QString id() const override;
QString visibleName() const override;
int sortKey() const override;
Flags flags() const override;
QgsTicksScaleBarRenderer *clone() const override SIP_FACTORY;

void draw( QgsRenderContext &context,

0 comments on commit b630185

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