Mapper  0.9.0
API documentation
Public Types | Public Member Functions | Protected Member Functions | List of all members
OpenOrienteering::TextObject Class Reference

A text object. More...

#include <text_object.h>

Inheritance diagram for OpenOrienteering::TextObject:
Inheritance graph
[legend]
Collaboration diagram for OpenOrienteering::TextObject:
Collaboration graph
[legend]

Public Types

enum  HorizontalAlignment { AlignLeft = 0, AlignHCenter = 1, AlignRight = 2 }
 
enum  VerticalAlignment { AlignBaseline = 0, AlignTop = 1, AlignVCenter = 2, AlignBottom = 3 }
 
typedef std::vector< TextObjectLineInfoLineInfoContainer
 A sequence container of TextObjectLineInfo objects. More...
 
- Public Types inherited from OpenOrienteering::Object
enum  Type { Point = 0, Path = 1, Text = 4 }
 Enumeration of possible object types. More...
 
typedef QHash< QString, QStringTags
 Defines a type which maps keys to values, to be used for tagging objects. More...
 

Public Member Functions

 TextObject (const Symbol *symbol=nullptr)
 Construct a new text object. More...
 
TextObjectduplicate () const override
 Creates a duplicate of the text object. More...
 
TextObjectoperator= (const TextObject &)=delete
 
void copyFrom (const Object &other) override
 
bool hasSingleAnchor () const
 Returns true if the text object has a single anchor, false if it has as word wrap box. More...
 
void setAnchorPosition (qint32 x, qint32 y)
 Sets the position of the anchor point to (x,y). More...
 
void setAnchorPosition (const MapCoord &coord)
 Sets the position of the anchor point to coord. More...
 
void setAnchorPosition (const MapCoordF &coord)
 Sets the position of the anchor point to coord. More...
 
MapCoordF getAnchorCoordF () const
 Returns the coordinates of the anchor point or midpoint. More...
 
void transform (const QTransform &t) override
 Apply a transformation to all coordinates. More...
 
void setBox (qint32 mid_x, qint32 mid_y, qreal width, qreal height)
 Set position and size. More...
 
void setBoxSize (const MapCoord &size)
 Set size. More...
 
MapCoord getBoxSize () const
 Returns the size as a MapCoord. More...
 
qreal getBoxWidth () const
 Returns the width of the word wrap box. More...
 
qreal getBoxHeight () const
 Returns the height of the word wrap box. More...
 
std::vector< QPointFcontrolPoints () const
 Returns the positions of the control points. More...
 
void scale (const MapCoordF &center, double factor) override
 Scales position and box, with the given scaling center. More...
 
void scale (double factor_x, double factor_y) override
 Scales position and box, with the center (0, 0). More...
 
void setText (const QString &text)
 Sets the text of the object. More...
 
const QStringgetText () const
 Returns the text of the object. More...
 
void setHorizontalAlignment (HorizontalAlignment h_align)
 Sets the horizontal alignment of the text. More...
 
HorizontalAlignment getHorizontalAlignment () const
 Returns the horizontal alignment of the text. More...
 
void setVerticalAlignment (VerticalAlignment v_align)
 Sets the vertical alignment of the text. More...
 
VerticalAlignment getVerticalAlignment () const
 Returns the vertical alignment of the text. More...
 
bool intersectsBox (const QRectF &box) const override
 Checks if a path point (excluding curve control points) is included in the given box. More...
 
QTransform calcTextToMapTransform () const
 Returns a QTransform from text coordinates to map coordinates. More...
 
QTransform calcMapToTextTransform () const
 Returns a QTransform from map coordinates to text coordinates. More...
 
int getNumLines () const
 Return the number of rendered lines. More...
 
TextObjectLineInfogetLineInfo (int i)
 Returns the layout information about a particular line. More...
 
const TextObjectLineInfogetLineInfo (int i) const
 Returns the layout information about a particular line. More...
 
int calcTextPositionAt (const MapCoordF &coord, bool find_line_only) const
 Return the index of the character or the line number corresponding to a particular map coordinate. More...
 
int calcTextPositionAt (const QPointF &coord, bool find_line_only) const
 Return the index of the character or the line number corresponding to a particular text coordinate. More...
 
int findLineForIndex (int index) const
 Returns the line number for a particular index in the text. More...
 
