QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgslabellinesettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslabellinesettings.cpp
3  ----------------------------
4  Date : August 2020
5  Copyright : (C) 2020 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 "qgslabellinesettings.h"
17 #include "qgspropertycollection.h"
18 #include "qgsexpressioncontext.h"
19 #include "qgslabelingengine.h"
20 #include "qgspallabeling.h"
21 
22 
24 {
26  {
28  const QString dataDefinedLineArrangement = properties.valueAsString( QgsPalLayerSettings::LinePlacementOptions, context );
29  if ( !dataDefinedLineArrangement.isEmpty() )
30  {
31  mPlacementFlags = QgsLabelingUtils::decodeLinePlacementFlags( dataDefinedLineArrangement );
32  }
33  }
34 
36  {
37  context.setOriginalValueVariable( mOverrunDistance );
38  mOverrunDistance = properties.valueAsDouble( QgsPalLayerSettings::OverrunDistance, context, mOverrunDistance );
39  }
40 
42  {
43  context.setOriginalValueVariable( mLineAnchorPercent );
44  mLineAnchorPercent = properties.valueAsDouble( QgsPalLayerSettings::LineAnchorPercent, context, mLineAnchorPercent );
45  }
46 
48  {
49  bool ok = false;
50  const QString value = properties.valueAsString( QgsPalLayerSettings::LineAnchorClipping, context, QString(), &ok ).trimmed();
51  if ( ok )
52  {
53  if ( value.compare( QLatin1String( "visible" ), Qt::CaseInsensitive ) == 0 )
54  mAnchorClipping = AnchorClipping::UseVisiblePartsOfLine;
55  else if ( value.compare( QLatin1String( "entire" ), Qt::CaseInsensitive ) == 0 )
56  mAnchorClipping = AnchorClipping::UseEntireLine;
57  }
58  }
59 
61  {
62  bool ok = false;
63  const QString value = properties.valueAsString( QgsPalLayerSettings::LineAnchorType, context, QString(), &ok ).trimmed();
64  if ( ok )
65  {
66  if ( value.compare( QLatin1String( "hint" ), Qt::CaseInsensitive ) == 0 )
67  mAnchorType = AnchorType::HintOnly;
68  else if ( value.compare( QLatin1String( "strict" ), Qt::CaseInsensitive ) == 0 )
69  mAnchorType = AnchorType::Strict;
70  }
71  }
72 
74  {
75  bool ok = false;
76  const QString value = properties.valueAsString( QgsPalLayerSettings::LineAnchorTextPoint, context, QString(), &ok ).trimmed();
77  if ( ok )
78  {
79  if ( value.compare( QLatin1String( "follow" ), Qt::CaseInsensitive ) == 0 )
80  mAnchorTextPoint = AnchorTextPoint::FollowPlacement;
81  else if ( value.compare( QLatin1String( "start" ), Qt::CaseInsensitive ) == 0 )
82  mAnchorTextPoint = AnchorTextPoint::StartOfText;
83  else if ( value.compare( QLatin1String( "center" ), Qt::CaseInsensitive ) == 0 )
84  mAnchorTextPoint = AnchorTextPoint::CenterOfText;
85  else if ( value.compare( QLatin1String( "end" ), Qt::CaseInsensitive ) == 0 )
86  mAnchorTextPoint = AnchorTextPoint::EndOfText;
87  }
88  }
89 }
QgsLabelLineSettings::AnchorClipping::UseEntireLine
@ UseEntireLine
Entire original feature line geometry is used when calculating the line anchor for labels.
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsLabelLineSettings::updateDataDefinedProperties
void updateDataDefinedProperties(const QgsPropertyCollection &properties, QgsExpressionContext &context)
Updates the thinning settings to respect any data defined properties set within the specified propert...
Definition: qgslabellinesettings.cpp:23
QgsLabelLineSettings::AnchorTextPoint::StartOfText
@ StartOfText
Anchor using start of text.
QgsAbstractPropertyCollection::valueAsDouble
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
Definition: qgspropertycollection.cpp:66
qgspallabeling.h
QgsExpressionContext::setOriginalValueVariable
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Definition: qgsexpressioncontext.cpp:600
qgslabellinesettings.h
qgsexpressioncontext.h
QgsLabelLineSettings::AnchorTextPoint::EndOfText
@ EndOfText
Anchor using end of text.
QgsLabelingUtils::encodeLinePlacementFlags
static QString encodeLinePlacementFlags(QgsLabeling::LinePlacementFlags flags)
Encodes line placement flags to a string.
Definition: qgslabelingengine.cpp:766
QgsLabelLineSettings::AnchorType::Strict
@ Strict
Line anchor is a strict placement, and other placements are not permitted.
QgsLabelLineSettings::AnchorClipping::UseVisiblePartsOfLine
@ UseVisiblePartsOfLine
Only visible parts of lines are considered when calculating the line anchor for labels.
QgsLabelLineSettings::AnchorTextPoint::CenterOfText
@ CenterOfText
Anchor using center of text.
QgsPalLayerSettings::OverrunDistance
@ OverrunDistance
Distance which labels can extend past either end of linear features.
Definition: qgspallabeling.h:255
QgsPalLayerSettings::LineAnchorPercent
@ LineAnchorPercent
Portion along line at which labels should be anchored (since QGIS 3.16)
Definition: qgspallabeling.h:258
QgsPalLayerSettings::LineAnchorClipping
@ LineAnchorClipping
Clipping mode for line anchor calculation (since QGIS 3.20)
Definition: qgspallabeling.h:259
QgsLabelLineSettings::AnchorType::HintOnly
@ HintOnly
Line anchor is a hint for preferred placement only, but other placements close to the hint are permit...
QgsPalLayerSettings::LineAnchorTextPoint
@ LineAnchorTextPoint
Line anchor text point (since QGIS 3.26)
Definition: qgspallabeling.h:261
QgsAbstractPropertyCollection::valueAsString
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string.
Definition: qgspropertycollection.cpp:42
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsLabelingUtils::decodeLinePlacementFlags
static QgsLabeling::LinePlacementFlags decodeLinePlacementFlags(const QString &string)
Decodes a string to set of line placement flags.
Definition: qgslabelingengine.cpp:780
QgsPalLayerSettings::LineAnchorType
@ LineAnchorType
Line anchor type (since QGIS 3.26)
Definition: qgspallabeling.h:260
qgspropertycollection.h
QgsPalLayerSettings::LinePlacementOptions
@ LinePlacementOptions
Line placement flags.
Definition: qgspallabeling.h:254
QgsPropertyCollection::isActive
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
Definition: qgspropertycollection.cpp:268
QgsLabelLineSettings::AnchorTextPoint::FollowPlacement
@ FollowPlacement
Automatically set the anchor point based on the lineAnchorPercent() value. Values <25% will use the s...
qgslabelingengine.h