@@ -177,7 +177,7 @@ class QgsPalGeometry : public PalGeometry
177
177
// -------------
178
178
179
179
QgsPalLayerSettings::QgsPalLayerSettings ()
180
- : palLayer( NULL ), ct( NULL ), extentGeom( NULL ), expression( NULL )
180
+ : palLayer( NULL ), ct( NULL ), extentGeom( NULL ), mFeaturesToLabel( 0 ), mFeatsSendingToPal( 0 ), mFeatsRegPal( 0 ), expression( NULL )
181
181
{
182
182
placement = AroundPoint;
183
183
placementFlags = 0 ;
@@ -658,13 +658,6 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
658
658
659
659
void QgsPalLayerSettings::registerFeature ( QgsVectorLayer* layer, QgsFeature& f, const QgsRenderContext& context )
660
660
{
661
-
662
- // check if max number of labels to draw (already registered features) has been reached
663
- if ( limitNumLabels && ( maxNumLabels == 0 || palLayer->getNbFeatures () >= maxNumLabels ) )
664
- {
665
- return ;
666
- }
667
-
668
661
// data defined show label? defaults to show label if not 0
669
662
QMap< DataDefinedProperties, int >::const_iterator showIt = dataDefinedProperties.find ( QgsPalLayerSettings::Show );
670
663
if ( showIt != dataDefinedProperties.constEnd () )
@@ -822,6 +815,32 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
822
815
if ( geos_geom == NULL )
823
816
return ; // invalid geometry
824
817
818
+ // likelihood exists label will be registered with PAL and may be drawn
819
+ // check if max number of features to label (already registered with PAL) has been reached
820
+ // Debug output at end of QgsPalLabeling::drawLabeling(), when deleting temp geometries
821
+ if ( limitNumLabels )
822
+ {
823
+ if ( !maxNumLabels )
824
+ {
825
+ return ;
826
+ }
827
+ mFeatsRegPal = palLayer->getNbFeatures ();
828
+ if ( mFeatsRegPal >= maxNumLabels )
829
+ {
830
+ return ;
831
+ }
832
+
833
+ int divNum = ( int )(( mFeaturesToLabel / maxNumLabels ) + 0.5 );
834
+ if ( divNum && ( mFeatsRegPal == ( int )( mFeatsSendingToPal / divNum ) ) )
835
+ {
836
+ mFeatsSendingToPal += 1 ;
837
+ if ( divNum && mFeatsSendingToPal % divNum )
838
+ {
839
+ return ;
840
+ }
841
+ }
842
+ }
843
+
825
844
GEOSGeometry* geos_geom_clone = GEOSGeom_clone ( geos_geom );
826
845
827
846
// data defined position / alignment / rotation?
@@ -1259,6 +1278,8 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices,
1259
1278
// rect for clipping
1260
1279
lyr.extentGeom = QgsGeometry::fromRect ( mMapRenderer ->extent () );
1261
1280
1281
+ lyr.mFeatsSendingToPal = 0 ;
1282
+
1262
1283
return 1 ; // init successful
1263
1284
}
1264
1285
@@ -1656,6 +1677,13 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
1656
1677
QgsPalLayerSettings& lyr = lit.value ();
1657
1678
for ( QList<QgsPalGeometry*>::iterator git = lyr.geometries .begin (); git != lyr.geometries .end (); ++git )
1658
1679
delete *git;
1680
+ if ( lyr.limitNumLabels )
1681
+ {
1682
+ QgsDebugMsg ( QString ( " mFeaturesToLabel: %1" ).arg ( lyr.mFeaturesToLabel ) );
1683
+ QgsDebugMsg ( QString ( " maxNumLabels: %1" ).arg ( lyr.maxNumLabels ) );
1684
+ QgsDebugMsg ( QString ( " mFeatsSendingToPal: %1" ).arg ( lyr.mFeatsSendingToPal ) );
1685
+ QgsDebugMsg ( QString ( " mFeatsRegPal: %1" ).arg ( lyr.geometries .count () ) );
1686
+ }
1659
1687
lyr.geometries .clear ();
1660
1688
}
1661
1689
0 commit comments