Skip to content

Commit eabfe02

Browse files
committedSep 21, 2015
Documentation fixes, memory leak fixes
This code has been funded by Tuscany Region (Italy) - SITA (CIG: 63526840AE) and commissioned to Gis3W s.a.s.
1 parent b5e4922 commit eabfe02

13 files changed

+180
-70
lines changed
 

‎src/core/dxf/qgsdxfpallabeling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void QgsDxfLabelProvider::drawLabel( QgsRenderContext& context, pal::LabelPositi
3838
//debug: print label infos
3939
if ( mDxfExport )
4040
{
41-
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->userFeature() );
41+
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->feature() );
4242
if ( !lf )
4343
return;
4444

‎src/core/pal/feature.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace pal
8282
public:
8383

8484
/** Creates a new generic feature.
85-
* @param feat a pointer for a feature which contains the spatial entites
85+
* @param lf a pointer for a feature which contains the spatial entites
8686
* @param geom a pointer to a GEOS geometry
8787
*/
8888
FeaturePart( QgsLabelFeature* lf, const GEOSGeometry* geom );
@@ -167,8 +167,6 @@ namespace pal
167167
void print();
168168
#endif
169169

170-
QgsLabelFeature* userFeature() { return mLF; }
171-
172170
double getLabelWidth() const { return mLF->size().width(); }
173171
double getLabelHeight() const { return mLF->size().height(); }
174172
double getLabelDistance() const { return mLF->distLabel(); }
@@ -181,7 +179,9 @@ namespace pal
181179
double obstacleFactor() { return mLF->obstacleFactor(); }
182180
double repeatDistance() { return mLF->repeatDistance(); }
183181

182+
//! Get number of holes (inner rings) - they are considered as obstacles
184183
int getNumSelfObstacles() const { return mHoles.count(); }
184+
//! Get hole (inner ring) - considered as obstacle
185185
FeaturePart* getSelfObstacle( int i ) { return mHoles.at( i ); }
186186

187187
/** Check whether this part is connected with some other part */

‎src/core/pal/layer.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -226,33 +226,13 @@ namespace pal
226226
bool fitInPolygonOnly() const { return mFitInPolygon; }
227227

228228
/** Register a feature in the layer.
229-
* @param fid unique identifier
230-
* @param userGeom user's geometry (does not take ownership)
231-
* @param label_x label width
232-
* @param label_y label height
233-
* @param labelText label text
234-
* @param labelPosX x position of the label (in case of fixed label position)
235-
* @param labelPosY y position of the label (in case of fixed label position)
236-
* @param fixedPos true if a single fixed position for this label is needed
237-
* @param angle fixed angle (in radians) to rotate the label
238-
* @param fixedAngle whether to use provided fixed angle
239-
* @param xQuadOffset move label to quadrant: left, don't move, right (-1, 0, 1)
240-
* @param yQuadOffset move label to quadrant: down, don't move, up (-1, 0, 1)
241-
* @param xOffset map unit (+/-) to x-offset the label
242-
* @param yOffset map unit (+/-) to y-offset the label
243-
* @param alwaysShow whether to skip priority and always show the label (causes overlapping)
244-
* @param repeatDistance distance for repeating the label
229+
*
230+
* Does not take ownership of the label feature (it is owned by its provider).
245231
*
246232
* @throws PalException::FeatureExists
247233
*
248234
* @return true on success (i.e. valid geometry)
249235
*/
250-
bool registerFeature( QgsLabelFeature* label, QgsFeatureId fid, const GEOSGeometry *userGeom, double label_x = -1, double label_y = -1,
251-
const QString& labelText = QString(), double labelPosX = 0.0, double labelPosY = 0.0,
252-
bool fixedPos = false, double angle = 0.0, bool fixedAngle = false,
253-
int xQuadOffset = 0, int yQuadOffset = 0, double xOffset = 0.0, double yOffset = 0.0,
254-
bool alwaysShow = false, double repeatDistance = 0 );
255-
256236
bool registerFeature( QgsLabelFeature* label );
257237

