|
QGIS API Documentation
master-59fd5e0
|
A class to render labels. More...
#include <qgslabel.h>
Collaboration diagram for QgsLabel: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 | |
| QgsFields & | fields () |
| Available vector fields. | |
| 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. | |
| QgsLabelAttributes * | labelAttributes () |
| Pointer to default attributes. | |
| QString | labelField (int attr) const |
| label field | |
| float | maxScale () const |
| float | minScale () const |
| void | readXML (const QDomNode &node) |
| Reads the renderer configuration from an XML file. | |
| void | renderLabel (QgsRenderContext &renderContext, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes=0) |
| render label | |
| bool | scaleBasedVisibility () const |
| void | setFields (const QgsFields &fields) |
| Set available fields. | |
| void | setLabelField (int attr, int fieldIndex) |
| Set label field. | |
| void | setMaxScale (float theMaxScale) |
| Accessor and mutator for the maximum scale member. | |
| void | setMinScale (float theMinScale) |
| Accessor and mutator for the minimum scale member. | |
| void | setScaleBasedVisibility (bool theVisibilityFlag) |
| Accessor and mutator for the scale based visilibility flag. | |
| void | writeXML (QDomNode &label_node, QDomDocument &document) const |
| Writes the contents of the renderer to a configuration file. | |
Private Member Functions | |
| 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. | |
| bool | readLabelField (QDomElement &el, int attr, QString prefix) |
| 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. | |
Private Attributes | |
| QgsFields | mFields |
| Available layer fields. | |
| QgsLabelAttributes * | mLabelAttributes |
| Default layer attributes. | |
| std::vector< QString > | mLabelField |
| Label fields. | |
| std::vector< int > | mLabelFieldIdx |
| Label field indexes. | |
| float | mMaxScale |
| Maximum scale at which this label should be displayed. | |
| float | mMinScale |
| Minimum 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. | |
| QColor | mSelectionColor |
| Color to draw selected features. | |
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 52 of file qgslabel.h.
| enum QgsLabel::LabelField |
Definition at line 60 of file qgslabel.h.
| QgsLabel::QgsLabel | ( | const QgsFields & | fields | ) |
Definition at line 47 of file qgslabel.cpp.
References fields(), LabelFieldCount, mFields, mLabelAttributes, and mLabelFieldIdx.
Definition at line 61 of file qgslabel.cpp.
References mLabelAttributes.
| void QgsLabel::addRequiredFields | ( | QgsAttributeList & | fields | ) | const |
add vector of required fields to existing list of fields
Definition at line 463 of file qgslabel.cpp.
References LabelFieldCount, and mLabelFieldIdx.
Referenced by QgsVectorLayer::drawLabels().
| QgsFields & QgsLabel::fields | ( | void | ) |
Available vector fields.
Definition at line 490 of file qgslabel.cpp.
References mFields.
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::attribute(), and mLabelFieldIdx.
Referenced by renderLabel().
| QgsLabelAttributes * QgsLabel::labelAttributes | ( | void | ) |
Pointer to default attributes.
Definition at line 514 of file qgslabel.cpp.
References mLabelAttributes.
| QString QgsLabel::labelField | ( | int | attr | ) | const |
label field
Definition at line 503 of file qgslabel.cpp.
References QgsFields::count(), LabelFieldCount, mFields, and mLabelFieldIdx.
Referenced by QgsVectorLayer::writeSymbology(), and writeXML().
| void QgsLabel::labelPoint | ( | std::vector< labelpoint > & | points, |
| QgsFeature & | feature | ||
| ) | [private] |
Get label point for simple feature in map units.
Definition at line 519 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 567 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.
| float QgsLabel::maxScale | ( | ) | const |
Definition at line 1401 of file qgslabel.cpp.
References mMaxScale.
Referenced by QgsVectorLayer::drawLabels(), and QgsVectorLayer::writeSymbology().
| float QgsLabel::minScale | ( | ) | const |
Definition at line 1391 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 698 of file qgslabel.cpp.
References QgsFields::count(), mFields, and mLabelFieldIdx.
Referenced by readXML().
| void QgsLabel::readXML | ( | const QDomNode & | node | ) |
Reads the renderer configuration from an XML file.
| node | the Dom node to read |
Definition at line 733 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::setSelectedOnly(), QgsLabelAttributes::setSize(), QgsLabelAttributes::setStrikeOut(), QgsLabelAttributes::setText(), QgsLabelAttributes::setUnderline(), Size, SizeType, StrikeOut, Text, Underline, QgsLabelAttributes::unitsCode(), XCoordinate, XOffset, YCoordinate, and YOffset.
Referenced by QgsVectorLayer::readSymbology().
| void QgsLabel::renderLabel | ( | QgsRenderContext & | renderContext, |
| QgsFeature & | feature, | ||
| bool | selected, | ||
| QgsLabelAttributes * | classAttributes = 0 |
||
| ) |
render label
| renderContext | the render context |
| feature | feature to render the label for |
| selected | feature is selected |
| classAttributes | attributes to create the label from |
Definition at line 76 of file qgslabel.cpp.
References Alignment, QgsLabelAttributes::alignment(), Angle, QgsLabelAttributes::angle(), QgsLabelAttributes::angleIsAuto(), Bold, QgsLabelAttributes::bold(), Color, QgsLabelAttributes::color(), Family, QgsLabelAttributes::family(), fieldValue(), Italic, QgsLabelAttributes::italic(), labelPoint(), QgsRenderContext::mapToPixel(), QgsLabelAttributes::MapUnits, mLabelAttributes, QgsLabelAttributes::multilineEnabled(), QgsLabelAttributes::offsetType(), QgsLabelAttributes::PointUnits, QgsRenderContext::rasterScaleFactor(), QgsRenderContext::scaleFactor(), QgsLabelAttributes::selectedOnly(), QgsPoint::setX(), QgsPoint::setY(), Size, size, QgsLabelAttributes::size(), SizeType, QgsLabelAttributes::sizeType(), StrikeOut, QgsLabelAttributes::strikeOut(), Text, QgsLabelAttributes::text(), QgsMapToPixel::transform(), Underline, QgsLabelAttributes::underline(), QgsPoint::x(), XCoordinate, XOffset, QgsLabelAttributes::xOffset(), YCoordinate, YOffset, and QgsLabelAttributes::yOffset().
Referenced by QgsVectorLayer::drawLabels().
| 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] |
Does the actual rendering of a label at the given point.
Definition at line 374 of file qgslabel.cpp.
References QgsLabelAttributes::bufferColor(), QgsLabelAttributes::bufferColorIsSet(), QgsLabelAttributes::bufferEnabled(), QgsLabelAttributes::bufferSize(), QgsLabelAttributes::bufferSizeIsSet(), QgsRenderContext::coordinateTransform(), M_PI, QgsRenderContext::mapToPixel(), mLabelAttributes, QgsLabelAttributes::multilineEnabled(), QgsRenderContext::painter(), QgsDebugMsg, QgsRenderContext::rasterScaleFactor(), QgsRenderContext::scaleFactor(), QgsMapToPixel::transform(), QgsCoordinateTransform::transform(), QgsPoint::x(), and QgsPoint::y().
| bool QgsLabel::scaleBasedVisibility | ( | ) | const |
Definition at line 1381 of file qgslabel.cpp.
References mScaleBasedVisibility.
Referenced by QgsVectorLayer::drawLabels(), and QgsVectorLayer::writeSymbology().
| void QgsLabel::setFields | ( | const QgsFields & | fields | ) |
Set available fields.
Definition at line 485 of file qgslabel.cpp.
| void QgsLabel::setLabelField | ( | int | attr, |
| int | fieldIndex | ||
| ) |
Set label field.
Definition at line 495 of file qgslabel.cpp.
References LabelFieldCount, and mLabelFieldIdx.
| void QgsLabel::setMaxScale | ( | float | theMaxScale | ) |
Accessor and mutator for the maximum scale member.
Definition at line 1396 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 1386 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 1376 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 1026 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().
QgsFields QgsLabel::mFields [private] |
Available layer fields.
Definition at line 177 of file qgslabel.h.
Referenced by fields(), labelField(), QgsLabel(), readLabelField(), and setFields().
QgsLabelAttributes* QgsLabel::mLabelAttributes [private] |
Default layer attributes.
Definition at line 174 of file qgslabel.h.
Referenced by labelAttributes(), QgsLabel(), readXML(), renderLabel(), writeXML(), and ~QgsLabel().
std::vector<QString> QgsLabel::mLabelField [private] |
Label fields.
Definition at line 180 of file qgslabel.h.
std::vector<int> QgsLabel::mLabelFieldIdx [private] |
Label field indexes.
Definition at line 183 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 188 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 186 of file qgslabel.h.
Referenced by minScale(), and setMinScale().
bool QgsLabel::mScaleBasedVisibility [private] |
A flag that tells us whether to use the above vars to restrict the label's visibility.
Definition at line 190 of file qgslabel.h.
Referenced by scaleBasedVisibility(), and setScaleBasedVisibility().
QColor QgsLabel::mSelectionColor [private] |
Color to draw selected features.
Definition at line 171 of file qgslabel.h.