QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgslabelobstaclesettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslabelobstaclesettings.cpp
3 ----------------------------
4 Date : December 2019
5 Copyright : (C) 2019 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
19#include "qgspallabeling.h"
20#include "qgsvariantutils.h"
21
23{
24 mObstacleGeometry = obstacleGeom;
25}
26
28{
29 return mObstacleGeometry;
30}
31
33{
35 {
36 context.setOriginalValueVariable( mObstacleFactor );
37 QVariant exprVal = properties.value( QgsPalLayerSettings::ObstacleFactor, context );
38 if ( !QgsVariantUtils::isNull( exprVal ) )
39 {
40 bool ok;
41 double factorD = exprVal.toDouble( &ok );
42 if ( ok )
43 {
44 factorD = std::clamp( factorD, 0.0, 10.0 );
45 factorD = factorD / 5.0 + 0.0001; // convert 0 -> 10 to 0.0001 -> 2.0
46 mObstacleFactor = factorD;
47 }
48 }
49 }
50
51}
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
void updateDataDefinedProperties(const QgsPropertyCollection &properties, QgsExpressionContext &context)
Updates the obstacle settings to respect any data defined properties set within the specified propert...
void setObstacleGeometry(const QgsGeometry &obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
QgsGeometry obstacleGeometry() const
Returns the label's obstacle geometry, if different to the feature geometry.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
static bool isNull(const QVariant &variant)
Returns true if the specified variant should be considered a NULL value.