258238
/** Join connected features with the same label text */

‎src/core/qgslabelingenginev2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void QgsLabelingEngineV2::run( QgsRenderContext& context )
263263
if ( context.renderingStopped() )
264264
break;
265265

266-
QgsLabelFeature* lf = ( *it )->getFeaturePart()->userFeature();
266+
QgsLabelFeature* lf = ( *it )->getFeaturePart()->feature();
267267
if ( !lf )
268268
{
269269
continue;

‎src/core/qgslabelingenginev2.h

Lines changed: 96 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class CORE_EXPORT QgsLabelFeature
5151
public:
5252
//! Create label feature, takes ownership of the geometry instance
5353
QgsLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, const QSizeF& size );
54+
//! Clean up geometry and curved label info (if present)
5455
virtual ~QgsLabelFeature();
5556

5657
//! Identifier of the label (unique within the parent label provider)
@@ -78,16 +79,20 @@ class CORE_EXPORT QgsLabelFeature
7879

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

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

9398
/** Returns whether the quadrant for the label is fixed.
@@ -107,22 +112,32 @@ class CORE_EXPORT QgsLabelFeature
107112
//! For X coordinate, values -1, 0, 1 mean left, center, right.
108113
//! For Y coordinate, values -1, 0, 1 mean above, center, below.
109114
QPointF quadOffset() const { return mQuadOffset; }
115+
//! Set which side of the point to use
116+
//! @see quadOffset
110117
void setQuadOffset( const QPointF& quadOffset ) { mQuadOffset = quadOffset; }
111-
//! Applies only to "offset from point" placement strategy - what offset to use from the point
118+
//! Applies only to "offset from point" placement strategy.
119+
//! What offset (in map units) to use from the point
112120
QgsPoint positionOffset() const { return mPositionOffset; }
121+
//! Applies only to "offset from point" placement strategy.
122+
//! Set what offset (in map units) to use from the point
113123
void setPositionOffset( const QgsPoint& offset ) { mPositionOffset = offset; }
114124
//! Applies to "around point" placement strategy or linestring features.
115125
//! Distance of the label from the feature (in map units)
116126
double distLabel() const { return mDistLabel; }
127+
//! Applies to "around point" placement strategy or linestring features.
128+
//! Set distance of the label from the feature (in map units)
117129
void setDistLabel( double dist ) { mDistLabel = dist; }
118130

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

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

128143
/** Returns whether the feature will act as an obstacle for labels.
@@ -131,7 +146,7 @@ class CORE_EXPORT QgsLabelFeature
131146
*/
132147
bool isObstacle() const { return mIsObstacle; }
133148
/** Sets whether the feature will act as an obstacle for labels.
134-
* @param obstacle whether feature will act as an obstacle
149+
* @param enabled whether feature will act as an obstacle
135150
* @see isObstacle
136151
*/
137152
void setIsObstacle( bool enabled ) { mIsObstacle = enabled; }
@@ -149,11 +164,13 @@ class CORE_EXPORT QgsLabelFeature
149164
*/
150165
void setObstacleFactor( double factor ) { mObstacleFactor = factor; }
151166

152-
//! Text of the label
153-
//!
154-
//! Used if "merge connected lines to avoid duplicate labels" is enabled
155-
//! to identify which features may be merged
167+
/** Text of the label
168+
*
169+
* Used also if "merge connected lines to avoid duplicate labels" is enabled
170+
* to identify which features may be merged.
171+
*/
156172
QString labelText() const { return mLabelText; }
173+
//! Set text of the label
157174
void setLabelText( const QString& text ) { mLabelText = text; }
158175

159176
//! Get additional infor required for curved label placement. Returns null if not set
@@ -164,9 +181,10 @@ class CORE_EXPORT QgsLabelFeature
164181
//! Get PAL layer of the label feature. Should be only used internally in PAL
165182
pal::Layer* layer() const { return mLayer; }
166183
//! Assign PAL layer to the label feature. Should be only used internally in PAL
167-
void setLayer(pal::Layer* layer) { mLayer = layer; }
184+
void setLayer( pal::Layer* layer ) { mLayer = layer; }
168185

