Documentation fixes, memory leak fixes

This code has been funded by Tuscany Region (Italy) - SITA (CIG: 63526840AE) and commissioned to Gis3W s.a.s.
This commit is contained in:
Martin Dobias 2015-09-20 13:45:33 +08:00
parent b5e492277b
commit eabfe021b2
13 changed files with 180 additions and 70 deletions

View File

@ -38,7 +38,7 @@ void QgsDxfLabelProvider::drawLabel( QgsRenderContext& context, pal::LabelPositi
//debug: print label infos
if ( mDxfExport )
{
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->userFeature() );
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->feature() );
if ( !lf )
return;

View File

@ -82,7 +82,7 @@ namespace pal
public:
/** Creates a new generic feature.
* @param feat a pointer for a feature which contains the spatial entites
* @param lf a pointer for a feature which contains the spatial entites
* @param geom a pointer to a GEOS geometry
*/
FeaturePart( QgsLabelFeature* lf, const GEOSGeometry* geom );
@ -167,8 +167,6 @@ namespace pal
void print();
#endif
QgsLabelFeature* userFeature() { return mLF; }
double getLabelWidth() const { return mLF->size().width(); }
double getLabelHeight() const { return mLF->size().height(); }
double getLabelDistance() const { return mLF->distLabel(); }
@ -181,7 +179,9 @@ namespace pal
double obstacleFactor() { return mLF->obstacleFactor(); }
double repeatDistance() { return mLF->repeatDistance(); }
//! Get number of holes (inner rings) - they are considered as obstacles
int getNumSelfObstacles() const { return mHoles.count(); }
//! Get hole (inner ring) - considered as obstacle
FeaturePart* getSelfObstacle( int i ) { return mHoles.at( i ); }
/** Check whether this part is connected with some other part */

View File

@ -226,33 +226,13 @@ namespace pal
bool fitInPolygonOnly() const { return mFitInPolygon; }
/** Register a feature in the layer.
* @param fid unique identifier
* @param userGeom user's geometry (does not take ownership)
* @param label_x label width
* @param label_y label height
* @param labelText label text
* @param labelPosX x position of the label (in case of fixed label position)
* @param labelPosY y position of the label (in case of fixed label position)
* @param fixedPos true if a single fixed position for this label is needed
* @param angle fixed angle (in radians) to rotate the label
* @param fixedAngle whether to use provided fixed angle
* @param xQuadOffset move label to quadrant: left, don't move, right (-1, 0, 1)
* @param yQuadOffset move label to quadrant: down, don't move, up (-1, 0, 1)
* @param xOffset map unit (+/-) to x-offset the label
* @param yOffset map unit (+/-) to y-offset the label
* @param alwaysShow whether to skip priority and always show the label (causes overlapping)
* @param repeatDistance distance for repeating the label
*
* Does not take ownership of the label feature (it is owned by its provider).
*
* @throws PalException::FeatureExists
*
* @return true on success (i.e. valid geometry)
*/
bool registerFeature( QgsLabelFeature* label, QgsFeatureId fid, const GEOSGeometry *userGeom, double label_x = -1, double label_y = -1,
const QString& labelText = QString(), double labelPosX = 0.0, double labelPosY = 0.0,
bool fixedPos = false, double angle = 0.0, bool fixedAngle = false,
int xQuadOffset = 0, int yQuadOffset = 0, double xOffset = 0.0, double yOffset = 0.0,
bool alwaysShow = false, double repeatDistance = 0 );
bool registerFeature( QgsLabelFeature* label );
/** Join connected features with the same label text */

View File

