Skip to content

Commit aa85cf3

Browse files
committedSep 21, 2015
More fixes, removal of layer-wise obstacle flag, removed pal::Layer usage outside of labeling engine
This code has been funded by Tuscany Region (Italy) - SITA (CIG: 63526840AE) and commissioned to Gis3W s.a.s.
1 parent 959fbb5 commit aa85cf3

12 files changed

+45
-83
lines changed
 

‎src/core/pal/layer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
namespace pal
4747
{
4848

49-
Layer::Layer( const QString &lyrName, Arrangement arrangement, double defaultPriority, bool obstacle, bool active, bool toLabel, Pal *pal, bool displayAll )
49+
Layer::Layer( const QString &lyrName, Arrangement arrangement, double defaultPriority, bool active, bool toLabel, Pal *pal, bool displayAll )
5050
: mName( lyrName )
5151
, pal( pal )
5252
, mObstacleType( PolygonInterior )
@@ -263,7 +263,12 @@ namespace pal
263263
bool Layer::registerFeature( QgsLabelFeature* label )
264264
{
265265
QgsPalGeometry* g = label->geometry();
266-
if ( !registerFeature( g->strId(), g, label->size().width(), label->size().height() ) )
266+
if ( !registerFeature( g->strId(), g, label->size().width(), label->size().height(), label->labelText(),
267+
label->fixedPosition().x(), label->fixedPosition().y(), label->hasFixedPosition(),
268+
label->fixedAngle(), label->hasFixedAngle(),
269+
label->quadOffset().x(), label->quadOffset().y(),
270+
label->positionOffset().x(), label->positionOffset().y(),
271+
label->alwaysShow(), label->repeatDistance() ) )
267272
return false;
268273

269274
pal::Feature* pf = getFeature( g->strId() );

‎src/core/pal/layer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,13 @@ namespace pal
309309
* @param lyrName layer's name
310310
* @param arrangement Arrangement mode : how to place candidates
311311
* @param defaultPriority layer's prioriry (0 is the best, 1 the worst)
312-
* @param obstacle 'true' will discourage other label to be placed above features of this layer
313312
* @param active is the layer is active (currently displayed)
314313
* @param toLabel the layer will be labeled whether toLablel is true
315314
* @param pal pointer to the pal object
316315
* @param displayAll if true, all features will be labelled even though overlaps occur
317316
*
318317
*/
319-
Layer( const QString& lyrName, Arrangement arrangement, double defaultPriority, bool obstacle, bool active, bool toLabel, Pal *pal, bool displayAll = false );
318+
Layer( const QString& lyrName, Arrangement arrangement, double defaultPriority, bool active, bool toLabel, Pal *pal, bool displayAll = false );
320319

321320
/** Add newly created feature part into r tree and to the list */
322321
void addFeaturePart( FeaturePart* fpart, const QString &labelText = QString() );

‎src/core/pal/pal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ namespace pal
138138
//finishGEOS();
139139
}
140140

141-
Layer* Pal::addLayer( const QString &layerName, Arrangement arrangement, double defaultPriority, bool obstacle, bool active, bool toLabel, bool displayAll )
141+
Layer* Pal::addLayer( const QString &layerName, Arrangement arrangement, double defaultPriority, bool active, bool toLabel, bool displayAll )
142142
{
143143
mMutex.lock();
144144

@@ -151,7 +151,7 @@ namespace pal
151151
return mLayers.value( layerName );
152152
}
153153

154-
Layer* layer = new Layer( layerName, arrangement, defaultPriority, obstacle, active, toLabel, this, displayAll );
154+
Layer* layer = new Layer( layerName, arrangement, defaultPriority, active, toLabel, this, displayAll );
155155
mLayers.insert( layerName, layer );
156156
mMutex.unlock();
157157

‎src/core/pal/pal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ namespace pal
130130
* @param layerName layer's name
131131
* @param arrangement Howto place candidates
132132
* @param defaultPriority layer's prioriry (0 is the best, 1 the worst)
133-
* @param obstacle 'true' will discourage other label to be placed above features of this layer
134133
* @param active is the layer is active (currently displayed)
135134
* @param toLabel the layer will be labeled only if toLablel is true
136135
* @param displayAll if true, all features will be labelled even though overlaps occur
@@ -139,7 +138,7 @@ namespace pal
139138
*
140139
* @todo add symbolUnit
141140
*/
142-
Layer* addLayer( const QString& layerName, Arrangement arrangement, double defaultPriority, bool obstacle, bool active, bool toLabel, bool displayAll = false );
141+
Layer* addLayer( const QString& layerName, Arrangement arrangement, double defaultPriority, bool active, bool toLabel, bool displayAll = false );
143142

144143
/**
145144
* \brief Look for a layer

‎src/core/qgsdiagramrendererv2.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ QgsDiagramLayerSettings::QgsDiagramLayerSettings()
3131
, obstacle( false )
3232
, dist( 0.0 )
3333
, renderer( 0 )
34-
, palLayer( 0 )
3534
, ct( 0 )
3635
, xform( 0 )
3736
, xPosColumn( -1 )

‎src/core/qgsdiagramrendererv2.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class CORE_EXPORT QgsDiagramLayerSettings
7373
QgsDiagramRendererV2* renderer; // if any renderer is assigned, it is owned by this class
7474

7575
//assigned when layer gets prepared
76-
pal::Layer* palLayer;
7776
const QgsCoordinateTransform* ct;
7877
const QgsMapToPixel* xform;
7978
QList<QgsPalGeometry*> geometries;

‎src/core/qgslabelingenginev2.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ void QgsLabelingEngineV2::run( QgsRenderContext& context )
112112
pal::Layer* l = p.addLayer( provider->id(),
113113
arrangement,
114114
provider->priority(),
115-
flags.testFlag( QgsAbstractLabelProvider::GeometriesAreObstacles ),
116115
true,
117116
flags.testFlag( QgsAbstractLabelProvider::DrawLabels ),
118117
flags.testFlag( QgsAbstractLabelProvider::DrawAllLabels ) );

‎src/core/qgslabelingenginev2.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ class CORE_EXPORT QgsLabelFeature
104104
double obstacleFactor() const { return mObstacleFactor; }
105105
void setObstacleFactor( double factor ) { mObstacleFactor = factor; }
106106

107+
//! Text of the label - used if "merge connected lines to avoid duplicate labels" is enabled
108+
//! to identify which features may be merged
109+
QString labelText() const { return mLabelText; }
110+
void setLabelText( const QString& text ) { mLabelText = text; }
111+
107112
protected:
108113

109114
//! Associated ID unique within the parent label provider
@@ -125,6 +130,7 @@ class CORE_EXPORT QgsLabelFeature
125130
bool mAlwaysShow;
126131
bool mIsObstacle;
127132
double mObstacleFactor;
133+
QString mLabelText;
128134
};
129135

130136

@@ -150,13 +156,12 @@ class CORE_EXPORT QgsAbstractLabelProvider
150156

151157
enum Flag
152158
{
153-
GeometriesAreObstacles = 1 << 1, //!< whether the geometries of labels by default act as obstacles (may be overriden on feature level)
154-
DrawLabels = 1 << 2, //!< whether the labels should be rendered
155-
DrawAllLabels = 1 << 3, //!< whether all features will be labelled even though overlaps occur
156-
MergeConnectedLines = 1 << 4, //!< whether adjacent lines (with the same label text) should be merged
157-
CentroidMustBeInside = 1 << 5, //!< whether location of centroid must be inside of polygons
158-
FitInPolygonOnly = 1 << 6, //!< whether labels must fall completely within the polygon
159-
LabelPerFeaturePart = 1 << 7, //!< whether to label each part of multi-part features separately
159+
DrawLabels = 1 << 1, //!< whether the labels should be rendered
160+
DrawAllLabels = 1 << 2, //!< whether all features will be labelled even though overlaps occur
161+
MergeConnectedLines = 1 << 3, //!< whether adjacent lines (with the same label text) should be merged
162+
CentroidMustBeInside = 1 << 4, //!< whether location of centroid must be inside of polygons
163+
FitInPolygonOnly = 1 << 5, //!< whether labels must fall completely within the polygon
164+
LabelPerFeaturePart = 1 << 6, //!< whether to label each part of multi-part features separately
160165
};
161166
Q_DECLARE_FLAGS( Flags, Flag )
162167

‎src/core/qgspallabeling.cpp

Lines changed: 21 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ using namespace pal;
8080

8181
QgsPalLayerSettings::QgsPalLayerSettings()
8282
: upsidedownLabels( Upright )
83-
, palLayer( NULL )
8483
, mCurFeat( 0 )
8584
, xform( NULL )
8685
, ct( NULL )
@@ -322,8 +321,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
322321
}
323322

324323
QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
325-
: palLayer( NULL )
326-
, mCurFeat( NULL )
324+
: mCurFeat( NULL )
327325
, fieldIndex( 0 )
328326
, xform( NULL )
329327
, ct( NULL )
@@ -1471,7 +1469,7 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
14711469
void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext& context, QString dxfLayer, QgsLabelFeature** labelFeature )
14721470
{
14731471
// either used in QgsPalLabeling (palLayer is set) or in QgsLabelingEngineV2 (labelFeature is set)
1474-
Q_ASSERT(( palLayer || labelFeature ) && !( palLayer && labelFeature ) );
1472+
Q_ASSERT( labelFeature );
14751473

14761474
if ( !drawLabels )
14771475
{
@@ -1835,7 +1833,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
18351833
{
18361834
return;
18371835
}
1838-
mFeatsRegPal = palLayer->featureCount();
1836+
mFeatsRegPal = geometries.count();
18391837
if ( mFeatsRegPal >= maxNumLabels )
18401838
{
18411839
return;
@@ -2185,30 +2183,22 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
21852183
}
21862184

21872185
// feature to the layer
2188-
try
2189-
{
2190-
if ( !palLayer )
2191-
*labelFeature = new QgsLabelFeature( lbl->strId(), lbl, QSizeF( labelX, labelY ) );
2192-
else
2193-
if ( !palLayer->registerFeature( lbl->strId(), lbl, labelX, labelY, labelText,
2194-
xPos, yPos, dataDefinedPosition, angle, dataDefinedRotation,
2195-
quadOffsetX, quadOffsetY, offsetX, offsetY, alwaysShow, repeatDist ) )
2196-
return;
2197-
}
2198-
catch ( std::exception &e )
2199-
{
2200-
Q_UNUSED( e );
2201-
QgsDebugMsgLevel( QString( "Ignoring feature %1 due PAL exception:" ).arg( f.id() ) + QString::fromLatin1( e.what() ), 4 );
2202-
return;
2203-
}
2186+
*labelFeature = new QgsLabelFeature( lbl->strId(), lbl, QSizeF( labelX, labelY ) );
2187+
2188+
( *labelFeature )->setHasFixedPosition( dataDefinedPosition );
2189+
( *labelFeature )->setFixedPosition( QgsPoint( xPos, yPos ) );
2190+
( *labelFeature )->setHasFixedAngle( dataDefinedRotation );
2191+
( *labelFeature )->setFixedAngle( angle );
2192+
( *labelFeature )->setQuadOffset( QPointF( quadOffsetX, quadOffsetY ) );
2193+
( *labelFeature )->setPositionOffset( QgsPoint( offsetX, offsetY ) );
2194+
( *labelFeature )->setAlwaysShow( alwaysShow );
2195+
( *labelFeature )->setRepeatDistance( repeatDist );
2196+
( *labelFeature )->setLabelText( labelText );
22042197

22052198
// TODO: only for placement which needs character info
2206-
pal::Feature* feat = palLayer ? palLayer->getFeature( lbl->strId() ) : 0;
22072199
// account for any data defined font metrics adjustments
22082200
lbl->calculateInfo( labelFontMetrics, xform, rasterCompressFactor, maxcharanglein, maxcharangleout );
22092201
// for labelFeature the LabelInfo is passed to feat when it is registered
2210-
if ( feat )
2211-
feat->setLabelInfo( lbl->info() );
22122202
delete labelFontMetrics;
22132203

22142204
// TODO: allow layer-wide feature dist in PAL...?
@@ -2248,18 +2238,12 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
22482238
distance *= vectorScaleFactor;
22492239
}
22502240
double d = qAbs( ptOne.x() - ptZero.x() ) * distance;
2251-
if ( feat )
2252-
feat->setDistLabel( d );
2253-
else
2254-
( *labelFeature )->setDistLabel( d );
2241+
( *labelFeature )->setDistLabel( d );
22552242
}
22562243

22572244
if ( ddFixedQuad )
22582245
{
2259-
if ( feat )
2260-
feat->setFixedQuadrant( true );
2261-
else
2262-
( *labelFeature )->setHasFixedQuadrant( true );
2246+
( *labelFeature )->setHasFixedQuadrant( true );
22632247
}
22642248

22652249
// data defined priority?
@@ -2271,10 +2255,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
22712255
{
22722256
priorityD = qBound( 0.0, priorityD, 10.0 );
22732257
priorityD = 1 - priorityD / 10.0; // convert 0..10 --> 1..0
2274-
if ( feat )
2275-
feat->setPriority( priorityD );
2276-
else
2277-
( *labelFeature )->setPriority( priorityD );
2258+
( *labelFeature )->setPriority( priorityD );
22782259
}
22792260
}
22802261

@@ -2285,10 +2266,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
22852266
isObstacle = exprVal.toBool();
22862267
}
22872268

2288-
if ( feat )
2289-
feat->setIsObstacle( isObstacle );
2290-
else
2291-
( *labelFeature )->setIsObstacle( isObstacle );
2269+
( *labelFeature )->setIsObstacle( isObstacle );
22922270

22932271
double featObstacleFactor = obstacleFactor;
22942272
if ( dataDefinedEvaluate( QgsPalLayerSettings::ObstacleFactor, exprVal, &context.expressionContext() ) )
@@ -2302,10 +2280,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
23022280
featObstacleFactor = factorD;
23032281
}
23042282
}
2305-
if ( feat )
2306-
feat->setObstacleFactor( featObstacleFactor );
2307-
else
2308-
( *labelFeature )->setObstacleFactor( featObstacleFactor );
2283+
( *labelFeature )->setObstacleFactor( featObstacleFactor );
23092284

23102285
//add parameters for data defined labeling to QgsPalGeometry
23112286
QMap< DataDefinedProperties, QVariant >::const_iterator dIt = dataDefinedValues.constBegin();
@@ -2358,23 +2333,8 @@ void QgsPalLayerSettings::registerObstacleFeature( QgsFeature& f, const QgsRende
23582333
geometries.append( lbl );
23592334

23602335
// feature to the layer
2361-
try
2362-
{
2363-
if ( obstacleFeature )
2364-
{
2365-
*obstacleFeature = new QgsLabelFeature( lbl->strId(), lbl, QSizeF( 0, 0 ) );
2366-
( *obstacleFeature )->setIsObstacle( true );
2367-
}
2368-
else
2369-
if ( !palLayer->registerFeature( lbl->strId(), lbl, 0, 0 ) )
2370-
return;
2371-
}
2372-
catch ( std::exception &e )
2373-
{
2374-
Q_UNUSED( e );
2375-
QgsDebugMsgLevel( QString( "Ignoring feature %1 due PAL exception:" ).arg( f.id() ) + QString::fromLatin1( e.what() ), 4 );
2376-
return;
2377-
}
2336+
*obstacleFeature = new QgsLabelFeature( lbl->strId(), lbl, QSizeF( 0, 0 ) );
2337+
( *obstacleFeature )->setIsObstacle( true );
23782338
}
23792339

23802340
bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType,

‎src/core/qgspallabeling.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,6 @@ class CORE_EXPORT QgsPalLayerSettings
555555
QMap<QgsPalLayerSettings::DataDefinedProperties, QPair<QString, int> > dataDefinedNames() const { return mDataDefinedNames; }
556556

557557
// temporary stuff: set when layer gets prepared or labeled
558-
// NOTE: not in Python binding
559-
pal::Layer* palLayer;
560558
QgsFeature* mCurFeat;
561559
QgsFields mCurFields;
562560
int fieldIndex;

‎src/core/qgsvectorlayerdiagramprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ void QgsVectorLayerDiagramProvider::init()
6464
mPlacement = QgsPalLayerSettings::Placement( mSettings.placement );
6565
mLinePlacementFlags = mSettings.placementFlags;
6666
mFlags |= DrawAllLabels;
67-
if ( mSettings.obstacle ) mFlags |= GeometriesAreObstacles;
6867
}
6968

7069

@@ -349,6 +348,7 @@ QgsLabelFeature* QgsVectorLayerDiagramProvider::registerDiagram( QgsFeature& fea
349348
lf->setHasFixedAngle( true );
350349
lf->setFixedAngle( 0 );
351350
lf->setAlwaysShow( alwaysShow );
351+
lf->setIsObstacle( mSettings.obstacle );
352352

353353
QgsPoint ptZero = mSettings.xform->toMapCoordinates( 0, 0 );
354354
QgsPoint ptOne = mSettings.xform->toMapCoordinates( 1, 0 );

‎src/core/qgsvectorlayerlabelprovider.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ void QgsVectorLayerLabelProvider::init()
9191
mPlacement = mSettings.placement;
9292
mLinePlacementFlags = mSettings.placementFlags;
9393
mFlags = Flags();
94-
if ( mSettings.obstacle ) mFlags |= GeometriesAreObstacles;
9594
if ( mSettings.drawLabels ) mFlags |= DrawLabels;
9695
if ( mSettings.displayAll ) mFlags |= DrawAllLabels;
9796
if ( mSettings.mergeLines ) mFlags |= MergeConnectedLines;

0 commit comments

Comments
 (0)
Please sign in to comment.