169186
protected:
187+
//! Pointer to PAL layer (assigned when registered to PAL)
170188
pal::Layer* mLayer;
171189

172190
//! Associated ID unique within the parent label provider
@@ -175,20 +193,35 @@ class CORE_EXPORT QgsLabelFeature
175193
GEOSGeometry* mGeometry;
176194
//! Width and height of the label
177195
QSizeF mSize;
196+
//! Priority of the label
178197
double mPriority;
198+
//! whether mFixedPosition should be respected
179199
bool mHasFixedPosition;
200+
//! fixed position for the label (instead of automatic placement)
180201
QgsPoint mFixedPosition;
202+
//! whether mFixedAngle should be respected
181203
bool mHasFixedAngle;
204+
//! fixed rotation for the label (instead of automatic choice)
182205
double mFixedAngle;
206+
//! whether mQuadOffset should be respected (only for "around point" placement)
183207
bool mHasFixedQuadrant;
208+
//! whether the side of the label is fixed (only for "around point" placement)
184209
QPointF mQuadOffset;
210+
//! offset of label from the feature (only for "offset from point" placement)
185211
QgsPoint mPositionOffset;
212+
//! distance of label from the feature (only for "around point" placement or linestrings)
186213
double mDistLabel;
214+
//! distance after which label should be repeated (only for linestrings)
187215
double mRepeatDistance;
216+
//! whether to always show label - even in case of collisions
188217
bool mAlwaysShow;
218+
//! whether the feature geometry acts as an obstacle for labels
189219
bool mIsObstacle;
220+
//! how strong is the geometry acting as obstacle
190221
double mObstacleFactor;
222+
//! text of the label
191223
QString mLabelText;
224+
//! extra information for curved labels (may be null)
192225
pal::LabelInfo* mInfo;
193226
};
194227

@@ -202,15 +235,20 @@ class QgsLabelingEngineV2;
202235
* return list of labels and their associated geometries - these are used by
203236
* QgsLabelingEngineV2 to compute the final layout of labels.
204237
*
238+
* Implementations also take care of drawing the returned final label positions.
239+
*
205240
* @note added in QGIS 2.12
206241
*/
207242
class CORE_EXPORT QgsAbstractLabelProvider
208243
{
209244

210245
public:
246+
//! Construct the provider with default values
211247
QgsAbstractLabelProvider();
248+
//! Vritual destructor
212249
virtual ~QgsAbstractLabelProvider() {}
213250

251+
//! Associate provider with a labeling engine (should be only called internally from QgsLabelingEngineV2)
214252
void setEngine( const QgsLabelingEngineV2* engine ) { mEngine = engine; }
215253

216254
enum Flag
@@ -227,35 +265,47 @@ class CORE_EXPORT QgsAbstractLabelProvider
227265
//! Return unique identifier of the provider
228266
virtual QString id() const = 0;
229267

230-
//! Return list of labels
268+
//! Return list of label features (they are owned by the provider and thus deleted on its destruction)
231269
virtual QList<QgsLabelFeature*> labelFeatures( const QgsRenderContext& context ) = 0;
232270

233271
//! draw this label at the position determined by the labeling engine
234272
virtual void drawLabel( QgsRenderContext& context, pal::LabelPosition* label ) const = 0;
235273

274+
//! Flags associated with the provider
236275
Flags flags() const { return mFlags; }
237276

238277
//! What placement strategy to use for the labels
239278
QgsPalLayerSettings::Placement placement() const { return mPlacement; }
240279

280+
//! For layers with linestring geometries - extra placement flags (or-ed combination of QgsPalLayerSettings::LinePlacementFlags)
241281
unsigned int linePlacementFlags() const { return mLinePlacementFlags; }
242282

283+
//! Default priority of labels (may be overridden by individual labels)
243284
double priority() const { return mPriority; }
244285

286+
//! How the feature geometries will work as obstacles
245287
QgsPalLayerSettings::ObstacleType obstacleType() const { return mObstacleType; }
246288

247-
unsigned int upsidedownLabels() const { return mUpsidedownLabels; }
289+
//! How to handle labels that would be upside down
290+
QgsPalLayerSettings::UpsideDownLabels upsidedownLabels() const { return mUpsidedownLabels; }
248291

249292

250293
protected:
294+
//! Associated labeling engine
251295
const QgsLabelingEngineV2* mEngine;
252296

297+
//! Flags altering drawing and registration of features
253298
Flags mFlags;
299+
//! Placement strategy
254300
QgsPalLayerSettings::Placement mPlacement;
301+
//! Extra placement flags for linestring geometries
255302
unsigned int mLinePlacementFlags;
303+
//! Default priority of labels
256304
double mPriority;
305+
//! Type of the obstacle of feature geometries
257306
QgsPalLayerSettings::ObstacleType mObstacleType;
258-
unsigned int mUpsidedownLabels;
307+
//! How to handle labels that would be upside down
308+
QgsPalLayerSettings::UpsideDownLabels mUpsidedownLabels;
259309
};
260310

