Skip to content
Permalink
Browse files
[labeling][api] Add api to supress unplaced label visibility for
a single layer

Not exposed anywhere, for PyQGIS use only
  • Loading branch information
nyalldawson committed May 25, 2021
1 parent 6ce91e4 commit e7c4c84ae3ce311fb263f8363b2fac723852f2d5
@@ -99,3 +99,8 @@
Qgis.DriveType.__doc__ = 'Drive types\n\n.. versionadded:: 3.20\n\n' + '* ``Unknown``: ' + Qgis.DriveType.Unknown.__doc__ + '\n' + '* ``Invalid``: ' + Qgis.DriveType.Invalid.__doc__ + '\n' + '* ``Removable``: ' + Qgis.DriveType.Removable.__doc__ + '\n' + '* ``Fixed``: ' + Qgis.DriveType.Fixed.__doc__ + '\n' + '* ``Remote``: ' + Qgis.DriveType.Remote.__doc__ + '\n' + '* ``CdRom``: ' + Qgis.DriveType.CdRom.__doc__ + '\n' + '* ``RamDisk``: ' + Qgis.DriveType.RamDisk.__doc__
# --
Qgis.DriveType.baseClass = Qgis
# monkey patching scoped based enum
Qgis.UnplacedLabelVisibility.FollowEngineSetting.__doc__ = "Respect the label engine setting"
Qgis.UnplacedLabelVisibility.NeverShow.__doc__ = "Never show unplaced labels, regardless of the engine setting"
Qgis.UnplacedLabelVisibility.__doc__ = 'Unplaced label visibility.\n\n.. versionadded:: 3.20\n\n' + '* ``FollowEngineSetting``: ' + Qgis.UnplacedLabelVisibility.FollowEngineSetting.__doc__ + '\n' + '* ``NeverShow``: ' + Qgis.UnplacedLabelVisibility.NeverShow.__doc__
# --
@@ -666,6 +666,24 @@ Returns a pixmap preview for label ``settings``.
:param padding: space between icon edge and color ramp

.. versionadded:: 3.10
%End

Qgis::UnplacedLabelVisibility unplacedVisibility() const;
%Docstring
Returns the layer's unplaced label visibility.

.. seealso:: :py:func:`setUnplacedVisibility`

.. versionadded:: 3.20
%End

void setUnplacedVisibility( Qgis::UnplacedLabelVisibility visibility );
%Docstring
Sets the layer's unplaced label ``visibility``.

.. seealso:: :py:func:`unplacedVisibility`

.. versionadded:: 3.20
%End

const QgsFeature *mCurFeat;
@@ -680,6 +698,7 @@ Returns a pixmap preview for label ``settings``.
int mFeaturesToLabel;
int mFeatsSendingToPal;
int mFeatsRegPal;

};

class QgsLabelCandidate
@@ -172,6 +172,12 @@ The development version
RamDisk,
};

enum class UnplacedLabelVisibility
{
FollowEngineSetting,
NeverShow,
};

static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
@@ -368,6 +368,8 @@ QgsPalLayerSettings &QgsPalLayerSettings::operator=( const QgsPalLayerSettings &

mLegendString = s.mLegendString;

mUnplacedVisibility = s.mUnplacedVisibility;

return *this;
}

