Mapper  0.9.0
API documentation
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
OpenOrienteering::Object Class Referenceabstract

Abstract base class which combines coordinates and a symbol to form an object (in a map, or inside a point symbol as one of its elements). More...

#include <object.h>

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

Public Types

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

 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
 
virtual void copyFrom (const Object &other)
 
virtual Objectduplicate () const =0
 Creates an identical copy of the object. More...
 
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...
 
virtual void scale (const MapCoordF &center, double factor)
 Scales all coordinates, with the given scaling center. More...
 
virtual void scale (double factor_x, double factor_y)
 Scales all coordinates, with the center (0, 0). 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...
 
virtual void transform (const QTransform &t)=0
 Apply a transformation to all coordinates. 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...
 
virtual bool intersectsBox (const QRectF &box) const =0
 Checks if a path point (excluding curve control points) is included in the given box. 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...
 

Static Public Member Functions

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 Member Functions

 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
 

Protected Attributes

Type type
 
const Symbolsymbol = nullptr
 
MapCoordVector coords
 
Mapmap = nullptr
 
Tags object_tags
 

Friends

class ObjectRenderables
 
class OCAD8FileImport
 
class XMLImportExport
 

Detailed Description

Abstract base class which combines coordinates and a symbol to form an object (in a map, or inside a point symbol as one of its elements).

Every object must have a symbol. If the symbol is not known, one of the "undefined" symbols from the Map class can be used.

From the object's data, a call to update() will generate the object's "output", that is a set of renderables and the calculation of the object's extent (bounding box). The renderables can then be inserted into a map where they are used to display the object.

Member Typedef Documentation

◆ Tags

Defines a type which maps keys to values, to be used for tagging objects.

Member Enumeration Documentation

◆ Type

Enumeration of possible object types.

Enumerator
Point 

A single coordinate, no further coordinates can be added.

For point symbols only.

Path 

A dynamic list of coordinates.

For line, area and combined symbols.

Text 

Either one or two coordinates, for single-anchor or box text.

For text symbols only.

Constructor & Destructor Documentation

◆ Object() [1/3]

OpenOrienteering::Object::Object ( Object::Type  type,
const Symbol symbol = nullptr 
)
explicit

Creates an empty object with the given type and (optional) symbol.

◆ Object() [2/3]

OpenOrienteering::Object::Object ( Object::Type  type,
const Symbol symbol,
const MapCoordVector coords,
Map map = nullptr 
)
explicit

Creates an empty object with the given type, symbol, coords and (optional) map.

◆ Object() [3/3]

OpenOrienteering::Object::Object ( const Object proto)
explicitprotected

Constructs a Object, initialized from the given prototype.

Note that the object is NOT added to a map, and consequently, the map pointer is initialized to nullptr.

◆ ~Object()

OpenOrienteering::Object::~Object ( )
virtualdefault

Destructs the object.

Member Function Documentation

◆ asPath() [1/2]

PathObject * OpenOrienteering::Object::asPath ( )

Convenience cast to PathObject with type checking.

◆ asPath() [2/2]

const PathObject * OpenOrienteering::Object::asPath ( ) const

Convenience cast to PathObject with type checking.

◆ asPoint() [1/2]

PointObject * OpenOrienteering::Object::asPoint ( )

Convenience cast to PointObject with type checking.

◆ asPoint() [2/2]

const PointObject * OpenOrienteering::Object::asPoint ( ) const

Convenience cast to PointObject with type checking.

◆ asText() [1/2]

TextObject * OpenOrienteering::Object::asText ( )

Convenience cast to TextObject with type checking.

◆ asText() [2/2]

const TextObject * OpenOrienteering::Object::asText ( ) const

Convenience cast to TextObject with type checking.

◆ clearRenderables()

void OpenOrienteering::Object::clearRenderables ( )

Deletes the renderables (and extent), undoing update()

◆ copyFrom()

void OpenOrienteering::Object::copyFrom ( const Object other)
virtual

◆ createRenderables()

void OpenOrienteering::Object::createRenderables ( ObjectRenderables output,
Symbol::RenderableOptions  options 
) const
protectedvirtual