261311
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAbstractLabelProvider::Flags )
@@ -269,12 +319,29 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAbstractLabelProvider::Flags )
269319
* with no collisions between the labels. Drawing of resulting labels is done
270320
* again by label providers.
271321
*
322+
* The labeling engine is used for the map rendering in QgsMapRendererJob instances,
323+
* individual map layer renderers may add label providers - for example,
324+
* QgsVectorLayerRenderer may add text label provider and diagram provider
325+
* (if labeling / diagrams were configured for such vector layer).
326+
*
327+
* The labeling engine may also be used independently from map rendering loop:
328+
* \code
329+
* QgsLabelingEngineV2 engine;
330+
* engine.setMapSettings( mapSettings );
331+
* // add one or more providers
332+
* engine.addProvider( ... );
333+
* // compute the labeling and draw labels (using painter from the context)
334+
* engine.run( context );
335+
* \endcode
336+
*
272337
* @note added in QGIS 2.12
273338
*/
274339
class CORE_EXPORT QgsLabelingEngineV2
275340
{
276341
public:
342+
//! Construct the labeling engine with default settings
277343
QgsLabelingEngineV2();
344+
//! Clean up everything (especially the registered providers)
278345
~QgsLabelingEngineV2();
279346

280347
enum Flag
@@ -288,7 +355,9 @@ class CORE_EXPORT QgsLabelingEngineV2
288355
};
289356
Q_DECLARE_FLAGS( Flags, Flag )
290357

358+
//! Associate map settings instance
291359
void setMapSettings( const QgsMapSettings& mapSettings ) { mMapSettings = mapSettings; }
360+
//! Get associated map settings
292361
const QgsMapSettings& mapSettings() const { return mMapSettings; }
293362

294363
//! Add provider of label features. Takes ownership of the provider
@@ -309,27 +378,43 @@ class CORE_EXPORT QgsLabelingEngineV2
309378
//! For internal use by the providers
310379
QgsLabelingResults* results() const { return mResults; }
311380

381+
//! Set flags of the labeling engine
312382
void setFlags( Flags flags ) { mFlags = flags; }
383+
//! Get flags of the labeling engine
313384
Flags flags() const { return mFlags; }
385+
//! Test whether a particular flag is enabled
314386
bool testFlag( Flag f ) const { return mFlags.testFlag( f ); }
315-
void setFlag( Flag f, bool enabled ) { if ( enabled ) mFlags |= f; else mFlags &= ~f; }
387+
//! Set whether a particual flag is enabled
388+
void setFlag( Flag f, bool enabled = true ) { if ( enabled ) mFlags |= f; else mFlags &= ~f; }
316389

390+
//! Get number of candidate positions that will be generated for each label feature (default to 8)
317391
void numCandidatePositions( int& candPoint, int& candLine, int& candPolygon ) { candPoint = mCandPoint; candLine = mCandLine; candPolygon = mCandPolygon; }
392+
//! Set number of candidate positions that will be generated for each label feature
318393
void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ) { mCandPoint = candPoint; mCandLine = candLine; mCandPolygon = candPolygon; }
319394