@ -263,7 +263,7 @@ void QgsLabelingEngineV2::run( QgsRenderContext& context )
if ( context.renderingStopped() )
break;
QgsLabelFeature* lf = ( *it )->getFeaturePart()->userFeature();
QgsLabelFeature* lf = ( *it )->getFeaturePart()->feature();
if ( !lf )
{
continue;

View File

@ -51,6 +51,7 @@ 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)
@ -78,16 +79,20 @@ class CORE_EXPORT QgsLabelFeature
//! 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.
@ -107,22 +112,32 @@ class CORE_EXPORT QgsLabelFeature
//! 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 to use from the point
//! 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.
@ -131,7 +146,7 @@ class CORE_EXPORT QgsLabelFeature
*/
bool isObstacle() const { return mIsObstacle; }
/** Sets whether the feature will act as an obstacle for labels.
* @param obstacle whether feature will act as an obstacle
* @param enabled whether feature will act as an obstacle
* @see isObstacle
*/
void setIsObstacle( bool enabled ) { mIsObstacle = enabled; }
@ -149,11 +164,13 @@ class CORE_EXPORT QgsLabelFeature
*/
void setObstacleFactor( double factor ) { mObstacleFactor = factor; }
//! Text of the label
//!
//! Used if "merge connected lines to avoid duplicate labels" is enabled
//! to identify which features may be merged
/** 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
@ -164,9 +181,10 @@ class CORE_EXPORT QgsLabelFeature
//! 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; }
void setLayer( pal::Layer* layer ) { mLayer = layer; }
protected:
//! Pointer to PAL layer (assigned when registered to PAL)
pal::Layer* mLayer;
//! Associated ID unique within the parent label provider
@ -175,20 +193,35 @@ class CORE_EXPORT QgsLabelFeature
GEOSGeometry* mGeometry;
//! 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;
};
@ -202,15 +235,20 @@ class QgsLabelingEngineV2;
* return list of labels and their associated geometries - these are used by
* QgsLabelingEngineV2 to compute the final layout of labels.
*
* Implementations also take care of drawing the returned final label positions.
*
* @note added in QGIS 2.12
*/
class CORE_EXPORT QgsAbstractLabelProvider
{
public:
//! Construct the provider with default values
QgsAbstractLabelProvider();
//! Vritual destructor
virtual ~QgsAbstractLabelProvider() {}
//! Associate provider with a labeling engine (should be only called internally from QgsLabelingEngineV2)
void setEngine( const QgsLabelingEngineV2* engine ) { mEngine = engine; }
enum Flag
@ -227,35 +265,47 @@ class CORE_EXPORT QgsAbstractLabelProvider
//! Return unique identifier of the provider
virtual QString id() const = 0;
//! Return list of labels
//! Return list of label features (they are owned by the provider and thus deleted on its destruction)
virtual QList<QgsLabelFeature*> labelFeatures( const QgsRenderContext& context ) = 0;
//! draw this label at the position determined by the labeling engine
virtual void drawLabel( QgsRenderContext& context, pal::LabelPosition* label ) const = 0;
//! Flags associated with the provider
Flags flags() const { return mFlags; }
//! What placement strategy to use for the labels
QgsPalLayerSettings::Placement placement() const { return mPlacement; }
//! For layers with linestring geometries - extra placement flags (or-ed combination of QgsPalLayerSettings::LinePlacementFlags)
unsigned int linePlacementFlags() const { return mLinePlacementFlags; }
//! Default priority of labels (may be overridden by individual labels)
double priority() const { return mPriority; }
//! How the feature geometries will work as obstacles
QgsPalLayerSettings::ObstacleType obstacleType() const { return mObstacleType; }
unsigned int upsidedownLabels() const { return mUpsidedownLabels; }
//! How to handle labels that would be upside down
QgsPalLayerSettings::UpsideDownLabels upsidedownLabels() const { return mUpsidedownLabels; }
protected:
//! Associated labeling engine
const QgsLabelingEngineV2* mEngine;
//! Flags altering drawing and registration of features
Flags mFlags;
//! Placement strategy
QgsPalLayerSettings::Placement mPlacement;
//! Extra placement flags for linestring geometries
unsigned int mLinePlacementFlags;
//! Default priority of labels
double mPriority;
//! Type of the obstacle of feature geometries
QgsPalLayerSettings::ObstacleType mObstacleType;
unsigned int mUpsidedownLabels;
//! How to handle labels that would be upside down
QgsPalLayerSettings::UpsideDownLabels mUpsidedownLabels;
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAbstractLabelProvider::Flags )
@ -269,12 +319,29 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAbstractLabelProvider::Flags )
* with no collisions between the labels. Drawing of resulting labels is done
* again by label providers.
*
* The labeling engine is used for the map rendering in QgsMapRendererJob instances,
* individual map layer renderers may add label providers - for example,
* QgsVectorLayerRenderer may add text label provider and diagram provider
* (if labeling / diagrams were configured for such vector layer).
*
* The labeling engine may also be used independently from map rendering loop:
* \code
* QgsLabelingEngineV2 engine;
* engine.setMapSettings( mapSettings );
* // add one or more providers
* engine.addProvider( ... );
* // compute the labeling and draw labels (using painter from the context)
* engine.run( context );
* \endcode
*
* @note added in QGIS 2.12
*/
class CORE_EXPORT QgsLabelingEngineV2
{
public:
//! Construct the labeling engine with default settings
QgsLabelingEngineV2();
//! Clean up everything (especially the registered providers)
~QgsLabelingEngineV2();
enum Flag
@ -288,7 +355,9 @@ class CORE_EXPORT QgsLabelingEngineV2
};
Q_DECLARE_FLAGS( Flags, Flag )
//! Associate map settings instance
void setMapSettings( const QgsMapSettings& mapSettings ) { mMapSettings = mapSettings; }
//! Get associated map settings
const QgsMapSettings& mapSettings() const { return mMapSettings; }
//! Add provider of label features. Takes ownership of the provider
@ -309,27 +378,43 @@ class CORE_EXPORT QgsLabelingEngineV2
//! For internal use by the providers
QgsLabelingResults* results() const { return mResults; }
//! Set flags of the labeling engine
void setFlags( Flags flags ) { mFlags = flags; }
//! Get flags of the labeling engine
Flags flags() const { return mFlags; }
//! Test whether a particular flag is enabled
bool testFlag( Flag f ) const { return mFlags.testFlag( f ); }
void setFlag( Flag f, bool enabled ) { if ( enabled ) mFlags |= f; else mFlags &= ~f; }
//! Set whether a particual flag is enabled
void setFlag( Flag f, bool enabled = true ) { if ( enabled ) mFlags |= f; else mFlags &= ~f; }
//! Get number of candidate positions that will be generated for each label feature (default to 8)
void numCandidatePositions( int& candPoint, int& candLine, int& candPolygon ) { candPoint = mCandPoint; candLine = mCandLine; candPolygon = mCandPolygon; }
//! Set number of candidate positions that will be generated for each label feature
void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ) { mCandPoint = candPoint; mCandLine = candLine; mCandPolygon = candPolygon; }
//! Set which search method to use for removal collisions between labels
void setSearchMethod( QgsPalLabeling::Search s ) { mSearchMethod = s; }
//! Which search method to use for removal collisions between labels
QgsPalLabeling::Search searchMethod() const { return mSearchMethod; }
//! Read configuration of the labeling engine from the current project file
void readSettingsFromProject();
//! Write configuration of the labeling engine to the current project file
void writeSettingsToProject();
protected:
//! Associated map settings instance
QgsMapSettings mMapSettings;
//! List of providers (the are owned by the labeling engine)
QList<QgsAbstractLabelProvider*> mProviders;
//! Flags
Flags mFlags;
//! search method to use for removal collisions between labels
QgsPalLabeling::Search mSearchMethod;
//! Number of candedate positions that will be generated for features
int mCandPoint, mCandLine, mCandPolygon;
//! Resulting labeling layout
QgsLabelingResults* mResults;
};

