QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
labeling
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
16
#include "
qgslabelobstaclesettings.h
"
17
18
#include "
qgsexpressioncontext.h
"
19
#include "
qgspallabeling.h
"
20
#include "
qgspropertycollection.h
"
21
#include "
qgsvariantutils.h
"
22
23
void
QgsLabelObstacleSettings::setObstacleGeometry
(
const
QgsGeometry
&obstacleGeom )
24
{
25
mObstacleGeometry = obstacleGeom;
26
}
27
28
QgsGeometry
QgsLabelObstacleSettings::obstacleGeometry
()
const
29
{
30
return
mObstacleGeometry;
31
}
32
33
void
QgsLabelObstacleSettings::updateDataDefinedProperties
(
const
QgsPropertyCollection
&properties,
QgsExpressionContext
&context )
34
{
35
if
( properties.
isActive
(
QgsPalLayerSettings::Property::ObstacleFactor
) )
36
{
37
context.
setOriginalValueVariable
( mObstacleFactor );
38
QVariant exprVal = properties.
value
(
QgsPalLayerSettings::Property::ObstacleFactor
, context );
39
if
( !
QgsVariantUtils::isNull
( exprVal ) )
40
{
41
bool
ok;
42
double
factorD = exprVal.toDouble( &ok );
43
if
( ok )
44
{
45
factorD = std::clamp( factorD, 0.0, 10.0 );
46
factorD = factorD / 5.0 + 0.0001;
// convert 0 -> 10 to 0.0001 -> 2.0
47
mObstacleFactor = factorD;
48
}
49
}
50
}
51
}
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition
qgsexpressioncontext.h:491
QgsExpressionContext::setOriginalValueVariable
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Definition
qgsexpressioncontext.cpp:754
QgsGeometry
A geometry is the spatial representation of a feature.
Definition
qgsgeometry.h:267
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:33
QgsLabelObstacleSettings::setObstacleGeometry
void setObstacleGeometry(const QgsGeometry &obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
Definition
qgslabelobstaclesettings.cpp:23
QgsLabelObstacleSettings::obstacleGeometry
QgsGeometry obstacleGeometry() const
Returns the label's obstacle geometry, if different to the feature geometry.
Definition
qgslabelobstaclesettings.cpp:28
QgsPalLayerSettings::Property::ObstacleFactor
@ ObstacleFactor
Definition
qgspallabeling.h:237
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
Definition
qgspropertycollection.h:348
QgsPropertyCollection::value
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const final
Returns the calculated value of the property with the specified key from within the collection.
Definition
qgspropertycollection.cpp:233
QgsPropertyCollection::isActive
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
Definition
qgspropertycollection.cpp:286
QgsVariantUtils::isNull
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Definition
qgsvariantutils.cpp:176
qgsexpressioncontext.h
qgslabelobstaclesettings.h
qgspallabeling.h
qgspropertycollection.h
qgsvariantutils.h
Generated on
for QGIS API Documentation by
1.17.0