395+
//! Set which search method to use for removal collisions between labels
320396
void setSearchMethod( QgsPalLabeling::Search s ) { mSearchMethod = s; }
397+
//! Which search method to use for removal collisions between labels
321398
QgsPalLabeling::Search searchMethod() const { return mSearchMethod; }
322399

400+
//! Read configuration of the labeling engine from the current project file
323401
void readSettingsFromProject();
402+
//! Write configuration of the labeling engine to the current project file
324403
void writeSettingsToProject();
325404

326405
protected:
406+
//! Associated map settings instance
327407
QgsMapSettings mMapSettings;
408+
//! List of providers (the are owned by the labeling engine)
328409
QList<QgsAbstractLabelProvider*> mProviders;
410+
//! Flags
329411
Flags mFlags;
412+
//! search method to use for removal collisions between labels
330413
QgsPalLabeling::Search mSearchMethod;
414+
//! Number of candedate positions that will be generated for features
331415
int mCandPoint, mCandLine, mCandPolygon;
332416

417+
//! Resulting labeling layout
333418
QgsLabelingResults* mResults;
334419
};
335420

‎src/core/qgsmaprendererparalleljob.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ class CORE_EXPORT QgsMapRendererParallelJob : public QgsMapRendererQImageJob
6464

6565
LayerRenderJobs mLayerJobs;
6666

67+
//! Old labeling engine
6768
QgsPalLabeling* mLabelingEngine;
69+
//! New labeling engine
6870
QgsLabelingEngineV2* mLabelingEngineV2;
6971
QgsRenderContext mLabelingRenderContext;
7072
QFuture<void> mLabelingFuture;

‎src/core/qgspalgeometry.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ using namespace pal;
1717
class QgsTextLabelFeature : public QgsLabelFeature
1818
{
1919
public:
20+
//! Construct text label feature
2021
QgsTextLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, const QSizeF& size )
2122
: QgsLabelFeature( id, geometry, size )
22-
, mIsPinned( false )
2323
, mFontMetrics( NULL )
2424
{
2525
mDefinedFont = QFont();
2626
}
2727

28+
//! Clean up
2829
~QgsTextLabelFeature()
2930
{
3031
delete mFontMetrics;
@@ -108,21 +109,25 @@ class QgsTextLabelFeature : public QgsLabelFeature
108109
}
109110
}
110111

112+
//! Get data-defined values
111113
const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& dataDefinedValues() const { return mDataDefinedValues; }
112-
void addDataDefinedValue( QgsPalLayerSettings::DataDefinedProperties p, QVariant v ) { mDataDefinedValues.insert( p, v ); }
113-
114-
void setIsPinned( bool f ) { mIsPinned = f; }
115-
bool isPinned() const { return mIsPinned; }
114+
//! Set data-defined values
115+
void setDataDefinedValues( const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& values ) { mDataDefinedValues = values; }
116116

117+
//! Set font to be used for rendering
117118
void setDefinedFont( QFont f ) { mDefinedFont = QFont( f ); }
119+
//! Font to be used for rendering
118120
QFont definedFont() { return mDefinedFont; }
119121

120-
QFontMetricsF* getLabelFontMetrics() { return mFontMetrics; }
122+
//! Metrics of the font for rendering
123+
QFontMetricsF* labelFontMetrics() { return mFontMetrics; }
121124

122125
protected:
126+
//! List of graphemes (used for curved labels)
123127
QStringList mClusters;
124-
bool mIsPinned;
128+
//! Font for rendering
125129
QFont mDefinedFont;
130+
//! Metrics of the font for rendering
126131
QFontMetricsF* mFontMetrics;
127132
/** Stores attribute values for data defined properties*/
128133
QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > mDataDefinedValues;

‎src/core/qgspallabeling.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,7 +1862,6 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
18621862