View File

@ -64,7 +64,9 @@ class CORE_EXPORT QgsMapRendererParallelJob : public QgsMapRendererQImageJob
LayerRenderJobs mLayerJobs;
//! Old labeling engine
QgsPalLabeling* mLabelingEngine;
//! New labeling engine
QgsLabelingEngineV2* mLabelingEngineV2;
QgsRenderContext mLabelingRenderContext;
QFuture<void> mLabelingFuture;

View File

@ -17,14 +17,15 @@ using namespace pal;
class QgsTextLabelFeature : public QgsLabelFeature
{
public:
//! Construct text label feature
QgsTextLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, const QSizeF& size )
: QgsLabelFeature( id, geometry, size )
, mIsPinned( false )
, mFontMetrics( NULL )
{
mDefinedFont = QFont();
}
//! Clean up
~QgsTextLabelFeature()
{
delete mFontMetrics;
@ -108,21 +109,25 @@ class QgsTextLabelFeature : public QgsLabelFeature
}
}
//! Get data-defined values
const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& dataDefinedValues() const { return mDataDefinedValues; }
void addDataDefinedValue( QgsPalLayerSettings::DataDefinedProperties p, QVariant v ) { mDataDefinedValues.insert( p, v ); }
void setIsPinned( bool f ) { mIsPinned = f; }
bool isPinned() const { return mIsPinned; }
//! Set data-defined values
void setDataDefinedValues( const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& values ) { mDataDefinedValues = values; }
//! Set font to be used for rendering
void setDefinedFont( QFont f ) { mDefinedFont = QFont( f ); }
//! Font to be used for rendering
QFont definedFont() { return mDefinedFont; }
QFontMetricsF* getLabelFontMetrics() { return mFontMetrics; }
//! Metrics of the font for rendering
QFontMetricsF* labelFontMetrics() { return mFontMetrics; }
protected:
//! List of graphemes (used for curved labels)
QStringList mClusters;
bool mIsPinned;
//! Font for rendering
QFont mDefinedFont;
//! Metrics of the font for rendering
QFontMetricsF* mFontMetrics;
/** Stores attribute values for data defined properties*/
QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > mDataDefinedValues;

View File

@ -1862,7 +1862,6 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
//data defined position / alignment / rotation?
bool dataDefinedPosition = false;
bool labelIsPinned = false;
bool layerDefinedRotation = false;
bool dataDefinedRotation = false;
double xPos = 0.0, yPos = 0.0, angle = 0.0;
@ -2014,7 +2013,6 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
if ( ddXPos && ddYPos )
{
dataDefinedPosition = true;
labelIsPinned = true;
// layer rotation set, but don't rotate pinned labels unless data defined
if ( layerDefinedRotation && !dataDefinedRotation )
{
@ -2271,15 +2269,8 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
}
( *labelFeature )->setObstacleFactor( featObstacleFactor );
//add parameters for data defined labeling to label feature
QMap< DataDefinedProperties, QVariant >::const_iterator dIt = dataDefinedValues.constBegin();
for ( ; dIt != dataDefinedValues.constEnd(); ++dIt )
{
lf->addDataDefinedValue( dIt.key(), dIt.value() );
}
// set geometry's pinned property
lf->setIsPinned( labelIsPinned );
// add parameters for data defined labeling to label feature
lf->setDataDefinedValues( dataDefinedValues );
}

View File

@ -439,7 +439,7 @@ class CORE_EXPORT QgsPalLayerSettings
int fontMaxPixelSize; // maximum pixel size for showing rendered map unit labels (1 - 10000)
bool displayAll; // if true, all features will be labelled even though overlaps occur
unsigned int upsidedownLabels; // whether, or how, to show upsidedown labels
UpsideDownLabels upsidedownLabels; // whether, or how, to show upsidedown labels
bool labelPerPart; // whether to label every feature's part or only the biggest one
bool mergeLines;

View File