Reimplemented in OpenOrienteering::PathObject.

◆ duplicate()

virtual Object* OpenOrienteering::Object::duplicate ( ) const
pure virtual

Creates an identical copy of the object.

This needs to be implemented in non-abstract subclasses. Implementation should use the copy constructor to ensure proper initialization.

Implemented in OpenOrienteering::PointObject, OpenOrienteering::PathObject, and OpenOrienteering::TextObject.

◆ equals()

bool OpenOrienteering::Object::equals ( const Object other,
bool  compare_symbol 
) const

Checks for equality with another object.

If compare_symbol is set, also the symbols are compared for having the same properties. Note that the map property is not compared.

◆ forceUpdate()

void OpenOrienteering::Object::forceUpdate ( ) const

Always regenerates output and extent, and updates the object's map (if set).

◆ getExtent()

const QRectF & OpenOrienteering::Object::getExtent ( ) const
inline

NOTE: The extent is only valid after update() has been called!

◆ getMap()

Map * OpenOrienteering::Object::getMap ( ) const
inline

Returns the object's map pointer.

◆ getObjectForType()

Object * OpenOrienteering::Object::getObjectForType ( Object::Type  type,
const Symbol symbol = nullptr 
)
static

Constructs an object of the given type with the given symbol.

◆ getRawCoordinateVector()

const MapCoordVector & OpenOrienteering::Object::getRawCoordinateVector ( ) const
inline

Returns the raw MapCoordVector of the object.

It's layout and interpretation depends on the object type.

◆ getRotation()

qreal OpenOrienteering::Object::getRotation ( ) const
inline

Returns the rotation for this object (in radians).

The interpretation of this value depends the object's symbol.

◆ getSymbol()

const Symbol * OpenOrienteering::Object::getSymbol ( ) const
inline

Returns the object's symbol.

◆ getTag()

QString OpenOrienteering::Object::getTag ( const QString key) const
inline

Returns the value of the given tag key.

◆ getType()

Object::Type OpenOrienteering::Object::getType ( ) const
inline

Returns the object type determined by the subclass.

◆ includeControlPointsRect()

void OpenOrienteering::Object::includeControlPointsRect ( QRectF rect) const

Extends a rectangle to enclose all of the object's control points.

◆ intersectsBox()

virtual bool OpenOrienteering::Object::intersectsBox ( const QRectF box) const
pure virtual

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

Implemented in OpenOrienteering::PointObject, OpenOrienteering::PathObject, and OpenOrienteering::TextObject.

◆ isOutputDirty()

bool OpenOrienteering::Object::isOutputDirty ( ) const
inline

Returns if the object's output must be regenerated.

◆ isPointOnObject()

int OpenOrienteering::Object::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.

With extended_selection, the coord is on point objects always if it is within their extent, otherwise it has to be close to their midpoint. Returns a Symbol::Type which specifies on which symbol type the coord is (important for combined symbols which can have areas and lines).

◆ load()

Object * OpenOrienteering::Object::load ( QXmlStreamReader xml,
Map map,
const SymbolDictionary symbol_dict,
const Symbol symbol = nullptr 
)
static

Loads the object in xml format from the given stream.

Parameters
xmlThe stream to load the object from, must be at the correct tag.
mapThe map in which the object will be inserted. This value will be assigned to the object's map pointer It may be nullptr.
symbol_dictA dictionary mapping symbol IDs to symbol pointers.
symbolIf set, this symbol will be assigned to the object, rather than reading the symbol from the stream.
Todo:
Add a warning, but don't throw - throwing lets loading fail.

◆ move() [1/2]

void OpenOrienteering::Object::move ( qint32  dx,
qint32  dy 
)

Moves the whole object.

Parameters
dxX offset in native map coordinates.
dyY offset in native map coordinates.

◆ move() [2/2]

void OpenOrienteering::Object::move ( const MapCoord offset)

Moves the whole object by the given offset.

◆ operator=()

Object& OpenOrienteering::Object::operator= ( const Object other)
delete

◆ removeTag()

void OpenOrienteering::Object::removeTag ( const QString key)