18631863
//data defined position / alignment / rotation?
18641864
bool dataDefinedPosition = false;
1865-
bool labelIsPinned = false;
18661865
bool layerDefinedRotation = false;
18671866
bool dataDefinedRotation = false;
18681867
double xPos = 0.0, yPos = 0.0, angle = 0.0;
@@ -2014,7 +2013,6 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
20142013
if ( ddXPos && ddYPos )
20152014
{
20162015
dataDefinedPosition = true;
2017-
labelIsPinned = true;
20182016
// layer rotation set, but don't rotate pinned labels unless data defined
20192017
if ( layerDefinedRotation && !dataDefinedRotation )
20202018
{
@@ -2271,15 +2269,8 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
22712269
}
22722270
( *labelFeature )->setObstacleFactor( featObstacleFactor );
22732271

2274-
//add parameters for data defined labeling to label feature
2275-
QMap< DataDefinedProperties, QVariant >::const_iterator dIt = dataDefinedValues.constBegin();
2276-
for ( ; dIt != dataDefinedValues.constEnd(); ++dIt )
2277-
{
2278-
lf->addDataDefinedValue( dIt.key(), dIt.value() );
2279-
}
2280-
2281-
// set geometry's pinned property
2282-
lf->setIsPinned( labelIsPinned );
2272+
// add parameters for data defined labeling to label feature
2273+
lf->setDataDefinedValues( dataDefinedValues );
22832274
}
22842275

22852276

‎src/core/qgspallabeling.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class CORE_EXPORT QgsPalLayerSettings
439439
int fontMaxPixelSize; // maximum pixel size for showing rendered map unit labels (1 - 10000)
440440

441441
bool displayAll; // if true, all features will be labelled even though overlaps occur
442-
unsigned int upsidedownLabels; // whether, or how, to show upsidedown labels
442+
UpsideDownLabels upsidedownLabels; // whether, or how, to show upsidedown labels
443443

444444
bool labelPerPart; // whether to label every feature's part or only the biggest one
445445
bool mergeLines;

‎src/core/qgsvectorlayerdiagramprovider.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ QgsVectorLayerDiagramProvider::~QgsVectorLayerDiagramProvider()
7070
{
7171
if ( mOwnsSource )
7272
delete mSource;
73+
74+
qDeleteAll( mFeatures );
75+
76+
// renderer is owned by mSettings
7377
}
7478

7579

@@ -124,13 +128,13 @@ void QgsVectorLayerDiagramProvider::drawLabel( QgsRenderContext& context, pal::L
124128
const QgsMapToPixel& xform = context.mapToPixel();
125129
#endif
126130

127-
QgsDiagramLabelFeature* dlf = dynamic_cast<QgsDiagramLabelFeature*>( label->getFeaturePart()->userFeature() );
131+
QgsDiagramLabelFeature* dlf = dynamic_cast<QgsDiagramLabelFeature*>( label->getFeaturePart()->feature() );
128132

129133
QgsFeature feature;
130134
feature.setFields( mSettings.fields );
131135
feature.setValid( true );
132136
feature.setFeatureId( label->getFeaturePart()->featureId() );
133-
feature.setAttributes( dlf->diagramAttributes() );
137+
feature.setAttributes( dlf->attributes() );
134138

135139
//calculate top-left point for diagram
136140
//first, calculate the centroid of the label (accounts for PAL creating
@@ -344,7 +348,7 @@ QgsLabelFeature* QgsVectorLayerDiagramProvider::registerDiagram( QgsFeature& fea
344348
if ( dr )
345349
{
346350
//append the diagram attributes to lbl
347-
lf->setDiagramAttributes( feat.attributes() );
351+
lf->setAttributes( feat.attributes() );
348352
}
349353

350354
QgsPoint ptZero = mSettings.xform->toMapCoordinates( 0, 0 );

‎src/core/qgsvectorlayerdiagramprovider.h

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ class QgsDiagramLabelFeature : public QgsLabelFeature
3131
QgsDiagramLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, const QSizeF& size )
3232
: QgsLabelFeature( id, geometry, size ) {}
3333

34-
void setDiagramAttributes( const QgsAttributes& attrs ) { mDiagramAttributes = attrs; }
35-
const QgsAttributes& diagramAttributes() { return mDiagramAttributes; }
34+
//! Store feature's attributes - used for rendering of diagrams
35+
void setAttributes( const QgsAttributes& attrs ) { mAttributes = attrs; }
36+
//! Get feature's attributes - used for rendering of diagrams
37+
const QgsAttributes& attributes() { return mAttributes; }
3638

3739
protected:
3840
/** Stores attribute values for diagram rendering*/
39-
QgsAttributes mDiagramAttributes;
41+
QgsAttributes mAttributes;
4042
};
4143

