Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make class for tracking default plot symbols
  • Loading branch information
nyalldawson committed Jan 17, 2023
1 parent c126930 commit 2fe201d
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 17 deletions.
53 changes: 52 additions & 1 deletion python/core/auto_generated/plot/qgsplot.sip.in
Expand Up @@ -341,7 +341,6 @@ Returns a reference to the plot's y axis.
%End



QgsFillSymbol *chartBackgroundSymbol();
%Docstring
Returns the fill symbol used to render the background of the chart.
Expand Down Expand Up @@ -392,6 +391,58 @@ Sets the ``margins`` of the plot area (in millimeters)
Qgs2DPlot( const Qgs2DPlot &other );
};

class QgsPlotDefaultSettings
{
%Docstring(signature="appended")
Manages default settings for plot objects

.. warning::

This class is not considered stable API, and may change in future!

.. versionadded:: 3.30
%End

%TypeHeaderCode
#include "qgsplot.h"
%End
public:

static QgsNumericFormat *axisLabelNumericFormat() /Factory/;
%Docstring
Returns the default numeric format to use for plot axis labels.
%End

static QgsLineSymbol *axisGridMajorSymbol() /Factory/;
%Docstring
Returns the default line symbol to use for axis major grid lines.

.. seealso:: :py:func:`axisGridMinorSymbol`
%End

static QgsLineSymbol *axisGridMinorSymbol() /Factory/;
%Docstring
Returns the default line symbol to use for axis minor grid lines.

.. seealso:: :py:func:`axisGridMajorSymbol`
%End

static QgsFillSymbol *chartFillSymbol() /Factory/;
%Docstring
Returns the default fill symbol to use for the chart area background fill.

.. seealso:: :py:func:`chartBorderSymbol`
%End

static QgsFillSymbol *chartBorderSymbol() /Factory/;
%Docstring
Returns the default fill symbol to use for the chart area border.

.. seealso:: :py:func:`chartFillSymbol`
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
55 changes: 40 additions & 15 deletions src/core/plot/qgsplot.cpp
Expand Up @@ -45,16 +45,9 @@ bool QgsPlot::readXml( const QDomElement &, const QgsReadWriteContext & )
QgsPlotAxis::QgsPlotAxis()
{
// setup default style

mNumericFormat = std::make_unique< QgsBasicNumericFormat >();

std::unique_ptr< QgsSimpleLineSymbolLayer > gridMinor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 50 ), 0.1 );
gridMinor->setPenCapStyle( Qt::FlatCap );
mGridMinorSymbol = std::make_unique< QgsLineSymbol>( QgsSymbolLayerList( { gridMinor.release() } ) );

std::unique_ptr< QgsSimpleLineSymbolLayer > gridMajor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 150 ), 0.1 );
gridMajor->setPenCapStyle( Qt::FlatCap );
mGridMajorSymbol = std::make_unique< QgsLineSymbol>( QgsSymbolLayerList( { gridMajor.release() } ) );
mNumericFormat.reset( QgsPlotDefaultSettings::axisLabelNumericFormat() );
mGridMinorSymbol.reset( QgsPlotDefaultSettings::axisGridMinorSymbol() );
mGridMajorSymbol.reset( QgsPlotDefaultSettings::axisGridMajorSymbol() );
}

QgsPlotAxis::~QgsPlotAxis() = default;
Expand Down Expand Up @@ -152,11 +145,8 @@ Qgs2DPlot::Qgs2DPlot()
: mMargins( 2, 2, 2, 2 )
{
// setup default style
std::unique_ptr< QgsSimpleFillSymbolLayer > chartFill = std::make_unique< QgsSimpleFillSymbolLayer >( QColor( 255, 255, 255 ) );
mChartBackgroundSymbol = std::make_unique< QgsFillSymbol>( QgsSymbolLayerList( { chartFill.release() } ) );

std::unique_ptr< QgsSimpleLineSymbolLayer > chartBorder = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20 ), 0.1 );
mChartBorderSymbol = std::make_unique< QgsFillSymbol>( QgsSymbolLayerList( { chartBorder.release() } ) );
mChartBackgroundSymbol.reset( QgsPlotDefaultSettings::chartFillSymbol() );
mChartBorderSymbol.reset( QgsPlotDefaultSettings::chartBorderSymbol() );
}

bool Qgs2DPlot::writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const
Expand Down Expand Up @@ -586,3 +576,38 @@ void Qgs2DPlot::setMargins( const QgsMargins &margins )
{
mMargins = margins;
}

//
// QgsPlotDefaultSettings
//

QgsNumericFormat *QgsPlotDefaultSettings::axisLabelNumericFormat()
{
return new QgsBasicNumericFormat();
}

QgsLineSymbol *QgsPlotDefaultSettings::axisGridMajorSymbol()
{
std::unique_ptr< QgsSimpleLineSymbolLayer > gridMajor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 150 ), 0.1 );
gridMajor->setPenCapStyle( Qt::FlatCap );
return new QgsLineSymbol( QgsSymbolLayerList( { gridMajor.release() } ) );
}

QgsLineSymbol *QgsPlotDefaultSettings::axisGridMinorSymbol()
{
std::unique_ptr< QgsSimpleLineSymbolLayer > gridMinor = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20, 50 ), 0.1 );
gridMinor->setPenCapStyle( Qt::FlatCap );
return new QgsLineSymbol( QgsSymbolLayerList( { gridMinor.release() } ) );
}

QgsFillSymbol *QgsPlotDefaultSettings::chartFillSymbol()
{
std::unique_ptr< QgsSimpleFillSymbolLayer > chartFill = std::make_unique< QgsSimpleFillSymbolLayer >( QColor( 255, 255, 255 ) );
return new QgsFillSymbol( QgsSymbolLayerList( { chartFill.release() } ) );
}

QgsFillSymbol *QgsPlotDefaultSettings::chartBorderSymbol()
{
std::unique_ptr< QgsSimpleLineSymbolLayer > chartBorder = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 20, 20, 20 ), 0.1 );
return new QgsFillSymbol( QgsSymbolLayerList( { chartBorder.release() } ) );
}
48 changes: 47 additions & 1 deletion src/core/plot/qgsplot.h
Expand Up @@ -374,7 +374,6 @@ class CORE_EXPORT Qgs2DPlot : public QgsPlot
*/
QgsPlotAxis &yAxis() { return mYAxis; }


/**
* Returns a reference to the plot's y axis.
*
Expand Down Expand Up @@ -450,4 +449,51 @@ class CORE_EXPORT Qgs2DPlot : public QgsPlot
QgsPlotAxis mYAxis;
};

/**
* \brief Manages default settings for plot objects
*
* \warning This class is not considered stable API, and may change in future!
*
* \ingroup core
* \since QGIS 3.30
*/
class CORE_EXPORT QgsPlotDefaultSettings
{
public:

/**
* Returns the default numeric format to use for plot axis labels.
*/
static QgsNumericFormat *axisLabelNumericFormat() SIP_FACTORY;

/**
* Returns the default line symbol to use for axis major grid lines.
*
* \see axisGridMinorSymbol()
*/
static QgsLineSymbol *axisGridMajorSymbol() SIP_FACTORY;

/**
* Returns the default line symbol to use for axis minor grid lines.
*
* \see axisGridMajorSymbol()
*/
static QgsLineSymbol *axisGridMinorSymbol() SIP_FACTORY;

/**
* Returns the default fill symbol to use for the chart area background fill.
*
* \see chartBorderSymbol()
*/
static QgsFillSymbol *chartFillSymbol() SIP_FACTORY;

/**
* Returns the default fill symbol to use for the chart area border.
*
* \see chartFillSymbol()
*/
static QgsFillSymbol *chartBorderSymbol() SIP_FACTORY;

};

#endif // QGSPLOT_H

0 comments on commit 2fe201d

Please sign in to comment.