QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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
17#include "moc_qgslabellinesettings.cpp"
20#include "qgslabelingengine.h"
21#include "qgspallabeling.h"
22
23
25{
27 {
29 const QString dataDefinedLineArrangement = properties.valueAsString( QgsPalLayerSettings::Property::LinePlacementOptions, context );
30 if ( !dataDefinedLineArrangement.isEmpty() )
31 {
32 mPlacementFlags = QgsLabelingUtils::decodeLinePlacementFlags( dataDefinedLineArrangement );
33 }
34 }
35
37 {
38 context.setOriginalValueVariable( mOverrunDistance );
39 mOverrunDistance = properties.valueAsDouble( QgsPalLayerSettings::Property::OverrunDistance, context, mOverrunDistance );
40 }
41
43 {
44 context.setOriginalValueVariable( mLineAnchorPercent );
45 mLineAnchorPercent = properties.valueAsDouble( QgsPalLayerSettings::Property::LineAnchorPercent, context, mLineAnchorPercent );
46 }
47
49 {
50 bool ok = false;
51 const QString value = properties.valueAsString( QgsPalLayerSettings::Property::LineAnchorClipping, context, QString(), &ok ).trimmed();
52 if ( ok )
53 {
54 if ( value.compare( QLatin1String( "visible" ), Qt::CaseInsensitive ) == 0 )
56 else if ( value.compare( QLatin1String( "entire" ), Qt::CaseInsensitive ) == 0 )
57 mAnchorClipping = AnchorClipping::UseEntireLine;
58 }
59 }
60
62 {
63 bool ok = false;
64 const QString value = properties.valueAsString( QgsPalLayerSettings::Property::LineAnchorType, context, QString(), &ok ).trimmed();
65 if ( ok )
66 {
67 if ( value.compare( QLatin1String( "hint" ), Qt::CaseInsensitive ) == 0 )
68 mAnchorType = AnchorType::HintOnly;
69 else if ( value.compare( QLatin1String( "strict" ), Qt::CaseInsensitive ) == 0 )
70 mAnchorType = AnchorType::Strict;
71 }
72 }
73
75 {
76 bool ok = false;
77 const QString value = properties.valueAsString( QgsPalLayerSettings::Property::LineAnchorTextPoint, context, QString(), &ok ).trimmed();
78 if ( ok )
79 {
80 if ( value.compare( QLatin1String( "follow" ), Qt::CaseInsensitive ) == 0 )
81 mAnchorTextPoint = AnchorTextPoint::FollowPlacement;
82 else if ( value.compare( QLatin1String( "start" ), Qt::CaseInsensitive ) == 0 )
83 mAnchorTextPoint = AnchorTextPoint::StartOfText;
84 else if ( value.compare( QLatin1String( "center" ), Qt::CaseInsensitive ) == 0 )
85 mAnchorTextPoint = AnchorTextPoint::CenterOfText;
86 else if ( value.compare( QLatin1String( "end" ), Qt::CaseInsensitive ) == 0 )
87 mAnchorTextPoint = AnchorTextPoint::EndOfText;
88 }
89 }
90}
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.
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.
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.
@ Strict
Line anchor is a strict placement, and other placements are not permitted.
@ HintOnly
Line anchor is a hint for preferred placement only, but other placements close to the hint are permit...
@ UseEntireLine
Entire original feature line geometry is used when calculating the line anchor for labels.
@ UseVisiblePartsOfLine
Only visible parts of lines are considered when calculating the line anchor for labels.
@ EndOfText
Anchor using end of text.
@ StartOfText
Anchor using start of text.
@ CenterOfText
Anchor using center of text.
@ FollowPlacement
Automatically set the anchor point based on the lineAnchorPercent() value. Values <25% will use the s...
void updateDataDefinedProperties(const QgsPropertyCollection &properties, QgsExpressionContext &context)
Updates the line settings to respect any data defined properties set within the specified properties ...
static Qgis::LabelLinePlacementFlags decodeLinePlacementFlags(const QString &string)
Decodes a string to set of line placement flags.
static QString encodeLinePlacementFlags(Qgis::LabelLinePlacementFlags flags)
Encodes line placement flags to a string.
@ LinePlacementOptions
Line placement flags.
@ LineAnchorType
Line anchor type.
@ LineAnchorClipping
Clipping mode for line anchor calculation.
@ LineAnchorPercent
Portion along line at which labels should be anchored.
@ LineAnchorTextPoint
Line anchor text point.
@ OverrunDistance
Distance which labels can extend past either end of linear features.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.