QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
Public Member Functions | List of all members
QgsLegendSettings Class Reference

The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLegendRenderer. More...

#include <qgslegendsettings.h>

Public Member Functions

 QgsLegendSettings ()
 
double boxSpace () const
 
int columnCount () const
 
double columnSpace () const
 
int dpi () const
 
bool drawRasterStroke () const
 Returns whether a stroke will be drawn around raster symbol items. More...
 
void drawText (QPainter *p, double x, double y, const QString &text, const QFont &font) const
 Draws Text. More...
 
void drawText (QPainter *p, const QRectF &rect, const QString &text, const QFont &font, Qt::AlignmentFlag halignment=Qt::AlignLeft, Qt::AlignmentFlag valignment=Qt::AlignTop, int flags=Qt::TextWordWrap) const
 Like the above, but with a rectangle for multiline text. More...
 
bool equalColumnWidth () const
 
QStringList evaluateItemText (const QString &text, const QgsExpressionContext &context) const
 Splits a string using the wrap char taking into account handling empty wrap char which means no wrapping. More...
 
double fontAscentMillimeters (const QFont &font) const
 Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE. More...
 
QColor fontColor () const
 
double fontDescentMillimeters (const QFont &font) const
 Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE. More...
 
double fontHeightCharacterMM (const QFont &font, QChar c) const
 Returns the font height of a character in millimeters. More...
 
QColor layerFontColor () const
 Returns layer font color, defaults to fontColor() More...
 
double lineSpacing () const
 
double mapScale () const
 Returns the legend map scale. More...
 
double mapUnitsPerPixel () const
 Returns the factor of map units per pixel for symbols with size given in map units calculated by dpi and mmPerMapUnit. More...
 
double mmPerMapUnit () const
 
double pixelFontSize (double pointSize) const
 Calculates font to from point size to pixel size. More...
 
QColor rasterStrokeColor () const
 Returns the stroke color for the stroke drawn around raster symbol items. More...
 
double rasterStrokeWidth () const
 Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items. More...
 
QgsLegendStylerstyle (QgsLegendStyle::Style s)
 Returns reference to modifiable style. More...
 
QFont scaledFontPixelSize (const QFont &font) const
 Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE. More...
 
void setBoxSpace (double s)
 
void setColumnCount (int c)
 
void setColumnSpace (double s)
 
void setDpi (int dpi)
 
void setDrawRasterStroke (bool enabled)
 Sets whether a stroke will be drawn around raster symbol items. More...
 
void setEqualColumnWidth (bool s)
 
void setFontColor (const QColor &c)
 
void setLayerFontColor (const QColor &fontColor)
 Sets layer font color to fontColor Overrides fontColor() More...
 
void setLineSpacing (double s)
 
void setMapScale (double scale)
 Sets the legend map scale. More...
 
void setMapUnitsPerPixel (double mapUnitsPerPixel)
 Sets the mmPerMapUnit calculated by mapUnitsPerPixel mostly taken from the map settings. More...
 
void setMmPerMapUnit (double mmPerMapUnit)
 
void setRasterStrokeColor (const QColor &color)
 Sets the stroke color for the stroke drawn around raster symbol items. More...
 
void setRasterStrokeWidth (double width)
 Sets the stroke width for the stroke drawn around raster symbol items. More...
 
void setSplitLayer (bool s)
 
void setStyle (QgsLegendStyle::Style s, const QgsLegendStyle &style)
 
void setSymbolAlignment (Qt::AlignmentFlag alignment)
 Sets the alignment for placement of legend symbols. More...
 
void setSymbolSize (QSizeF s)
 
void setTitle (const QString &t)
 
void setTitleAlignment (Qt::AlignmentFlag alignment)
 Sets the alignment of the legend title. More...
 
void setUseAdvancedEffects (bool use)
 
void setWmsLegendSize (QSizeF s)
 
void setWrapChar (const QString &t)
 
bool splitLayer () const
 
QStringList splitStringForWrapping (const QString &stringToSplt) const
 Splits a string using the wrap char taking into account handling empty wrap char which means no wrapping. More...
 
QgsLegendStyle style (QgsLegendStyle::Style s) const
 Returns style. More...
 
Qt::AlignmentFlag symbolAlignment () const
 Returns the alignment for placement of legend symbols. More...
 
QSizeF symbolSize () const
 
double textWidthMillimeters (const QFont &font, const QString &text) const
 Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE. More...
 
QString title () const
 
Qt::AlignmentFlag titleAlignment () const
 Returns the alignment of the legend title. More...
 
bool useAdvancedEffects () const
 
QSizeF wmsLegendSize () const
 
