QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLegendRenderer. The content of the legend is given in QgsLegendModel class. More...
#include <qgslegendsettings.h>
Public Member Functions | |
QgsLegendSettings () | |
double | boxSpace () const |
Returns the legend box space (in millimeters), which is the empty margin around the inside of the legend's rectangle. More... | |
int | columnCount () const |
Returns the desired minimum number of columns to show in the legend. More... | |
double | columnSpace () const |
Returns the margin space between adjacent columns (in millimeters). More... | |
Q_DECL_DEPRECATED int | dpi () const |
bool | drawRasterStroke () const |
Returns whether a stroke will be drawn around raster symbol items. 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... | |
void | drawText (QPainter *p, double x, double y, const QString &text, const QFont &font) const |
Draws Text. More... | |
bool | equalColumnWidth () const |
Returns true if all columns should have equal widths. More... | |
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 |
Returns the font color used for legend items. More... | |
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 |
Returns the line spacing to use between lines of legend text. More... | |
Q_DECL_DEPRECATED double | mapScale () const |
Returns the legend map scale. More... | |
Q_DECL_DEPRECATED 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... | |
Q_DECL_DEPRECATED 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... | |
QgsLegendStyle & | rstyle (QgsLegendStyle::Style s) |
Returns modifiable reference to the style for a legend component. 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) |
Sets the legend box space (in millimeters), which is the empty margin around the inside of the legend's rectangle. More... | |
void | setColumnCount (int c) |
Sets the desired minimum number of columns to show in the legend. More... | |
void | setColumnSpace (double s) |
Sets the margin space between adjacent columns (in millimeters). More... | |
Q_DECL_DEPRECATED void | setDpi (int dpi) |
void | setDrawRasterStroke (bool enabled) |
Sets whether a stroke will be drawn around raster symbol items. More... | |
void | setEqualColumnWidth (bool s) |
Sets whether all columns should have equal widths. More... | |
void | setFontColor (const QColor &c) |
Sets the font color used for legend items. More... | |
void | setLayerFontColor (const QColor &fontColor) |
Sets layer font color to fontColor Overrides fontColor() More... | |
void | setLineSpacing (double s) |
Sets the line spacing to use between lines of legend text. More... | |
Q_DECL_DEPRECATED void | setMapScale (double scale) |
Sets the legend map scale. More... | |
Q_DECL_DEPRECATED void | setMapUnitsPerPixel (double mapUnitsPerPixel) |
Sets the mmPerMapUnit calculated by mapUnitsPerPixel mostly taken from the map settings. More... | |
Q_DECL_DEPRECATED 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) |
Sets whether layer components can be split over multiple columns. More... | |
void | setStyle (QgsLegendStyle::Style s, const QgsLegendStyle &style) |
Sets the style for a legend component. More... | |
void | setSymbolAlignment (Qt::AlignmentFlag alignment) |
Sets the alignment for placement of legend symbols. More... | |
void | setSymbolSize (QSizeF s) |
Sets the default symbol size (in millimeters) used for legend items. More... | |
void | setTitle (const QString &t) |
Sets the title for the legend, which will be rendered above all legend items. More... | |
void | setTitleAlignment (Qt::AlignmentFlag alignment) |
Sets the alignment of the legend title. More... | |
Q_DECL_DEPRECATED void | setUseAdvancedEffects (bool use) |
void | setWmsLegendSize (QSizeF s) |
Sets the desired size (in millimeters) of WMS legend graphics shown in the legend. More... | |
void | setWrapChar (const QString &t) |
Sets a string to use as a wrapping character. More... | |
bool | splitLayer () const |
Returns true if layer components can be split over multiple columns. More... | |
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 the style for a legend component. More... | |
Qt::AlignmentFlag | symbolAlignment () const |
Returns the alignment for placement of legend symbols. More... | |
QSizeF | symbolSize () const |
Returns the default symbol size (in millimeters) used for legend items. More... | |
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 |
Returns the title for the legend, which will be rendered above all legend items. More... | |
Qt::AlignmentFlag | titleAlignment () const |
Returns the alignment of the legend title. More... | |
Q_DECL_DEPRECATED bool | useAdvancedEffects () const |
QSizeF | wmsLegendSize () const |
Returns the size (in millimeters) of WMS legend graphics shown in the legend. More... | |
QString | wrapChar () const |
Returns the string used as a wrapping character. More... | |
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLegendRenderer. The content of the legend is given in QgsLegendModel class.
Definition at line 38 of file qgslegendsettings.h.
QgsLegendSettings::QgsLegendSettings | ( | ) |
Definition at line 22 of file qgslegendsettings.cpp.
|
inline |
Returns the legend box space (in millimeters), which is the empty margin around the inside of the legend's rectangle.
Definition at line 96 of file qgslegendsettings.h.
|
inline |
Returns the desired minimum number of columns to show in the legend.
If legend components have forced column breaks then the actual number of columns in the rendered legend may be larger than this value.
Definition at line 148 of file qgslegendsettings.h.
|
inline |
Returns the margin space between adjacent columns (in millimeters).
Definition at line 131 of file qgslegendsettings.h.
int QgsLegendSettings::dpi | ( | ) | const |
Definition at line 80 of file qgslegendsettings.cpp.
|
inline |
Returns whether a stroke will be drawn around raster symbol items.
Definition at line 264 of file qgslegendsettings.h.
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.
p | painter to use |
rect | rectangle to draw into |
text | text to draw |
font | font to use |
halignment | optional horizontal alignment |
valignment | optional vertical alignment |
flags | allows for passing Qt::TextFlags to control appearance of rendered text |
Definition at line 128 of file qgslegendsettings.cpp.
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 115 of file qgslegendsettings.cpp.
|
inline |
Returns true
if all columns should have equal widths.
If false
is returned then columns will be individually resized to their minimum possible width.
Definition at line 181 of file qgslegendsettings.h.
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.
Definition at line 90 of file qgslegendsettings.cpp.
double QgsLegendSettings::fontAscentMillimeters | ( | const QFont & | font | ) | const |
Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.
Definition at line 171 of file qgslegendsettings.cpp.
|
inline |
Returns the font color used for legend items.
Definition at line 197 of file qgslegendsettings.h.
double QgsLegendSettings::fontDescentMillimeters | ( | const QFont & | font | ) | const |
Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.
Definition at line 178 of file qgslegendsettings.cpp.
double QgsLegendSettings::fontHeightCharacterMM | ( | const QFont & | font, |
QChar | c | ||
) | const |
Returns the font height of a character in millimeters.
Definition at line 164 of file qgslegendsettings.cpp.
|
inline |
Returns layer font color, defaults to fontColor()
Definition at line 212 of file qgslegendsettings.h.
|
inline |
Returns the line spacing to use between lines of legend text.
Definition at line 337 of file qgslegendsettings.h.
double QgsLegendSettings::mapScale | ( | ) | const |
Returns the legend map scale.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
Definition at line 60 of file qgslegendsettings.cpp.
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.
Definition at line 70 of file qgslegendsettings.cpp.
double QgsLegendSettings::mmPerMapUnit | ( | ) | const |
Definition at line 40 of file qgslegendsettings.cpp.
double QgsLegendSettings::pixelFontSize | ( | double | pointSize | ) | const |
Calculates font to from point size to pixel size.
Definition at line 152 of file qgslegendsettings.cpp.
|
inline |
Returns the stroke color for the stroke drawn around raster symbol items.
The stroke is only drawn if drawRasterStroke() is true
.
Definition at line 284 of file qgslegendsettings.h.
|
inline |
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items.
The stroke is only drawn if drawRasterStroke() is true
.
Definition at line 305 of file qgslegendsettings.h.
|
inline |
Returns modifiable reference to the style for a legend component.
Definition at line 74 of file qgslegendsettings.h.
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 144 of file qgslegendsettings.cpp.
|
inline |
Sets the legend box space (in millimeters), which is the empty margin around the inside of the legend's rectangle.
Definition at line 104 of file qgslegendsettings.h.
|
inline |
Sets the desired minimum number of columns to show in the legend.
If legend components have forced column breaks then the actual number of columns in the rendered legend may be larger than this value.
Definition at line 158 of file qgslegendsettings.h.
|
inline |
Sets the margin space between adjacent columns (in millimeters).
Definition at line 138 of file qgslegendsettings.h.
void QgsLegendSettings::setDpi | ( | int | dpi | ) |
Definition at line 85 of file qgslegendsettings.cpp.
|
inline |
Sets whether a stroke will be drawn around raster symbol items.
enabled | set to true to draw borders |
Definition at line 274 of file qgslegendsettings.h.
|
inline |
Sets whether all columns should have equal widths.
If false
, then then columns will be individually resized to their minimum possible width.
Definition at line 190 of file qgslegendsettings.h.
|
inline |
Sets the font color used for legend items.
Definition at line 204 of file qgslegendsettings.h.
|
inline |
Sets layer font color to fontColor Overrides fontColor()
Definition at line 221 of file qgslegendsettings.h.
|
inline |
Sets the line spacing to use between lines of legend text.
Definition at line 344 of file qgslegendsettings.h.
void QgsLegendSettings::setMapScale | ( | double | scale | ) |
Sets the legend map scale.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
Definition at line 65 of file qgslegendsettings.cpp.
void QgsLegendSettings::setMapUnitsPerPixel | ( | double | mapUnitsPerPixel | ) |
Sets the mmPerMapUnit calculated by mapUnitsPerPixel mostly taken from the map settings.
Definition at line 75 of file qgslegendsettings.cpp.
void QgsLegendSettings::setMmPerMapUnit | ( | double | mmPerMapUnit | ) |
Definition at line 45 of file qgslegendsettings.cpp.
|
inline |
Sets the stroke color for the stroke drawn around raster symbol items.
The stroke is only drawn if drawRasterStroke() is true
.
color | stroke color |
Definition at line 295 of file qgslegendsettings.h.
|
inline |
Sets the stroke width for the stroke drawn around raster symbol items.
The stroke is only drawn if drawRasterStroke() is true
.
width | stroke width in millimeters |
Definition at line 316 of file qgslegendsettings.h.
|
inline |
Sets whether layer components can be split over multiple columns.
Definition at line 172 of file qgslegendsettings.h.
|
inline |
Sets the style for a legend component.
Definition at line 88 of file qgslegendsettings.h.
|
inline |
Sets the alignment for placement of legend symbols.
Only Qt::AlignLeft or Qt::AlignRight are supported values.
Definition at line 245 of file qgslegendsettings.h.
|
inline |
Sets the default symbol size (in millimeters) used for legend items.
Definition at line 235 of file qgslegendsettings.h.
|
inline |
Sets the title for the legend, which will be rendered above all legend items.
Definition at line 48 of file qgslegendsettings.h.
|
inline |
Sets the alignment of the legend title.
Definition at line 67 of file qgslegendsettings.h.
void QgsLegendSettings::setUseAdvancedEffects | ( | bool | use | ) |
Definition at line 55 of file qgslegendsettings.cpp.
|
inline |
Sets the desired size (in millimeters) of WMS legend graphics shown in the legend.
Definition at line 330 of file qgslegendsettings.h.
|
inline |
Sets a string to use as a wrapping character.
Whenever this string is encountered inside legend component text it will be automatically replaced with a new line character.
Definition at line 114 of file qgslegendsettings.h.
|
inline |
Returns true
if layer components can be split over multiple columns.
Definition at line 165 of file qgslegendsettings.h.
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 96 of file qgslegendsettings.cpp.
|
inline |
Returns the style for a legend component.
Definition at line 81 of file qgslegendsettings.h.
|
inline |
Returns the alignment for placement of legend symbols.
Only Qt::AlignLeft or Qt::AlignRight are supported values.
Definition at line 255 of file qgslegendsettings.h.
|
inline |
Returns the default symbol size (in millimeters) used for legend items.
Definition at line 228 of file qgslegendsettings.h.
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 157 of file qgslegendsettings.cpp.
|
inline |
Returns the title for the legend, which will be rendered above all legend items.
Definition at line 55 of file qgslegendsettings.h.
|
inline |
Returns the alignment of the legend title.
Definition at line 61 of file qgslegendsettings.h.
bool QgsLegendSettings::useAdvancedEffects | ( | ) | const |
Definition at line 50 of file qgslegendsettings.cpp.
|
inline |
Returns the size (in millimeters) of WMS legend graphics shown in the legend.
Definition at line 323 of file qgslegendsettings.h.
|
inline |
Returns the string used as a wrapping character.
Whenever this string is encountered inside legend component text it will be automatically replaced with a new line character.
Definition at line 124 of file qgslegendsettings.h.