4244

@@ -56,6 +58,7 @@ class CORE_EXPORT QgsVectorLayerDiagramProvider : public QgsAbstractLabelProvide
5658
//! Convenience constructor to initialize the provider from given vector layer
5759
explicit QgsVectorLayerDiagramProvider( QgsVectorLayer* layer, bool ownFeatureLoop = true );
5860

61+
//! Construct diagram provider with all the necessary configuration parameters
5962
QgsVectorLayerDiagramProvider( const QgsDiagramLayerSettings* diagSettings,
6063
const QgsDiagramRendererV2* diagRenderer,
6164
const QString& layerId,
@@ -64,6 +67,7 @@ class CORE_EXPORT QgsVectorLayerDiagramProvider : public QgsAbstractLabelProvide
6467
QgsAbstractFeatureSource* source,
6568
bool ownsSource );
6669

70+
//! Clean up
6771
~QgsVectorLayerDiagramProvider();
6872

6973
virtual QString id() const override;
@@ -74,25 +78,50 @@ class CORE_EXPORT QgsVectorLayerDiagramProvider : public QgsAbstractLabelProvide
7478

7579
// new virtual methods
7680

81+
/**
82+
* Prepare for registration of features. Must be called after provider has been added to engine (uses its map settings)
83+
* @param context render context.
84+
* @param attributeNames list of attribute names to which additional required attributes shall be added
85+
* @return Whether the preparation was successful - if not, the provider shall not be used
86+
*/
7787
virtual bool prepare( const QgsRenderContext& context, QStringList& attributeNames );
7888

89+
/**
90+
* Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures
91+
*
92+
* @param feature feature for diagram
93+
* @param context render context. The QgsExpressionContext contained within the render context
94+
* must have already had the feature and fields sets prior to calling this method.
95+
*/
7996
virtual void registerFeature( QgsFeature& feature, const QgsRenderContext& context );
8097

8198
protected:
99+
//! initialization method - called from constructors
82100
void init();
101+
//! helper method to register one diagram feautre
83102
QgsLabelFeature* registerDiagram( QgsFeature& feat, const QgsRenderContext& context );
84103

85104
protected:
86105

106+
//! Diagram layer settings
87107
QgsDiagramLayerSettings mSettings;
108+
//! Diagram renderer instance (owned by mSettings)
88109
QgsDiagramRendererV2* mDiagRenderer;
89-
110+
//! ID of the layer
90111
QString mLayerId;
112+
113+
// these are needed only if using own renderer loop
114+
115+
//! Layer's fields
91116
QgsFields mFields;
117+
//! Layer's CRS
92118
QgsCoordinateReferenceSystem mLayerCrs;
119+
//! Layer's feature source
93120
QgsAbstractFeatureSource* mSource;
121+
//! Whether layer's feature source is owned
94122
bool mOwnsSource;
95123

124+
//! List of generated label features (owned by the provider)
96125
QList<QgsLabelFeature*> mFeatures;
97126
};
98127

‎src/core/qgsvectorlayerlabelprovider.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ QgsVectorLayerLabelProvider::~QgsVectorLayerLabelProvider()
114114
}
115115
mSettings.dataDefinedProperties.clear();
116116

117+
qDeleteAll( mLabels );
118+
117119
if ( mOwnsSource )
118120
delete mSource;
119121
}
@@ -298,7 +300,7 @@ void QgsVectorLayerLabelProvider::drawLabel( QgsRenderContext& context, pal::Lab
298300
if ( !mSettings.drawLabels )
299301
return;
300302

301-
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->userFeature() );
303+
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->feature() );
302304