QString wrapChar () const
 

Detailed Description

The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLegendRenderer.

The content of the legend is given in QgsLegendModel class.

Since
QGIS 2.6

Definition at line 38 of file qgslegendsettings.h.

Constructor & Destructor Documentation

◆ QgsLegendSettings()

QgsLegendSettings::QgsLegendSettings ( )

Definition at line 22 of file qgslegendsettings.cpp.

Member Function Documentation

◆ boxSpace()

double QgsLegendSettings::boxSpace ( ) const
inline

Definition at line 68 of file qgslegendsettings.h.

◆ columnCount()

int QgsLegendSettings::columnCount ( ) const
inline

Definition at line 77 of file qgslegendsettings.h.

◆ columnSpace()

double QgsLegendSettings::columnSpace ( ) const
inline

Definition at line 74 of file qgslegendsettings.h.

◆ dpi()

int QgsLegendSettings::dpi ( ) const
inline

Definition at line 231 of file qgslegendsettings.h.

◆ drawRasterStroke()

bool QgsLegendSettings::drawRasterStroke ( ) const
inline

Returns whether a stroke will be drawn around raster symbol items.

See also
setDrawRasterStroke()
rasterStrokeColor()
rasterStrokeWidth()
Since
QGIS 2.12

Definition at line 137 of file qgslegendsettings.h.

◆ drawText() [1/2]

void QgsLegendSettings::drawText ( QPainter *  p,
double  x,
double  y,
const QString &  text,
const QFont &  font 
) const

Draws Text.

Takes care about all the composer specific issues (calculation to pixel, scaling of font and painter to work around the Qt font bug)

Definition at line 70 of file qgslegendsettings.cpp.

◆ drawText() [2/2]

void QgsLegendSettings::drawText ( QPainter *  p,
const QRectF &  rect,
const QString &  text,
const QFont &  font,
Qt::AlignmentFlag  halignment = Qt::AlignLeft,
Qt::AlignmentFlag  valignment = Qt::AlignTop,
int  flags = Qt::TextWordWrap 
) const

Like the above, but with a rectangle for multiline text.

Parameters
ppainter to use
rectrectangle to draw into
texttext to draw
fontfont to use
halignmentoptional horizontal alignment
valignmentoptional vertical alignment
flagsallows for passing Qt::TextFlags to control appearance of rendered text

Definition at line 83 of file qgslegendsettings.cpp.

◆ equalColumnWidth()

bool QgsLegendSettings::equalColumnWidth ( ) const
inline

Definition at line 83 of file qgslegendsettings.h.

◆ evaluateItemText()

QStringList QgsLegendSettings::evaluateItemText ( const QString &  text,
const QgsExpressionContext context 
) const

Splits a string using the wrap char taking into account handling empty wrap char which means no wrapping.

Returns the actual text to render for a legend item, split into separate lines.

The expression context argument is used to correctly evaluated expressions contained within legend item text.

Since
QGIS 3.6

Definition at line 50 of file qgslegendsettings.cpp.

◆ fontAscentMillimeters()

double QgsLegendSettings::fontAscentMillimeters ( const QFont &  font) const

Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.

Definition at line 126 of file qgslegendsettings.cpp.

◆ fontColor()

QColor QgsLegendSettings::fontColor ( ) const
inline

Definition at line 86 of file qgslegendsettings.h.

◆ fontDescentMillimeters()

double QgsLegendSettings::fontDescentMillimeters ( const QFont &  font) const

Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.

Definition at line 133 of file qgslegendsettings.cpp.

◆ fontHeightCharacterMM()

double QgsLegendSettings::fontHeightCharacterMM ( const QFont &  font,
QChar  c 
) const

Returns the font height of a character in millimeters.

Definition at line 119 of file qgslegendsettings.cpp.

◆ layerFontColor()

QColor QgsLegendSettings::layerFontColor ( ) const
inline

Returns layer font color, defaults to fontColor()

See also
setLayerFontColor()
fontColor()
Since
QGIS 3.4.7

Definition at line 95 of file qgslegendsettings.h.

◆ lineSpacing()

double QgsLegendSettings::lineSpacing ( ) const
inline

Definition at line 194 of file qgslegendsettings.h.

◆ mapScale()

double QgsLegendSettings::mapScale ( ) const
inline

Returns the legend map scale.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

See also
setMapScale()

Definition at line 208 of file qgslegendsettings.h.

◆ mapUnitsPerPixel()

double QgsLegendSettings::mapUnitsPerPixel ( ) const

Returns the factor of map units per pixel for symbols with size given in map units calculated by dpi and mmPerMapUnit.

