Quantum GIS API Documentation  1.8
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
QgsLabel Class Reference

A class to render labels. More...

#include <qgslabel.h>

Collaboration diagram for QgsLabel:
Collaboration graph
[legend]

List of all members.

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 QgsFieldMap &fields)
 ~QgsLabel ()
Q_DECL_DEPRECATED void renderLabel (QPainter *painter, const QgsRectangle &viewExtent, QgsCoordinateTransform *coordinateTransform, const QgsMapToPixel *transform, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes=0, double sizeScale=1., double rasterScaleFactor=1.0)
 render label
void renderLabel (QgsRenderContext &renderContext, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes=0)
 render label
void readXML (const QDomNode &node)
 Reads the renderer configuration from an XML file.
void writeXML (QDomNode &label_node, QDomDocument &document) const
 Writes the contents of the renderer to a configuration file.
void addRequiredFields (QgsAttributeList &fields) const
 add vector of required fields to existing list of fields
void setFields (const QgsFieldMap &fields)
 Set available fields.
QgsFieldMapfields (void)
 Available vector fields.
Q_DECL_DEPRECATED
QgsLabelAttributes
layerAttributes (void)
 Pointer to default attributes.
QgsLabelAttributeslabelAttributes (void)
 Pointer to default attributes.
void setLabelField (int attr, int fieldIndex)
 Set label field.
QString labelField (int attr) const
 label field
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.
void setMinScale (float theMinScale)
 Accessor and mutator for the minimum scale member.
float minScale () const
void setMaxScale (float theMaxScale)
 Accessor and mutator for the maximum scale member.
float maxScale () const
void setScaleBasedVisibility (bool theVisibilityFlag)
 Accessor and mutator for the scale based visilibility flag.
bool scaleBasedVisibility () const

Private Member Functions

void renderLabel (QgsRenderContext &renderContext, QgsPoint point, QString text, QFont font, QPen pen, int dx, int dy, double xoffset, double yoffset, double ang, int width, int height, int alignment)
 Does the actual rendering of a label at the given point.
bool readLabelField (QDomElement &el, int attr, QString prefix)
void labelPoint (std::vector< labelpoint > &, QgsFeature &feature)
 Get label point for simple feature in map units.
unsigned char * labelPoint (labelpoint &point, unsigned char *wkb, size_t wkblen)
 Get label point for the given feature in wkb format.

Private Attributes

QColor mSelectionColor
 Color to draw selected features.
QgsLabelAttributesmLabelAttributes
 Default layer attributes.
QgsFieldMap mField
 Available layer fields.
std::vector< QString > mLabelField
 Label fields.
std::vector< int > mLabelFieldIdx
 Label field indexes.
float mMinScale
 Minimum scale at which this label should be displayed.
float mMaxScale
 Maximum scale at which this label should be displayed.
bool mScaleBasedVisibility
 A flag that tells us whether to use the above vars to restrict the label's visibility.

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

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 ( const QgsFieldMap fields)

Definition at line 47 of file qgslabel.cpp.

References fields(), LabelFieldCount, mField, mLabelAttributes, and mLabelFieldIdx.

Definition at line 61 of file qgslabel.cpp.

References mLabelAttributes.


Member Function Documentation

add vector of required fields to existing list of fields

Definition at line 473 of file qgslabel.cpp.

References LabelFieldCount, and mLabelFieldIdx.

Referenced by QgsVectorLayer::drawLabels().

Available vector fields.

Definition at line 500 of file qgslabel.cpp.

References mField.

Referenced by QgsLabel(), and setFields().

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.

References QgsFeature::attributeMap(), and mLabelFieldIdx.

Referenced by renderLabel().

Pointer to default attributes.

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

Definition at line 522 of file qgslabel.cpp.

References mLabelAttributes.

Referenced by QgsQuickPrint::scaleTextLabels().

QString QgsLabel::labelField ( int  attr) const

label field

Definition at line 513 of file qgslabel.cpp.

References LabelFieldCount, mField, and mLabelFieldIdx.

Referenced by QgsVectorLayer::writeSymbology(), and writeXML().

void QgsLabel::labelPoint ( std::vector< labelpoint > &  points,
QgsFeature feature 
) [private]
unsigned char * QgsLabel::labelPoint ( labelpoint point,
unsigned char *  wkb,
size_t  wkblen 
) [private]

Pointer to default attributes.

Deprecated:
in version 2 as it is badly named. Rather use attributes.
See also:
labelAttributes method rather

Definition at line 527 of file qgslabel.cpp.

References mLabelAttributes.

float QgsLabel::maxScale ( ) const

Definition at line 1414 of file qgslabel.cpp.

References mMaxScale.

Referenced by QgsVectorLayer::drawLabels(), and QgsVectorLayer::writeSymbology().

float QgsLabel::minScale ( ) const

Definition at line 1404 of file qgslabel.cpp.

References mMinScale.

Referenced by QgsVectorLayer::drawLabels(), and QgsVectorLayer::writeSymbology().

bool QgsLabel::readLabelField ( QDomElement &  el,
int  attr,
QString  prefix = "field" 
) [private]

Definition at line 711 of file qgslabel.cpp.

References mField, and mLabelFieldIdx.

Referenced by readXML().

void QgsLabel::readXML ( const QDomNode &  node)
Q_DECL_DEPRECATED void QgsLabel::renderLabel ( QPainter *  painter,
const QgsRectangle viewExtent,
QgsCoordinateTransform coordinateTransform,
const QgsMapToPixel transform,
QgsFeature feature,
bool  selected,
QgsLabelAttributes classAttributes = 0,
double  sizeScale = 1.,
double  rasterScaleFactor = 1.0 
) [inline]

render label

Parameters:
painterpainter to render label in
viewExtentextent to render labels in
coordinateTransformcoordinate transformation to use
transformtransformation from coordinate to canvas pixels
featurefeature to label
selectedfeature is selected
classAttributesattributes to create label from
sizeScalescale
rasterScaleFactorraster scale
Deprecated:

Definition at line 105 of file qgslabel.h.

References QgsCoordinateTransform::destCRS(), rasterScaleFactor, QgsRenderContext::setCoordinateTransform(), QgsRenderContext::setExtent(), QgsRenderContext::setMapToPixel(), QgsRenderContext::setPainter(), QgsRenderContext::setRasterScaleFactor(), QgsRenderContext::setScaleFactor(), and QgsCoordinateTransform::sourceCrs().

Referenced by QgsVectorLayer::drawLabels(), and renderLabel().

void QgsLabel::renderLabel ( QgsRenderContext renderContext,
QgsFeature feature,
bool  selected,
QgsLabelAttributes classAttributes = 0 
)
void QgsLabel::renderLabel ( QgsRenderContext renderContext,
QgsPoint  point,
QString  text,
QFont  font,
QPen  pen,
int  dx,
int  dy,
double  xoffset,
double  yoffset,
double  ang,
int  width,
int  height,
int  alignment 
) [private]

Definition at line 1394 of file qgslabel.cpp.

References mScaleBasedVisibility.

Referenced by QgsVectorLayer::drawLabels(), and QgsVectorLayer::writeSymbology().

void QgsLabel::setFields ( const QgsFieldMap fields)

Set available fields.

Definition at line 495 of file qgslabel.cpp.

References fields(), and mField.

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

Set label field.

Definition at line 505 of file qgslabel.cpp.

References LabelFieldCount, and mLabelFieldIdx.

void QgsLabel::setMaxScale ( float  theMaxScale)

Accessor and mutator for the maximum scale member.

Definition at line 1409 of file qgslabel.cpp.

References mMaxScale.

Referenced by QgsVectorLayer::readSymbology().

void QgsLabel::setMinScale ( float  theMinScale)

Accessor and mutator for the minimum scale member.

Definition at line 1399 of file qgslabel.cpp.

References mMinScale.

Referenced by QgsVectorLayer::readSymbology().

void QgsLabel::setScaleBasedVisibility ( bool  theVisibilityFlag)

Accessor and mutator for the scale based visilibility flag.

Definition at line 1389 of file qgslabel.cpp.

References mScaleBasedVisibility.

Referenced by QgsVectorLayer::readSymbology().

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

Writes the contents of the renderer to a configuration file.

Definition at line 1039 of file qgslabel.cpp.

References Alignment, QgsLabelAttributes::alignment(), QgsLabelAttributes::alignmentIsSet(), QgsLabelAttributes::alignmentName(), Angle, MathUtils::angle(), QgsLabelAttributes::angle(), QgsLabelAttributes::angleIsAuto(), QgsLabelAttributes::angleIsSet(), Bold, QgsLabelAttributes::bold(), QgsLabelAttributes::boldIsSet(), BufferColor, QgsLabelAttributes::bufferColor(), QgsLabelAttributes::bufferColorIsSet(), BufferEnabled, QgsLabelAttributes::bufferEnabled(), BufferSize, QgsLabelAttributes::bufferSize(), QgsLabelAttributes::bufferSizeIsSet(), QgsLabelAttributes::bufferSizeType(), Color, QgsLabelAttributes::color(), QgsLabelAttributes::colorIsSet(), Family, QgsLabelAttributes::family(), QgsLabelAttributes::familyIsSet(), Italic, QgsLabelAttributes::italic(), QgsLabelAttributes::italicIsSet(), labelField(), mLabelAttributes, mLabelFieldIdx, MultilineEnabled, QgsLabelAttributes::multilineEnabled(), QgsLabelAttributes::offsetIsSet(), QgsLabelAttributes::offsetType(), QgsLabelAttributes::selectedOnly(), Size, size, QgsLabelAttributes::size(), QgsLabelAttributes::sizeIsSet(), SizeType, QgsLabelAttributes::sizeType(), StrikeOut, QgsLabelAttributes::strikeOut(), QgsLabelAttributes::strikeOutIsSet(), Text, QgsLabelAttributes::text(), QgsLabelAttributes::textIsSet(), Underline, QgsLabelAttributes::underline(), QgsLabelAttributes::underlineIsSet(), QgsLabelAttributes::unitsName(), XCoordinate, XOffset, QgsLabelAttributes::xOffset(), YCoordinate, YOffset, and QgsLabelAttributes::yOffset().

Referenced by QgsVectorLayer::writeSymbology().


Member Data Documentation

Available layer fields.

Definition at line 209 of file qgslabel.h.

Referenced by fields(), labelField(), QgsLabel(), readLabelField(), and setFields().

Default layer attributes.

Definition at line 206 of file qgslabel.h.

Referenced by labelAttributes(), layerAttributes(), QgsLabel(), readXML(), renderLabel(), writeXML(), and ~QgsLabel().

std::vector<QString> QgsLabel::mLabelField [private]

Label fields.

Definition at line 212 of file qgslabel.h.

std::vector<int> QgsLabel::mLabelFieldIdx [private]

Label field indexes.

Definition at line 215 of file qgslabel.h.

Referenced by addRequiredFields(), fieldValue(), labelField(), QgsLabel(), readLabelField(), setLabelField(), and writeXML().

float QgsLabel::mMaxScale [private]

Maximum scale at which this label should be displayed.

Definition at line 220 of file qgslabel.h.

Referenced by maxScale(), and setMaxScale().

float QgsLabel::mMinScale [private]

Minimum scale at which this label should be displayed.

Definition at line 218 of file qgslabel.h.

Referenced by minScale(), and setMinScale().

A flag that tells us whether to use the above vars to restrict the label's visibility.

Definition at line 222 of file qgslabel.h.

Referenced by scaleBasedVisibility(), and setScaleBasedVisibility().

QColor QgsLabel::mSelectionColor [private]

Color to draw selected features.

Definition at line 203 of file qgslabel.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines