Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move QgsLabelFeature and QgsTextLabelFeature class to separate files
No actual code changes

This code has been funded by Tuscany Region (Italy) - SITA (CIG: 63526840AE) and commissioned to Gis3W s.a.s.
  • Loading branch information
wonder-sk committed Jan 4, 2016
1 parent 215ba22 commit 5ac6170
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 272 deletions.
5 changes: 4 additions & 1 deletion src/core/CMakeLists.txt
Expand Up @@ -120,6 +120,7 @@ SET(QGIS_CORE_SRCS
qgslayerdefinition.cpp
qgslabel.cpp
qgslabelattributes.cpp
qgslabelfeature.cpp
qgslabelingenginev2.cpp
qgslabelsearchtree.cpp
qgslegacyhelpers.cpp
Expand Down Expand Up @@ -184,6 +185,7 @@ SET(QGIS_CORE_SRCS
qgsstatisticalsummary.cpp
qgsstringutils.cpp
qgstransaction.cpp
qgstextlabelfeature.cpp
qgstolerance.cpp
qgsvectordataprovider.cpp
qgsvectorfilewriter.cpp
Expand Down Expand Up @@ -608,6 +610,7 @@ SET(QGIS_CORE_HDRS
qgslayerdefinition.h
qgslabel.h
qgslabelattributes.h
qgslabelfeature.h
qgslabelingenginev2.h
qgslabelsearchtree.h
qgslegacyhelpers.h
Expand All @@ -627,7 +630,6 @@ SET(QGIS_CORE_HDRS
qgsogcutils.h
qgsowsconnection.h
qgspaintenginehack.h
qgspalgeometry.h
qgspallabeling.h
qgspluginlayerregistry.h
qgspoint.h
Expand Down Expand Up @@ -655,6 +657,7 @@ SET(QGIS_CORE_HDRS
qgssqlexpressioncompiler.h
qgsstatisticalsummary.h
qgsstringutils.h
qgstextlabelfeature.h
qgstolerance.h

qgsvectordataprovider.h
Expand Down
3 changes: 2 additions & 1 deletion src/core/dxf/qgsdxfpallabeling.cpp
Expand Up @@ -17,10 +17,11 @@

#include "qgsdxfpallabeling.h"
#include "qgsdxfexport.h"
#include "qgspalgeometry.h"
#include "qgstextlabelfeature.h"
#include "qgspallabeling.h"
#include "qgsmapsettings.h"

#include "pal/feature.h"
#include "pal/pointset.h"
#include "pal/labelposition.h"

Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/feature.h
Expand Up @@ -39,7 +39,7 @@
#include <cmath>
#include <QString>

#include "qgslabelingenginev2.h"
#include "qgslabelfeature.h"

/**
* \class pal::LabelInfo
Expand Down
2 changes: 2 additions & 0 deletions src/core/pal/problem.cpp
Expand Up @@ -41,6 +41,8 @@
#include <cfloat>
#include <limits.h> //for INT_MAX

#include "qgslabelingenginev2.h"

using namespace pal;

inline void delete_chain( Chain *chain )
Expand Down
43 changes: 43 additions & 0 deletions src/core/qgslabelfeature.cpp
@@ -0,0 +1,43 @@
#include "qgslabelfeature.h"

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Jan 5, 2016

Collaborator

@wonder-sk Nice clean up! Just a note - these files are missing copyright headers

This comment has been minimized.

Copy link
@wonder-sk

wonder-sk Jan 6, 2016

Author Member

Ah right - will add those. thanks for the note!


#include "feature.h"


QgsLabelFeature::QgsLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, const QSizeF& size )
: mLayer( nullptr )
, mId( id )
, mGeometry( geometry )
, mObstacleGeometry( nullptr )
, mSize( size )
, mPriority( -1 )
, mHasFixedPosition( false )
, mHasFixedAngle( false )
, mFixedAngle( 0 )
, mHasFixedQuadrant( false )
, mDistLabel( 0 )
, mRepeatDistance( 0 )
, mAlwaysShow( false )
, mIsObstacle( false )
, mObstacleFactor( 1 )
, mInfo( nullptr )
{
}

QgsLabelFeature::~QgsLabelFeature()
{
if ( mGeometry )
GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mGeometry );

if ( mObstacleGeometry )
GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mObstacleGeometry );

delete mInfo;
}

void QgsLabelFeature::setObstacleGeometry( GEOSGeometry* obstacleGeom )
{
if ( mObstacleGeometry )
GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mObstacleGeometry );

mObstacleGeometry = obstacleGeom;
}
233 changes: 233 additions & 0 deletions src/core/qgslabelfeature.h
@@ -0,0 +1,233 @@
#ifndef QGSLABELFEATURE_H
#define QGSLABELFEATURE_H

#include "qgsgeometry.h"

#include "qgspallabeling.h"

namespace pal
{
class LabelInfo;
}

class QgsAbstractLabelProvider;
class QgsRenderContext;
class QgsGeometry;


/**
* @brief The QgsLabelFeature class describes a feature that
* should be used within the labeling engine. Those may be the usual textual labels,
* diagrams, or any other custom type of map annotations (generated by custom
* label providers).
*
* Instances only contain data relevant to the labeling engine (geometry, label size etc.)
* necessary for the layout. Rendering of labels is done by label providers.
*
* Individual label providers may create subclasses of QgsLabelFeature in order to add
* more data to the instances that will be later used for drawing of labels.
*
* @note this class is not a part of public API yet. See notes in QgsLabelingEngineV2
* @note added in QGIS 2.12
*/
class CORE_EXPORT QgsLabelFeature
{
public:
//! Create label feature, takes ownership of the geometry instance
QgsLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, const QSizeF& size );
//! Clean up geometry and curved label info (if present)
virtual ~QgsLabelFeature();

//! Identifier of the label (unique within the parent label provider)
QgsFeatureId id() const { return mId; }

//! Get access to the associated geometry
GEOSGeometry* geometry() const { return mGeometry; }

/** Sets the label's obstacle geometry, if different to the feature geometry.
* This can be used to override the shape of the feature for obstacle detection, eg to
* buffer around a point geometry to prevent labels being placed too close to the
* point itself. It not set, the feature's geometry is used for obstacle detection.
* Ownership of obstacle geometry is transferred.
* @note added in QGIS 2.14
* @see obstacleGeometry()
*/
void setObstacleGeometry( GEOSGeometry* obstacleGeom );

/** Returns the label's obstacle geometry, if different to the feature geometry.
* @note added in QGIS 2.14
* @see setObstacleGeometry()
*/
GEOSGeometry* obstacleGeometry() const { return mObstacleGeometry; }

//! Size of the label (in map units)
QSizeF size() const { return mSize; }

/** Returns the feature's labeling priority.
* @returns feature's priority, as a value between 0 (highest priority)
* and 1 (lowest priority). Returns -1.0 if feature will use the layer's default priority.
* @see setPriority
*/
double priority() const { return mPriority; }
/** Sets the priority for labeling the feature.
* @param priority feature's priority, as a value between 0 (highest priority)
* and 1 (lowest priority). Set to -1.0 to use the layer's default priority
* for this feature.
* @see priority
*/
void setPriority( double priority ) { mPriority = priority; }

//! Whether the label should use a fixed position instead of being automatically placed
bool hasFixedPosition() const { return mHasFixedPosition; }
//! Set whether the label should use a fixed position instead of being automatically placed
void setHasFixedPosition( bool enabled ) { mHasFixedPosition = enabled; }
//! Coordinates of the fixed position (relevant only if hasFixedPosition() returns true)
QgsPoint fixedPosition() const { return mFixedPosition; }
//! Set coordinates of the fixed position (relevant only if hasFixedPosition() returns true)
void setFixedPosition( const QgsPoint& point ) { mFixedPosition = point; }

//! Whether the label should use a fixed angle instead of using angle from automatic placement
bool hasFixedAngle() const { return mHasFixedAngle; }
//! Set whether the label should use a fixed angle instead of using angle from automatic placement
void setHasFixedAngle( bool enabled ) { mHasFixedAngle = enabled; }
//! Angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true)
double fixedAngle() const { return mFixedAngle; }
//! Set angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true)
void setFixedAngle( double angle ) { mFixedAngle = angle; }

/** Returns whether the quadrant for the label is fixed.
* Applies to "around point" placement strategy.
* @see setFixedQuadrant
* @see quadOffset
*/
bool hasFixedQuadrant() const { return mHasFixedQuadrant; }
/** Sets whether the quadrant for the label must be respected. This can be used
* to fix the quadrant for specific features when using an "around point" placement.
* @see fixedQuadrant
* @see quadOffset
*/
void setHasFixedQuadrant( bool enabled ) { mHasFixedQuadrant = enabled; }
//! Applies to "offset from point" placement strategy and "around point" (in case hasFixedQuadrant() returns true).
//! Determines which side of the point to use.
//! For X coordinate, values -1, 0, 1 mean left, center, right.
//! For Y coordinate, values -1, 0, 1 mean above, center, below.
QPointF quadOffset() const { return mQuadOffset; }
//! Set which side of the point to use
//! @see quadOffset
void setQuadOffset( const QPointF& quadOffset ) { mQuadOffset = quadOffset; }
//! Applies only to "offset from point" placement strategy.
//! What offset (in map units) to use from the point
QgsPoint positionOffset() const { return mPositionOffset; }
//! Applies only to "offset from point" placement strategy.
//! Set what offset (in map units) to use from the point
void setPositionOffset( const QgsPoint& offset ) { mPositionOffset = offset; }
//! Applies to "around point" placement strategy or linestring features.
//! Distance of the label from the feature (in map units)
double distLabel() const { return mDistLabel; }
//! Applies to "around point" placement strategy or linestring features.
//! Set distance of the label from the feature (in map units)
void setDistLabel( double dist ) { mDistLabel = dist; }

//! Applies only to linestring features - after what distance (in map units)
//! the labels should be repeated (0 = no repetitions)
double repeatDistance() const { return mRepeatDistance; }
//! Applies only to linestring features - set after what distance (in map units)
//! the labels should be repeated (0 = no repetitions)
void setRepeatDistance( double dist ) { mRepeatDistance = dist; }

//! Whether label should be always shown (sets very high label priority)
bool alwaysShow() const { return mAlwaysShow; }
//! Set whether label should be always shown (sets very high label priority)
void setAlwaysShow( bool enabled ) { mAlwaysShow = enabled; }

/** Returns whether the feature will act as an obstacle for labels.
* @returns true if feature is an obstacle
* @see setIsObstacle
*/
bool isObstacle() const { return mIsObstacle; }
/** Sets whether the feature will act as an obstacle for labels.
* @param enabled whether feature will act as an obstacle
* @see isObstacle
*/
void setIsObstacle( bool enabled ) { mIsObstacle = enabled; }
/** Returns the obstacle factor for the feature. The factor controls the penalty
* for labels overlapping this feature.
* @see setObstacleFactor
*/
double obstacleFactor() const { return mObstacleFactor; }
/** Sets the obstacle factor for the feature. The factor controls the penalty
* for labels overlapping this feature.
* @param factor larger factors ( > 1.0 ) will result in labels
* which are less likely to cover this feature, smaller factors ( < 1.0 ) mean labels
* are more likely to cover this feature (where required)
* @see obstacleFactor
*/
void setObstacleFactor( double factor ) { mObstacleFactor = factor; }

/** Text of the label
*
* Used also if "merge connected lines to avoid duplicate labels" is enabled
* to identify which features may be merged.
*/
QString labelText() const { return mLabelText; }
//! Set text of the label
void setLabelText( const QString& text ) { mLabelText = text; }

//! Get additional infor required for curved label placement. Returns null if not set
pal::LabelInfo* curvedLabelInfo() const { return mInfo; }
//! takes ownership of the instance
void setCurvedLabelInfo( pal::LabelInfo* info ) { mInfo = info; }

//! Get PAL layer of the label feature. Should be only used internally in PAL
pal::Layer* layer() const { return mLayer; }
//! Assign PAL layer to the label feature. Should be only used internally in PAL
void setLayer( pal::Layer* layer ) { mLayer = layer; }

//! Return provider of this instance
QgsAbstractLabelProvider* provider() const;

protected:
//! Pointer to PAL layer (assigned when registered to PAL)
pal::Layer* mLayer;

//! Associated ID unique within the parent label provider
QgsFeatureId mId;
//! Geometry of the feature to be labelled
GEOSGeometry* mGeometry;
//! Optional geometry to use for label obstacles, if different to mGeometry
GEOSGeometry* mObstacleGeometry;
//! Width and height of the label
QSizeF mSize;
//! Priority of the label
double mPriority;
//! whether mFixedPosition should be respected
bool mHasFixedPosition;
//! fixed position for the label (instead of automatic placement)
QgsPoint mFixedPosition;
//! whether mFixedAngle should be respected
bool mHasFixedAngle;
//! fixed rotation for the label (instead of automatic choice)
double mFixedAngle;
//! whether mQuadOffset should be respected (only for "around point" placement)
bool mHasFixedQuadrant;
//! whether the side of the label is fixed (only for "around point" placement)
QPointF mQuadOffset;
//! offset of label from the feature (only for "offset from point" placement)
QgsPoint mPositionOffset;
//! distance of label from the feature (only for "around point" placement or linestrings)
double mDistLabel;
//! distance after which label should be repeated (only for linestrings)
double mRepeatDistance;
//! whether to always show label - even in case of collisions
bool mAlwaysShow;
//! whether the feature geometry acts as an obstacle for labels
bool mIsObstacle;
//! how strong is the geometry acting as obstacle
double mObstacleFactor;
//! text of the label
QString mLabelText;
//! extra information for curved labels (may be null)
pal::LabelInfo* mInfo;
};

#endif // QGSLABELFEATURE_H
41 changes: 0 additions & 41 deletions src/core/qgslabelingenginev2.cpp
Expand Up @@ -340,47 +340,6 @@ void QgsLabelingEngineV2::writeSettingsToProject()

////



QgsLabelFeature::QgsLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, const QSizeF& size )
: mLayer( nullptr )
, mId( id )
, mGeometry( geometry )
, mObstacleGeometry( nullptr )
, mSize( size )
, mPriority( -1 )
, mHasFixedPosition( false )
, mHasFixedAngle( false )
, mFixedAngle( 0 )
, mHasFixedQuadrant( false )
, mDistLabel( 0 )
, mRepeatDistance( 0 )
, mAlwaysShow( false )
, mIsObstacle( false )
, mObstacleFactor( 1 )
, mInfo( nullptr )
{
}

QgsLabelFeature::~QgsLabelFeature()
{
if ( mGeometry )
GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mGeometry );

if ( mObstacleGeometry )
GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mObstacleGeometry );

delete mInfo;
}

void QgsLabelFeature::setObstacleGeometry( GEOSGeometry* obstacleGeom )
{
if ( mObstacleGeometry )
GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mObstacleGeometry );

mObstacleGeometry = obstacleGeom;
}

QgsAbstractLabelProvider*QgsLabelFeature::provider() const
{
return mLayer ? mLayer->provider() : nullptr;
Expand Down

0 comments on commit 5ac6170

Please sign in to comment.