@@ -1096,6 +1098,7 @@ void QgsPalLayerSettings::readXml( const QDomElement &elem, const QgsReadWriteCo
mObstacleSettings.setFactor( renderingElem.attribute( QStringLiteral( "obstacleFactor" ), QStringLiteral( "1" ) ).toDouble() );
mObstacleSettings.setType( static_cast< QgsLabelObstacleSettings::ObstacleType >( renderingElem.attribute( QStringLiteral( "obstacleType" ), QString::number( PolygonInterior ) ).toUInt() ) );
zIndex = renderingElem.attribute( QStringLiteral( "zIndex" ), QStringLiteral( "0.0" ) ).toDouble();
mUnplacedVisibility = static_cast< Qgis::UnplacedLabelVisibility >( renderingElem.attribute( QStringLiteral( "unplacedVisibility" ), QString::number( static_cast< int >( Qgis::UnplacedLabelVisibility::FollowEngineSetting ) ) ).toInt() );

QDomElement ddElem = elem.firstChildElement( QStringLiteral( "dd_properties" ) );
if ( !ddElem.isNull() )
@@ -1248,6 +1251,7 @@ QDomElement QgsPalLayerSettings::writeXml( QDomDocument &doc, const QgsReadWrite
renderingElem.setAttribute( QStringLiteral( "obstacleFactor" ), mObstacleSettings.factor() );
renderingElem.setAttribute( QStringLiteral( "obstacleType" ), static_cast< unsigned int >( mObstacleSettings.type() ) );
renderingElem.setAttribute( QStringLiteral( "zIndex" ), zIndex );
renderingElem.setAttribute( QStringLiteral( "unplacedVisibility" ), static_cast< int >( mUnplacedVisibility ) );

QDomElement ddElem = doc.createElement( QStringLiteral( "dd_properties" ) );
mDataDefinedProperties.writeXml( ddElem, *sPropertyDefinitions() );
@@ -1400,6 +1404,16 @@ QPixmap QgsPalLayerSettings::labelSettingsPreviewPixmap( const QgsPalLayerSettin
return pixmap;
}

Qgis::UnplacedLabelVisibility QgsPalLayerSettings::unplacedVisibility() const
{
return mUnplacedVisibility;
}

void QgsPalLayerSettings::setUnplacedVisibility( Qgis::UnplacedLabelVisibility visibility )
{
mUnplacedVisibility = visibility;
}

bool QgsPalLayerSettings::checkMinimumSizeMM( const QgsRenderContext &ct, const QgsGeometry &geom, double minSize ) const
{
return QgsPalLabeling::checkMinimumSizeMM( ct, geom, minSize );
@@ -994,6 +994,22 @@ class CORE_EXPORT QgsPalLayerSettings
*/
static QPixmap labelSettingsPreviewPixmap( const QgsPalLayerSettings &settings, QSize size, const QString &previewText = QString(), int padding = 0 );

/**
* Returns the layer's unplaced label visibility.
*
* \see setUnplacedVisibility()
* \since QGIS 3.20
*/
Qgis::UnplacedLabelVisibility unplacedVisibility() const;

/**
* Sets the layer's unplaced label \a visibility.
*
* \see unplacedVisibility()
* \since QGIS 3.20
*/
void setUnplacedVisibility( Qgis::UnplacedLabelVisibility visibility );

// temporary stuff: set when layer gets prepared or labeled
const QgsFeature *mCurFeat = nullptr;
QgsFields mCurFields;
@@ -1007,6 +1023,7 @@ class CORE_EXPORT QgsPalLayerSettings
int mFeaturesToLabel = 0; // total features that will probably be labeled, may be less (figured before PAL)
int mFeatsSendingToPal = 0; // total features tested for sending into PAL (relative to maxNumLabels)
int mFeatsRegPal = 0; // number of features registered in PAL, when using limitNumLabels

private:

friend class QgsVectorLayer; // to allow calling readFromLayerCustomProperties()
@@ -1100,6 +1117,8 @@ class CORE_EXPORT QgsPalLayerSettings

QString mLegendString = QObject::tr( "Aa" );

Qgis::UnplacedLabelVisibility mUnplacedVisibility = Qgis::UnplacedLabelVisibility::FollowEngineSetting;

static void initPropertyDefinitions();
};

@@ -466,7 +466,7 @@ void QgsVectorLayerLabelProvider::drawLabel( QgsRenderContext &context, pal::Lab

void QgsVectorLayerLabelProvider::drawUnplacedLabel( QgsRenderContext &context, LabelPosition *label ) const
{
if ( !mSettings.drawLabels )
if ( !mSettings.drawLabels || mSettings.unplacedVisibility() == Qgis::UnplacedLabelVisibility::NeverShow )
return;

QgsTextLabelFeature *lf = dynamic_cast<QgsTextLabelFeature *>( label->getFeaturePart()->feature() );
@@ -241,6 +241,17 @@ class CORE_EXPORT Qgis
};
Q_ENUM( DriveType )

/**
* Unplaced label visibility.
*
* \since QGIS 3.20
*/
enum class UnplacedLabelVisibility : int
{
FollowEngineSetting, //!< Respect the label engine setting
NeverShow, //!< Never show unplaced labels, regardless of the engine setting
};

/**
* Identify search radius in mm
* \since QGIS 2.3

0 comments on commit e7c4c84

Please sign in to comment.