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 #include "qgspropertycollection.h" 18 #include "qgsexpressioncontext.h" 19 #include "qgspallabeling.h" 20 setObstacleGeometry(const QgsGeometry & obstacleGeom)21void QgsLabelObstacleSettings::setObstacleGeometry( const QgsGeometry &obstacleGeom ) 22 { 23 mObstacleGeometry = obstacleGeom; 24 } 25 obstacleGeometry() const26QgsGeometry QgsLabelObstacleSettings::obstacleGeometry() const 27 { 28 return mObstacleGeometry; 29 } 30 updateDataDefinedProperties(const QgsPropertyCollection & properties,QgsExpressionContext & context)31void QgsLabelObstacleSettings::updateDataDefinedProperties( const QgsPropertyCollection &properties, QgsExpressionContext &context ) 32 { 33 if ( properties.isActive( QgsPalLayerSettings::ObstacleFactor ) ) 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 = 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 } 51