See also
setMapUnitsPerPixel()
Since
QGIS 3.8

Definition at line 40 of file qgslegendsettings.cpp.

◆ mmPerMapUnit()

double QgsLegendSettings::mmPerMapUnit ( ) const
inline

Definition at line 197 of file qgslegendsettings.h.

◆ pixelFontSize()

double QgsLegendSettings::pixelFontSize ( double  pointSize) const

Calculates font to from point size to pixel size.

Definition at line 107 of file qgslegendsettings.cpp.

◆ rasterStrokeColor()

QColor QgsLegendSettings::rasterStrokeColor ( ) const
inline

Returns the stroke color for the stroke drawn around raster symbol items.

The stroke is only drawn if drawRasterStroke() is true.

See also
setRasterStrokeColor()
drawRasterStroke()
rasterStrokeWidth()
Since
QGIS 2.12

Definition at line 157 of file qgslegendsettings.h.

◆ rasterStrokeWidth()

double QgsLegendSettings::rasterStrokeWidth ( ) const
inline

Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items.

The stroke is only drawn if drawRasterStroke() is true.

See also
setRasterStrokeWidth()
drawRasterStroke()
rasterStrokeColor()
Since
QGIS 2.12

Definition at line 178 of file qgslegendsettings.h.

◆ rstyle()

QgsLegendStyle& QgsLegendSettings::rstyle ( QgsLegendStyle::Style  s)
inline

Returns reference to modifiable style.

Note
Not available in Python bindings.

Definition at line 63 of file qgslegendsettings.h.

◆ scaledFontPixelSize()

QFont QgsLegendSettings::scaledFontPixelSize ( const QFont &  font) const

Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE.

Definition at line 99 of file qgslegendsettings.cpp.

◆ setBoxSpace()

void QgsLegendSettings::setBoxSpace ( double  s)
inline

Definition at line 69 of file qgslegendsettings.h.

◆ setColumnCount()

void QgsLegendSettings::setColumnCount ( int  c)
inline

Definition at line 78 of file qgslegendsettings.h.

◆ setColumnSpace()

void QgsLegendSettings::setColumnSpace ( double  s)
inline

Definition at line 75 of file qgslegendsettings.h.

◆ setDpi()

void QgsLegendSettings::setDpi ( int  dpi)
inline

Definition at line 232 of file qgslegendsettings.h.

◆ setDrawRasterStroke()

void QgsLegendSettings::setDrawRasterStroke ( bool  enabled)
inline

Sets whether a stroke will be drawn around raster symbol items.

Parameters
enabledset to true to draw borders
See also
drawRasterStroke()
setRasterStrokeColor()
setRasterStrokeWidth()
Since
QGIS 2.12

Definition at line 147 of file qgslegendsettings.h.

◆ setEqualColumnWidth()

void QgsLegendSettings::setEqualColumnWidth ( bool  s)
inline

Definition at line 84 of file qgslegendsettings.h.

◆ setFontColor()

void QgsLegendSettings::setFontColor ( const QColor &  c)
inline

Definition at line 87 of file qgslegendsettings.h.

◆ setLayerFontColor()

void QgsLegendSettings::setLayerFontColor ( const QColor &  fontColor)
inline

Sets layer font color to fontColor Overrides fontColor()

See also
layerFontColor()
fontColor()
Since
QGIS 3.4.7

Definition at line 104 of file qgslegendsettings.h.

◆ setLineSpacing()

void QgsLegendSettings::setLineSpacing ( double  s)
inline

Definition at line 195 of file qgslegendsettings.h.

◆ setMapScale()

void QgsLegendSettings::setMapScale ( double  scale)
inline

Sets the legend map scale.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

See also
mapScale()

Definition at line 215 of file qgslegendsettings.h.

◆ setMapUnitsPerPixel()

void QgsLegendSettings::setMapUnitsPerPixel ( double  mapUnitsPerPixel)

Sets the mmPerMapUnit calculated by mapUnitsPerPixel mostly taken from the map settings.

See also
mapUnitsPerPixel()
Since
QGIS 3.8

Definition at line 45 of file qgslegendsettings.cpp.

◆ setMmPerMapUnit()

void QgsLegendSettings::setMmPerMapUnit ( double  mmPerMapUnit)
inline

Definition at line 198 of file qgslegendsettings.h.

◆ setRasterStrokeColor()

void QgsLegendSettings::setRasterStrokeColor ( const QColor &  color)
inline

Sets the stroke color for the stroke drawn around raster symbol items.

The stroke is only drawn if drawRasterStroke() is true.

Parameters
colorstroke color
See also
rasterStrokeColor()
setDrawRasterStroke()
setRasterStrokeWidth()
Since
QGIS 2.12