303305
// Copy to temp, editable layer settings
304306
// 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
386388
drawLabelPrivate( label, context, tmpLyr, QgsPalLabeling::LabelText );
387389

388390
// add to the results
389-
QString labeltext = label->getFeaturePart()->userFeature()->labelText();
390-
mEngine->results()->mLabelSearchTree->insertLabel( label, label->getFeaturePart()->featureId(), id(), labeltext, dFont, false, lf->isPinned() );
391+
QString labeltext = label->getFeaturePart()->feature()->labelText();
392+
mEngine->results()->mLabelSearchTree->insertLabel( label, label->getFeaturePart()->featureId(), id(), labeltext, dFont, false, lf->hasFixedPosition() );
391393
}
392394

393395

@@ -477,9 +479,9 @@ void QgsVectorLayerLabelProvider::drawLabelPrivate( pal::LabelPosition* label, Q
477479
{
478480

479481
// TODO: optimize access :)
480-
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->userFeature() );
482+
QgsTextLabelFeature* lf = dynamic_cast<QgsTextLabelFeature*>( label->getFeaturePart()->feature() );
481483
QString txt = lf->text( label->getPartId() );
482-
QFontMetricsF* labelfm = lf->getLabelFontMetrics();
484+
QFontMetricsF* labelfm = lf->labelFontMetrics();
483485

484486
//add the direction symbol if needed
485487
if ( !txt.isEmpty() && tmpLyr.placement == QgsPalLayerSettings::Line &&

‎src/core/qgsvectorlayerlabelprovider.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class CORE_EXPORT QgsVectorLayerLabelProvider : public QgsAbstractLabelProvider
3434
//! Convenience constructor to initialize the provider from given vector layer
3535
explicit QgsVectorLayerLabelProvider( QgsVectorLayer* layer, bool withFeatureLoop = true );
3636

37+
//! Construct diagram provider with all the necessary configuration parameters
3738
QgsVectorLayerLabelProvider( const QgsPalLayerSettings& settings,
3839
const QString& layerId,
3940
const QgsFields& fields,
@@ -55,7 +56,7 @@ class CORE_EXPORT QgsVectorLayerLabelProvider : public QgsAbstractLabelProvider
5556
* Prepare for registration of features. Must be called after provider has been added to engine (uses its map settings)
5657
* @param context render context.
5758
* @param attributeNames list of attribute names to which additional required attributes shall be added
58-
* @return List of attributes necessary for labeling
59+
* @return Whether the preparation was successful - if not, the provider shall not be used
5960
*/
6061
virtual bool prepare( const QgsRenderContext& context, QStringList& attributeNames );
6162

@@ -69,18 +70,29 @@ class CORE_EXPORT QgsVectorLayerLabelProvider : public QgsAbstractLabelProvider
6970
virtual void registerFeature( QgsFeature& feature, const QgsRenderContext& context );
7071

7172
protected:
73+
//! initialization method - called from constructors
7274
void init();
75+
//! Internal label drawing method
7376
void drawLabelPrivate( pal::LabelPosition* label, QgsRenderContext& context, QgsPalLayerSettings& tmpLyr, QgsPalLabeling::DrawLabelType drawType, double dpiRatio = 1.0 ) const;
7477

7578
protected:
79+
//! Layer's labeling configuration
7680
QgsPalLayerSettings mSettings;
81+
//! Layer's ID
7782
QString mLayerId;
83+
7884
// these are needed only if using own renderer loop
85+
86+
//! Layer's fields
7987
QgsFields mFields;
88+
//! Layer's CRS
8089
QgsCoordinateReferenceSystem mCrs;
90+
//! Layer's feature source
8191
QgsAbstractFeatureSource* mSource;
92+
//! Whether layer's feature source is owned
8293
bool mOwnsSource;
8394

95+
//! List of generated
8496
QList<QgsLabelFeature*> mLabels;
8597
};
8698

0 commit comments

Comments
 (0)
Please sign in to comment.