const TextObjectLineInfofindLineInfoForIndex (int index) const
 Returns the line layout information for particular index. More...
 
void prepareLineInfos () const
 Prepare the text layout information. More...
 
- Public Member Functions inherited from OpenOrienteering::Object
 Object (Type type, const Symbol *symbol=nullptr)
 Creates an empty object with the given type and (optional) symbol. More...
 
 Object (Type type, const Symbol *symbol, const MapCoordVector &coords, Map *map=nullptr)
 Creates an empty object with the given type, symbol, coords and (optional) map. More...
 
virtual ~Object ()
 Destructs the object. More...
 
Objectoperator= (const Object &other)=delete
 
bool equals (const Object *other, bool compare_symbol) const
 Checks for equality with another object. More...
 
virtual bool validate () const
 
Type getType () const
 Returns the object type determined by the subclass. More...
 
PointObjectasPoint ()
 Convenience cast to PointObject with type checking. More...
 
const PointObjectasPoint () const
 Convenience cast to PointObject with type checking. More...
 
PathObjectasPath ()
 Convenience cast to PathObject with type checking. More...
 
const PathObjectasPath () const
 Convenience cast to PathObject with type checking. More...
 
TextObjectasText ()
 Convenience cast to TextObject with type checking. More...
 
const TextObjectasText () const
 Convenience cast to TextObject with type checking. More...
 
void save (QXmlStreamWriter &xml) const
 Saves the object in xml format to the given stream. More...
 
qreal getRotation () const
 Returns the rotation for this object (in radians). More...
 
void setRotation (qreal new_rotation)
 Sets the object's rotation (in radians). More...
 
bool update () const
 If the output_dirty flag is set, regenerates output and extent, and updates the object's map (if set). More...
 
void forceUpdate () const
 Always regenerates output and extent, and updates the object's map (if set). More...
 
void move (qint32 dx, qint32 dy)
 Moves the whole object. More...
 
void move (const MapCoord &offset)
 Moves the whole object by the given offset. More...
 
void rotateAround (const MapCoordF &center, qreal angle)
 Rotates the whole object around the center point. More...
 
void rotate (qreal angle)
 Rotates the whole object around the center (0, 0). More...
 
int isPointOnObject (const MapCoordF &coord, float tolerance, bool treat_areas_as_paths, bool extended_selection) const
 Checks if the given coord, with the given tolerance, is on this object. More...
 
void takeRenderables ()
 Takes ownership of the renderables. More...
 
void clearRenderables ()
 Deletes the renderables (and extent), undoing update() More...
 
const ObjectRenderablesrenderables () const
 Returns the renderables, read-only. More...
 
const MapCoordVectorgetRawCoordinateVector () const
 Returns the raw MapCoordVector of the object. More...
 
void setOutputDirty (bool dirty=true)
 Sets the object output's dirty state. More...
 
bool isOutputDirty () const
 Returns if the object's output must be regenerated. More...
 
bool setSymbol (const Symbol *new_symbol, bool no_checks)
 Changes the object's symbol, returns if successful. More...
 
const SymbolgetSymbol () const
 Returns the object's symbol. More...
 
const QRectFgetExtent () const
 NOTE: The extent is only valid after update() has been called! More...
 
void setMap (Map *map)
 Sets the object's map pointer. More...
 
MapgetMap () const
 Returns the object's map pointer. More...
 
const Tagstags () const
 Returns a const reference to the object's tags. More...
 
void setTags (const Tags &tags)
 Replaces the object's tags. More...
 
QString getTag (const QString &key) const
 Returns the value of the given tag key. More...
 
void setTag (const QString &key, const QString &value)
 Sets the given tag key to the value. More...
 
void removeTag (const QString &key)
 Removes the given tag key and its value. More...
 
void includeControlPointsRect (QRectF &rect) const
 Extends a rectangle to enclose all of the object's control points. More...
 

Protected Member Functions

 TextObject (const TextObject &proto)
 Constructs a TextObject, initialized from the given prototype. More...
 
- Protected Member Functions inherited from OpenOrienteering::Object
 Object (const Object &proto)
 Constructs a Object, initialized from the given prototype. More...
 
virtual void updateEvent () const
 
virtual void createRenderables (ObjectRenderables &output, Symbol::RenderableOptions options) const
 

