QGIS API Documentation  3.25.0-Master (dec16ba68b)
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 
17 #include "qgspropertycollection.h"
18 #include "qgsexpressioncontext.h"
19 #include "qgspallabeling.h"
20 
22 {
23  mObstacleGeometry = obstacleGeom;
24 }
25 
27 {
28  return mObstacleGeometry;
29 }
30 
32 {
34  {
35  context.setOriginalValueVariable( mObstacleFactor );
36  QVariant exprVal = properties.value( QgsPalLayerSettings::ObstacleFactor, context );
37  if ( !exprVal.isNull() )
38  {
39  bool ok;
40  double factorD = exprVal.toDouble( &ok );
41  if ( ok )
42  {
43  factorD = std::clamp( factorD, 0.0, 10.0 );
44  factorD = factorD / 5.0 + 0.0001; // convert 0 -> 10 to 0.0001 -> 2.0
45  mObstacleFactor = factorD;
46  }
47  }
48  }
49 
50 }
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:125
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.