Removes the given tag key and its value.

◆ renderables()

const ObjectRenderables & OpenOrienteering::Object::renderables ( ) const
inline

Returns the renderables, read-only.

◆ rotate()

void OpenOrienteering::Object::rotate ( qreal  angle)

Rotates the whole object around the center (0, 0).

The angle must be given in radians.

◆ rotateAround()

void OpenOrienteering::Object::rotateAround ( const MapCoordF center,
qreal  angle 
)

Rotates the whole object around the center point.

The angle must be given in radians.

◆ save()

void OpenOrienteering::Object::save ( QXmlStreamWriter xml) const

Saves the object in xml format to the given stream.

Todo:
From Mapper 1.0, save just the single anchor coordinate.

◆ scale() [1/2]

void OpenOrienteering::Object::scale ( const MapCoordF center,
double  factor 
)
virtual

Scales all coordinates, with the given scaling center.

Reimplemented in OpenOrienteering::TextObject.

◆ scale() [2/2]

void OpenOrienteering::Object::scale ( double  factor_x,
double  factor_y 
)
virtual

Scales all coordinates, with the center (0, 0).

Parameters
factor_xhorizontal scaling factor
factor_yvertical scaling factor

Reimplemented in OpenOrienteering::TextObject.

◆ setMap()

void OpenOrienteering::Object::setMap ( Map map)
inline

Sets the object's map pointer.

May be nullptr if the object is not in a map.

◆ setOutputDirty()

void OpenOrienteering::Object::setOutputDirty ( bool  dirty = true)
inline

Sets the object output's dirty state.

◆ setRotation()

void OpenOrienteering::Object::setRotation ( qreal  new_rotation)

Sets the object's rotation (in radians).

The interpretation of this value depends the object's symbol. It may have no effect at all. The value must not be NaN.

◆ setSymbol()

bool OpenOrienteering::Object::setSymbol ( const Symbol new_symbol,
bool  no_checks 
)

Changes the object's symbol, returns if successful.

Some conversions are impossible, for example point to line. Normally, this method checks if the types of the old and the new symbol are compatible. If the old symbol pointer is no longer valid, you can use no_checks to disable this.

◆ setTag()

void OpenOrienteering::Object::setTag ( const QString key,
const QString value 
)

Sets the given tag key to the value.

◆ setTags()

void OpenOrienteering::Object::setTags ( const Tags tags)

Replaces the object's tags.

◆ tags()

const Object::Tags & OpenOrienteering::Object::tags ( ) const
inline

Returns a const reference to the object's tags.

◆ takeRenderables()

void OpenOrienteering::Object::takeRenderables ( )

Takes ownership of the renderables.

◆ transform()

virtual void OpenOrienteering::Object::transform ( const QTransform t)
pure virtual

Apply a transformation to all coordinates.

Todo:
Handle rotation of patterns or text (?)

Implemented in OpenOrienteering::PointObject, OpenOrienteering::PathObject, and OpenOrienteering::TextObject.

◆ update()

bool OpenOrienteering::Object::update ( ) const

If the output_dirty flag is set, regenerates output and extent, and updates the object's map (if set).

Returns true if output was dirty.

◆ updateEvent()

void OpenOrienteering::Object::updateEvent ( ) const
protectedvirtual

Reimplemented in OpenOrienteering::PathObject.

◆ validate()

bool OpenOrienteering::Object::validate ( ) const
virtual

Reimplemented in OpenOrienteering::PathObject.

Friends And Related Function Documentation

◆ ObjectRenderables

friend class ObjectRenderables
friend

◆ OCAD8FileImport

friend class OCAD8FileImport
friend

◆ XMLImportExport

friend class XMLImportExport
friend

Member Data Documentation

◆ coords

MapCoordVector OpenOrienteering::Object::coords
protected

◆ map

Map* OpenOrienteering::Object::map = nullptr
protected

◆ object_tags

Tags OpenOrienteering::Object::object_tags
protected

◆ symbol

const Symbol* OpenOrienteering::Object::symbol = nullptr
protected

◆ type

Type OpenOrienteering::Object::type
protected

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