Additional Inherited Members

- Static Public Member Functions inherited from OpenOrienteering::Object
static Objectload (QXmlStreamReader &xml, Map *map, const SymbolDictionary &symbol_dict, const Symbol *symbol=nullptr)
 Loads the object in xml format from the given stream. More...
 
static ObjectgetObjectForType (Type type, const Symbol *symbol=nullptr)
 Constructs an object of the given type with the given symbol. More...
 
- Protected Attributes inherited from OpenOrienteering::Object
Type type
 
const Symbolsymbol = nullptr
 
MapCoordVector coords
 
Mapmap = nullptr
 
Tags object_tags
 

Detailed Description

A text object.

A text object is an instance of a text symbol. Its position may be specified by a single coordinate (the anchor point) or by two coordinates (word wrap box: first coordinate specifies the coordinate of the midpoint, second coordinates specifies the width and height).

TODO: the way of defining word wrap boxes is inconvenient, as the second coordinate does not specify a real coordinate in this case, but is misused as extent. Change this?

Member Typedef Documentation

◆ LineInfoContainer

A sequence container of TextObjectLineInfo objects.

Member Enumeration Documentation

◆ HorizontalAlignment

Enumerator
AlignLeft 
AlignHCenter 
AlignRight 

◆ VerticalAlignment

Enumerator
AlignBaseline 
AlignTop 
AlignVCenter 
AlignBottom 

Constructor & Destructor Documentation

◆ TextObject() [1/2]

OpenOrienteering::TextObject::TextObject ( const Symbol symbol = nullptr)
explicit

Construct a new text object.

If a symbol is specified, it must be a text symbol.

Parameters
symbolthe text symbol (optional)

◆ TextObject() [2/2]

OpenOrienteering::TextObject::TextObject ( const TextObject proto)
explicitprotected

Constructs a TextObject, initialized from the given prototype.

Member Function Documentation

◆ calcMapToTextTransform()

QTransform OpenOrienteering::TextObject::calcMapToTextTransform ( ) const

Returns a QTransform from map coordinates to text coordinates.

◆ calcTextPositionAt() [1/2]

int OpenOrienteering::TextObject::calcTextPositionAt ( const MapCoordF coord,
bool  find_line_only 
) const

Return the index of the character or the line number corresponding to a particular map coordinate.

Returns -1 if the coordinate is not at a text position. If find_line_only is true, the line number is returned, otherwise the index of the character.

◆ calcTextPositionAt() [2/2]

int OpenOrienteering::TextObject::calcTextPositionAt ( const QPointF coord,
bool  find_line_only 
) const

Return the index of the character or the line number corresponding to a particular text coordinate.

Returns -1 if the coordinate is not at a text position. If find_line_only is true, the line number is returned, otherwise the index of the character.

◆ calcTextToMapTransform()

QTransform OpenOrienteering::TextObject::calcTextToMapTransform ( ) const

Returns a QTransform from text coordinates to map coordinates.

◆ controlPoints()

std::vector< QPointF > OpenOrienteering::TextObject::controlPoints ( ) const

Returns the positions of the control points.

The returned vector may have one or four members, depending on the type of object.

◆ copyFrom()

void OpenOrienteering::TextObject::copyFrom ( const Object other)
overridevirtual

Reimplemented from OpenOrienteering::Object.

◆ duplicate()

TextObject * OpenOrienteering::TextObject::duplicate ( ) const
overridevirtual

Creates a duplicate of the text object.

Returns
a new object with same text, symbol and formatting.

Implements OpenOrienteering::Object.

◆ findLineForIndex()

int OpenOrienteering::TextObject::findLineForIndex ( int  index) const

Returns the line number for a particular index in the text.

◆ findLineInfoForIndex()

const TextObjectLineInfo & OpenOrienteering::TextObject::findLineInfoForIndex ( int  index) const

Returns the line layout information for particular index.

◆ getAnchorCoordF()

MapCoordF OpenOrienteering::TextObject::getAnchorCoordF ( ) const

Returns the coordinates of the anchor point or midpoint.

◆ getBoxHeight()

qreal OpenOrienteering::TextObject::getBoxHeight ( ) const
inline

Returns the height of the word wrap box.

The text object must have a specified size.

◆ getBoxSize()

