QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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.isValid() )
38  {
39  bool ok;
40  double factorD = exprVal.toDouble( &ok );
41  if ( ok )
42  {
43  factorD = qBound( 0.0, factorD, 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 }
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsLabelObstacleSettings::updateDataDefinedProperties
void updateDataDefinedProperties(const QgsPropertyCollection &properties, QgsExpressionContext &context)
Updates the obstacle settings to respect any data defined properties set within the specified propert...
Definition: qgslabelobstaclesettings.cpp:31
QgsLabelObstacleSettings::setObstacleGeometry
void setObstacleGeometry(const QgsGeometry &obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
Definition: qgslabelobstaclesettings.cpp:21
qgspallabeling.h
QgsExpressionContext::setOriginalValueVariable
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Definition: qgsexpressioncontext.cpp:566
QgsLabelObstacleSettings::obstacleGeometry
QgsGeometry obstacleGeometry() const
Returns the label's obstacle geometry, if different to the feature geometry.
Definition: qgslabelobstaclesettings.cpp:26
QgsPalLayerSettings::ObstacleFactor
@ ObstacleFactor
Definition: qgspallabeling.h:460
qgsexpressioncontext.h
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsPropertyCollection::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.
Definition: qgspropertycollection.cpp:218
QgsGeometry
Definition: qgsgeometry.h:122
qgspropertycollection.h
QgsPropertyCollection::isActive
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
Definition: qgspropertycollection.cpp:258
qgslabelobstaclesettings.h