QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Classes | Public Types | Public Member Functions | List of all members
QgsLabel Class Reference

A class to render labels. More...

#include <qgslabel.h>

Classes

struct  labelpoint
 

Public Types

enum  LabelField {
  Text = 0, Family, Size, SizeType,
  Bold, Italic, Underline, Color,
  XCoordinate, YCoordinate, XOffset, YOffset,
  Angle, Alignment, BufferEnabled, BufferSize,
  BufferColor, BufferBrush, BorderWidth, BorderColor,
  BorderStyle, MultilineEnabled, StrikeOut, LabelFieldCount
}
 

Public Member Functions

 QgsLabel (const QgsFields &fields)
 
 ~QgsLabel ()
 
void addRequiredFields (QgsAttributeList &fields) const
 add vector of required fields to existing list of fields More...
 
QgsFieldsfields ()
 Available vector fields. More...
 
QString fieldValue (int attr, QgsFeature &feature)
 Get field value if : 1) field name is not empty 2) field exists 3) value is defined otherwise returns empty string. More...
 
bool isInScaleRange (double scale) const
 Return true if the label is visible at the given scale. More...
 
QgsLabelAttributeslabelAttributes ()
 Pointer to default attributes. More...
 
QString labelField (int attr) const
 label field More...
 
float maxScale () const
 
float minScale () const
 
void readXML (const QDomNode &node)
 Reads the renderer configuration from an XML file. More...
 
void renderLabel (QgsRenderContext &renderContext, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes=nullptr)
 render label More...
 
bool scaleBasedVisibility () const
 
void setFields (const QgsFields &fields)
 Set available fields. More...
 
void setLabelField (int attr, int fieldIndex)
 Set label field. More...
 
void setMaxScale (float theMaxScale)
 Accessor and mutator for the maximum scale member. More...
 
void setMinScale (float theMinScale)
 Accessor and mutator for the minimum scale member. More...
 
void setScaleBasedVisibility (bool theVisibilityFlag)
 Accessor and mutator for the scale based visilibility flag. More...
 
void writeXML (QDomNode &label_node, QDomDocument &document) const
 Writes the contents of the renderer to a configuration file. More...
 

Detailed Description

A class to render labels.

Label rendering properties can be either specified directly or in most cases determined dynamically based on the value of an attribute.

Definition at line 51 of file qgslabel.h.

Member Enumeration Documentation

◆ LabelField

Enumerator
Text 
Family 
Size 
SizeType 
Bold 
Italic 
Underline 
Color 
XCoordinate 
YCoordinate 
XOffset 
YOffset 
Angle 
Alignment 
BufferEnabled 
BufferSize 
BufferColor 
BufferBrush 
BorderWidth 
BorderColor 
BorderStyle 
MultilineEnabled 
StrikeOut 
LabelFieldCount 

Definition at line 59 of file qgslabel.h.

Constructor & Destructor Documentation

◆ QgsLabel()

QgsLabel::QgsLabel ( const QgsFields fields)

Definition at line 47 of file qgslabel.cpp.

◆ ~QgsLabel()

QgsLabel::~QgsLabel ( )

Definition at line 61 of file qgslabel.cpp.

Member Function Documentation

◆ addRequiredFields()

void QgsLabel::addRequiredFields ( QgsAttributeList fields) const

add vector of required fields to existing list of fields

Definition at line 459 of file qgslabel.cpp.

◆ fields()

QgsFields & QgsLabel::fields ( )

Available vector fields.

Definition at line 486 of file qgslabel.cpp.

◆ fieldValue()

QString QgsLabel::fieldValue ( int  attr,
QgsFeature feature 
)

Get field value if : 1) field name is not empty 2) field exists 3) value is defined otherwise returns empty string.

Definition at line 66 of file qgslabel.cpp.

◆ isInScaleRange()

bool QgsLabel::isInScaleRange ( double  scale) const

Return true if the label is visible at the given scale.

Definition at line 1418 of file qgslabel.cpp.

◆ labelAttributes()

QgsLabelAttributes * QgsLabel::labelAttributes ( )

Pointer to default attributes.

Note
this replaces the to-be-deprecated layerAttributes method.
introduced in QGIS 1.4

Definition at line 510 of file qgslabel.cpp.

◆ labelField()

QString QgsLabel::labelField ( int  attr) const

label field

Definition at line 499 of file qgslabel.cpp.

◆ maxScale()

float QgsLabel::maxScale ( ) const

Definition at line 1413 of file qgslabel.cpp.

◆ minScale()

float QgsLabel::minScale ( ) const

Definition at line 1403 of file qgslabel.cpp.

◆ readXML()

void QgsLabel::readXML ( const QDomNode node)

Reads the renderer configuration from an XML file.

Parameters
nodethe Dom node to read

Definition at line 745 of file qgslabel.cpp.

◆ renderLabel()

void QgsLabel::renderLabel ( QgsRenderContext renderContext,
QgsFeature feature,
bool  selected,
QgsLabelAttributes classAttributes = nullptr 
)

render label

Parameters
renderContextthe render context
featurefeature to render the label for
selectedfeature is selected
classAttributesattributes to create the label from

Definition at line 72 of file qgslabel.cpp.

◆ scaleBasedVisibility()

bool QgsLabel::scaleBasedVisibility ( ) const

Definition at line 1393 of file qgslabel.cpp.

◆ setFields()

void QgsLabel::setFields ( const QgsFields fields)

Set available fields.

Definition at line 481 of file qgslabel.cpp.

◆ setLabelField()

void QgsLabel::setLabelField ( int  attr,
int  fieldIndex 
)

Set label field.

Definition at line 491 of file qgslabel.cpp.

◆ setMaxScale()

void QgsLabel::setMaxScale ( float  theMaxScale)

Accessor and mutator for the maximum scale member.

Definition at line 1408 of file qgslabel.cpp.

◆ setMinScale()

void QgsLabel::setMinScale ( float  theMinScale)

Accessor and mutator for the minimum scale member.

Definition at line 1398 of file qgslabel.cpp.

◆ setScaleBasedVisibility()

void QgsLabel::setScaleBasedVisibility ( bool  theVisibilityFlag)

Accessor and mutator for the scale based visilibility flag.

Definition at line 1388 of file qgslabel.cpp.

◆ writeXML()

void QgsLabel::writeXML ( QDomNode label_node,
QDomDocument document 
) const

Writes the contents of the renderer to a configuration file.

Definition at line 1038 of file qgslabel.cpp.


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