MapCoord OpenOrienteering::TextObject::getBoxSize ( ) const
inline

Returns the size as a MapCoord.

◆ getBoxWidth()

qreal OpenOrienteering::TextObject::getBoxWidth ( ) const
inline

Returns the width of the word wrap box.

The text object must have a specified size.

◆ getHorizontalAlignment()

TextObject::HorizontalAlignment OpenOrienteering::TextObject::getHorizontalAlignment ( ) const
inline

Returns the horizontal alignment of the text.

◆ getLineInfo() [1/2]

TextObjectLineInfo * OpenOrienteering::TextObject::getLineInfo ( int  i)
inline

Returns the layout information about a particular line.

◆ getLineInfo() [2/2]

const TextObjectLineInfo * OpenOrienteering::TextObject::getLineInfo ( int  i) const
inline

Returns the layout information about a particular line.

◆ getNumLines()

int OpenOrienteering::TextObject::getNumLines ( ) const
inline

Return the number of rendered lines.

For a text object with a word wrap box, the number of rendered lines may be higher than the number of explicit line breaks in the original text.

◆ getText()

const QString & OpenOrienteering::TextObject::getText ( ) const
inline

Returns the text of the object.

◆ getVerticalAlignment()

TextObject::VerticalAlignment OpenOrienteering::TextObject::getVerticalAlignment ( ) const
inline

Returns the vertical alignment of the text.

◆ hasSingleAnchor()

bool OpenOrienteering::TextObject::hasSingleAnchor ( ) const
inline

Returns true if the text object has a single anchor, false if it has as word wrap box.

◆ intersectsBox()

bool OpenOrienteering::TextObject::intersectsBox ( const QRectF box) const
overridevirtual

Checks if a path point (excluding curve control points) is included in the given box.

Implements OpenOrienteering::Object.

◆ operator=()

TextObject& OpenOrienteering::TextObject::operator= ( const TextObject )
delete

◆ prepareLineInfos()

void OpenOrienteering::TextObject::prepareLineInfos ( ) const

Prepare the text layout information.

◆ scale() [1/2]

void OpenOrienteering::TextObject::scale ( const MapCoordF center,
double  factor 
)
overridevirtual

Scales position and box, with the given scaling center.

Reimplemented from OpenOrienteering::Object.

◆ scale() [2/2]

void OpenOrienteering::TextObject::scale ( double  factor_x,
double  factor_y 
)
overridevirtual

Scales position and box, with the center (0, 0).

Reimplemented from OpenOrienteering::Object.

◆ setAnchorPosition() [1/3]

void OpenOrienteering::TextObject::setAnchorPosition ( qint32  x,
qint32  y 
)

Sets the position of the anchor point to (x,y).

This will drop an existing word wrap box.

◆ setAnchorPosition() [2/3]

void OpenOrienteering::TextObject::setAnchorPosition ( const MapCoord coord)

Sets the position of the anchor point to coord.

This will drop an existing word wrap box.

◆ setAnchorPosition() [3/3]

void OpenOrienteering::TextObject::setAnchorPosition ( const MapCoordF coord)

Sets the position of the anchor point to coord.

This will drop an existing word wrap box.

◆ setBox()

void OpenOrienteering::TextObject::setBox ( qint32  mid_x,
qint32  mid_y,
qreal  width,
qreal  height 
)

Set position and size.

The midpoint is set to (mid_x, mid_y), the size is specified by the parameters width and height.

◆ setBoxSize()

void OpenOrienteering::TextObject::setBoxSize ( const MapCoord size)

Set size.

◆ setHorizontalAlignment()

void OpenOrienteering::TextObject::setHorizontalAlignment ( TextObject::HorizontalAlignment  h_align)

Sets the horizontal alignment of the text.

◆ setText()

void OpenOrienteering::TextObject::setText ( const QString text)

Sets the text of the object.

◆ setVerticalAlignment()

void OpenOrienteering::TextObject::setVerticalAlignment ( TextObject::VerticalAlignment  v_align)

Sets the vertical alignment of the text.

◆ transform()

void OpenOrienteering::TextObject::transform ( const QTransform t)
overridevirtual

Apply a transformation to all coordinates.

Todo:
Handle rotation of patterns or text (?)

Implements OpenOrienteering::Object.


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