@ -70,6 +70,10 @@ QgsVectorLayerDiagramProvider::~QgsVectorLayerDiagramProvider()
{
if ( mOwnsSource )
delete mSource;
qDeleteAll( mFeatures );
// renderer is owned by mSettings
}
@ -124,13 +128,13 @@ void QgsVectorLayerDiagramProvider::drawLabel( QgsRenderContext& context, pal::L
const QgsMapToPixel& xform = context.mapToPixel();
#endif
QgsDiagramLabelFeature* dlf = dynamic_cast<QgsDiagramLabelFeature*>( label->getFeaturePart()->userFeature() );
QgsDiagramLabelFeature* dlf = dynamic_cast<QgsDiagramLabelFeature*>( label->getFeaturePart()->feature() );
QgsFeature feature;
feature.setFields( mSettings.fields );
feature.setValid( true );
feature.setFeatureId( label->getFeaturePart()->featureId() );
feature.setAttributes( dlf->diagramAttributes() );
feature.setAttributes( dlf->attributes() );
//calculate top-left point for diagram
//first, calculate the centroid of the label (accounts for PAL creating
@ -344,7 +348,7 @@ QgsLabelFeature* QgsVectorLayerDiagramProvider::registerDiagram( QgsFeature& fea
if ( dr )
{
//append the diagram attributes to lbl
lf->setDiagramAttributes( feat.attributes() );
lf->setAttributes( feat.attributes() );
}
QgsPoint ptZero = mSettings.xform->toMapCoordinates( 0, 0 );

View File

@ -31,12 +31,14 @@ class QgsDiagramLabelFeature : public QgsLabelFeature
QgsDiagramLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, const QSizeF& size )
: QgsLabelFeature( id, geometry, size ) {}
void setDiagramAttributes( const QgsAttributes& attrs ) { mDiagramAttributes = attrs; }
const QgsAttributes& diagramAttributes() { return mDiagramAttributes; }
//! Store feature's attributes - used for rendering of diagrams
void setAttributes( const QgsAttributes& attrs ) { mAttributes = attrs; }
//! Get feature's attributes - used for rendering of diagrams
const QgsAttributes& attributes() { return mAttributes; }
protected:
/** Stores attribute values for diagram rendering*/
QgsAttributes mDiagramAttributes;
QgsAttributes mAttributes;
};
@ -56,6 +58,7 @@ class CORE_EXPORT QgsVectorLayerDiagramProvider : public QgsAbstractLabelProvide
//! Convenience constructor to initialize the provider from given vector layer
explicit QgsVectorLayerDiagramProvider( QgsVectorLayer* layer, bool ownFeatureLoop = true );
//! Construct diagram provider with all the necessary configuration parameters
QgsVectorLayerDiagramProvider( const QgsDiagramLayerSettings* diagSettings,
const QgsDiagramRendererV2* diagRenderer,
const QString& layerId,
@ -64,6 +67,7 @@ class CORE_EXPORT QgsVectorLayerDiagramProvider : public QgsAbstractLabelProvide
QgsAbstractFeatureSource* source,
bool ownsSource );
//! Clean up
~QgsVectorLayerDiagramProvider();
virtual QString id() const override;
@ -74,25 +78,50 @@ class CORE_EXPORT QgsVectorLayerDiagramProvider : public QgsAbstractLabelProvide
// new virtual methods
/**
* Prepare for registration of features. Must be called after provider has been added to engine (uses its map settings)
* @param context render context.
* @param attributeNames list of attribute names to which additional required attributes shall be added
* @return Whether the preparation was successful - if not, the provider shall not be used
*/
virtual bool prepare( const QgsRenderContext& context, QStringList& attributeNames );
/**
* Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures
*
* @param feature feature for diagram
* @param context render context. The QgsExpressionContext contained within the render context
* must have already had the feature and fields sets prior to calling this method.
*/
virtual void registerFeature( QgsFeature& feature, const QgsRenderContext& context );
protected:
//! initialization method - called from constructors
void init();
//! helper method to register one diagram feautre
QgsLabelFeature* registerDiagram( QgsFeature& feat, const QgsRenderContext& context );
protected:
//! Diagram layer settings
QgsDiagramLayerSettings mSettings;
//! Diagram renderer instance (owned by mSettings)
QgsDiagramRendererV2* mDiagRenderer;
//! ID of the layer
QString mLayerId;
// these are needed only if using own renderer loop
//! Layer's fields
QgsFields mFields;
//! Layer's CRS
QgsCoordinateReferenceSystem mLayerCrs;
//! Layer's feature source
QgsAbstractFeatureSource* mSource;
//! Whether layer's feature source is owned
bool mOwnsSource;
//! List of generated label features (owned by the provider)
QList<QgsLabelFeature*> mFeatures;
};

