QGIS API Documentation 3.41.0-Master (45a0abf3bec)
|
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 |
Returns the legend box space (in millimeters), which is the empty margin around the inside of the legend's rectangle. | |
int | columnCount () const |
Returns the desired minimum number of columns to show in the legend. | |
double | columnSpace () const |
Returns the margin space between adjacent columns (in millimeters). | |
Q_DECL_DEPRECATED int | dpi () const |
bool | drawRasterStroke () const |
Returns whether a stroke will be drawn around raster symbol items. | |
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. | |
void | drawText (QPainter *p, double x, double y, const QString &text, const QFont &font) const |
Draws Text. | |
bool | equalColumnWidth () const |
Returns true if all columns should have equal widths. | |
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. | |
double | fontAscentMillimeters (const QFont &font) const |
Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE. | |
Q_DECL_DEPRECATED QColor | fontColor () const |
Returns the font color used for legend items. | |
double | fontDescentMillimeters (const QFont &font) const |
Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE. | |
double | fontHeightCharacterMM (const QFont &font, QChar c) const |
Returns the font height of a character in millimeters. | |
Qgis::LegendJsonRenderFlags | jsonRenderFlags () const |
Returns the JSON export flags. | |
Q_DECL_DEPRECATED QColor | layerFontColor () const |
Returns layer font color, defaults to fontColor() | |
Q_DECL_DEPRECATED double | lineSpacing () const |
Returns the line spacing to use between lines of legend text. | |
Q_DECL_DEPRECATED double | mapScale () const |
Returns the legend map scale. | |
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. | |
double | maximumSymbolSize () const |
Returns the maximum symbol size (in mm). | |
double | minimumSymbolSize () const |
Returns the minimum symbol size (in mm). | |
Q_DECL_DEPRECATED double | mmPerMapUnit () const |
double | pixelFontSize (double pointSize) const |
Calculates font to from point size to pixel size. | |
QColor | rasterStrokeColor () const |
Returns the stroke color for the stroke drawn around raster symbol items. | |
double | rasterStrokeWidth () const |
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items. | |
QgsLegendStyle & | rstyle (QgsLegendStyle::Style s) |
Returns modifiable reference to the style for a legend component. | |
QFont | scaledFontPixelSize (const QFont &font) const |
Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE. | |
void | setBoxSpace (double s) |
Sets the legend box space (in millimeters), which is the empty margin around the inside of the legend's rectangle. | |
void | setColumnCount (int c) |
Sets the desired minimum number of columns to show in the legend. | |
void | setColumnSpace (double s) |
Sets the margin space between adjacent columns (in millimeters). | |
Q_DECL_DEPRECATED void | setDpi (int dpi) |
void | setDrawRasterStroke (bool enabled) |
Sets whether a stroke will be drawn around raster symbol items. | |
void | setEqualColumnWidth (bool s) |
Sets whether all columns should have equal widths. | |
Q_DECL_DEPRECATED void | setFontColor (const QColor &c) |
Sets the font color used for legend items. | |
void | setJsonRenderFlags (const Qgis::LegendJsonRenderFlags &jsonRenderFlags) |
Sets the the JSON export flags to jsonRenderFlags. | |
Q_DECL_DEPRECATED void | setLayerFontColor (const QColor &fontColor) |
Sets layer font color to fontColor Overrides fontColor() | |
Q_DECL_DEPRECATED void | setLineSpacing (double s) |
Sets the line spacing to use between lines of legend text. | |
Q_DECL_DEPRECATED void | setMapScale (double scale) |
Sets the legend map scale. | |
Q_DECL_DEPRECATED void | setMapUnitsPerPixel (double mapUnitsPerPixel) |
Sets the mmPerMapUnit calculated by mapUnitsPerPixel mostly taken from the map settings. | |
void | setMaximumSymbolSize (double size) |
Set the maximum symbol size for symbol (in millimeters). | |
void | setMinimumSymbolSize (double size) |
Set the minimum symbol size for symbol (in millimeters). | |
Q_DECL_DEPRECATED void | setMmPerMapUnit (double mmPerMapUnit) |
void | setRasterStrokeColor (const QColor &color) |
Sets the stroke color for the stroke drawn around raster symbol items. | |
void | setRasterStrokeWidth (double width) |
Sets the stroke width for the stroke drawn around raster symbol items. | |
void | setSplitLayer (bool s) |
Sets whether layer components can be split over multiple columns. | |
void | setStyle (QgsLegendStyle::Style s, const QgsLegendStyle &style) |
Sets the style for a legend component. | |
void | setSymbolAlignment (Qt::AlignmentFlag alignment) |
Sets the alignment for placement of legend symbols. | |
void | setSymbolSize (QSizeF s) |
Sets the default symbol size (in millimeters) used for legend items. | |
void | setSynchronousLegendRequests (bool b) |
Sets whether to request legend graphics synchronously. | |
void | setTitle (const QString &t) |
Sets the title for the legend, which will be rendered above all legend items. | |
void | setTitleAlignment (Qt::AlignmentFlag alignment) |
Sets the alignment of the legend title. | |
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. | |
void | setWrapChar (const QString &t) |
Sets a string to use as a wrapping character. | |
bool | splitLayer () const |
Returns true if layer components can be split over multiple columns. | |
QStringList | splitStringForWrapping (const QString &stringToSplt) const |
Splits a string using the wrap char taking into account handling empty wrap char which means no wrapping. | |
QgsLegendStyle | style (QgsLegendStyle::Style s) const |
Returns the style for a legend component. | |
Qt::AlignmentFlag | symbolAlignment () const |
Returns the alignment for placement of legend symbols. | |
QSizeF | symbolSize () const |
Returns the default symbol size (in millimeters) used for legend items. | |
bool | synchronousLegendRequests () const |
Returns whether to request legend graphics synchronously. | |
double | textWidthMillimeters (const QFont &font, const QString &text) const |
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE. | |
QString | title () const |
Returns the title for the legend, which will be rendered above all legend items. | |
Qt::AlignmentFlag | titleAlignment () const |
Returns the alignment of the legend title. | |
Q_DECL_DEPRECATED bool | useAdvancedEffects () const |
QSizeF | wmsLegendSize () const |
Returns the size (in millimeters) of WMS legend graphics shown in the legend. | |
QString | wrapChar () const |
Returns the string used as a wrapping character. | |
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLegendRenderer.
The content of the legend is driven by the QgsLegendModel class.
Definition at line 37 of file qgslegendsettings.h.
QgsLegendSettings::QgsLegendSettings | ( | ) |
Definition at line 23 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 95 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 147 of file qgslegendsettings.h.
|
inline |
Returns the margin space between adjacent columns (in millimeters).
Definition at line 130 of file qgslegendsettings.h.
int QgsLegendSettings::dpi | ( | ) | const |
Definition at line 158 of file qgslegendsettings.cpp.
|
inline |
Returns whether a stroke will be drawn around raster symbol items.
Definition at line 300 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 205 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 193 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 180 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 168 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 247 of file qgslegendsettings.cpp.
QColor QgsLegendSettings::fontColor | ( | ) | const |
Returns the font color used for legend items.
Definition at line 67 of file qgslegendsettings.cpp.
double QgsLegendSettings::fontDescentMillimeters | ( | const QFont & | font | ) | const |
Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.
Definition at line 254 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 240 of file qgslegendsettings.cpp.
Qgis::LegendJsonRenderFlags QgsLegendSettings::jsonRenderFlags | ( | ) | const |
QColor QgsLegendSettings::layerFontColor | ( | ) | const |
Returns layer font color, defaults to fontColor()
Definition at line 80 of file qgslegendsettings.cpp.
|
inline |
Returns the line spacing to use between lines of legend text.
Definition at line 387 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 138 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 148 of file qgslegendsettings.cpp.
|
inline |
Returns the maximum symbol size (in mm).
0.0 means there is no maximum set.
Definition at line 244 of file qgslegendsettings.h.
|
inline |
Returns the minimum symbol size (in mm).
A value 0.0 means there is no minimum set.
Definition at line 262 of file qgslegendsettings.h.
double QgsLegendSettings::mmPerMapUnit | ( | ) | const |
Definition at line 118 of file qgslegendsettings.cpp.
double QgsLegendSettings::pixelFontSize | ( | double | pointSize | ) | const |
Calculates font to from point size to pixel size.
Definition at line 228 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 318 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 337 of file qgslegendsettings.h.
|
inline |
Returns modifiable reference to the style for a legend component.
Definition at line 73 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 220 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 103 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 157 of file qgslegendsettings.h.
|
inline |
Sets the margin space between adjacent columns (in millimeters).
Definition at line 137 of file qgslegendsettings.h.
void QgsLegendSettings::setDpi | ( | int | dpi | ) |
Definition at line 163 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 309 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 189 of file qgslegendsettings.h.
void QgsLegendSettings::setFontColor | ( | const QColor & | c | ) |
Sets the font color used for legend items.
Definition at line 72 of file qgslegendsettings.cpp.
void QgsLegendSettings::setJsonRenderFlags | ( | const Qgis::LegendJsonRenderFlags & | jsonRenderFlags | ) |
Sets the the JSON export flags to jsonRenderFlags.
Definition at line 266 of file qgslegendsettings.cpp.
void QgsLegendSettings::setLayerFontColor | ( | const QColor & | fontColor | ) |
Sets layer font color to fontColor Overrides fontColor()
Definition at line 85 of file qgslegendsettings.cpp.
void QgsLegendSettings::setLineSpacing | ( | double | s | ) |
Sets the line spacing to use between lines of legend text.
Definition at line 91 of file qgslegendsettings.cpp.
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 143 of file qgslegendsettings.cpp.
void QgsLegendSettings::setMapUnitsPerPixel | ( | double | mapUnitsPerPixel | ) |
Sets the mmPerMapUnit calculated by mapUnitsPerPixel mostly taken from the map settings.
Definition at line 153 of file qgslegendsettings.cpp.
|
inline |
Set the maximum symbol size for symbol (in millimeters).
A symbol size of 0.0 indicates no maximum is set.
Definition at line 254 of file qgslegendsettings.h.
|
inline |
Set the minimum symbol size for symbol (in millimeters).
A symbol size of 0.0 indicates no minimum is set.
Definition at line 272 of file qgslegendsettings.h.
void QgsLegendSettings::setMmPerMapUnit | ( | double | mmPerMapUnit | ) |
Definition at line 123 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 328 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 347 of file qgslegendsettings.h.
|
inline |
Sets whether layer components can be split over multiple columns.
Definition at line 171 of file qgslegendsettings.h.
|
inline |
Sets the style for a legend component.
Definition at line 87 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 282 of file qgslegendsettings.h.
|
inline |
Sets the default symbol size (in millimeters) used for legend items.
Definition at line 236 of file qgslegendsettings.h.
|
inline |
Sets whether to request legend graphics synchronously.
Definition at line 370 of file qgslegendsettings.h.
|
inline |
Sets the title for the legend, which will be rendered above all legend items.
Definition at line 47 of file qgslegendsettings.h.
|
inline |
Sets the alignment of the legend title.
Definition at line 66 of file qgslegendsettings.h.
void QgsLegendSettings::setUseAdvancedEffects | ( | bool | use | ) |
Definition at line 133 of file qgslegendsettings.cpp.
|
inline |
Sets the desired size (in millimeters) of WMS legend graphics shown in the legend.
Definition at line 361 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 113 of file qgslegendsettings.h.
|
inline |
Returns true
if layer components can be split over multiple columns.
Definition at line 164 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 174 of file qgslegendsettings.cpp.
|
inline |
Returns the style for a legend component.
Definition at line 80 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 292 of file qgslegendsettings.h.
|
inline |
Returns the default symbol size (in millimeters) used for legend items.
Definition at line 229 of file qgslegendsettings.h.
|
inline |
Returns whether to request legend graphics synchronously.
Definition at line 379 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 233 of file qgslegendsettings.cpp.
|
inline |
Returns the title for the legend, which will be rendered above all legend items.
Definition at line 54 of file qgslegendsettings.h.
|
inline |
Returns the alignment of the legend title.
Definition at line 60 of file qgslegendsettings.h.
bool QgsLegendSettings::useAdvancedEffects | ( | ) | const |
Definition at line 128 of file qgslegendsettings.cpp.
|
inline |
Returns the size (in millimeters) of WMS legend graphics shown in the legend.
Definition at line 354 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 123 of file qgslegendsettings.h.