Skip to content
Permalink
Browse files

Fix suppress labelling of short lines

And deduplicate code
Followup cfe397e
  • Loading branch information
m-kuhn committed Jun 3, 2015
1 parent 8ab005f commit 2b096e09e2d65e32351ae8dbab70923475cc87c1
Showing with 13 additions and 45 deletions.
  1. +1 −1 python/core/qgspallabeling.sip
  2. +9 −42 src/core/qgspallabeling.cpp
  3. +3 −2 src/core/qgspallabeling.h
@@ -812,5 +812,5 @@ class QgsPalLabeling : QgsLabelingEngineInterface
* @returns true if geometry exceeds minimum size
* @note added in QGIS 2.9
*/
static bool checkMinimumSizeMM( const QgsRenderContext &context, QgsGeometry *geom, double minSize );
static bool checkMinimumSizeMM( const QgsRenderContext &context, const QgsGeometry *geom, double minSize );
};
@@ -1240,42 +1240,9 @@ bool QgsPalLayerSettings::dataDefinedUseExpression( DataDefinedProperties p ) co
return useExpression;
}

bool QgsPalLayerSettings::checkMinimumSizeMM( const QgsRenderContext& ct, QgsGeometry* geom, double minSize ) const
bool QgsPalLayerSettings::checkMinimumSizeMM( const QgsRenderContext& ct, const QgsGeometry* geom, double minSize ) const
{
if ( minSize <= 0 )
{
return true;
}

if ( !geom )
{
return false;
}

QGis::GeometryType featureType = geom->type();
if ( featureType == QGis::Point ) //minimum size does not apply to point features
{
return true;
}

double mapUnitsPerMM = ct.mapToPixel().mapUnitsPerPixel() * ct.scaleFactor();
if ( featureType == QGis::Line )
{
double length = geom->length();
if ( length >= 0.0 )
{
return ( length >= ( minSize * mapUnitsPerMM ) );
}
}
else if ( featureType == QGis::Polygon )
{
double area = geom->area();
if ( area >= 0.0 )
{
return ( sqrt( area ) >= ( minSize * mapUnitsPerMM ) );
}
}
return true; //should never be reached. Return true in this case to label such geometries anyway.
return QgsPalLabeling::checkMinimumSizeMM( ct, geom, minSize );
}

void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY, QgsFeature* f )
@@ -1764,7 +1731,12 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext

const GEOSGeometry* geos_geom = 0;
QScopedPointer<QgsGeometry> preparedGeom;
if ( QgsPalLabeling::geometryRequiresPreparation( geom, context, ct, doClip ? extentGeom : 0 ) )

if ( minFeatureSize > 0 && !checkMinimumSizeMM( context, geom, minFeatureSize ) )
{
return;
}
else if ( QgsPalLabeling::geometryRequiresPreparation( geom, context, ct, doClip ? extentGeom : 0 ) )
{
preparedGeom.reset( QgsPalLabeling::prepareGeometry( geom, context, ct, minFeatureSize, doClip ? extentGeom : 0 ) );
if ( !preparedGeom.data() )
@@ -3452,11 +3424,6 @@ QgsGeometry* QgsPalLabeling::prepareGeometry( const QgsGeometry* geometry, const
}
}

if ( minSize > 0 && !checkMinimumSizeMM( context, geom, minSize ) )
{
return 0;
}

// Rotate the geometry if needed, before clipping
const QgsMapToPixel& m2p = context.mapToPixel();
if ( !qgsDoubleNear( m2p.mapRotation(), 0 ) )
@@ -3513,7 +3480,7 @@ QgsGeometry* QgsPalLabeling::prepareGeometry( const QgsGeometry* geometry, const
return clonedGeometry.take();
}

bool QgsPalLabeling::checkMinimumSizeMM( const QgsRenderContext& context, QgsGeometry* geom, double minSize )
bool QgsPalLabeling::checkMinimumSizeMM( const QgsRenderContext& context, const QgsGeometry* geom, double minSize )
{
if ( minSize <= 0 )
{
@@ -558,7 +558,7 @@ class CORE_EXPORT QgsPalLayerSettings

/**Checks if a feature is larger than a minimum size (in mm)
@return true if above size, false if below*/
bool checkMinimumSizeMM( const QgsRenderContext& ct, QgsGeometry* geom, double minSize ) const;
bool checkMinimumSizeMM( const QgsRenderContext& ct, const QgsGeometry* geom, double minSize ) const;


QMap<DataDefinedProperties, QVariant> dataDefinedValues;
@@ -882,7 +882,7 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
* @returns true if geometry exceeds minimum size
* @note added in QGIS 2.9
*/
static bool checkMinimumSizeMM( const QgsRenderContext &context, QgsGeometry *geom, double minSize );
static bool checkMinimumSizeMM( const QgsRenderContext &context, const QgsGeometry *geom, double minSize );

// hashtable of layer settings, being filled during labeling (key = layer ID)
QHash<QString, QgsPalLayerSettings> mActiveLayers;
@@ -906,6 +906,7 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface

QgsLabelingResults* mResults;

friend class QgsPalLayerSettings;
};
Q_NOWARN_DEPRECATED_POP

2 comments on commit 2b096e0

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Jun 3, 2015

@m-kuhn I can't test right now, but wouldn't checkMinimumSizeMM need to be called after reprojecting the feature?

@m-kuhn

This comment has been minimized.

Copy link
Member Author

@m-kuhn m-kuhn replied Jun 3, 2015

Please sign in to comment.
You can’t perform that action at this time.