View File

@ -114,6 +114,8 @@ QgsVectorLayerLabelProvider::~QgsVectorLayerLabelProvider()
}
mSettings.dataDefinedProperties.clear();
qDeleteAll( mLabels );
if ( mOwnsSource )
delete mSource;
}
@ -298,7 +300,7 @@ void QgsVectorLayerLabelProvider::drawLabel( QgsRenderContext& context, pal::Lab
if ( !mSettings.drawLabels )
return;
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->userFeature() );
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->feature() );
// Copy to temp, editable layer settings
// these settings will be changed by any data defined values, then used for rendering label components
@ -386,8 +388,8 @@ void QgsVectorLayerLabelProvider::drawLabel( QgsRenderContext& context, pal::Lab
drawLabelPrivate( label, context, tmpLyr, QgsPalLabeling::LabelText );
// add to the results
QString labeltext = label->getFeaturePart()->userFeature()->labelText();
mEngine->results()->mLabelSearchTree->insertLabel( label, label->getFeaturePart()->featureId(), id(), labeltext, dFont, false, lf->isPinned() );
QString labeltext = label->getFeaturePart()->feature()->labelText();
mEngine->results()->mLabelSearchTree->insertLabel( label, label->getFeaturePart()->featureId(), id(), labeltext, dFont, false, lf->hasFixedPosition() );
}
@ -477,9 +479,9 @@ void QgsVectorLayerLabelProvider::drawLabelPrivate( pal::LabelPosition* label, Q
{
// TODO: optimize access :)
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->userFeature() );
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->feature() );
QString txt = lf->text( label->getPartId() );
QFontMetricsF* labelfm = lf->getLabelFontMetrics();
QFontMetricsF* labelfm = lf->labelFontMetrics();
//add the direction symbol if needed
if ( !txt.isEmpty() && tmpLyr.placement == QgsPalLayerSettings::Line &&

View File

@ -34,6 +34,7 @@ class CORE_EXPORT QgsVectorLayerLabelProvider : public QgsAbstractLabelProvider
//! Convenience constructor to initialize the provider from given vector layer
explicit QgsVectorLayerLabelProvider( QgsVectorLayer* layer, bool withFeatureLoop = true );
//! Construct diagram provider with all the necessary configuration parameters
QgsVectorLayerLabelProvider( const QgsPalLayerSettings& settings,
const QString& layerId,
const QgsFields& fields,
@ -55,7 +56,7 @@ class CORE_EXPORT QgsVectorLayerLabelProvider : public QgsAbstractLabelProvider
* Prepare for registration of features. Must be called after provider has been added to engine (uses its map settings)
* @param context render context.
* @param attributeNames list of attribute names to which additional required attributes shall be added
* @return List of attributes necessary for labeling
* @return Whether the preparation was successful - if not, the provider shall not be used
*/
virtual bool prepare( const QgsRenderContext& context, QStringList& attributeNames );
@ -69,18 +70,29 @@ class CORE_EXPORT QgsVectorLayerLabelProvider : public QgsAbstractLabelProvider
virtual void registerFeature( QgsFeature& feature, const QgsRenderContext& context );
protected:
//! initialization method - called from constructors
void init();
//! Internal label drawing method
void drawLabelPrivate( pal::LabelPosition* label, QgsRenderContext& context, QgsPalLayerSettings& tmpLyr, QgsPalLabeling::DrawLabelType drawType, double dpiRatio = 1.0 ) const;
protected:
//! Layer's labeling configuration
QgsPalLayerSettings mSettings;
//! Layer's ID
QString mLayerId;
// these are needed only if using own renderer loop
//! Layer's fields
QgsFields mFields;
//! Layer's CRS
QgsCoordinateReferenceSystem mCrs;
//! Layer's feature source
QgsAbstractFeatureSource* mSource;
//! Whether layer's feature source is owned
bool mOwnsSource;
//! List of generated
QList<QgsLabelFeature*> mLabels;
};