Skip to content

Commit

Permalink
restore fill brush when switching back to single and double box scalebar
Browse files Browse the repository at this point in the history
(fix #37413)
  • Loading branch information
alexbruy authored and nyalldawson committed Feb 5, 2025
1 parent 33aad3e commit 1f7d1ad
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ Double box with alternating colors.
const QgsScaleBarSettings &settings,
const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const;

virtual bool applyDefaultSettings( QgsScaleBarSettings &settings ) const;

%Docstring
Applies any default settings relating to the scalebar to the passed ``settings`` object.

Returns ``True`` if settings were applied.

.. versionadded:: 3.42
%End
};

/************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ alternating segments. AKA "South African" style.
const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const;
virtual bool applyDefaultSettings( QgsScaleBarSettings &settings ) const;


};

/************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ color for the segments.
const QgsScaleBarSettings &settings,
const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const;

virtual bool applyDefaultSettings( QgsScaleBarSettings &settings ) const;

%Docstring
Applies any default settings relating to the scalebar to the passed ``settings`` object.

Returns ``True`` if settings were applied.

.. versionadded:: 3.42
%End
};

/************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ Double box with alternating colors.
const QgsScaleBarSettings &settings,
const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const;

virtual bool applyDefaultSettings( QgsScaleBarSettings &settings ) const;

%Docstring
Applies any default settings relating to the scalebar to the passed ``settings`` object.

Returns ``True`` if settings were applied.

.. versionadded:: 3.42
%End
};

/************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ alternating segments. AKA "South African" style.
const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const;
virtual bool applyDefaultSettings( QgsScaleBarSettings &settings ) const;


};

/************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ color for the segments.
const QgsScaleBarSettings &settings,
const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const;

virtual bool applyDefaultSettings( QgsScaleBarSettings &settings ) const;

%Docstring
Applies any default settings relating to the scalebar to the passed ``settings`` object.

Returns ``True`` if settings were applied.

.. versionadded:: 3.42
%End
};

/************************************************************************
Expand Down
22 changes: 22 additions & 0 deletions src/core/scalebar/qgsdoubleboxscalebarrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "qgstextrenderer.h"
#include "qgslinesymbol.h"
#include "qgsfillsymbol.h"
#include "qgsfillsymbollayer.h"
#include <QList>
#include <QPainter>

Expand Down Expand Up @@ -190,3 +191,24 @@ void QgsDoubleBoxScaleBarRenderer::draw( QgsRenderContext &context, const QgsSca
//draw labels using the default method
drawDefaultLabels( context, settings, scaleContext );
}

bool QgsDoubleBoxScaleBarRenderer::applyDefaultSettings( QgsScaleBarSettings &settings ) const
{
// restore the fill symbols by default
std::unique_ptr< QgsFillSymbol > fillSymbol = std::make_unique< QgsFillSymbol >();
std::unique_ptr< QgsSimpleFillSymbolLayer > fillSymbolLayer = std::make_unique< QgsSimpleFillSymbolLayer >();
fillSymbolLayer->setColor( QColor( 0, 0, 0 ) );
fillSymbolLayer->setBrushStyle( Qt::SolidPattern );
fillSymbolLayer->setStrokeStyle( Qt::SolidLine );
fillSymbol->changeSymbolLayer( 0, fillSymbolLayer.release() );
settings.setFillSymbol( fillSymbol.release() );

fillSymbol = std::make_unique< QgsFillSymbol >();
fillSymbolLayer = std::make_unique< QgsSimpleFillSymbolLayer >();
fillSymbolLayer->setColor( QColor( 255, 255, 255 ) );
fillSymbolLayer->setStrokeStyle( Qt::NoPen );
fillSymbol->changeSymbolLayer( 0, fillSymbolLayer.release() );
settings.setAlternateFillSymbol( fillSymbol.release() );

return true;
}
8 changes: 8 additions & 0 deletions src/core/scalebar/qgsdoubleboxscalebarrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class CORE_EXPORT QgsDoubleBoxScaleBarRenderer: public QgsScaleBarRenderer
const QgsScaleBarSettings &settings,
const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const override;

/**
* Applies any default settings relating to the scalebar to the passed \a settings object.
*
* Returns TRUE if settings were applied.
*
* \since QGIS 3.42
*/
bool applyDefaultSettings( QgsScaleBarSettings &settings ) const override;
};

#endif // QGSDOUBLEBOXSCALEBARRENDERER_H
3 changes: 0 additions & 3 deletions src/core/scalebar/qgshollowscalebarrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,3 @@ bool QgsHollowScaleBarRenderer::applyDefaultSettings( QgsScaleBarSettings &setti

return true;
}



1 change: 0 additions & 1 deletion src/core/scalebar/qgshollowscalebarrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class CORE_EXPORT QgsHollowScaleBarRenderer: public QgsScaleBarRenderer
const QgsScaleBarSettings &settings,
const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const override;
bool applyDefaultSettings( QgsScaleBarSettings &settings ) const override;

};

#endif // QGSHOLLOWSCALEBARRENDERER_H
23 changes: 21 additions & 2 deletions src/core/scalebar/qgssingleboxscalebarrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "qgstextrenderer.h"
#include "qgslinesymbol.h"
#include "qgsfillsymbol.h"
#include "qgsfillsymbollayer.h"
#include <QList>
#include <QPainter>

Expand Down Expand Up @@ -157,5 +158,23 @@ void QgsSingleBoxScaleBarRenderer::draw( QgsRenderContext &context, const QgsSca
drawDefaultLabels( context, settings, scaleContext );
}



bool QgsSingleBoxScaleBarRenderer::applyDefaultSettings( QgsScaleBarSettings &settings ) const
{
// restore the fill symbols by default
std::unique_ptr< QgsFillSymbol > fillSymbol = std::make_unique< QgsFillSymbol >();
std::unique_ptr< QgsSimpleFillSymbolLayer > fillSymbolLayer = std::make_unique< QgsSimpleFillSymbolLayer >();
fillSymbolLayer->setColor( QColor( 0, 0, 0 ) );
fillSymbolLayer->setBrushStyle( Qt::SolidPattern );
fillSymbolLayer->setStrokeStyle( Qt::SolidLine );
fillSymbol->changeSymbolLayer( 0, fillSymbolLayer.release() );
settings.setFillSymbol( fillSymbol.release() );

fillSymbol = std::make_unique< QgsFillSymbol >();
fillSymbolLayer = std::make_unique< QgsSimpleFillSymbolLayer >();
fillSymbolLayer->setColor( QColor( 255, 255, 255 ) );
fillSymbolLayer->setStrokeStyle( Qt::NoPen );
fillSymbol->changeSymbolLayer( 0, fillSymbolLayer.release() );
settings.setAlternateFillSymbol( fillSymbol.release() );

return true;
}
8 changes: 8 additions & 0 deletions src/core/scalebar/qgssingleboxscalebarrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class CORE_EXPORT QgsSingleBoxScaleBarRenderer: public QgsScaleBarRenderer
const QgsScaleBarSettings &settings,
const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const override;

/**
* Applies any default settings relating to the scalebar to the passed \a settings object.
*
* Returns TRUE if settings were applied.
*
* \since QGIS 3.42
*/
bool applyDefaultSettings( QgsScaleBarSettings &settings ) const override;
};

#endif // QGSSINGLEBOXSCALEBARRENDERER_H

0 comments on commit 1f7d1ad

Please sign in to comment.