Definition at line 168 of file qgslegendsettings.h.

◆ setRasterStrokeWidth()

void QgsLegendSettings::setRasterStrokeWidth ( double  width)
inline

Sets the stroke width for the stroke drawn around raster symbol items.

The stroke is only drawn if drawRasterStroke() is true.

Parameters
widthstroke width in millimeters
See also
rasterStrokeWidth()
setDrawRasterStroke()
setRasterStrokeColor()
Since
QGIS 2.12

Definition at line 189 of file qgslegendsettings.h.

◆ setSplitLayer()

void QgsLegendSettings::setSplitLayer ( bool  s)
inline

Definition at line 81 of file qgslegendsettings.h.

◆ setStyle()

void QgsLegendSettings::setStyle ( QgsLegendStyle::Style  s,
const QgsLegendStyle style 
)
inline

Definition at line 66 of file qgslegendsettings.h.

◆ setSymbolAlignment()

void QgsLegendSettings::setSymbolAlignment ( Qt::AlignmentFlag  alignment)
inline

Sets the alignment for placement of legend symbols.

Only Qt::AlignLeft or Qt::AlignRight are supported values.

See also
symbolAlignment()
Since
QGIS 3.10

Definition at line 118 of file qgslegendsettings.h.

◆ setSymbolSize()

void QgsLegendSettings::setSymbolSize ( QSizeF  s)
inline

Definition at line 108 of file qgslegendsettings.h.

◆ setTitle()

void QgsLegendSettings::setTitle ( const QString &  t)
inline

Definition at line 43 of file qgslegendsettings.h.

◆ setTitleAlignment()

void QgsLegendSettings::setTitleAlignment ( Qt::AlignmentFlag  alignment)
inline

Sets the alignment of the legend title.

See also
titleAlignment()

Definition at line 56 of file qgslegendsettings.h.

◆ setUseAdvancedEffects()

void QgsLegendSettings::setUseAdvancedEffects ( bool  use)
inline

Definition at line 201 of file qgslegendsettings.h.

◆ setWmsLegendSize()

void QgsLegendSettings::setWmsLegendSize ( QSizeF  s)
inline

Definition at line 192 of file qgslegendsettings.h.

◆ setWrapChar()

void QgsLegendSettings::setWrapChar ( const QString &  t)
inline

Definition at line 71 of file qgslegendsettings.h.

◆ splitLayer()

bool QgsLegendSettings::splitLayer ( ) const
inline

Definition at line 80 of file qgslegendsettings.h.

◆ splitStringForWrapping()

QStringList QgsLegendSettings::splitStringForWrapping ( const QString &  stringToSplt) const

Splits a string using the wrap char taking into account handling empty wrap char which means no wrapping.

Definition at line 56 of file qgslegendsettings.cpp.

◆ style()

QgsLegendStyle QgsLegendSettings::style ( QgsLegendStyle::Style  s) const
inline

Returns style.

Definition at line 65 of file qgslegendsettings.h.

◆ symbolAlignment()

Qt::AlignmentFlag QgsLegendSettings::symbolAlignment ( ) const
inline

Returns the alignment for placement of legend symbols.

Only Qt::AlignLeft or Qt::AlignRight are supported values.

See also
setSymbolAlignment()
Since
QGIS 3.10

Definition at line 128 of file qgslegendsettings.h.

◆ symbolSize()

QSizeF QgsLegendSettings::symbolSize ( ) const
inline

Definition at line 107 of file qgslegendsettings.h.

◆ textWidthMillimeters()

double QgsLegendSettings::textWidthMillimeters ( const QFont &  font,
const QString &  text 
) const

Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.

Definition at line 112 of file qgslegendsettings.cpp.

◆ title()

QString QgsLegendSettings::title ( ) const
inline

Definition at line 44 of file qgslegendsettings.h.

◆ titleAlignment()

Qt::AlignmentFlag QgsLegendSettings::titleAlignment ( ) const
inline

Returns the alignment of the legend title.

See also
setTitleAlignment()

Definition at line 50 of file qgslegendsettings.h.

◆ useAdvancedEffects()

bool QgsLegendSettings::useAdvancedEffects ( ) const
inline

Definition at line 200 of file qgslegendsettings.h.

◆ wmsLegendSize()

QSizeF QgsLegendSettings::wmsLegendSize ( ) const
inline

Definition at line 191 of file qgslegendsettings.h.

◆ wrapChar()

QString QgsLegendSettings::wrapChar ( ) const
inline

Definition at line 72 of file qgslegendsettings.h.


The documentation for this class was generated from the following files: