QgsLabel Class Reference
[Core]

#include <qgslabel.h>

Collaboration diagram for QgsLabel:

Collaboration graph
[legend]
List of all members.

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 53 of file qgslabel.h.

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, LabelFieldCount
}

Public Member Functions

 QgsLabel (const QgsFieldMap &fields)
 ~QgsLabel ()
void renderLabel (QPainter *painter, const QgsRectangle &viewExtent, const QgsCoordinateTransform *coordinateTransform, const QgsMapToPixel *transform, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes=0, double sizeScale=1., double rasterScaleFactor=1.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.
QgsLabelAttributeslayerAttributes (void)
 Pointer to default attributes.
void setLabelField (int attr, int fieldIndex)
 Set label field.
bool setLabelFieldName (int attr, QString name)
 Set label field by name.
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 (QPainter *painter, QgsPoint point, const QgsCoordinateTransform *coordinateTransform, const QgsMapToPixel *transform, QString text, QFont font, QPen pen, int dx, int dy, double xoffset, double yoffset, double ang, int width, int height, int alignment, double sizeScale=1.0, double rasterScaleFactor=1.0)
 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.

Classes

struct  labelpoint


Member Enumeration Documentation

enum QgsLabel::LabelField

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

Definition at line 61 of file qgslabel.h.


Constructor & Destructor Documentation

QgsLabel::QgsLabel ( const QgsFieldMap fields  ) 

Definition at line 49 of file qgslabel.cpp.

References LabelFieldCount, mField, mLabelAttributes, and mLabelFieldIdx.

QgsLabel::~QgsLabel (  ) 

Definition at line 63 of file qgslabel.cpp.

References mLabelAttributes.


Member Function Documentation

void QgsLabel::renderLabel ( QPainter *  painter,
const QgsRectangle viewExtent,
const QgsCoordinateTransform coordinateTransform,
const QgsMapToPixel transform,
QgsFeature feature,
bool  selected,
QgsLabelAttributes classAttributes = 0,
double  sizeScale = 1.,
double  rasterScaleFactor = 1.0 
)

render label

Parameters:
sizeScale global scale factor for size in pixels, labels in map units are not scaled

Definition at line 88 of file qgslabel.cpp.

References QgsLabelAttributes::alignment(), Alignment, QgsLabelAttributes::angle(), Angle, QgsLabelAttributes::angleIsAuto(), QgsLabelAttributes::bold(), Bold, QgsLabelAttributes::color(), Color, QgsLabelAttributes::family(), Family, fieldValue(), QgsLabelAttributes::italic(), Italic, labelPoint(), QgsLabelAttributes::MapUnits, mLabelAttributes, QgsLabelAttributes::multilineEnabled(), QgsLabelAttributes::offsetType(), QgsLabelAttributes::PointUnits, QgsPoint::setX(), QgsPoint::setY(), QgsLabelAttributes::size(), Size, QgsLabelAttributes::sizeType(), SizeType, QgsLabelAttributes::text(), Text, QgsMapToPixel::transform(), QgsLabelAttributes::underline(), Underline, QgsPoint::x(), XCoordinate, QgsLabelAttributes::xOffset(), XOffset, YCoordinate, QgsLabelAttributes::yOffset(), and YOffset.

Referenced by QgsVectorLayer::drawLabels().

void QgsLabel::readXML ( const QDomNode &  node  ) 

Reads the renderer configuration from an XML file.

Parameters:
rnode the Dom node to read

Definition at line 730 of file qgslabel.cpp.

References Alignment, QgsLabelAttributes::alignmentCode(), Angle, Bold, BufferColor, BufferEnabled, BufferSize, Color, Family, Italic, mLabelAttributes, MultilineEnabled, QgsDebugMsg, readLabelField(), QgsLabelAttributes::setAlignment(), QgsLabelAttributes::setAngle(), QgsLabelAttributes::setAutoAngle(), QgsLabelAttributes::setBold(), QgsLabelAttributes::setBufferColor(), QgsLabelAttributes::setBufferEnabled(), QgsLabelAttributes::setBufferSize(), QgsLabelAttributes::setColor(), QgsLabelAttributes::setFamily(), QgsLabelAttributes::setItalic(), QgsLabelAttributes::setMultilineEnabled(), QgsLabelAttributes::setOffset(), QgsLabelAttributes::setSize(), QgsLabelAttributes::setText(), QgsLabelAttributes::setUnderline(), Size, SizeType, Text, Underline, QgsLabelAttributes::unitsCode(), XCoordinate, XOffset, YCoordinate, and YOffset.

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 997 of file qgslabel.cpp.

References Alignment, QgsLabelAttributes::alignment(), QgsLabelAttributes::alignmentIsSet(), QgsLabelAttributes::alignmentName(), 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(), Size, QgsLabelAttributes::size(), QgsLabelAttributes::sizeIsSet(), QgsLabelAttributes::sizeType(), SizeType, 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().

void QgsLabel::addRequiredFields ( QgsAttributeList fields  )  const

add vector of required fields to existing list of fields

Definition at line 464 of file qgslabel.cpp.

References LabelFieldCount, and mLabelFieldIdx.

Referenced by QgsVectorLayer::drawLabels().

void QgsLabel::setFields ( const QgsFieldMap fields  ) 

Set available fields.

Definition at line 486 of file qgslabel.cpp.

References mField.

QgsFieldMap & QgsLabel::fields ( void   ) 

Available vector fields.

Definition at line 491 of file qgslabel.cpp.

References mField.

QgsLabelAttributes * QgsLabel::layerAttributes ( void   ) 

Pointer to default attributes.

Definition at line 513 of file qgslabel.cpp.

References mLabelAttributes.

Referenced by QgsQuickPrint::scaleTextLabels().

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

Set label field.

Definition at line 496 of file qgslabel.cpp.

References LabelFieldCount, and mLabelFieldIdx.

bool QgsLabel::setLabelFieldName ( int  attr,
QString  name 
)

Set label field by name.

QString QgsLabel::labelField ( int  attr  )  const

label field

Definition at line 504 of file qgslabel.cpp.

References LabelFieldCount, mField, and mLabelFieldIdx.

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

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 68 of file qgslabel.cpp.

References QgsFeature::attributeMap(), and mLabelFieldIdx.

Referenced by renderLabel().

void QgsLabel::setMinScale ( float  theMinScale  ) 

Accessor and mutator for the minimum scale member.

Definition at line 1325 of file qgslabel.cpp.

References mMinScale.

Referenced by QgsVectorLayer::readSymbology().

float QgsLabel::minScale (  )  const

Definition at line 1330 of file qgslabel.cpp.

References mMinScale.

void QgsLabel::setMaxScale ( float  theMaxScale  ) 

Accessor and mutator for the maximum scale member.

Definition at line 1335 of file qgslabel.cpp.

References mMaxScale.

Referenced by QgsVectorLayer::readSymbology().

float QgsLabel::maxScale (  )  const

Definition at line 1340 of file qgslabel.cpp.

References mMaxScale.

Referenced by QgsVectorLayer::drawLabels().

void QgsLabel::setScaleBasedVisibility ( bool  theVisibilityFlag  ) 

Accessor and mutator for the scale based visilibility flag.

Definition at line 1315 of file qgslabel.cpp.

References mScaleBasedVisibility.

Referenced by QgsVectorLayer::readSymbology().

bool QgsLabel::scaleBasedVisibility (  )  const

Definition at line 1320 of file qgslabel.cpp.

References mScaleBasedVisibility.

void QgsLabel::renderLabel ( QPainter *  painter,
QgsPoint  point,
const QgsCoordinateTransform coordinateTransform,
const QgsMapToPixel transform,
QString  text,
QFont  font,
QPen  pen,
int  dx,
int  dy,
double  xoffset,
double  yoffset,
double  ang,
int  width,
int  height,
int  alignment,
double  sizeScale = 1.0,
double  rasterScaleFactor = 1.0 
) [private]

Does the actual rendering of a label at the given point.

Definition at line 375 of file qgslabel.cpp.

References QgsLabelAttributes::bufferColor(), QgsLabelAttributes::bufferColorIsSet(), QgsLabelAttributes::bufferEnabled(), QgsLabelAttributes::bufferSize(), QgsLabelAttributes::bufferSizeIsSet(), M_PI, mLabelAttributes, QgsLabelAttributes::multilineEnabled(), QgsDebugMsg, QgsMapToPixel::transform(), QgsCoordinateTransform::transform(), QgsPoint::x(), and QgsPoint::y().

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

Definition at line 695 of file qgslabel.cpp.

References mField, and mLabelFieldIdx.

Referenced by readXML().

void QgsLabel::labelPoint ( std::vector< labelpoint > &  ,
QgsFeature feature 
) [private]

Get label point for simple feature in map units.

Definition at line 518 of file qgslabel.cpp.

References QgsGeometry::asWkb(), QgsFeature::geometry(), QgsDebugMsg, QGis::WKBLineString, QGis::WKBLineString25D, QGis::WKBMultiLineString, QGis::WKBMultiLineString25D, QGis::WKBMultiPoint, QGis::WKBMultiPoint25D, QGis::WKBMultiPolygon, QGis::WKBMultiPolygon25D, QGis::WKBPoint, QGis::WKBPoint25D, QGis::WKBPolygon, QGis::WKBPolygon25D, QgsGeometry::wkbSize(), and QgsGeometry::wkbType().

Referenced by renderLabel().

unsigned char * QgsLabel::labelPoint ( labelpoint point,
unsigned char *  wkb,
size_t  wkblen 
) [private]

Get label point for the given feature in wkb format.

Definition at line 566 of file qgslabel.cpp.

References QgsLabel::labelpoint::angle, QgsLabel::labelpoint::p, QgsDebugMsg, QgsPoint::set(), QGis::WKBLineString, QGis::WKBLineString25D, QGis::WKBPoint, QGis::WKBPoint25D, QGis::WKBPolygon, and QGis::WKBPolygon25D.


Member Data Documentation

QColor QgsLabel::mSelectionColor [private]

Color to draw selected features.

Definition at line 172 of file qgslabel.h.

QgsLabelAttributes* QgsLabel::mLabelAttributes [private]

Default layer attributes.

Definition at line 175 of file qgslabel.h.

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

QgsFieldMap QgsLabel::mField [private]

Available layer fields.

Definition at line 178 of file qgslabel.h.

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

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

Label fields.

Definition at line 181 of file qgslabel.h.

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

Label field indexes.

Definition at line 184 of file qgslabel.h.

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

float QgsLabel::mMinScale [private]

Minimum scale at which this label should be displayed.

Definition at line 187 of file qgslabel.h.

Referenced by minScale(), and setMinScale().

float QgsLabel::mMaxScale [private]

Maximum scale at which this label should be displayed.

Definition at line 189 of file qgslabel.h.

Referenced by maxScale(), and setMaxScale().

bool QgsLabel::mScaleBasedVisibility [private]

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

Definition at line 191 of file qgslabel.h.

Referenced by scaleBasedVisibility(), and setScaleBasedVisibility().


The documentation for this class was generated from the following files:
Generated on Tue Jan 6 16:51:21 2009 for Quantum GIS API Documentation by  doxygen 1.5.1