Skip to content

Commit

Permalink
Dox++
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 27, 2019
1 parent ca1f255 commit 99d6524
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 36 deletions.
65 changes: 56 additions & 9 deletions python/core/auto_generated/qgslegendstyle.sip.in
Expand Up @@ -13,13 +13,14 @@
class QgsLegendStyle
{
%Docstring
Composer legend components style
Contains detailed styling information relating to how a layout legend should be rendered.
%End

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

enum Style
{
Undefined,
Expand All @@ -28,36 +29,62 @@ Composer legend components style
Group,
Subgroup,
Symbol,
SymbolLabel
SymbolLabel,
};


enum Side
{
Top,
Bottom,
Left,
Right
Right,
};

QgsLegendStyle();

QFont font() const;
%Docstring
The font for this style.
Returns the font used for rendering this legend component.

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

void setFont( const QFont &font );
%Docstring
The font for this style.
Sets the ``font`` used for rendering this legend component.

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


double margin( Side side );
%Docstring
Returns the margin (in mm) for the specified ``side`` of the component.

.. note::

Not all legend components respect all margin side settings!

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

void setMargin( Side side, double margin );
%Docstring
Sets the ``margin`` (in mm) for the specified ``side`` of the component.

.. note::

Not all legend components respect all margin side settings!

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

void setMargin( double margin );
%Docstring
Sets all margins
Sets all margin sides to the same ``margin`` size (in mm).

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

Qt::Alignment alignment() const;
Expand All @@ -79,22 +106,42 @@ Sets the alignment for the legend component.
%End

void writeXml( const QString &name, QDomElement &elem, QDomDocument &doc ) const;
%Docstring
Writes the component's style definition to an XML element.

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

void readXml( const QDomElement &elem, const QDomDocument &doc );
%Docstring
Reads the component's style definition from an XML element.

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

static QString styleName( Style s );
%Docstring
Gets name for style, used in project file
Returns the name for a style component as a string.

This is a non-localised version, for internal use.

.. seealso:: :py:func:`styleFromName`

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

static Style styleFromName( const QString &styleName );
%Docstring
Gets style from name, used in project file
Returns the style from name string.

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

static QString styleLabel( Style s );
%Docstring
Gets style label, translated, used in UI
Returns a translated string representing a style component, for use in UI.

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

};
Expand Down
20 changes: 13 additions & 7 deletions src/core/qgslegendstyle.cpp
Expand Up @@ -29,7 +29,7 @@

QgsLegendStyle::QgsLegendStyle()
{
//get default composer font from settings
//get default layout font from settings
QgsSettings settings;
QString defaultFontString = settings.value( QStringLiteral( "LayoutDesigner/defaultFont" ), QVariant(), QgsSettings::Gui ).toString();
if ( !defaultFontString.isEmpty() )
Expand Down Expand Up @@ -112,12 +112,18 @@ QString QgsLegendStyle::styleName( Style s )

QgsLegendStyle::Style QgsLegendStyle::styleFromName( const QString &styleName )
{
if ( styleName == QLatin1String( "hidden" ) ) return Hidden;
else if ( styleName == QLatin1String( "title" ) ) return Title;
else if ( styleName == QLatin1String( "group" ) ) return Group;
else if ( styleName == QLatin1String( "subgroup" ) ) return Subgroup;
else if ( styleName == QLatin1String( "symbol" ) ) return Symbol;
else if ( styleName == QLatin1String( "symbolLabel" ) ) return SymbolLabel;
if ( styleName == QLatin1String( "hidden" ) )
return Hidden;
else if ( styleName == QLatin1String( "title" ) )
return Title;
else if ( styleName == QLatin1String( "group" ) )
return Group;
else if ( styleName == QLatin1String( "subgroup" ) )
return Subgroup;
else if ( styleName == QLatin1String( "symbol" ) )
return Symbol;
else if ( styleName == QLatin1String( "symbolLabel" ) )
return SymbolLabel;
return Undefined;
}

Expand Down
83 changes: 63 additions & 20 deletions src/core/qgslegendstyle.h
Expand Up @@ -29,55 +29,79 @@

/**
* \ingroup core
* Composer legend components style
* Contains detailed styling information relating to how a layout legend should be rendered.
*/
class CORE_EXPORT QgsLegendStyle
{
public:

//! Component of legends which can be styled
enum Style
{
Undefined, //!< Should not happen, only if corrupted project file
Hidden, //!< Special style, item is hidden including margins around
Title,
Group,
Subgroup, //!< Layer
Symbol, //!< Symbol without label
SymbolLabel
Title, //!< Legend title
Group, //!< Legend group title
Subgroup, //!< Legend subgroup title
Symbol, //!< Symbol icon (excluding label)
SymbolLabel, //!< Symbol label (excluding icon)
};

//! Margin side
// TODO QGIS 4.0 - use Qt enum instead

//! Margin sides
enum Side
{
Top = 0,
Bottom = 1,
Left = 2,
Right = 3
Top = 0, //!< Top side
Bottom = 1, //!< Bottom side
Left = 2, //!< Left side
Right = 3, //!< Right side
};

QgsLegendStyle();

/**
* The font for this style.
* Returns the font used for rendering this legend component.
* \see setFont()
*/
QFont font() const { return mFont; }

/**
* The font for this style.
* Sets the \a font used for rendering this legend component.
* \see font()
*/
void setFont( const QFont &font ) { mFont = font; }

/**
* Modifiable reference to font.
* Returns a modifiable reference to the component's font.
*
* \see setFont()
* \note Not available in Python bindings
*/
SIP_SKIP QFont &rfont() { return mFont; }

/**
* Returns the margin (in mm) for the specified \a side of the component.
*
* \note Not all legend components respect all margin side settings!
*
* \see setMargin()
*/
double margin( Side side ) { return mMarginMap.value( side ); }

/**
* Sets the \a margin (in mm) for the specified \a side of the component.
*
* \note Not all legend components respect all margin side settings!
*
* \see margin()
*/
void setMargin( Side side, double margin ) { mMarginMap[side] = margin; }

//! Sets all margins
/**
* Sets all margin sides to the same \a margin size (in mm).
* \see margin()
*/
void setMargin( double margin );

/**
Expand All @@ -96,24 +120,43 @@ class CORE_EXPORT QgsLegendStyle
*/
void setAlignment( Qt::Alignment alignment ) { mAlignment = alignment; }

/**
* Writes the component's style definition to an XML element.
* \see readXml()
*/
void writeXml( const QString &name, QDomElement &elem, QDomDocument &doc ) const;

/**
* Reads the component's style definition from an XML element.
* \see writeXml()
*/
void readXml( const QDomElement &elem, const QDomDocument &doc );

//! Gets name for style, used in project file
/**
* Returns the name for a style component as a string.
*
* This is a non-localised version, for internal use.
*
* \see styleFromName()
* \see styleLabel()
*/
static QString styleName( Style s );

//! Gets style from name, used in project file
/**
* Returns the style from name string.
* \see styleName()
*/
static Style styleFromName( const QString &styleName );

//! Gets style label, translated, used in UI
/**
* Returns a translated string representing a style component, for use in UI.
* \see styleName()
*/
static QString styleLabel( Style s );

private:
QFont mFont;
//! Space around element
QMap<Side, double> mMarginMap;

Qt::Alignment mAlignment = Qt::AlignLeft;
};

Expand Down

0 comments on commit 99d6524

Please sign in to comment.